Changeset 15328 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Jul 10, 2006, 10:37:00 PM (19 years ago)
Author:
ggaren
Message:

Reviewed by Darin.


  • Changed public header includes to the <JavaScriptCore/ style.
  • Changed instances of 'buffer' to 'string' since we decided on JSInternalString instead of JSStringBuffer.
  • API/JSContextRef.h:
  • API/JSInternalStringRef.cpp: (JSStringMake): (JSInternalStringRetain): (JSInternalStringRelease): (JSValueCopyStringValue): (JSInternalStringGetLength): (JSInternalStringGetCharactersPtr): (JSInternalStringGetCharacters): (JSInternalStringGetMaxLengthUTF8): (JSInternalStringGetCharactersUTF8): (CFStringCreateWithJSInternalString):
  • API/JSInternalStringRef.h:
  • API/JSNode.c: (JSNodePrototype_appendChild): (JSNode_getNodeType):
  • API/JSObjectRef.cpp: (JSObjectCallAsConstructor):
  • API/JSValueRef.h:
  • API/JavaScriptCore.h:
  • API/minidom.c: (main): (print):
  • API/testapi.c: (MyObject_getPropertyList): (myConstructor_callAsConstructor): (main): I noticed that we were prematurely releasing some string buffers, so I moved their release calls to the end of main(). I got rid of 'Buf' in *Buf (sometimes changing to 'IString', when necessary to differentiate a variable) to match the buffer->string change.
