mirror of
https://github.com/denoland/deno.git
synced 2025-09-28 13:14:48 +00:00
refactor: Move URL to op_crates/web (#7544)
This commit is contained in:
parent
a6f4559174
commit
6453cb7567
11 changed files with 75 additions and 83 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -414,7 +414,6 @@ dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"fwdansi",
|
"fwdansi",
|
||||||
"http",
|
"http",
|
||||||
"idna",
|
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"jsonc-parser",
|
"jsonc-parser",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
@ -506,6 +505,8 @@ version = "0.8.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"deno_core",
|
"deno_core",
|
||||||
"futures",
|
"futures",
|
||||||
|
"idna",
|
||||||
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -31,6 +31,7 @@ winapi = "0.3.9"
|
||||||
deno_core = { path = "../core", version = "0.57.0" }
|
deno_core = { path = "../core", version = "0.57.0" }
|
||||||
deno_doc = "0.1.9"
|
deno_doc = "0.1.9"
|
||||||
deno_lint = { version = "0.2.0", features = ["json"] }
|
deno_lint = { version = "0.2.0", features = ["json"] }
|
||||||
|
deno_web = { path = "../op_crates/web", version = "0.8.0" }
|
||||||
|
|
||||||
atty = "0.2.14"
|
atty = "0.2.14"
|
||||||
base64 = "0.12.3"
|
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
|
futures = "0.3.5" # TODO(ry) Remove and use deno_core::futures
|
||||||
filetime = "0.2.12"
|
filetime = "0.2.12"
|
||||||
http = "0.2.1"
|
http = "0.2.1"
|
||||||
idna = "0.2.0"
|
|
||||||
indexmap = "1.6.0"
|
indexmap = "1.6.0"
|
||||||
jsonc-parser = "0.14.0"
|
jsonc-parser = "0.14.0"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
|
|
|
@ -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))
|
|
||||||
}
|
|
|
@ -8,7 +8,6 @@ pub mod errors;
|
||||||
pub mod fetch;
|
pub mod fetch;
|
||||||
pub mod fs;
|
pub mod fs;
|
||||||
pub mod fs_events;
|
pub mod fs_events;
|
||||||
pub mod idna;
|
|
||||||
pub mod io;
|
pub mod io;
|
||||||
pub mod net;
|
pub mod net;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
|
|
@ -41,19 +41,6 @@
|
||||||
return Object.prototype.hasOwnProperty.call(obj, v);
|
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();
|
const objectCloneMemo = new WeakMap();
|
||||||
|
|
||||||
function cloneArrayBuffer(
|
function cloneArrayBuffer(
|
||||||
|
@ -192,7 +179,6 @@
|
||||||
requiredArguments,
|
requiredArguments,
|
||||||
immutableDefine,
|
immutableDefine,
|
||||||
hasOwnProperty,
|
hasOwnProperty,
|
||||||
isIterable,
|
|
||||||
cloneValue,
|
cloneValue,
|
||||||
defineEnumerableProps,
|
defineEnumerableProps,
|
||||||
getHeaderValueParams,
|
getHeaderValueParams,
|
||||||
|
|
|
@ -4,9 +4,6 @@
|
||||||
((window) => {
|
((window) => {
|
||||||
const core = window.Deno.core;
|
const core = window.Deno.core;
|
||||||
const { log } = window.__bootstrap.util;
|
const { log } = window.__bootstrap.util;
|
||||||
/*
|
|
||||||
import { blobURLMap } from "./web/url.ts";
|
|
||||||
*/
|
|
||||||
|
|
||||||
function createWorker(
|
function createWorker(
|
||||||
specifier,
|
specifier,
|
||||||
|
@ -68,22 +65,6 @@
|
||||||
const hasSourceCode = false;
|
const hasSourceCode = false;
|
||||||
const sourceCode = decoder.decode(new Uint8Array());
|
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 useDenoNamespace = options ? !!options.deno : false;
|
||||||
|
|
||||||
const { id } = createWorker(
|
const { id } = createWorker(
|
||||||
|
|
|
@ -115,7 +115,11 @@ impl WebWorker {
|
||||||
let handle = web_worker.thread_safe_handle();
|
let handle = web_worker.thread_safe_handle();
|
||||||
ops::web_worker::init(&mut web_worker.worker, sender, handle);
|
ops::web_worker::init(&mut web_worker.worker, sender, handle);
|
||||||
ops::worker_host::init(&mut web_worker.worker);
|
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::io::init(&mut web_worker.worker);
|
||||||
ops::reg_json_sync(
|
ops::reg_json_sync(
|
||||||
&mut web_worker.worker,
|
&mut web_worker.worker,
|
||||||
|
|
|
@ -277,7 +277,11 @@ impl MainWorker {
|
||||||
ops::websocket::init(&mut worker);
|
ops::websocket::init(&mut worker);
|
||||||
ops::fs::init(&mut worker);
|
ops::fs::init(&mut worker);
|
||||||
ops::fs_events::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::io::init(&mut worker);
|
||||||
ops::plugin::init(&mut worker);
|
ops::plugin::init(&mut worker);
|
||||||
ops::net::init(&mut worker);
|
ops::net::init(&mut worker);
|
||||||
|
|
|
@ -2,7 +2,31 @@
|
||||||
|
|
||||||
((window) => {
|
((window) => {
|
||||||
const core = window.Deno.core;
|
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 */
|
/** https://url.spec.whatwg.org/#idna */
|
||||||
function domainToAscii(
|
function domainToAscii(
|
||||||
|
@ -383,9 +407,6 @@
|
||||||
return parts;
|
return parts;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep it outside of URL to avoid any attempts of access.
|
|
||||||
const blobURLMap = new Map();
|
|
||||||
|
|
||||||
// Resolves `.`s and `..`s where possible.
|
// Resolves `.`s and `..`s where possible.
|
||||||
// Preserves repeating and trailing `/`s by design.
|
// Preserves repeating and trailing `/`s by design.
|
||||||
// Assumes drive letter file paths will have a leading slash.
|
// Assumes drive letter file paths will have a leading slash.
|
||||||
|
@ -872,6 +893,5 @@
|
||||||
window.__bootstrap.url = {
|
window.__bootstrap.url = {
|
||||||
URL,
|
URL,
|
||||||
URLSearchParams,
|
URLSearchParams,
|
||||||
blobURLMap,
|
|
||||||
};
|
};
|
||||||
})(this);
|
})(this);
|
|
@ -15,6 +15,8 @@ path = "lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
deno_core = { version = "0.57.0", path = "../../core" }
|
deno_core = { version = "0.57.0", path = "../../core" }
|
||||||
|
idna = "0.2.0"
|
||||||
|
serde = { version = "1.0.116", features = ["derive"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
futures = "0.3.5"
|
futures = "0.3.5"
|
||||||
|
|
|
@ -1,9 +1,43 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// 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::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::JsRuntime;
|
||||||
|
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::{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) {
|
pub fn init(isolate: &mut JsRuntime) {
|
||||||
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
|
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||||
let files = vec![
|
let files = vec![
|
||||||
|
@ -11,6 +45,7 @@ pub fn init(isolate: &mut JsRuntime) {
|
||||||
manifest_dir.join("01_event.js"),
|
manifest_dir.join("01_event.js"),
|
||||||
manifest_dir.join("02_abort_signal.js"),
|
manifest_dir.join("02_abort_signal.js"),
|
||||||
manifest_dir.join("08_text_encoding.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
|
// TODO(nayeemrmn): https://github.com/rust-lang/cargo/issues/3946 to get the
|
||||||
// workspace root.
|
// workspace root.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue