summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/runtime/Completion.cpp
diff options
context:
space:
mode:
authorKonstantin Tokarev <annulen@yandex.ru>2016-08-25 19:20:41 +0300
committerKonstantin Tokarev <annulen@yandex.ru>2017-02-02 12:30:55 +0000
commit6882a04fb36642862b11efe514251d32070c3d65 (patch)
treeb7959826000b061fd5ccc7512035c7478742f7b0 /Source/JavaScriptCore/runtime/Completion.cpp
parentab6df191029eeeb0b0f16f127d553265659f739e (diff)
downloadqtwebkit-6882a04fb36642862b11efe514251d32070c3d65.tar.gz
Imported QtWebKit TP3 (git b57bc6801f1876c3220d5a4bfea33d620d477443)
Change-Id: I3b1d8a2808782c9f34d50240000e20cb38d3680f Reviewed-by: Konstantin Tokarev <annulen@yandex.ru>
Diffstat (limited to 'Source/JavaScriptCore/runtime/Completion.cpp')
-rw-r--r--Source/JavaScriptCore/runtime/Completion.cpp164
1 files changed, 146 insertions, 18 deletions
diff --git a/Source/JavaScriptCore/runtime/Completion.cpp b/Source/JavaScriptCore/runtime/Completion.cpp
index a2d8a6b5f..c178a4a52 100644
--- a/Source/JavaScriptCore/runtime/Completion.cpp
+++ b/Source/JavaScriptCore/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
@@ -26,20 +26,27 @@
#include "CallFrame.h"
#include "CodeProfiling.h"
#include "Debugger.h"
+#include "Exception.h"
+#include "IdentifierInlines.h"
#include "Interpreter.h"
+#include "JSCInlines.h"
#include "JSGlobalObject.h"
+#include "JSInternalPromise.h"
+#include "JSInternalPromiseDeferred.h"
#include "JSLock.h"
-#include "Operations.h"
+#include "JSModuleRecord.h"
+#include "ModuleAnalyzer.h"
+#include "ModuleLoaderObject.h"
#include "Parser.h"
+#include "ScriptProfilingScope.h"
#include <wtf/WTFThreadData.h>
-#include <stdio.h>
namespace JSC {
bool checkSyntax(ExecState* exec, const SourceCode& source, JSValue* returnedException)
{
JSLockHolder lock(exec);
- RELEASE_ASSERT(exec->vm().identifierTable == wtfThreadData().currentIdentifierTable());
+ RELEASE_ASSERT(exec->vm().atomicStringTable() == wtfThreadData().atomicStringTable());
ProgramExecutable* program = ProgramExecutable::create(exec, source);
JSObject* error = program->checkSyntax(exec);
@@ -55,37 +62,51 @@ bool checkSyntax(ExecState* exec, const SourceCode& source, JSValue* returnedExc
bool checkSyntax(VM& vm, const SourceCode& source, ParserError& error)
{
JSLockHolder lock(vm);
- RELEASE_ASSERT(vm.identifierTable == wtfThreadData().currentIdentifierTable());
- RefPtr<ProgramNode> programNode = parse<ProgramNode>(&vm, source, 0, Identifier(), JSParseNormal, JSParseProgramCode, error);
- return programNode;
+ RELEASE_ASSERT(vm.atomicStringTable() == wtfThreadData().atomicStringTable());
+ return !!parse<ProgramNode>(
+ &vm, source, Identifier(), JSParserBuiltinMode::NotBuiltin,
+ JSParserStrictMode::NotStrict, SourceParseMode::ProgramMode, SuperBinding::NotNeeded, error);
}
-JSValue evaluate(ExecState* exec, const SourceCode& source, JSValue thisValue, JSValue* returnedException)
+bool checkModuleSyntax(ExecState* exec, const SourceCode& source, ParserError& error)
+{
+ VM& vm = exec->vm();
+ JSLockHolder lock(vm);
+ RELEASE_ASSERT(vm.atomicStringTable() == wtfThreadData().atomicStringTable());
+ std::unique_ptr<ModuleProgramNode> moduleProgramNode = parse<ModuleProgramNode>(
+ &vm, source, Identifier(), JSParserBuiltinMode::NotBuiltin,
+ JSParserStrictMode::Strict, SourceParseMode::ModuleAnalyzeMode, SuperBinding::NotNeeded, error);
+ if (!moduleProgramNode)
+ return false;
+
+ PrivateName privateName(PrivateName::Description, "EntryPointModule");
+ ModuleAnalyzer moduleAnalyzer(exec, Identifier::fromUid(privateName), source, moduleProgramNode->varDeclarations(), moduleProgramNode->lexicalVariables());
+ moduleAnalyzer.analyze(*moduleProgramNode);
+ return true;
+}
+
+JSValue evaluate(ExecState* exec, const SourceCode& source, JSValue thisValue, NakedPtr<Exception>& returnedException)
{
JSLockHolder lock(exec);
- RELEASE_ASSERT(exec->vm().identifierTable == wtfThreadData().currentIdentifierTable());
+ RELEASE_ASSERT(exec->vm().atomicStringTable() == wtfThreadData().atomicStringTable());
RELEASE_ASSERT(!exec->vm().isCollectorBusy());
CodeProfiling profile(source);
ProgramExecutable* program = ProgramExecutable::create(exec, source);
if (!program) {
- if (returnedException)
- *returnedException = exec->vm().exception;
-
- exec->vm().exception = JSValue();
+ returnedException = exec->vm().exception();
+ exec->vm().clearException();
return jsUndefined();
}
if (!thisValue || thisValue.isUndefinedOrNull())
- thisValue = exec->dynamicGlobalObject();
- JSObject* thisObj = thisValue.toThisObject(exec);
+ thisValue = exec->vmEntryGlobalObject();
+ JSObject* thisObj = jsCast<JSObject*>(thisValue.toThis(exec, NotStrictMode));
JSValue result = exec->interpreter()->execute(program, exec, thisObj);
if (exec->hadException()) {
- if (returnedException)
- *returnedException = exec->exception();
-
+ returnedException = exec->exception();
exec->clearException();
return jsUndefined();
}
@@ -94,4 +115,111 @@ JSValue evaluate(ExecState* exec, const SourceCode& source, JSValue thisValue, J
return result;
}
+JSValue profiledEvaluate(ExecState* exec, ProfilingReason reason, const SourceCode& source, JSValue thisValue, NakedPtr<Exception>& returnedException)
+{
+ ScriptProfilingScope profilingScope(exec->vmEntryGlobalObject(), reason);
+ return evaluate(exec, source, thisValue, returnedException);
+}
+
+static Symbol* createSymbolForEntryPointModule(VM& vm)
+{
+ // Generate the unique key for the source-provided module.
+ PrivateName privateName(PrivateName::Description, "EntryPointModule");
+ return Symbol::create(vm, *privateName.uid());
+}
+
+static JSInternalPromise* rejectPromise(ExecState* exec, JSGlobalObject* globalObject)
+{
+ ASSERT(exec->hadException());
+ JSValue exception = exec->exception()->value();
+ exec->clearException();
+ JSInternalPromiseDeferred* deferred = JSInternalPromiseDeferred::create(exec, globalObject);
+ deferred->reject(exec, exception);
+ return deferred->promise();
+}
+
+static JSInternalPromise* loadAndEvaluateModule(const JSLockHolder&, ExecState* exec, JSGlobalObject* globalObject, JSValue moduleName, JSValue referrer)
+{
+ return globalObject->moduleLoader()->loadAndEvaluateModule(exec, moduleName, referrer);
+}
+
+static JSInternalPromise* loadAndEvaluateModule(const JSLockHolder& lock, ExecState* exec, JSGlobalObject* globalObject, const Identifier& moduleName)
+{
+ return loadAndEvaluateModule(lock, exec, globalObject, identifierToJSValue(exec->vm(), moduleName), jsUndefined());
+}
+
+JSInternalPromise* loadAndEvaluateModule(ExecState* exec, const String& moduleName)
+{
+ JSLockHolder lock(exec);
+ RELEASE_ASSERT(exec->vm().atomicStringTable() == wtfThreadData().atomicStringTable());
+ RELEASE_ASSERT(!exec->vm().isCollectorBusy());
+
+ return loadAndEvaluateModule(lock, exec, exec->vmEntryGlobalObject(), Identifier::fromString(exec, moduleName));
+}
+
+JSInternalPromise* loadAndEvaluateModule(ExecState* exec, const SourceCode& source)
+{
+ JSLockHolder lock(exec);
+ RELEASE_ASSERT(exec->vm().atomicStringTable() == wtfThreadData().atomicStringTable());
+ RELEASE_ASSERT(!exec->vm().isCollectorBusy());
+
+ Symbol* key = createSymbolForEntryPointModule(exec->vm());
+
+ JSGlobalObject* globalObject = exec->vmEntryGlobalObject();
+
+ // Insert the given source code to the ModuleLoader registry as the fetched registry entry.
+ globalObject->moduleLoader()->provide(exec, key, ModuleLoaderObject::Status::Fetch, source.view().toString());
+ if (exec->hadException())
+ return rejectPromise(exec, globalObject);
+
+ return loadAndEvaluateModule(lock, exec, globalObject, key, jsUndefined());
+}
+
+static JSInternalPromise* loadModule(const JSLockHolder&, ExecState* exec, JSGlobalObject* globalObject, JSValue moduleName, JSValue referrer)
+{
+ return globalObject->moduleLoader()->loadModule(exec, moduleName, referrer);
+}
+
+static JSInternalPromise* loadModule(const JSLockHolder& lock, ExecState* exec, JSGlobalObject* globalObject, const Identifier& moduleName)
+{
+ return loadModule(lock, exec, globalObject, identifierToJSValue(exec->vm(), moduleName), jsUndefined());
+}
+
+JSInternalPromise* loadModule(ExecState* exec, const String& moduleName)
+{
+ JSLockHolder lock(exec);
+ RELEASE_ASSERT(exec->vm().atomicStringTable() == wtfThreadData().atomicStringTable());
+ RELEASE_ASSERT(!exec->vm().isCollectorBusy());
+
+ return loadModule(lock, exec, exec->vmEntryGlobalObject(), Identifier::fromString(exec, moduleName));
+}
+
+JSInternalPromise* loadModule(ExecState* exec, const SourceCode& source)
+{
+ JSLockHolder lock(exec);
+ RELEASE_ASSERT(exec->vm().atomicStringTable() == wtfThreadData().atomicStringTable());
+ RELEASE_ASSERT(!exec->vm().isCollectorBusy());
+
+ Symbol* key = createSymbolForEntryPointModule(exec->vm());
+
+ JSGlobalObject* globalObject = exec->vmEntryGlobalObject();
+
+ // Insert the given source code to the ModuleLoader registry as the fetched registry entry.
+ globalObject->moduleLoader()->provide(exec, key, ModuleLoaderObject::Status::Fetch, source.view().toString());
+ if (exec->hadException())
+ return rejectPromise(exec, globalObject);
+
+ return loadModule(lock, exec, globalObject, key, jsUndefined());
+}
+
+JSInternalPromise* linkAndEvaluateModule(ExecState* exec, const Identifier& moduleKey)
+{
+ JSLockHolder lock(exec);
+ RELEASE_ASSERT(exec->vm().atomicStringTable() == wtfThreadData().atomicStringTable());
+ RELEASE_ASSERT(!exec->vm().isCollectorBusy());
+
+ JSGlobalObject* globalObject = exec->vmEntryGlobalObject();
+ return globalObject->moduleLoader()->linkAndEvaluateModule(exec, identifierToJSValue(exec->vm(), moduleKey));
+}
+
} // namespace JSC