X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/9dae56ea45a0f5f8136a5c93d6f3a7f99399ca73..ed1e77d3adeb83d26fd1dfb16dd84cabdcefd250:/runtime/Completion.cpp?ds=inline diff --git a/runtime/Completion.cpp b/runtime/Completion.cpp index 5655fa5..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,54 +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 - -#if !PLATFORM(WIN_OS) -#include -#endif +#include 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().atomicStringTable() == wtfThreadData().atomicStringTable()); - 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.atomicStringTable() == wtfThreadData().atomicStringTable()); + return !!parse( + &vm, source, 0, Identifier(), JSParserBuiltinMode::NotBuiltin, + JSParserStrictMode::NotStrict, JSParserCodeType::Program, error); } -Completion evaluate(ExecState* exec, ScopeChain& scopeChain, const SourceCode& source, JSValuePtr thisValue) +JSValue evaluate(ExecState* exec, const SourceCode& source, JSValue thisValue, NakedPtr& 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().atomicStringTable() == wtfThreadData().atomicStringTable()); + 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) { + returnedException = exec->vm().exception(); + exec->vm().clearException(); + return jsUndefined(); + } - JSValuePtr exception = noValue(); - JSValuePtr result = exec->interpreter()->execute(programNode.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()) { + returnedException = exec->exception(); + exec->clearException(); + return jsUndefined(); } - return Completion(Normal, result); + + RELEASE_ASSERT(result); + return result; } } // namespace JSC