Skip to content

Commit

Permalink
Merge mod_evaluate() and mod_evaluate_dyn_import() methods (denoland#…
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Feb 28, 2020
1 parent 397deb4 commit 1cb1ab6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 47 deletions.
2 changes: 1 addition & 1 deletion cli/js/workers_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

Expand Down
48 changes: 2 additions & 46 deletions core/es_isolate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
}
Expand Down Expand Up @@ -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)?,
};
Expand Down

0 comments on commit 1cb1ab6

Please sign in to comment.