Changeset 447 for trunk/JavaScriptCore/API/JSContextRef.cpp
- Timestamp:
- 08/20/08 13:23:52 (5 months ago)
- Files:
-
- trunk/JavaScriptCore/API/JSContextRef.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/JavaScriptCore/API/JSContextRef.cpp
r436 r447 56 56 JSGlobalContextRef JSGlobalContextCreate(JSClassRef globalObjectClass) 57 57 { 58 return JSGlobalContextCreateInGroup(toRef(JSGlobalData::create().get()), globalObjectClass); 58 JSLock lock(true); 59 return JSGlobalContextCreateInGroup(toRef(&JSGlobalData::sharedInstance()), globalObjectClass); 59 60 } 60 61 … … 63 64 initializeThreading(); 64 65 65 JSGlobalData* globalData = toJS(group); 66 JSLock lock(true); 67 68 RefPtr<JSGlobalData> globalData = group ? PassRefPtr<JSGlobalData>(toJS(group)) : JSGlobalData::create(); 66 69 67 70 if (!globalObjectClass) { 68 JSGlobalObject* globalObject = new (globalData ) JSGlobalObject;71 JSGlobalObject* globalObject = new (globalData.get()) JSGlobalObject; 69 72 return JSGlobalContextRetain(toGlobalRef(globalObject->globalExec())); 70 73 } 71 74 72 JSGlobalObject* globalObject = new (globalData ) JSCallbackObject<JSGlobalObject>(globalObjectClass);75 JSGlobalObject* globalObject = new (globalData.get()) JSCallbackObject<JSGlobalObject>(globalObjectClass); 73 76 ExecState* exec = globalObject->globalExec(); 74 77 JSValue* prototype = globalObjectClass->prototype(exec); … … 82 85 { 83 86 ExecState* exec = toJS(ctx); 84 exec->globalData().heap->registerThread(); 87 JSLock lock(exec); 88 89 JSGlobalData& globalData = exec->globalData(); 90 91 globalData.heap->registerThread(); 85 92 86 93 gcProtect(exec->dynamicGlobalObject()); 94 globalData.ref(); 87 95 return ctx; 88 96 } … … 91 99 { 92 100 ExecState* exec = toJS(ctx); 101 JSLock lock(exec); 93 102 94 103 gcUnprotect(exec->dynamicGlobalObject()); 95 104 96 105 JSGlobalData& globalData = exec->globalData(); 97 if (globalData.refCount() == 1) {106 if (globalData.refCount() == 2) { // One reference is held by JSGlobalObject, another added by JSGlobalContextRetain(). 98 107 // The last reference was released, this is our last chance to collect. 99 108 Heap* heap = globalData.heap; … … 102 111 ASSERT(!heap->isBusy()); 103 112 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; 106 114 globalData.heap = 0; 115 } 107 116 108 delete heap; 109 } 117 globalData.deref(); 110 118 } 111 119 … … 114 122 ExecState* exec = toJS(ctx); 115 123 exec->globalData().heap->registerThread(); 124 JSLock lock(exec); 116 125 117 126 // It is necessary to call toThisObject to get the wrapper object when used with WebCore.
