JSC::JSValue ScriptModuleLoader::evaluate(JSC::JSGlobalObject*, JSC::ExecState* exec, JSC::JSModuleLoader*, JSC::JSValue moduleKeyValue, JSC::JSValue moduleRecordValue, JSC::JSValue) { JSC::VM& vm = exec->vm(); auto scope = DECLARE_THROW_SCOPE(vm); // FIXME: Currently, we only support JSModuleRecord. // Once the reflective part of the module loader is supported, we will handle arbitrary values. // https://whatwg.github.io/loader/#registry-prototype-provide auto* moduleRecord = jsDynamicDowncast<JSC::JSModuleRecord*>(moduleRecordValue); if (!moduleRecord) return JSC::jsUndefined(); URL sourceURL; if (moduleKeyValue.isSymbol()) sourceURL = m_document.url(); else if (moduleKeyValue.isString()) sourceURL = URL(URL(), asString(moduleKeyValue)->value(exec)); else return JSC::throwTypeError(exec, scope, ASCIILiteral("Module key is not Symbol or String.")); if (!sourceURL.isValid()) return JSC::throwTypeError(exec, scope, ASCIILiteral("Module key is an invalid URL.")); if (auto* frame = m_document.frame()) return frame->script().evaluateModule(sourceURL, *moduleRecord); return JSC::jsUndefined(); }
JSC::JSValue JSModuleLoader::evaluate(JSC::JSGlobalObject*, JSC::ExecState* exec, JSC::JSModuleLoader*, JSC::JSValue moduleKeyValue, JSC::JSValue moduleRecordValue) { // FIXME: Currently, we only support JSModuleRecord. // Once the reflective part of the module loader is supported, we will handle arbitrary values. // https://whatwg.github.io/loader/#registry-prototype-provide JSC::JSModuleRecord* moduleRecord = JSC::jsDynamicCast<JSC::JSModuleRecord*>(moduleRecordValue); if (!moduleRecord) return JSC::jsUndefined(); URL sourceUrl; if (moduleKeyValue.isSymbol()) sourceUrl = m_document.url(); else if (moduleKeyValue.isString()) sourceUrl = URL(URL(), asString(moduleKeyValue)->value(exec)); else return JSC::throwTypeError(exec, ASCIILiteral("Module key is not Symbol or String.")); if (!sourceUrl.isValid()) return JSC::throwTypeError(exec, ASCIILiteral("Module key is an invalid URL.")); // FIXME: Implement evaluating module code. return JSC::jsUndefined(); }
static bool isRootModule(JSC::JSValue importerModuleKey) { return importerModuleKey.isSymbol() || importerModuleKey.isUndefined(); }