Changeset 15328 in webkit for trunk/JavaScriptCore
- Timestamp:
- Jul 10, 2006, 10:37:00 PM (19 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSContextRef.h
r15317 r15328 28 28 #define JSContextRef_h 29 29 30 #include "JSObjectRef.h"31 #include "JSValueRef.h"30 #include <JavaScriptCore/JSObjectRef.h> 31 #include <JavaScriptCore/JSValueRef.h> 32 32 33 33 #ifdef __cplusplus -
trunk/JavaScriptCore/API/JSInternalStringRef.cpp
r15307 r15328 37 37 using namespace KJS; 38 38 39 JSValueRef JSStringMake(JSInternalStringRef buffer)39 JSValueRef JSStringMake(JSInternalStringRef string) 40 40 { 41 41 JSLock lock; 42 UString::Rep* rep = toJS( buffer);42 UString::Rep* rep = toJS(string); 43 43 return toRef(jsString(UString(rep))); 44 44 } … … 58 58 } 59 59 60 JSInternalStringRef JSInternalStringRetain(JSInternalStringRef buffer)60 JSInternalStringRef JSInternalStringRetain(JSInternalStringRef string) 61 61 { 62 UString::Rep* rep = toJS( buffer);62 UString::Rep* rep = toJS(string); 63 63 return toRef(rep->ref()); 64 64 } 65 65 66 void JSInternalStringRelease(JSInternalStringRef buffer)66 void JSInternalStringRelease(JSInternalStringRef string) 67 67 { 68 68 JSLock lock; 69 UString::Rep* rep = toJS( buffer);69 UString::Rep* rep = toJS(string); 70 70 rep->deref(); 71 71 } … … 77 77 ExecState* exec = toJS(context); 78 78 79 JSInternalStringRef charBufferRef = toRef(jsValue->toString(exec).rep()->ref());79 JSInternalStringRef stringRef = toRef(jsValue->toString(exec).rep()->ref()); 80 80 if (exec->hadException()) 81 81 exec->clearException(); 82 return charBufferRef;82 return stringRef; 83 83 } 84 84 85 size_t JSInternalStringGetLength(JSInternalStringRef buffer)85 size_t JSInternalStringGetLength(JSInternalStringRef string) 86 86 { 87 UString::Rep* rep = toJS( buffer);87 UString::Rep* rep = toJS(string); 88 88 return rep->size(); 89 89 } 90 90 91 const JSChar* JSInternalStringGetCharactersPtr(JSInternalStringRef buffer)91 const JSChar* JSInternalStringGetCharactersPtr(JSInternalStringRef string) 92 92 { 93 UString::Rep* rep = toJS( buffer);93 UString::Rep* rep = toJS(string); 94 94 return reinterpret_cast<const JSChar*>(rep->data()); 95 95 } 96 96 97 void JSInternalStringGetCharacters(JSInternalStringRef inBuffer, JSChar* outBuffer, size_t numChars)97 void JSInternalStringGetCharacters(JSInternalStringRef string, JSChar* buffer, size_t numChars) 98 98 { 99 UString::Rep* rep = toJS( inBuffer);99 UString::Rep* rep = toJS(string); 100 100 const JSChar* data = reinterpret_cast<const JSChar*>(rep->data()); 101 101 102 memcpy( outBuffer, data, numChars * sizeof(JSChar));102 memcpy(buffer, data, numChars * sizeof(JSChar)); 103 103 } 104 104 105 size_t JSInternalStringGetMaxLengthUTF8(JSInternalStringRef buffer)105 size_t JSInternalStringGetMaxLengthUTF8(JSInternalStringRef string) 106 106 { 107 UString::Rep* rep = toJS( buffer);107 UString::Rep* rep = toJS(string); 108 108 109 109 // Any UTF8 character > 3 bytes encodes as a UTF16 surrogate pair. … … 111 111 } 112 112 113 size_t JSInternalStringGetCharactersUTF8(JSInternalStringRef inBuffer, char* outBuffer, size_t bufferSize)113 size_t JSInternalStringGetCharactersUTF8(JSInternalStringRef string, char* buffer, size_t bufferSize) 114 114 { 115 115 JSLock lock; 116 UString::Rep* rep = toJS( inBuffer);116 UString::Rep* rep = toJS(string); 117 117 CString cString = UString(rep).UTF8String(); 118 118 119 119 size_t length = std::min(bufferSize, cString.size() + 1); // + 1 for terminating '\0' 120 memcpy( outBuffer, cString.c_str(), length);120 memcpy(buffer, cString.c_str(), length); 121 121 return length; 122 122 } … … 157 157 } 158 158 159 CFStringRef CFStringCreateWithJSInternalString(CFAllocatorRef alloc, JSInternalStringRef buffer)159 CFStringRef CFStringCreateWithJSInternalString(CFAllocatorRef alloc, JSInternalStringRef string) 160 160 { 161 UString::Rep* rep = toJS( buffer);161 UString::Rep* rep = toJS(string); 162 162 return CFStringCreateWithCharacters(alloc, reinterpret_cast<const JSChar*>(rep->data()), rep->size()); 163 163 } -
trunk/JavaScriptCore/API/JSInternalStringRef.h
r15307 r15328 28 28 #define JSInternalStringRef_h 29 29 30 #include "JSValueRef.h"30 #include <JavaScriptCore/JSValueRef.h> 31 31 #ifdef __cplusplus 32 32 extern "C" { … … 62 62 @function 63 63 @abstract Retains a JavaScript string. 64 @param bufferThe JSInternalString to retain.64 @param string The JSInternalString to retain. 65 65 @result A JSInternalString that is the same as buffer. 66 66 */ 67 JSInternalStringRef JSInternalStringRetain(JSInternalStringRef buffer);67 JSInternalStringRef JSInternalStringRetain(JSInternalStringRef string); 68 68 /*! 69 69 @function 70 70 @abstract Releases a JavaScript string. 71 @param bufferThe JSInternalString to release.71 @param string The JSInternalString to release. 72 72 */ 73 void JSInternalStringRelease(JSInternalStringRef buffer);73 void JSInternalStringRelease(JSInternalStringRef string); 74 74 75 75 /*! 76 76 @function 77 77 @abstract Returns the number of Unicode characters in a JavaScript string. 78 @param bufferThe JSInternalString whose length (in Unicode characters) you want to know.79 @result The number of Unicode characters stored in buffer.78 @param string The JSInternalString whose length (in Unicode characters) you want to know. 79 @result The number of Unicode characters stored in string. 80 80 */ 81 size_t JSInternalStringGetLength(JSInternalStringRef buffer);81 size_t JSInternalStringGetLength(JSInternalStringRef string); 82 82 /*! 83 83 @function 84 84 @abstract Quickly obtains a pointer to the Unicode character buffer that 85 85 serves as the backing store for a JavaScript string. 86 @param bufferThe JSInternalString whose backing store you want to access.87 @result A pointer to the Unicode character buffer that serves as buffer's88 backing store, which will be deallocated when bufferis deallocated.86 @param string The JSInternalString whose backing store you want to access. 87 @result A pointer to the Unicode character buffer that serves as string's 88 backing store, which will be deallocated when string is deallocated. 89 89 */ 90 const JSChar* JSInternalStringGetCharactersPtr(JSInternalStringRef buffer);90 const JSChar* JSInternalStringGetCharactersPtr(JSInternalStringRef string); 91 91 /*! 92 92 @function 93 93 @abstract Copies a JavaScript string's Unicode characters into an 94 94 external character buffer. 95 @param inBufferThe source JSInternalString.96 @param outBuffer The destination JSChar buffer into which to copy inBuffer's97 characters. On return, outBuffer contains the requested Unicode characters.95 @param string The source JSInternalString. 96 @param buffer The destination JSChar buffer into which to copy string's 97 characters. On return, buffer contains the requested Unicode characters. 98 98 @param numChars The number of Unicode characters to copy. This number must not 99 99 exceed the length of the string. 100 100 */ 101 void JSInternalStringGetCharacters(JSInternalStringRef inBuffer, JSChar* outBuffer, size_t numChars);101 void JSInternalStringGetCharacters(JSInternalStringRef string, JSChar* buffer, size_t numChars); 102 102 103 103 /*! … … 105 105 @abstract Returns the maximum number of bytes required to encode the 106 106 contents of a JavaScript string as a null-terminated UTF8 string. 107 @param bufferThe JSInternalString whose maximum encoded length (in bytes) you107 @param string The JSInternalString whose maximum encoded length (in bytes) you 108 108 want to know. 109 @result The maximum number of bytes required to encode buffer's contents109 @result The maximum number of bytes required to encode string's contents 110 110 as a null-terminated UTF8 string. 111 111 */ 112 size_t JSInternalStringGetMaxLengthUTF8(JSInternalStringRef buffer);112 size_t JSInternalStringGetMaxLengthUTF8(JSInternalStringRef string); 113 113 /*! 114 114 @function 115 115 @abstract Converts a JavaScript string's contents into a 116 116 null-terminated UTF8 string, and copies the result into an external byte buffer. 117 @param inBufferThe source JSInternalString.118 @param outBuffer The destination byte buffer into which to copy a UTF8 string119 representation of inBuffer. The buffer must be at least bufferSize bytes in length.120 On return, outBuffer contains a UTF8 string representation of inBuffer.121 If bufferSize is too small, outBuffer will contain only partial results.117 @param string The source JSInternalString. 118 @param buffer The destination byte buffer into which to copy a UTF8 string 119 representation of string. The buffer must be at least bufferSize bytes in length. 120 On return, buffer contains a UTF8 string representation of string. 121 If bufferSize is too small, buffer will contain only partial results. 122 122 @param bufferSize The length of the external buffer in bytes. 123 @result The number of bytes written into outBuffer (including the null-terminator byte).123 @result The number of bytes written into buffer (including the null-terminator byte). 124 124 */ 125 size_t JSInternalStringGetCharactersUTF8(JSInternalStringRef inBuffer, char* outBuffer, size_t bufferSize);125 size_t JSInternalStringGetCharactersUTF8(JSInternalStringRef string, char* buffer, size_t bufferSize); 126 126 127 127 /*! … … 130 130 @param a The first JSInternalString to test. 131 131 @param b The second JSInternalString to test. 132 @result true if the characters in the two buffers match, otherwise false.132 @result true if the characters in the two strings match, otherwise false. 133 133 */ 134 134 bool JSInternalStringIsEqual(JSInternalStringRef a, JSInternalStringRef b); … … 139 139 @param a The JSInternalString to test. 140 140 @param b The null-terminated UTF8 string to test. 141 @result true if the characters in the two buffers match, otherwise false.141 @result true if the characters in the two strings match, otherwise false. 142 142 */ 143 143 bool JSInternalStringIsEqualUTF8(JSInternalStringRef a, const char* b); … … 159 159 @abstract Creates a CFString form a JavaScript string. 160 160 @param alloc The alloc parameter to pass to CFStringCreate. 161 @param bufferThe JSInternalString to copy into the new CFString.162 @result A CFString containing buffer. Ownership follows the create rule.161 @param string The JSInternalString to copy into the new CFString. 162 @result A CFString containing string. Ownership follows the create rule. 163 163 */ 164 CFStringRef CFStringCreateWithJSInternalString(CFAllocatorRef alloc, JSInternalStringRef buffer);164 CFStringRef CFStringCreateWithJSInternalString(CFAllocatorRef alloc, JSInternalStringRef string); 165 165 #endif // __APPLE__ 166 166 -
trunk/JavaScriptCore/API/JSNode.c
r15317 r15328 40 40 // Example of throwing a type error for invalid values 41 41 if (!JSValueIsObjectOfClass(thisObject, JSNode_class(context))) { 42 JSInternalStringRef message Buf= JSInternalStringCreateUTF8("TypeError: appendChild can only be called on nodes");43 *exception = JSStringMake(message Buf);44 JSInternalStringRelease(message Buf);42 JSInternalStringRef message = JSInternalStringCreateUTF8("TypeError: appendChild can only be called on nodes"); 43 *exception = JSStringMake(message); 44 JSInternalStringRelease(message); 45 45 } else if (argc < 1 || !JSValueIsObjectOfClass(argv[0], JSNode_class(context))) { 46 JSInternalStringRef message Buf= JSInternalStringCreateUTF8("TypeError: first argument to appendChild must be a node");47 *exception = JSStringMake(message Buf);48 JSInternalStringRelease(message Buf);46 JSInternalStringRef message = JSInternalStringCreateUTF8("TypeError: first argument to appendChild must be a node"); 47 *exception = JSStringMake(message); 48 JSInternalStringRelease(message); 49 49 } else { 50 50 Node* node = JSObjectGetPrivate(thisObject); … … 121 121 Node* node = JSObjectGetPrivate(object); 122 122 if (node) { 123 JSInternalStringRef node Buf= JSInternalStringCreateUTF8(node->nodeType);124 *returnValue = JSStringMake(node Buf);125 JSInternalStringRelease(node Buf);123 JSInternalStringRef nodeType = JSInternalStringCreateUTF8(node->nodeType); 124 *returnValue = JSStringMake(nodeType); 125 JSInternalStringRelease(nodeType); 126 126 return true; 127 127 } -
trunk/JavaScriptCore/API/JSObjectRef.h
r15317 r15328 28 28 #define JSObjectRef_h 29 29 30 #include "JSBase.h"31 #include "JSValueRef.h"30 #include <JavaScriptCore/JSBase.h> 31 #include <JavaScriptCore/JSValueRef.h> 32 32 33 33 #ifdef __cplusplus … … 269 269 @struct JSStaticValue 270 270 @abstract This structure describes a static value property. 271 @field name A UTF8 buffercontaining the property's name.271 @field name A null-terminated UTF8 string containing the property's name. 272 272 @field getProperty A JSGetPropertyCallback to invoke when getting the property's value. 273 273 @field setProperty A JSSetPropertyCallback to invoke when setting the property's value. … … 284 284 @struct JSStaticFunction 285 285 @abstract This structure describes a static function property. 286 @field name A UTF8 buffercontaining the property's name.286 @field name A null-terminated UTF8 string containing the property's name. 287 287 @field callAsFunction A JSCallAsFunctionCallback to invoke when the property is called as a function. 288 288 @field attributes A logically ORed set of JSPropertyAttributes to give to the property. -
trunk/JavaScriptCore/API/JSValueRef.h
r15307 r15328 28 28 #define JSValueRef_h 29 29 30 #include "JSBase.h"30 #include <JavaScriptCore/JSBase.h> 31 31 32 32 /*! … … 189 189 @function 190 190 @abstract Creates a JavaScript value of the string type. 191 @param bufferThe JSInternalString to assign to the newly created JSValue. The192 newly created JSValue retains buffer, and releases it upon garbage collection.193 @result A JSValue of the string type, representing the string value of buffer.194 */ 195 JSValueRef JSStringMake(JSInternalStringRef buffer);191 @param string The JSInternalString to assign to the newly created JSValue. The 192 newly created JSValue retains string, and releases it upon garbage collection. 193 @result A JSValue of the string type, representing the string value of string. 194 */ 195 JSValueRef JSStringMake(JSInternalStringRef string); 196 196 197 197 // Converting to primitive values -
trunk/JavaScriptCore/API/JavaScriptCore.h
r15307 r15328 31 31 #include <stddef.h> // for size_t 32 32 33 #include "JSBase.h"34 #include "JSInternalStringRef.h"35 #include "JSContextRef.h"36 #include "JSObjectRef.h"37 #include "JSValueRef.h"33 #include <JavaScriptCore/JSBase.h> 34 #include <JavaScriptCore/JSInternalStringRef.h> 35 #include <JavaScriptCore/JSContextRef.h> 36 #include <JavaScriptCore/JSObjectRef.h> 37 #include <JavaScriptCore/JSValueRef.h> 38 38 39 39 #endif // JavaScriptCore_h -
trunk/JavaScriptCore/API/minidom.c
r15317 r15328 40 40 JSObjectRef globalObject = JSContextGetGlobalObject(context); 41 41 42 JSInternalStringRef print Buf= JSInternalStringCreateUTF8("print");43 JSObjectSetProperty(context, globalObject, print Buf, JSFunctionMake(context, print), kJSPropertyAttributeNone);44 JSInternalStringRelease(print Buf);42 JSInternalStringRef printIString = JSInternalStringCreateUTF8("print"); 43 JSObjectSetProperty(context, globalObject, printIString, JSFunctionMake(context, print), kJSPropertyAttributeNone); 44 JSInternalStringRelease(printIString); 45 45 46 JSInternalStringRef node Buf= JSInternalStringCreateUTF8("Node");47 JSObjectSetProperty(context, globalObject, node Buf, JSConstructorMake(context, JSNode_construct), kJSPropertyAttributeNone);48 JSInternalStringRelease(node Buf);46 JSInternalStringRef node = JSInternalStringCreateUTF8("Node"); 47 JSObjectSetProperty(context, globalObject, node, JSConstructorMake(context, JSNode_construct), kJSPropertyAttributeNone); 48 JSInternalStringRelease(node); 49 49 50 char* script = createStringWithContentsOfFile("minidom.js");51 JSInternalStringRef script Buf = JSInternalStringCreateUTF8(script);50 char* scriptUTF8 = createStringWithContentsOfFile("minidom.js"); 51 JSInternalStringRef script = JSInternalStringCreateUTF8(scriptUTF8); 52 52 JSValueRef exception; 53 JSValueRef result = JSEvaluate(context, script Buf, NULL, NULL, 0, &exception);53 JSValueRef result = JSEvaluate(context, script, NULL, NULL, 0, &exception); 54 54 if (result) 55 55 printf("PASS: Test script executed successfully.\n"); 56 56 else { 57 57 printf("FAIL: Test script threw exception:\n"); 58 JSInternalStringRef exception Buf= JSValueCopyStringValue(context, exception);59 CFStringRef exceptionCF = CFStringCreateWithJSInternalString(kCFAllocatorDefault, exception Buf);58 JSInternalStringRef exceptionIString = JSValueCopyStringValue(context, exception); 59 CFStringRef exceptionCF = CFStringCreateWithJSInternalString(kCFAllocatorDefault, exceptionIString); 60 60 CFShow(exceptionCF); 61 61 CFRelease(exceptionCF); 62 JSInternalStringRelease(exception Buf);62 JSInternalStringRelease(exceptionIString); 63 63 } 64 JSInternalStringRelease(script Buf);65 free(script );64 JSInternalStringRelease(script); 65 free(scriptUTF8); 66 66 67 67 #if 0 // used for leak/finalize debugging … … 82 82 { 83 83 if (argc > 0) { 84 JSInternalStringRef string Buf= JSValueCopyStringValue(context, argv[0]);85 size_t numChars = JSInternalStringGetMaxLengthUTF8(string Buf);86 char string [numChars];87 JSInternalStringGetCharactersUTF8(string Buf, string, numChars);88 printf("%s\n", string );84 JSInternalStringRef string = JSValueCopyStringValue(context, argv[0]); 85 size_t numChars = JSInternalStringGetMaxLengthUTF8(string); 86 char stringUTF8[numChars]; 87 JSInternalStringGetCharactersUTF8(string, stringUTF8, numChars); 88 printf("%s\n", stringUTF8); 89 89 } 90 90 -
trunk/JavaScriptCore/API/testapi.c
r15317 r15328 194 194 UNUSED_PARAM(context); 195 195 196 JSInternalStringRef propertyName Buf;197 198 propertyName Buf= JSInternalStringCreateUTF8("alwaysOne");199 JSPropertyListAdd(propertyList, object, propertyName Buf);200 JSInternalStringRelease(propertyName Buf);201 202 propertyName Buf= JSInternalStringCreateUTF8("myPropertyName");203 JSPropertyListAdd(propertyList, object, propertyName Buf);204 JSInternalStringRelease(propertyName Buf);196 JSInternalStringRef propertyName; 197 198 propertyName = JSInternalStringCreateUTF8("alwaysOne"); 199 JSPropertyListAdd(propertyList, object, propertyName); 200 JSInternalStringRelease(propertyName); 201 202 propertyName = JSInternalStringCreateUTF8("myPropertyName"); 203 JSPropertyListAdd(propertyList, object, propertyName); 204 JSInternalStringRelease(propertyName); 205 205 } 206 206 … … 303 303 JSObjectRef result = JSObjectMake(context, NULL, 0); 304 304 if (argc > 0) { 305 JSInternalStringRef value Buffer= JSInternalStringCreateUTF8("value");306 JSObjectSetProperty(context, result, value Buffer, argv[0], kJSPropertyAttributeNone);307 JSInternalStringRelease(value Buffer);305 JSInternalStringRef value = JSInternalStringCreateUTF8("value"); 306 JSObjectSetProperty(context, result, value, argv[0], kJSPropertyAttributeNone); 307 JSInternalStringRelease(value); 308 308 } 309 309 … … 330 330 331 331 // FIXME: test funny utf8 characters 332 JSInternalStringRef jsEmpty StringBuf= JSInternalStringCreateUTF8("");333 JSValueRef jsEmptyString = JSStringMake(jsEmpty StringBuf);334 335 JSInternalStringRef jsOne StringBuf= JSInternalStringCreateUTF8("1");336 JSValueRef jsOneString = JSStringMake(jsOne StringBuf);332 JSInternalStringRef jsEmptyIString = JSInternalStringCreateUTF8(""); 333 JSValueRef jsEmptyString = JSStringMake(jsEmptyIString); 334 335 JSInternalStringRef jsOneIString = JSInternalStringCreateUTF8("1"); 336 JSValueRef jsOneString = JSStringMake(jsOneIString); 337 337 338 338 #if defined(__APPLE__) … … 345 345 kCFAllocatorNull); 346 346 347 JSInternalStringRef jsCF StringBuf= JSInternalStringCreateCF(cfString);348 JSValueRef jsCFString = JSStringMake(jsCF StringBuf);347 JSInternalStringRef jsCFIString = JSInternalStringCreateCF(cfString); 348 JSValueRef jsCFString = JSStringMake(jsCFIString); 349 349 350 350 CFStringRef cfEmptyString = CFStringCreateWithCString(kCFAllocatorDefault, "", kCFStringEncodingUTF8); 351 351 352 JSInternalStringRef jsCFEmpty StringBuf= JSInternalStringCreateCF(cfEmptyString);353 JSValueRef jsCFEmptyString = JSStringMake(jsCFEmpty StringBuf);352 JSInternalStringRef jsCFEmptyIString = JSInternalStringCreateCF(cfEmptyString); 353 JSValueRef jsCFEmptyString = JSStringMake(jsCFEmptyIString); 354 354 355 355 CFIndex cfStringLength = CFStringGetLength(cfString); … … 358 358 CFRangeMake(0, cfStringLength), 359 359 buffer); 360 JSInternalStringRef jsCF StringWithCharactersBuf= JSInternalStringCreate(buffer, cfStringLength);361 JSValueRef jsCFStringWithCharacters = JSStringMake(jsCF StringWithCharactersBuf);362 363 JSInternalStringRef jsCFEmpty StringWithCharactersBuf= JSInternalStringCreate(buffer, CFStringGetLength(cfEmptyString));364 JSValueRef jsCFEmptyStringWithCharacters = JSStringMake(jsCFEmpty StringWithCharactersBuf);360 JSInternalStringRef jsCFIStringWithCharacters = JSInternalStringCreate(buffer, cfStringLength); 361 JSValueRef jsCFStringWithCharacters = JSStringMake(jsCFIStringWithCharacters); 362 363 JSInternalStringRef jsCFEmptyIStringWithCharacters = JSInternalStringCreate(buffer, CFStringGetLength(cfEmptyString)); 364 JSValueRef jsCFEmptyStringWithCharacters = JSStringMake(jsCFEmptyIStringWithCharacters); 365 365 #endif // __APPLE__ 366 366 … … 474 474 475 475 #if defined(__APPLE__) 476 CFStringRef cfJSString = CFStringCreateWithJSInternalString(kCFAllocatorDefault, jsCF StringBuf);477 CFStringRef cfJSEmptyString = CFStringCreateWithJSInternalString(kCFAllocatorDefault, jsCFEmpty StringBuf);476 CFStringRef cfJSString = CFStringCreateWithJSInternalString(kCFAllocatorDefault, jsCFIString); 477 CFStringRef cfJSEmptyString = CFStringCreateWithJSInternalString(kCFAllocatorDefault, jsCFEmptyIString); 478 478 assert(CFEqual(cfJSString, cfString)); 479 479 assert(CFEqual(cfJSEmptyString, cfEmptyString)); … … 496 496 assert(JSValueIsObject(globalObject)); 497 497 498 JSInternalStringRef goodSyntax Buf= JSInternalStringCreateUTF8("x = 1;");499 JSInternalStringRef badSyntax Buf= JSInternalStringCreateUTF8("x := 1;");500 assert(JSCheckSyntax(context, goodSyntax Buf, NULL, 0, NULL));501 assert(!JSCheckSyntax(context, badSyntax Buf, NULL, 0, NULL));498 JSInternalStringRef goodSyntax = JSInternalStringCreateUTF8("x = 1;"); 499 JSInternalStringRef badSyntax = JSInternalStringCreateUTF8("x := 1;"); 500 assert(JSCheckSyntax(context, goodSyntax, NULL, 0, NULL)); 501 assert(!JSCheckSyntax(context, badSyntax, NULL, 0, NULL)); 502 502 503 503 JSValueRef result; … … 506 506 JSObjectRef o; 507 507 508 result = JSEvaluate(context, goodSyntax Buf, NULL, NULL, 1, NULL);508 result = JSEvaluate(context, goodSyntax, NULL, NULL, 1, NULL); 509 509 assert(result); 510 510 assert(JSValueIsEqual(context, result, jsOne)); 511 511 512 512 exception = NULL; 513 result = JSEvaluate(context, badSyntax Buf, NULL, NULL, 1, &exception);513 result = JSEvaluate(context, badSyntax, NULL, NULL, 1, &exception); 514 514 assert(!result); 515 515 assert(JSValueIsObject(exception)); 516 516 517 JSInternalStringRelease(jsEmptyStringBuf); 518 JSInternalStringRelease(jsOneStringBuf); 519 #if defined(__APPLE__) 520 JSInternalStringRelease(jsCFStringBuf); 521 JSInternalStringRelease(jsCFEmptyStringBuf); 522 JSInternalStringRelease(jsCFStringWithCharactersBuf); 523 JSInternalStringRelease(jsCFEmptyStringWithCharactersBuf); 524 #endif // __APPLE__ 525 JSInternalStringRelease(goodSyntaxBuf); 526 JSInternalStringRelease(badSyntaxBuf); 527 528 JSInternalStringRef arrayBuf = JSInternalStringCreateUTF8("Array"); 529 v = JSObjectGetProperty(context, globalObject, arrayBuf); 517 JSInternalStringRef array = JSInternalStringCreateUTF8("Array"); 518 v = JSObjectGetProperty(context, globalObject, array); 530 519 assert(v); 531 520 JSObjectRef arrayConstructor = JSValueToObject(context, v); 532 JSInternalStringRelease(array Buf);521 JSInternalStringRelease(array); 533 522 result = JSObjectCallAsConstructor(context, arrayConstructor, 0, NULL, NULL); 534 523 assert(result); … … 536 525 assert(!JSValueIsInstanceOf(context, JSNullMake(), arrayConstructor)); 537 526 538 JSInternalStringRef functionB uf;527 JSInternalStringRef functionBody; 539 528 540 529 exception = NULL; 541 functionB uf= JSInternalStringCreateUTF8("rreturn Array;");542 JSInternalStringRef line Buf= JSInternalStringCreateUTF8("line");543 assert(!JSFunctionMakeWithBody(context, functionB uf, NULL, 1, &exception));530 functionBody = JSInternalStringCreateUTF8("rreturn Array;"); 531 JSInternalStringRef line = JSInternalStringCreateUTF8("line"); 532 assert(!JSFunctionMakeWithBody(context, functionBody, NULL, 1, &exception)); 544 533 assert(JSValueIsObject(exception)); 545 v = JSObjectGetProperty(context, JSValueToObject(context, exception), line Buf);534 v = JSObjectGetProperty(context, JSValueToObject(context, exception), line); 546 535 assert(v); 547 536 assertEqualsAsNumber(v, 2); // FIXME: Lexer::setCode bumps startingLineNumber by 1 -- we need to change internal callers so that it doesn't have to (saying '0' to mean '1' in the API would be really confusing -- it's really confusing internally, in fact) 548 JSInternalStringRelease(functionB uf);549 JSInternalStringRelease(line Buf);550 551 functionB uf= JSInternalStringCreateUTF8("return Array;");552 JSObjectRef function = JSFunctionMakeWithBody(context, functionB uf, NULL, 1, NULL);553 JSInternalStringRelease(functionB uf);537 JSInternalStringRelease(functionBody); 538 JSInternalStringRelease(line); 539 540 functionBody = JSInternalStringCreateUTF8("return Array;"); 541 JSObjectRef function = JSFunctionMakeWithBody(context, functionBody, NULL, 1, NULL); 542 JSInternalStringRelease(functionBody); 554 543 555 544 assert(JSObjectIsFunction(function)); … … 559 548 JSObjectRef myObject = JSObjectMake(context, MyObject_class(context), NULL); 560 549 assert(didInitialize); 561 JSInternalStringRef myObject Buf= JSInternalStringCreateUTF8("MyObject");562 JSObjectSetProperty(context, globalObject, myObject Buf, myObject, kJSPropertyAttributeNone);563 JSInternalStringRelease(myObject Buf);564 565 JSInternalStringRef print Buf= JSInternalStringCreateUTF8("print");550 JSInternalStringRef myObjectIString = JSInternalStringCreateUTF8("MyObject"); 551 JSObjectSetProperty(context, globalObject, myObjectIString, myObject, kJSPropertyAttributeNone); 552 JSInternalStringRelease(myObjectIString); 553 554 JSInternalStringRef print = JSInternalStringCreateUTF8("print"); 566 555 JSObjectRef printFunction = JSFunctionMake(context, print_callAsFunction); 567 JSObjectSetProperty(context, globalObject, print Buf, printFunction, kJSPropertyAttributeNone);568 JSInternalStringRelease(print Buf);556 JSObjectSetProperty(context, globalObject, print, printFunction, kJSPropertyAttributeNone); 557 JSInternalStringRelease(print); 569 558 570 559 assert(JSObjectSetPrivate(printFunction, (void*)1)); 571 560 assert(JSObjectGetPrivate(printFunction) == (void*)1); 572 561 573 JSInternalStringRef myConstructor Buf= JSInternalStringCreateUTF8("MyConstructor");562 JSInternalStringRef myConstructorIString = JSInternalStringCreateUTF8("MyConstructor"); 574 563 JSObjectRef myConstructor = JSConstructorMake(context, myConstructor_callAsConstructor); 575 JSObjectSetProperty(context, globalObject, myConstructor Buf, myConstructor, kJSPropertyAttributeNone);576 JSInternalStringRelease(myConstructor Buf);564 JSObjectSetProperty(context, globalObject, myConstructorIString, myConstructor, kJSPropertyAttributeNone); 565 JSInternalStringRelease(myConstructorIString); 577 566 578 567 assert(JSObjectSetPrivate(myConstructor, (void*)1)); … … 580 569 581 570 o = JSObjectMake(context, NULL, NULL); 582 JSObjectSetProperty(context, o, jsOne StringBuf, JSNumberMake(1), kJSPropertyAttributeNone);583 JSObjectSetProperty(context, o, jsCF StringBuf, JSNumberMake(1), kJSPropertyAttributeDontEnum);571 JSObjectSetProperty(context, o, jsOneIString, JSNumberMake(1), kJSPropertyAttributeNone); 572 JSObjectSetProperty(context, o, jsCFIString, JSNumberMake(1), kJSPropertyAttributeDontEnum); 584 573 JSPropertyEnumeratorRef enumerator = JSObjectCreatePropertyEnumerator(context, o); 585 574 int count = 0; … … 592 581 JSClassRelease(nullCallbacksClass); 593 582 594 functionB uf= JSInternalStringCreateUTF8("return this;");595 function = JSFunctionMakeWithBody(context, functionB uf, NULL, 1, NULL);596 JSInternalStringRelease(functionB uf);583 functionBody = JSInternalStringCreateUTF8("return this;"); 584 function = JSFunctionMakeWithBody(context, functionBody, NULL, 1, NULL); 585 JSInternalStringRelease(functionBody); 597 586 v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL); 598 587 assert(JSValueIsEqual(context, v, globalObject)); … … 600 589 assert(JSValueIsEqual(context, v, o)); 601 590 602 char* script = createStringWithContentsOfFile("testapi.js");603 JSInternalStringRef script Buf = JSInternalStringCreateUTF8(script);604 result = JSEvaluate(context, script Buf, NULL, NULL, 1, &exception);591 char* scriptUTF8 = createStringWithContentsOfFile("testapi.js"); 592 JSInternalStringRef script = JSInternalStringCreateUTF8(scriptUTF8); 593 result = JSEvaluate(context, script, NULL, NULL, 1, &exception); 605 594 if (JSValueIsUndefined(result)) 606 595 printf("PASS: Test script executed successfully.\n"); 607 596 else { 608 597 printf("FAIL: Test script returned unexcpected value:\n"); 609 JSInternalStringRef exception Buf= JSValueCopyStringValue(context, exception);610 CFStringRef exceptionCF = CFStringCreateWithJSInternalString(kCFAllocatorDefault, exception Buf);598 JSInternalStringRef exceptionIString = JSValueCopyStringValue(context, exception); 599 CFStringRef exceptionCF = CFStringCreateWithJSInternalString(kCFAllocatorDefault, exceptionIString); 611 600 CFShow(exceptionCF); 612 601 CFRelease(exceptionCF); 613 JSInternalStringRelease(exception Buf);614 } 615 JSInternalStringRelease(script Buf);616 free(script );602 JSInternalStringRelease(exceptionIString); 603 } 604 JSInternalStringRelease(script); 605 free(scriptUTF8); 617 606 618 607 // Allocate a few dummies so that at least one will be collected … … 622 611 assert(didFinalize); 623 612 613 JSInternalStringRelease(jsEmptyIString); 614 JSInternalStringRelease(jsOneIString); 615 #if defined(__APPLE__) 616 JSInternalStringRelease(jsCFIString); 617 JSInternalStringRelease(jsCFEmptyIString); 618 JSInternalStringRelease(jsCFIStringWithCharacters); 619 JSInternalStringRelease(jsCFEmptyIStringWithCharacters); 620 #endif // __APPLE__ 621 JSInternalStringRelease(goodSyntax); 622 JSInternalStringRelease(badSyntax); 623 624 624 JSContextDestroy(context); 625 625 printf("PASS: Program exited normally.\n"); -
trunk/JavaScriptCore/ChangeLog
r15325 r15328 1 2006-07-10 Geoffrey Garen <[email protected]> 2 3 Reviewed by Darin. 4 5 - Changed public header includes to the <JavaScriptCore/ style. 6 - Changed instances of 'buffer' to 'string' since we decided on 7 JSInternalString instead of JSStringBuffer. 8 9 * API/JSContextRef.h: 10 * API/JSInternalStringRef.cpp: 11 (JSStringMake): 12 (JSInternalStringRetain): 13 (JSInternalStringRelease): 14 (JSValueCopyStringValue): 15 (JSInternalStringGetLength): 16 (JSInternalStringGetCharactersPtr): 17 (JSInternalStringGetCharacters): 18 (JSInternalStringGetMaxLengthUTF8): 19 (JSInternalStringGetCharactersUTF8): 20 (CFStringCreateWithJSInternalString): 21 * API/JSInternalStringRef.h: 22 * API/JSNode.c: 23 (JSNodePrototype_appendChild): 24 (JSNode_getNodeType): 25 * API/JSObjectRef.cpp: 26 (JSObjectCallAsConstructor): 27 * API/JSValueRef.h: 28 * API/JavaScriptCore.h: 29 * API/minidom.c: 30 (main): 31 (print): 32 * API/testapi.c: 33 (MyObject_getPropertyList): 34 (myConstructor_callAsConstructor): 35 (main): I noticed that we were prematurely releasing some string buffers, 36 so I moved their release calls to the end of main(). I got rid of 'Buf' in *Buf 37 (sometimes changing to 'IString', when necessary to differentiate a variable) 38 to match the buffer->string change. 39 1 40 === Safari-521.16 === 2 41
Note:
See TracChangeset
for help on using the changeset viewer.