]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - runtime/Completion.cpp
JavaScriptCore-1218.34.tar.gz
[apple/javascriptcore.git] / runtime / Completion.cpp
index 5655fa54c442cdaf2a8b399941bc6d1c723c9eb2..a2d8a6b5fe77febf30c4ac330b2efbe3898737bd 100644 (file)
 #include "Completion.h"
 
 #include "CallFrame.h"
 #include "Completion.h"
 
 #include "CallFrame.h"
+#include "CodeProfiling.h"
+#include "Debugger.h"
+#include "Interpreter.h"
 #include "JSGlobalObject.h"
 #include "JSLock.h"
 #include "JSGlobalObject.h"
 #include "JSLock.h"
-#include "Interpreter.h"
+#include "Operations.h"
 #include "Parser.h"
 #include "Parser.h"
-#include "Debugger.h"
+#include <wtf/WTFThreadData.h>
 #include <stdio.h>
 
 #include <stdio.h>
 
-#if !PLATFORM(WIN_OS)
-#include <unistd.h>
-#endif
-
 namespace JSC {
 
 namespace JSC {
 
-Completion checkSyntax(ExecState* exec, const SourceCode& source)
+bool checkSyntax(ExecState* exec, const SourceCode& source, JSValue* returnedException)
 {
 {
-    JSLock lock(exec);
+    JSLockHolder lock(exec);
+    RELEASE_ASSERT(exec->vm().identifierTable == wtfThreadData().currentIdentifierTable());
 
 
-    int errLine;
-    UString errMsg;
+    ProgramExecutable* program = ProgramExecutable::create(exec, source);
+    JSObject* error = program->checkSyntax(exec);
+    if (error) {
+        if (returnedException)
+            *returnedException = error;
+        return false;
+    }
 
 
-    RefPtr<ProgramNode> progNode = exec->globalData().parser->parse<ProgramNode>(exec, exec->dynamicGlobalObject()->debugger(), source, &errLine, &errMsg);
-    if (!progNode)
-        return Completion(Throw, Error::create(exec, SyntaxError, errMsg, errLine, source.provider()->asID(), source.provider()->url()));
-    return Completion(Normal);
+    return true;
+}
+    
+bool checkSyntax(VM& vm, const SourceCode& source, ParserError& error)
+{
+    JSLockHolder lock(vm);
+    RELEASE_ASSERT(vm.identifierTable == wtfThreadData().currentIdentifierTable());
+    RefPtr<ProgramNode> programNode = parse<ProgramNode>(&vm, source, 0, Identifier(), JSParseNormal, JSParseProgramCode, error);
+    return programNode;
 }
 
 }
 
-Completion evaluate(ExecState* exec, ScopeChain& scopeChain, const SourceCode& source, JSValuePtr thisValue)
+JSValue evaluate(ExecState* exec, const SourceCode& source, JSValue thisValue, JSValue* returnedException)
 {
 {
-    JSLock lock(exec);
-    
-    int errLine;
-    UString errMsg;
-    RefPtr<ProgramNode> programNode = exec->globalData().parser->parse<ProgramNode>(exec, exec->dynamicGlobalObject()->debugger(), source, &errLine, &errMsg);
+    JSLockHolder lock(exec);
+    RELEASE_ASSERT(exec->vm().identifierTable == wtfThreadData().currentIdentifierTable());
+    RELEASE_ASSERT(!exec->vm().isCollectorBusy());
 
 
-    if (!programNode)
-        return Completion(Throw, Error::create(exec, SyntaxError, errMsg, errLine, source.provider()->asID(), source.provider()->url()));
+    CodeProfiling profile(source);
 
 
-    JSObject* thisObj = (!thisValue || thisValue.isUndefinedOrNull()) ? exec->dynamicGlobalObject() : thisValue.toObject(exec);
+    ProgramExecutable* program = ProgramExecutable::create(exec, source);
+    if (!program) {
+        if (returnedException)
+            *returnedException = exec->vm().exception;
 
 
-    JSValuePtr exception = noValue();
-    JSValuePtr result = exec->interpreter()->execute(programNode.get(), exec, scopeChain.node(), thisObj, &exception);
+        exec->vm().exception = JSValue();
+        return jsUndefined();
+    }
 
 
-    if (exception) {
-        if (exception.isObject() && asObject(exception)->isWatchdogException())
-            return Completion(Interrupted, exception);
-        return Completion(Throw, exception);
+    if (!thisValue || thisValue.isUndefinedOrNull())
+        thisValue = exec->dynamicGlobalObject();
+    JSObject* thisObj = thisValue.toThisObject(exec);
+    JSValue result = exec->interpreter()->execute(program, exec, thisObj);
+
+    if (exec->hadException()) {
+        if (returnedException)
+            *returnedException = exec->exception();
+
+        exec->clearException();
+        return jsUndefined();
     }
     }
-    return Completion(Normal, result);
+
+    RELEASE_ASSERT(result);
+    return result;
 }
 
 } // namespace JSC
 }
 
 } // namespace JSC