JSInternalPromise* ModuleLoaderObject::instantiate(ExecState* exec, JSValue key, JSValue source) { if (Options::dumpModuleLoadingState()) dataLog("Loader [instantiate] ", printableModuleKey(exec, key), "\n"); JSGlobalObject* globalObject = exec->lexicalGlobalObject(); if (globalObject->globalObjectMethodTable()->moduleLoaderInstantiate) return globalObject->globalObjectMethodTable()->moduleLoaderInstantiate(globalObject, exec, key, source); JSInternalPromiseDeferred* deferred = JSInternalPromiseDeferred::create(exec, globalObject); deferred->resolve(exec, jsUndefined()); return deferred->promise(); }
JSInternalPromise* ModuleLoaderObject::translate(ExecState* exec, JSValue key, JSValue payload) { if (Options::dumpModuleLoadingState()) dataLog("Loader [translate] ", printableModuleKey(exec, key), "\n"); JSGlobalObject* globalObject = exec->lexicalGlobalObject(); if (globalObject->globalObjectMethodTable()->moduleLoaderTranslate) return globalObject->globalObjectMethodTable()->moduleLoaderTranslate(globalObject, exec, key, payload); JSInternalPromiseDeferred* deferred = JSInternalPromiseDeferred::create(exec, globalObject); deferred->resolve(exec, payload); return deferred->promise(); }
JSInternalPromise* ModuleLoaderObject::resolve(ExecState* exec, JSValue name, JSValue referrer) { if (Options::dumpModuleLoadingState()) dataLog("Loader [resolve] ", printableModuleKey(exec, name), "\n"); JSGlobalObject* globalObject = exec->lexicalGlobalObject(); if (globalObject->globalObjectMethodTable()->moduleLoaderResolve) return globalObject->globalObjectMethodTable()->moduleLoaderResolve(globalObject, exec, name, referrer); JSInternalPromiseDeferred* deferred = JSInternalPromiseDeferred::create(exec, globalObject); deferred->resolve(exec, name); return deferred->promise(); }
JSValue ModuleLoaderObject::evaluate(ExecState* exec, JSValue key, JSValue moduleRecordValue) { if (Options::dumpModuleLoadingState()) dataLog("Loader [evaluate] ", printableModuleKey(exec, key), "\n"); JSGlobalObject* globalObject = exec->lexicalGlobalObject(); if (globalObject->globalObjectMethodTable()->moduleLoaderEvaluate) return globalObject->globalObjectMethodTable()->moduleLoaderEvaluate(globalObject, exec, key, moduleRecordValue); JSModuleRecord* moduleRecord = jsDynamicCast<JSModuleRecord*>(moduleRecordValue); if (!moduleRecord) return jsUndefined(); return moduleRecord->evaluate(exec); }
JSInternalPromise* ModuleLoaderObject::fetch(ExecState* exec, JSValue key) { if (Options::dumpModuleLoadingState()) dataLog("Loader [fetch] ", printableModuleKey(exec, key), "\n"); JSGlobalObject* globalObject = exec->lexicalGlobalObject(); if (globalObject->globalObjectMethodTable()->moduleLoaderFetch) return globalObject->globalObjectMethodTable()->moduleLoaderFetch(globalObject, exec, key); JSInternalPromiseDeferred* deferred = JSInternalPromiseDeferred::create(exec, globalObject); String moduleKey = key.toString(exec)->value(exec); if (exec->hadException()) { JSValue exception = exec->exception()->value(); exec->clearException(); deferred->reject(exec, exception); return deferred->promise(); } deferred->reject(exec, createError(exec, makeString("Could not open the module '", moduleKey, "'."))); return deferred->promise(); }
JSInternalPromise* JSModuleLoader::fetch(ExecState* exec, JSValue key, JSValue scriptFetcher) { if (Options::dumpModuleLoadingState()) dataLog("Loader [fetch] ", printableModuleKey(exec, key), "\n"); JSGlobalObject* globalObject = exec->lexicalGlobalObject(); VM& vm = globalObject->vm(); auto scope = DECLARE_CATCH_SCOPE(vm); if (globalObject->globalObjectMethodTable()->moduleLoaderFetch) return globalObject->globalObjectMethodTable()->moduleLoaderFetch(globalObject, exec, this, key, scriptFetcher); JSInternalPromiseDeferred* deferred = JSInternalPromiseDeferred::create(exec, globalObject); String moduleKey = key.toWTFString(exec); if (UNLIKELY(scope.exception())) { JSValue exception = scope.exception()->value(); scope.clearException(); deferred->reject(exec, exception); return deferred->promise(); } deferred->reject(exec, createError(exec, makeString("Could not open the module '", moduleKey, "'."))); return deferred->promise(); }