mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
refactor: improve op crate interfaces for other consumers (#7745)
This commit is contained in:
parent
dcd0595058
commit
290da280a8
6 changed files with 71 additions and 51 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -483,7 +483,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "deno_fetch"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"deno_core",
|
||||
"reqwest",
|
||||
|
@ -508,7 +508,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "deno_web"
|
||||
version = "0.10.0"
|
||||
version = "0.11.0"
|
||||
dependencies = [
|
||||
"deno_core",
|
||||
"futures",
|
||||
|
|
|
@ -21,8 +21,8 @@ path = "./bench/main.rs"
|
|||
|
||||
[build-dependencies]
|
||||
deno_core = { path = "../core", version = "0.59.0" }
|
||||
deno_web = { path = "../op_crates/web", version = "0.10.0" }
|
||||
deno_fetch = { path = "../op_crates/fetch", version = "0.2.0" }
|
||||
deno_web = { path = "../op_crates/web", version = "0.11.0" }
|
||||
deno_fetch = { path = "../op_crates/fetch", version = "0.3.0" }
|
||||
|
||||
[target.'cfg(windows)'.build-dependencies]
|
||||
winres = "0.1.11"
|
||||
|
@ -32,8 +32,8 @@ winapi = "0.3.9"
|
|||
deno_core = { path = "../core", version = "0.59.0" }
|
||||
deno_doc = "0.1.9"
|
||||
deno_lint = { version = "0.2.0", features = ["json"] }
|
||||
deno_web = { path = "../op_crates/web", version = "0.10.0" }
|
||||
deno_fetch = { path = "../op_crates/fetch", version = "0.2.0" }
|
||||
deno_web = { path = "../op_crates/web", version = "0.11.0" }
|
||||
deno_fetch = { path = "../op_crates/fetch", version = "0.3.0" }
|
||||
|
||||
atty = "0.2.14"
|
||||
base64 = "0.12.3"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
[package]
|
||||
name = "deno_fetch"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
edition = "2018"
|
||||
description = "provides fetch Web API to deno_core"
|
||||
authors = ["the Deno authors"]
|
||||
|
|
|
@ -27,40 +27,56 @@ use std::cell::RefCell;
|
|||
use std::convert::From;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub use reqwest; // Re-export reqwest
|
||||
|
||||
/// Execute this crates' JS source files.
|
||||
pub fn init(isolate: &mut JsRuntime) {
|
||||
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||
let files = vec![
|
||||
manifest_dir.join("01_fetch_util.js"),
|
||||
manifest_dir.join("03_dom_iterable.js"),
|
||||
manifest_dir.join("11_streams.js"),
|
||||
manifest_dir.join("20_headers.js"),
|
||||
manifest_dir.join("26_fetch.js"),
|
||||
(
|
||||
"deno:op_crates/fetch/01_fetch_util.js",
|
||||
include_str!("01_fetch_util.js"),
|
||||
),
|
||||
(
|
||||
"deno:op_crates/fetch/03_dom_iterable.js",
|
||||
include_str!("03_dom_iterable.js"),
|
||||
),
|
||||
(
|
||||
"deno:op_crates/fetch/11_streams.js",
|
||||
include_str!("11_streams.js"),
|
||||
),
|
||||
(
|
||||
"deno:op_crates/fetch/20_headers.js",
|
||||
include_str!("20_headers.js"),
|
||||
),
|
||||
(
|
||||
"deno:op_crates/fetch/26_fetch.js",
|
||||
include_str!("26_fetch.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();
|
||||
}
|
||||
}
|
||||
|
||||
pub trait FetchPermissions {
|
||||
fn check_net_url(&self, url: &Url) -> Result<(), AnyError>;
|
||||
fn check_read(&self, p: &PathBuf) -> Result<(), AnyError>;
|
||||
fn check_net_url(&self, _url: &Url) -> Result<(), AnyError>;
|
||||
fn check_read(&self, _p: &PathBuf) -> Result<(), AnyError>;
|
||||
}
|
||||
|
||||
/// For use with `op_fetch` when the user does not want permissions.
|
||||
pub struct NoFetchPermissions;
|
||||
|
||||
impl FetchPermissions for NoFetchPermissions {
|
||||
fn check_net_url(&self, _url: &Url) -> Result<(), AnyError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn check_read(&self, _p: &PathBuf) -> Result<(), AnyError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_declaration() -> PathBuf {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
[package]
|
||||
name = "deno_web"
|
||||
version = "0.10.0"
|
||||
version = "0.11.0"
|
||||
edition = "2018"
|
||||
description = "Collection of Web APIs"
|
||||
authors = ["the Deno authors"]
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue