X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/4e4e5a6f2694187498445a6ac6f1634ce8141119..4be4e30906bcb8ee30b4d189205cb70bad6707ce:/runtime/Completion.cpp?ds=sidebyside diff --git a/runtime/Completion.cpp b/runtime/Completion.cpp index 9af5171..a2d8a6b 100644 --- a/runtime/Completion.cpp +++ b/runtime/Completion.cpp @@ -24,51 +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 "WTFThreadData.h" +#include #include namespace JSC { -Completion checkSyntax(ExecState* exec, const SourceCode& source) +bool checkSyntax(ExecState* exec, const SourceCode& source, JSValue* returnedException) { - JSLock lock(exec); - ASSERT(exec->globalData().identifierTable == wtfThreadData().currentIdentifierTable()); + JSLockHolder lock(exec); + RELEASE_ASSERT(exec->vm().identifierTable == wtfThreadData().currentIdentifierTable()); - RefPtr program = ProgramExecutable::create(exec, source); + 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; +} + +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); - ASSERT(exec->globalData().identifierTable == wtfThreadData().currentIdentifierTable()); + JSLockHolder lock(exec); + RELEASE_ASSERT(exec->vm().identifierTable == wtfThreadData().currentIdentifierTable()); + RELEASE_ASSERT(!exec->vm().isCollectorBusy()); + + CodeProfiling profile(source); - RefPtr program = ProgramExecutable::create(exec, source); - JSObject* error = program->compile(exec, scopeChain.node()); - if (error) - return Completion(Throw, error); + ProgramExecutable* program = ProgramExecutable::create(exec, source); + if (!program) { + if (returnedException) + *returnedException = exec->vm().exception; - JSObject* thisObj = (!thisValue || thisValue.isUndefinedOrNull()) ? exec->dynamicGlobalObject() : thisValue.toObject(exec); + exec->vm().exception = JSValue(); + return jsUndefined(); + } - JSValue exception; - JSValue result = exec->interpreter()->execute(program.get(), exec, scopeChain.node(), thisObj, &exception); + if (!thisValue || thisValue.isUndefinedOrNull()) + thisValue = exec->dynamicGlobalObject(); + JSObject* thisObj = thisValue.toThisObject(exec); + JSValue result = exec->interpreter()->execute(program, exec, thisObj); - if (exception) { - ComplType exceptionType = Throw; - if (exception.isObject()) - exceptionType = asObject(exception)->exceptionType(); - return Completion(exceptionType, exception); + if (exec->hadException()) { + if (returnedException) + *returnedException = exec->exception(); + + exec->clearException(); + return jsUndefined(); } - return Completion(Normal, result); + + RELEASE_ASSERT(result); + return result; } } // namespace JSC