Changeset 15376 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Jul 12, 2006, 1:12:08 AM (19 years ago)
Author:
ggaren
Message:

Reviewed by Maciej.


  • Implemented a vast number of renames and comment clarifications suggested during API review.


JSInternalString -> JSString
JS*Make -> JSValueMake*, JSObjectMake*
JSTypeCode -> JSType
JSValueIsInstanceOf -> JSValueIsInstanceOfConstructor (reads strangely well in client code)
JSGC*Protect -> JSValue*Protect
JS*Callback -> JSObject*Callback
JSGetPropertyListCallback -> JSObjectAddPropertiesToListCallback
JSPropertyEnumeratorGetNext -> JSPropertyEnumeratorGetNextName
JSString* ->

JSStringCreateWithUTF8CString, JSStringGetUTF8CString,
JSStringGetMaximumUTF8CStringSize JSStringIsEqualToUTF8CString,
JSStringCreateWithCFString, JSStringCopyCFString, JSStringCreateWithCharacters.


  • Changed functions taking a JSValue out arg and returning a bool indicating whether it was set to simply return a JSValue or NULL.


  • Removed JSStringGetCharacters because it's more documentation than code, and it's just a glorified memcpy built on existing API functionality.


  • Moved standard library includes into the headers that actually require them.


  • Standardized use of the phrase "Create Rule."


  • Removed JSLock from make functions that don't allocate.


  • Added exception handling to JSValueToBoolean, since we now allow callback objects to throw exceptions upon converting to boolean.


  • Renamed JSGCCollect to JSGarbageCollect.
Location:
trunk/JavaScriptCore
Files:
23 edited

