mirror of
https://github.com/lexmount/moli.git
synced 2026-10-08 00:01:00 +00:00
fix(modules): expose inline import meta base URLs
This commit is contained in:
@@ -304,12 +304,6 @@ impl DocumentRuntime {
|
||||
.native_compiled_module(entry_id)
|
||||
}
|
||||
|
||||
pub(crate) fn native_module_url_for(&self, module: v8::Local<'_, v8::Module>) -> Option<Url> {
|
||||
self.script_lifecycle
|
||||
.scripts()
|
||||
.native_module_url_for(module)
|
||||
}
|
||||
|
||||
pub(crate) fn mark_native_module_instantiated(&mut self, entry_id: ModuleEntryId) {
|
||||
self.script_lifecycle
|
||||
.scripts_mut()
|
||||
|
||||
@@ -687,13 +687,6 @@ impl HostScriptScheduler {
|
||||
self.module_owner.native_compiled_module(entry_id)
|
||||
}
|
||||
|
||||
pub(crate) fn native_module_url_for(
|
||||
&self,
|
||||
module: v8::Local<'_, v8::Module>,
|
||||
) -> Option<url::Url> {
|
||||
self.module_owner.native_module_url_for(module)
|
||||
}
|
||||
|
||||
pub(crate) fn mark_native_module_instantiated(&mut self, entry_id: ModuleEntryId) {
|
||||
self.module_owner.mark_native_module_instantiated(entry_id);
|
||||
}
|
||||
|
||||
@@ -592,12 +592,6 @@ impl ModuleOwnerState {
|
||||
.map(|record| record.compiled_module().clone())
|
||||
}
|
||||
|
||||
pub(crate) fn native_module_url_for(&self, module: v8::Local<'_, v8::Module>) -> Option<Url> {
|
||||
self.document_modulator
|
||||
.module_key_for(module)
|
||||
.map(|key| key.url().clone())
|
||||
}
|
||||
|
||||
pub(crate) fn mark_native_module_instantiated(&mut self, entry_id: ModuleEntryId) {
|
||||
self.document_modulator.mark_instantiated(entry_id);
|
||||
}
|
||||
|
||||
@@ -2307,7 +2307,7 @@ fn module_script_inline_tree_job_for_owner(
|
||||
let (record, identity) = match vm.compile_native_module_record(
|
||||
key.clone(),
|
||||
&source,
|
||||
&root.source_url,
|
||||
&root.base_url,
|
||||
&root.fetch_metadata,
|
||||
) {
|
||||
Ok(result) => result,
|
||||
|
||||
@@ -35,16 +35,10 @@ pub(crate) unsafe extern "C" fn initialize_import_meta_object_callback(
|
||||
meta: v8::Local<'_, v8::Object>,
|
||||
) {
|
||||
v8::callback_scope!(unsafe scope, context);
|
||||
let Some(host_ptr) = context_host_ptr_from_global_bridge(scope) else {
|
||||
let Ok(module_url) = v8::Local::<v8::String>::try_from(module.get_resource_name(scope)) else {
|
||||
return;
|
||||
};
|
||||
let Some(module_url) = (unsafe { &*host_ptr }).native_module_url_for(module) else {
|
||||
return;
|
||||
};
|
||||
let Some(value) = v8_string(scope, module_url.as_str()) else {
|
||||
return;
|
||||
};
|
||||
let _ = ImportMetaDeclaration::new(value).initialize(scope, meta);
|
||||
let _ = ImportMetaDeclaration::new(module_url).initialize(scope, meta);
|
||||
}
|
||||
|
||||
pub(crate) fn dynamic_import_callback<'s, 'i>(
|
||||
|
||||
@@ -655,14 +655,6 @@ impl NativeDocumentModulator {
|
||||
.set_record_state_for_entry(self.core.entry(entry_id), ModuleRecordState::Evaluated);
|
||||
}
|
||||
|
||||
pub(crate) fn module_key_for(
|
||||
&self,
|
||||
module: v8::Local<'_, v8::Module>,
|
||||
) -> Option<&ModuleMapKey> {
|
||||
self.module_entry_id_for(module)
|
||||
.map(|entry_id| self.entry(entry_id).effective_key())
|
||||
}
|
||||
|
||||
pub(crate) fn module_source_for(
|
||||
&self,
|
||||
module: v8::Local<'_, v8::Module>,
|
||||
|
||||
@@ -11945,15 +11945,19 @@ async fn stream_declared_controller_and_writer_surface_ignores_reflection_and_sp
|
||||
async fn parser_inline_module_runs_from_parser_after_parsing_order() {
|
||||
run_page_vm_async_test(async move {
|
||||
let loader = crate::network::ResourceRequestClient::new(&FetchConfig::default()).expect("loader");
|
||||
let document_url = Url::parse(
|
||||
"https://example.com/page.html?case=inline-module#document-fragment",
|
||||
)
|
||||
.expect("document URL");
|
||||
let mut page_vm = test_page_vm_with_loader_and_document_url(
|
||||
&loader,
|
||||
Vec::new(),
|
||||
Url::parse("https://example.com/page.html").expect("document URL"),
|
||||
document_url.clone(),
|
||||
);
|
||||
let script = prepared_inline_module_for_page_vm_test(
|
||||
&page_vm,
|
||||
9002,
|
||||
"globalThis.__inlineParserModuleExecuted = (globalThis.__inlineParserModuleExecuted ?? 0) + 1; export const value = 1;",
|
||||
"globalThis.__inlineParserModuleExecuted = (globalThis.__inlineParserModuleExecuted ?? 0) + 1; globalThis.__inlineParserModuleUrl = import.meta.url; export const value = 1;",
|
||||
);
|
||||
|
||||
let parser_module_work = install_parser_module_defer_work(&mut page_vm, script);
|
||||
@@ -11989,6 +11993,14 @@ async fn parser_inline_module_runs_from_parser_after_parsing_order() {
|
||||
"1",
|
||||
"parser after-parsing release should evaluate the prewarmed inline graph once"
|
||||
);
|
||||
assert_eq!(
|
||||
page_vm
|
||||
.vm_mut()
|
||||
.eval("globalThis.__inlineParserModuleUrl")
|
||||
.expect("read inline module URL after page task"),
|
||||
document_url.as_str(),
|
||||
"an inline module must expose its document base URL, not its internal module-map key"
|
||||
);
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
@@ -8871,7 +8871,9 @@ async fn child_inline_parser_module_executes_from_registered_pending_script() {
|
||||
frame.srcdoc = `
|
||||
<script>parent.__childInlineParserModuleEvents.push("before");<\/script>
|
||||
<script type="module">
|
||||
parent.__childInlineParserModuleEvents.push("module:" + (globalThis === self));
|
||||
parent.__childInlineParserModuleEvents.push(
|
||||
"module:" + (globalThis === self) + ":" + import.meta.url + ":" + import.meta.resolve("./x")
|
||||
);
|
||||
globalThis.__childInlineParserModuleValue = 42;
|
||||
<\/script>
|
||||
<script>parent.__childInlineParserModuleEvents.push("after:" + String(globalThis.__childInlineParserModuleValue));<\/script>
|
||||
@@ -8950,7 +8952,7 @@ async fn child_inline_parser_module_executes_from_registered_pending_script() {
|
||||
assert_eq!(
|
||||
vm.eval("__childInlineParserModuleEvents.join('|')")
|
||||
.expect("child inline parser module events should evaluate"),
|
||||
"before|after:undefined|module:true"
|
||||
"before|after:undefined|module:true:http://child-inline-module.test/:http://child-inline-module.test/x"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Vendored
+16
@@ -211,6 +211,7 @@ where
|
||||
}
|
||||
|
||||
unsafe extern "C" {
|
||||
fn v8__Module__GetResourceName(this: *const Module) -> *const Value;
|
||||
fn v8__Module__GetStatus(this: *const Module) -> ModuleStatus;
|
||||
fn v8__Module__GetException(this: *const Module) -> *const Value;
|
||||
fn v8__Module__GetModuleRequests(this: *const Module) -> *const FixedArray;
|
||||
@@ -323,6 +324,21 @@ pub enum ModuleStatus {
|
||||
}
|
||||
|
||||
impl Module {
|
||||
/// If this is a source text module, returns the resource name passed to its
|
||||
/// [`ScriptOrigin`](crate::ScriptOrigin). If this is a synthetic module,
|
||||
/// returns the name passed to [`Module::create_synthetic_module`].
|
||||
#[inline(always)]
|
||||
pub fn get_resource_name<'s>(
|
||||
&self,
|
||||
scope: &PinScope<'s, '_>,
|
||||
) -> Local<'s, Value> {
|
||||
unsafe {
|
||||
scope
|
||||
.cast_local(|_| v8__Module__GetResourceName(self))
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the module's current status.
|
||||
#[inline(always)]
|
||||
pub fn get_status(&self) -> ModuleStatus {
|
||||
|
||||
Vendored
+4
@@ -7,6 +7,10 @@ using namespace support;
|
||||
|
||||
extern "C" {
|
||||
|
||||
const v8::Value* v8__Module__GetResourceName(const v8::Module& self) {
|
||||
return local_to_ptr(self.GetResourceName());
|
||||
}
|
||||
|
||||
MaybeBool v8__Module__SetSyntheticModuleExportUninitialized(
|
||||
const v8::Module& self,
|
||||
v8::Isolate* isolate,
|
||||
|
||||
Reference in New Issue
Block a user