diff options
-rw-r--r-- | Cargo.lock | 3 | ||||
-rw-r--r-- | cli/Cargo.toml | 2 | ||||
-rw-r--r-- | cli/ops/idna.rs | 40 | ||||
-rw-r--r-- | cli/ops/mod.rs | 1 | ||||
-rw-r--r-- | cli/rt/01_web_util.js | 14 | ||||
-rw-r--r-- | cli/rt/11_workers.js | 19 | ||||
-rw-r--r-- | cli/web_worker.rs | 6 | ||||
-rw-r--r-- | cli/worker.rs | 6 | ||||
-rw-r--r-- | op_crates/web/11_url.js (renamed from cli/rt/11_url.js) | 30 | ||||
-rw-r--r-- | op_crates/web/Cargo.toml | 2 | ||||
-rw-r--r-- | op_crates/web/lib.rs | 35 |
11 files changed, 75 insertions, 83 deletions
diff --git a/Cargo.lock b/Cargo.lock index 4bfdc3e2f..5ffc17e79 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -414,7 +414,6 @@ dependencies = [ "futures", "fwdansi", "http", - "idna", "indexmap", "jsonc-parser", "lazy_static", @@ -506,6 +505,8 @@ version = "0.8.0" dependencies = [ "deno_core", "futures", + "idna", + "serde", ] [[package]] diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 26f452ad4..1c19dabdb 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -31,6 +31,7 @@ winapi = "0.3.9" deno_core = { path = "../core", version = "0.57.0" } deno_doc = "0.1.9" deno_lint = { version = "0.2.0", features = ["json"] } +deno_web = { path = "../op_crates/web", version = "0.8.0" } atty = "0.2.14" base64 = "0.12.3" @@ -44,7 +45,6 @@ dprint-plugin-typescript = "0.31.3" futures = "0.3.5" # TODO(ry) Remove and use deno_core::futures filetime = "0.2.12" http = "0.2.1" -idna = "0.2.0" indexmap = "1.6.0" jsonc-parser = "0.14.0" lazy_static = "1.4.0" diff --git a/cli/ops/idna.rs b/cli/ops/idna.rs deleted file mode 100644 index c81d9c314..000000000 --- a/cli/ops/idna.rs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. - -//! https://url.spec.whatwg.org/#idna - -use deno_core::error::uri_error; -use deno_core::error::AnyError; -use deno_core::ZeroCopyBuf; -use idna::domain_to_ascii; -use idna::domain_to_ascii_strict; -use serde::Deserialize; -use serde_json::Value; - -pub fn init(rt: &mut deno_core::JsRuntime) { - super::reg_json_sync(rt, "op_domain_to_ascii", op_domain_to_ascii); -} - -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -struct DomainToAscii { - domain: String, - be_strict: bool, -} - -fn op_domain_to_ascii( - _state: &mut deno_core::OpState, - args: Value, - _zero_copy: &mut [ZeroCopyBuf], -) -> Result<Value, AnyError> { - let args: DomainToAscii = serde_json::from_value(args)?; - if args.be_strict { - domain_to_ascii_strict(args.domain.as_str()) - } else { - domain_to_ascii(args.domain.as_str()) - } - .map_err(|err| { - let message = format!("Invalid IDNA encoded domain name: {:?}", err); - uri_error(message) - }) - .map(|domain| json!(domain)) -} diff --git a/cli/ops/mod.rs b/cli/ops/mod.rs index 288e3d0c0..2c8e3472f 100644 --- a/cli/ops/mod.rs +++ b/cli/ops/mod.rs @@ -8,7 +8,6 @@ pub mod errors; pub mod fetch; pub mod fs; pub mod fs_events; -pub mod idna; pub mod io; pub mod net; #[cfg(unix)] diff --git a/cli/rt/01_web_util.js b/cli/rt/01_web_util.js index 596dcbfcd..d64ef28c3 100644 --- a/cli/rt/01_web_util.js +++ b/cli/rt/01_web_util.js @@ -41,19 +41,6 @@ return Object.prototype.hasOwnProperty.call(obj, v); } - /** Returns whether o is iterable. */ - function isIterable( - o, - ) { - // checks for null and undefined - if (o == null) { - return false; - } - return ( - typeof (o)[Symbol.iterator] === "function" - ); - } - const objectCloneMemo = new WeakMap(); function cloneArrayBuffer( @@ -192,7 +179,6 @@ requiredArguments, immutableDefine, hasOwnProperty, - isIterable, cloneValue, defineEnumerableProps, getHeaderValueParams, diff --git a/cli/rt/11_workers.js b/cli/rt/11_workers.js index 77ac273f4..0a726a714 100644 --- a/cli/rt/11_workers.js +++ b/cli/rt/11_workers.js @@ -4,9 +4,6 @@ ((window) => { const core = window.Deno.core; const { log } = window.__bootstrap.util; - /* - import { blobURLMap } from "./web/url.ts"; - */ function createWorker( specifier, @@ -68,22 +65,6 @@ const hasSourceCode = false; const sourceCode = decoder.decode(new Uint8Array()); - /* TODO(bartlomieju): - // Handle blob URL. - if (specifier.startsWith("blob:")) { - hasSourceCode = true; - const b = blobURLMap.get(specifier); - if (!b) { - throw new Error("No Blob associated with the given URL is found"); - } - const blobBytes = blobBytesWeakMap.get(b!); - if (!blobBytes) { - throw new Error("Invalid Blob"); - } - sourceCode = blobBytes!; - } - */ - const useDenoNamespace = options ? !!options.deno : false; const { id } = createWorker( diff --git a/cli/web_worker.rs b/cli/web_worker.rs index bad017914..a4d0fe24c 100644 --- a/cli/web_worker.rs +++ b/cli/web_worker.rs @@ -115,7 +115,11 @@ impl WebWorker { let handle = web_worker.thread_safe_handle(); ops::web_worker::init(&mut web_worker.worker, sender, handle); ops::worker_host::init(&mut web_worker.worker); - ops::idna::init(&mut web_worker.worker); + ops::reg_json_sync( + &mut web_worker.worker, + "op_domain_to_ascii", + deno_web::op_domain_to_ascii, + ); ops::io::init(&mut web_worker.worker); ops::reg_json_sync( &mut web_worker.worker, diff --git a/cli/worker.rs b/cli/worker.rs index 6c22ba92b..33e9f1443 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -277,7 +277,11 @@ impl MainWorker { ops::websocket::init(&mut worker); ops::fs::init(&mut worker); ops::fs_events::init(&mut worker); - ops::idna::init(&mut worker); + ops::reg_json_sync( + &mut worker, + "op_domain_to_ascii", + deno_web::op_domain_to_ascii, + ); ops::io::init(&mut worker); ops::plugin::init(&mut worker); ops::net::init(&mut worker); diff --git a/cli/rt/11_url.js b/op_crates/web/11_url.js index 99f4ba0e1..fb5bece25 100644 --- a/cli/rt/11_url.js +++ b/op_crates/web/11_url.js @@ -2,7 +2,31 @@ ((window) => { const core = window.Deno.core; - const { isIterable, requiredArguments } = window.__bootstrap.webUtil; + + function requiredArguments( + name, + length, + required, + ) { + if (length < required) { + const errMsg = `${name} requires at least ${required} argument${ + required === 1 ? "" : "s" + }, but only ${length} present`; + throw new TypeError(errMsg); + } + } + + function isIterable( + o, + ) { + // checks for null and undefined + if (o == null) { + return false; + } + return ( + typeof (o)[Symbol.iterator] === "function" + ); + } /** https://url.spec.whatwg.org/#idna */ function domainToAscii( @@ -383,9 +407,6 @@ return parts; } - // Keep it outside of URL to avoid any attempts of access. - const blobURLMap = new Map(); - // Resolves `.`s and `..`s where possible. // Preserves repeating and trailing `/`s by design. // Assumes drive letter file paths will have a leading slash. @@ -872,6 +893,5 @@ window.__bootstrap.url = { URL, URLSearchParams, - blobURLMap, }; })(this); diff --git a/op_crates/web/Cargo.toml b/op_crates/web/Cargo.toml index a7a758150..b5db36db1 100644 --- a/op_crates/web/Cargo.toml +++ b/op_crates/web/Cargo.toml @@ -15,6 +15,8 @@ path = "lib.rs" [dependencies] deno_core = { version = "0.57.0", path = "../../core" } +idna = "0.2.0" +serde = { version = "1.0.116", features = ["derive"] } [dev-dependencies] futures = "0.3.5" diff --git a/op_crates/web/lib.rs b/op_crates/web/lib.rs index 96f269a1d..f6c7137f7 100644 --- a/op_crates/web/lib.rs +++ b/op_crates/web/lib.rs @@ -1,9 +1,43 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. +use deno_core::error::uri_error; +use deno_core::error::AnyError; use deno_core::js_check; +use deno_core::serde_json; +use deno_core::serde_json::json; +use deno_core::serde_json::Value; use deno_core::JsRuntime; +use deno_core::ZeroCopyBuf; +use idna::domain_to_ascii; +use idna::domain_to_ascii_strict; +use serde::Deserialize; use std::path::{Path, PathBuf}; +pub fn op_domain_to_ascii( + _state: &mut deno_core::OpState, + args: Value, + _zero_copy: &mut [ZeroCopyBuf], +) -> Result<Value, AnyError> { + #[derive(Deserialize)] + #[serde(rename_all = "camelCase")] + struct DomainToAscii { + domain: String, + be_strict: bool, + } + + let args: DomainToAscii = serde_json::from_value(args)?; + if args.be_strict { + domain_to_ascii_strict(args.domain.as_str()) + } else { + domain_to_ascii(args.domain.as_str()) + } + .map_err(|err| { + let message = format!("Invalid IDNA encoded domain name: {:?}", err); + uri_error(message) + }) + .map(|domain| json!(domain)) +} + pub fn init(isolate: &mut JsRuntime) { let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR")); let files = vec![ @@ -11,6 +45,7 @@ pub fn init(isolate: &mut JsRuntime) { 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"), ]; // TODO(nayeemrmn): https://github.com/rust-lang/cargo/issues/3946 to get the // workspace root. |