Ignore:
Timestamp:
Aug 24, 2015, 4:48:55 PM (10 years ago)
Author:
Yusuke Suzuki
Message:

[ES6] Return JSInternalPromise as result of evaluateModule
https://bugs.webkit.org/show_bug.cgi?id=148173

Reviewed by Saam Barati.

Now evaluateModule returns JSInternalPromise* as its result value.
When an error occurs while loading or executing the modules,
this promise is rejected by that error. By leveraging this, we implemented
asynchronous error reporting when executing the modules in JSC shell.

And this patch also changes the evaluateModule signature to accept the entry
point by the moduleName. By using it, JSC shell can start executing the modules
with the entry point module name.

  • builtins/ModuleLoaderObject.js:

(loadModule):

  • jsc.cpp:

(dumpException):
(runWithScripts):

  • runtime/Completion.cpp:

(JSC::evaluateModule):

  • runtime/Completion.h:
  • runtime/JSInternalPromise.cpp:

(JSC::JSInternalPromise::then):

  • runtime/JSInternalPromise.h:
  • runtime/ModuleLoaderObject.cpp:

(JSC::ModuleLoaderObject::requestInstantiateAll):
(JSC::ModuleLoaderObject::loadModule):
(JSC::ModuleLoaderObject::resolve):
(JSC::ModuleLoaderObject::fetch):
(JSC::ModuleLoaderObject::translate):
(JSC::ModuleLoaderObject::instantiate):
(JSC::moduleLoaderObjectParseModule):

  • runtime/ModuleLoaderObject.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/Completion.cpp

    r188752 r188894  
    3131#include "JSCInlines.h"
    3232#include "JSGlobalObject.h"
     33#include "JSInternalPromise.h"
     34#include "JSInternalPromiseDeferred.h"
    3335#include "JSLock.h"
    3436#include "JSModuleRecord.h"
     
    112114}
    113115
    114 void evaluateModule(ExecState* exec, const SourceCode& source, NakedPtr<Exception>& returnedException)
     116static JSInternalPromise* evaluateModule(const JSLockHolder&, ExecState* exec, JSGlobalObject* globalObject, JSValue moduleName, JSValue referrer)
     117{
     118    return globalObject->moduleLoader()->loadModule(exec, moduleName, referrer);
     119}
     120
     121static JSInternalPromise* evaluateModule(const JSLockHolder& lock, ExecState* exec, JSGlobalObject* globalObject, const Identifier& moduleName)
     122{
     123    JSValue moduleNameValue;
     124    if (moduleName.isSymbol())
     125        moduleNameValue = Symbol::create(exec->vm(), static_cast<SymbolImpl&>(*moduleName.impl()));
     126    else
     127        moduleNameValue = jsString(&exec->vm(), moduleName.impl());
     128
     129    return evaluateModule(lock, exec, globalObject, moduleNameValue, jsUndefined());
     130}
     131
     132JSInternalPromise* evaluateModule(ExecState* exec, const SourceCode& source)
    115133{
    116134    JSLockHolder lock(exec);
    117135    RELEASE_ASSERT(exec->vm().atomicStringTable() == wtfThreadData().atomicStringTable());
    118136    RELEASE_ASSERT(!exec->vm().isCollectorBusy());
    119 
    120     CodeProfiling profile(source);
    121137
    122138    JSGlobalObject* globalObject = exec->vmEntryGlobalObject();
     
    126142    Symbol* key = Symbol::create(exec->vm(), *privateName.uid());
    127143
    128     ModuleLoaderObject* moduleLoader = globalObject->moduleLoader();
    129 
    130144    // Insert the given source code to the ModuleLoader registry as the fetched registry entry.
    131     moduleLoader->provide(exec, key, ModuleLoaderObject::Status::Fetch, source.toString());
     145    globalObject->moduleLoader()->provide(exec, key, ModuleLoaderObject::Status::Fetch, source.toString());
    132146    if (exec->hadException()) {
    133         returnedException = exec->exception();
     147        JSValue exception = exec->exception()->value();
    134148        exec->clearException();
    135         return;
     149        JSInternalPromiseDeferred* deferred = JSInternalPromiseDeferred::create(exec, globalObject);
     150        deferred->reject(exec, exception);
     151        return deferred->promise();
    136152    }
    137153
    138     // FIXME: Now, we don't implement the linking phase yet.
    139     // So here, we just call requestInstantiateAll to only perform the module loading.
    140     // At last, it should be replaced with requestReady.
    141     // https://bugs.webkit.org/show_bug.cgi?id=148172
    142     moduleLoader->requestInstantiateAll(exec, key);
     154    return evaluateModule(lock, exec, globalObject, key, jsUndefined());
     155}
    143156
    144     // FIXME: We should also handle the asynchronous Syntax Errors that will be delivered by the rejected promise.
    145     // https://bugs.webkit.org/show_bug.cgi?id=148173
    146     if (exec->hadException()) {
    147         returnedException = exec->exception();
    148         exec->clearException();
    149         return;
    150     }
     157JSInternalPromise* evaluateModule(ExecState* exec, const Identifier& moduleName)
     158{
     159    JSLockHolder lock(exec);
     160    RELEASE_ASSERT(exec->vm().atomicStringTable() == wtfThreadData().atomicStringTable());
     161    RELEASE_ASSERT(!exec->vm().isCollectorBusy());
     162
     163    return evaluateModule(lock, exec, exec->vmEntryGlobalObject(), moduleName);
     164}
     165
     166JSInternalPromise* evaluateModule(ExecState* exec, const String& moduleName)
     167{
     168    JSLockHolder lock(exec);
     169    RELEASE_ASSERT(exec->vm().atomicStringTable() == wtfThreadData().atomicStringTable());
     170    RELEASE_ASSERT(!exec->vm().isCollectorBusy());
     171
     172    return evaluateModule(lock, exec, exec->vmEntryGlobalObject(), Identifier::fromString(exec, moduleName));
    151173}
    152174
Note: See TracChangeset for help on using the changeset viewer.