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/JSClassRef.cpp

    r53642 r53657  
    3535#include <runtime/Identifier.h>
    3636
     37using namespace std;
    3738using namespace JSC;
    3839
     
    121122}
    122123
    123 PassRefPtr<OpaqueJSClass> OpaqueJSClass::create(const JSClassDefinition* definition)
    124 {
    125     const JSStaticFunction* staticFunctions = definition->staticFunctions;
    126     if (staticFunctions || definition->parentClass) {
    127         // copy functions into a prototype class
    128         JSClassDefinition protoDefinition = kJSClassDefinitionEmpty;
    129         protoDefinition.staticFunctions = staticFunctions;
    130         protoDefinition.finalize = clearReferenceToPrototype;
    131        
    132         // We are supposed to use JSClassRetain/Release but since we know that we currently have
    133         // the only reference to this class object we cheat and use a RefPtr instead.
    134         RefPtr<OpaqueJSClass> protoClass = adoptRef(new OpaqueJSClass(&protoDefinition, 0));
    135 
    136         // remove functions from the original class
    137         JSClassDefinition objectDefinition = *definition;
    138         objectDefinition.staticFunctions = 0;
    139 
    140         return adoptRef(new OpaqueJSClass(&objectDefinition, protoClass.get()));
    141     }
    142 
    143     return adoptRef(new OpaqueJSClass(definition, 0));
     124PassRefPtr<OpaqueJSClass> OpaqueJSClass::create(const JSClassDefinition* clientDefinition)
     125{
     126    JSClassDefinition definition = *clientDefinition; // Avoid modifying client copy.
     127
     128    JSClassDefinition protoDefinition = kJSClassDefinitionEmpty;
     129    protoDefinition.finalize = clearReferenceToPrototype;
     130    swap(definition.staticFunctions, protoDefinition.staticFunctions); // Move static functions to the prototype.
     131   
     132    // We are supposed to use JSClassRetain/Release but since we know that we currently have
     133    // the only reference to this class object we cheat and use a RefPtr instead.
     134    RefPtr<OpaqueJSClass> protoClass = adoptRef(new OpaqueJSClass(&protoDefinition, 0));
     135    return adoptRef(new OpaqueJSClass(&definition, protoClass.get()));
    144136}
    145137
Note: See TracChangeset for help on using the changeset viewer.