Ignore:
Timestamp:
Jan 21, 2010, 4:06:00 PM (15 years ago)
Author:
[email protected]
Message:

2010-01-21 Geoffrey Garen <[email protected]>

Reviewed by Oliver Hunt.

Always create a prototype for automatically managed classes.


This fixes some errors where prototype chains were not correctly hooked
up, and also ensures that API classes work correctly with features like
instanceof.

  • API/JSClassRef.cpp: (OpaqueJSClass::create): Cleaned up some of this code. Also changed it to always create a prototype class.
  • API/tests/testapi.c: (Derived2_class): (main): Fixed a null value crash in the exception checking code.
  • API/tests/testapi.js: Added some tests for the case where a prototype chain would not be hooked up correctly.
File:
1 edited

Legend:

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

    r51068 r53657  
    624624}
    625625
     626static JSClassRef Derived2_class(JSContextRef context)
     627{
     628    static JSClassRef jsClass;
     629    if (!jsClass) {
     630        JSClassDefinition definition = kJSClassDefinitionEmpty;
     631        definition.parentClass = Derived_class(context);
     632        jsClass = JSClassCreate(&definition);
     633    }
     634    return jsClass;
     635}
     636
    626637static JSValueRef print_callAsFunction(JSContextRef ctx, JSObjectRef functionObject, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
    627638{
     
    10711082    ASSERT(!JSObjectGetPrivate(myConstructor));
    10721083   
     1084    string = JSStringCreateWithUTF8CString("Base");
     1085    JSObjectRef baseConstructor = JSObjectMakeConstructor(context, Base_class(context), NULL);
     1086    JSObjectSetProperty(context, globalObject, string, baseConstructor, kJSPropertyAttributeNone, NULL);
     1087    JSStringRelease(string);
     1088   
    10731089    string = JSStringCreateWithUTF8CString("Derived");
    10741090    JSObjectRef derivedConstructor = JSObjectMakeConstructor(context, Derived_class(context), NULL);
     
    10761092    JSStringRelease(string);
    10771093   
     1094    string = JSStringCreateWithUTF8CString("Derived2");
     1095    JSObjectRef derived2Constructor = JSObjectMakeConstructor(context, Derived2_class(context), NULL);
     1096    JSObjectSetProperty(context, globalObject, string, derived2Constructor, kJSPropertyAttributeNone, NULL);
     1097    JSStringRelease(string);
     1098
    10781099    o = JSObjectMake(context, NULL, NULL);
    10791100    JSObjectSetProperty(context, o, jsOneIString, JSValueMakeNumber(context, 1), kJSPropertyAttributeNone, NULL);
     
    11741195        script = JSStringCreateWithUTF8CString(scriptUTF8);
    11751196        result = JSEvaluateScript(context, script, NULL, NULL, 1, &exception);
    1176         if (JSValueIsUndefined(context, result))
     1197        if (result && JSValueIsUndefined(context, result))
    11771198            printf("PASS: Test script executed successfully.\n");
    11781199        else {
Note: See TracChangeset for help on using the changeset viewer.