Legend:

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

    r15317 r15376  
    5050}
    5151
    52 inline KJS::UString::Rep* toJS(JSInternalStringRef b)
     52inline KJS::UString::Rep* toJS(JSStringRef b)
    5353{
    5454    return reinterpret_cast<KJS::UString::Rep*>(b);
     
    7575}
    7676
    77 inline JSInternalStringRef toRef(KJS::UString::Rep* s)
     77inline JSStringRef toRef(KJS::UString::Rep* s)
    7878{
    79     return reinterpret_cast<JSInternalStringRef>(s);
     79    return reinterpret_cast<JSStringRef>(s);
    8080}
    8181
  • trunk/JavaScriptCore/API/JSBase.h

    r15310 r15376  
    3232/*! @typedef JSContextRef A JavaScript execution context. Holds the global object and other execution state. */
    3333typedef struct __JSContext* JSContextRef;
    34 /*! @typedef JSInternalString A UTF16 character buffer. The fundamental string representation in JavaScript. */
    35 typedef struct __JSInternalString* JSInternalStringRef;
     34/*! @typedef JSString A UTF16 character buffer. The fundamental string representation in JavaScript. */
     35typedef struct __JSString* JSStringRef;
    3636/*! @typedef JSClassRef A JavaScript class. Used with JSObjectMake to construct objects with custom behavior. */
    3737typedef struct __JSClass* JSClassRef;
     
    4646/*! @typedef JSValueRef A JavaScript value. The base type for all JavaScript values, and polymorphic functions on them. */
    4747typedef const struct __JSValue* JSValueRef;
    48 
    4948/*! @typedef JSObjectRef A JavaScript object. A JSObject is a JSValue. */
    5049typedef struct __JSValue* JSObjectRef;
  • trunk/JavaScriptCore/API/JSCallbackConstructor.cpp

    r15317 r15376  
    3232const ClassInfo JSCallbackConstructor::info = { "CallbackConstructor", 0, 0, 0 };
    3333
    34 JSCallbackConstructor::JSCallbackConstructor(ExecState* exec, JSCallAsConstructorCallback callback)
     34JSCallbackConstructor::JSCallbackConstructor(ExecState* exec, JSObjectCallAsConstructorCallback callback)
    3535    : JSObject(exec->lexicalInterpreter()->builtinObjectPrototype())
    3636    , m_callback(callback)
  • trunk/JavaScriptCore/API/JSCallbackConstructor.h

    r15133 r15376  
    3636{
    3737public:
    38     JSCallbackConstructor(ExecState* exec, JSCallAsConstructorCallback callback);
     38    JSCallbackConstructor(ExecState* exec, JSObjectCallAsConstructorCallback callback);
    3939   
    4040    virtual bool implementsConstruct() const;
     
    5252   
    5353    void* m_privateData;
    54     JSCallAsConstructorCallback m_callback;
     54    JSObjectCallAsConstructorCallback m_callback;
    5555};
    5656
  • trunk/JavaScriptCore/API/JSCallbackFunction.cpp

    r15317 r15376  
    3434const ClassInfo JSCallbackFunction::info = { "CallbackFunction", &InternalFunctionImp::info, 0, 0 };
    3535
    36 JSCallbackFunction::JSCallbackFunction(ExecState* exec, JSCallAsFunctionCallback callback)
     36JSCallbackFunction::JSCallbackFunction(ExecState* exec, JSObjectCallAsFunctionCallback callback)
    3737    : InternalFunctionImp(static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()))
    3838    , m_callback(callback)
  • trunk/JavaScriptCore/API/JSCallbackFunction.h

    r15133 r15376  
    3737{
    3838public:
    39     JSCallbackFunction(ExecState* exec, JSCallAsFunctionCallback callback);
     39    JSCallbackFunction(ExecState* exec, JSObjectCallAsFunctionCallback callback);
    4040
    4141    virtual bool implementsCall() const;
     
    5353   
    5454    void* m_privateData;
    55     JSCallAsFunctionCallback m_callback;
     55    JSObjectCallAsFunctionCallback m_callback;
    5656};
    5757
  • trunk/JavaScriptCore/API/JSCallbackObject.cpp

    r15317 r15376  
    6060   
    6161    do {
    62         if (JSInitializeCallback initialize = jsClass->callbacks.initialize)
     62        if (JSObjectInitializeCallback initialize = jsClass->callbacks.initialize)
    6363            initialize(context, thisRef, toRef(exec->exceptionSlot()));
    6464    } while ((jsClass = jsClass->parent));
     
    7070   
    7171    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent)
    72         if (JSFinalizeCallback finalize = jsClass->callbacks.finalize)
     72        if (JSObjectFinalizeCallback finalize = jsClass->callbacks.finalize)
    7373            finalize(thisRef);
    7474   
     
    8585    JSContextRef context = toRef(exec);
    8686    JSObjectRef thisRef = toRef(this);
    87     JSInternalStringRef propertyNameRef = toRef(propertyName.ustring().rep());
     87    JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
    8888
    8989    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    9090        // optional optimization to bypass getProperty in cases when we only need to know if the property exists
    91         if (JSHasPropertyCallback hasPropertyCallback = jsClass->callbacks.hasProperty) {
    92             if (hasPropertyCallback(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) {
     91        if (JSObjectHasPropertyCallback hasProperty = jsClass->callbacks.hasProperty) {
     92            if (hasProperty(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) {
    9393                slot.setCustom(this, callbackGetter);
    9494                return true;
    9595            }
    96         } else if (JSGetPropertyCallback getPropertyCallback = jsClass->callbacks.getProperty) {
    97             JSValueRef returnValue;
    98             if (getPropertyCallback(context, thisRef, propertyNameRef, &returnValue, toRef(exec->exceptionSlot()))) {
     96        } else if (JSObjectGetPropertyCallback getProperty = jsClass->callbacks.getProperty) {
     97            if (JSValueRef value = getProperty(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) {
    9998                // cache the value so we don't have to compute it again
    10099                // FIXME: This violates the PropertySlot design a little bit.
    101100                // We should either use this optimization everywhere, or nowhere.
    102                 slot.setCustom(reinterpret_cast<JSObject*>(toJS(returnValue)), cachedValueGetter);
     101                slot.setCustom(reinterpret_cast<JSObject*>(toJS(value)), cachedValueGetter);
    103102                return true;
    104103            }
     
    134133    JSContextRef context = toRef(exec);
    135134    JSObjectRef thisRef = toRef(this);
    136     JSInternalStringRef propertyNameRef = toRef(propertyName.ustring().rep());
     135    JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
    137136    JSValueRef valueRef = toRef(value);
    138137
    139138    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    140         if (JSSetPropertyCallback setPropertyCallback = jsClass->callbacks.setProperty) {
    141             if (setPropertyCallback(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
     139        if (JSObjectSetPropertyCallback setProperty = jsClass->callbacks.setProperty) {
     140            if (setProperty(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
    142141                return;
    143142        }
     
    147146                if (entry->attributes & kJSPropertyAttributeReadOnly)
    148147                    return;
    149                 if (JSSetPropertyCallback setPropertyCallback = entry->setProperty) {
    150                     if (setPropertyCallback(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
     148                if (JSObjectSetPropertyCallback setProperty = entry->setProperty) {
     149                    if (setProperty(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
    151150                        return;
    152151                }
     
    163162        }
    164163    }
     164
    165165    return JSObject::put(exec, propertyName, value, attr);
    166166}
     
    175175    JSContextRef context = toRef(exec);
    176176    JSObjectRef thisRef = toRef(this);
    177     JSInternalStringRef propertyNameRef = toRef(propertyName.ustring().rep());
    178    
    179     for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    180         if (JSDeletePropertyCallback deletePropertyCallback = jsClass->callbacks.deleteProperty) {
    181             if (deletePropertyCallback(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
     177    JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
     178   
     179    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
     180        if (JSObjectDeletePropertyCallback deleteProperty = jsClass->callbacks.deleteProperty) {
     181            if (deleteProperty(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
    182182                return true;
    183183        }
     
    199199        }
    200200    }
     201
    201202    return JSObject::deleteProperty(exec, propertyName);
    202203}
     
    222223   
    223224    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    224         if (JSCallAsConstructorCallback callAsConstructorCallback = jsClass->callbacks.callAsConstructor) {
     225        if (JSObjectCallAsConstructorCallback callAsConstructor = jsClass->callbacks.callAsConstructor) {
    225226            size_t argc = args.size();
    226227            JSValueRef argv[argc];
    227228            for (size_t i = 0; i < argc; i++)
    228229                argv[i] = toRef(args[i]);
    229             return toJS(callAsConstructorCallback(execRef, thisRef, argc, argv, toRef(exec->exceptionSlot())));
     230            return toJS(callAsConstructor(execRef, thisRef, argc, argv, toRef(exec->exceptionSlot())));
    230231        }
    231232    }
     
    251252
    252253    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    253         if (JSCallAsFunctionCallback callAsFunctionCallback = jsClass->callbacks.callAsFunction) {
     254        if (JSObjectCallAsFunctionCallback callAsFunction = jsClass->callbacks.callAsFunction) {
    254255            size_t argc = args.size();
    255256            JSValueRef argv[argc];
    256257            for (size_t i = 0; i < argc; i++)
    257258                argv[i] = toRef(args[i]);
    258             return toJS(callAsFunctionCallback(execRef, thisRef, thisObjRef, argc, argv, toRef(exec->exceptionSlot())));
     259            return toJS(callAsFunction(execRef, thisRef, thisObjRef, argc, argv, toRef(exec->exceptionSlot())));
    259260        }
    260261    }
     
    270271
    271272    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    272         if (JSGetPropertyListCallback getPropertyListCallback = jsClass->callbacks.getPropertyList)
    273             getPropertyListCallback(context, thisRef, toRef(&propertyList), toRef(exec->exceptionSlot()));
     273        if (JSObjectAddPropertiesToListCallback addPropertiesToList = jsClass->callbacks.addPropertiesToList)
     274            addPropertiesToList(context, thisRef, toRef(&propertyList), toRef(exec->exceptionSlot()));
    274275
    275276        if (__JSClass::StaticValuesTable* staticValues = jsClass->staticValues) {
     
    304305    JSObjectRef thisRef = toRef(this);
    305306
    306     for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    307         if (JSConvertToTypeCallback convertToTypeCallback = jsClass->callbacks.convertToType) {
    308             JSValueRef returnValue;
    309             if (convertToTypeCallback(context, thisRef, kJSTypeBoolean, &returnValue, toRef(exec->exceptionSlot())))
    310                 return toJS(returnValue)->getBoolean();
    311         }
    312     }
     307    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent)
     308        if (JSObjectConvertToTypeCallback convertToType = jsClass->callbacks.convertToType)
     309            if (JSValueRef value = convertToType(context, thisRef, kJSTypeBoolean, toRef(exec->exceptionSlot())))
     310                return toJS(value)->getBoolean();
     311
    313312    return JSObject::toBoolean(exec);
    314313}
     
    319318    JSObjectRef thisRef = toRef(this);
    320319
    321     for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    322         if (JSConvertToTypeCallback convertToTypeCallback = jsClass->callbacks.convertToType) {
    323             JSValueRef returnValue;
    324             if (convertToTypeCallback(context, thisRef, kJSTypeNumber, &returnValue, toRef(exec->exceptionSlot())))
    325                 return toJS(returnValue)->getNumber();
    326         }
    327     }
     320    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent)
     321        if (JSObjectConvertToTypeCallback convertToType = jsClass->callbacks.convertToType)
     322            if (JSValueRef value = convertToType(context, thisRef, kJSTypeNumber, toRef(exec->exceptionSlot())))
     323                return toJS(value)->getNumber();
     324
    328325    return JSObject::toNumber(exec);
    329326}
     
    334331    JSObjectRef thisRef = toRef(this);
    335332
    336     for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    337         if (JSConvertToTypeCallback convertToTypeCallback = jsClass->callbacks.convertToType) {
    338             JSValueRef returnValue;
    339             if (convertToTypeCallback(context, thisRef, kJSTypeString, &returnValue, toRef(exec->exceptionSlot())))
    340                 return toJS(returnValue)->getString();
    341         }
    342     }
     333    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent)
     334        if (JSObjectConvertToTypeCallback convertToType = jsClass->callbacks.convertToType)
     335            if (JSValueRef value = convertToType(context, thisRef, kJSTypeString, toRef(exec->exceptionSlot())))
     336                return toJS(value)->getString();
     337
    343338    return JSObject::toString(exec);
    344339}
     
    359354        if (jsClass == c)
    360355            return true;
     356
    361357    return false;
    362358}
     
    375371
    376372    JSObjectRef thisRef = toRef(thisObj);
    377     JSInternalStringRef propertyNameRef = toRef(propertyName.ustring().rep());
    378 
    379     for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parent) {
    380         JSValueRef returnValue;
    381        
     373    JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
     374
     375    for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parent)
    382376        if (__JSClass::StaticValuesTable* staticValues = jsClass->staticValues)
    383377            if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep()))
    384                 if (JSGetPropertyCallback getPropertyCallback = entry->getProperty)
    385                     if (getPropertyCallback(toRef(exec), thisRef, propertyNameRef, &returnValue, toRef(exec->exceptionSlot())))
    386                         return toJS(returnValue);
    387     }
     378                if (JSObjectGetPropertyCallback getProperty = entry->getProperty)
     379                    if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
     380                        return toJS(value);
    388381
    389382    return jsUndefined();
     
    401394        if (__JSClass::StaticFunctionsTable* staticFunctions = jsClass->staticFunctions) {
    402395            if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
    403                 JSValue* v = toJS(JSFunctionMake(toRef(exec), entry->callAsFunction));
     396                JSValue* v = toJS(JSObjectMakeFunction(toRef(exec), entry->callAsFunction));
    404397                thisObj->putDirect(propertyName, v, entry->attributes);
    405398                return v;
     
    417410
    418411    JSObjectRef thisRef = toRef(thisObj);
    419     JSInternalStringRef propertyNameRef = toRef(propertyName.ustring().rep());
    420 
    421     for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parent) {
    422         JSValueRef returnValue;
    423 
    424         if (JSGetPropertyCallback getPropertyCallback = jsClass->callbacks.getProperty)
    425             if (getPropertyCallback(toRef(exec), thisRef, propertyNameRef, &returnValue, toRef(exec->exceptionSlot())))
    426                 return toJS(returnValue);
    427     }
     412    JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
     413
     414    for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parent)
     415        if (JSObjectGetPropertyCallback getProperty = jsClass->callbacks.getProperty)
     416            if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
     417                return toJS(value);
    428418
    429419    return jsUndefined();
  • trunk/JavaScriptCore/API/JSClassRef.h

    r15133 r15376  
    3333
    3434struct StaticValueEntry {
    35     StaticValueEntry(JSGetPropertyCallback _getProperty, JSSetPropertyCallback _setProperty, JSPropertyAttributes _attributes)
     35    StaticValueEntry(JSObjectGetPropertyCallback _getProperty, JSObjectSetPropertyCallback _setProperty, JSPropertyAttributes _attributes)
    3636        : getProperty(_getProperty), setProperty(_setProperty), attributes(_attributes)
    3737    {
    3838    }
    3939   
    40     JSGetPropertyCallback getProperty;
    41     JSSetPropertyCallback setProperty;
     40    JSObjectGetPropertyCallback getProperty;
     41    JSObjectSetPropertyCallback setProperty;
    4242    JSPropertyAttributes attributes;
    4343};
    4444
    4545struct StaticFunctionEntry {
    46     StaticFunctionEntry(JSCallAsFunctionCallback _callAsFunction, JSPropertyAttributes _attributes)
    47     : callAsFunction(_callAsFunction), attributes(_attributes)
     46    StaticFunctionEntry(JSObjectCallAsFunctionCallback _callAsFunction, JSPropertyAttributes _attributes)
     47        : callAsFunction(_callAsFunction), attributes(_attributes)
    4848    {
    4949    }
    5050
    51     JSCallAsFunctionCallback callAsFunction;
     51    JSObjectCallAsFunctionCallback callAsFunction;
    5252    JSPropertyAttributes attributes;
    5353};
    5454
    5555struct __JSClass {
    56     __JSClass() : refCount(0), staticValues(0), staticFunctions(0)
     56    __JSClass()
     57        : refCount(0), staticValues(0), staticFunctions(0)
    5758    {
    5859    }
  • trunk/JavaScriptCore/API/JSContextRef.cpp

    r15317 r15376  
    6363}
    6464
    65 JSValueRef JSEvaluate(JSContextRef context, JSInternalStringRef script, JSObjectRef thisObject, JSInternalStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
     65JSValueRef JSEvaluate(JSContextRef context, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
    6666{
    6767    JSLock lock;
     
    8686}
    8787
    88 bool JSCheckSyntax(JSContextRef context, JSInternalStringRef script, JSInternalStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
     88bool JSCheckSyntax(JSContextRef context, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
    8989{
    9090    JSLock lock;
  • trunk/JavaScriptCore/API/JSContextRef.h

    r15328 r15376  
    3131#include <JavaScriptCore/JSValueRef.h>
    3232
     33#include <stdbool.h>
     34
    3335#ifdef __cplusplus
    3436extern "C" {
     
    5557/*!
    5658@function
    57 @abstract       Returns the global object of a JavaScript execution context.
    58 @param context  The JSContext whose global object you want to retrieve.
     59@abstract       Gets the global object of a JavaScript execution context.
     60@param context  The JSContext whose global object you want to get.
    5961@result         context's global object.
    6062*/
     
    6668@abstract                 Evaluates a string of JavaScript.
    6769@param context            The execution context to use.
    68 @param script             A JSInternalString containing the script to evaluate.
     70@param script             A JSString containing the script to evaluate.
    6971@param thisObject         The object to use as "this," or NULL to use the global object as "this."
    70 @param sourceURL          A JSInternalString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
     72@param sourceURL          A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
    7173@param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions.
    7274@param exception          A pointer to a JSValueRef in which to store an uncaught exception, if any. Pass NULL if you do not care to store an uncaught exception.
    7375@result                   The JSValue that results from evaluating script, or NULL if an uncaught exception is thrown.
    7476*/
    75 JSValueRef JSEvaluate(JSContextRef context, JSInternalStringRef script, JSObjectRef thisObject, JSInternalStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
     77JSValueRef JSEvaluate(JSContextRef context, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
    7678
    7779/*!
     
    7981@abstract                 Checks for syntax errors in a string of JavaScript.
    8082@param context            The execution context to use.
    81 @param script             A JSInternalString containing the JavaScript to check for syntax errors.
    82 @param sourceURL          A JSInternalString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
     83@param script             A JSString containing the script to check for syntax errors.
     84@param sourceURL          A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
    8385@param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions.
    8486@param exception          A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception.
    8587@result                   true if the script is syntactically correct, otherwise false.
    8688*/
    87 bool JSCheckSyntax(JSContextRef context, JSInternalStringRef script, JSInternalStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
     89bool JSCheckSyntax(JSContextRef context, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
    8890
    8991#ifdef __cplusplus
  • trunk/JavaScriptCore/API/JSInternalStringRef.cpp

    r15328 r15376  
    3737using namespace KJS;
    3838
    39 JSValueRef JSStringMake(JSInternalStringRef string)
     39JSValueRef JSValueMakeString(JSStringRef string)
    4040{
    4141    JSLock lock;
     
    4444}
    4545
    46 JSInternalStringRef JSInternalStringCreate(const JSChar* chars, size_t numChars)
     46JSStringRef JSStringCreateWithCharacters(const JSChar* chars, size_t numChars)
    4747{
    4848    JSLock lock;
     
    5050}
    5151
    52 JSInternalStringRef JSInternalStringCreateUTF8(const char* string)
     52JSStringRef JSStringCreateWithUTF8CString(const char* string)
    5353{
    5454    JSLock lock;
     
    5858}
    5959
    60 JSInternalStringRef JSInternalStringRetain(JSInternalStringRef string)
     60JSStringRef JSStringRetain(JSStringRef string)
    6161{
    6262    UString::Rep* rep = toJS(string);
     
    6464}
    6565
    66 void JSInternalStringRelease(JSInternalStringRef string)
     66void JSStringRelease(JSStringRef string)
    6767{
    6868    JSLock lock;
     
    7171}
    7272
    73 JSInternalStringRef JSValueCopyStringValue(JSContextRef context, JSValueRef value)
     73JSStringRef JSValueToStringCopy(JSContextRef context, JSValueRef value)
    7474{
    7575    JSLock lock;
     
    7777    ExecState* exec = toJS(context);
    7878
    79     JSInternalStringRef stringRef = toRef(jsValue->toString(exec).rep()->ref());
     79    JSStringRef stringRef = toRef(jsValue->toString(exec).rep()->ref());
    8080    if (exec->hadException())
    8181        exec->clearException();
     
    8383}
    8484
    85 size_t JSInternalStringGetLength(JSInternalStringRef string)
     85size_t JSStringGetLength(JSStringRef string)
    8686{
    8787    UString::Rep* rep = toJS(string);
     
    8989}
    9090
    91 const JSChar* JSInternalStringGetCharactersPtr(JSInternalStringRef string)
     91const JSChar* JSStringGetCharactersPtr(JSStringRef string)
    9292{
    9393    UString::Rep* rep = toJS(string);
     
    9595}
    9696
    97 void JSInternalStringGetCharacters(JSInternalStringRef string, JSChar* buffer, size_t numChars)
    98 {
    99     UString::Rep* rep = toJS(string);
    100     const JSChar* data = reinterpret_cast<const JSChar*>(rep->data());
    101    
    102     memcpy(buffer, data, numChars * sizeof(JSChar));
    103 }
    104 
    105 size_t JSInternalStringGetMaxLengthUTF8(JSInternalStringRef string)
     97size_t JSStringGetMaximumUTF8CStringSize(JSStringRef string)
    10698{
    10799    UString::Rep* rep = toJS(string);
     
    111103}
    112104
    113 size_t JSInternalStringGetCharactersUTF8(JSInternalStringRef string, char* buffer, size_t bufferSize)
     105size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSize)
    114106{
    115107    JSLock lock;
     
    122114}
    123115
    124 bool JSInternalStringIsEqual(JSInternalStringRef a, JSInternalStringRef b)
     116bool JSStringIsEqual(JSStringRef a, JSStringRef b)
    125117{
    126118    UString::Rep* aRep = toJS(a);
     
    130122}
    131123
    132 bool JSInternalStringIsEqualUTF8(JSInternalStringRef a, const char* b)
     124bool JSStringIsEqualToUTF8CString(JSStringRef a, const char* b)
    133125{
    134     JSInternalStringRef bBuf = JSInternalStringCreateUTF8(b);
    135     bool result = JSInternalStringIsEqual(a, bBuf);
    136     JSInternalStringRelease(bBuf);
     126    JSStringRef bBuf = JSStringCreateWithUTF8CString(b);
     127    bool result = JSStringIsEqual(a, bBuf);
     128    JSStringRelease(bBuf);
    137129   
    138130    return result;
     
    140132
    141133#if defined(__APPLE__)
    142 JSInternalStringRef JSInternalStringCreateCF(CFStringRef string)
     134JSStringRef JSStringCreateWithCFString(CFStringRef string)
    143135{
    144136    JSLock lock;
     
    157149}
    158150
    159 CFStringRef CFStringCreateWithJSInternalString(CFAllocatorRef alloc, JSInternalStringRef string)
     151CFStringRef JSStringCopyCFString(CFAllocatorRef alloc, JSStringRef string)
    160152{
    161153    UString::Rep* rep = toJS(string);
  • trunk/JavaScriptCore/API/JSInternalStringRef.h

    r15328 r15376  
    2929
    3030#include <JavaScriptCore/JSValueRef.h>
     31
     32#include <stdbool.h>
     33#include <stddef.h> // for size_t
     34
    3135#ifdef __cplusplus
    3236extern "C" {
     
    4650@function
    4751@abstract         Creates a JavaScript string from a buffer of Unicode characters.
    48 @param chars      The buffer of Unicode characters to copy into the new JSInternalString.
     52@param chars      The buffer of Unicode characters to copy into the new JSString.
    4953@param numChars   The number of characters to copy from the buffer pointed to by chars.
    50 @result           A JSInternalString containing chars. Ownership follows the create rule.
     54@result           A JSString containing chars. Ownership follows the Create Rule.
    5155*/
    52 JSInternalStringRef JSInternalStringCreate(const JSChar* chars, size_t numChars);
     56JSStringRef JSStringCreateWithCharacters(const JSChar* chars, size_t numChars);
    5357/*!
    5458@function
    5559@abstract         Creates a JavaScript string from a null-terminated UTF8 string.
    56 @param string     The null-terminated UTF8 string to copy into the new JSInternalString.
    57 @result           A JSInternalString containing string. Ownership follows the create rule.
     60@param string     The null-terminated UTF8 string to copy into the new JSString.
     61@result           A JSString containing string. Ownership follows the Create Rule.
    5862*/
    59 JSInternalStringRef JSInternalStringCreateUTF8(const char* string);
     63JSStringRef JSStringCreateWithUTF8CString(const char* string);
    6064
    6165/*!
    6266@function
    6367@abstract         Retains a JavaScript string.
    64 @param string     The JSInternalString to retain.
    65 @result           A JSInternalString that is the same as buffer.
     68@param string     The JSString to retain.
     69@result           A JSString that is the same as string.
    6670*/
    67 JSInternalStringRef JSInternalStringRetain(JSInternalStringRef string);
     71JSStringRef JSStringRetain(JSStringRef string);
    6872/*!
    6973@function
    7074@abstract         Releases a JavaScript string.
    71 @param string     The JSInternalString to release.
     75@param string     The JSString to release.
    7276*/
    73 void JSInternalStringRelease(JSInternalStringRef string);
     77void JSStringRelease(JSStringRef string);
    7478
    7579/*!
    7680@function
    7781@abstract         Returns the number of Unicode characters in a JavaScript string.
    78 @param string     The JSInternalString whose length (in Unicode characters) you want to know.
     82@param string     The JSString whose length (in Unicode characters) you want to know.
    7983@result           The number of Unicode characters stored in string.
    8084*/
    81 size_t JSInternalStringGetLength(JSInternalStringRef string);
     85size_t JSStringGetLength(JSStringRef string);
    8286/*!
    8387@function
    84 @abstract         Quickly obtains a pointer to the Unicode character buffer that
     88@abstract         Returns a pointer to the Unicode character buffer that
    8589 serves as the backing store for a JavaScript string.
    86 @param string     The JSInternalString whose backing store you want to access.
     90@param string     The JSString whose backing store you want to access.
    8791@result           A pointer to the Unicode character buffer that serves as string's
    8892 backing store, which will be deallocated when string is deallocated.
    8993*/
    90 const JSChar* JSInternalStringGetCharactersPtr(JSInternalStringRef string);
    91 /*!
    92 @function
    93 @abstract         Copies a JavaScript string's Unicode characters into an
    94  external character buffer.
    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 @param numChars   The number of Unicode characters to copy. This number must not
    99  exceed the length of the string.
    100 */
    101 void JSInternalStringGetCharacters(JSInternalStringRef string, JSChar* buffer, size_t numChars);
     94const JSChar* JSStringGetCharactersPtr(JSStringRef string);
    10295
    10396/*!
    10497@function
    105 @abstract         Returns the maximum number of bytes required to encode the
    106  contents of a JavaScript string as a null-terminated UTF8 string.
    107 @param string     The JSInternalString whose maximum encoded length (in bytes) you
     98@abstract Returns the maximum number of bytes a JavaScript string will
     99 take up if converted into a null-terminated UTF8 string.
     100@param string The JSString whose maximum converted size (in bytes) you
    108101 want to know.
    109 @result           The maximum number of bytes required to encode string's contents
    110  as a null-terminated UTF8 string.
     102@result The maximum number of bytes that could be required to convert string into a
     103 null-terminated UTF8 string. The number of bytes that the conversion actually ends
     104 up requiring could be less than this, but never more.
    111105*/
    112 size_t JSInternalStringGetMaxLengthUTF8(JSInternalStringRef string);
     106size_t JSStringGetMaximumUTF8CStringSize(JSStringRef string);
    113107/*!
    114108@function
    115 @abstract         Converts a JavaScript string's contents into a
    116  null-terminated UTF8 string, and copies the result into an external byte buffer.
    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.
     109@abstract Converts a JavaScript string into a null-terminated UTF8 string,
     110 and copies the result into an external byte buffer.
     111@param string The source JSString.
     112@param buffer The destination byte buffer into which to copy a null-terminated
     113 UTF8 string representation of string. The buffer must be at least bufferSize
     114 bytes in size. On return, buffer contains a UTF8 string representation of string.
    121115 If bufferSize is too small, buffer will contain only partial results.
    122 @param bufferSize The length of the external buffer in bytes.
    123 @result           The number of bytes written into buffer (including the null-terminator byte).
     116@param bufferSize The size of the external buffer in bytes.
     117@result The number of bytes written into buffer (including the null-terminator byte).
    124118*/
    125 size_t JSInternalStringGetCharactersUTF8(JSInternalStringRef string, char* buffer, size_t bufferSize);
     119size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSize);
    126120
    127121/*!
    128122@function
    129 @abstract     Tests whether the characters in two JavaScript strings match.
    130 @param a      The first JSInternalString to test.
    131 @param b      The second JSInternalString to test.
    132 @result       true if the characters in the two strings match, otherwise false.
     123@abstract     Tests whether two JavaScript strings match.
     124@param a      The first JSString to test.
     125@param b      The second JSString to test.
     126@result       true if the two strings match, otherwise false.
    133127*/
    134 bool JSInternalStringIsEqual(JSInternalStringRef a, JSInternalStringRef b);
     128bool JSStringIsEqual(JSStringRef a, JSStringRef b);
    135129/*!
    136130@function
    137 @abstract     Tests whether the characters in a JavaScript string match
    138  the characters in a null-terminated UTF8 string.
    139 @param a      The JSInternalString to test.
     131@abstract     Tests whether a JavaScript string matches a null-terminated UTF8 string.
     132@param a      The JSString to test.
    140133@param b      The null-terminated UTF8 string to test.
    141 @result       true if the characters in the two strings match, otherwise false.
     134@result       true if the two strings match, otherwise false.
    142135*/
    143 bool JSInternalStringIsEqualUTF8(JSInternalStringRef a, const char* b);
     136bool JSStringIsEqualToUTF8CString(JSStringRef a, const char* b);
    144137
    145138#if defined(__APPLE__)
     
    151144@discussion       This function is optimized to take advantage of cases when
    152145 CFStringGetCharactersPtr returns a valid pointer.
    153 @param string     The CFString to copy into the new JSInternalString.
    154 @result           A JSInternalString containing string. Ownership follows the create rule.
     146@param string     The CFString to copy into the new JSString.
     147@result           A JSString containing string. Ownership follows the Create Rule.
    155148*/
    156 JSInternalStringRef JSInternalStringCreateCF(CFStringRef string);
     149JSStringRef JSStringCreateWithCFString(CFStringRef string);
    157150/*!
    158151@function
    159152@abstract         Creates a CFString form a JavaScript string.
    160153@param alloc      The alloc parameter to pass to CFStringCreate.
    161 @param string     The JSInternalString to copy into the new CFString.
    162 @result           A CFString containing string. Ownership follows the create rule.
     154@param string     The JSString to copy into the new CFString.
     155@result           A CFString containing string. Ownership follows the Create Rule.
    163156*/
    164 CFStringRef CFStringCreateWithJSInternalString(CFAllocatorRef alloc, JSInternalStringRef string);
     157CFStringRef JSStringCopyCFString(CFAllocatorRef alloc, JSStringRef string);
    165158#endif // __APPLE__
    166159   
  • trunk/JavaScriptCore/API/JSNode.c

    r15328 r15376  
    4040    // Example of throwing a type error for invalid values
    4141    if (!JSValueIsObjectOfClass(thisObject, JSNode_class(context))) {
    42         JSInternalStringRef message = JSInternalStringCreateUTF8("TypeError: appendChild can only be called on nodes");
    43         *exception = JSStringMake(message);
    44         JSInternalStringRelease(message);
     42        JSStringRef message = JSStringCreateWithUTF8CString("TypeError: appendChild can only be called on nodes");
     43        *exception = JSValueMakeString(message);
     44        JSStringRelease(message);
    4545    } else if (argc < 1 || !JSValueIsObjectOfClass(argv[0], JSNode_class(context))) {
    46         JSInternalStringRef message = JSInternalStringCreateUTF8("TypeError: first argument to appendChild must be a node");
    47         *exception = JSStringMake(message);
    48         JSInternalStringRelease(message);
     46        JSStringRef message = JSStringCreateWithUTF8CString("TypeError: first argument to appendChild must be a node");
     47        *exception = JSValueMakeString(message);
     48        JSStringRelease(message);
    4949    } else {
    5050        Node* node = JSObjectGetPrivate(thisObject);
     
    5454    }
    5555
    56     return JSUndefinedMake();
     56    return JSValueMakeUndefined();
    5757}
    5858
     
    7474    }
    7575   
    76     return JSUndefinedMake();
     76    return JSValueMakeUndefined();
    7777}
    7878
     
    9696    }
    9797   
    98     return JSUndefinedMake();
     98    return JSValueMakeUndefined();
    9999}
    100100
     
    114114}
    115115
    116 static bool JSNode_getNodeType(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception)
     116static JSValueRef JSNode_getNodeType(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
    117117{
    118118    UNUSED_PARAM(context);
     
    121121    Node* node = JSObjectGetPrivate(object);
    122122    if (node) {
    123         JSInternalStringRef nodeType = JSInternalStringCreateUTF8(node->nodeType);
    124         *returnValue = JSStringMake(nodeType);
    125         JSInternalStringRelease(nodeType);
    126         return true;
    127     }
    128     return false;
    129 }
    130 
    131 static bool JSNode_getChildNodes(JSContextRef context, JSObjectRef thisObject, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception)
     123        JSStringRef nodeType = JSStringCreateWithUTF8CString(node->nodeType);
     124        JSValueRef value = JSValueMakeString(nodeType);
     125        JSStringRelease(nodeType);
     126        return value;
     127    }
     128   
     129    return NULL;
     130}
     131
     132static JSValueRef JSNode_getChildNodes(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
    132133{
    133134    UNUSED_PARAM(propertyName);
    134135    Node* node = JSObjectGetPrivate(thisObject);
    135136    assert(node);
    136     *returnValue = JSNodeList_new(context, NodeList_new(node));
    137     return true;
    138 }
    139 
    140 static bool JSNode_getFirstChild(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception)
     137    return JSNodeList_new(context, NodeList_new(node));
     138}
     139
     140static JSValueRef JSNode_getFirstChild(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
    141141{
    142142    UNUSED_PARAM(context);
     
    144144    UNUSED_PARAM(object);
    145145   
    146     *returnValue = JSUndefinedMake();
    147     return true;
     146    return JSValueMakeUndefined();
    148147}
    149148
     
    180179    if (!prototype) {
    181180        prototype = JSObjectMake(context, JSNodePrototype_class(context), NULL);
    182         JSGCProtect(prototype);
     181        JSValueProtect(prototype);
    183182    }
    184183    return prototype;
  • trunk/JavaScriptCore/API/JSNodeList.c

    r15317 r15376  
    3939    }
    4040   
    41     return JSUndefinedMake();
     41    return JSValueMakeUndefined();
    4242}
    4343
     
    5757}
    5858
    59 static bool JSNodeList_length(JSContextRef context, JSObjectRef thisObject, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception)
     59static JSValueRef JSNodeList_length(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
    6060{
    6161    UNUSED_PARAM(context);
     
    6363    NodeList* nodeList = JSObjectGetPrivate(thisObject);
    6464    assert(nodeList);
    65     *returnValue = JSNumberMake(NodeList_length(nodeList));
    66     return true;
     65    return JSValueMakeNumber(NodeList_length(nodeList));
    6766}
    6867
     
    7271};
    7372
    74 static bool JSNodeList_getProperty(JSContextRef context, JSObjectRef thisObject, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception)
     73static JSValueRef JSNodeList_getProperty(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
    7574{
    7675    NodeList* nodeList = JSObjectGetPrivate(thisObject);
    7776    assert(nodeList);
    78     double index = JSValueToNumber(context, JSStringMake(propertyName));
     77    double index = JSValueToNumber(context, JSValueMakeString(propertyName));
    7978    unsigned uindex = index;
    8079    if (uindex == index) { // false for NaN
    8180        Node* node = NodeList_item(nodeList, uindex);
    8281        if (node) {
    83             *returnValue = JSNode_new(context, node);
    84             return true;
     82            return JSNode_new(context, node);
    8583        }
    8684    }
    8785   
    88     return false;
     86    return NULL;
    8987}
    9088
     
    115113    if (!prototype) {
    116114        prototype = JSObjectMake(context, JSNodeListPrototype_class(context), NULL);
    117         JSGCProtect(prototype);
     115        JSValueProtect(prototype);
    118116    }
    119117    return prototype;
  • trunk/JavaScriptCore/API/JSObjectRef.cpp

    r15310 r15376  
    5757}
    5858
    59 JSObjectRef JSFunctionMake(JSContextRef context, JSCallAsFunctionCallback callAsFunction)
     59JSObjectRef JSObjectMakeFunction(JSContextRef context, JSObjectCallAsFunctionCallback callAsFunction)
    6060{
    6161    JSLock lock;
     
    6464}
    6565
    66 JSObjectRef JSConstructorMake(JSContextRef context, JSCallAsConstructorCallback callAsConstructor)
     66JSObjectRef JSObjectMakeConstructor(JSContextRef context, JSObjectCallAsConstructorCallback callAsConstructor)
    6767{
    6868    JSLock lock;
     
    7171}
    7272
    73 JSObjectRef JSFunctionMakeWithBody(JSContextRef context, JSInternalStringRef body, JSInternalStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
     73JSObjectRef JSObjectMakeFunctionWithBody(JSContextRef context, JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
    7474{
    7575    JSLock lock;
     
    9797}
    9898
    99 JSInternalStringRef JSObjectGetDescription(JSObjectRef object)
     99JSStringRef JSObjectGetDescription(JSObjectRef object)
    100100{
    101101    JSLock lock;
     
    118118}
    119119
    120 bool JSObjectHasProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName)
     120bool JSObjectHasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
    121121{
    122122    JSLock lock;
     
    128128}
    129129
    130 JSValueRef JSObjectGetProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName)
     130JSValueRef JSObjectGetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
    131131{
    132132    JSLock lock;
     
    141141}
    142142
    143 bool JSObjectSetProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes)
     143bool JSObjectSetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes)
    144144{
    145145    JSLock lock;
     
    157157}
    158158
    159 bool JSObjectDeleteProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName)
     159bool JSObjectDeleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
    160160{
    161161    JSLock lock;
     
    285285}
    286286
    287 JSInternalStringRef JSPropertyEnumeratorGetNext(JSPropertyEnumeratorRef enumerator)
     287JSStringRef JSPropertyEnumeratorGetNextName(JSPropertyEnumeratorRef enumerator)
    288288{
    289289    ReferenceListIterator& iterator = enumerator->iterator;
    290290    if (iterator != enumerator->list.end()) {
    291         JSInternalStringRef result = toRef(iterator->getPropertyName().ustring().rep());
     291        JSStringRef result = toRef(iterator->getPropertyName().ustring().rep());
    292292        iterator++;
    293293        return result;
     
    308308}
    309309
    310 void JSPropertyListAdd(JSPropertyListRef propertyList, JSObjectRef thisObject, JSInternalStringRef propertyName)
     310void JSPropertyListAdd(JSPropertyListRef propertyList, JSObjectRef thisObject, JSStringRef propertyName)
    311311{
    312312    JSLock lock;
  • trunk/JavaScriptCore/API/JSObjectRef.h

    r15328 r15376  
    3131#include <JavaScriptCore/JSValueRef.h>
    3232
     33#include <stdbool.h>
     34#include <stddef.h> // for size_t
     35
    3336#ifdef __cplusplus
    3437extern "C" {
     
    5659
    5760/*!
    58 @typedef JSInitializeCallback
     61@typedef JSObjectInitializeCallback
    5962@abstract The callback invoked when an object is first created.
    6063@param context The execution context to use.
     
    6669*/
    6770typedef void
    68 (*JSInitializeCallback) (JSContextRef context, JSObjectRef object, JSValueRef* exception);
    69 
    70 /*!
    71 @typedef JSFinalizeCallback
     71(*JSObjectInitializeCallback) (JSContextRef context, JSObjectRef object, JSValueRef* exception);
     72
     73/*!
     74@typedef JSObjectFinalizeCallback
    7275@abstract The callback invoked when an object is finalized (prepared for garbage collection).
    7376@param object The JSObject being finalized.
     
    7780*/
    7881typedef void           
    79 (*JSFinalizeCallback) (JSObjectRef object);
    80 
    81 /*!
    82 @typedef JSHasPropertyCallback
     82(*JSObjectFinalizeCallback) (JSObjectRef object);
     83
     84/*!
     85@typedef JSObjectHasPropertyCallback
    8386@abstract The callback invoked when determining whether an object has a given property.
    8487@param context The current execution context.
    8588@param object The JSObject to search for the property.
    86 @param propertyName A JSInternalString containing the name of the property look up.
     89@param propertyName A JSString containing the name of the property look up.
    8790@param exception A pointer to a JSValueRef in which to return an exception, if any.
    8891@result true if object has the property, otherwise false.
    8992@discussion If you named your function HasProperty, you would declare it like this:
    9093
    91 bool HasProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* exception);
    92 
    93 This callback enables optimization in cases where only a property's existence needs to be known, not its value, and computing its value would be expensive. If this callback is NULL, the getProperty callback will be used to service hasProperty calls.
     94bool HasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
     95
     96If this function returns false, the hasProperty request forwards to object's static property table, then its parent class chain (which includes the default object class), then its prototype chain.
     97
     98This callback enables optimization in cases where only a property's existence needs to be known, not its value, and computing its value would be expensive. If this callback is NULL, the getProperty callback will be used to service hasProperty requests.
    9499*/
    95100typedef bool
    96 (*JSHasPropertyCallback) (JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* exception);
    97 
    98 /*!
    99 @typedef JSGetPropertyCallback
     101(*JSObjectHasPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
     102
     103/*!
     104@typedef JSObjectGetPropertyCallback
    100105@abstract The callback invoked when getting a property from an object.
    101106@param context The current execution context.
    102107@param object The JSObject to search for the property.
    103 @param propertyName A JSInternalString containing the name of the property to get.
    104 @param returnValue A pointer to a JSValue in which to store the property's value.
    105 @param exception A pointer to a JSValueRef in which to return an exception, if any.
    106 @result true if object has the property in question, otherwise false. If this function returns true, returnValue is assumed to contain a valid JSValue.
     108@param propertyName A JSString containing the name of the property to get.
     109@param exception A pointer to a JSValueRef in which to return an exception, if any.
     110@result The property's value if object has the property, otherwise NULL.
    107111@discussion If you named your function GetProperty, you would declare it like this:
    108112
    109 bool GetProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception);
    110 
    111 If this function returns false, the get request forwards to object's static property table, then its parent class chain (which includes the default object class), then its prototype chain.
     113JSValueRef GetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
     114
     115If this function returns NULL, the get request forwards to object's static property table, then its parent class chain (which includes the default object class), then its prototype chain.
     116*/
     117typedef JSValueRef
     118(*JSObjectGetPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
     119
     120/*!
     121@typedef JSObjectSetPropertyCallback
     122@abstract The callback invoked when setting the value of a given property.
     123@param context The current execution context.
     124@param object The JSObject on which to set the property's value.
     125@param propertyName A JSString containing the name of the property to set.
     126@param value A JSValue to use as the property's value.
     127@param exception A pointer to a JSValueRef in which to return an exception, if any.
     128@result true if the property was set, otherwise false.
     129@discussion If you named your function SetProperty, you would declare it like this:
     130
     131bool SetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
     132
     133If this function returns false, the set request forwards to object's static property table, then its parent class chain (which includes the default object class).
    112134*/
    113135typedef bool
    114 (*JSGetPropertyCallback) (JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception);
    115 
    116 /*!
    117 @typedef JSSetPropertyCallback
    118 @abstract The callback invoked when setting the value of a given property.
    119 @param context The current execution context.
    120 @param object The JSObject on which to set the property's value.
    121 @param propertyName A JSInternalString containing the name of the property to set.
    122 @param value A JSValue to use as the property's value.
    123 @param exception A pointer to a JSValueRef in which to return an exception, if any.
    124 @result true if the property was successfully set, otherwise false.
    125 @discussion If you named your function SetProperty, you would declare it like this:
    126 
    127 bool SetProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef value, JSValueRef* exception);
    128 
    129 If this function returns false, the set request forwards to object's static property table, then its parent class chain (which includes the default object class).
    130 */
    131 typedef bool
    132 (*JSSetPropertyCallback) (JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef value, JSValueRef* exception);
    133 
    134 /*!
    135 @typedef JSDeletePropertyCallback
     136(*JSObjectSetPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
     137
     138/*!
     139@typedef JSObjectDeletePropertyCallback
    136140@abstract The callback invoked when deleting a given property.
    137141@param context The current execution context.
    138142@param object The JSObject in which to delete the property.
    139 @param propertyName A JSInternalString containing the name of the property to delete.
     143@param propertyName A JSString containing the name of the property to delete.
    140144@param exception A pointer to a JSValueRef in which to return an exception, if any.
    141145@result true if propertyName was successfully deleted, otherwise false.
    142146@discussion If you named your function DeleteProperty, you would declare it like this:
    143147
    144 bool DeleteProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* exception);
     148bool DeleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
    145149
    146150If this function returns false, the delete request forwards to object's static property table, then its parent class chain (which includes the default object class).
    147151*/
    148152typedef bool
    149 (*JSDeletePropertyCallback) (JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* exception);
    150 
    151 /*!
    152 @typedef JSGetPropertyListCallback
     153(*JSObjectDeletePropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
     154
     155/*!
     156@typedef JSObjectAddPropertiesToListCallback
    153157@abstract The callback invoked when adding an object's properties to a property list.
    154158@param context The current execution context.
     
    158162@discussion If you named your function GetPropertyList, you would declare it like this:
    159163
    160 void GetPropertyList(JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList, JSValueRef* exception);
     164void AddPropertiesToList(JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList, JSValueRef* exception);
    161165
    162166Use JSPropertyListAdd to add properties to propertyList.
     
    165169*/
    166170typedef void
    167 (*JSGetPropertyListCallback) (JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList, JSValueRef* exception);
    168 
    169 /*!
    170 @typedef JSCallAsFunctionCallback
     171(*JSObjectAddPropertiesToListCallback) (JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList, JSValueRef* exception);
     172
     173/*!
     174@typedef JSObjectCallAsFunctionCallback
    171175@abstract The callback invoked when an object is called as a function.
    172176@param context The current execution context.
     
    186190*/
    187191typedef JSValueRef
    188 (*JSCallAsFunctionCallback) (JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, JSValueRef argv[], JSValueRef* exception);
    189 
    190 /*!
    191 @typedef JSCallAsConstructorCallback
     192(*JSObjectCallAsFunctionCallback) (JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, JSValueRef argv[], JSValueRef* exception);
     193
     194/*!
     195@typedef JSObjectCallAsConstructorCallback
    192196@abstract The callback invoked when an object is used as a constructor in a 'new' statement.
    193197@param context The current execution context.
     
    206210*/
    207211typedef JSObjectRef
    208 (*JSCallAsConstructorCallback) (JSContextRef context, JSObjectRef constructor, size_t argc, JSValueRef argv[], JSValueRef* exception);
    209 
    210 /*!
    211 @typedef JSConvertToTypeCallback
     212(*JSObjectCallAsConstructorCallback) (JSContextRef context, JSObjectRef constructor, size_t argc, JSValueRef argv[], JSValueRef* exception);
     213
     214/*!
     215@typedef JSObjectConvertToTypeCallback
    212216@abstract The callback invoked when converting an object to a particular JavaScript type.
    213217@param context The current execution context.
    214218@param object The JSObject to convert.
    215 @param typeCode A JSTypeCode specifying the JavaScript type to convert to.
    216 @param returnValue A pointer to a JSValue in which to store the converted value.
    217 @param exception A pointer to a JSValueRef in which to return an exception, if any.
    218 @result true if the value was converted, otherwise false. If this function returns true, returnValue is assumed to contain a valid JSValue.
     219@param type A JSType specifying the JavaScript type to convert to.
     220@param exception A pointer to a JSValueRef in which to return an exception, if any.
     221@result The objects's converted value, or NULL if the object was not converted.
    219222@discussion If you named your function ConvertToType, you would declare it like this:
    220223
    221 bool ConvertToType(JSContextRef context, JSObjectRef object, JSTypeCode typeCode, JSValueRef* returnValue, JSValueRef* exception);
     224JSValueRef ConvertToType(JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception);
    222225
    223226If this function returns false, the conversion request forwards to object's parent class chain (which includes the default object class).
    224227*/
    225 typedef bool
    226 (*JSConvertToTypeCallback) (JSContextRef context, JSObjectRef object, JSTypeCode typeCode, JSValueRef* returnValue, JSValueRef* exception);
     228typedef JSValueRef
     229(*JSObjectConvertToTypeCallback) (JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception);
    227230
    228231/*!
     
    242245*/
    243246typedef struct {
    244     int                         version; // current (and only) version is 0
    245     JSInitializeCallback        initialize;
    246     JSFinalizeCallback          finalize;
    247     JSHasPropertyCallback       hasProperty;
    248     JSGetPropertyCallback       getProperty;
    249     JSSetPropertyCallback       setProperty;
    250     JSDeletePropertyCallback    deleteProperty;
    251     JSGetPropertyListCallback   getPropertyList;
    252     JSCallAsFunctionCallback    callAsFunction;
    253     JSCallAsConstructorCallback callAsConstructor;
    254     JSConvertToTypeCallback     convertToType;
     247    int                                 version; // current (and only) version is 0
     248    JSObjectInitializeCallback          initialize;
     249    JSObjectFinalizeCallback            finalize;
     250    JSObjectHasPropertyCallback         hasProperty;
     251    JSObjectGetPropertyCallback         getProperty;
     252    JSObjectSetPropertyCallback         setProperty;
     253    JSObjectDeletePropertyCallback      deleteProperty;
     254    JSObjectAddPropertiesToListCallback addPropertiesToList;
     255    JSObjectCallAsFunctionCallback      callAsFunction;
     256    JSObjectCallAsConstructorCallback  callAsConstructor;
     257    JSObjectConvertToTypeCallback       convertToType;
    255258} JSObjectCallbacks;
    256259
     
    270273@abstract This structure describes a static value property.
    271274@field name A null-terminated UTF8 string containing the property's name.
    272 @field getProperty A JSGetPropertyCallback to invoke when getting the property's value.
    273 @field setProperty A JSSetPropertyCallback to invoke when setting the property's value.
     275@field getProperty A JSObjectGetPropertyCallback to invoke when getting the property's value.
     276@field setProperty A JSObjectSetPropertyCallback to invoke when setting the property's value.
    274277@field attributes A logically ORed set of JSPropertyAttributes to give to the property.
    275278*/
    276279typedef struct {
    277280    const char* const name; // FIXME: convert UTF8
    278     JSGetPropertyCallback getProperty;
    279     JSSetPropertyCallback setProperty;
     281    JSObjectGetPropertyCallback getProperty;
     282    JSObjectSetPropertyCallback setProperty;
    280283    JSPropertyAttributes attributes;
    281284} JSStaticValue;
     
    285288@abstract This structure describes a static function property.
    286289@field name A null-terminated UTF8 string containing the property's name.
    287 @field callAsFunction A JSCallAsFunctionCallback to invoke when the property is called as a function.
     290@field callAsFunction A JSObjectCallAsFunctionCallback to invoke when the property is called as a function.
    288291@field attributes A logically ORed set of JSPropertyAttributes to give to the property.
    289292*/
    290293typedef struct {
    291294    const char* const name; // FIXME: convert UTF8
    292     JSCallAsFunctionCallback callAsFunction;
     295    JSObjectCallAsFunctionCallback callAsFunction;
    293296    JSPropertyAttributes attributes;
    294297} JSStaticFunction;
     
    296299/*!
    297300@function
    298 @abstract Creates a JavaScript class suitable for use with JSObjectMake. Ownership follows the create rule.
     301@abstract Creates a JavaScript class suitable for use with JSObjectMake
    299302@param staticValues A JSStaticValue array representing the class's static value properties. Pass NULL to specify no static value properties. The array must be terminated by a JSStaticValue whose name field is NULL.
    300303@param staticFunctions A JSStaticFunction array representing the class's static function properties. Pass NULL to specify no static function properties. The array must be terminated by a JSStaticFunction whose name field is NULL.
    301304@param callbacks A pointer to a JSObjectCallbacks structure holding custom callbacks for supplementing default object behavior. Pass NULL to specify no custom behavior.
    302305@param parentClass A JSClass to set as the class's parent class. Pass NULL use the default object class.
     306@result A JSClass with the given properties, callbacks, and parent class. Ownership follows the Create Rule.
    303307@discussion The simplest and most efficient way to add custom properties to a class is by specifying static values and functions. Standard JavaScript practice calls for functions to be placed in prototype objects, so that they can be shared among objects.
    304308*/
     
    332336@abstract Convenience method for creating a JavaScript function with a given callback as its implementation.
    333337@param context The execution context to use.
    334 @param callAsFunction The JSCallAsFunctionCallback to invoke when the function is called.
     338@param callAsFunction The JSObjectCallAsFunctionCallback to invoke when the function is called.
    335339@result A JSObject that is an anonymous function. The object's prototype will be the default function prototype.
    336340*/
    337 JSObjectRef JSFunctionMake(JSContextRef context, JSCallAsFunctionCallback callAsFunction);
     341JSObjectRef JSObjectMakeFunction(JSContextRef context, JSObjectCallAsFunctionCallback callAsFunction);
    338342/*!
    339343@function
    340344@abstract Convenience method for creating a JavaScript constructor with a given callback as its implementation.
    341345@param context The execution context to use.
    342 @param callAsConstructor The JSCallAsConstructorCallback to invoke when the constructor is used in a 'new' statement.
     346@param callAsConstructor The JSObjectCallAsConstructorCallback to invoke when the constructor is used in a 'new' statement.
    343347@result A JSObject that is a constructor. The object's prototype will be the default object prototype.
    344348*/
    345 JSObjectRef JSConstructorMake(JSContextRef context, JSCallAsConstructorCallback callAsConstructor);
     349JSObjectRef JSObjectMakeConstructor(JSContextRef context, JSObjectCallAsConstructorCallback callAsConstructor);
    346350
    347351/*!
     
    349353@abstract Creates a function with a given script as its body.
    350354@param context The execution context to use.
    351 @param body A JSInternalString containing the script to use as the function's body.
    352 @param sourceURL A JSInternalString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
     355@param body A JSString containing the script to use as the function's body.
     356@param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
    353357@param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions.
    354358@param exception A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception.
     
    356360@discussion Use this method when you want to execute a script repeatedly, to avoid the cost of re-parsing the script before each execution.
    357361*/
    358 JSObjectRef JSFunctionMakeWithBody(JSContextRef context, JSInternalStringRef body, JSInternalStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
     362JSObjectRef JSObjectMakeFunctionWithBody(JSContextRef context, JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
    359363
    360364/*!
     
    363367@param context The execution context to use.
    364368@param object The object whose description you want to get.
    365 @result A JSInternalString containing the object's description. This is usually the object's class name.
    366 */
    367 JSInternalStringRef JSObjectGetDescription(JSObjectRef object);
     369@result A JSString containing the object's description. This is usually the object's class name.
     370*/
     371JSStringRef JSObjectGetDescription(JSObjectRef object);
    368372
    369373/*!
     
    386390@abstract Tests whether an object has a certain property.
    387391@param object The JSObject to test.
    388 @param propertyName A JSInternalString containing the property's name.
     392@param propertyName A JSString containing the property's name.
    389393@result true if the object has a property whose name matches propertyName, otherwise false.
    390394*/
    391 bool JSObjectHasProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName);
     395bool JSObjectHasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
    392396/*!
    393397@function
     
    395399@param context The execution context to use.
    396400@param object The JSObject whose property you want to get.
    397 @param propertyName A JSInternalString containing the property's name.
    398 @result The property's value, or NULL if the object does not have a property whose name matches propertyName.
    399 */
    400 JSValueRef JSObjectGetProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName);
     401@param propertyName A JSString containing the property's name.
     402@result The property's value if object has the property, otherwise NULL.
     403*/
     404JSValueRef JSObjectGetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
    401405/*!
    402406@function
     
    404408@param context The execution context to use.
    405409@param object The JSObject whose property you want to set.
    406 @param propertyName A JSInternalString containing the property's name.
     410@param propertyName A JSString containing the property's name.
    407411@param value A JSValue to use as the property's value.
    408412@param attributes A logically ORed set of JSPropertyAttributes to give to the property.
    409413@result true if the set operation succeeds, otherwise false (for example, if the object already has a property of the given name with the kJSPropertyAttributeReadOnly attribute set).
    410414*/
    411 bool JSObjectSetProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes);
     415bool JSObjectSetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes);
    412416/*!
    413417@function
     
    415419@param context The execution context to use.
    416420@param object The JSObject whose property you want to delete.
    417 @param propertyName A JSInternalString containing the property's name.
     421@param propertyName A JSString containing the property's name.
    418422@result true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set).
    419423*/
    420 bool JSObjectDeleteProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName);
     424bool JSObjectDeleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
    421425
    422426/*!
     
    424428@abstract Gets a pointer to private data from an object.
    425429@param object A JSObject whose private data you want to get.
    426 @result A void* that points to the object's private data, or NULL if the object has no private data.
    427 @discussion JSObjectGetPrivate and JSObjectSetPrivate only work on custom objects created by JSObjectMake, JSFunctionMake, and JSConstructorMake.
     430@result A void* that points to the object's private data, if the object has private data, otherwise NULL.
     431@discussion JSObjectGetPrivate and JSObjectSetPrivate only work on custom objects created by JSObjectMake, JSObjectMakeFunction, and JSObjectMakeConstructor.
    428432*/
    429433void* JSObjectGetPrivate(JSObjectRef object);
     
    434438@param data A void* that points to the object's private data.
    435439@result true if the set operation succeeds, otherwise false.
    436 @discussion JSObjectGetPrivate and JSObjectSetPrivate only work on custom objects created by JSObjectMake, JSFunctionMake, and JSConstructorMake.
     440@discussion JSObjectGetPrivate and JSObjectSetPrivate only work on custom objects created by JSObjectMake, JSObjectMakeFunction, and JSObjectMakeConstructor.
    437441*/
    438442bool JSObjectSetPrivate(JSObjectRef object, void* data);
     
    481485@param context The execution context to use.
    482486@param object The object whose properties you want to enumerate.
    483 @result A JSPropertyEnumerator with a list of object's properties. Ownership follows the create rule.
     487@result A JSPropertyEnumerator with a list of object's properties. Ownership follows the Create Rule.
    484488*/
    485489JSPropertyEnumeratorRef JSObjectCreatePropertyEnumerator(JSContextRef context, JSObjectRef object);
     
    501505@abstract Gets a property enumerator's next property.
    502506@param enumerator The JSPropertyEnumerator whose next property you want to get.
    503 @result A JSInternalString containing the property's name, or NULL if all properties have been enumerated.
    504 */
    505 JSInternalStringRef JSPropertyEnumeratorGetNext(JSPropertyEnumeratorRef enumerator);
     507@result A JSString containing the property's name, or NULL if all properties have been enumerated.
     508*/
     509JSStringRef JSPropertyEnumeratorGetNextName(JSPropertyEnumeratorRef enumerator);
    506510
    507511/*!
    508512@function
    509513@abstract Adds a property to a property list.
    510 @discussion Use this method inside a JSGetPropertyListCallback to add a custom property to an object's property list.
     514@discussion Use this method inside a JSObjectAddPropertiesToListCallback to add a custom property to an object's property list.
    511515@param propertyList The JSPropertyList to which you want to add a property.
    512516@param thisObject The JSObject to which the property belongs.
    513 @param propertyName A JSInternalString specifying the property's name.
    514 */
    515 void JSPropertyListAdd(JSPropertyListRef propertyList, JSObjectRef thisObject, JSInternalStringRef propertyName);
     517@param propertyName A JSString specifying the property's name.
     518*/
     519void JSPropertyListAdd(JSPropertyListRef propertyList, JSObjectRef thisObject, JSStringRef propertyName);
    516520
    517521#ifdef __cplusplus
  • trunk/JavaScriptCore/API/JSValueRef.cpp

    r15234 r15376  
    4040#include <algorithm> // for std::min
    4141
    42 using namespace KJS;
    43 
    44 JSTypeCode JSValueGetType(JSValueRef value)
    45 {
    46     JSValue* jsValue = toJS(value);
     42JSType JSValueGetType(JSValueRef value)
     43{
     44    KJS::JSValue* jsValue = toJS(value);
    4745    switch (jsValue->type()) {
    48         case UndefinedType:
     46        case KJS::UndefinedType:
    4947            return kJSTypeUndefined;
    50         case NullType:
     48        case KJS::NullType:
    5149            return kJSTypeNull;
    52         case BooleanType:
     50        case KJS::BooleanType:
    5351            return kJSTypeBoolean;
    54         case NumberType:
     52        case KJS::NumberType:
    5553            return kJSTypeNumber;
    56         case StringType:
     54        case KJS::StringType:
    5755            return kJSTypeString;
    58         case ObjectType:
     56        case KJS::ObjectType:
    5957            return kJSTypeObject;
    6058        default:
     
    6462}
    6563
     64using namespace KJS; // placed here to avoid conflict between KJS::JSType and JSType, above.
     65
    6666bool JSValueIsUndefined(JSValueRef value)
    6767{
     
    136136}
    137137
    138 bool JSValueIsInstanceOf(JSContextRef context, JSValueRef value, JSObjectRef constructor)
     138bool JSValueIsInstanceOfConstructor(JSContextRef context, JSValueRef value, JSObjectRef constructor)
    139139{
    140140    ExecState* exec = toJS(context);
     
    149149}
    150150
    151 JSValueRef JSUndefinedMake()
    152 {
    153     JSLock lock;
     151JSValueRef JSValueMakeUndefined()
     152{
    154153    return toRef(jsUndefined());
    155154}
    156155
    157 JSValueRef JSNullMake()
    158 {
    159     JSLock lock;
     156JSValueRef JSValueMakeNull()
     157{
    160158    return toRef(jsNull());
    161159}
    162160
    163 JSValueRef JSBooleanMake(bool value)
    164 {
    165     JSLock lock;
     161JSValueRef JSValueMakeBoolean(bool value)
     162{
    166163    return toRef(jsBoolean(value));
    167164}
    168165
    169 JSValueRef JSNumberMake(double value)
     166JSValueRef JSValueMakeNumber(double value)
    170167{
    171168    JSLock lock;
     
    179176    JSValue* jsValue = toJS(value);
    180177   
    181     return jsValue->toBoolean(exec);
     178    bool boolean = jsValue->toBoolean(exec);
     179    if (exec->hadException()) {
     180        exec->clearException();
     181        boolean = false;
     182    }
     183    return boolean;
    182184}
    183185
     
    210212}   
    211213
    212 void JSGCProtect(JSValueRef value)
     214void JSValueProtect(JSValueRef value)
    213215{
    214216    JSLock lock;
     
    217219}
    218220
    219 void JSGCUnprotect(JSValueRef value)
     221void JSValueUnprotect(JSValueRef value)
    220222{
    221223    JSLock lock;
     
    224226}
    225227
    226 void JSGCCollect()
     228void JSGarbageCollect()
    227229{
    228230    JSLock lock;
  • trunk/JavaScriptCore/API/JSValueRef.h

    r15328 r15376  
    3030#include <JavaScriptCore/JSBase.h>
    3131
    32 /*!
    33 @enum JSTypeCode
     32#include <stdbool.h>
     33
     34/*!
     35@enum JSType
    3436@abstract     A constant identifying the type of a JSValue.
    3537@constant     kJSTypeUndefined  The unique undefined value.
     
    4749    kJSTypeString,
    4850    kJSTypeObject
    49 } JSTypeCode;
     51} JSType;
    5052
    5153#ifdef __cplusplus
     
    5557/*!
    5658@function
    57 @abstract       Returns a JavaScript value's type code.
     59@abstract       Returns a JavaScript value's type.
    5860@param value    The JSValue whose type you want to obtain.
    59 @result         A value of type JSTypeCode that identifies value's type.
    60 */
    61 JSTypeCode JSValueGetType(JSValueRef value);
     61@result         A value of type JSType that identifies value's type.
     62*/
     63JSType JSValueGetType(JSValueRef value);
    6264
    6365/*!
     
    151153 by the JS instanceof operator, otherwise false.
    152154*/
    153 bool JSValueIsInstanceOf(JSContextRef context, JSValueRef value, JSObjectRef constructor);
     155bool JSValueIsInstanceOfConstructor(JSContextRef context, JSValueRef value, JSObjectRef constructor);
    154156
    155157// Creating values
     
    160162@result     The unique undefined value.
    161163*/
    162 JSValueRef JSUndefinedMake(void);
     164JSValueRef JSValueMakeUndefined(void);
    163165
    164166/*!
     
    167169@result     The unique null value.
    168170*/
    169 JSValueRef JSNullMake(void);
     171JSValueRef JSValueMakeNull(void);
    170172
    171173/*!
    172174@function
    173175@abstract       Creates a JavaScript value of the boolean type.
    174 @param value    The boolean value to assign to the newly created JSValue.
    175 @result         A JSValue of the boolean type, representing the boolean value of value.
    176 */
    177 
    178 JSValueRef JSBooleanMake(bool value);
     176@param boolean  The bool to assign to the newly created JSValue.
     177@result         A JSValue of the boolean type, representing the value of boolean.
     178*/
     179
     180JSValueRef JSValueMakeBoolean(bool boolean);
    179181
    180182/*!
    181183@function
    182184@abstract       Creates a JavaScript value of the number type.
    183 @param value    The numeric value to assign to the newly created JSValue.
    184 @result         A JSValue of the number type, representing the numeric value of value.
    185 */
    186 JSValueRef JSNumberMake(double value);
     185@param number   The double to assign to the newly created JSValue.
     186@result         A JSValue of the number type, representing the value of number.
     187*/
     188JSValueRef JSValueMakeNumber(double number);
    187189
    188190/*!
    189191@function
    190192@abstract       Creates a JavaScript value of the string type.
    191 @param string   The JSInternalString to assign to the newly created JSValue. The
     193@param string   The JSString to assign to the newly created JSValue. The
    192194 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);
     195@result         A JSValue of the string type, representing the value of string.
     196*/
     197JSValueRef JSValueMakeString(JSStringRef string);
    196198
    197199// Converting to primitive values
     
    217219/*!
    218220@function
    219 @abstract       Converts a JavaScript value to string and copies the resulting
    220  string into a newly allocated JavaScript string.
    221 @param context  The execution context to use.
    222 @param value    The JSValue to convert.
    223 @result         A JSInternalString containing the result of conversion, or an empty
    224  string if conversion fails. Ownership follows the copy rule.
    225 */
    226 JSInternalStringRef JSValueCopyStringValue(JSContextRef context, JSValueRef value);
     221@abstract       Converts a JavaScript value to string and copies the result into a JavaScript string.
     222@param context  The execution context to use.
     223@param value    The JSValue to convert.
     224@result         A JSString with the result of conversion, or an empty string if conversion fails. Ownership follows the Create Rule.
     225*/
     226JSStringRef JSValueToStringCopy(JSContextRef context, JSValueRef value);
    227227
    228228/*!
     
    243243 equal number of times before becoming eligible for garbage collection.
    244244*/
    245 void JSGCProtect(JSValueRef value);
     245void JSValueProtect(JSValueRef value);
    246246
    247247/*!
     
    252252 equal number of times before becoming eligible for garbage collection.
    253253*/
    254 void JSGCUnprotect(JSValueRef value);
     254void JSValueUnprotect(JSValueRef value);
    255255
    256256/*!
     
    258258@abstract Performs a JavaScript garbage collection.
    259259@discussion JavaScript values that are on the machine stack, in a register,
    260  protected by JSGCProtect, set as the global object of an execution context, or reachable from any such
    261  value will not be collected. It is not normally necessary to call this function
    262  directly; the JS runtime will garbage collect as needed.
    263 */
    264 void JSGCCollect(void);
     260 protected by JSValueProtect, set as the global object of an execution context,
     261 or reachable from any such value will not be collected.
     262 
     263 You are not required to call this function; the JavaScript engine will garbage
     264 collect as needed.
     265*/
     266void JSGarbageCollect(void);
    265267
    266268#ifdef __cplusplus
  • trunk/JavaScriptCore/API/JavaScriptCore.h

    r15328 r15376  
    2828#define JavaScriptCore_h
    2929
    30 #include <stdbool.h>
    31 #include <stddef.h> // for size_t
    32 
    3330#include <JavaScriptCore/JSBase.h>
     31#include <JavaScriptCore/JSContextRef.h>
    3432#include <JavaScriptCore/JSInternalStringRef.h>
    35 #include <JavaScriptCore/JSContextRef.h>
    3633#include <JavaScriptCore/JSObjectRef.h>
    3734#include <JavaScriptCore/JSValueRef.h>
  • trunk/JavaScriptCore/API/minidom.c

    r15328 r15376  
    4040    JSObjectRef globalObject = JSContextGetGlobalObject(context);
    4141   
    42     JSInternalStringRef printIString = JSInternalStringCreateUTF8("print");
    43     JSObjectSetProperty(context, globalObject, printIString, JSFunctionMake(context, print), kJSPropertyAttributeNone);
    44     JSInternalStringRelease(printIString);
     42    JSStringRef printIString = JSStringCreateWithUTF8CString("print");
     43    JSObjectSetProperty(context, globalObject, printIString, JSObjectMakeFunction(context, print), kJSPropertyAttributeNone);
     44    JSStringRelease(printIString);
    4545   
    46     JSInternalStringRef node = JSInternalStringCreateUTF8("Node");
    47     JSObjectSetProperty(context, globalObject, node, JSConstructorMake(context, JSNode_construct), kJSPropertyAttributeNone);
    48     JSInternalStringRelease(node);
     46    JSStringRef node = JSStringCreateWithUTF8CString("Node");
     47    JSObjectSetProperty(context, globalObject, node, JSObjectMakeConstructor(context, JSNode_construct), kJSPropertyAttributeNone);
     48    JSStringRelease(node);
    4949   
    5050    char* scriptUTF8 = createStringWithContentsOfFile("minidom.js");
    51     JSInternalStringRef script = JSInternalStringCreateUTF8(scriptUTF8);
     51    JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8);
    5252    JSValueRef exception;
    5353    JSValueRef result = JSEvaluate(context, script, NULL, NULL, 0, &exception);
     
    5656    else {
    5757        printf("FAIL: Test script threw exception:\n");
    58         JSInternalStringRef exceptionIString = JSValueCopyStringValue(context, exception);
    59         CFStringRef exceptionCF = CFStringCreateWithJSInternalString(kCFAllocatorDefault, exceptionIString);
     58        JSStringRef exceptionIString = JSValueToStringCopy(context, exception);
     59        CFStringRef exceptionCF = JSStringCopyCFString(kCFAllocatorDefault, exceptionIString);
    6060        CFShow(exceptionCF);
    6161        CFRelease(exceptionCF);
    62         JSInternalStringRelease(exceptionIString);
     62        JSStringRelease(exceptionIString);
    6363    }
    64     JSInternalStringRelease(script);
     64    JSStringRelease(script);
    6565    free(scriptUTF8);
    6666
     
    7171        (void)o;
    7272    }
    73     JSGCCollect();
     73    JSGarbageCollect();
    7474#endif
    7575   
     
    8282{
    8383    if (argc > 0) {
    84         JSInternalStringRef string = JSValueCopyStringValue(context, argv[0]);
    85         size_t numChars = JSInternalStringGetMaxLengthUTF8(string);
     84        JSStringRef string = JSValueToStringCopy(context, argv[0]);
     85        size_t numChars = JSStringGetMaximumUTF8CStringSize(string);
    8686        char stringUTF8[numChars];
    87         JSInternalStringGetCharactersUTF8(string, stringUTF8, numChars);
     87        JSStringGetUTF8CString(string, stringUTF8, numChars);
    8888        printf("%s\n", stringUTF8);
    8989    }
    9090   
    91     return JSUndefinedMake();
     91    return JSValueMakeUndefined();
    9292}
    9393
  • trunk/JavaScriptCore/API/testapi.c

    r15328 r15376  
    5252static void assertEqualsAsUTF8String(JSValueRef value, const char* expectedValue)
    5353{
    54     JSInternalStringRef valueAsString = JSValueCopyStringValue(context, value);
    55 
    56     size_t jsSize = JSInternalStringGetMaxLengthUTF8(valueAsString);
     54    JSStringRef valueAsString = JSValueToStringCopy(context, value);
     55
     56    size_t jsSize = JSStringGetMaximumUTF8CStringSize(valueAsString);
    5757    char jsBuffer[jsSize];
    58     JSInternalStringGetCharactersUTF8(valueAsString, jsBuffer, jsSize);
     58    JSStringGetUTF8CString(valueAsString, jsBuffer, jsSize);
    5959   
    6060    if (strcmp(jsBuffer, expectedValue) != 0)
     
    6464        fprintf(stderr, "assertEqualsAsUTF8String failed: jsSize was too small\n");
    6565
    66     JSInternalStringRelease(valueAsString);
     66    JSStringRelease(valueAsString);
    6767}
    6868
     
    7070static void assertEqualsAsCharactersPtr(JSValueRef value, const char* expectedValue)
    7171{
    72     JSInternalStringRef valueAsString = JSValueCopyStringValue(context, value);
    73 
    74     size_t jsLength = JSInternalStringGetLength(valueAsString);
    75     const JSChar* jsBuffer = JSInternalStringGetCharactersPtr(valueAsString);
     72    JSStringRef valueAsString = JSValueToStringCopy(context, value);
     73
     74    size_t jsLength = JSStringGetLength(valueAsString);
     75    const JSChar* jsBuffer = JSStringGetCharactersPtr(valueAsString);
    7676
    7777    CFStringRef expectedValueAsCFString = CFStringCreateWithCString(kCFAllocatorDefault,
     
    8989        fprintf(stderr, "assertEqualsAsCharactersPtr failed: jsLength(%ld) != cfLength(%ld)\n", jsLength, cfLength);
    9090   
    91     JSInternalStringRelease(valueAsString);
    92 }
    93 
    94 static void assertEqualsAsCharacters(JSValueRef value, const char* expectedValue)
    95 {
    96     JSInternalStringRef valueAsString = JSValueCopyStringValue(context, value);
    97    
    98     size_t jsLength = JSInternalStringGetLength(valueAsString);
    99     JSChar jsBuffer[jsLength];
    100     JSInternalStringGetCharacters(valueAsString, jsBuffer, jsLength);
    101    
    102     CFStringRef expectedValueAsCFString = CFStringCreateWithCString(kCFAllocatorDefault,
    103                                                                     expectedValue,
    104                                                                     kCFStringEncodingUTF8);   
    105     CFIndex cfLength = CFStringGetLength(expectedValueAsCFString);
    106     UniChar cfBuffer[cfLength];
    107     CFStringGetCharacters(expectedValueAsCFString, CFRangeMake(0, cfLength), cfBuffer);
    108     CFRelease(expectedValueAsCFString);
    109    
    110     if (memcmp(jsBuffer, cfBuffer, cfLength * sizeof(UniChar)) != 0)
    111         fprintf(stderr, "assertEqualsAsCharacters failed: jsBuffer != cfBuffer\n");
    112    
    113     if (jsLength != (size_t)cfLength)
    114         fprintf(stderr, "assertEqualsAsCharacters failed: jsLength(%ld) != cfLength(%ld)\n", jsLength, cfLength);
    115    
    116     JSInternalStringRelease(valueAsString);
    117 }
    118 #endif // __APPLE__
    119 
    120 static JSValueRef jsGlobalValue; // non-stack value for testing JSGCProtect()
     91    JSStringRelease(valueAsString);
     92}
     93
     94#endif // __APPLE__
     95
     96static JSValueRef jsGlobalValue; // non-stack value for testing JSValueProtect()
    12197
    12298/* MyObject pseudo-class */
     
    130106}
    131107
    132 static bool MyObject_hasProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* exception)
    133 {
    134     UNUSED_PARAM(context);
    135     UNUSED_PARAM(object);
    136 
    137     if (JSInternalStringIsEqualUTF8(propertyName, "alwaysOne")
    138         || JSInternalStringIsEqualUTF8(propertyName, "cantFind")
    139         || JSInternalStringIsEqualUTF8(propertyName, "myPropertyName")) {
     108static bool MyObject_hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
     109{
     110    UNUSED_PARAM(context);
     111    UNUSED_PARAM(object);
     112
     113    if (JSStringIsEqualToUTF8CString(propertyName, "alwaysOne")
     114        || JSStringIsEqualToUTF8CString(propertyName, "cantFind")
     115        || JSStringIsEqualToUTF8CString(propertyName, "myPropertyName")) {
    140116        return true;
    141117    }
     
    144120}
    145121
    146 static bool MyObject_getProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception)
    147 {
    148     UNUSED_PARAM(context);
    149     UNUSED_PARAM(object);
    150    
    151     if (JSInternalStringIsEqualUTF8(propertyName, "alwaysOne")) {
    152         *returnValue = JSNumberMake(1);
     122static JSValueRef MyObject_getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
     123{
     124    UNUSED_PARAM(context);
     125    UNUSED_PARAM(object);
     126   
     127    if (JSStringIsEqualToUTF8CString(propertyName, "alwaysOne")) {
     128        return JSValueMakeNumber(1);
     129    }
     130   
     131    if (JSStringIsEqualToUTF8CString(propertyName, "myPropertyName")) {
     132        return JSValueMakeNumber(1);
     133    }
     134
     135    if (JSStringIsEqualToUTF8CString(propertyName, "cantFind")) {
     136        return JSValueMakeUndefined();
     137    }
     138   
     139    return NULL;
     140}
     141
     142static bool MyObject_setProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
     143{
     144    UNUSED_PARAM(context);
     145    UNUSED_PARAM(object);
     146    UNUSED_PARAM(value);
     147
     148    if (JSStringIsEqualToUTF8CString(propertyName, "cantSet"))
     149        return true; // pretend we set the property in order to swallow it
     150   
     151    return false;
     152}
     153
     154static bool MyObject_deleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
     155{
     156    UNUSED_PARAM(context);
     157    UNUSED_PARAM(object);
     158   
     159    if (JSStringIsEqualToUTF8CString(propertyName, "cantDelete"))
    153160        return true;
    154     }
    155    
    156     if (JSInternalStringIsEqualUTF8(propertyName, "myPropertyName")) {
    157         *returnValue = JSNumberMake(1);
    158         return true;
    159     }
    160 
    161     if (JSInternalStringIsEqualUTF8(propertyName, "cantFind")) {
    162         *returnValue = JSUndefinedMake();
    163         return true;
    164     }
    165161   
    166162    return false;
    167163}
    168164
    169 static bool MyObject_setProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef value, JSValueRef* exception)
    170 {
    171     UNUSED_PARAM(context);
    172     UNUSED_PARAM(object);
    173     UNUSED_PARAM(value);
    174 
    175     if (JSInternalStringIsEqualUTF8(propertyName, "cantSet"))
    176         return true; // pretend we set the property in order to swallow it
    177    
    178     return false;
    179 }
    180 
    181 static bool MyObject_deleteProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* exception)
    182 {
    183     UNUSED_PARAM(context);
    184     UNUSED_PARAM(object);
    185    
    186     if (JSInternalStringIsEqualUTF8(propertyName, "cantDelete"))
    187         return true;
    188    
    189     return false;
    190 }
    191 
    192165static void MyObject_getPropertyList(JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList, JSValueRef* exception)
    193166{
    194167    UNUSED_PARAM(context);
    195168   
    196     JSInternalStringRef propertyName;
    197    
    198     propertyName = JSInternalStringCreateUTF8("alwaysOne");
     169    JSStringRef propertyName;
     170   
     171    propertyName = JSStringCreateWithUTF8CString("alwaysOne");
    199172    JSPropertyListAdd(propertyList, object, propertyName);
    200     JSInternalStringRelease(propertyName);
    201    
    202     propertyName = JSInternalStringCreateUTF8("myPropertyName");
     173    JSStringRelease(propertyName);
     174   
     175    propertyName = JSStringCreateWithUTF8CString("myPropertyName");
    203176    JSPropertyListAdd(propertyList, object, propertyName);
    204     JSInternalStringRelease(propertyName);
     177    JSStringRelease(propertyName);
    205178}
    206179
     
    211184    UNUSED_PARAM(thisObject);
    212185
    213     if (argc > 0 && JSValueIsStrictEqual(context, argv[0], JSNumberMake(0)))
    214         return JSNumberMake(1);
    215    
    216     return JSUndefinedMake();
     186    if (argc > 0 && JSValueIsStrictEqual(context, argv[0], JSValueMakeNumber(0)))
     187        return JSValueMakeNumber(1);
     188   
     189    return JSValueMakeUndefined();
    217190}
    218191
     
    222195    UNUSED_PARAM(object);
    223196
    224     if (argc > 0 && JSValueIsStrictEqual(context, argv[0], JSNumberMake(0)))
    225         return JSValueToObject(context, JSNumberMake(1));
    226    
    227     return JSValueToObject(context, JSNumberMake(0));
    228 }
    229 
    230 static bool MyObject_convertToType(JSContextRef context, JSObjectRef object, JSTypeCode typeCode, JSValueRef* returnValue, JSValueRef* exception)
    231 {
    232     UNUSED_PARAM(context);
    233     UNUSED_PARAM(object);
    234    
    235     switch (typeCode) {
     197    if (argc > 0 && JSValueIsStrictEqual(context, argv[0], JSValueMakeNumber(0)))
     198        return JSValueToObject(context, JSValueMakeNumber(1));
     199   
     200    return JSValueToObject(context, JSValueMakeNumber(0));
     201}
     202
     203static JSValueRef MyObject_convertToType(JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception)
     204{
     205    UNUSED_PARAM(context);
     206    UNUSED_PARAM(object);
     207   
     208    switch (type) {
    236209    case kJSTypeBoolean:
    237         *returnValue = JSBooleanMake(false); // default object conversion is 'true'
    238         return true;
     210        return JSValueMakeBoolean(false); // default object conversion is 'true'
    239211    case kJSTypeNumber:
    240         *returnValue = JSNumberMake(1);
    241         return true;
     212        return JSValueMakeNumber(1);
    242213    default:
    243214        break;
    244215    }
    245216
    246     // string
    247     return false;
     217    // string conversion -- forward to default object class
     218    return NULL;
    248219}
    249220
     
    286257   
    287258    if (argc > 0) {
    288         JSInternalStringRef string = JSValueCopyStringValue(context, argv[0]);
    289         size_t sizeUTF8 = JSInternalStringGetMaxLengthUTF8(string);
     259        JSStringRef string = JSValueToStringCopy(context, argv[0]);
     260        size_t sizeUTF8 = JSStringGetMaximumUTF8CStringSize(string);
    290261        char stringUTF8[sizeUTF8];
    291         JSInternalStringGetCharactersUTF8(string, stringUTF8, sizeUTF8);
     262        JSStringGetUTF8CString(string, stringUTF8, sizeUTF8);
    292263        printf("%s\n", stringUTF8);
    293         JSInternalStringRelease(string);
    294     }
    295    
    296     return JSUndefinedMake();
     264        JSStringRelease(string);
     265    }
     266   
     267    return JSValueMakeUndefined();
    297268}
    298269
     
    303274    JSObjectRef result = JSObjectMake(context, NULL, 0);
    304275    if (argc > 0) {
    305         JSInternalStringRef value = JSInternalStringCreateUTF8("value");
     276        JSStringRef value = JSStringCreateWithUTF8CString("value");
    306277        JSObjectSetProperty(context, result, value, argv[0], kJSPropertyAttributeNone);
    307         JSInternalStringRelease(value);
     278        JSStringRelease(value);
    308279    }
    309280   
     
    320291    context = JSContextCreate(NULL);
    321292
    322     JSValueRef jsUndefined = JSUndefinedMake();
    323     JSValueRef jsNull = JSNullMake();
    324     JSValueRef jsTrue = JSBooleanMake(true);
    325     JSValueRef jsFalse = JSBooleanMake(false);
    326     JSValueRef jsZero = JSNumberMake(0);
    327     JSValueRef jsOne = JSNumberMake(1);
    328     JSValueRef jsOneThird = JSNumberMake(1.0 / 3.0);
    329     JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, JSNullMake());
     293    JSValueRef jsUndefined = JSValueMakeUndefined();
     294    JSValueRef jsNull = JSValueMakeNull();
     295    JSValueRef jsTrue = JSValueMakeBoolean(true);
     296    JSValueRef jsFalse = JSValueMakeBoolean(false);
     297    JSValueRef jsZero = JSValueMakeNumber(0);
     298    JSValueRef jsOne = JSValueMakeNumber(1);
     299    JSValueRef jsOneThird = JSValueMakeNumber(1.0 / 3.0);
     300    JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, JSValueMakeNull());
    330301
    331302    // FIXME: test funny utf8 characters
    332     JSInternalStringRef jsEmptyIString = JSInternalStringCreateUTF8("");
    333     JSValueRef jsEmptyString = JSStringMake(jsEmptyIString);
    334    
    335     JSInternalStringRef jsOneIString = JSInternalStringCreateUTF8("1");
    336     JSValueRef jsOneString = JSStringMake(jsOneIString);
     303    JSStringRef jsEmptyIString = JSStringCreateWithUTF8CString("");
     304    JSValueRef jsEmptyString = JSValueMakeString(jsEmptyIString);
     305   
     306    JSStringRef jsOneIString = JSStringCreateWithUTF8CString("1");
     307    JSValueRef jsOneString = JSValueMakeString(jsOneIString);
    337308
    338309#if defined(__APPLE__)
     
    345316                                                          kCFAllocatorNull);
    346317
    347     JSInternalStringRef jsCFIString = JSInternalStringCreateCF(cfString);
    348     JSValueRef jsCFString = JSStringMake(jsCFIString);
     318    JSStringRef jsCFIString = JSStringCreateWithCFString(cfString);
     319    JSValueRef jsCFString = JSValueMakeString(jsCFIString);
    349320   
    350321    CFStringRef cfEmptyString = CFStringCreateWithCString(kCFAllocatorDefault, "", kCFStringEncodingUTF8);
    351322   
    352     JSInternalStringRef jsCFEmptyIString = JSInternalStringCreateCF(cfEmptyString);
    353     JSValueRef jsCFEmptyString = JSStringMake(jsCFEmptyIString);
     323    JSStringRef jsCFEmptyIString = JSStringCreateWithCFString(cfEmptyString);
     324    JSValueRef jsCFEmptyString = JSValueMakeString(jsCFEmptyIString);
    354325
    355326    CFIndex cfStringLength = CFStringGetLength(cfString);
     
    358329                          CFRangeMake(0, cfStringLength),
    359330                          buffer);
    360     JSInternalStringRef jsCFIStringWithCharacters = JSInternalStringCreate(buffer, cfStringLength);
    361     JSValueRef jsCFStringWithCharacters = JSStringMake(jsCFIStringWithCharacters);
    362    
    363     JSInternalStringRef jsCFEmptyIStringWithCharacters = JSInternalStringCreate(buffer, CFStringGetLength(cfEmptyString));
    364     JSValueRef jsCFEmptyStringWithCharacters = JSStringMake(jsCFEmptyIStringWithCharacters);
     331    JSStringRef jsCFIStringWithCharacters = JSStringCreateWithCharacters(buffer, cfStringLength);
     332    JSValueRef jsCFStringWithCharacters = JSValueMakeString(jsCFIStringWithCharacters);
     333   
     334    JSStringRef jsCFEmptyIStringWithCharacters = JSStringCreateWithCharacters(buffer, CFStringGetLength(cfEmptyString));
     335    JSValueRef jsCFEmptyStringWithCharacters = JSValueMakeString(jsCFEmptyIStringWithCharacters);
    365336#endif // __APPLE__
    366337
     
    435406#endif // __APPLE__
    436407   
    437     assertEqualsAsCharacters(jsUndefined, "undefined");
    438     assertEqualsAsCharacters(jsNull, "null");
    439     assertEqualsAsCharacters(jsTrue, "true");
    440     assertEqualsAsCharacters(jsFalse, "false");
    441     assertEqualsAsCharacters(jsZero, "0");
    442     assertEqualsAsCharacters(jsOne, "1");
    443     assertEqualsAsCharacters(jsOneThird, "0.3333333333333333");
    444     assertEqualsAsCharacters(jsEmptyString, "");
    445     assertEqualsAsCharacters(jsOneString, "1");
    446 #if defined(__APPLE__)
    447     assertEqualsAsCharacters(jsCFString, "A");
    448     assertEqualsAsCharacters(jsCFStringWithCharacters, "A");
    449     assertEqualsAsCharacters(jsCFEmptyString, "");
    450     assertEqualsAsCharacters(jsCFEmptyStringWithCharacters, "");
    451 #endif // __APPLE__
    452    
    453408    assertEqualsAsUTF8String(jsUndefined, "undefined");
    454409    assertEqualsAsUTF8String(jsNull, "null");
     
    474429   
    475430#if defined(__APPLE__)
    476     CFStringRef cfJSString = CFStringCreateWithJSInternalString(kCFAllocatorDefault, jsCFIString);
    477     CFStringRef cfJSEmptyString = CFStringCreateWithJSInternalString(kCFAllocatorDefault, jsCFEmptyIString);
     431    CFStringRef cfJSString = JSStringCopyCFString(kCFAllocatorDefault, jsCFIString);
     432    CFStringRef cfJSEmptyString = JSStringCopyCFString(kCFAllocatorDefault, jsCFEmptyIString);
    478433    assert(CFEqual(cfJSString, cfString));
    479434    assert(CFEqual(cfJSEmptyString, cfEmptyString));
     
    486441   
    487442    jsGlobalValue = JSObjectMake(context, NULL, NULL);
    488     JSGCProtect(jsGlobalValue);
    489     JSGCCollect();
     443    JSValueProtect(jsGlobalValue);
     444    JSGarbageCollect();
    490445    assert(JSValueIsObject(jsGlobalValue));
    491     JSGCUnprotect(jsGlobalValue);
     446    JSValueUnprotect(jsGlobalValue);
    492447
    493448    /* JSInterpreter.h */
     
    496451    assert(JSValueIsObject(globalObject));
    497452
    498     JSInternalStringRef goodSyntax = JSInternalStringCreateUTF8("x = 1;");
    499     JSInternalStringRef badSyntax = JSInternalStringCreateUTF8("x := 1;");
     453    JSStringRef goodSyntax = JSStringCreateWithUTF8CString("x = 1;");
     454    JSStringRef badSyntax = JSStringCreateWithUTF8CString("x := 1;");
    500455    assert(JSCheckSyntax(context, goodSyntax, NULL, 0, NULL));
    501456    assert(!JSCheckSyntax(context, badSyntax, NULL, 0, NULL));
     
    515470    assert(JSValueIsObject(exception));
    516471   
    517     JSInternalStringRef array = JSInternalStringCreateUTF8("Array");
     472    JSStringRef array = JSStringCreateWithUTF8CString("Array");
    518473    v = JSObjectGetProperty(context, globalObject, array);
    519474    assert(v);
    520475    JSObjectRef arrayConstructor = JSValueToObject(context, v);
    521     JSInternalStringRelease(array);
     476    JSStringRelease(array);
    522477    result = JSObjectCallAsConstructor(context, arrayConstructor, 0, NULL, NULL);
    523478    assert(result);
    524     assert(JSValueIsInstanceOf(context, result, arrayConstructor));
    525     assert(!JSValueIsInstanceOf(context, JSNullMake(), arrayConstructor));
    526    
    527     JSInternalStringRef functionBody;
     479    assert(JSValueIsInstanceOfConstructor(context, result, arrayConstructor));
     480    assert(!JSValueIsInstanceOfConstructor(context, JSValueMakeNull(), arrayConstructor));
     481   
     482    JSStringRef functionBody;
    528483   
    529484    exception = NULL;
    530     functionBody = JSInternalStringCreateUTF8("rreturn Array;");
    531     JSInternalStringRef line = JSInternalStringCreateUTF8("line");
    532     assert(!JSFunctionMakeWithBody(context, functionBody, NULL, 1, &exception));
     485    functionBody = JSStringCreateWithUTF8CString("rreturn Array;");
     486    JSStringRef line = JSStringCreateWithUTF8CString("line");
     487    assert(!JSObjectMakeFunctionWithBody(context, functionBody, NULL, 1, &exception));
    533488    assert(JSValueIsObject(exception));
    534489    v = JSObjectGetProperty(context, JSValueToObject(context, exception), line);
    535490    assert(v);
    536491    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)
    537     JSInternalStringRelease(functionBody);
    538     JSInternalStringRelease(line);
    539 
    540     functionBody = JSInternalStringCreateUTF8("return Array;");
    541     JSObjectRef function = JSFunctionMakeWithBody(context, functionBody, NULL, 1, NULL);
    542     JSInternalStringRelease(functionBody);
     492    JSStringRelease(functionBody);
     493    JSStringRelease(line);
     494
     495    functionBody = JSStringCreateWithUTF8CString("return Array;");
     496    JSObjectRef function = JSObjectMakeFunctionWithBody(context, functionBody, NULL, 1, NULL);
     497    JSStringRelease(functionBody);
    543498
    544499    assert(JSObjectIsFunction(function));
     
    548503    JSObjectRef myObject = JSObjectMake(context, MyObject_class(context), NULL);
    549504    assert(didInitialize);
    550     JSInternalStringRef myObjectIString = JSInternalStringCreateUTF8("MyObject");
     505    JSStringRef myObjectIString = JSStringCreateWithUTF8CString("MyObject");
    551506    JSObjectSetProperty(context, globalObject, myObjectIString, myObject, kJSPropertyAttributeNone);
    552     JSInternalStringRelease(myObjectIString);
    553 
    554     JSInternalStringRef print = JSInternalStringCreateUTF8("print");
    555     JSObjectRef printFunction = JSFunctionMake(context, print_callAsFunction);
     507    JSStringRelease(myObjectIString);
     508
     509    JSStringRef print = JSStringCreateWithUTF8CString("print");
     510    JSObjectRef printFunction = JSObjectMakeFunction(context, print_callAsFunction);
    556511    JSObjectSetProperty(context, globalObject, print, printFunction, kJSPropertyAttributeNone);
    557     JSInternalStringRelease(print);
     512    JSStringRelease(print);
    558513   
    559514    assert(JSObjectSetPrivate(printFunction, (void*)1));
    560515    assert(JSObjectGetPrivate(printFunction) == (void*)1);
    561516
    562     JSInternalStringRef myConstructorIString = JSInternalStringCreateUTF8("MyConstructor");
    563     JSObjectRef myConstructor = JSConstructorMake(context, myConstructor_callAsConstructor);
     517    JSStringRef myConstructorIString = JSStringCreateWithUTF8CString("MyConstructor");
     518    JSObjectRef myConstructor = JSObjectMakeConstructor(context, myConstructor_callAsConstructor);
    564519    JSObjectSetProperty(context, globalObject, myConstructorIString, myConstructor, kJSPropertyAttributeNone);
    565     JSInternalStringRelease(myConstructorIString);
     520    JSStringRelease(myConstructorIString);
    566521   
    567522    assert(JSObjectSetPrivate(myConstructor, (void*)1));
     
    569524   
    570525    o = JSObjectMake(context, NULL, NULL);
    571     JSObjectSetProperty(context, o, jsOneIString, JSNumberMake(1), kJSPropertyAttributeNone);
    572     JSObjectSetProperty(context, o, jsCFIString,  JSNumberMake(1), kJSPropertyAttributeDontEnum);
     526    JSObjectSetProperty(context, o, jsOneIString, JSValueMakeNumber(1), kJSPropertyAttributeNone);
     527    JSObjectSetProperty(context, o, jsCFIString,  JSValueMakeNumber(1), kJSPropertyAttributeDontEnum);
    573528    JSPropertyEnumeratorRef enumerator = JSObjectCreatePropertyEnumerator(context, o);
    574529    int count = 0;
    575     while (JSPropertyEnumeratorGetNext(enumerator))
     530    while (JSPropertyEnumeratorGetNextName(enumerator))
    576531        ++count;
    577532    JSPropertyEnumeratorRelease(enumerator);
     
    581536    JSClassRelease(nullCallbacksClass);
    582537   
    583     functionBody = JSInternalStringCreateUTF8("return this;");
    584     function = JSFunctionMakeWithBody(context, functionBody, NULL, 1, NULL);
    585     JSInternalStringRelease(functionBody);
     538    functionBody = JSStringCreateWithUTF8CString("return this;");
     539    function = JSObjectMakeFunctionWithBody(context, functionBody, NULL, 1, NULL);
     540    JSStringRelease(functionBody);
    586541    v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL);
    587542    assert(JSValueIsEqual(context, v, globalObject));
     
    590545   
    591546    char* scriptUTF8 = createStringWithContentsOfFile("testapi.js");
    592     JSInternalStringRef script = JSInternalStringCreateUTF8(scriptUTF8);
     547    JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8);
    593548    result = JSEvaluate(context, script, NULL, NULL, 1, &exception);
    594549    if (JSValueIsUndefined(result))
     
    596551    else {
    597552        printf("FAIL: Test script returned unexcpected value:\n");
    598         JSInternalStringRef exceptionIString = JSValueCopyStringValue(context, exception);
    599         CFStringRef exceptionCF = CFStringCreateWithJSInternalString(kCFAllocatorDefault, exceptionIString);
     553        JSStringRef exceptionIString = JSValueToStringCopy(context, exception);
     554        CFStringRef exceptionCF = JSStringCopyCFString(kCFAllocatorDefault, exceptionIString);
    600555        CFShow(exceptionCF);
    601556        CFRelease(exceptionCF);
    602         JSInternalStringRelease(exceptionIString);
    603     }
    604     JSInternalStringRelease(script);
     557        JSStringRelease(exceptionIString);
     558    }
     559    JSStringRelease(script);
    605560    free(scriptUTF8);
    606561
     
    608563    JSObjectMake(context, MyObject_class(context), 0);
    609564    JSObjectMake(context, MyObject_class(context), 0);
    610     JSGCCollect();
     565    JSGarbageCollect();
    611566    assert(didFinalize);
    612567
    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);
     568    JSStringRelease(jsEmptyIString);
     569    JSStringRelease(jsOneIString);
     570#if defined(__APPLE__)
     571    JSStringRelease(jsCFIString);
     572    JSStringRelease(jsCFEmptyIString);
     573    JSStringRelease(jsCFIStringWithCharacters);
     574    JSStringRelease(jsCFEmptyIStringWithCharacters);
     575#endif // __APPLE__
     576    JSStringRelease(goodSyntax);
     577    JSStringRelease(badSyntax);
    623578   
    624579    JSContextDestroy(context);
  • trunk/JavaScriptCore/ChangeLog

    r15328 r15376  
     12006-07-11  Geoffrey Garen  <[email protected]>
     2
     3        Reviewed by Maciej.
     4       
     5        - Implemented a vast number of renames and comment clarifications
     6        suggested during API review.
     7       
     8        JSInternalString -> JSString
     9        JS*Make -> JSValueMake*, JSObjectMake*
     10        JSTypeCode -> JSType
     11        JSValueIsInstanceOf -> JSValueIsInstanceOfConstructor (reads strangely well in client code)
     12        JSGC*Protect -> JSValue*Protect
     13        JS*Callback -> JSObject*Callback
     14        JSGetPropertyListCallback -> JSObjectAddPropertiesToListCallback
     15        JSPropertyEnumeratorGetNext -> JSPropertyEnumeratorGetNextName
     16        JSString* ->
     17            JSStringCreateWithUTF8CString, JSStringGetUTF8CString,
     18            JSStringGetMaximumUTF8CStringSize JSStringIsEqualToUTF8CString,
     19            JSStringCreateWithCFString, JSStringCopyCFString, JSStringCreateWithCharacters.
     20       
     21        - Changed functions taking a JSValue out arg and returning a bool indicating
     22        whether it was set to simply return a JSValue or NULL.
     23       
     24        - Removed JSStringGetCharacters because it's more documentation than code,
     25        and it's just a glorified memcpy built on existing API functionality.
     26       
     27        - Moved standard library includes into the headers that actually require them.
     28       
     29        - Standardized use of the phrase "Create Rule."
     30       
     31        - Removed JSLock from make functions that don't allocate.
     32       
     33        - Added exception handling to JSValueToBoolean, since we now allow
     34        callback objects to throw exceptions upon converting to boolean.
     35       
     36        - Renamed JSGCCollect to JSGarbageCollect.
     37
    1382006-07-10  Geoffrey Garen  <[email protected]>
    239
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r15321 r15376  
    22.objc_class_name_WebScriptObjectPrivate
    33.objc_class_name_WebUndefined
    4 _CFStringCreateWithJSInternalString
    5 _JSBooleanMake
    64_JSCheckSyntax
    75_JSClassCreate
    86_JSClassRelease
    97_JSClassRetain
    10 _JSConstructorMake
    118_JSContextCreate
    129_JSContextDestroy
    1310_JSContextGetGlobalObject
    1411_JSEvaluate
    15 _JSFunctionMake
    16 _JSFunctionMakeWithBody
    17 _JSGCCollect
    18 _JSGCProtect
    19 _JSGCUnprotect
    20 _JSInternalStringCreate
    21 _JSInternalStringCreateCF
    22 _JSInternalStringCreateUTF8
    23 _JSInternalStringGetCharacters
    24 _JSInternalStringGetCharactersPtr
    25 _JSInternalStringGetCharactersUTF8
    26 _JSInternalStringGetLength
    27 _JSInternalStringGetMaxLengthUTF8
    28 _JSInternalStringIsEqual
    29 _JSInternalStringIsEqualUTF8
    30 _JSInternalStringRelease
    31 _JSInternalStringRetain
    32 _JSNullMake
    33 _JSNumberMake
     12_JSGarbageCollect
    3413_JSObjectCallAsConstructor
    3514_JSObjectCallAsFunction
     
    4423_JSObjectIsFunction
    4524_JSObjectMake
     25_JSObjectMakeConstructor
     26_JSObjectMakeFunction
     27_JSObjectMakeFunctionWithBody
    4628_JSObjectSetPrivate
    4729_JSObjectSetProperty
    4830_JSObjectSetPrototype
    49 _JSPropertyEnumeratorGetNext
     31_JSPropertyEnumeratorGetNextName
    5032_JSPropertyEnumeratorRelease
    5133_JSPropertyEnumeratorRetain
    5234_JSPropertyListAdd
    53 _JSStringMake
    54 _JSUndefinedMake
    55 _JSValueCopyStringValue
     35_JSStringCopyCFString
     36_JSStringCreateWithCFString
     37_JSStringCreateWithCharacters
     38_JSStringCreateWithUTF8CString
     39_JSStringGetCharactersPtr
     40_JSStringGetLength
     41_JSStringGetMaximumUTF8CStringSize
     42_JSStringGetUTF8CString
     43_JSStringIsEqual
     44_JSStringIsEqualToUTF8CString
     45_JSStringRelease
     46_JSStringRetain
    5647_JSValueGetType
    5748_JSValueIsBoolean
    5849_JSValueIsEqual
    59 _JSValueIsInstanceOf
     50_JSValueIsInstanceOfConstructor
    6051_JSValueIsNull
    6152_JSValueIsNumber
     
    6556_JSValueIsString
    6657_JSValueIsUndefined
     58_JSValueMakeBoolean
     59_JSValueMakeNull
     60_JSValueMakeNumber
     61_JSValueMakeString
     62_JSValueMakeUndefined
     63_JSValueProtect
    6764_JSValueToBoolean
    6865_JSValueToNumber
    6966_JSValueToObject
     67_JSValueToStringCopy
     68_JSValueUnprotect
    7069_KJS_JSCreateNativeJSObject
    7170_KJS_JSObject_JSFinalize
Note: See TracChangeset for help on using the changeset viewer.