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

refactor: update core extension api usage (#19952)

This commit is contained in:
Nayeem Rahman 2023-07-31 19:19:15 +01:00 committed by GitHub
parent 99daad0541
commit d5efdeeff1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 142 additions and 141 deletions

12
Cargo.lock generated
View file

@ -982,9 +982,9 @@ dependencies = [
[[package]] [[package]]
name = "deno_core" name = "deno_core"
version = "0.197.0" version = "0.198.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efdf066ffb540f889e481c4f1cdbb7bc202a7af937e7c435234586395e533976" checksum = "9b34b6caa86eeea6f1449334c9ee26bec07e1db909bff5a4849727482cf06473"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@ -1350,9 +1350,9 @@ dependencies = [
[[package]] [[package]]
name = "deno_ops" name = "deno_ops"
version = "0.75.0" version = "0.76.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba2d2ca95637f48ba885bfa78cf3b962aa6752e4bb0bacda438e024a4b6b3b69" checksum = "e4ca7df186f9f20d087a03d0ab314706bf5ffec1cf18c658efae833ce5dac3e8"
dependencies = [ dependencies = [
"deno-proc-macro-rules", "deno-proc-macro-rules",
"lazy-regex", "lazy-regex",
@ -4453,9 +4453,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_v8" name = "serde_v8"
version = "0.108.0" version = "0.109.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a1a26c89d56d8607d220c639e971e3e3901138fcc5dd0f619cee0868e1cc89e" checksum = "440a8a1f1cb9abe071937aa5190b0186fa6ce15ba0de5f88e57f71583e212b2c"
dependencies = [ dependencies = [
"bytes", "bytes",
"derive_more", "derive_more",

View file

@ -41,9 +41,9 @@ repository = "https://github.com/denoland/deno"
v8 = { version = "0.74.1", default-features = false } v8 = { version = "0.74.1", default-features = false }
deno_ast = { version = "0.27.0", features = ["transpiling"] } deno_ast = { version = "0.27.0", features = ["transpiling"] }
deno_core = "0.197.0" deno_core = "0.198.0"
deno_ops = "0.75.0" deno_ops = "0.76.0"
serde_v8 = "0.108.0" serde_v8 = "0.109.0"
deno_runtime = { version = "0.121.0", path = "./runtime" } deno_runtime = { version = "0.121.0", path = "./runtime" }
napi_sym = { version = "0.43.0", path = "./cli/napi/sym" } napi_sym = { version = "0.43.0", path = "./cli/napi/sym" }

View file

@ -7,26 +7,18 @@ use deno_bench_util::bench_or_profile;
use deno_bench_util::bencher::{benchmark_group, Bencher}; use deno_bench_util::bencher::{benchmark_group, Bencher};
use deno_bench_util::bench_js_sync}; use deno_bench_util::bench_js_sync};
use deno_core::op_sync;
use deno_core::serialize_op_result;
use deno_core::Extension; use deno_core::Extension;
use deno_core::JsRuntime;
use deno_core::Op; #[op]
use deno_core::OpState; fn op_nop() -> usize {
9
}
fn setup() -> Vec<Extension> { fn setup() -> Vec<Extension> {
let custom_ext = Extension::builder() vec![Extension {
.ops(vec![ name: "my_ext"
("op_nop", |state, _| { ops: std::borrow::Cow::Borrowed(&[op_nop::DECL])
Op::Sync(serialize_op_result(Ok(9), state)) }]
}),
])
.build();
vec![
// deno_{ext}::init(...),
custom_ext,
]
} }
fn bench_op_nop(b: &mut Bencher) { fn bench_op_nop(b: &mut Bencher) {

View file

@ -10,21 +10,23 @@ use deno_core::ExtensionFileSource;
use deno_core::ExtensionFileSourceCode; use deno_core::ExtensionFileSourceCode;
fn setup() -> Vec<Extension> { fn setup() -> Vec<Extension> {
vec![Extension::builder("bench_setup") vec![Extension {
.js(vec![ExtensionFileSource { name: "bench_setup",
js_files: std::borrow::Cow::Borrowed(&[ExtensionFileSource {
specifier: "ext:bench_setup/setup.js", specifier: "ext:bench_setup/setup.js",
code: ExtensionFileSourceCode::IncludedInBinary( code: ExtensionFileSourceCode::IncludedInBinary(
r#" r#"
const hello = "hello world\n"; const hello = "hello world\n";
const hello1k = hello.repeat(1e3); const hello1k = hello.repeat(1e3);
const hello1m = hello.repeat(1e6); const hello1m = hello.repeat(1e6);
const helloEncoded = Deno.core.encode(hello); const helloEncoded = Deno.core.encode(hello);
const hello1kEncoded = Deno.core.encode(hello1k); const hello1kEncoded = Deno.core.encode(hello1k);
const hello1mEncoded = Deno.core.encode(hello1m); const hello1mEncoded = Deno.core.encode(hello1m);
"#, "#,
), ),
}]) }]),
.build()] ..Default::default()
}]
} }
fn bench_utf8_encode_12_b(b: &mut Bencher) { fn bench_utf8_encode_12_b(b: &mut Bencher) {

View file

@ -317,13 +317,13 @@ deno_core::extension!(
"40_testing.js", "40_testing.js",
"99_main.js" "99_main.js"
], ],
customizer = |ext: &mut deno_core::ExtensionBuilder| { customizer = |ext: &mut deno_core::Extension| {
ext.esm(vec![ExtensionFileSource { ext.esm_files.to_mut().push(ExtensionFileSource {
specifier: "ext:cli/runtime/js/99_main.js", specifier: "ext:cli/runtime/js/99_main.js",
code: ExtensionFileSourceCode::LoadedFromFsDuringSnapshot( code: ExtensionFileSourceCode::LoadedFromFsDuringSnapshot(
std::path::PathBuf::from(deno_runtime::js::PATH_FOR_99_MAIN_JS), deno_runtime::js::PATH_FOR_99_MAIN_JS,
), ),
}]); });
} }
); );

View file

@ -19,7 +19,6 @@ use crate::ops::*;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::OpState; use deno_core::OpState;
use std::cell::RefCell; use std::cell::RefCell;
use std::convert::From;
use std::path::Path; use std::path::Path;
use std::rc::Rc; use std::rc::Rc;

View file

@ -8,7 +8,6 @@ use std::borrow::Cow;
use std::cell::RefCell; use std::cell::RefCell;
use std::num::NonZeroU32; use std::num::NonZeroU32;
use std::rc::Rc; use std::rc::Rc;
use std::vec;
use codec::decode_key; use codec::decode_key;
use codec::encode_key; use codec::encode_key;

View file

@ -446,58 +446,55 @@ deno_core::extension!(deno_node,
"path/separator.ts", "path/separator.ts",
"readline/promises.ts", "readline/promises.ts",
"repl.ts", "repl.ts",
"wasi.ts" "wasi.ts",
], "assert.ts" with_specifier "node:assert",
esm_with_specifiers = [ "assert/strict.ts" with_specifier "node:assert/strict",
dir "polyfills", "async_hooks.ts" with_specifier "node:async_hooks",
("node:assert", "assert.ts"), "buffer.ts" with_specifier "node:buffer",
("node:assert/strict", "assert/strict.ts"), "child_process.ts" with_specifier "node:child_process",
("node:async_hooks", "async_hooks.ts"), "cluster.ts" with_specifier "node:cluster",
("node:buffer", "buffer.ts"), "console.ts" with_specifier "node:console",
("node:child_process", "child_process.ts"), "constants.ts" with_specifier "node:constants",
("node:cluster", "cluster.ts"), "crypto.ts" with_specifier "node:crypto",
("node:console", "console.ts"), "dgram.ts" with_specifier "node:dgram",
("node:constants", "constants.ts"), "diagnostics_channel.ts" with_specifier "node:diagnostics_channel",
("node:crypto", "crypto.ts"), "dns.ts" with_specifier "node:dns",
("node:dgram", "dgram.ts"), "dns/promises.ts" with_specifier "node:dns/promises",
("node:diagnostics_channel", "diagnostics_channel.ts"), "domain.ts" with_specifier "node:domain",
("node:dns", "dns.ts"), "events.ts" with_specifier "node:events",
("node:dns/promises", "dns/promises.ts"), "fs.ts" with_specifier "node:fs",
("node:domain", "domain.ts"), "fs/promises.ts" with_specifier "node:fs/promises",
("node:events", "events.ts"), "http.ts" with_specifier "node:http",
("node:fs", "fs.ts"), "http2.ts" with_specifier "node:http2",
("node:fs/promises", "fs/promises.ts"), "https.ts" with_specifier "node:https",
("node:http", "http.ts"), "01_require.js" with_specifier "node:module",
("node:http2", "http2.ts"), "net.ts" with_specifier "node:net",
("node:https", "https.ts"), "os.ts" with_specifier "node:os",
("node:module", "01_require.js"), "path.ts" with_specifier "node:path",
("node:net", "net.ts"), "path/posix.ts" with_specifier "node:path/posix",
("node:os", "os.ts"), "path/win32.ts" with_specifier "node:path/win32",
("node:path", "path.ts"), "perf_hooks.ts" with_specifier "node:perf_hooks",
("node:path/posix", "path/posix.ts"), "process.ts" with_specifier "node:process",
("node:path/win32", "path/win32.ts"), "punycode.ts" with_specifier "node:punycode",
("node:perf_hooks", "perf_hooks.ts"), "querystring.ts" with_specifier "node:querystring",
("node:process", "process.ts"), "readline.ts" with_specifier "node:readline",
("node:punycode", "punycode.ts"), "stream.ts" with_specifier "node:stream",
("node:querystring", "querystring.ts"), "stream/consumers.mjs" with_specifier "node:stream/consumers",
("node:readline", "readline.ts"), "stream/promises.mjs" with_specifier "node:stream/promises",
("node:stream", "stream.ts"), "stream/web.ts" with_specifier "node:stream/web",
("node:stream/consumers", "stream/consumers.mjs"), "string_decoder.ts" with_specifier "node:string_decoder",
("node:stream/promises", "stream/promises.mjs"), "sys.ts" with_specifier "node:sys",
("node:stream/web", "stream/web.ts"), "timers.ts" with_specifier "node:timers",
("node:string_decoder", "string_decoder.ts"), "timers/promises.ts" with_specifier "node:timers/promises",
("node:sys", "sys.ts"), "tls.ts" with_specifier "node:tls",
("node:timers", "timers.ts"), "tty.ts" with_specifier "node:tty",
("node:timers/promises", "timers/promises.ts"), "url.ts" with_specifier "node:url",
("node:tls", "tls.ts"), "util.ts" with_specifier "node:util",
("node:tty", "tty.ts"), "util/types.ts" with_specifier "node:util/types",
("node:url", "url.ts"), "v8.ts" with_specifier "node:v8",
("node:util", "util.ts"), "vm.ts" with_specifier "node:vm",
("node:util/types", "util/types.ts"), "worker_threads.ts" with_specifier "node:worker_threads",
("node:v8", "v8.ts"), "zlib.ts" with_specifier "node:zlib",
("node:vm", "vm.ts"),
("node:worker_threads", "worker_threads.ts"),
("node:zlib", "zlib.ts"),
], ],
options = { options = {
maybe_npm_resolver: Option<NpmResolverRc>, maybe_npm_resolver: Option<NpmResolverRc>,
@ -516,7 +513,7 @@ deno_core::extension!(deno_node,
}, },
global_template_middleware = global_template_middleware, global_template_middleware = global_template_middleware,
global_object_middleware = global_object_middleware, global_object_middleware = global_object_middleware,
customizer = |ext: &mut deno_core::ExtensionBuilder| { customizer = |ext: &mut deno_core::Extension| {
let mut external_references = Vec::with_capacity(7); let mut external_references = Vec::with_capacity(7);
global::GETTER_MAP_FN.with(|getter| { global::GETTER_MAP_FN.with(|getter| {
@ -554,7 +551,7 @@ deno_core::extension!(deno_node,
named_getter: *descriptor, named_getter: *descriptor,
}); });
}); });
ext.external_references(external_references); ext.external_references.to_mut().extend(external_references);
}, },
); );

View file

@ -13,17 +13,20 @@ fn setup() -> Vec<Extension> {
vec![ vec![
deno_webidl::deno_webidl::init_ops_and_esm(), deno_webidl::deno_webidl::init_ops_and_esm(),
deno_url::deno_url::init_ops_and_esm(), deno_url::deno_url::init_ops_and_esm(),
Extension::builder("bench_setup") Extension {
.esm(vec![ExtensionFileSource { name: "bench_setup",
esm_files: std::borrow::Cow::Borrowed(&[ExtensionFileSource {
specifier: "ext:bench_setup/setup", specifier: "ext:bench_setup/setup",
code: ExtensionFileSourceCode::IncludedInBinary( code: ExtensionFileSourceCode::IncludedInBinary(
r#"import { URL } from "ext:deno_url/00_url.js"; r#"
globalThis.URL = URL; import { URL } from "ext:deno_url/00_url.js";
globalThis.URL = URL;
"#, "#,
), ),
}]) }]),
.esm_entry_point("ext:bench_setup/setup") esm_entry_point: Some("ext:bench_setup/setup"),
.build(), ..Default::default()
},
] ]
} }

