0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 17:34:47 -05:00

refactor: improve op crate interfaces for other consumers (#7745)

This commit is contained in:
Bartek Iwańczuk 2020-09-30 16:51:01 +02:00 committed by GitHub
parent dcd0595058
commit 290da280a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 71 additions and 51 deletions

4
Cargo.lock generated
View file

@ -483,7 +483,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_fetch" name = "deno_fetch"
version = "0.2.0" version = "0.3.0"
dependencies = [ dependencies = [
"deno_core", "deno_core",
"reqwest", "reqwest",
@ -508,7 +508,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_web" name = "deno_web"
version = "0.10.0" version = "0.11.0"
dependencies = [ dependencies = [
"deno_core", "deno_core",
"futures", "futures",

View file

@ -21,8 +21,8 @@ path = "./bench/main.rs"
[build-dependencies] [build-dependencies]
deno_core = { path = "../core", version = "0.59.0" } deno_core = { path = "../core", version = "0.59.0" }
deno_web = { path = "../op_crates/web", version = "0.10.0" } deno_web = { path = "../op_crates/web", version = "0.11.0" }
deno_fetch = { path = "../op_crates/fetch", version = "0.2.0" } deno_fetch = { path = "../op_crates/fetch", version = "0.3.0" }
[target.'cfg(windows)'.build-dependencies] [target.'cfg(windows)'.build-dependencies]
winres = "0.1.11" winres = "0.1.11"
@ -32,8 +32,8 @@ winapi = "0.3.9"
deno_core = { path = "../core", version = "0.59.0" } deno_core = { path = "../core", version = "0.59.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.10.0" } deno_web = { path = "../op_crates/web", version = "0.11.0" }
deno_fetch = { path = "../op_crates/fetch", version = "0.2.0" } deno_fetch = { path = "../op_crates/fetch", version = "0.3.0" }
atty = "0.2.14" atty = "0.2.14"
base64 = "0.12.3" base64 = "0.12.3"

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_fetch" name = "deno_fetch"
version = "0.2.0" version = "0.3.0"
edition = "2018" edition = "2018"
description = "provides fetch Web API to deno_core" description = "provides fetch Web API to deno_core"
authors = ["the Deno authors"] authors = ["the Deno authors"]

View file

@ -27,40 +27,56 @@ use std::cell::RefCell;
use std::convert::From; use std::convert::From;
use std::fs::File; use std::fs::File;
use std::io::Read; use std::io::Read;
use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
use std::rc::Rc; use std::rc::Rc;
pub use reqwest; // Re-export reqwest pub use reqwest; // Re-export reqwest
/// Execute this crates' JS source files.
pub fn init(isolate: &mut JsRuntime) { pub fn init(isolate: &mut JsRuntime) {
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
let files = vec![ let files = vec![
manifest_dir.join("01_fetch_util.js"), (
manifest_dir.join("03_dom_iterable.js"), "deno:op_crates/fetch/01_fetch_util.js",
manifest_dir.join("11_streams.js"), include_str!("01_fetch_util.js"),
manifest_dir.join("20_headers.js"), ),
manifest_dir.join("26_fetch.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 for (url, source_code) in files {
// workspace root. isolate.execute(url, source_code).unwrap();
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();
} }
} }
pub trait FetchPermissions { pub trait FetchPermissions {
fn check_net_url(&self, url: &Url) -> Result<(), AnyError>; fn check_net_url(&self, _url: &Url) -> Result<(), AnyError>;
fn check_read(&self, p: &PathBuf) -> 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 { pub fn get_declaration() -> PathBuf {

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_web" name = "deno_web"
version = "0.10.0" version = "0.11.0"
edition = "2018" edition = "2018"
description = "Collection of Web APIs" description = "Collection of Web APIs"
authors = ["the Deno authors"] authors = ["the Deno authors"]

View file

@ -10,7 +10,7 @@ use deno_core::ZeroCopyBuf;
use idna::domain_to_ascii; use idna::domain_to_ascii;
use idna::domain_to_ascii_strict; use idna::domain_to_ascii_strict;
use serde::Deserialize; use serde::Deserialize;
use std::path::{Path, PathBuf}; use std::path::PathBuf;
pub fn op_domain_to_ascii( pub fn op_domain_to_ascii(
_state: &mut deno_core::OpState, _state: &mut deno_core::OpState,
@ -37,29 +37,33 @@ pub fn op_domain_to_ascii(
.map(|domain| json!(domain)) .map(|domain| json!(domain))
} }
/// Load and execute the javascript code.
pub fn init(isolate: &mut JsRuntime) { pub fn init(isolate: &mut JsRuntime) {
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
let files = vec![ let files = vec![
manifest_dir.join("00_dom_exception.js"), (
manifest_dir.join("01_event.js"), "deno:op_crates/web/00_dom_exception.js",
manifest_dir.join("02_abort_signal.js"), include_str!("00_dom_exception.js"),
manifest_dir.join("08_text_encoding.js"), ),
manifest_dir.join("11_url.js"), (
manifest_dir.join("21_filereader.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 for (url, source_code) in files {
// workspace root. isolate.execute(url, source_code).unwrap();
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();
} }
} }