From d5efdeeff149202b24011918984a15389dae98a2 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Mon, 31 Jul 2023 19:19:15 +0100 Subject: [PATCH] refactor: update core extension api usage (#19952) --- Cargo.lock | 12 ++-- Cargo.toml | 6 +- bench_util/README.md | 26 +++------ bench_util/benches/utf8.rs | 22 +++---- cli/build.rs | 8 +-- ext/fs/lib.rs | 1 - ext/kv/lib.rs | 1 - ext/node/lib.rs | 105 +++++++++++++++++----------------- ext/url/benches/url_ops.rs | 17 +++--- ext/web/benches/encoding.rs | 22 +++---- ext/web/benches/timers_ops.rs | 37 ++++++------ ext/webidl/benches/dict.rs | 12 ++-- runtime/build.rs | 12 ++-- runtime/ops/tty.rs | 2 + 14 files changed, 142 insertions(+), 141 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 349354d25c..7ba53ae628 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -982,9 +982,9 @@ dependencies = [ [[package]] name = "deno_core" -version = "0.197.0" +version = "0.198.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efdf066ffb540f889e481c4f1cdbb7bc202a7af937e7c435234586395e533976" +checksum = "9b34b6caa86eeea6f1449334c9ee26bec07e1db909bff5a4849727482cf06473" dependencies = [ "anyhow", "bytes", @@ -1350,9 +1350,9 @@ dependencies = [ [[package]] name = "deno_ops" -version = "0.75.0" +version = "0.76.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba2d2ca95637f48ba885bfa78cf3b962aa6752e4bb0bacda438e024a4b6b3b69" +checksum = "e4ca7df186f9f20d087a03d0ab314706bf5ffec1cf18c658efae833ce5dac3e8" dependencies = [ "deno-proc-macro-rules", "lazy-regex", @@ -4453,9 +4453,9 @@ dependencies = [ [[package]] name = "serde_v8" -version = "0.108.0" +version = "0.109.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a1a26c89d56d8607d220c639e971e3e3901138fcc5dd0f619cee0868e1cc89e" +checksum = "440a8a1f1cb9abe071937aa5190b0186fa6ce15ba0de5f88e57f71583e212b2c" dependencies = [ "bytes", "derive_more", diff --git a/Cargo.toml b/Cargo.toml index c65da291c1..1b7a394f9b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,9 +41,9 @@ repository = "https://github.com/denoland/deno" v8 = { version = "0.74.1", default-features = false } deno_ast = { version = "0.27.0", features = ["transpiling"] } -deno_core = "0.197.0" -deno_ops = "0.75.0" -serde_v8 = "0.108.0" +deno_core = "0.198.0" +deno_ops = "0.76.0" +serde_v8 = "0.109.0" deno_runtime = { version = "0.121.0", path = "./runtime" } napi_sym = { version = "0.43.0", path = "./cli/napi/sym" } diff --git a/bench_util/README.md b/bench_util/README.md index 0ec15f0d0b..3d507ecae2 100644 --- a/bench_util/README.md +++ b/bench_util/README.md @@ -7,26 +7,18 @@ use deno_bench_util::bench_or_profile; use deno_bench_util::bencher::{benchmark_group, Bencher}; 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::JsRuntime; -use deno_core::Op; -use deno_core::OpState; + +#[op] +fn op_nop() -> usize { + 9 +} fn setup() -> Vec { - let custom_ext = Extension::builder() - .ops(vec![ - ("op_nop", |state, _| { - Op::Sync(serialize_op_result(Ok(9), state)) - }), - ]) - .build(); - - vec![ - // deno_{ext}::init(...), - custom_ext, - ] + vec![Extension { + name: "my_ext" + ops: std::borrow::Cow::Borrowed(&[op_nop::DECL]) + }] } fn bench_op_nop(b: &mut Bencher) { diff --git a/bench_util/benches/utf8.rs b/bench_util/benches/utf8.rs index 9bc7cdaee4..242fb2bfc3 100644 --- a/bench_util/benches/utf8.rs +++ b/bench_util/benches/utf8.rs @@ -10,21 +10,23 @@ use deno_core::ExtensionFileSource; use deno_core::ExtensionFileSourceCode; fn setup() -> Vec { - vec![Extension::builder("bench_setup") - .js(vec![ExtensionFileSource { + vec![Extension { + name: "bench_setup", + js_files: std::borrow::Cow::Borrowed(&[ExtensionFileSource { specifier: "ext:bench_setup/setup.js", code: ExtensionFileSourceCode::IncludedInBinary( r#" - const hello = "hello world\n"; - const hello1k = hello.repeat(1e3); - const hello1m = hello.repeat(1e6); - const helloEncoded = Deno.core.encode(hello); - const hello1kEncoded = Deno.core.encode(hello1k); - const hello1mEncoded = Deno.core.encode(hello1m); + const hello = "hello world\n"; + const hello1k = hello.repeat(1e3); + const hello1m = hello.repeat(1e6); + const helloEncoded = Deno.core.encode(hello); + const hello1kEncoded = Deno.core.encode(hello1k); + const hello1mEncoded = Deno.core.encode(hello1m); "#, ), - }]) - .build()] + }]), + ..Default::default() + }] } fn bench_utf8_encode_12_b(b: &mut Bencher) { diff --git a/cli/build.rs b/cli/build.rs index 8d379f604c..9860412a1a 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -317,13 +317,13 @@ deno_core::extension!( "40_testing.js", "99_main.js" ], - customizer = |ext: &mut deno_core::ExtensionBuilder| { - ext.esm(vec![ExtensionFileSource { + customizer = |ext: &mut deno_core::Extension| { + ext.esm_files.to_mut().push(ExtensionFileSource { specifier: "ext:cli/runtime/js/99_main.js", code: ExtensionFileSourceCode::LoadedFromFsDuringSnapshot( - std::path::PathBuf::from(deno_runtime::js::PATH_FOR_99_MAIN_JS), + deno_runtime::js::PATH_FOR_99_MAIN_JS, ), - }]); + }); } ); diff --git a/ext/fs/lib.rs b/ext/fs/lib.rs index 7ba6cd7cac..d277129271 100644 --- a/ext/fs/lib.rs +++ b/ext/fs/lib.rs @@ -19,7 +19,6 @@ use crate::ops::*; use deno_core::error::AnyError; use deno_core::OpState; use std::cell::RefCell; -use std::convert::From; use std::path::Path; use std::rc::Rc; diff --git a/ext/kv/lib.rs b/ext/kv/lib.rs index db7c5c22ea..a781f45795 100644 --- a/ext/kv/lib.rs +++ b/ext/kv/lib.rs @@ -8,7 +8,6 @@ use std::borrow::Cow; use std::cell::RefCell; use std::num::NonZeroU32; use std::rc::Rc; -use std::vec; use codec::decode_key; use codec::encode_key; diff --git a/ext/node/lib.rs b/ext/node/lib.rs index 89ee87cd32..8f910ac63f 100644 --- a/ext/node/lib.rs +++ b/ext/node/lib.rs @@ -446,58 +446,55 @@ deno_core::extension!(deno_node, "path/separator.ts", "readline/promises.ts", "repl.ts", - "wasi.ts" - ], - esm_with_specifiers = [ - dir "polyfills", - ("node:assert", "assert.ts"), - ("node:assert/strict", "assert/strict.ts"), - ("node:async_hooks", "async_hooks.ts"), - ("node:buffer", "buffer.ts"), - ("node:child_process", "child_process.ts"), - ("node:cluster", "cluster.ts"), - ("node:console", "console.ts"), - ("node:constants", "constants.ts"), - ("node:crypto", "crypto.ts"), - ("node:dgram", "dgram.ts"), - ("node:diagnostics_channel", "diagnostics_channel.ts"), - ("node:dns", "dns.ts"), - ("node:dns/promises", "dns/promises.ts"), - ("node:domain", "domain.ts"), - ("node:events", "events.ts"), - ("node:fs", "fs.ts"), - ("node:fs/promises", "fs/promises.ts"), - ("node:http", "http.ts"), - ("node:http2", "http2.ts"), - ("node:https", "https.ts"), - ("node:module", "01_require.js"), - ("node:net", "net.ts"), - ("node:os", "os.ts"), - ("node:path", "path.ts"), - ("node:path/posix", "path/posix.ts"), - ("node:path/win32", "path/win32.ts"), - ("node:perf_hooks", "perf_hooks.ts"), - ("node:process", "process.ts"), - ("node:punycode", "punycode.ts"), - ("node:querystring", "querystring.ts"), - ("node:readline", "readline.ts"), - ("node:stream", "stream.ts"), - ("node:stream/consumers", "stream/consumers.mjs"), - ("node:stream/promises", "stream/promises.mjs"), - ("node:stream/web", "stream/web.ts"), - ("node:string_decoder", "string_decoder.ts"), - ("node:sys", "sys.ts"), - ("node:timers", "timers.ts"), - ("node:timers/promises", "timers/promises.ts"), - ("node:tls", "tls.ts"), - ("node:tty", "tty.ts"), - ("node:url", "url.ts"), - ("node:util", "util.ts"), - ("node:util/types", "util/types.ts"), - ("node:v8", "v8.ts"), - ("node:vm", "vm.ts"), - ("node:worker_threads", "worker_threads.ts"), - ("node:zlib", "zlib.ts"), + "wasi.ts", + "assert.ts" with_specifier "node:assert", + "assert/strict.ts" with_specifier "node:assert/strict", + "async_hooks.ts" with_specifier "node:async_hooks", + "buffer.ts" with_specifier "node:buffer", + "child_process.ts" with_specifier "node:child_process", + "cluster.ts" with_specifier "node:cluster", + "console.ts" with_specifier "node:console", + "constants.ts" with_specifier "node:constants", + "crypto.ts" with_specifier "node:crypto", + "dgram.ts" with_specifier "node:dgram", + "diagnostics_channel.ts" with_specifier "node:diagnostics_channel", + "dns.ts" with_specifier "node:dns", + "dns/promises.ts" with_specifier "node:dns/promises", + "domain.ts" with_specifier "node:domain", + "events.ts" with_specifier "node:events", + "fs.ts" with_specifier "node:fs", + "fs/promises.ts" with_specifier "node:fs/promises", + "http.ts" with_specifier "node:http", + "http2.ts" with_specifier "node:http2", + "https.ts" with_specifier "node:https", + "01_require.js" with_specifier "node:module", + "net.ts" with_specifier "node:net", + "os.ts" with_specifier "node:os", + "path.ts" with_specifier "node:path", + "path/posix.ts" with_specifier "node:path/posix", + "path/win32.ts" with_specifier "node:path/win32", + "perf_hooks.ts" with_specifier "node:perf_hooks", + "process.ts" with_specifier "node:process", + "punycode.ts" with_specifier "node:punycode", + "querystring.ts" with_specifier "node:querystring", + "readline.ts" with_specifier "node:readline", + "stream.ts" with_specifier "node:stream", + "stream/consumers.mjs" with_specifier "node:stream/consumers", + "stream/promises.mjs" with_specifier "node:stream/promises", + "stream/web.ts" with_specifier "node:stream/web", + "string_decoder.ts" with_specifier "node:string_decoder", + "sys.ts" with_specifier "node:sys", + "timers.ts" with_specifier "node:timers", + "timers/promises.ts" with_specifier "node:timers/promises", + "tls.ts" with_specifier "node:tls", + "tty.ts" with_specifier "node:tty", + "url.ts" with_specifier "node:url", + "util.ts" with_specifier "node:util", + "util/types.ts" with_specifier "node:util/types", + "v8.ts" with_specifier "node:v8", + "vm.ts" with_specifier "node:vm", + "worker_threads.ts" with_specifier "node:worker_threads", + "zlib.ts" with_specifier "node:zlib", ], options = { maybe_npm_resolver: Option, @@ -516,7 +513,7 @@ deno_core::extension!(deno_node, }, global_template_middleware = global_template_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); global::GETTER_MAP_FN.with(|getter| { @@ -554,7 +551,7 @@ deno_core::extension!(deno_node, named_getter: *descriptor, }); }); - ext.external_references(external_references); + ext.external_references.to_mut().extend(external_references); }, ); diff --git a/ext/url/benches/url_ops.rs b/ext/url/benches/url_ops.rs index 835dfea2ec..b65a0e345b 100644 --- a/ext/url/benches/url_ops.rs +++ b/ext/url/benches/url_ops.rs @@ -13,17 +13,20 @@ fn setup() -> Vec { vec![ deno_webidl::deno_webidl::init_ops_and_esm(), deno_url::deno_url::init_ops_and_esm(), - Extension::builder("bench_setup") - .esm(vec![ExtensionFileSource { + Extension { + name: "bench_setup", + esm_files: std::borrow::Cow::Borrowed(&[ExtensionFileSource { specifier: "ext:bench_setup/setup", code: ExtensionFileSourceCode::IncludedInBinary( - r#"import { URL } from "ext:deno_url/00_url.js"; - globalThis.URL = URL; + r#" + import { URL } from "ext:deno_url/00_url.js"; + globalThis.URL = URL; "#, ), - }]) - .esm_entry_point("ext:bench_setup/setup") - .build(), + }]), + esm_entry_point: Some("ext:bench_setup/setup"), + ..Default::default() + }, ] } diff --git a/ext/web/benches/encoding.rs b/ext/web/benches/encoding.rs index 12fff5d757..fc4ab37fc1 100644 --- a/ext/web/benches/encoding.rs +++ b/ext/web/benches/encoding.rs @@ -30,22 +30,24 @@ fn setup() -> Vec { Default::default(), None, ), - Extension::builder("bench_setup") - .esm(vec![ExtensionFileSource { + Extension { + name: "bench_setup", + esm_files: std::borrow::Cow::Borrowed(&[ExtensionFileSource { specifier: "ext:bench_setup/setup", code: ExtensionFileSourceCode::IncludedInBinary( r#" - import { TextDecoder } from "ext:deno_web/08_text_encoding.js"; - globalThis.TextDecoder = TextDecoder; - globalThis.hello12k = Deno.core.encode("hello world\n".repeat(1e3)); + import { TextDecoder } from "ext:deno_web/08_text_encoding.js"; + globalThis.TextDecoder = TextDecoder; + 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 {}); - }) - .esm_entry_point("ext:bench_setup/setup") - .build(), + })), + ..Default::default() + }, ] } diff --git a/ext/web/benches/timers_ops.rs b/ext/web/benches/timers_ops.rs index 9d74abd173..589fc8534d 100644 --- a/ext/web/benches/timers_ops.rs +++ b/ext/web/benches/timers_ops.rs @@ -24,23 +24,28 @@ fn setup() -> Vec { deno_webidl::deno_webidl::init_ops_and_esm(), deno_url::deno_url::init_ops_and_esm(), deno_console::deno_console::init_ops_and_esm(), - deno_web::deno_web::init_ops_and_esm::(Default::default(), None), - Extension::builder("bench_setup") - .esm(vec![ - ExtensionFileSource { + deno_web::deno_web::init_ops_and_esm::( + Default::default(), + None, + ), + Extension { + name: "bench_setup", + esm_files: std::borrow::Cow::Borrowed(&[ExtensionFileSource { specifier: "ext:bench_setup/setup", - code: ExtensionFileSourceCode::IncludedInBinary(r#" - import { setTimeout, handleTimerMacrotask } from "ext:deno_web/02_timers.js"; - globalThis.setTimeout = setTimeout; - Deno.core.setMacrotaskCallback(handleTimerMacrotask); - "#) - }, - ]) - .state(|state| { - state.put(Permissions{}); - }) - .esm_entry_point("ext:bench_setup/setup") - .build() + code: ExtensionFileSourceCode::IncludedInBinary( + r#" + import { setTimeout, handleTimerMacrotask } from "ext:deno_web/02_timers.js"; + globalThis.setTimeout = setTimeout; + Deno.core.setMacrotaskCallback(handleTimerMacrotask); + "#, + ), + }]), + esm_entry_point: Some("ext:bench_setup/setup"), + op_state_fn: Some(Box::new(|state| { + state.put(Permissions {}); + })), + ..Default::default() + }, ] } diff --git a/ext/webidl/benches/dict.rs b/ext/webidl/benches/dict.rs index b3d95c8a32..e7f4d03006 100644 --- a/ext/webidl/benches/dict.rs +++ b/ext/webidl/benches/dict.rs @@ -12,15 +12,17 @@ use deno_core::ExtensionFileSourceCode; fn setup() -> Vec { vec![ deno_webidl::deno_webidl::init_ops_and_esm(), - Extension::builder("deno_webidl_bench") - .esm(vec![ExtensionFileSource { + Extension { + name: "deno_webidl_bench", + esm_files: std::borrow::Cow::Borrowed(&[ExtensionFileSource { specifier: "ext:deno_webidl_bench/setup.js", code: ExtensionFileSourceCode::IncludedInBinary(include_str!( "dict.js" )), - }]) - .esm_entry_point("ext:deno_webidl_bench/setup.js") - .build(), + }]), + esm_entry_point: Some("ext:deno_webidl_bench/setup.js"), + ..Default::default() + }, ] } diff --git a/runtime/build.rs b/runtime/build.rs index 6fde453776..d7de298832 100644 --- a/runtime/build.rs +++ b/runtime/build.rs @@ -275,14 +275,14 @@ mod startup_snapshot { deno_core::extension!( runtime_main, deps = [runtime], - customizer = |ext: &mut deno_core::ExtensionBuilder| { - ext.esm(vec![ExtensionFileSource { + esm_entry_point = "ext:runtime_main/js/99_main.js", + customizer = |ext: &mut deno_core::Extension| { + ext.esm_files.to_mut().push(ExtensionFileSource { specifier: "ext:runtime_main/js/99_main.js", code: deno_core::ExtensionFileSourceCode::IncludedInBinary( 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!( runtime_main, deps = [runtime], - customizer = |ext: &mut deno_core::ExtensionBuilder| { - ext.esm_entry_point("ext:runtime/90_deno_ns.js"); - } + esm_entry_point = "ext:runtime/90_deno_ns.js", ); pub fn create_runtime_snapshot(snapshot_path: PathBuf) { diff --git a/runtime/ops/tty.rs b/runtime/ops/tty.rs index b4e4d73400..9c34c512fb 100644 --- a/runtime/ops/tty.rs +++ b/runtime/ops/tty.rs @@ -51,6 +51,7 @@ fn get_fd_from_resource( ) -> Result { use winapi::um::handleapi; + #[allow(deprecated)] let Some(handle) = resource.backing_fd() else { return Err(resource_unavailable()); }; @@ -66,6 +67,7 @@ fn get_fd_from_resource( fn get_fd_from_resource( resource: Rc, ) -> Result { + #[allow(deprecated)] match resource.backing_fd() { Some(fd) => Ok(fd), None => Err(resource_unavailable()),