X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/ba379fdc102753d6be2c4d937058fe40257329fe..4be4e30906bcb8ee30b4d189205cb70bad6707ce:/runtime/Completion.cpp diff --git a/runtime/Completion.cpp b/runtime/Completion.cpp index b8b1581..a2d8a6b 100644 --- a/runtime/Completion.cpp +++ b/runtime/Completion.cpp @@ -24,54 +24,74 @@ #include "Completion.h" #include "CallFrame.h" +#include "CodeProfiling.h" +#include "Debugger.h" +#include "Interpreter.h" #include "JSGlobalObject.h" #include "JSLock.h" -#include "Interpreter.h" +#include "Operations.h" #include "Parser.h" -#include "Debugger.h" +#include #include -#if !PLATFORM(WIN_OS) -#include -#endif - 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 progNode = exec->globalData().parser->parse(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 = parse(&vm, source, 0, Identifier(), JSParseNormal, JSParseProgramCode, error); + return programNode; } -Completion evaluate(ExecState* exec, ScopeChain& scopeChain, const SourceCode& source, JSValue thisValue) +JSValue evaluate(ExecState* exec, const SourceCode& source, JSValue thisValue, JSValue* returnedException) { - JSLock lock(exec); - - int errLine; - UString errMsg; - RefPtr programNode = exec->globalData().parser->parse(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; - JSValue exception; - JSValue 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