]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - runtime/Completion.cpp
JavaScriptCore-1097.3.tar.gz
[apple/javascriptcore.git] / runtime / Completion.cpp
index ac19705c0aa9699707106e103bbe6eb33b385914..1c35b9626733afdfec9bc94fc12f1b7e0e85f16e 100644 (file)
 #include "Completion.h"
 
 #include "CallFrame.h"
+#include "CodeProfiling.h"
 #include "JSGlobalObject.h"
 #include "JSLock.h"
 #include "Interpreter.h"
 #include "Parser.h"
 #include "Debugger.h"
-#include "WTFThreadData.h"
+#include <wtf/WTFThreadData.h>
 #include <stdio.h>
 
 namespace JSC {
 
-Completion checkSyntax(ExecState* exec, const SourceCode& source)
+bool checkSyntax(ExecState* exec, const SourceCode& source, JSValue* returnedException)
 {
-    JSLock lock(exec);
+    JSLockHolder lock(exec);
     ASSERT(exec->globalData().identifierTable == wtfThreadData().currentIdentifierTable());
 
     ProgramExecutable* program = ProgramExecutable::create(exec, source);
     JSObject* error = program->checkSyntax(exec);
-    if (error)
-        return Completion(Throw, error);
+    if (error) {
+        if (returnedException)
+            *returnedException = error;
+        return false;
+    }
 
-    return Completion(Normal);
+    return true;
 }
 
-Completion evaluate(ExecState* exec, ScopeChainNode* scopeChain, const SourceCode& source, JSValue thisValue)
+JSValue evaluate(ExecState* exec, ScopeChainNode* scopeChain, const SourceCode& source, JSValue thisValue, JSValue* returnedException)
 {
-    JSLock lock(exec);
+    JSLockHolder lock(exec);
     ASSERT(exec->globalData().identifierTable == wtfThreadData().currentIdentifierTable());
+    if (exec->globalData().isCollectorBusy())
+        CRASH();
+
+    CodeProfiling profile(source);
 
     ProgramExecutable* program = ProgramExecutable::create(exec, source);
     if (!program) {
-        JSValue exception = exec->globalData().exception;
+        if (returnedException)
+            *returnedException = exec->globalData().exception;
+
         exec->globalData().exception = JSValue();
-        return Completion(Throw, exception);
+        return jsUndefined();
     }
 
-    JSObject* thisObj = (!thisValue || thisValue.isUndefinedOrNull()) ? exec->dynamicGlobalObject() : thisValue.toObject(exec);
-
+    if (!thisValue || thisValue.isUndefinedOrNull())
+        thisValue = exec->dynamicGlobalObject();
+    JSObject* thisObj = thisValue.toThisObject(exec);
     JSValue result = exec->interpreter()->execute(program, exec, scopeChain, thisObj);
 
     if (exec->hadException()) {
-        JSValue exception = exec->exception();
-        exec->clearException();
+        if (returnedException)
+            *returnedException = exec->exception();
 
-        ComplType exceptionType = Throw;
-        if (exception.isObject())
-            exceptionType = asObject(exception)->exceptionType();
-        return Completion(exceptionType, exception);
+        exec->clearException();
+        return jsUndefined();
     }
-    return Completion(Normal, result);
+
+    ASSERT(result);
+    return result;
 }
 
 } // namespace JSC