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


Ignore:
Timestamp:
Nov 18, 2007, 1:09:27 AM (18 years ago)
Author:
[email protected]
Message:

Fix: <rdar://problem/5607032> (REGRESSION: testapi exits with assertion failure in debug build) and <rdar://problem/5440659> (JSGlobalContextCreate throws away globalObjectClass's prototype)

Split Interpreter's initialization into two distinct steps: the creation of the global prototypes
and constructors, and storing them on the global object. This allows JSClassRef's passed to
JSGlobalContextCreate to be instantiated with the correct prototype.

Reviewed by Darin Adler.

File:
1 edited

Legend:

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

    r27882 r27885  
    467467}
    468468
    469 static void testInitializeOfGlobalObjectClassHasNonNullContext(JSContextRef context, JSObjectRef object)
    470 {
    471     UNUSED_PARAM(object);
     469
     470static void globalObject_initialize(JSContextRef context, JSObjectRef object)
     471{
     472    UNUSED_PARAM(object);
     473    // Ensure that an execution context is passed in
    472474    ASSERT(context);
    473 }
     475
     476    // Ensure that the global object is set to the object that we were passed
     477    JSObjectRef globalObject = JSContextGetGlobalObject(context);
     478    ASSERT(globalObject);
     479    ASSERT(object == globalObject);
     480
     481    // Ensure that the standard global properties have been set on the global object
     482    JSStringRef array = JSStringCreateWithUTF8CString("Array");
     483    JSObjectRef arrayConstructor = JSValueToObject(context, JSObjectGetProperty(context, globalObject, array, NULL), NULL);
     484    JSStringRelease(array);
     485    ASSERT(arrayConstructor);
     486}
     487
     488static JSValueRef globalObject_get(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
     489{
     490    UNUSED_PARAM(object);
     491    UNUSED_PARAM(propertyName);
     492    UNUSED_PARAM(exception);
     493
     494    return JSValueMakeNumber(ctx, 3);
     495}
     496
     497static bool globalObject_set(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
     498{
     499    UNUSED_PARAM(object);
     500    UNUSED_PARAM(propertyName);
     501    UNUSED_PARAM(value);
     502
     503    *exception = JSValueMakeNumber(ctx, 3);
     504    return true;
     505}
     506
     507
     508static JSStaticValue globalObject_staticValues[] = {
     509    { "globalStaticValue", globalObject_get, globalObject_set, kJSPropertyAttributeNone },
     510    { 0, 0, 0, 0 }
     511};
    474512
    475513static char* createStringWithContentsOfFile(const char* fileName);
     
    497535
    498536    JSClassDefinition globalObjectClassDefinition = kJSClassDefinitionEmpty;
    499     globalObjectClassDefinition.initialize = testInitializeOfGlobalObjectClassHasNonNullContext;
     537    globalObjectClassDefinition.initialize = globalObject_initialize;
     538    globalObjectClassDefinition.staticValues = globalObject_staticValues;
    500539    JSClassRef globalObjectClass = JSClassCreate(&globalObjectClassDefinition);
    501540    context = JSGlobalContextCreate(globalObjectClass);
Note: See TracChangeset for help on using the changeset viewer.