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

    r27730 r27885  
    3232
    3333#include "JSCallbackObject.h"
     34#include "JSClassRef.h"
    3435#include "JSGlobalObject.h"
    3536#include "completion.h"
     
    4344    JSLock lock;
    4445
    45     JSGlobalObject* globalObject;
    46     if (globalObjectClass)
    47         // Specify jsNull() as the prototype.  Interpreter will fix it up to point at builtinObjectPrototype() in its constructor
    48         globalObject = new JSCallbackObject<JSGlobalObject>(0, globalObjectClass, jsNull(), 0);
    49     else
    50         globalObject = new JSGlobalObject();
     46    Interpreter* interpreter = new Interpreter();
     47    ExecState* globalExec = interpreter->globalExec();
     48    JSGlobalContextRef ctx = toGlobalRef(globalExec);
    5149
    52     Interpreter* interpreter = new Interpreter(globalObject); // adds the built-in object prototype to the global object
    53     if (globalObjectClass)
    54         static_cast<JSCallbackObject<JSGlobalObject>*>(globalObject)->initializeIfNeeded(interpreter->globalExec());
    55     JSGlobalContextRef ctx = reinterpret_cast<JSGlobalContextRef>(interpreter->globalExec());
     50    if (globalObjectClass) {
     51        JSObject* prototype = globalObjectClass->prototype(ctx);
     52        JSCallbackObject<JSGlobalObject>* globalObject = new JSCallbackObject<JSGlobalObject>(globalObjectClass, prototype ? prototype : jsNull(), 0);
     53        interpreter->setGlobalObject(globalObject);
     54        globalObject->init(globalExec);
     55    } else
     56        interpreter->setGlobalObject(new JSGlobalObject());
     57
    5658    return JSGlobalContextRetain(ctx);
    5759}
Note: See TracChangeset for help on using the changeset viewer.