Location:
trunk/JavaScriptCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSContextRef.h

    r15317 r15328  
    2828#define JSContextRef_h
    2929
    30 #include "JSObjectRef.h"
    31 #include "JSValueRef.h"
     30#include <JavaScriptCore/JSObjectRef.h>
     31#include <JavaScriptCore/JSValueRef.h>
    3232
    3333#ifdef __cplusplus
  • trunk/JavaScriptCore/API/JSInternalStringRef.cpp

    r15307 r15328  
    3737using namespace KJS;
    3838
    39 JSValueRef JSStringMake(JSInternalStringRef buffer)
     39JSValueRef JSStringMake(JSInternalStringRef string)
    4040{
    4141    JSLock lock;
    42     UString::Rep* rep = toJS(buffer);
     42    UString::Rep* rep = toJS(string);
    4343    return toRef(jsString(UString(rep)));
    4444}
     
    5858}
    5959
    60 JSInternalStringRef JSInternalStringRetain(JSInternalStringRef buffer)
     60JSInternalStringRef JSInternalStringRetain(JSInternalStringRef string)
    6161{
    62     UString::Rep* rep = toJS(buffer);
     62    UString::Rep* rep = toJS(string);
    6363    return toRef(rep->ref());
    6464}
    6565
    66 void JSInternalStringRelease(JSInternalStringRef buffer)
     66void JSInternalStringRelease(JSInternalStringRef string)
    6767{
    6868    JSLock lock;
    69     UString::Rep* rep = toJS(buffer);
     69    UString::Rep* rep = toJS(string);
    7070    rep->deref();
    7171}
     
    7777    ExecState* exec = toJS(context);
    7878
    79     JSInternalStringRef charBufferRef = toRef(jsValue->toString(exec).rep()->ref());
     79    JSInternalStringRef stringRef = toRef(jsValue->toString(exec).rep()->ref());
    8080    if (exec->hadException())
    8181        exec->clearException();
    82     return charBufferRef;
     82    return stringRef;
    8383}
    8484
    85 size_t JSInternalStringGetLength(JSInternalStringRef buffer)
     85size_t JSInternalStringGetLength(JSInternalStringRef string)
    8686{
    87     UString::Rep* rep = toJS(buffer);
     87    UString::Rep* rep = toJS(string);
    8888    return rep->size();
    8989}
    9090
    91 const JSChar* JSInternalStringGetCharactersPtr(JSInternalStringRef buffer)
     91const JSChar* JSInternalStringGetCharactersPtr(JSInternalStringRef string)
    9292{
    93     UString::Rep* rep = toJS(buffer);
     93    UString::Rep* rep = toJS(string);
    9494    return reinterpret_cast<const JSChar*>(rep->data());
    9595}
    9696
    97 void JSInternalStringGetCharacters(JSInternalStringRef inBuffer, JSChar* outBuffer, size_t numChars)
     97void JSInternalStringGetCharacters(JSInternalStringRef string, JSChar* buffer, size_t numChars)
    9898{
    99     UString::Rep* rep = toJS(inBuffer);
     99    UString::Rep* rep = toJS(string);
    100100    const JSChar* data = reinterpret_cast<const JSChar*>(rep->data());
    101101   
    102     memcpy(outBuffer, data, numChars * sizeof(JSChar));
     102    memcpy(buffer, data, numChars * sizeof(JSChar));
    103103}
    104104
    105 size_t JSInternalStringGetMaxLengthUTF8(JSInternalStringRef buffer)
     105size_t JSInternalStringGetMaxLengthUTF8(JSInternalStringRef string)
    106106{
    107     UString::Rep* rep = toJS(buffer);
     107    UString::Rep* rep = toJS(string);
    108108   
    109109    // Any UTF8 character > 3 bytes encodes as a UTF16 surrogate pair.
     
    111111}
    112112
    113 size_t JSInternalStringGetCharactersUTF8(JSInternalStringRef inBuffer, char* outBuffer, size_t bufferSize)
     113size_t JSInternalStringGetCharactersUTF8(JSInternalStringRef string, char* buffer, size_t bufferSize)
    114114{
    115115    JSLock lock;
    116     UString::Rep* rep = toJS(inBuffer);
     116    UString::Rep* rep = toJS(string);
    117117    CString cString = UString(rep).UTF8String();
    118118
    119119    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);
    121121    return length;
    122122}
     
    157157}
    158158
    159 CFStringRef CFStringCreateWithJSInternalString(CFAllocatorRef alloc, JSInternalStringRef buffer)
     159CFStringRef CFStringCreateWithJSInternalString(CFAllocatorRef alloc, JSInternalStringRef string)
    160160{
    161     UString::Rep* rep = toJS(buffer);
     161    UString::Rep* rep = toJS(string);
    162162    return CFStringCreateWithCharacters(alloc, reinterpret_cast<const JSChar*>(rep->data()), rep->size());
    163163}
  • trunk/JavaScriptCore/API/JSInternalStringRef.h

    r15307 r15328  
    2828#define JSInternalStringRef_h
    2929
    30 #include "JSValueRef.h"
     30#include <JavaScriptCore/JSValueRef.h>
    3131#ifdef __cplusplus
    3232extern "C" {
     
    6262@function
    6363@abstract         Retains a JavaScript string.
    64 @param buffer     The JSInternalString to retain.
     64@param string     The JSInternalString to retain.
    6565@result           A JSInternalString that is the same as buffer.
    6666*/
    67 JSInternalStringRef JSInternalStringRetain(JSInternalStringRef buffer);
     67JSInternalStringRef JSInternalStringRetain(JSInternalStringRef string);
    6868/*!
    6969@function
    7070@abstract         Releases a JavaScript string.
    71 @param buffer     The JSInternalString to release.
     71@param string     The JSInternalString to release.
    7272*/
    73 void JSInternalStringRelease(JSInternalStringRef buffer);
     73void JSInternalStringRelease(JSInternalStringRef string);
    7474
    7575/*!
    7676@function
    7777@abstract         Returns the number of Unicode characters in a JavaScript string.
    78 @param buffer     The 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.
    8080*/
    81 size_t JSInternalStringGetLength(JSInternalStringRef buffer);
     81size_t JSInternalStringGetLength(JSInternalStringRef string);
    8282/*!
    8383@function
    8484@abstract         Quickly obtains a pointer to the Unicode character buffer that
    8585 serves as the backing store for a JavaScript string.
    86 @param buffer     The JSInternalString whose backing store you want to access.
    87 @result           A pointer to the Unicode character buffer that serves as buffer's
    88  backing store, which will be deallocated when buffer is 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.
    8989*/
    90 const JSChar* JSInternalStringGetCharactersPtr(JSInternalStringRef buffer);
     90const JSChar* JSInternalStringGetCharactersPtr(JSInternalStringRef string);
    9191/*!
    9292@function
    9393@abstract         Copies a JavaScript string's Unicode characters into an
    9494 external character buffer.
    95 @param inBuffer   The source JSInternalString.
    96 @param outBuffer  The destination JSChar buffer into which to copy inBuffer's
    97  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.
    9898@param numChars   The number of Unicode characters to copy. This number must not
    9999 exceed the length of the string.
    100100*/
    101 void JSInternalStringGetCharacters(JSInternalStringRef inBuffer, JSChar* outBuffer, size_t numChars);
     101void JSInternalStringGetCharacters(JSInternalStringRef string, JSChar* buffer, size_t numChars);
    102102
    103103/*!
     
    105105@abstract         Returns the maximum number of bytes required to encode the
    106106 contents of a JavaScript string as a null-terminated UTF8 string.
    107 @param buffer     The JSInternalString whose maximum encoded length (in bytes) you
     107@param string     The JSInternalString whose maximum encoded length (in bytes) you
    108108 want to know.
    109 @result           The maximum number of bytes required to encode buffer's contents
     109@result           The maximum number of bytes required to encode string's contents
    110110 as a null-terminated UTF8 string.
    111111*/
    112 size_t JSInternalStringGetMaxLengthUTF8(JSInternalStringRef buffer);
     112size_t JSInternalStringGetMaxLengthUTF8(JSInternalStringRef string);
    113113/*!
    114114@function
    115115@abstract         Converts a JavaScript string's contents into a
    116116 null-terminated UTF8 string, and copies the result into an external byte buffer.
    117 @param inBuffer   The source JSInternalString.
    118 @param outBuffer  The destination byte buffer into which to copy a UTF8 string
    119  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.
    122122@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).
    124124*/
    125 size_t JSInternalStringGetCharactersUTF8(JSInternalStringRef inBuffer, char* outBuffer, size_t bufferSize);
     125size_t JSInternalStringGetCharactersUTF8(JSInternalStringRef string, char* buffer, size_t bufferSize);
    126126
    127127/*!
     
    130130@param a      The first JSInternalString to test.
    131131@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.
    133133*/
    134134bool JSInternalStringIsEqual(JSInternalStringRef a, JSInternalStringRef b);
     
    139139@param a      The JSInternalString to test.
    140140@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.
    142142*/
    143143bool JSInternalStringIsEqualUTF8(JSInternalStringRef a, const char* b);
     
    159159@abstract         Creates a CFString form a JavaScript string.
    160160@param alloc      The alloc parameter to pass to CFStringCreate.
    161 @param buffer     The 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.
    163163*/
    164 CFStringRef CFStringCreateWithJSInternalString(CFAllocatorRef alloc, JSInternalStringRef buffer);
     164CFStringRef CFStringCreateWithJSInternalString(CFAllocatorRef alloc, JSInternalStringRef string);
    165165#endif // __APPLE__
    166166   
  • trunk/JavaScriptCore/API/JSNode.c

    r15317 r15328  
    4040    // Example of throwing a type error for invalid values
    4141    if (!JSValueIsObjectOfClass(thisObject, JSNode_class(context))) {
    42         JSInternalStringRef messageBuf = JSInternalStringCreateUTF8("TypeError: appendChild can only be called on nodes");
    43         *exception = JSStringMake(messageBuf);
    44         JSInternalStringRelease(messageBuf);
     42        JSInternalStringRef message = JSInternalStringCreateUTF8("TypeError: appendChild can only be called on nodes");
     43        *exception = JSStringMake(message);
     44        JSInternalStringRelease(message);
    4545    } else if (argc < 1 || !JSValueIsObjectOfClass(argv[0], JSNode_class(context))) {
    46         JSInternalStringRef messageBuf = JSInternalStringCreateUTF8("TypeError: first argument to appendChild must be a node");
    47         *exception = JSStringMake(messageBuf);
    48         JSInternalStringRelease(messageBuf);
     46        JSInternalStringRef message = JSInternalStringCreateUTF8("TypeError: first argument to appendChild must be a node");
     47        *exception = JSStringMake(message);
     48        JSInternalStringRelease(message);
    4949    } else {
    5050        Node* node = JSObjectGetPrivate(thisObject);
     
    121121    Node* node = JSObjectGetPrivate(object);
    122122    if (node) {
    123         JSInternalStringRef nodeBuf = JSInternalStringCreateUTF8(node->nodeType);
    124         *returnValue = JSStringMake(nodeBuf);
    125         JSInternalStringRelease(nodeBuf);
     123        JSInternalStringRef nodeType = JSInternalStringCreateUTF8(node->nodeType);
     124        *returnValue = JSStringMake(nodeType);
     125        JSInternalStringRelease(nodeType);
    126126        return true;
    127127    }
  • trunk/JavaScriptCore/API/JSObjectRef.h

    r15317 r15328  
    2828#define JSObjectRef_h
    2929
    30 #include "JSBase.h"
    31 #include "JSValueRef.h"
     30#include <JavaScriptCore/JSBase.h>
     31#include <JavaScriptCore/JSValueRef.h>
    3232
    3333#ifdef __cplusplus
     
    269269@struct JSStaticValue
    270270@abstract This structure describes a static value property.
    271 @field name A UTF8 buffer containing the property's name.
     271@field name A null-terminated UTF8 string containing the property's name.
    272272@field getProperty A JSGetPropertyCallback to invoke when getting the property's value.
    273273@field setProperty A JSSetPropertyCallback to invoke when setting the property's value.
     
    284284@struct JSStaticFunction
    285285@abstract This structure describes a static function property.
    286 @field name A UTF8 buffer containing the property's name.
     286@field name A null-terminated UTF8 string containing the property's name.
    287287@field callAsFunction A JSCallAsFunctionCallback to invoke when the property is called as a function.
    288288@field attributes A logically ORed set of JSPropertyAttributes to give to the property.
  • trunk/JavaScriptCore/API/JSValueRef.h

    r15307 r15328  
    2828#define JSValueRef_h
    2929
    30 #include "JSBase.h"
     30#include <JavaScriptCore/JSBase.h>
    3131
    3232/*!
     
    189189@function
    190190@abstract       Creates a JavaScript value of the string type.
    191 @param buffer   The JSInternalString to assign to the newly created JSValue. The
    192  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*/
     195JSValueRef JSStringMake(JSInternalStringRef string);
    196196
    197197// Converting to primitive values
  • trunk/JavaScriptCore/API/JavaScriptCore.h

    r15307 r15328  
    3131#include <stddef.h> // for size_t
    3232
    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>
    3838
    3939#endif // JavaScriptCore_h
  • trunk/JavaScriptCore/API/minidom.c

    r15317 r15328  
    4040    JSObjectRef globalObject = JSContextGetGlobalObject(context);
    4141   
    42     JSInternalStringRef printBuf = JSInternalStringCreateUTF8("print");
    43     JSObjectSetProperty(context, globalObject, printBuf, JSFunctionMake(context, print), kJSPropertyAttributeNone);
    44     JSInternalStringRelease(printBuf);
     42    JSInternalStringRef printIString = JSInternalStringCreateUTF8("print");
     43    JSObjectSetProperty(context, globalObject, printIString, JSFunctionMake(context, print), kJSPropertyAttributeNone);
     44    JSInternalStringRelease(printIString);
    4545   
    46     JSInternalStringRef nodeBuf = JSInternalStringCreateUTF8("Node");
    47     JSObjectSetProperty(context, globalObject, nodeBuf, JSConstructorMake(context, JSNode_construct), kJSPropertyAttributeNone);
    48     JSInternalStringRelease(nodeBuf);
     46    JSInternalStringRef node = JSInternalStringCreateUTF8("Node");
     47    JSObjectSetProperty(context, globalObject, node, JSConstructorMake(context, JSNode_construct), kJSPropertyAttributeNone);
     48    JSInternalStringRelease(node);
    4949   
    50     char* script = createStringWithContentsOfFile("minidom.js");
    51     JSInternalStringRef scriptBuf = JSInternalStringCreateUTF8(script);
     50    char* scriptUTF8 = createStringWithContentsOfFile("minidom.js");
     51    JSInternalStringRef script = JSInternalStringCreateUTF8(scriptUTF8);
    5252    JSValueRef exception;
    53     JSValueRef result = JSEvaluate(context, scriptBuf, NULL, NULL, 0, &exception);
     53    JSValueRef result = JSEvaluate(context, script, NULL, NULL, 0, &exception);
    5454    if (result)
    5555        printf("PASS: Test script executed successfully.\n");
    5656    else {
    5757        printf("FAIL: Test script threw exception:\n");
    58         JSInternalStringRef exceptionBuf = JSValueCopyStringValue(context, exception);
    59         CFStringRef exceptionCF = CFStringCreateWithJSInternalString(kCFAllocatorDefault, exceptionBuf);
     58        JSInternalStringRef exceptionIString = JSValueCopyStringValue(context, exception);
     59        CFStringRef exceptionCF = CFStringCreateWithJSInternalString(kCFAllocatorDefault, exceptionIString);
    6060        CFShow(exceptionCF);
    6161        CFRelease(exceptionCF);
    62         JSInternalStringRelease(exceptionBuf);
     62        JSInternalStringRelease(exceptionIString);
    6363    }
    64     JSInternalStringRelease(scriptBuf);
    65     free(script);
     64    JSInternalStringRelease(script);
     65    free(scriptUTF8);
    6666
    6767#if 0 // used for leak/finalize debugging   
     
    8282{
    8383    if (argc > 0) {
    84         JSInternalStringRef stringBuf = JSValueCopyStringValue(context, argv[0]);
    85         size_t numChars = JSInternalStringGetMaxLengthUTF8(stringBuf);
    86         char string[numChars];
    87         JSInternalStringGetCharactersUTF8(stringBuf, 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);
    8989    }
    9090   
  • trunk/JavaScriptCore/API/testapi.c

    r15317 r15328  
    194194    UNUSED_PARAM(context);
    195195   
    196     JSInternalStringRef propertyNameBuf;
    197    
    198     propertyNameBuf = JSInternalStringCreateUTF8("alwaysOne");
    199     JSPropertyListAdd(propertyList, object, propertyNameBuf);
    200     JSInternalStringRelease(propertyNameBuf);
    201    
    202     propertyNameBuf = JSInternalStringCreateUTF8("myPropertyName");
    203     JSPropertyListAdd(propertyList, object, propertyNameBuf);
    204     JSInternalStringRelease(propertyNameBuf);
     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);
    205205}
    206206
     
    303303    JSObjectRef result = JSObjectMake(context, NULL, 0);
    304304    if (argc > 0) {
    305         JSInternalStringRef valueBuffer = JSInternalStringCreateUTF8("value");
    306         JSObjectSetProperty(context, result, valueBuffer, argv[0], kJSPropertyAttributeNone);
    307         JSInternalStringRelease(valueBuffer);
     305        JSInternalStringRef value = JSInternalStringCreateUTF8("value");
     306        JSObjectSetProperty(context, result, value, argv[0], kJSPropertyAttributeNone);
     307        JSInternalStringRelease(value);
    308308    }
    309309   
     
    330330
    331331    // FIXME: test funny utf8 characters
    332     JSInternalStringRef jsEmptyStringBuf = JSInternalStringCreateUTF8("");
    333     JSValueRef jsEmptyString = JSStringMake(jsEmptyStringBuf);
    334    
    335     JSInternalStringRef jsOneStringBuf = JSInternalStringCreateUTF8("1");
    336     JSValueRef jsOneString = JSStringMake(jsOneStringBuf);
     332    JSInternalStringRef jsEmptyIString = JSInternalStringCreateUTF8("");
     333    JSValueRef jsEmptyString = JSStringMake(jsEmptyIString);
     334   
     335    JSInternalStringRef jsOneIString = JSInternalStringCreateUTF8("1");
     336    JSValueRef jsOneString = JSStringMake(jsOneIString);
    337337
    338338#if defined(__APPLE__)
     
    345345                                                          kCFAllocatorNull);
    346346
    347     JSInternalStringRef jsCFStringBuf = JSInternalStringCreateCF(cfString);
    348     JSValueRef jsCFString = JSStringMake(jsCFStringBuf);
     347    JSInternalStringRef jsCFIString = JSInternalStringCreateCF(cfString);
     348    JSValueRef jsCFString = JSStringMake(jsCFIString);
    349349   
    350350    CFStringRef cfEmptyString = CFStringCreateWithCString(kCFAllocatorDefault, "", kCFStringEncodingUTF8);
    351351   
    352     JSInternalStringRef jsCFEmptyStringBuf = JSInternalStringCreateCF(cfEmptyString);
    353     JSValueRef jsCFEmptyString = JSStringMake(jsCFEmptyStringBuf);
     352    JSInternalStringRef jsCFEmptyIString = JSInternalStringCreateCF(cfEmptyString);
     353    JSValueRef jsCFEmptyString = JSStringMake(jsCFEmptyIString);
    354354
    355355    CFIndex cfStringLength = CFStringGetLength(cfString);
     
    358358                          CFRangeMake(0, cfStringLength),
    359359                          buffer);
    360     JSInternalStringRef jsCFStringWithCharactersBuf = JSInternalStringCreate(buffer, cfStringLength);
    361     JSValueRef jsCFStringWithCharacters = JSStringMake(jsCFStringWithCharactersBuf);
    362    
    363     JSInternalStringRef jsCFEmptyStringWithCharactersBuf = JSInternalStringCreate(buffer, CFStringGetLength(cfEmptyString));
    364     JSValueRef jsCFEmptyStringWithCharacters = JSStringMake(jsCFEmptyStringWithCharactersBuf);
     360    JSInternalStringRef jsCFIStringWithCharacters = JSInternalStringCreate(buffer, cfStringLength);
     361    JSValueRef jsCFStringWithCharacters = JSStringMake(jsCFIStringWithCharacters);
     362   
     363    JSInternalStringRef jsCFEmptyIStringWithCharacters = JSInternalStringCreate(buffer, CFStringGetLength(cfEmptyString));
     364    JSValueRef jsCFEmptyStringWithCharacters = JSStringMake(jsCFEmptyIStringWithCharacters);
    365365#endif // __APPLE__
    366366
     
    474474   
    475475#if defined(__APPLE__)
    476     CFStringRef cfJSString = CFStringCreateWithJSInternalString(kCFAllocatorDefault, jsCFStringBuf);
    477     CFStringRef cfJSEmptyString = CFStringCreateWithJSInternalString(kCFAllocatorDefault, jsCFEmptyStringBuf);
     476    CFStringRef cfJSString = CFStringCreateWithJSInternalString(kCFAllocatorDefault, jsCFIString);
     477    CFStringRef cfJSEmptyString = CFStringCreateWithJSInternalString(kCFAllocatorDefault, jsCFEmptyIString);
    478478    assert(CFEqual(cfJSString, cfString));
    479479    assert(CFEqual(cfJSEmptyString, cfEmptyString));
     
    496496    assert(JSValueIsObject(globalObject));
    497497
    498     JSInternalStringRef goodSyntaxBuf = JSInternalStringCreateUTF8("x = 1;");
    499     JSInternalStringRef badSyntaxBuf = JSInternalStringCreateUTF8("x := 1;");
    500     assert(JSCheckSyntax(context, goodSyntaxBuf, NULL, 0, NULL));
    501     assert(!JSCheckSyntax(context, badSyntaxBuf, 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));
    502502
    503503    JSValueRef result;
     
    506506    JSObjectRef o;
    507507
    508     result = JSEvaluate(context, goodSyntaxBuf, NULL, NULL, 1, NULL);
     508    result = JSEvaluate(context, goodSyntax, NULL, NULL, 1, NULL);
    509509    assert(result);
    510510    assert(JSValueIsEqual(context, result, jsOne));
    511511
    512512    exception = NULL;
    513     result = JSEvaluate(context, badSyntaxBuf, NULL, NULL, 1, &exception);
     513    result = JSEvaluate(context, badSyntax, NULL, NULL, 1, &exception);
    514514    assert(!result);
    515515    assert(JSValueIsObject(exception));
    516516   
    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);
    530519    assert(v);
    531520    JSObjectRef arrayConstructor = JSValueToObject(context, v);
    532     JSInternalStringRelease(arrayBuf);
     521    JSInternalStringRelease(array);
    533522    result = JSObjectCallAsConstructor(context, arrayConstructor, 0, NULL, NULL);
    534523    assert(result);
     
    536525    assert(!JSValueIsInstanceOf(context, JSNullMake(), arrayConstructor));
    537526   
    538     JSInternalStringRef functionBuf;
     527    JSInternalStringRef functionBody;
    539528   
    540529    exception = NULL;
    541     functionBuf = JSInternalStringCreateUTF8("rreturn Array;");
    542     JSInternalStringRef lineBuf = JSInternalStringCreateUTF8("line");
    543     assert(!JSFunctionMakeWithBody(context, functionBuf, NULL, 1, &exception));
     530    functionBody = JSInternalStringCreateUTF8("rreturn Array;");
     531    JSInternalStringRef line = JSInternalStringCreateUTF8("line");
     532    assert(!JSFunctionMakeWithBody(context, functionBody, NULL, 1, &exception));
    544533    assert(JSValueIsObject(exception));
    545     v = JSObjectGetProperty(context, JSValueToObject(context, exception), lineBuf);
     534    v = JSObjectGetProperty(context, JSValueToObject(context, exception), line);
    546535    assert(v);
    547536    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(functionBuf);
    549     JSInternalStringRelease(lineBuf);
    550 
    551     functionBuf = JSInternalStringCreateUTF8("return Array;");
    552     JSObjectRef function = JSFunctionMakeWithBody(context, functionBuf, NULL, 1, NULL);
    553     JSInternalStringRelease(functionBuf);
     537    JSInternalStringRelease(functionBody);
     538    JSInternalStringRelease(line);
     539
     540    functionBody = JSInternalStringCreateUTF8("return Array;");
     541    JSObjectRef function = JSFunctionMakeWithBody(context, functionBody, NULL, 1, NULL);
     542    JSInternalStringRelease(functionBody);
    554543
    555544    assert(JSObjectIsFunction(function));
     
    559548    JSObjectRef myObject = JSObjectMake(context, MyObject_class(context), NULL);
    560549    assert(didInitialize);
    561     JSInternalStringRef myObjectBuf = JSInternalStringCreateUTF8("MyObject");
    562     JSObjectSetProperty(context, globalObject, myObjectBuf, myObject, kJSPropertyAttributeNone);
    563     JSInternalStringRelease(myObjectBuf);
    564 
    565     JSInternalStringRef printBuf = JSInternalStringCreateUTF8("print");
     550    JSInternalStringRef myObjectIString = JSInternalStringCreateUTF8("MyObject");
     551    JSObjectSetProperty(context, globalObject, myObjectIString, myObject, kJSPropertyAttributeNone);
     552    JSInternalStringRelease(myObjectIString);
     553
     554    JSInternalStringRef print = JSInternalStringCreateUTF8("print");
    566555    JSObjectRef printFunction = JSFunctionMake(context, print_callAsFunction);
    567     JSObjectSetProperty(context, globalObject, printBuf, printFunction, kJSPropertyAttributeNone);
    568     JSInternalStringRelease(printBuf);
     556    JSObjectSetProperty(context, globalObject, print, printFunction, kJSPropertyAttributeNone);
     557    JSInternalStringRelease(print);
    569558   
    570559    assert(JSObjectSetPrivate(printFunction, (void*)1));
    571560    assert(JSObjectGetPrivate(printFunction) == (void*)1);
    572561
    573     JSInternalStringRef myConstructorBuf = JSInternalStringCreateUTF8("MyConstructor");
     562    JSInternalStringRef myConstructorIString = JSInternalStringCreateUTF8("MyConstructor");
    574563    JSObjectRef myConstructor = JSConstructorMake(context, myConstructor_callAsConstructor);
    575     JSObjectSetProperty(context, globalObject, myConstructorBuf, myConstructor, kJSPropertyAttributeNone);
    576     JSInternalStringRelease(myConstructorBuf);
     564    JSObjectSetProperty(context, globalObject, myConstructorIString, myConstructor, kJSPropertyAttributeNone);
     565    JSInternalStringRelease(myConstructorIString);
    577566   
    578567    assert(JSObjectSetPrivate(myConstructor, (void*)1));
     
    580569   
    581570    o = JSObjectMake(context, NULL, NULL);
    582     JSObjectSetProperty(context, o, jsOneStringBuf, JSNumberMake(1), kJSPropertyAttributeNone);
    583     JSObjectSetProperty(context, o, jsCFStringBuf,  JSNumberMake(1), kJSPropertyAttributeDontEnum);
     571    JSObjectSetProperty(context, o, jsOneIString, JSNumberMake(1), kJSPropertyAttributeNone);
     572    JSObjectSetProperty(context, o, jsCFIString,  JSNumberMake(1), kJSPropertyAttributeDontEnum);
    584573    JSPropertyEnumeratorRef enumerator = JSObjectCreatePropertyEnumerator(context, o);
    585574    int count = 0;
     
    592581    JSClassRelease(nullCallbacksClass);
    593582   
    594     functionBuf = JSInternalStringCreateUTF8("return this;");
    595     function = JSFunctionMakeWithBody(context, functionBuf, NULL, 1, NULL);
    596     JSInternalStringRelease(functionBuf);
     583    functionBody = JSInternalStringCreateUTF8("return this;");
     584    function = JSFunctionMakeWithBody(context, functionBody, NULL, 1, NULL);
     585    JSInternalStringRelease(functionBody);
    597586    v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL);
    598587    assert(JSValueIsEqual(context, v, globalObject));
     
    600589    assert(JSValueIsEqual(context, v, o));
    601590   
    602     char* script = createStringWithContentsOfFile("testapi.js");
    603     JSInternalStringRef scriptBuf = JSInternalStringCreateUTF8(script);
    604     result = JSEvaluate(context, scriptBuf, NULL, NULL, 1, &exception);
     591    char* scriptUTF8 = createStringWithContentsOfFile("testapi.js");
     592    JSInternalStringRef script = JSInternalStringCreateUTF8(scriptUTF8);
     593    result = JSEvaluate(context, script, NULL, NULL, 1, &exception);
    605594    if (JSValueIsUndefined(result))
    606595        printf("PASS: Test script executed successfully.\n");
    607596    else {
    608597        printf("FAIL: Test script returned unexcpected value:\n");
    609         JSInternalStringRef exceptionBuf = JSValueCopyStringValue(context, exception);
    610         CFStringRef exceptionCF = CFStringCreateWithJSInternalString(kCFAllocatorDefault, exceptionBuf);
     598        JSInternalStringRef exceptionIString = JSValueCopyStringValue(context, exception);
     599        CFStringRef exceptionCF = CFStringCreateWithJSInternalString(kCFAllocatorDefault, exceptionIString);
    611600        CFShow(exceptionCF);
    612601        CFRelease(exceptionCF);
    613         JSInternalStringRelease(exceptionBuf);
    614     }
    615     JSInternalStringRelease(scriptBuf);
    616     free(script);
     602        JSInternalStringRelease(exceptionIString);
     603    }
     604    JSInternalStringRelease(script);
     605    free(scriptUTF8);
    617606
    618607    // Allocate a few dummies so that at least one will be collected
     
    622611    assert(didFinalize);
    623612
     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   
    624624    JSContextDestroy(context);
    625625    printf("PASS: Program exited normally.\n");
  • trunk/JavaScriptCore/ChangeLog

    r15325 r15328  
     12006-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
    140=== Safari-521.16 ===
    241
Note: See TracChangeset for help on using the changeset viewer.