1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -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]]
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",

View file

@ -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" }

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::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<Extension> {
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) {

View file

@ -10,21 +10,23 @@ use deno_core::ExtensionFileSource;
use deno_core::ExtensionFileSourceCode;
fn setup() -> Vec<Extension> {
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) {

View file

@ -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,
),
}]);
});
}
);

View file

@ -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;

View file

@ -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;

View file

@ -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<NpmResolverRc>,
@ -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);
},
);

View file

@ -13,17 +13,20 @@ fn setup() -> Vec<Extension> {
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()
},
]
}

View file

@ -30,22 +30,24 @@ fn setup() -> Vec<Extension> {
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()
},
]
}

View file

@ -24,23 +24,28 @@ fn setup() -> Vec<Extension> {
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::<Permissions>(Default::default(), None),
Extension::builder("bench_setup")
.esm(vec![
ExtensionFileSource {
deno_web::deno_web::init_ops_and_esm::<Permissions>(
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()
},
]
}

View file

@ -12,15 +12,17 @@ use deno_core::ExtensionFileSourceCode;
fn setup() -> Vec<Extension> {
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()
},
]
}

View file

@ -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) {

View file

@ -51,6 +51,7 @@ fn get_fd_from_resource(
) -> Result<std::os::windows::io::RawHandle, AnyError> {
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<FileResource>,
) -> Result<std::os::unix::prelude::RawFd, AnyError> {
#[allow(deprecated)]
match resource.backing_fd() {
Some(fd) => Ok(fd),
None => Err(resource_unavailable()),