diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-09-30 16:51:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-30 10:51:01 -0400 |
commit | 290da280a8a8ab8f886462cd61484f5a6a4d57a4 (patch) | |
tree | 473d3f8f3cef55b6167ef983de33a8f0d97f01ba /op_crates/web/lib.rs | |
parent | dcd0595058c9a736529c11e64cf13911774be2b5 (diff) |
refactor: improve op crate interfaces for other consumers (#7745)
Diffstat (limited to 'op_crates/web/lib.rs')
-rw-r--r-- | op_crates/web/lib.rs | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/op_crates/web/lib.rs b/op_crates/web/lib.rs index 1078a7917..26e36365b 100644 --- a/op_crates/web/lib.rs +++ b/op_crates/web/lib.rs @@ -10,7 +10,7 @@ use deno_core::ZeroCopyBuf; use idna::domain_to_ascii; use idna::domain_to_ascii_strict; use serde::Deserialize; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; pub fn op_domain_to_ascii( _state: &mut deno_core::OpState, @@ -37,29 +37,33 @@ pub fn op_domain_to_ascii( .map(|domain| json!(domain)) } +/// Load and execute the javascript code. pub fn init(isolate: &mut JsRuntime) { - let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR")); let files = vec![ - manifest_dir.join("00_dom_exception.js"), - manifest_dir.join("01_event.js"), - manifest_dir.join("02_abort_signal.js"), - manifest_dir.join("08_text_encoding.js"), - manifest_dir.join("11_url.js"), - manifest_dir.join("21_filereader.js"), + ( + "deno:op_crates/web/00_dom_exception.js", + include_str!("00_dom_exception.js"), + ), + ( + "deno:op_crates/web/01_event.js", + include_str!("01_event.js"), + ), + ( + "deno:op_crates/web/02_abort_signal.js", + include_str!("02_abort_signal.js"), + ), + ( + "deno:op_crates/web/08_text_encoding.js", + include_str!("08_text_encoding.js"), + ), + ("deno:op_crates/web/11_url.js", include_str!("11_url.js")), + ( + "deno:op_crates/web/21_filereader.js", + include_str!("21_filereader.js"), + ), ]; - // TODO(nayeemrmn): https://github.com/rust-lang/cargo/issues/3946 to get the - // workspace root. - let display_root = manifest_dir.parent().unwrap().parent().unwrap(); - for file in files { - println!("cargo:rerun-if-changed={}", file.display()); - let display_path = file.strip_prefix(display_root).unwrap(); - let display_path_str = display_path.display().to_string(); - isolate - .execute( - &("deno:".to_string() + &display_path_str.replace('\\', "/")), - &std::fs::read_to_string(&file).unwrap(), - ) - .unwrap(); + for (url, source_code) in files { + isolate.execute(url, source_code).unwrap(); } } |