Update versioning to support the mysterious future.
[WebKit-https.git] / JavaScriptGlue / JSValueWrapper.cpp
index 270c45a..f955ed0 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "config.h"
 #include "JSValueWrapper.h"
+#include "JSRun.h"
 #include <JavaScriptCore/PropertyNameArray.h>
 #include <pthread.h>
 
@@ -60,35 +61,35 @@ JSValue *JSValueWrapper::GetValue()
  * need to supply the global scope.
  */      
 
-pthread_key_t interpreterKey;
-pthread_once_t interpreterKeyOnce = PTHREAD_ONCE_INIT;
+pthread_key_t globalObjectKey;
+pthread_once_t globalObjectKeyOnce = PTHREAD_ONCE_INIT;
 
-static void derefInterpreter(void* data) 
+static void unprotectGlobalObject(void* data) 
 {
-    static_cast<Interpreter*>(data)->deref();
+    gcUnprotect(static_cast<JSGlobalObject*>(data));
 }
 
-static void initializeInterpreterKey()
+static void initializeGlobalObjectKey()
 {
-    pthread_key_create(&interpreterKey, derefInterpreter);
+    pthread_key_create(&globalObjectKey, unprotectGlobalObject);
 }
 
 static ExecState* getThreadGlobalExecState()
 {
-    pthread_once(&interpreterKeyOnce, initializeInterpreterKey);
-    Interpreter* interpreter = static_cast<Interpreter*>(pthread_getspecific(interpreterKey));
-    if (!interpreter) {
-        interpreter = new Interpreter();
-        interpreter->setGlobalObject(new JSGlobalObject());
-        interpreter->ref();
-        pthread_setspecific(interpreterKey, interpreter);
+    pthread_once(&globalObjectKeyOnce, initializeGlobalObjectKey);
+    JSGlobalObject* globalObject = static_cast<JSGlobalObject*>(pthread_getspecific(globalObjectKey));
+    if (!globalObject) {
+        globalObject = new JSGlueGlobalObject;
+        gcProtect(globalObject);
+        pthread_setspecific(globalObjectKey, globalObject);
     }
+    
+    ExecState* exec = globalObject->globalExec();
 
     // Discard exceptions -- otherwise an exception would forestall JS 
     // evaluation throughout the thread
-    interpreter->globalExec()->clearException();
-
-    return interpreter->globalExec();
+    exec->clearException();
+    return exec;
 }
 
 void JSValueWrapper::GetJSObectCallBacks(JSObjectCallBacks& callBacks)