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


Ignore:
Timestamp:
Jul 17, 2006, 1:14:39 AM (19 years ago)
Author:
mjs
Message:

Reviewed by Geoff.


  • add a JSContextRef parameter to all JSValueRef, JSObjectRef, and JSContextRef operations; except JSObject{Get,Set}PrivateData which can be assumed to be simple pure accessors.


Also renamed the parameter "context" to "ctx" because it makes the code read better with this pervasive
but usually uninteresting parameter.

  • API/JSBase.cpp: (JSEvaluateScript): (JSCheckScriptSyntax): (JSGarbageCollect):
  • API/JSBase.h:
  • API/JSCallbackObject.cpp: (KJS::JSCallbackObject::JSCallbackObject): (KJS::JSCallbackObject::init): (KJS::JSCallbackObject::getOwnPropertySlot): (KJS::JSCallbackObject::put): (KJS::JSCallbackObject::deleteProperty): (KJS::JSCallbackObject::toNumber): (KJS::JSCallbackObject::toString):
  • API/JSContextRef.cpp: (JSGlobalContextCreate): (JSGlobalContextRetain): (JSGlobalContextRelease): (JSContextGetGlobalObject):
  • API/JSContextRef.h:
  • API/JSNode.c: (JSNodePrototype_appendChild): (JSNodePrototype_removeChild): (JSNodePrototype_replaceChild): (JSNode_getNodeType): (JSNode_getFirstChild): (JSNode_prototype):
  • API/JSNodeList.c: (JSNodeListPrototype_item): (JSNodeList_length): (JSNodeList_getProperty): (JSNodeList_prototype):
  • API/JSObjectRef.cpp: (JSObjectMake): (JSObjectMakeFunctionWithCallback): (JSObjectMakeConstructor): (JSObjectMakeFunction): (JSObjectGetPrototype): (JSObjectSetPrototype): (JSObjectHasProperty): (JSObjectGetProperty): (JSObjectSetProperty): (JSObjectGetPropertyAtIndex): (JSObjectSetPropertyAtIndex): (JSObjectDeleteProperty): (JSObjectIsFunction): (JSObjectCallAsFunction): (JSObjectIsConstructor): (JSObjectCallAsConstructor): (JSObjectCopyPropertyNames):
  • API/JSObjectRef.h:
  • API/JSStringRef.cpp:
  • API/JSValueRef.cpp: (JSValueGetType): (JSValueIsUndefined): (JSValueIsNull): (JSValueIsBoolean): (JSValueIsNumber): (JSValueIsString): (JSValueIsObject): (JSValueIsObjectOfClass): (JSValueIsEqual): (JSValueIsStrictEqual): (JSValueIsInstanceOfConstructor): (JSValueMakeUndefined): (JSValueMakeNull): (JSValueMakeBoolean): (JSValueMakeNumber): (JSValueMakeString): (JSValueToBoolean): (JSValueToNumber): (JSValueToStringCopy): (JSValueToObject): (JSValueProtect): (JSValueUnprotect):
  • API/JSValueRef.h:
  • API/minidom.c: (print):
  • API/testapi.c: (MyObject_getProperty): (MyObject_deleteProperty): (MyObject_callAsFunction): (MyObject_callAsConstructor): (MyObject_convertToType): (print_callAsFunction): (main):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/testapi.c

    r15480 r15481  
    130130   
    131131    if (JSStringIsEqualToUTF8CString(propertyName, "alwaysOne")) {
    132         return JSValueMakeNumber(1);
     132        return JSValueMakeNumber(context, 1);
    133133    }
    134134   
    135135    if (JSStringIsEqualToUTF8CString(propertyName, "myPropertyName")) {
    136         return JSValueMakeNumber(1);
     136        return JSValueMakeNumber(context, 1);
    137137    }
    138138
    139139    if (JSStringIsEqualToUTF8CString(propertyName, "cantFind")) {
    140         return JSValueMakeUndefined();
     140        return JSValueMakeUndefined(context);
    141141    }
    142142   
    143143    if (JSStringIsEqualToUTF8CString(propertyName, "0")) {
    144         *exception = JSValueMakeNumber(1);
    145         return JSValueMakeNumber(1);
     144        *exception = JSValueMakeNumber(context, 1);
     145        return JSValueMakeNumber(context, 1);
    146146    }
    147147   
     
    170170   
    171171    if (JSStringIsEqualToUTF8CString(propertyName, "throwOnDelete")) {
    172         *exception = JSValueMakeNumber(2);
     172        *exception = JSValueMakeNumber(context, 2);
    173173        return false;
    174174    }
     
    198198    UNUSED_PARAM(thisObject);
    199199
    200     if (argumentCount > 0 && JSValueIsStrictEqual(context, arguments[0], JSValueMakeNumber(0)))
    201         return JSValueMakeNumber(1);
    202    
    203     return JSValueMakeUndefined();
     200    if (argumentCount > 0 && JSValueIsStrictEqual(context, arguments[0], JSValueMakeNumber(context, 0)))
     201        return JSValueMakeNumber(context, 1);
     202   
     203    return JSValueMakeUndefined(context);
    204204}
    205205
     
    209209    UNUSED_PARAM(object);
    210210
    211     if (argumentCount > 0 && JSValueIsStrictEqual(context, arguments[0], JSValueMakeNumber(0)))
    212         return JSValueToObject(context, JSValueMakeNumber(1), NULL);
    213    
    214     return JSValueToObject(context, JSValueMakeNumber(0), NULL);
     211    if (argumentCount > 0 && JSValueIsStrictEqual(context, arguments[0], JSValueMakeNumber(context, 0)))
     212        return JSValueToObject(context, JSValueMakeNumber(context, 1), NULL);
     213   
     214    return JSValueToObject(context, JSValueMakeNumber(context, 0), NULL);
    215215}
    216216
     
    233233    switch (type) {
    234234    case kJSTypeNumber:
    235         return JSValueMakeNumber(1);
     235        return JSValueMakeNumber(context, 1);
    236236    default:
    237237        break;
     
    305305    }
    306306   
    307     return JSValueMakeUndefined();
     307    return JSValueMakeUndefined(context);
    308308}
    309309
     
    332332   
    333333    JSObjectRef globalObject = JSContextGetGlobalObject(context);
    334     assert(JSValueIsObject(globalObject));
    335    
    336     JSValueRef jsUndefined = JSValueMakeUndefined();
    337     JSValueRef jsNull = JSValueMakeNull();
    338     JSValueRef jsTrue = JSValueMakeBoolean(true);
    339     JSValueRef jsFalse = JSValueMakeBoolean(false);
    340     JSValueRef jsZero = JSValueMakeNumber(0);
    341     JSValueRef jsOne = JSValueMakeNumber(1);
    342     JSValueRef jsOneThird = JSValueMakeNumber(1.0 / 3.0);
    343     JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, JSValueMakeNull());
     334    assert(JSValueIsObject(context, globalObject));
     335   
     336    JSValueRef jsUndefined = JSValueMakeUndefined(context);
     337    JSValueRef jsNull = JSValueMakeNull(context);
     338    JSValueRef jsTrue = JSValueMakeBoolean(context, true);
     339    JSValueRef jsFalse = JSValueMakeBoolean(context, false);
     340    JSValueRef jsZero = JSValueMakeNumber(context, 0);
     341    JSValueRef jsOne = JSValueMakeNumber(context, 1);
     342    JSValueRef jsOneThird = JSValueMakeNumber(context, 1.0 / 3.0);
     343    JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, JSValueMakeNull(context));
    344344
    345345    // FIXME: test funny utf8 characters
    346346    JSStringRef jsEmptyIString = JSStringCreateWithUTF8CString("");
    347     JSValueRef jsEmptyString = JSValueMakeString(jsEmptyIString);
     347    JSValueRef jsEmptyString = JSValueMakeString(context, jsEmptyIString);
    348348   
    349349    JSStringRef jsOneIString = JSStringCreateWithUTF8CString("1");
    350     JSValueRef jsOneString = JSValueMakeString(jsOneIString);
     350    JSValueRef jsOneString = JSValueMakeString(context, jsOneIString);
    351351
    352352#if defined(__APPLE__)
     
    360360
    361361    JSStringRef jsCFIString = JSStringCreateWithCFString(cfString);
    362     JSValueRef jsCFString = JSValueMakeString(jsCFIString);
     362    JSValueRef jsCFString = JSValueMakeString(context, jsCFIString);
    363363   
    364364    CFStringRef cfEmptyString = CFStringCreateWithCString(kCFAllocatorDefault, "", kCFStringEncodingUTF8);
    365365   
    366366    JSStringRef jsCFEmptyIString = JSStringCreateWithCFString(cfEmptyString);
    367     JSValueRef jsCFEmptyString = JSValueMakeString(jsCFEmptyIString);
     367    JSValueRef jsCFEmptyString = JSValueMakeString(context, jsCFEmptyIString);
    368368
    369369    CFIndex cfStringLength = CFStringGetLength(cfString);
     
    373373                          buffer);
    374374    JSStringRef jsCFIStringWithCharacters = JSStringCreateWithCharacters(buffer, cfStringLength);
    375     JSValueRef jsCFStringWithCharacters = JSValueMakeString(jsCFIStringWithCharacters);
     375    JSValueRef jsCFStringWithCharacters = JSValueMakeString(context, jsCFIStringWithCharacters);
    376376   
    377377    JSStringRef jsCFEmptyIStringWithCharacters = JSStringCreateWithCharacters(buffer, CFStringGetLength(cfEmptyString));
    378     JSValueRef jsCFEmptyStringWithCharacters = JSValueMakeString(jsCFEmptyIStringWithCharacters);
    379 #endif // __APPLE__
    380 
    381     assert(JSValueGetType(jsUndefined) == kJSTypeUndefined);
    382     assert(JSValueGetType(jsNull) == kJSTypeNull);
    383     assert(JSValueGetType(jsTrue) == kJSTypeBoolean);
    384     assert(JSValueGetType(jsFalse) == kJSTypeBoolean);
    385     assert(JSValueGetType(jsZero) == kJSTypeNumber);
    386     assert(JSValueGetType(jsOne) == kJSTypeNumber);
    387     assert(JSValueGetType(jsOneThird) == kJSTypeNumber);
    388     assert(JSValueGetType(jsEmptyString) == kJSTypeString);
    389     assert(JSValueGetType(jsOneString) == kJSTypeString);
    390 #if defined(__APPLE__)
    391     assert(JSValueGetType(jsCFString) == kJSTypeString);
    392     assert(JSValueGetType(jsCFStringWithCharacters) == kJSTypeString);
    393     assert(JSValueGetType(jsCFEmptyString) == kJSTypeString);
    394     assert(JSValueGetType(jsCFEmptyStringWithCharacters) == kJSTypeString);
     378    JSValueRef jsCFEmptyStringWithCharacters = JSValueMakeString(context, jsCFEmptyIStringWithCharacters);
     379#endif // __APPLE__
     380
     381    assert(JSValueGetType(context, jsUndefined) == kJSTypeUndefined);
     382    assert(JSValueGetType(context, jsNull) == kJSTypeNull);
     383    assert(JSValueGetType(context, jsTrue) == kJSTypeBoolean);
     384    assert(JSValueGetType(context, jsFalse) == kJSTypeBoolean);
     385    assert(JSValueGetType(context, jsZero) == kJSTypeNumber);
     386    assert(JSValueGetType(context, jsOne) == kJSTypeNumber);
     387    assert(JSValueGetType(context, jsOneThird) == kJSTypeNumber);
     388    assert(JSValueGetType(context, jsEmptyString) == kJSTypeString);
     389    assert(JSValueGetType(context, jsOneString) == kJSTypeString);
     390#if defined(__APPLE__)
     391    assert(JSValueGetType(context, jsCFString) == kJSTypeString);
     392    assert(JSValueGetType(context, jsCFStringWithCharacters) == kJSTypeString);
     393    assert(JSValueGetType(context, jsCFEmptyString) == kJSTypeString);
     394    assert(JSValueGetType(context, jsCFEmptyStringWithCharacters) == kJSTypeString);
    395395#endif // __APPLE__
    396396
     
    419419   
    420420    exception = NULL;
    421     assert(!JSValueIsEqual(context, jsObjectNoProto, JSValueMakeNumber(1), &exception));
     421    assert(!JSValueIsEqual(context, jsObjectNoProto, JSValueMakeNumber(context, 1), &exception));
    422422    assert(exception);
    423423   
     
    510510   
    511511    jsGlobalValue = JSObjectMake(context, NULL, NULL);
    512     JSValueProtect(jsGlobalValue);
    513     JSGarbageCollect();
    514     assert(JSValueIsObject(jsGlobalValue));
    515     JSValueUnprotect(jsGlobalValue);
     512    JSValueProtect(context, jsGlobalValue);
     513    JSGarbageCollect(context);
     514    assert(JSValueIsObject(context, jsGlobalValue));
     515    JSValueUnprotect(context, jsGlobalValue);
    516516
    517517    JSStringRef goodSyntax = JSStringCreateWithUTF8CString("x = 1;");
     
    532532    result = JSEvaluateScript(context, badSyntax, NULL, NULL, 1, &exception);
    533533    assert(!result);
    534     assert(JSValueIsObject(exception));
     534    assert(JSValueIsObject(context, exception));
    535535   
    536536    JSStringRef array = JSStringCreateWithUTF8CString("Array");
     
    539539    result = JSObjectCallAsConstructor(context, arrayConstructor, 0, NULL, NULL);
    540540    assert(result);
    541     assert(JSValueIsObject(result));
     541    assert(JSValueIsObject(context, result));
    542542    assert(JSValueIsInstanceOfConstructor(context, result, arrayConstructor, NULL));
    543     assert(!JSValueIsInstanceOfConstructor(context, JSValueMakeNull(), arrayConstructor, NULL));
     543    assert(!JSValueIsInstanceOfConstructor(context, JSValueMakeNull(context), arrayConstructor, NULL));
    544544
    545545    o = JSValueToObject(context, result, NULL);
    546546    exception = NULL;
    547     assert(JSValueIsUndefined(JSObjectGetPropertyAtIndex(context, o, 0, &exception)));
     547    assert(JSValueIsUndefined(context, JSObjectGetPropertyAtIndex(context, o, 0, &exception)));
    548548    assert(!exception);
    549549   
    550     JSObjectSetPropertyAtIndex(context, o, 0, JSValueMakeNumber(1), &exception);
     550    JSObjectSetPropertyAtIndex(context, o, 0, JSValueMakeNumber(context, 1), &exception);
    551551    assert(!exception);
    552552   
     
    562562    JSStringRef line = JSStringCreateWithUTF8CString("line");
    563563    assert(!JSObjectMakeFunction(context, NULL, 0, NULL, functionBody, NULL, 1, &exception));
    564     assert(JSValueIsObject(exception));
     564    assert(JSValueIsObject(context, exception));
    565565    v = JSObjectGetProperty(context, JSValueToObject(context, exception, NULL), line, NULL);
    566566    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)
     
    573573    JSStringRelease(functionBody);
    574574    assert(!exception);
    575     assert(JSObjectIsFunction(function));
     575    assert(JSObjectIsFunction(context, function));
    576576    v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL);
    577577    assert(v);
     
    583583    v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, &exception);
    584584    assert(v && !exception);
    585     assert(JSValueIsUndefined(v));
     585    assert(JSValueIsUndefined(context, v));
    586586   
    587587    exception = NULL;
     
    592592    function = JSObjectMakeFunction(context, foo, 1, argumentNames, functionBody, NULL, 1, &exception);
    593593    assert(function && !exception);
    594     JSValueRef arguments[] = { JSValueMakeNumber(2) };
     594    JSValueRef arguments[] = { JSValueMakeNumber(context, 2) };
    595595    v = JSObjectCallAsFunction(context, function, NULL, 1, arguments, &exception);
    596596    JSStringRelease(foo);
     
    598598   
    599599    string = JSValueToStringCopy(context, function, NULL);
    600     assertEqualsAsUTF8String(JSValueMakeString(string), "function foo(foo) \n{\n  return foo;\n}");
     600    assertEqualsAsUTF8String(JSValueMakeString(context, string), "function foo(foo) \n{\n  return foo;\n}");
    601601    JSStringRelease(string);
    602602
     
    618618   
    619619    o = JSObjectMake(context, NULL, NULL);
    620     JSObjectSetProperty(context, o, jsOneIString, JSValueMakeNumber(1), kJSPropertyAttributeNone, NULL);
    621     JSObjectSetProperty(context, o, jsCFIString,  JSValueMakeNumber(1), kJSPropertyAttributeDontEnum, NULL);
     620    JSObjectSetProperty(context, o, jsOneIString, JSValueMakeNumber(context, 1), kJSPropertyAttributeNone, NULL);
     621    JSObjectSetProperty(context, o, jsCFIString,  JSValueMakeNumber(context, 1), kJSPropertyAttributeDontEnum, NULL);
    622622    JSPropertyNameArrayRef nameArray = JSObjectCopyPropertyNames(context, o);
    623623    size_t expectedCount = JSPropertyNameArrayGetCount(nameArray);
     
    645645    JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8);
    646646    result = JSEvaluateScript(context, script, NULL, NULL, 1, &exception);
    647     if (JSValueIsUndefined(result))
     647    if (JSValueIsUndefined(context, result))
    648648        printf("PASS: Test script executed successfully.\n");
    649649    else {
     
    661661    JSObjectMake(context, MyObject_class(context), 0);
    662662    JSObjectMake(context, MyObject_class(context), 0);
    663     JSGarbageCollect();
     663    JSGarbageCollect(context);
    664664    assert(didFinalize);
    665665
Note: See TracChangeset for help on using the changeset viewer.