diff options
author | Bert Belder <bertbelder@gmail.com> | 2020-02-27 16:29:02 -0800 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2020-02-27 16:30:18 -0800 |
commit | 1cb1ab6c004ec0b20edaf65c6fdd3bc0b7ce465e (patch) | |
tree | 84660e1eeb8735f1219e1074e1c260e7e6990750 | |
parent | 397deb4e29775b7395a7ed4ccd253b89ee211b66 (diff) |
Merge mod_evaluate() and mod_evaluate_dyn_import() methods (#4167)
-rw-r--r-- | cli/js/workers_test.ts | 2 | ||||
-rw-r--r-- | core/es_isolate.rs | 48 |
2 files changed, 3 insertions, 47 deletions
diff --git a/cli/js/workers_test.ts b/cli/js/workers_test.ts index eccf83f65..7dbd316ec 100644 --- a/cli/js/workers_test.ts +++ b/cli/js/workers_test.ts @@ -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(); }; diff --git a/core/es_isolate.rs b/core/es_isolate.rs index ea3e7b4b9..1147741d9 100644 --- a/core/es_isolate.rs +++ b/core/es_isolate.rs @@ -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)?, }; |