diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2021-09-18 03:44:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-18 03:44:53 +0200 |
commit | f840906943849f5a09981e172d57e84301b77386 (patch) | |
tree | 8c1b5fcaf0e96a9edd1124d5b8048d28b63a2e27 /cli/main.rs | |
parent | 7c0173df27f57450508ad1400ab5599b8f7593f9 (diff) |
fix(core): prevent multiple main module loading (#12128)
This commit fixes a problem where loading and executing multiple
modules leads to all of the having "import.meta.main" set to true.
Following Rust APIs were deprecated:
- deno_core::JsRuntime::load_module
- deno_runtime::Worker::execute_module
- deno_runtime::WebWorker::execute_module
Following Rust APIs were added:
- deno_core::JsRuntime::load_main_module
- deno_core::JsRuntime::load_side_module
- deno_runtime::Worker::execute_main_module
- deno_runtime::Worker::execute_side_module
- deno_runtime::WebWorker::execute_main_module
Trying to load multiple "main" modules into the runtime now results in an
error. If user needs to load additional "non-main" modules they should use
APIs for "side" module.
Diffstat (limited to 'cli/main.rs')
-rw-r--r-- | cli/main.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/cli/main.rs b/cli/main.rs index 672668c2a..8c27e34b7 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -492,7 +492,7 @@ async fn install_command( let mut worker = create_main_worker(&program_state, main_module.clone(), permissions, None); // First, fetch and compile the module; this step ensures that the module exists. - worker.preload_module(&main_module).await?; + worker.preload_module(&main_module, true).await?; tools::installer::install( flags, &install_flags.module_url, @@ -604,7 +604,7 @@ async fn eval_command( // to allow module access by TS compiler. program_state.file_fetcher.insert_cached(file); debug!("main_module {}", &main_module); - worker.execute_module(&main_module).await?; + worker.execute_main_module(&main_module).await?; worker.execute_script( &located_script_name!(), "window.dispatchEvent(new Event('load'))", @@ -862,7 +862,7 @@ async fn run_from_stdin(flags: Flags) -> Result<(), AnyError> { program_state.file_fetcher.insert_cached(source_file); debug!("main_module {}", main_module); - worker.execute_module(&main_module).await?; + worker.execute_main_module(&main_module).await?; worker.execute_script( &located_script_name!(), "window.dispatchEvent(new Event('load'))", @@ -949,7 +949,7 @@ async fn run_with_watch(flags: Flags, script: String) -> Result<(), AnyError> { &mut self, main_module: &ModuleSpecifier, ) -> Result<(), AnyError> { - self.worker.execute_module(main_module).await?; + self.worker.execute_main_module(main_module).await?; self.worker.execute_script( &located_script_name!(), "window.dispatchEvent(new Event('load'))", @@ -1044,7 +1044,7 @@ async fn run_command( }; debug!("main_module {}", main_module); - worker.execute_module(&main_module).await?; + worker.execute_main_module(&main_module).await?; worker.execute_script( &located_script_name!(), "window.dispatchEvent(new Event('load'))", |