Show
Ignore:
Timestamp:
08/20/08 13:23:52 (5 months ago)
Author:
mbensi
Message:

merge with webkit revision 35853

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/JavaScriptCore/API/JSContextRef.cpp

    r436 r447  
    5656JSGlobalContextRef JSGlobalContextCreate(JSClassRef globalObjectClass) 
    5757{ 
    58     return JSGlobalContextCreateInGroup(toRef(JSGlobalData::create().get()), globalObjectClass); 
     58    JSLock lock(true); 
     59    return JSGlobalContextCreateInGroup(toRef(&JSGlobalData::sharedInstance()), globalObjectClass); 
    5960} 
    6061 
     
    6364    initializeThreading(); 
    6465 
    65     JSGlobalData* globalData = toJS(group); 
     66    JSLock lock(true); 
     67 
     68    RefPtr<JSGlobalData> globalData = group ? PassRefPtr<JSGlobalData>(toJS(group)) : JSGlobalData::create(); 
    6669 
    6770    if (!globalObjectClass) { 
    68         JSGlobalObject* globalObject = new (globalData) JSGlobalObject; 
     71        JSGlobalObject* globalObject = new (globalData.get()) JSGlobalObject; 
    6972        return JSGlobalContextRetain(toGlobalRef(globalObject->globalExec())); 
    7073    } 
    7174 
    72     JSGlobalObject* globalObject = new (globalData) JSCallbackObject<JSGlobalObject>(globalObjectClass); 
     75    JSGlobalObject* globalObject = new (globalData.get()) JSCallbackObject<JSGlobalObject>(globalObjectClass); 
    7376    ExecState* exec = globalObject->globalExec(); 
    7477    JSValue* prototype = globalObjectClass->prototype(exec); 
     
    8285{ 
    8386    ExecState* exec = toJS(ctx); 
    84     exec->globalData().heap->registerThread(); 
     87    JSLock lock(exec); 
     88 
     89    JSGlobalData& globalData = exec->globalData(); 
     90 
     91    globalData.heap->registerThread(); 
    8592 
    8693    gcProtect(exec->dynamicGlobalObject()); 
     94    globalData.ref(); 
    8795    return ctx; 
    8896} 
     
    9199{ 
    92100    ExecState* exec = toJS(ctx); 
     101    JSLock lock(exec); 
    93102 
    94103    gcUnprotect(exec->dynamicGlobalObject()); 
    95104 
    96105    JSGlobalData& globalData = exec->globalData(); 
    97     if (globalData.refCount() == 1) { 
     106    if (globalData.refCount() == 2) { // One reference is held by JSGlobalObject, another added by JSGlobalContextRetain(). 
    98107        // The last reference was released, this is our last chance to collect. 
    99108        Heap* heap = globalData.heap; 
     
    102111        ASSERT(!heap->isBusy()); 
    103112 
    104         // Heap destructor will delete JSGlobalObject, which will in turn delete JSGlobalData, which will 
    105         // delete the heap, which would cause a crash if allowed. 
     113        delete heap; 
    106114        globalData.heap = 0; 
     115    } 
    107116 
    108         delete heap; 
    109     } 
     117    globalData.deref(); 
    110118} 
    111119 
     
    114122    ExecState* exec = toJS(ctx); 
    115123    exec->globalData().heap->registerThread(); 
     124    JSLock lock(exec); 
    116125 
    117126    // It is necessary to call toThisObject to get the wrapper object when used with WebCore.