mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 10:33:54 +00:00
Merge mod_evaluate() and mod_evaluate_dyn_import() methods (#4167)
This commit is contained in:
parent
397deb4e29
commit
1cb1ab6c00
2 changed files with 3 additions and 47 deletions
|
@ -76,7 +76,7 @@ test(async function workerThrowsWhenExecuting(): Promise<void> {
|
|||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
throwingWorker.onerror = (e: any): void => {
|
||||
e.preventDefault();
|
||||
assertEquals(e.message, "Uncaught Error: Thrown error");
|
||||
assert(/Uncaught Error: Thrown error/.test(e.message));
|
||||
promise.resolve();
|
||||
};
|
||||
|
||||
|
|
|
@ -226,51 +226,6 @@ impl EsIsolate {
|
|||
}
|
||||
}
|
||||
|
||||
/// TODO(bartlomieju): copy-pasta to avoid problem with global handle attached
|
||||
/// to ErrBox
|
||||
pub fn mod_evaluate_dyn_import(
|
||||
&mut self,
|
||||
id: ModuleId,
|
||||
) -> Result<(), ErrBox> {
|
||||
let v8_isolate = self.core_isolate.v8_isolate.as_mut().unwrap();
|
||||
let js_error_create_fn = &*self.core_isolate.js_error_create_fn;
|
||||
|
||||
let mut hs = v8::HandleScope::new(v8_isolate);
|
||||
let scope = hs.enter();
|
||||
assert!(!self.core_isolate.global_context.is_empty());
|
||||
let context = self.core_isolate.global_context.get(scope).unwrap();
|
||||
let mut cs = v8::ContextScope::new(scope, context);
|
||||
let scope = cs.enter();
|
||||
|
||||
let info = self.modules.get_info(id).expect("ModuleInfo not found");
|
||||
let mut module = info.handle.get(scope).expect("Empty module handle");
|
||||
let mut status = module.get_status();
|
||||
|
||||
if status == v8::ModuleStatus::Instantiated {
|
||||
let ok = module.evaluate(scope, context).is_some();
|
||||
// Update status after evaluating.
|
||||
status = module.get_status();
|
||||
if ok {
|
||||
assert!(
|
||||
status == v8::ModuleStatus::Evaluated
|
||||
|| status == v8::ModuleStatus::Errored
|
||||
);
|
||||
} else {
|
||||
assert!(status == v8::ModuleStatus::Errored);
|
||||
}
|
||||
}
|
||||
|
||||
match status {
|
||||
v8::ModuleStatus::Evaluated => Ok(()),
|
||||
v8::ModuleStatus::Errored => {
|
||||
let exception = module.get_exception();
|
||||
exception_to_err_result(scope, exception, js_error_create_fn)
|
||||
.map_err(|err| attach_handle_to_error(scope, err, exception))
|
||||
}
|
||||
other => panic!("Unexpected module status {:?}", other),
|
||||
}
|
||||
}
|
||||
|
||||
/// Evaluates an already instantiated ES module.
|
||||
///
|
||||
/// ErrBox can be downcast to a type that exposes additional information about
|
||||
|
@ -311,6 +266,7 @@ impl EsIsolate {
|
|||
v8::ModuleStatus::Errored => {
|
||||
let exception = module.get_exception();
|
||||
exception_to_err_result(scope, exception, js_error_create_fn)
|
||||
.map_err(|err| attach_handle_to_error(scope, err, exception))
|
||||
}
|
||||
other => panic!("Unexpected module status {:?}", other),
|
||||
}
|
||||
|
@ -461,7 +417,7 @@ impl EsIsolate {
|
|||
// Load is done.
|
||||
let module_id = load.root_module_id.unwrap();
|
||||
self.mod_instantiate(module_id)?;
|
||||
match self.mod_evaluate_dyn_import(module_id) {
|
||||
match self.mod_evaluate(module_id) {
|
||||
Ok(()) => self.dyn_import_done(dyn_import_id, module_id)?,
|
||||
Err(err) => self.dyn_import_error(dyn_import_id, err)?,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue