X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/14957cd040308e3eeec43d26bae5d76da13fcd85..refs/heads/master:/runtime/Completion.cpp diff --git a/runtime/Completion.cpp b/runtime/Completion.cpp index ac19705..f67bc57 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,55 +24,71 @@ #include "Completion.h" #include "CallFrame.h" +#include "CodeProfiling.h" +#include "Debugger.h" +#include "Exception.h" +#include "Interpreter.h" #include "JSGlobalObject.h" #include "JSLock.h" -#include "Interpreter.h" +#include "JSCInlines.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().atomicStringTable() == wtfThreadData().atomicStringTable()); 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()); + return !!parse( + &vm, source, 0, Identifier(), JSParserBuiltinMode::NotBuiltin, + JSParserStrictMode::NotStrict, JSParserCodeType::Program, error); } -Completion evaluate(ExecState* exec, ScopeChainNode* scopeChain, const SourceCode& source, JSValue thisValue) +JSValue evaluate(ExecState* exec, const SourceCode& source, JSValue thisValue, NakedPtr& returnedException) { - JSLock lock(exec); - ASSERT(exec->globalData().identifierTable == wtfThreadData().currentIdentifierTable()); + JSLockHolder lock(exec); + RELEASE_ASSERT(exec->vm().atomicStringTable() == wtfThreadData().atomicStringTable()); + RELEASE_ASSERT(!exec->vm().isCollectorBusy()); + + CodeProfiling profile(source); ProgramExecutable* program = ProgramExecutable::create(exec, source); if (!program) { - JSValue exception = exec->globalData().exception; - exec->globalData().exception = JSValue(); - return Completion(Throw, exception); + returnedException = exec->vm().exception(); + exec->vm().clearException(); + return jsUndefined(); } - JSObject* thisObj = (!thisValue || thisValue.isUndefinedOrNull()) ? exec->dynamicGlobalObject() : thisValue.toObject(exec); - - JSValue result = exec->interpreter()->execute(program, exec, scopeChain, thisObj); + if (!thisValue || thisValue.isUndefinedOrNull()) + thisValue = exec->vmEntryGlobalObject(); + JSObject* thisObj = jsCast(thisValue.toThis(exec, NotStrictMode)); + JSValue result = exec->interpreter()->execute(program, exec, thisObj); if (exec->hadException()) { - JSValue exception = exec->exception(); + returnedException = exec->exception(); exec->clearException(); - - ComplType exceptionType = Throw; - if (exception.isObject()) - exceptionType = asObject(exception)->exceptionType(); - return Completion(exceptionType, exception); + return jsUndefined(); } - return Completion(Normal, result); + + RELEASE_ASSERT(result); + return result; } } // namespace JSC