View file

@ -30,22 +30,24 @@ fn setup() -> Vec<Extension> {
Default::default(), Default::default(),
None, None,
), ),
Extension::builder("bench_setup") Extension {
.esm(vec![ExtensionFileSource { name: "bench_setup",
esm_files: std::borrow::Cow::Borrowed(&[ExtensionFileSource {
specifier: "ext:bench_setup/setup", specifier: "ext:bench_setup/setup",
code: ExtensionFileSourceCode::IncludedInBinary( code: ExtensionFileSourceCode::IncludedInBinary(
r#" r#"
import { TextDecoder } from "ext:deno_web/08_text_encoding.js"; import { TextDecoder } from "ext:deno_web/08_text_encoding.js";
globalThis.TextDecoder = TextDecoder; globalThis.TextDecoder = TextDecoder;
globalThis.hello12k = Deno.core.encode("hello world\n".repeat(1e3)); globalThis.hello12k = Deno.core.encode("hello world\n".repeat(1e3));
"#, "#,
), ),
}]) }]),
.state(|state| { esm_entry_point: Some("ext:bench_setup/setup"),
op_state_fn: Some(Box::new(|state| {
state.put(Permissions {}); state.put(Permissions {});
}) })),
.esm_entry_point("ext:bench_setup/setup") ..Default::default()
.build(), },
] ]
} }

