Changeset 15224 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Jul 7, 2006, 7:02:47 PM (19 years ago)
Author:
ggaren
Message:

Reviewed by Maciej.


More API action.


  • Headerdoc finished

Semantic Changes:

  • Added a JSContextRef argument to many functions, because you need a JSContextRef for doing virtually anything. I expect to add this argument to even more functions in a future patch.


  • Removed the globalObjectPrototype argument to JSContextCreate because you can't create an object until you have a context, so it's impossible to pass a prototype object to JSContextCreate. That's OK because (1) there's no reason to give the global object a prototype and (2) if you really want to, you can just use a separate call to JSObjectSetPrototype.


  • Removed the JSClassRef argument to JSClassCreate because it was unnecessary, and you need to be able to make the global object's class before you've created a JSContext.


  • Added an optional exception parameter to JSFunctionMakeWithBody because anything less would be uncivilized.


  • Made the return value parameter to JSObjectGetProperty optional to match all other return value parameters in the API.


  • Made JSObjectSetPrivate/JSObjectGetPrivate work on JSCallbackFunctions and JSCallbackConstructors. You could use an abstract base class or strategic placement of m_privateData in the class structure to implement this, but the former seemed like overkill, and the latter seemed too dangerous.


  • Fixed a bug where JSPropertyEnumeratorGetNext would skip the first property.

Cosmetic Changes:

  • Reversed the logic of the JSChar #ifdef to avoid confusing headerdoc


  • Removed function names from @function declarations because headeroc can parse them automatically, and I wanted to rule out manual mismatch.
  • Changed Error::create to take a const UString& instead of a UString* because it was looking at me funny.


  • Renamed JSStringBufferCreateWithCFString to JSStringBufferCreateCF because the latter is more concise and it matches JSStringBufferCreateUTF8.


  • API/JSCallbackObject.cpp: (KJS::JSCallbackObject::getOwnPropertySlot): (KJS::JSCallbackObject::put): (KJS::JSCallbackObject::deleteProperty): (KJS::JSCallbackObject::getPropertyList): (KJS::JSCallbackObject::toBoolean): (KJS::JSCallbackObject::toNumber): (KJS::JSCallbackObject::toString):
  • API/JSClassRef.cpp: (JSClassCreate):
  • API/JSContextRef.cpp: (JSContextCreate): (JSContextSetException):
  • API/JSContextRef.h:
  • API/JSNode.c: (JSNodePrototype_class): (JSNode_class):
  • API/JSNodeList.c: (JSNodeListPrototype_class): (JSNodeList_class):
  • API/JSObjectRef.cpp: (JSObjectGetProperty): (JSObjectGetPrivate): (JSObjectSetPrivate): (JSObjectCallAsFunction): (JSObjectCallAsConstructor): (JSPropertyEnumeratorGetNext):
  • API/JSObjectRef.h:
  • API/JSStringBufferRef.cpp: (JSStringBufferCreateCF):
  • API/JSStringBufferRef.h:
  • API/JSValueRef.cpp: (JSValueIsInstanceOf):
  • API/JSValueRef.h:
  • API/minidom.c: (main):
  • API/minidom.js:
  • API/testapi.c: (MyObject_hasProperty): (MyObject_setProperty): (MyObject_deleteProperty): (MyObject_getPropertyList): (MyObject_convertToType): (MyObject_class): (main):
  • JavaScriptCore.exp:
