Changeset 15224 in webkit for trunk/JavaScriptCore/API/testapi.c


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:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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   
Note: See TracChangeset for help on using the changeset viewer.