View file

@ -24,23 +24,28 @@ fn setup() -> Vec<Extension> {
deno_webidl::deno_webidl::init_ops_and_esm(), deno_webidl::deno_webidl::init_ops_and_esm(),
deno_url::deno_url::init_ops_and_esm(), deno_url::deno_url::init_ops_and_esm(),
deno_console::deno_console::init_ops_and_esm(), deno_console::deno_console::init_ops_and_esm(),
deno_web::deno_web::init_ops_and_esm::<Permissions>(Default::default(), None), deno_web::deno_web::init_ops_and_esm::<Permissions>(
Extension::builder("bench_setup") Default::default(),
.esm(vec![ None,
ExtensionFileSource { ),
Extension {
name: "bench_setup",
esm_files: std::borrow::Cow::Borrowed(&[ExtensionFileSource {
specifier: "ext:bench_setup/setup", specifier: "ext:bench_setup/setup",
code: ExtensionFileSourceCode::IncludedInBinary(r#" code: ExtensionFileSourceCode::IncludedInBinary(
import { setTimeout, handleTimerMacrotask } from "ext:deno_web/02_timers.js"; r#"
globalThis.setTimeout = setTimeout; import { setTimeout, handleTimerMacrotask } from "ext:deno_web/02_timers.js";
Deno.core.setMacrotaskCallback(handleTimerMacrotask); globalThis.setTimeout = setTimeout;
"#) Deno.core.setMacrotaskCallback(handleTimerMacrotask);
}, "#,
]) ),
.state(|state| { }]),
state.put(Permissions{}); esm_entry_point: Some("ext:bench_setup/setup"),
}) op_state_fn: Some(Box::new(|state| {
.esm_entry_point("ext:bench_setup/setup") state.put(Permissions {});
.build() })),
..Default::default()
},
] ]
} }

