Issue #1691 - Part 7d: Allow dynamic import in cases where there's no referencing script or module. Support dynamic import from classic scripts by creating ClassicScript objects and associating them with the compiled. https://bugzilla.mozilla.org/show_bug.cgi?id=1342012 This patch is incomplete, some code in ScriptLoader::EvaluateScript() could not be applied for missing dependencies. Part 7e will apply the missing dependencies and finish the patch.

(cherry picked from commit ce31a906e801b72f06385b0755710317ccf3658b)
This commit is contained in:
Brian Smith 2023-04-19 01:59:14 -05:00 committed by roytam1
commit d5d7bb5e47
6 changed files with 188 additions and 88 deletions

View file

@ -258,6 +258,9 @@ public:
// Holds the top-level JSScript that corresponds to the current source, once
// it is parsed, and planned to be saved in the bytecode cache.
JS::Heap<JSScript*> mScript;
// The base URL used for resolving relative module imports.
nsCOMPtr<nsIURI> mBaseURL;
};
class ScriptLoadRequestList : private mozilla::LinkedList<ScriptLoadRequest>
@ -561,11 +564,30 @@ public:
*/
void ClearModuleMap();
/**
* Implement the HostResolveImportedModule abstract operation.
*
* Resolve a module specifier string and look this up in the module
* map, returning the result. This is only called for previously
* loaded modules and always succeeds.
*
* @param aReferencingPrivate A JS::Value which is either undefined
* or contains a LoadedScript private pointer.
* @param aSpecifier The module specifier.
* @param aModuleOut This is set to the module found.
*/
static void ResolveImportedModule(JSContext* aCx,
JS::Handle<JS::Value> aReferencingPrivate,
JS::Handle<JSString*> aSpecifier,
JS::MutableHandle<JSObject*> aModuleOut);
void StartDynamicImport(ModuleLoadRequest* aRequest);
void FinishDynamicImport(ModuleLoadRequest* aRequest, nsresult aResult);
void FinishDynamicImport(JSContext* aCx, ModuleLoadRequest* aRequest,
nsresult aResult);
nsIDocument* GetDocument() const { return mDocument; }
private:
virtual ~ScriptLoader();