X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/f9bf01c6616d5ddcf65b13b33cedf9e387ff7a63..cb9aa2694aba0ae4f946ed34b8e0f6c99c1cfe44:/runtime/Completion.cpp diff --git a/runtime/Completion.cpp b/runtime/Completion.cpp index 2f88df9..c414570 100644 --- a/runtime/Completion.cpp +++ b/runtime/Completion.cpp @@ -1,7 +1,7 @@ /* * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) * Copyright (C) 2001 Peter Kelly (pmk@post.com) - * Copyright (C) 2003, 2007 Apple Inc. + * Copyright (C) 2003, 2007, 2013 Apple Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -24,49 +24,73 @@ #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 "JSCInlines.h" #include "Parser.h" -#include "Debugger.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 == currentIdentifierTable()); + JSLockHolder lock(exec); + RELEASE_ASSERT(exec->vm().atomicStringTable() == wtfThreadData().atomicStringTable()); - 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.atomicStringTable() == wtfThreadData().atomicStringTable()); + 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 == currentIdentifierTable()); + JSLockHolder lock(exec); + RELEASE_ASSERT(exec->vm().atomicStringTable() == wtfThreadData().atomicStringTable()); + 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().clearException(); + return jsUndefined(); + } - JSValue exception; - JSValue result = exec->interpreter()->execute(program.get(), exec, scopeChain.node(), thisObj, &exception); + if (!thisValue || thisValue.isUndefinedOrNull()) + thisValue = exec->vmEntryGlobalObject(); + JSObject* thisObj = jsCast(thisValue.toThis(exec, NotStrictMode)); + JSValue result = exec->interpreter()->execute(program, exec, thisObj); - if (exception) { - if (exception.isObject() && asObject(exception)->isWatchdogException()) - return Completion(Interrupted, exception); - return Completion(Throw, exception); + if (exec->hadException()) { + if (returnedException) + *returnedException = exec->exception(); + + exec->clearException(); + return jsUndefined(); } - return Completion(Normal, result); + + RELEASE_ASSERT(result); + return result; } } // namespace JSC