View file

@ -12,15 +12,17 @@ use deno_core::ExtensionFileSourceCode;
fn setup() -> Vec<Extension> { fn setup() -> Vec<Extension> {
vec![ vec![
deno_webidl::deno_webidl::init_ops_and_esm(), deno_webidl::deno_webidl::init_ops_and_esm(),
Extension::builder("deno_webidl_bench") Extension {
.esm(vec![ExtensionFileSource { name: "deno_webidl_bench",
esm_files: std::borrow::Cow::Borrowed(&[ExtensionFileSource {
specifier: "ext:deno_webidl_bench/setup.js", specifier: "ext:deno_webidl_bench/setup.js",
code: ExtensionFileSourceCode::IncludedInBinary(include_str!( code: ExtensionFileSourceCode::IncludedInBinary(include_str!(
"dict.js" "dict.js"
)), )),
}]) }]),
.esm_entry_point("ext:deno_webidl_bench/setup.js") esm_entry_point: Some("ext:deno_webidl_bench/setup.js"),
.build(), ..Default::default()
},
] ]
} }

View file

@ -275,14 +275,14 @@ mod startup_snapshot {
deno_core::extension!( deno_core::extension!(
runtime_main, runtime_main,
deps = [runtime], deps = [runtime],
customizer = |ext: &mut deno_core::ExtensionBuilder| { esm_entry_point = "ext:runtime_main/js/99_main.js",
ext.esm(vec![ExtensionFileSource { customizer = |ext: &mut deno_core::Extension| {
ext.esm_files.to_mut().push(ExtensionFileSource {
specifier: "ext:runtime_main/js/99_main.js", specifier: "ext:runtime_main/js/99_main.js",
code: deno_core::ExtensionFileSourceCode::IncludedInBinary( code: deno_core::ExtensionFileSourceCode::IncludedInBinary(
include_str!("js/99_main.js"), include_str!("js/99_main.js"),
), ),
}]); });
ext.esm_entry_point("ext:runtime_main/js/99_main.js");
} }
); );
@ -290,9 +290,7 @@ mod startup_snapshot {
deno_core::extension!( deno_core::extension!(
runtime_main, runtime_main,
deps = [runtime], deps = [runtime],
customizer = |ext: &mut deno_core::ExtensionBuilder| { esm_entry_point = "ext:runtime/90_deno_ns.js",
ext.esm_entry_point("ext:runtime/90_deno_ns.js");
}
); );
pub fn create_runtime_snapshot(snapshot_path: PathBuf) { pub fn create_runtime_snapshot(snapshot_path: PathBuf) {

View file

@ -51,6 +51,7 @@ fn get_fd_from_resource(
) -> Result<std::os::windows::io::RawHandle, AnyError> { ) -> Result<std::os::windows::io::RawHandle, AnyError> {
use winapi::um::handleapi; use winapi::um::handleapi;
#[allow(deprecated)]
let Some(handle) = resource.backing_fd() else { let Some(handle) = resource.backing_fd() else {
return Err(resource_unavailable()); return Err(resource_unavailable());
}; };
@ -66,6 +67,7 @@ fn get_fd_from_resource(
fn get_fd_from_resource( fn get_fd_from_resource(
resource: Rc<FileResource>, resource: Rc<FileResource>,
) -> Result<std::os::unix::prelude::RawFd, AnyError> { ) -> Result<std::os::unix::prelude::RawFd, AnyError> {
#[allow(deprecated)]
match resource.backing_fd() { match resource.backing_fd() {
Some(fd) => Ok(fd), Some(fd) => Ok(fd),
None => Err(resource_unavailable()), None => Err(resource_unavailable()),