Location:
trunk/JavaScriptCore
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSCallbackObject.cpp

    r15168 r15224  
    8181bool JSCallbackObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
    8282{
     83    JSContextRef context = toRef(exec);
    8384    JSObjectRef thisRef = toRef(this);
    8485    JSStringBufferRef propertyNameRef = toRef(propertyName.ustring().rep());
     
    8788        // optional optimization to bypass getProperty in cases when we only need to know if the property exists
    8889        if (JSHasPropertyCallback hasPropertyCallback = jsClass->callbacks.hasProperty) {
    89             if (hasPropertyCallback(thisRef, propertyNameRef)) {
     90            if (hasPropertyCallback(context, thisRef, propertyNameRef)) {
    9091                slot.setCustom(this, callbackGetter);
    9192                return true;
     
    9394        } else if (JSGetPropertyCallback getPropertyCallback = jsClass->callbacks.getProperty) {
    9495            JSValueRef returnValue;
    95             if (getPropertyCallback(toRef(exec), thisRef, propertyNameRef, &returnValue)) {
     96            if (getPropertyCallback(context, thisRef, propertyNameRef, &returnValue)) {
    9697                // cache the value so we don't have to compute it again
    9798                // FIXME: This violates the PropertySlot design a little bit.
     
    129130void JSCallbackObject::put(ExecState* exec, const Identifier& propertyName, JSValue* value, int attr)
    130131{
     132    JSContextRef context = toRef(exec);
    131133    JSObjectRef thisRef = toRef(this);
    132134    JSStringBufferRef propertyNameRef = toRef(propertyName.ustring().rep());
     
    134136    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    135137        if (JSSetPropertyCallback setPropertyCallback = jsClass->callbacks.setProperty) {
    136             if (setPropertyCallback(thisRef, propertyNameRef, value))
     138            if (setPropertyCallback(context, thisRef, propertyNameRef, value))
    137139                return;
    138140        }
     
    143145                    return;
    144146                if (JSSetPropertyCallback setPropertyCallback = entry->setProperty) {
    145                     if (setPropertyCallback(thisRef, propertyNameRef, value))
     147                    if (setPropertyCallback(context, thisRef, propertyNameRef, value))
    146148                        return;
    147149                }
     
    168170bool JSCallbackObject::deleteProperty(ExecState* exec, const Identifier& propertyName)
    169171{
     172    JSContextRef context = toRef(exec);
    170173    JSObjectRef thisRef = toRef(this);
    171174    JSStringBufferRef propertyNameRef = toRef(propertyName.ustring().rep());
     
    173176    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    174177        if (JSDeletePropertyCallback deletePropertyCallback = jsClass->callbacks.deleteProperty) {
    175             if (deletePropertyCallback(thisRef, propertyNameRef))
     178            if (deletePropertyCallback(context, thisRef, propertyNameRef))
    176179                return true;
    177180        }
     
    260263void JSCallbackObject::getPropertyList(ExecState* exec, ReferenceList& propertyList, bool recursive)
    261264{
     265    JSContextRef context = toRef(exec);
    262266    JSObjectRef thisRef = toRef(this);
    263267
    264268    for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) {
    265269        if (JSGetPropertyListCallback getPropertyListCallback = jsClass->callbacks.getPropertyList)
    266             getPropertyListCallback(thisRef, toRef(&propertyList));
     270            getPropertyListCallback(context, thisRef, toRef(&propertyList));
    267271
    268272        if (__JSClass::StaticValuesTable* staticValues = jsClass->staticValues) {
     
    294298bool JSCallbackObject::toBoolean(ExecState* exec) const
    295299{
     300    JSContextRef context = toRef(exec);
    296301    JSObjectRef thisRef = toRef(this);
    297302
     
    299304        if (JSConvertToTypeCallback convertToTypeCallback = jsClass->callbacks.convertToType) {
    300305            JSValueRef returnValue;
    301             if (convertToTypeCallback(thisRef, kJSTypeBoolean, &returnValue))
     306            if (convertToTypeCallback(context, thisRef, kJSTypeBoolean, &returnValue))
    302307                return toJS(returnValue)->getBoolean();
    303308        }
     
    308313double JSCallbackObject::toNumber(ExecState* exec) const
    309314{
     315    JSContextRef context = toRef(exec);
    310316    JSObjectRef thisRef = toRef(this);
    311317
     
    313319        if (JSConvertToTypeCallback convertToTypeCallback = jsClass->callbacks.convertToType) {
    314320            JSValueRef returnValue;
    315             if (convertToTypeCallback(thisRef, kJSTypeNumber, &returnValue))
     321            if (convertToTypeCallback(context, thisRef, kJSTypeNumber, &returnValue))
    316322                return toJS(returnValue)->getNumber();
    317323        }
     
    322328UString JSCallbackObject::toString(ExecState* exec) const
    323329{
     330    JSContextRef context = toRef(exec);
    324331    JSObjectRef thisRef = toRef(this);
    325332
     
    327334        if (JSConvertToTypeCallback convertToTypeCallback = jsClass->callbacks.convertToType) {
    328335            JSValueRef returnValue;
    329             if (convertToTypeCallback(thisRef, kJSTypeString, &returnValue))
     336            if (convertToTypeCallback(context, thisRef, kJSTypeString, &returnValue))
    330337                return toJS(returnValue)->getString();
    331338        }
  • trunk/JavaScriptCore/API/JSClassRef.cpp

    r15213 r15224  
    3333const JSObjectCallbacks kJSObjectCallbacksNone = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    3434
    35 JSClassRef JSClassCreate(JSContextRef, JSStaticValue* staticValues, JSStaticFunction* staticFunctions, const JSObjectCallbacks* callbacks, JSClassRef parentClass)
     35JSClassRef JSClassCreate(JSStaticValue* staticValues, JSStaticFunction* staticFunctions, const JSObjectCallbacks* callbacks, JSClassRef parentClass)
    3636{
    3737    JSClassRef jsClass = new __JSClass;
  • trunk/JavaScriptCore/API/JSContextRef.cpp

    r15212 r15224  
    3535using namespace KJS;
    3636
    37 JSContextRef JSContextCreate(JSClassRef globalObjectClass, JSObjectRef globalObjectPrototype)
     37JSContextRef JSContextCreate(JSClassRef globalObjectClass)
    3838{
    3939    JSLock lock;
    4040
    41     JSObject* jsPrototype = toJS(globalObjectPrototype);
    42 
    4341    JSObject* globalObject;
    44     if (globalObjectClass) {
    45         if (jsPrototype)
    46             globalObject = new JSCallbackObject(globalObjectClass, jsPrototype);
    47         else
    48             globalObject = new JSCallbackObject(globalObjectClass);
    49     } else {
    50         // creates a slightly more efficient object
    51         if (jsPrototype)
    52             globalObject = new JSObject(jsPrototype);
    53         else
    54             globalObject = new JSObject();
    55     }
     42    if (globalObjectClass)
     43        globalObject = new JSCallbackObject(globalObjectClass);
     44    else
     45        globalObject = new JSObject();
    5646
    5747    Interpreter* interpreter = new Interpreter(globalObject); // adds the built-in object prototype to the global object
     
    131121    exec->setException(jsValue);
    132122}
    133 
  • trunk/JavaScriptCore/API/JSContextRef.h

    r15212 r15224  
    3535#endif
    3636
    37 JSContextRef JSContextCreate(JSClassRef globalObjectClass, JSObjectRef globalObjectPrototype);
     37/*!
     38@function
     39@abstract Creates a JavaScript execution context.
     40@discussion JSContextCreate allocates a global object and populates it with all the
     41 built-in JavaScript objects, such as Object, Function, String, and Array.
     42@param globalObjectClass The class to use when creating the JSContext's global object.
     43 Pass NULL to use the default object class.
     44@result A JSContext with a global object of class globalObjectClass.
     45*/
     46JSContextRef JSContextCreate(JSClassRef globalObjectClass);
     47
     48/*!
     49@function
     50@abstract       Destroys a JavaScript execution context, freeing its resources.
     51@param context  The JSContext to destroy.
     52*/
    3853void JSContextDestroy(JSContextRef context);
    3954
     55/*!
     56@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@result         context's global object.
     60*/
    4061JSObjectRef JSContextGetGlobalObject(JSContextRef context);
    4162
    42 JSValueRef JSContextGetException(JSContextRef context); // NULL if there is no exception
     63/*!
     64@function
     65@abstract       Returns the current exception in a JavaScript execution context.
     66@param context  The JSContext whose exception you want to retrieve.
     67@result         A JSValue representing context's exception, or NULL if no exception has been set.
     68*/
     69JSValueRef JSContextGetException(JSContextRef context);
     70/*!
     71@function
     72@abstract       Sets an exception in a JavaScript execution context.
     73@param context  The JSContext whose exception you want to set.
     74@param value    The exception you want to set.
     75*/
    4376void JSContextSetException(JSContextRef context, JSValueRef value);
     77/*!
     78@function
     79@abstract       Clears the exception in a JavaScript execution context.
     80@param context  The JSContext whose exception you want to clear.
     81*/
    4482void JSContextClearException(JSContextRef context);
    45    
     83
    4684// Evaluation
    4785/*!
    48   @function JSEvaluate
    49   Evaluates a string of JavaScript
    50   @param context            execution context to use
    51   @param script             a character buffer containing the JavaScript to evaluate
    52   @param thisObject         the object to use as "this," or NULL to use the global object as "this."
    53   @param sourceURL          URL to the file containing the JavaScript, or NULL - this is only used for error reporting
    54   @param startingLineNumber the JavaScript's starting line number in the file located at sourceURL - this is only used for error reporting
    55   @param exception          pointer to a JSValueRef in which to store an uncaught exception, if any; can be NULL
    56   @result                   result of evaluation, or NULL if an uncaught exception was thrown
     86@function
     87@abstract                 Evaluates a string of JavaScript.
     88@param context            The execution context to use.
     89@param script             A JSStringBuffer containing the script to evaluate.
     90@param thisObject         The object to use as "this," or NULL to use the global object as "this."
     91@param sourceURL          A JSStringBuffer 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.
     92@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.
     93@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.
     94@result                   The JSValue that results from evaluating script, or NULL if an uncaught exception is thrown.
    5795*/
    5896JSValueRef JSEvaluate(JSContextRef context, JSStringBufferRef script, JSObjectRef thisObject, JSStringBufferRef sourceURL, int startingLineNumber, JSValueRef* exception);
    5997
    6098/*!
    61   @function JSCheckSyntax
    62   Check for syntax errors in a string of JavaScript
    63   @param context            execution context to use
    64   @param script             a character buffer containing the JavaScript to evaluate
    65   @param sourceURL          URL to the file containing the JavaScript, or NULL - this is only used for error reporting
    66   @param startingLineNumber the JavaScript's starting line number in the file located at sourceURL - this is only used for error reporting
    67   @param exception          pointer to a JSValueRef in which to store a syntax error, if any; can be NULL
    68   @result                   true if the script is syntactically correct, false otherwise
    69 
     99@function JSCheckSyntax
     100@abstract                 Checks for syntax errors in a string of JavaScript.
     101@param context            The execution context to use.
     102@param script             A JSStringBuffer containing the JavaScript to check for syntax errors.
     103@param sourceURL          A JSStringBuffer 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.
     104@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.
     105@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.
     106@result                   true if the script is syntactically correct, otherwise false.
    70107*/
    71108bool JSCheckSyntax(JSContextRef context, JSStringBufferRef script, JSStringBufferRef sourceURL, int startingLineNumber, JSValueRef* exception);
  • trunk/JavaScriptCore/API/JSNode.c

    r15168 r15224  
    110110    static JSClassRef nodePrototypeClass;
    111111    if (!nodePrototypeClass)
    112         nodePrototypeClass = JSClassCreate(context, NULL, JSNodePrototype_staticFunctions, &kJSObjectCallbacksNone, NULL);
     112        nodePrototypeClass = JSClassCreate(NULL, JSNodePrototype_staticFunctions, &kJSObjectCallbacksNone, NULL);
    113113    return nodePrototypeClass;
    114114}
     
    170170        JSNode_callbacks.finalize = JSNode_finalize;
    171171       
    172         nodeClass = JSClassCreate(context, JSNode_staticValues, NULL, &JSNode_callbacks, NULL);
     172        nodeClass = JSClassCreate(JSNode_staticValues, NULL, &JSNode_callbacks, NULL);
    173173    }
    174174    return nodeClass;
  • trunk/JavaScriptCore/API/JSNodeList.c

    r15168 r15224  
    5151    static JSClassRef jsClass;
    5252    if (!jsClass) {
    53         jsClass = JSClassCreate(context, NULL, JSNodeListPrototype_staticFunctions, &kJSObjectCallbacksNone, NULL);
     53        jsClass = JSClassCreate(NULL, JSNodeListPrototype_staticFunctions, &kJSObjectCallbacksNone, NULL);
    5454    }
    5555   
     
    104104        callbacks.finalize = JSNodeList_finalize;
    105105       
    106         jsClass = JSClassCreate(context, JSNodeList_staticValues, NULL, &callbacks, NULL);
     106        jsClass = JSClassCreate(JSNodeList_staticValues, NULL, &callbacks, NULL);
    107107    }
    108108   
  • trunk/JavaScriptCore/API/JSObjectRef.cpp

    r15168 r15224  
    7171}
    7272
    73 JSObjectRef JSFunctionMakeWithBody(JSContextRef context, JSStringBufferRef body, JSStringBufferRef sourceURL, int startingLineNumber)
     73JSObjectRef JSFunctionMakeWithBody(JSContextRef context, JSStringBufferRef body, JSStringBufferRef sourceURL, int startingLineNumber, JSValueRef* exception)
    7474{
    7575    JSLock lock;
     
    7777    ExecState* exec = toJS(context);
    7878    UString::Rep* bodyRep = toJS(body);
    79     UString::Rep* sourceURLRep = toJS(sourceURL);
     79    UString jsSourceURL = UString(toJS(sourceURL));
     80
    8081    if (!bodyRep)
    8182        bodyRep = &UString::Rep::null;
    82     RefPtr<FunctionBodyNode> bodyNode = Parser::parse(UString(sourceURLRep), startingLineNumber, bodyRep->data(), bodyRep->size(), NULL, NULL, NULL);
    83     if (!bodyNode)
     83   
     84    int sid;
     85    int errLine;
     86    UString errMsg;
     87    RefPtr<FunctionBodyNode> bodyNode = Parser::parse(jsSourceURL, startingLineNumber, bodyRep->data(), bodyRep->size(), &sid, &errLine, &errMsg);
     88    if (!bodyNode) {
     89        if (exception)
     90            *exception = Error::create(exec, SyntaxError, errMsg, errLine, sid, jsSourceURL);
    8491        return NULL;
     92    }
    8593
    8694    ScopeChain scopeChain;
     
    127135    UString::Rep* nameRep = toJS(propertyName);
    128136
    129     *value = toRef(jsObject->get(exec, Identifier(nameRep)));
    130     return !JSValueIsUndefined(*value);
     137    JSValue* jsValue = jsObject->get(exec, Identifier(nameRep));
     138    if (value)
     139        *value = toRef(jsValue);
     140    return !jsValue->isUndefined();
    131141}
    132142
     
    161171    JSObject* jsObject = toJS(object);
    162172   
    163     if (!jsObject->inherits(&JSCallbackObject::info))
    164         return 0;
    165    
    166     return static_cast<JSCallbackObject*>(jsObject)->getPrivate();
     173    if (jsObject->inherits(&JSCallbackObject::info))
     174        return static_cast<JSCallbackObject*>(jsObject)->getPrivate();
     175   
     176    if (jsObject->inherits(&JSCallbackFunction::info))
     177        return static_cast<JSCallbackFunction*>(jsObject)->getPrivate();
     178   
     179    if (jsObject->inherits(&JSCallbackConstructor::info))
     180        return static_cast<JSCallbackConstructor*>(jsObject)->getPrivate();
     181   
     182    return 0;
    167183}
    168184
     
    171187    JSObject* jsObject = toJS(object);
    172188   
    173     if (!jsObject->inherits(&JSCallbackObject::info))
    174         return false;
    175    
    176     static_cast<JSCallbackObject*>(jsObject)->setPrivate(data);
    177     return true;
     189    if (jsObject->inherits(&JSCallbackObject::info)) {
     190        static_cast<JSCallbackObject*>(jsObject)->setPrivate(data);
     191        return true;
     192    }
     193       
     194    if (jsObject->inherits(&JSCallbackFunction::info)) {
     195        static_cast<JSCallbackFunction*>(jsObject)->setPrivate(data);
     196        return true;
     197    }
     198       
     199    if (jsObject->inherits(&JSCallbackConstructor::info)) {
     200        static_cast<JSCallbackConstructor*>(jsObject)->setPrivate(data);
     201        return true;
     202    }
     203   
     204    return false;
    178205}
    179206
     
    194221    for (size_t i = 0; i < argc; i++)
    195222        argList.append(toJS(argv[i]));
    196    
    197     JSValueRef result = toRef(jsObject->call(exec, jsThisObject, argList));
     223
     224    JSValueRef result = toRef(jsObject->call(exec, jsThisObject, argList)); // returns NULL if object->implementsCall() is false
    198225    if (exec->hadException()) {
    199226        if (exception)
     
    221248        argList.append(toJS(argv[i]));
    222249   
    223     JSObjectRef result = toRef(jsObject->construct(exec, argList));
     250    JSObjectRef result = toRef(jsObject->construct(exec, argList)); // returns NULL if object->implementsCall() is false
    224251    if (exec->hadException()) {
    225252        if (exception)
     
    260287    ReferenceListIterator& iterator = enumerator->iterator;
    261288    if (iterator != enumerator->list.end()) {
     289        JSStringBufferRef result = toRef(iterator->getPropertyName(exec).ustring().rep());
    262290        iterator++;
    263         return toRef(iterator->getPropertyName(exec).ustring().rep());
     291        return result;
    264292    }
    265293    return 0;
  • trunk/JavaScriptCore/API/JSObjectRef.h

    r15168 r15224  
    3535#endif
    3636
     37/*!
     38@enum JSPropertyAttribute
     39@constant kJSPropertyAttributeNone         Specifies that a property has no special attributes.
     40@constant kJSPropertyAttributeReadOnly     Specifies that a property is read-only.
     41@constant kJSPropertyAttributeDontEnum     Specifies that a property should not be enumerated by JSPropertyEnumerators and JavaScript for...in loops.
     42@constant kJSPropertyAttributeDontDelete   Specifies that the delete operation should fail on a property.
     43*/
    3744enum {
    3845    kJSPropertyAttributeNone         = 0,
     
    4148    kJSPropertyAttributeDontDelete   = 1 << 3
    4249};
     50
     51/*!
     52@typedef JSPropertyAttributes
     53@abstract A set of JSPropertyAttributes. Combine multiple attributes by logically ORing them together.
     54*/
    4355typedef unsigned JSPropertyAttributes;
    4456
     57/*!
     58@typedef JSInitializeCallback
     59@abstract The callback invoked when an object is first created.
     60@param object The JSObject being created.
     61@discussion If you named your function Initialize, you would declare it like this:
     62
     63void Initialize(JSObjectRef object);
     64*/
     65
     66// FIXME: Needs to take a context argument, but can't because no context exists when we're creating the global object
    4567typedef void
    4668(*JSInitializeCallback)         (JSObjectRef object);
    4769
     70/*!
     71@typedef JSFinalizeCallback
     72@abstract The callback invoked when an object is finalized (prepared for garbage collection).
     73@param object The JSObject being finalized.
     74@discussion If you named your function Finalize, you would declare it like this:
     75
     76void Finalize(JSObjectRef object);
     77*/
    4878typedef void           
    4979(*JSFinalizeCallback)           (JSObjectRef object);
    5080
     81/*!
     82@typedef JSHasPropertyCallback
     83@abstract The callback invoked when determining whether an object has a given property.
     84@param context The current execution context.
     85@param object The JSObject to search for the property.
     86@param propertyName A JSStringBuffer containing the name of the property look up.
     87@result true if object has the property, otherwise false.
     88@discussion If you named your function HasProperty, you would declare it like this:
     89
     90bool HasProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName);
     91
     92This 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.
     93*/
    5194typedef bool
    52 (*JSHasPropertyCallback)        (JSObjectRef object, JSStringBufferRef propertyName);
    53 
     95(*JSHasPropertyCallback)        (JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName);
     96
     97/*!
     98@typedef JSGetPropertyCallback
     99@abstract The callback invoked when getting a property from an object.
     100@param context The current execution context.
     101@param object The JSObject to search for the property.
     102@param propertyName A JSStringBuffer containing the name of the property to get.
     103@param returnValue A pointer to a JSValue in which to store the property's value.
     104@result true if object has the property in question, otherwise false. If this function returns true, returnValue is assumed to contain a valid JSValue.
     105@discussion If you named your function GetProperty, you would declare it like this:
     106
     107bool GetProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName, JSValueRef* returnValue);
     108
     109If 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.
     110*/
    54111typedef bool
    55112(*JSGetPropertyCallback)        (JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName, JSValueRef* returnValue);
    56113
     114/*!
     115@typedef JSSetPropertyCallback
     116@abstract The callback invoked when setting the value of a given property.
     117@param context The current execution context.
     118@param object The JSObject on which to set the property's value.
     119@param propertyName A JSStringBuffer containing the name of the property to set.
     120@param value A JSValue to use as the property's value.
     121@result true if the property was successfully set, otherwise false.
     122@discussion If you named your function SetProperty, you would declare it like this:
     123
     124bool SetProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName, JSValueRef value);
     125
     126If 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).
     127*/
    57128typedef bool
    58 (*JSSetPropertyCallback)        (JSObjectRef object, JSStringBufferRef propertyName, JSValueRef value);
    59 
     129(*JSSetPropertyCallback)        (JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName, JSValueRef value);
     130
     131/*!
     132@typedef JSDeletePropertyCallback
     133@abstract The callback invoked when deleting a given property.
     134@param context The current execution context.
     135@param object The JSObject in which to delete the property.
     136@param propertyName A JSStringBuffer containing the name of the property to delete.
     137@result true if propertyName was successfully deleted, otherwise false.
     138@discussion If you named your function DeleteProperty, you would declare it like this:
     139
     140bool DeleteProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName);
     141
     142If 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).
     143*/
    60144typedef bool
    61 (*JSDeletePropertyCallback)     (JSObjectRef object, JSStringBufferRef propertyName);
    62 
     145(*JSDeletePropertyCallback)     (JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName);
     146
     147/*!
     148@typedef JSGetPropertyListCallback
     149@abstract The callback invoked when adding an object's properties to a property list.
     150@param context The current execution context.
     151@param object The JSObject whose properties need to be added to propertyList.
     152@param propertyList A JavaScript property list that will be used to enumerate object's properties.
     153@discussion If you named your function GetPropertyList, you would declare it like this:
     154
     155void GetPropertyList(JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList);
     156
     157Use JSPropertyListAdd to add properties to propertyList.
     158
     159Property lists are used by JSPropertyEnumerators and JavaScript for...in loops.
     160*/
    63161typedef void
    64 (*JSGetPropertyListCallback)    (JSObjectRef object, JSPropertyListRef propertyList);
    65 
     162(*JSGetPropertyListCallback)    (JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList);
     163
     164/*!
     165@typedef JSCallAsFunctionCallback
     166@abstract The callback invoked when an object is called as a function.
     167@param context The current execution context.
     168@param function A JSObject that is the function being called.
     169@param thisObject A JSObject that is the 'this' variable in the function's scope.
     170@param argc An integer count of the number of arguments in argv.
     171@param argv A JSValue array of the  arguments passed to the function.
     172@result A JSValue that is the function's return value.
     173@discussion If you named your function CallAsFunction, you would declare it like this:
     174
     175JSValueRef CallAsFunction(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, JSValueRef argv[]);
     176
     177If your callback were invoked by the JavaScript expression 'myObject.myMemberFunction()', function would be set to myMemberFunction, and thisObject would be set to myObject.
     178
     179If this callback is NULL, calling your object as a function will throw an exception.
     180*/
    66181typedef JSValueRef
    67 (*JSCallAsFunctionCallback)     (JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argc, JSValueRef argv[]);
    68 
     182(*JSCallAsFunctionCallback)     (JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, JSValueRef argv[]);
     183
     184/*!
     185@typedef JSCallAsConstructorCallback
     186@abstract The callback invoked when an object is used as a constructor in a 'new' statement.
     187@param context The current execution context.
     188@param constructor A JSObject that is the constructor being called.
     189@param argc An integer count of the number of arguments in argv.
     190@param argv A JSValue array of the  arguments passed to the function.
     191@result A JSObject that is the constructor's return value.
     192@discussion If you named your function CallAsConstructor, you would declare it like this:
     193
     194JSObjectRef CallAsConstructor(JSContextRef context, JSObjectRef constructor, size_t argc, JSValueRef argv[]);
     195
     196If your callback were invoked by the JavaScript expression 'new myConstructorFunction()', constructor would be set to myConstructorFunction.
     197
     198If this callback is NULL, using your object as a constructor in a 'new' statement will throw an exception.
     199*/
    69200typedef JSObjectRef
    70 (*JSCallAsConstructorCallback)  (JSContextRef context, JSObjectRef object, size_t argc, JSValueRef argv[]);
    71 
     201(*JSCallAsConstructorCallback)  (JSContextRef context, JSObjectRef constructor, size_t argc, JSValueRef argv[]);
     202
     203/*!
     204@typedef JSConvertToTypeCallback
     205@abstract The callback invoked when converting an object to a particular JavaScript type.
     206@param context The current execution context.
     207@param object The JSObject to convert.
     208@param typeCode A JSTypeCode specifying the JavaScript type to convert to.
     209@param returnValue A pointer to a JSValue in which to store the converted value.
     210@result true if the value was converted, otherwise false. If this function returns true, returnValue is assumed to contain a valid JSValue.
     211@discussion If you named your function ConvertToType, you would declare it like this:
     212
     213bool ConvertToType(JSContextRef context, JSObjectRef object, JSTypeCode typeCode, JSValueRef* returnValue);
     214
     215If this function returns false, the conversion request forwards to object's parent class chain (which includes the default object class).
     216*/
    72217typedef bool
    73 (*JSConvertToTypeCallback)      (JSObjectRef object, JSTypeCode typeCode, JSValueRef* returnValue);
    74 
    75 typedef struct __JSObjectCallbacks {
     218(*JSConvertToTypeCallback)      (JSContextRef context, JSObjectRef object, JSTypeCode typeCode, JSValueRef* returnValue);
     219
     220/*!
     221@struct JSObjectCallbacks
     222@abstract This structure contains optional callbacks for supplementing default object behavior. Any callback field can be NULL.
     223@field version The version number of this structure. The current version is 0.
     224@field initialize The callback invoked when an object is first created. Use this callback in conjunction with JSObjectSetPrivate to initialize private data in your object.
     225@field finalize The callback invoked when an object is finalized (prepared for garbage collection). Use this callback to release resources allocated for your object, and perform other cleanup.
     226@field hasProperty The callback invoked when determining whether an object has a given property. If this field is NULL, getProperty will be called instead. The hasProperty 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.
     227@field getProperty The callback invoked when getting the value of a given property.
     228@field setProperty The callback invoked when setting the value of a given property.
     229@field deleteProperty The callback invoked when deleting a given property.
     230@field getPropertyList The callback invoked when adding an object's properties to a property list.
     231@field callAsFunction The callback invoked when an object is called as a function.
     232@field callAsConstructor The callback invoked when an object is used as a constructor in a 'new' statement.
     233@field convertToType The callback invoked when converting an object to a particular JavaScript type.
     234*/
     235typedef struct {
    76236    int                         version; // current (and only) version is 0
    77237    JSInitializeCallback        initialize;
     
    87247} JSObjectCallbacks;
    88248
     249/*!
     250@const kJSObjectCallbacksNone
     251@abstract A JSObjectCallbacks structure of the current version, filled with NULL callbacks.
     252@discussion Use this constant as a convenience when creating callback structures. For example, to create a callback structure that has only a finalize method:
     253
     254JSObjectCallbacks callbacks = kJSObjectCallbacksNone;
     255
     256callbacks.finalize = Finalize;
     257*/
    89258extern const JSObjectCallbacks kJSObjectCallbacksNone;
    90259
     260/*!
     261@struct JSStaticValue
     262@abstract This structure describes a static value property.
     263@field name A UTF8 buffer containing the property's name.
     264@field getProperty A JSGetPropertyCallback to invoke when getting the property's value.
     265@field setProperty A JSSetPropertyCallback to invoke when setting the property's value.
     266@field attributes A logically ORed set of JSPropertyAttributes to give to the property.
     267*/
    91268typedef struct {
    92269    const char* const name; // FIXME: convert UTF8
     
    96273} JSStaticValue;
    97274
     275/*!
     276@struct JSStaticFunction
     277@abstract This structure describes a static function property.
     278@field name A UTF8 buffer containing the property's name.
     279@field callAsFunction A JSCallAsFunctionCallback to invoke when the property is called as a function.
     280@field attributes A logically ORed set of JSPropertyAttributes to give to the property.
     281*/
    98282typedef struct {
    99283    const char* const name; // FIXME: convert UTF8
     
    102286} JSStaticFunction;
    103287
    104 JSClassRef JSClassCreate(JSContextRef context, JSStaticValue* staticValues, JSStaticFunction* staticFunctions, const JSObjectCallbacks* callbacks, JSClassRef parentClass);
     288/*!
     289@function
     290@abstract Creates a JavaScript class suitable for use with JSObjectMake. Ownership follows the create rule.
     291@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.
     292@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.
     293@param callbacks A pointer to a JSObjectCallbacks structure holding custom callbacks for supplementing default object behavior. Pass NULL to specify no custom behavior.
     294@param parentClass A JSClass to set as the class's parent class. Pass NULL use the default object class.
     295@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.
     296*/
     297JSClassRef JSClassCreate(JSStaticValue* staticValues, JSStaticFunction* staticFunctions, const JSObjectCallbacks* callbacks, JSClassRef parentClass);
     298/*!
     299@function
     300@abstract Retains a JavaScript class.
     301@param jsClass The JSClass to retain.
     302@result A JSClass that is the same as jsClass.
     303*/
     304JSClassRef JSClassRetain(JSClassRef jsClass);
     305/*!
     306@function
     307@abstract Releases a JavaScript class.
     308@param jsClass The JSClass to release.
     309*/
    105310void JSClassRelease(JSClassRef jsClass);
    106 JSClassRef JSClassRetain(JSClassRef jsClass);
    107 
    108 // pass NULL as prototype to get the built-in object prototype
     311
     312/*!
     313@function
     314@abstract Creates a JavaScript object with a given class and prototype.
     315@param context The execution context to use.
     316@param jsClass The JSClass to assign to the object. Pass NULL to use the default object class.
     317@param prototype The prototype to assign to the object. Pass NULL to use the default object prototype.
     318@result A JSObject with the given class and prototype.
     319*/
    109320JSObjectRef JSObjectMake(JSContextRef context, JSClassRef jsClass, JSObjectRef prototype);
    110321
    111 // Will be assigned the built-in function prototype
     322/*!
     323@function
     324@abstract Convenience method for creating a JavaScript function with a given callback as its implementation.
     325@param context The execution context to use.
     326@param callAsFunction The JSCallAsFunctionCallback to invoke when the function is called.
     327@result A JSObject that is an anonymous function. The object's prototype will be the default function prototype.
     328*/
    112329JSObjectRef JSFunctionMake(JSContextRef context, JSCallAsFunctionCallback callAsFunction);
    113 // Will be assigned the built-in object prototype
     330/*!
     331@function
     332@abstract Convenience method for creating a JavaScript constructor with a given callback as its implementation.
     333@param context The execution context to use.
     334@param callAsConstructor The JSCallAsConstructorCallback to invoke when the constructor is used in a 'new' statement.
     335@result A JSObject that is a constructor. The object's prototype will be the default object prototype.
     336*/
    114337JSObjectRef JSConstructorMake(JSContextRef context, JSCallAsConstructorCallback callAsConstructor);
    115338
    116 // returns NULL if functionBody has a syntax error
    117 JSObjectRef JSFunctionMakeWithBody(JSContextRef context, JSStringBufferRef body, JSStringBufferRef sourceURL, int startingLineNumber);
    118 
     339/*!
     340@function
     341@abstract Creates a function with a given script as its body.
     342@param context The execution context to use.
     343@param body A JSStringBuffer containing the script to use as the function's body.
     344@param sourceURL A JSStringBuffer 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.
     345@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.
     346@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.
     347@result A JSObject that is an anonymous function, or NULL if body contains a syntax error. The returned object's prototype will be the default function prototype.
     348@discussion Use this method when you want to execute a script repeatedly, to avoid the cost of re-parsing the script before each execution.
     349*/
     350JSObjectRef JSFunctionMakeWithBody(JSContextRef context, JSStringBufferRef body, JSStringBufferRef sourceURL, int startingLineNumber, JSValueRef* exception);
     351
     352/*!
     353@function
     354@abstract Gets a short description of a JavaScript object.
     355@param context The execution context to use.
     356@param object The object whose description you want to get.
     357@result A JSStringBuffer containing the object's description. This is usually the object's class name.
     358*/
    119359JSStringBufferRef JSObjectGetDescription(JSObjectRef object);
    120360
     361/*!
     362@function
     363@abstract Gets an object's prototype.
     364@param object A JSObject whose prototype you want to get.
     365@result A JSValue containing the object's prototype.
     366*/
    121367JSValueRef JSObjectGetPrototype(JSObjectRef object);
     368/*!
     369@function
     370@abstract Sets an object's prototype.
     371@param object The JSObject whose prototype you want to set.
     372@param value A JSValue to set as the object's prototype.
     373*/
    122374void JSObjectSetPrototype(JSObjectRef object, JSValueRef value);
    123375
     376/*!
     377@function
     378@abstract Tests whether an object has a certain property.
     379@param object The JSObject to test.
     380@param propertyName A JSStringBuffer containing the property's name.
     381@result true if the object has a property whose name matches propertyName, otherwise false.
     382*/
    124383bool JSObjectHasProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName);
     384/*!
     385@function
     386@abstract Gets a property from an object.
     387@param context The execution context to use.
     388@param object The JSObject whose property you want to get.
     389@param propertyName A JSStringBuffer containing the property's name.
     390@param value A pointer to a JSValueRef in which to store the property's value. On return, value will contain the property's value. Pass NULL if you do not care to store the property's value.
     391@result true if the object has a property whose name matches propertyName, otherwise false. If this function returns false, the contents of value will be unmodified.
     392*/
    125393bool JSObjectGetProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName, JSValueRef* value);
     394/*!
     395@function
     396@abstract Sets a property on an object.
     397@param context The execution context to use.
     398@param object The JSObject whose property you want to set.
     399@param propertyName A JSStringBuffer containing the property's name.
     400@param value A JSValue to use as the property's value.
     401@param attributes A logically ORed set of JSPropertyAttributes to give to the property.
     402@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).
     403*/
    126404bool JSObjectSetProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName, JSValueRef value, JSPropertyAttributes attributes);
     405/*!
     406@function
     407@abstract Deletes a property from an object.
     408@param context The execution context to use.
     409@param object The JSObject whose property you want to delete.
     410@param propertyName A JSStringBuffer containing the property's name.
     411@result true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set).
     412*/
    127413bool JSObjectDeleteProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName);
    128414
    129 // Only works with objects created by JSObjectMake
     415/*!
     416@function
     417@abstract Gets a pointer to private data from an object.
     418@param object A JSObject whose private data you want to get.
     419@result A void* that points to the object's private data, or NULL if the object has no private data.
     420@discussion JSObjectGetPrivate and JSObjectSetPrivate only work on custom objects created by JSObjectMake, JSFunctionMake, and JSConstructorMake.
     421*/
    130422void* JSObjectGetPrivate(JSObjectRef object);
     423/*!
     424@function
     425@abstract Sets a pointer to private data on an object.
     426@param object A JSObject whose private data you want to set.
     427@param data A void* that points to the object's private data.
     428@result true if the set operation succeeds, otherwise false.
     429@discussion JSObjectGetPrivate and JSObjectSetPrivate only work on custom objects created by JSObjectMake, JSFunctionMake, and JSConstructorMake.
     430*/
    131431bool JSObjectSetPrivate(JSObjectRef object, void* data);
    132432
     433/*!
     434@function
     435@abstract Tests whether an object is a function.
     436@param object The JSObject to test.
     437@result true if the object is a function, otherwise false.
     438*/
    133439bool JSObjectIsFunction(JSObjectRef object);
     440/*!
     441@function
     442@abstract Calls an object as a function.
     443@param context The execution context to use.
     444@param object The JSObject to call as a function.
     445@param thisObject The JSObject to use as 'this' in the function call.
     446@param argc An integer count of the number of arguments in argv.
     447@param argv A JSValue array of the  arguments to pass to the function.
     448@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.
     449@result The JSValue that results from calling object as a function, or NULL if an uncaught exception is thrown or object is not a function.
     450*/
    134451JSValueRef JSObjectCallAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argc, JSValueRef argv[], JSValueRef* exception);
     452/*!
     453@function
     454@abstract Tests whether an object is a constructor.
     455@param object The JSObject to test.
     456@result true if the object is a constructor, otherwise false.
     457*/
    135458bool JSObjectIsConstructor(JSObjectRef object);
     459/*!
     460@function
     461@abstract Calls an object as a constructor.
     462@param context The execution context to use.
     463@param object The JSObject to call as a constructor.
     464@param argc An integer count of the number of arguments in argv.
     465@param argv A JSValue array of the  arguments to pass to the function.
     466@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.
     467@result The JSObject that results from calling object as a constructor, or NULL if an uncaught exception is thrown or object is not a constructor.
     468*/
    136469JSObjectRef JSObjectCallAsConstructor(JSContextRef context, JSObjectRef object, size_t argc, JSValueRef argv[], JSValueRef* exception);
    137470
    138 // Used for enumerating the names of an object's properties like a for...in loop would
     471/*!
     472@function
     473@abstract Creates an enumerator for an object's properties.
     474@param context The execution context to use.
     475@param object The object whose properties you want to enumerate.
     476@result A JSPropertyEnumerator with a list of object's properties. Ownership follows the create rule.
     477*/
    139478JSPropertyEnumeratorRef JSObjectCreatePropertyEnumerator(JSContextRef context, JSObjectRef object);
     479/*!
     480@function
     481@abstract Retains a property enumerator.
     482@param enumerator The JSPropertyEnumerator to retain.
     483@result A JSPropertyEnumerator that is the same as enumerator.
     484*/
    140485JSPropertyEnumeratorRef JSPropertyEnumeratorRetain(JSPropertyEnumeratorRef enumerator);
     486/*!
     487@function
     488@abstract Releases a property enumerator.
     489@param enumerator The JSPropertyEnumerator to release.
     490*/
    141491void JSPropertyEnumeratorRelease(JSPropertyEnumeratorRef enumerator);
     492/*!
     493@function
     494@abstract Gets a property enumerator's next property.
     495@param context The execution context to use.
     496@param enumerator The JSPropertyEnumerator whose next property you want to get.
     497@result A JSStringBuffer containing the property's name, or NULL if all properties have been enumerated.
     498*/
    142499JSStringBufferRef JSPropertyEnumeratorGetNext(JSContextRef context, JSPropertyEnumeratorRef enumerator);
    143500
    144 // Used for adding property names to a for...in enumeration
     501/*!
     502@function
     503@abstract Adds a property to a property list.
     504@discussion Use this method inside a JSGetPropertyListCallback to add a custom property to an object's property list.
     505@param propertyList The JSPropertyList to which you want to add a property.
     506@param thisObject The JSObject to which the property belongs.
     507@param propertyName A JSStringBuffer specifying the property's name.
     508*/
    145509void JSPropertyListAdd(JSPropertyListRef propertyList, JSObjectRef thisObject, JSStringBufferRef propertyName);
    146510
  • trunk/JavaScriptCore/API/JSStringBufferRef.cpp

    r15168 r15224  
    140140
    141141#if defined(__APPLE__)
    142 JSStringBufferRef JSStringBufferCreateWithCFString(CFStringRef string)
     142JSStringBufferRef JSStringBufferCreateCF(CFStringRef string)
    143143{
    144144    JSLock lock;
  • trunk/JavaScriptCore/API/JSStringBufferRef.h

    r15168 r15224  
    3333#endif
    3434
    35 #if defined(WIN32) || defined(_WIN32)
     35/*!
     36@typedef JSChar
     37@abstract A Unicode character.
     38*/
     39#if !defined(WIN32) && !defined(_WIN32)
     40    typedef unsigned short JSChar;
     41#else
    3642    typedef wchar_t JSChar;
    37 #else
    38     typedef unsigned short JSChar;
    3943#endif
    40    
     44
     45/*!
     46@function
     47@abstract         Creates a JavaScript string buffer from a buffer of Unicode characters.
     48@param chars      The buffer of Unicode characters to copy into the new JSStringBuffer.
     49@param numChars   The number of characters to copy from the buffer pointed to by chars.
     50@result           A JSStringBuffer containing chars. Ownership follows the create rule.
     51*/
    4152JSStringBufferRef JSStringBufferCreate(const JSChar* chars, size_t numChars);
     53/*!
     54@function
     55@abstract         Creates a JavaScript string buffer from a null-terminated UTF8 string.
     56@param string     The null-terminated UTF8 string to copy into the new JSStringBuffer.
     57@result           A JSStringBuffer containing string. Ownership follows the create rule.
     58*/
    4259JSStringBufferRef JSStringBufferCreateUTF8(const char* string);
    4360
     61/*!
     62@function
     63@abstract         Retains a JavaScript string buffer.
     64@param buffer     The JSStringBuffer to retain.
     65@result           A JSStringBuffer that is the same as buffer.
     66*/
    4467JSStringBufferRef JSStringBufferRetain(JSStringBufferRef buffer);
     68/*!
     69@function
     70@abstract         Releases a JavaScript string buffer.
     71@param buffer     The JSStringBuffer to release.
     72*/
    4573void JSStringBufferRelease(JSStringBufferRef buffer);
    4674
     75/*!
     76@function
     77@abstract         Returns the number of Unicode characters in a JavaScript string buffer.
     78@param buffer     The JSStringBuffer whose length (in Unicode characters) you want to know.
     79@result           The number of Unicode characters stored in buffer.
     80*/
    4781size_t JSStringBufferGetLength(JSStringBufferRef buffer);
     82/*!
     83@function
     84@abstract         Quickly obtains a pointer to the Unicode character buffer that
     85 serves as the backing store for a JavaScript string buffer.
     86@param buffer     The JSStringBuffer whose backing store you want to access.
     87@result           A pointer to the Unicode character buffer that serves as buffer's
     88 backing store, which will be deallocated when buffer is deallocated.
     89*/
    4890const JSChar* JSStringBufferGetCharactersPtr(JSStringBufferRef buffer);
     91/*!
     92@function
     93@abstract         Copies a JavaScript string buffer's Unicode characters into an
     94 external character buffer.
     95@param inBuffer   The source JSStringBuffer.
     96@param outBuffer  The destination JSChar buffer into which to copy inBuffer's
     97 characters. On return, outBuffer 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 buffer.
     100*/
    49101void JSStringBufferGetCharacters(JSStringBufferRef inBuffer, JSChar* outBuffer, size_t numChars);
    50102
     103/*!
     104@function
     105@abstract         Returns the maximum number of bytes required to encode the
     106 contents of a JavaScript string buffer as a null-terminated UTF8 string.
     107@param buffer     The JSStringBuffer whose maximum encoded length (in bytes) you
     108 want to know.
     109@result           The maximum number of bytes required to encode buffer's contents
     110 as a null-terminated UTF8 string.
     111*/
    51112size_t JSStringBufferGetMaxLengthUTF8(JSStringBufferRef buffer);
    52 // Returns the number of bytes written into outBuffer, including the trailing '\0'
     113/*!
     114@function
     115@abstract         Converts a JavaScript string buffer's contents into a
     116 null-terminated UTF8 string, and copies the result into an external byte buffer.
     117@param inBuffer   The source JSStringBuffer.
     118@param outBuffer  The destination byte buffer into which to copy a UTF8 string
     119 representation of inBuffer. The buffer must be at least bufferSize bytes in length.
     120 On return, outBuffer contains a UTF8 string representation of inBuffer.
     121 If bufferSize is too small, outBuffer will contain only partial results.
     122@param bufferSize The length of the external buffer in bytes.
     123@result           The number of bytes written into outBuffer (including the null-terminator byte).
     124*/
    53125size_t JSStringBufferGetCharactersUTF8(JSStringBufferRef inBuffer, char* outBuffer, size_t bufferSize);
    54126
     127/*!
     128@function
     129@abstract     Tests whether the characters in two JavaScript string buffers match.
     130@param a      The first JSStringBuffer to test.
     131@param b      The second JSStringBuffer to test.
     132@result       true if the characters in the two buffers match, otherwise false.
     133*/
    55134bool JSStringBufferIsEqual(JSStringBufferRef a, JSStringBufferRef b);
     135/*!
     136@function
     137@abstract     Tests whether the characters in a JavaScript string buffer match
     138 the characters in a null-terminated UTF8 string.
     139@param a      The JSStringBuffer to test.
     140@param b      The null-terminated UTF8 string to test.
     141@result       true if the characters in the two buffers match, otherwise false.
     142*/
    56143bool JSStringBufferIsEqualUTF8(JSStringBufferRef a, const char* b);
    57144
     
    59146#include <CoreFoundation/CoreFoundation.h>
    60147// CFString convenience methods
    61 JSStringBufferRef JSStringBufferCreateWithCFString(CFStringRef string);
     148/*!
     149@function
     150@abstract         Creates a JavaScript string buffer from a CFString.
     151@discussion       This function is optimized to take advantage of cases when
     152 CFStringGetCharactersPtr returns a valid pointer.
     153@param string     The CFString to copy into the new JSStringBuffer.
     154@result           A JSStringBuffer containing string. Ownership follows the create rule.
     155*/
     156JSStringBufferRef JSStringBufferCreateCF(CFStringRef string);
     157/*!
     158@function
     159@abstract         Creates a CFString form a JavaScript string buffer.
     160@param alloc      The alloc parameter to pass to CFStringCreate.
     161@param buffer     The JSStringBuffer to copy into the new CFString.
     162@result           A CFString containing buffer. Ownership follows the create rule.
     163*/
    62164CFStringRef CFStringCreateWithJSStringBuffer(CFAllocatorRef alloc, JSStringBufferRef buffer);
    63165#endif // __APPLE__
  • trunk/JavaScriptCore/API/JSValueRef.cpp

    r15165 r15224  
    136136}
    137137
    138 bool JSValueIsInstanceOf(JSContextRef context, JSValueRef value, JSObjectRef object)
    139 {
    140     ExecState* exec = toJS(context);
    141     JSValue* jsValue = toJS(value);
    142     JSObject* jsObject = toJS(object);
    143     if (!jsObject->implementsHasInstance())
     138bool JSValueIsInstanceOf(JSContextRef context, JSValueRef value, JSObjectRef constructor)
     139{
     140    ExecState* exec = toJS(context);
     141    JSValue* jsValue = toJS(value);
     142    JSObject* jsConstructor = toJS(constructor);
     143    if (!jsConstructor->implementsHasInstance())
    144144        return false;
    145     bool result = jsObject->hasInstance(exec, jsValue);
     145    bool result = jsConstructor->hasInstance(exec, jsValue);
    146146    if (exec->hadException())
    147147        exec->clearException();
  • trunk/JavaScriptCore/API/JSValueRef.h

    r15168 r15224  
    2222 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2323 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2525 */
    2626
     
    3131
    3232/*!
    33   @enum JSTypeCode
    34   A constant identifying the type of a JSValueRef.
    35   @constant kJSTypeUndefined the unique undefined value
    36   @constant kJSTypeNull the unique null value
    37   @constant kJSBoolean a primitive boolean value, one of true or false
    38   @constant kJSTypeNumber a primitive number value
    39   @constant kJSTypeString a primitive string value
    40   @constant kJSTypeObject an object (meaning that this JSValueRef is a JSObjectRef)
     33@enum JSTypeCode
     34@abstract     A constant identifying the type of a JSValue.
     35@constant     kJSTypeUndefined  The unique undefined value.
     36@constant     kJSTypeNull       The unique null value.
     37@constant     kJSTypeBoolean    A primitive boolean value, one of true or false.
     38@constant     kJSTypeNumber     A primitive number value.
     39@constant     kJSTypeString     A primitive string value.
     40@constant     kJSTypeObject     An object value (meaning that this JSValueRef is a JSObjectRef).
    4141*/
    4242typedef enum {
     
    5454
    5555/*!
    56   @function JSValueGetType
    57   Get the type code for a particular JavaScript value
    58   @param value the JS value for which the type should be determined
    59   @result      a type code identifying the type
     56@function
     57@abstract       Returns a JavaScript value's type code.
     58@param value    The JSValue whose type you want to obtain.
     59@result         A value of type JSTypeCode that identifies value's type.
    6060*/
    6161JSTypeCode JSValueGetType(JSValueRef value);
    6262
    6363/*!
    64   @function JSValueIsUndefined
    65   Determine if value is of type undefined
    66   @param value the JS value to check for undefined type
    67   @result      true if the value is undefined, false otherwise
     64@function
     65@abstract       Tests whether a JavaScript value's type is the undefined type.
     66@param value    The JSValue to test.
     67@result         true if value's type is the undefined type, otherwise false.
    6868*/
    6969bool JSValueIsUndefined(JSValueRef value);
    7070
    7171/*!
    72   @function JSValueIsNull
    73   Determine if value is of type null
    74   @param value the JS value to check for null type
    75   @result      true if the value is null, false otherwise
     72@function
     73@abstract       Tests whether a JavaScript value's type is the null type.
     74@param value    The JSValue to test.
     75@result         true if value's type is the null type, otherwise false.
    7676*/
    7777bool JSValueIsNull(JSValueRef value);
    7878
    7979/*!
    80   @function JSValueIsBoolean
    81   Determine if value is of type boolean
    82   @param value the JS value to check for boolean type
    83   @result      true if the value is a boolean, false otherwise
     80@function
     81@abstract       Tests whether a JavaScript value's type is the boolean type.
     82@param value    The JSValue to test.
     83@result         true if value's type is the boolean type, otherwise false.
    8484*/
    8585bool JSValueIsBoolean(JSValueRef value);
    8686
    8787/*!
    88   @function JSValueIsNumber
    89   Determine if value is of type number
    90   @param value the JS value to check for number type
    91   @result      true if the value is a number, false otherwise
     88@function
     89@abstract       Tests whether a JavaScript value's type is the number type.
     90@param value    The JSValue to test.
     91@result         true if value's type is the number type, otherwise false.
    9292*/
    9393bool JSValueIsNumber(JSValueRef value);
    9494
    9595/*!
    96   @function JSValueIsString
    97   Determine if value is of type string
    98   @param value the JS value to check for string type
    99   @result      true if the value is a string, false otherwise
     96@function
     97@abstract       Tests whether a JavaScript value's type is the string type.
     98@param value    The JSValue to test.
     99@result         true if value's type is the string type, otherwise false.
    100100*/
    101101bool JSValueIsString(JSValueRef value);
    102102
    103103/*!
    104   @function JSValueIsObject
    105   Determine if value is of type object
    106   @param value the JS value to check for object type
    107   @result      true if the value is an object, false otherwise
     104@function
     105@abstract       Tests whether a JavaScript value's type is the object type.
     106@param value    The JSValue to test.
     107@result         true if value's type is the object type, otherwise false.
    108108*/
    109109bool JSValueIsObject(JSValueRef value);
     110
     111/*!
     112@function
     113@abstract       Tests whether a JavaScript value is an object with a given
     114 class in its class chain.
     115@param value    The JSValue to test.
     116 @result        true if value is an object and has jsClass in its class chain,
     117 otherwise false.
     118*/
    110119bool JSValueIsObjectOfClass(JSValueRef value, JSClassRef jsClass);
    111120
     
    113122
    114123/*!
    115   @function JSValueIsEqual
    116   Check if two values are equal by JavaScript rules, as if compared by the JS == operator
    117   @param context the execution context to use
    118   @param a       the first value to compare
    119   @param b       the second value to compare
    120   @result        true if the two values are equal, false otherwise
     124@function
     125@abstract       Tests whether two JavaScript values are equal, as compared by the JS == operator.
     126@param context  The execution context to use.
     127@param a        The first value to test.
     128@param b        The second value to test.
     129@result         true if the two values are equal, otherwise false.
    121130*/
    122131bool JSValueIsEqual(JSContextRef context, JSValueRef a, JSValueRef b);
    123132
    124133/*!
    125   @function JSValueIsStrictEqual
    126   Check if two values are strict equal by JavaScript rules, as if compared by the JS === operator
    127   @param context the execution context to use
    128   @param a       the first value to compare
    129   @param b       the second value to compare
    130   @result        true if the two values are strict equal, false otherwise
     134@function
     135@abstract       Tests whether two JavaScript values are strict equal, as compared by the JS === operator.
     136@param context  The execution context to use.
     137@param a        The first value to test.
     138@param b        The second value to test.
     139@result         true if the two values are strict equal, otherwise false.
    131140*/
    132141bool JSValueIsStrictEqual(JSContextRef context, JSValueRef a, JSValueRef b);
    133142
    134143/*!
    135   @function JSValueIsInstanceOf
    136   Check if a value is an instance of a particular object; generally this means the object
    137   was used as the constructor for that instance
    138   @param context the execution context to use
    139   @param value   the possible instance
    140   @param object  the possible constructor
    141   @result        true if value is an instance of object
    142 */
    143 bool JSValueIsInstanceOf(JSContextRef context, JSValueRef value, JSObjectRef object);
     144@function
     145@abstract       Tests whether a JavaScript value is an object constructed by
     146 a given constructor, as compared by the JS instanceof operator.
     147@param context  The execution context to use.
     148@param value    The JSValue to test.
     149@param object   The constructor to test against.
     150@result         true if value is an object constructed by constructor, as compared
     151 by the JS instanceof operator, otherwise false.
     152*/
     153bool JSValueIsInstanceOf(JSContextRef context, JSValueRef value, JSObjectRef constructor);
    144154
    145155// Creating values
    146156
    147157/*!
    148   @function JSUndefinedMake
    149   Make a value of the undefined type.
    150   @result The unique undefined value.
     158@function
     159@abstract   Creates a JavaScript value of the undefined type.
     160@result    The unique undefined value.
    151161*/
    152162JSValueRef JSUndefinedMake(void);
    153163
    154164/*!
    155   @function JSNullMake
    156   Make a value of the null type.
    157   @result the unique null value
     165@function
     166@abstract   Creates a JavaScript value of the null type.
     167@result     The unique null value.
    158168*/
    159169JSValueRef JSNullMake(void);
    160170
    161171/*!
    162   @function JSBooleanMake
    163   Make a value of the boolean type.
    164   @param value whether the returned value should be true or false
    165   @result      a JS true or false boolean value, as appropriate
     172@function
     173@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.
    166176*/
    167177
     
    169179
    170180/*!
    171   @function JSNumberMake
    172   Make a value of the number type.
    173   @param  value the numberic value of the number to make
    174   @result a JS number corresponding to value
     181@function
     182@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.
    175185*/
    176186JSValueRef JSNumberMake(double value);
    177187
    178188/*!
    179   @function JSStringMake
    180   Make a value of the string type.
    181   @param  buffer the internal string contents for the string value
    182   @result a JS string value that has the value of the buffer
     189@function
     190@abstract       Creates a JavaScript value of the string type.
     191@param buffer   The JSStringBuffer to assign to the newly created JSValue. The
     192 newly created JSValue retains buffer, and releases it upon garbage collection.
     193@result         A JSValue of the string type, representing the string value of buffer.
    183194*/
    184195JSValueRef JSStringMake(JSStringBufferRef buffer);
     
    187198
    188199/*!
    189   @function JSValueToBoolean
    190   Convert a JavaScript value to boolean and return the resulting boolean
    191   @param context the execution context to use
    192   @param value   the value to convert
    193   @result        the boolean result of conversion
     200@function
     201@abstract       Converts a JavaScript value to boolean and returns the resulting boolean.
     202@param context  The execution context to use.
     203@param value    The JSValue to convert.
     204@result         The boolean result of conversion.
    194205*/
    195206bool JSValueToBoolean(JSContextRef context, JSValueRef value);
    196207
    197208/*!
    198   @function JSValueToNumber
    199   Convert a JavaScript value to number and return the resulting number
    200   @param context the execution context to use
    201   @param value   the value to convert
    202   @result        the numeric result of conversion, or NaN if conversion fails
     209@function
     210@abstract       Converts a JavaScript value to number and returns the resulting number.
     211@param context  The execution context to use.
     212@param value    The JSValue to convert.
     213@result         The numeric result of conversion, or NaN if conversion fails.
    203214*/
    204215double JSValueToNumber(JSContextRef context, JSValueRef value);
    205216
    206217/*!
    207   @function JSValueCopyStringValue
    208   Convert a JavaScript value to string and copy the resulting string into a newly allocated character buffer
    209   @param context the execution context to use
    210   @param value   the value to convert
    211   @result        a character buffer containing the result of conversion, or an empty character buffer if conversion fails
     218@function
     219@abstract       Converts a JavaScript value to string and copies the resulting
     220 string into a newly allocated JavaScript string buffer.
     221@param context  The execution context to use.
     222@param value    The JSValue to convert.
     223@result         A JSStringBuffer containing the result of conversion, or an empty
     224 string buffer if conversion fails. Ownership follows the copy rule.
    212225*/
    213226JSStringBufferRef JSValueCopyStringValue(JSContextRef context, JSValueRef value);
    214227
    215228/*!
    216   @function JSValueToObject
    217   Convert a JavaScript value to object and return the resulting object
    218   @param context the execution context to use
    219   @param value   the value to convert
    220   @result        the object result of conversion, or NULL if conversion fails
     229@function
     230@abstract Converts a JavaScript value to object and returns the resulting object.
     231@param context  The execution context to use.
     232@param value    The JSValue to convert.
     233@result         The JSObject result of conversion, or NULL if conversion fails.
    221234*/
    222235JSObjectRef JSValueToObject(JSContextRef context, JSValueRef value);
     
    224237// Garbage collection
    225238/*!
    226   @function JSGCProtect
    227   Protect a JavaScript value from garbage collection; a value may be
    228   protected multiple times and must be unprotected an equal number of
    229   times to become collectable again.
     239@function
     240@abstract       Protects a JavaScript value from garbage collection.
     241@param value    The JSValue to protect.
     242@discussion     A value may be protected multiple times and must be unprotected an
     243 equal number of times before becoming eligible for garbage collection.
    230244*/
    231245void JSGCProtect(JSValueRef value);
    232246
    233247/*!
    234   @function JSGCProtect
    235   Stop protecting a JavaScript value from garbage collection; a value may be
    236   protected multiple times and must be unprotected an equal number of
    237   times to become collectable again.
     248@function
     249@abstract       Unprotects a JavaScript value from garbage collection.
     250@param value    The JSValue to unprotect.
     251@discussion     A value may be protected multiple times and must be unprotected an
     252 equal number of times before becoming eligible for garbage collection.
    238253*/
    239254void JSGCUnprotect(JSValueRef value);
    240255
    241 /*!
    242   @function JSGCCollect
    243   Immediately perform a JavaScript garbage collection. JavaScript
    244   values that are on the machine stack, in a register, protected, set
    245   as the global object of any interpreter, or reachable from any such
    246   value will not be collected. It is not normally necessary to call
    247   this function directly; the JS runtime will garbage collect as
    248   needed.
     256/*!
     257@function
     258@abstract Performs a JavaScript garbage collection.
     259@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.
    249263*/
    250264void JSGCCollect(void);
  • trunk/JavaScriptCore/API/minidom.c

    r15168 r15224  
    3737    UNUSED_PARAM(argv);
    3838   
    39     JSContextRef context = JSContextCreate(NULL, NULL);
     39    JSContextRef context = JSContextCreate(NULL);
    4040    JSObjectRef globalObject = JSContextGetGlobalObject(context);
    4141   
  • trunk/JavaScriptCore/API/testapi.c

    r15213 r15224  
    130130}
    131131
    132 static bool MyObject_hasProperty(JSObjectRef object, JSStringBufferRef propertyName)
    133 {
     132static bool MyObject_hasProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName)
     133{
     134    UNUSED_PARAM(context);
    134135    UNUSED_PARAM(object);
    135136
     
    166167}
    167168
    168 static bool MyObject_setProperty(JSObjectRef object, JSStringBufferRef propertyName, JSValueRef value)
    169 {
     169static bool MyObject_setProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName, JSValueRef value)
     170{
     171    UNUSED_PARAM(context);
    170172    UNUSED_PARAM(object);
    171173    UNUSED_PARAM(value);
     
    177179}
    178180
    179 static bool MyObject_deleteProperty(JSObjectRef object, JSStringBufferRef propertyName)
    180 {
     181static bool MyObject_deleteProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName)
     182{
     183    UNUSED_PARAM(context);
    181184    UNUSED_PARAM(object);
    182185   
     
    187190}
    188191
    189 static void MyObject_getPropertyList(JSObjectRef object, JSPropertyListRef propertyList)
    190 {
     192static void MyObject_getPropertyList(JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList)
     193{
     194    UNUSED_PARAM(context);
     195   
    191196    JSStringBufferRef propertyNameBuf;
    192197   
     
    223228}
    224229
    225 static bool MyObject_convertToType(JSObjectRef object, JSTypeCode typeCode, JSValueRef* returnValue)
    226 {
     230static bool MyObject_convertToType(JSContextRef context, JSObjectRef object, JSTypeCode typeCode, JSValueRef* returnValue)
     231{
     232    UNUSED_PARAM(context);
    227233    UNUSED_PARAM(object);
    228234   
     
    268274    static JSClassRef jsClass;
    269275    if (!jsClass) {
    270         jsClass = JSClassCreate(context, NULL, NULL, &MyObject_callbacks, NULL);
     276        jsClass = JSClassCreate(NULL, NULL, &MyObject_callbacks, NULL);
    271277    }
    272278   
     
    312318    UNUSED_PARAM(argv);
    313319   
    314     context = JSContextCreate(NULL, NULL);
     320    context = JSContextCreate(NULL);
    315321
    316322    JSValueRef jsUndefined = JSUndefinedMake();
     
    339345                                                          kCFAllocatorNull);
    340346
    341     JSStringBufferRef jsCFStringBuf = JSStringBufferCreateWithCFString(cfString);
     347    JSStringBufferRef jsCFStringBuf = JSStringBufferCreateCF(cfString);
    342348    JSValueRef jsCFString = JSStringMake(jsCFStringBuf);
    343349   
    344350    CFStringRef cfEmptyString = CFStringCreateWithCString(kCFAllocatorDefault, "", kCFStringEncodingUTF8);
    345351   
    346     JSStringBufferRef jsCFEmptyStringBuf = JSStringBufferCreateWithCFString(cfEmptyString);
     352    JSStringBufferRef jsCFEmptyStringBuf = JSStringBufferCreateCF(cfEmptyString);
    347353    JSValueRef jsCFEmptyString = JSStringMake(jsCFEmptyStringBuf);
    348354
     
    500506    JSValueRef result;
    501507    JSValueRef exception;
     508    JSValueRef v;
     509    JSObjectRef o;
    502510
    503511    result = JSEvaluate(context, goodSyntaxBuf, NULL, NULL, 1, NULL);
    504512    assert(result);
    505513    assert(JSValueIsEqual(context, result, jsOne));
    506    
     514
     515    exception = NULL;
    507516    result = JSEvaluate(context, badSyntaxBuf, NULL, NULL, 1, &exception);
    508517    assert(!result);
     
    527536    JSStringBufferRelease(badSyntaxBuf);
    528537
     538    v = NULL;
    529539    JSStringBufferRef arrayBuf = JSStringBufferCreateUTF8("Array");
    530     JSValueRef v;
    531540    assert(JSObjectGetProperty(context, globalObject, arrayBuf, &v));
    532541    JSObjectRef arrayConstructor = JSValueToObject(context, v);
     
    539548    JSStringBufferRef functionBuf;
    540549   
     550    v = NULL;
     551    exception = NULL;
    541552    functionBuf = JSStringBufferCreateUTF8("rreturn Array;");
    542     assert(!JSFunctionMakeWithBody(context, functionBuf, NULL, 1));
     553    JSStringBufferRef lineBuf = JSStringBufferCreateUTF8("line");
     554    assert(!JSFunctionMakeWithBody(context, functionBuf, NULL, 1, &exception));
     555    assert(JSValueIsObject(exception));
     556    assert(JSObjectGetProperty(context, exception, lineBuf, &v));
     557    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)
    543558    JSStringBufferRelease(functionBuf);
     559    JSStringBufferRelease(lineBuf);
    544560
    545561    functionBuf = JSStringBufferCreateUTF8("return Array;");
    546     JSObjectRef function = JSFunctionMakeWithBody(context, functionBuf, NULL, 1);
     562    JSObjectRef function = JSFunctionMakeWithBody(context, functionBuf, NULL, 1, NULL);
    547563    JSStringBufferRelease(functionBuf);
    548564
     
    558574
    559575    JSStringBufferRef printBuf = JSStringBufferCreateUTF8("print");
    560     JSObjectSetProperty(context, globalObject, printBuf, JSFunctionMake(context, print_callAsFunction), kJSPropertyAttributeNone);
     576    JSValueRef printFunction = JSFunctionMake(context, print_callAsFunction);
     577    JSObjectSetProperty(context, globalObject, printBuf, printFunction, kJSPropertyAttributeNone);
    561578    JSStringBufferRelease(printBuf);
     579   
     580    assert(JSObjectSetPrivate(printFunction, (void*)1));
     581    assert(JSObjectGetPrivate(printFunction) == (void*)1);
    562582
    563583    JSStringBufferRef myConstructorBuf = JSStringBufferCreateUTF8("MyConstructor");
    564     JSObjectSetProperty(context, globalObject, myConstructorBuf, JSConstructorMake(context, myConstructor_callAsConstructor), kJSPropertyAttributeNone);
     584    JSValueRef myConstructor = JSConstructorMake(context, myConstructor_callAsConstructor);
     585    JSObjectSetProperty(context, globalObject, myConstructorBuf, myConstructor, kJSPropertyAttributeNone);
    565586    JSStringBufferRelease(myConstructorBuf);
    566 
    567     JSClassRef nullCallbacksClass = JSClassCreate(context, NULL, NULL, NULL, NULL);
     587   
     588    assert(JSObjectSetPrivate(myConstructor, (void*)1));
     589    assert(JSObjectGetPrivate(myConstructor) == (void*)1);
     590   
     591    o = JSObjectMake(context, NULL, NULL);
     592    JSObjectSetProperty(context, o, jsOneString, JSNumberMake(1), kJSPropertyAttributeNone);
     593    JSObjectSetProperty(context, o, jsCFString,  JSNumberMake(1), kJSPropertyAttributeDontEnum);
     594    JSPropertyEnumeratorRef enumerator = JSObjectCreatePropertyEnumerator(context, o);
     595    int count = 0;
     596    while (JSPropertyEnumeratorGetNext(context, enumerator))
     597        ++count;
     598    JSPropertyEnumeratorRelease(enumerator);
     599    assert(count == 1); // jsCFString should not be enumerated
     600
     601    JSClassRef nullCallbacksClass = JSClassCreate(NULL, NULL, NULL, NULL);
    568602    JSClassRelease(nullCallbacksClass);
    569603   
  • trunk/JavaScriptCore/ChangeLog

    r15213 r15224  
     12006-07-06  Geoffrey Garen  <[email protected]>
     2
     3        Reviewed by Maciej.
     4       
     5        More API action.
     6       
     7        - Headerdoc finished
     8
     9        Semantic Changes:
     10        - Added a JSContextRef argument to many functions, because you need a
     11        JSContextRef for doing virtually anything. I expect to add this argument
     12        to even more functions in a future patch.
     13       
     14        - Removed the globalObjectPrototype argument to JSContextCreate because
     15        you can't create an object until you have a context, so it's impossible
     16        to pass a prototype object to JSContextCreate. That's OK because (1) there's
     17        no reason to give the global object a prototype and (2) if you really want
     18        to, you can just use a separate call to JSObjectSetPrototype.
     19       
     20        - Removed the JSClassRef argument to JSClassCreate because it was unnecessary,
     21        and you need to be able to make the global object's class before you've
     22        created a JSContext.
     23       
     24        - Added an optional exception parameter to JSFunctionMakeWithBody because anything
     25        less would be uncivilized.
     26       
     27        - Made the return value parameter to JSObjectGetProperty optional to match
     28        all other return value parameters in the API.
     29       
     30        - Made JSObjectSetPrivate/JSObjectGetPrivate work on JSCallbackFunctions
     31        and JSCallbackConstructors. You could use an abstract base class or strategic
     32        placement of m_privateData in the class structure to implement this, but
     33        the former seemed like overkill, and the latter seemed too dangerous.
     34       
     35        - Fixed a bug where JSPropertyEnumeratorGetNext would skip the first property.
     36
     37        Cosmetic Changes:
     38        - Reversed the logic of the JSChar #ifdef to avoid confusing headerdoc
     39       
     40        - Removed function names from @function declarations because headeroc
     41        can parse them automatically, and I wanted to rule out manual mismatch.
     42
     43        - Changed Error::create to take a const UString& instead of a UString*
     44        because it was looking at me funny.
     45       
     46        - Renamed JSStringBufferCreateWithCFString to JSStringBufferCreateCF
     47        because the latter is more concise and it matches JSStringBufferCreateUTF8.
     48       
     49        * API/JSCallbackObject.cpp:
     50        (KJS::JSCallbackObject::getOwnPropertySlot):
     51        (KJS::JSCallbackObject::put):
     52        (KJS::JSCallbackObject::deleteProperty):
     53        (KJS::JSCallbackObject::getPropertyList):
     54        (KJS::JSCallbackObject::toBoolean):
     55        (KJS::JSCallbackObject::toNumber):
     56        (KJS::JSCallbackObject::toString):
     57        * API/JSClassRef.cpp:
     58        (JSClassCreate):
     59        * API/JSContextRef.cpp:
     60        (JSContextCreate):
     61        (JSContextSetException):
     62        * API/JSContextRef.h:
     63        * API/JSNode.c:
     64        (JSNodePrototype_class):
     65        (JSNode_class):
     66        * API/JSNodeList.c:
     67        (JSNodeListPrototype_class):
     68        (JSNodeList_class):
     69        * API/JSObjectRef.cpp:
     70        (JSObjectGetProperty):
     71        (JSObjectGetPrivate):
     72        (JSObjectSetPrivate):
     73        (JSObjectCallAsFunction):
     74        (JSObjectCallAsConstructor):
     75        (JSPropertyEnumeratorGetNext):
     76        * API/JSObjectRef.h:
     77        * API/JSStringBufferRef.cpp:
     78        (JSStringBufferCreateCF):
     79        * API/JSStringBufferRef.h:
     80        * API/JSValueRef.cpp:
     81        (JSValueIsInstanceOf):
     82        * API/JSValueRef.h:
     83        * API/minidom.c:
     84        (main):
     85        * API/minidom.js:
     86        * API/testapi.c:
     87        (MyObject_hasProperty):
     88        (MyObject_setProperty):
     89        (MyObject_deleteProperty):
     90        (MyObject_getPropertyList):
     91        (MyObject_convertToType):
     92        (MyObject_class):
     93        (main):
     94        * JavaScriptCore.exp:
     95
    1962006-07-07  Geoffrey Garen  <[email protected]>
    297
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r15168 r15224  
    4444_JSStringBufferCreate
    4545_JSStringBufferCreateUTF8
    46 _JSStringBufferCreateWithCFString
     46_JSStringBufferCreateCF
    4747_JSStringBufferGetCharacters
    4848_JSStringBufferGetCharactersPtr
  • trunk/JavaScriptCore/kjs/function_object.cpp

    r15026 r15224  
    202202    // we can't return a Completion(Throw) here, so just set the exception
    203203    // and return it
    204     return throwError(exec, SyntaxError, errMsg, errLine, sid, &sourceURL);
     204    return throwError(exec, SyntaxError, errMsg, errLine, sid, sourceURL);
    205205
    206206  ScopeChain scopeChain;
  • trunk/JavaScriptCore/kjs/interpreter.cpp

    r15163 r15224  
    426426    RefPtr<ProgramNode> progNode = Parser::parse(sourceURL, startingLineNumber, code, codeLength, 0, &errLine, &errMsg);
    427427    if (!progNode)
    428         return Completion(Throw, Error::create(&m_globalExec, SyntaxError, errMsg, errLine, 0, &sourceURL));
     428        return Completion(Throw, Error::create(&m_globalExec, SyntaxError, errMsg, errLine, 0, sourceURL));
    429429    return Completion(Normal);
    430430}
     
    458458    // no program node means a syntax error occurred
    459459    if (!progNode)
    460         return Completion(Throw, Error::create(&m_globalExec, SyntaxError, errMsg, errLine, sid, &sourceURL));
     460        return Completion(Throw, Error::create(&m_globalExec, SyntaxError, errMsg, errLine, sid, sourceURL));
    461461   
    462462    m_globalExec.clearException();
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r15155 r15224  
    196196Completion Node::createErrorCompletion(ExecState* exec, ErrorType e, const char *msg)
    197197{
    198     return Completion(Throw, Error::create(exec, e, msg, lineNo(), currentSourceId(exec), &currentSourceURL(exec)));
     198    return Completion(Throw, Error::create(exec, e, msg, lineNo(), currentSourceId(exec), currentSourceURL(exec)));
    199199}
    200200
     
    203203    UString message = msg;
    204204    substitute(message, ident.ustring());
    205     return Completion(Throw, Error::create(exec, e, message, lineNo(), currentSourceId(exec), &currentSourceURL(exec)));
     205    return Completion(Throw, Error::create(exec, e, message, lineNo(), currentSourceId(exec), currentSourceURL(exec)));
    206206}
    207207
    208208JSValue *Node::throwError(ExecState* exec, ErrorType e, const char *msg)
    209209{
    210     return KJS::throwError(exec, e, msg, lineNo(), currentSourceId(exec), &currentSourceURL(exec));
     210    return KJS::throwError(exec, e, msg, lineNo(), currentSourceId(exec), currentSourceURL(exec));
    211211}
    212212
     
    216216    substitute(message, v->toString(exec));
    217217    substitute(message, expr->toString());
    218     return KJS::throwError(exec, e, message, lineNo(), currentSourceId(exec), &currentSourceURL(exec));
     218    return KJS::throwError(exec, e, message, lineNo(), currentSourceId(exec), currentSourceURL(exec));
    219219}
    220220
     
    224224    UString message = msg;
    225225    substitute(message, label.ustring());
    226     return KJS::throwError(exec, e, message, lineNo(), currentSourceId(exec), &currentSourceURL(exec));
     226    return KJS::throwError(exec, e, message, lineNo(), currentSourceId(exec), currentSourceURL(exec));
    227227}
    228228
     
    233233    substitute(message, e1->toString());
    234234    substitute(message, e2->toString());
    235     return KJS::throwError(exec, e, message, lineNo(), currentSourceId(exec), &currentSourceURL(exec));
     235    return KJS::throwError(exec, e, message, lineNo(), currentSourceId(exec), currentSourceURL(exec));
    236236}
    237237
     
    242242    substitute(message, expr->toString());
    243243    substitute(message, label.ustring());
    244     return KJS::throwError(exec, e, message, lineNo(), currentSourceId(exec), &currentSourceURL(exec));
     244    return KJS::throwError(exec, e, message, lineNo(), currentSourceId(exec), currentSourceURL(exec));
    245245}
    246246
     
    250250    substitute(message, v->toString(exec));
    251251    substitute(message, label.ustring());
    252     return KJS::throwError(exec, e, message, lineNo(), currentSourceId(exec), &currentSourceURL(exec));
     252    return KJS::throwError(exec, e, message, lineNo(), currentSourceId(exec), currentSourceURL(exec));
    253253}
    254254
  • trunk/JavaScriptCore/kjs/object.cpp

    r14951 r15224  
    563563
    564564JSObject *Error::create(ExecState *exec, ErrorType errtype, const UString &message,
    565                          int lineno, int sourceId, const UString *sourceURL)
     565                         int lineno, int sourceId, const UString &sourceURL)
    566566{
    567567  JSObject *cons;
     
    602602    err->put(exec, "sourceId", jsNumber(sourceId));
    603603
    604   if(sourceURL)
    605    err->put(exec,"sourceURL", jsString(*sourceURL));
     604  if(!sourceURL.isNull())
     605    err->put(exec, "sourceURL", jsString(sourceURL));
    606606 
    607607  return err;
     
    646646}
    647647
    648 JSObject *throwError(ExecState *exec, ErrorType type, const UString &message, int line, int sourceId, const UString *sourceURL)
     648JSObject *throwError(ExecState *exec, ErrorType type, const UString &message, int line, int sourceId, const UString &sourceURL)
    649649{
    650650    JSObject *error = Error::create(exec, type, message, line, sourceId, sourceURL);
  • trunk/JavaScriptCore/kjs/object.h

    r14951 r15224  
    554554     * @param sourceURL Optional source URL.
    555555     */
    556     static JSObject *create(ExecState *, ErrorType, const UString &message, int lineNumber, int sourceId, const UString *sourceURL);
     556    static JSObject *create(ExecState *, ErrorType, const UString &message, int lineNumber, int sourceId, const UString &sourceURL);
    557557    static JSObject *create(ExecState *, ErrorType, const char *message);
    558558
     
    563563  };
    564564
    565 JSObject *throwError(ExecState *, ErrorType, const UString &message, int lineNumber, int sourceId, const UString *sourceURL);
     565JSObject *throwError(ExecState *, ErrorType, const UString &message, int lineNumber, int sourceId, const UString &sourceURL);
    566566JSObject *throwError(ExecState *, ErrorType, const UString &message);
    567567JSObject *throwError(ExecState *, ErrorType, const char *message);
Note: See TracChangeset for help on using the changeset viewer.