mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 15:49:44 -05:00
fix: dynamic import BorrowMutError (#6065)
This commit is contained in:
parent
445e44199b
commit
a90d9fbd34
1 changed files with 81 additions and 51 deletions
|
@ -330,13 +330,15 @@ impl EsIsolate {
|
||||||
let state_rc = Self::state(self);
|
let state_rc = Self::state(self);
|
||||||
|
|
||||||
let core_state_rc = CoreIsolate::state(self);
|
let core_state_rc = CoreIsolate::state(self);
|
||||||
let core_state = core_state_rc.borrow();
|
|
||||||
|
|
||||||
debug!("dyn_import_done {} {:?}", id, mod_id);
|
debug!("dyn_import_done {} {:?}", id, mod_id);
|
||||||
assert!(mod_id != 0);
|
assert!(mod_id != 0);
|
||||||
let mut hs = v8::HandleScope::new(&mut self.0);
|
let mut hs = v8::HandleScope::new(&mut self.0);
|
||||||
let scope = hs.enter();
|
let scope = hs.enter();
|
||||||
let context = core_state.global_context.get(scope).unwrap();
|
let context = {
|
||||||
|
let core_state = core_state_rc.borrow();
|
||||||
|
core_state.global_context.get(scope).unwrap()
|
||||||
|
};
|
||||||
let mut cs = v8::ContextScope::new(scope, context);
|
let mut cs = v8::ContextScope::new(scope, context);
|
||||||
let scope = cs.enter();
|
let scope = cs.enter();
|
||||||
|
|
||||||
|
@ -837,8 +839,6 @@ pub mod tests {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn dyn_import_ok() {
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
struct DynImportOkLoader {
|
struct DynImportOkLoader {
|
||||||
pub prepare_load_count: Arc<AtomicUsize>,
|
pub prepare_load_count: Arc<AtomicUsize>,
|
||||||
|
@ -888,6 +888,8 @@ pub mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn dyn_import_ok() {
|
||||||
run_in_task(|cx| {
|
run_in_task(|cx| {
|
||||||
let loader = Rc::new(DynImportOkLoader::default());
|
let loader = Rc::new(DynImportOkLoader::default());
|
||||||
let prepare_load_count = loader.prepare_load_count.clone();
|
let prepare_load_count = loader.prepare_load_count.clone();
|
||||||
|
@ -935,4 +937,32 @@ pub mod tests {
|
||||||
assert_eq!(load_count.load(Ordering::Relaxed), 2);
|
assert_eq!(load_count.load(Ordering::Relaxed), 2);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn dyn_import_borrow_mut_error() {
|
||||||
|
// https://github.com/denoland/deno/issues/6054
|
||||||
|
run_in_task(|cx| {
|
||||||
|
let loader = Rc::new(DynImportOkLoader::default());
|
||||||
|
let prepare_load_count = loader.prepare_load_count.clone();
|
||||||
|
let mut isolate = EsIsolate::new(loader, StartupData::None, false);
|
||||||
|
js_check(isolate.execute(
|
||||||
|
"file:///dyn_import3.js",
|
||||||
|
r#"
|
||||||
|
(async () => {
|
||||||
|
let mod = await import("./b.js");
|
||||||
|
if (mod.b() !== 'b') {
|
||||||
|
throw Error("bad");
|
||||||
|
}
|
||||||
|
// Now do any op
|
||||||
|
Deno.core.ops();
|
||||||
|
})();
|
||||||
|
"#,
|
||||||
|
));
|
||||||
|
// First poll runs `prepare_load` hook.
|
||||||
|
let _ = isolate.poll_unpin(cx);
|
||||||
|
assert_eq!(prepare_load_count.load(Ordering::Relaxed), 1);
|
||||||
|
// Second poll triggers error
|
||||||
|
let _ = isolate.poll_unpin(cx);
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue