1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

chore: upgrade deno_core (#22699)

Co-authored-by: Matt Mastracci <matthew@mastracci.com>
This commit is contained in:
Bartek Iwańczuk 2024-03-05 01:17:39 +00:00 committed by GitHub
parent 0022c35a23
commit d9fa2dd550
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 52 additions and 83 deletions

12
Cargo.lock generated
View file

@ -1257,9 +1257,9 @@ dependencies = [
[[package]] [[package]]
name = "deno_core" name = "deno_core"
version = "0.266.0" version = "0.267.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfbfe65d133be3abefb973f87b601f686666bb05d5521f0fab16d9dd28a5d5cf" checksum = "b5dc9aeacf98e78c1d8fa716e35f2e8a960e349f73d6bc485d45e49457d80556"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",
@ -1714,9 +1714,9 @@ dependencies = [
[[package]] [[package]]
name = "deno_ops" name = "deno_ops"
version = "0.142.0" version = "0.143.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f96d7d6806eb726b4feb3092cbdaf887ae412b6e8be7c67617c61dbe8b3f1693" checksum = "594aa46152868ee15e104ab3484976a144162694a00c4096174e71b78fdb32c7"
dependencies = [ dependencies = [
"proc-macro-rules", "proc-macro-rules",
"proc-macro2", "proc-macro2",
@ -5600,9 +5600,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_v8" name = "serde_v8"
version = "0.175.0" version = "0.176.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfb0193c9e969f1d7a660a2c5ad7c94bb00146c5f5367607eabb2af78094160f" checksum = "25b62c66605745359af254c41af8e6ea2b6124a3698628a7329a6f32698250ee"
dependencies = [ dependencies = [
"bytes", "bytes",
"derive_more", "derive_more",

View file

@ -43,7 +43,7 @@ repository = "https://github.com/denoland/deno"
[workspace.dependencies] [workspace.dependencies]
deno_ast = { version = "0.34.1", features = ["transpiling"] } deno_ast = { version = "0.34.1", features = ["transpiling"] }
deno_core = { version = "0.266.0", features = ["snapshot_data_bincode"] } deno_core = { version = "0.267.0" }
deno_bench_util = { version = "0.134.0", path = "./bench_util" } deno_bench_util = { version = "0.134.0", path = "./bench_util" }
deno_lockfile = "0.19.0" deno_lockfile = "0.19.0"

View file

@ -116,7 +116,7 @@ pub fn bench_js_async_with(
} }
async fn inner_async(src: &'static str, runtime: &mut JsRuntime) { async fn inner_async(src: &'static str, runtime: &mut JsRuntime) {
runtime.execute_script_static("inner_loop", src).unwrap(); runtime.execute_script("inner_loop", src).unwrap();
runtime runtime
.run_event_loop(PollEventLoopOptions::default()) .run_event_loop(PollEventLoopOptions::default())
.await .await

View file

@ -276,6 +276,7 @@ mod ts {
build_libs, build_libs,
path_dts, path_dts,
)], )],
extension_transpiler: None,
with_runtime_cb: None, with_runtime_cb: None,
skip_op_registration: false, skip_op_registration: false,
}, },

View file

@ -29,7 +29,7 @@ mod tests {
..Default::default() ..Default::default()
}); });
js_runtime js_runtime
.execute_script_static( .execute_script(
"<anon>", "<anon>",
r#" r#"
if (!(bootstrap.mainRuntime && bootstrap.workerRuntime)) { if (!(bootstrap.mainRuntime && bootstrap.workerRuntime)) {

View file

@ -4186,7 +4186,7 @@ fn start_tsc(runtime: &mut JsRuntime, debug: bool) -> Result<(), AnyError> {
let init_config = json!({ "debug": debug }); let init_config = json!({ "debug": debug });
let init_src = format!("globalThis.serverInit({init_config});"); let init_src = format!("globalThis.serverInit({init_config});");
runtime.execute_script(located_script_name!(), init_src.into())?; runtime.execute_script(located_script_name!(), init_src)?;
Ok(()) Ok(())
} }
@ -4564,7 +4564,7 @@ fn request(
"globalThis.serverRequest({id}, \"{}\", {});", "globalThis.serverRequest({id}, \"{}\", {});",
request.method, &request.args request.method, &request.args
); );
runtime.execute_script(located_script_name!(), request_src.into())?; runtime.execute_script(located_script_name!(), request_src)?;
let op_state = runtime.op_state(); let op_state = runtime.op_state();
let mut op_state = op_state.borrow_mut(); let mut op_state = op_state.borrow_mut();

View file

@ -848,7 +848,7 @@ pub fn exec(request: Request) -> Result<Response, AnyError> {
"rootNames": root_names, "rootNames": root_names,
"localOnly": request.check_mode == TypeCheckMode::Local, "localOnly": request.check_mode == TypeCheckMode::Local,
}); });
let exec_source = format!("globalThis.exec({request_value})").into(); let exec_source = format!("globalThis.exec({request_value})");
let mut runtime = JsRuntime::new(RuntimeOptions { let mut runtime = JsRuntime::new(RuntimeOptions {
startup_snapshot: Some(compiler_snapshot()), startup_snapshot: Some(compiler_snapshot()),
@ -1007,7 +1007,7 @@ mod tests {
..Default::default() ..Default::default()
}); });
js_runtime js_runtime
.execute_script_static( .execute_script(
"<anon>", "<anon>",
r#" r#"
if (!(globalThis.exec)) { if (!(globalThis.exec)) {

View file

@ -397,10 +397,7 @@ impl CliMainWorker {
name: &'static str, name: &'static str,
source_code: &'static str, source_code: &'static str,
) -> Result<v8::Global<v8::Value>, AnyError> { ) -> Result<v8::Global<v8::Value>, AnyError> {
self self.worker.js_runtime.execute_script(name, source_code)
.worker
.js_runtime
.execute_script_static(name, source_code)
} }
} }
@ -656,9 +653,9 @@ impl CliMainWorkerFactory {
if self.shared.subcommand.needs_test() { if self.shared.subcommand.needs_test() {
macro_rules! test_file { macro_rules! test_file {
($($file:literal),*) => { ($($file:literal),*) => {
$(worker.js_runtime.lazy_load_es_module_from_code( $(worker.js_runtime.lazy_load_es_module_with_code(
concat!("ext:cli/", $file), concat!("ext:cli/", $file),
deno_core::FastString::StaticAscii(include_str!(concat!("js/", $file))), deno_core::ascii_str_include!(concat!("js/", $file)),
)?;)* )?;)*
} }
} }

View file

@ -636,8 +636,7 @@ pub fn load_cjs_module(
main = main, main = main,
module = escape_for_single_quote_string(module), module = escape_for_single_quote_string(module),
inspect_brk = inspect_brk, inspect_brk = inspect_brk,
) );
.into();
js_runtime.execute_script(located_script_name!(), source_code)?; js_runtime.execute_script(located_script_name!(), source_code)?;
Ok(()) Ok(())

View file

@ -7,8 +7,9 @@ use deno_ast::SourceTextInfo;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::extension; use deno_core::extension;
use deno_core::Extension; use deno_core::Extension;
use deno_core::ExtensionFileSource; use deno_core::ModuleCodeString;
use deno_core::ExtensionFileSourceCode; use deno_core::ModuleName;
use deno_core::SourceMapData;
use std::path::Path; use std::path::Path;
extension!(runtime, extension!(runtime,
@ -56,36 +57,38 @@ extension!(runtime,
customizer = |ext: &mut Extension| { customizer = |ext: &mut Extension| {
#[cfg(not(feature = "exclude_runtime_main_js"))] #[cfg(not(feature = "exclude_runtime_main_js"))]
{ {
ext.esm_files.to_mut().push(ExtensionFileSource::new("ext:runtime_main/js/99_main.js", include_str!("./js/99_main.js"))); use deno_core::ascii_str_include;
use deno_core::ExtensionFileSource;
ext.esm_files.to_mut().push(ExtensionFileSource::new("ext:runtime_main/js/99_main.js", ascii_str_include!("./js/99_main.js")));
ext.esm_entry_point = Some("ext:runtime_main/js/99_main.js"); ext.esm_entry_point = Some("ext:runtime_main/js/99_main.js");
} }
} }
); );
pub fn maybe_transpile_source( pub fn maybe_transpile_source(
source: &mut ExtensionFileSource, name: ModuleName,
) -> Result<(), AnyError> { source: ModuleCodeString,
) -> Result<(ModuleCodeString, Option<SourceMapData>), AnyError> {
// Always transpile `node:` built-in modules, since they might be TypeScript. // Always transpile `node:` built-in modules, since they might be TypeScript.
let media_type = if source.specifier.starts_with("node:") { let media_type = if name.starts_with("node:") {
MediaType::TypeScript MediaType::TypeScript
} else { } else {
MediaType::from_path(Path::new(&source.specifier)) MediaType::from_path(Path::new(&name))
}; };
match media_type { match media_type {
MediaType::TypeScript => {} MediaType::TypeScript => {}
MediaType::JavaScript => return Ok(()), MediaType::JavaScript => return Ok((source, None)),
MediaType::Mjs => return Ok(()), MediaType::Mjs => return Ok((source, None)),
_ => panic!( _ => panic!(
"Unsupported media type for snapshotting {media_type:?} for file {}", "Unsupported media type for snapshotting {media_type:?} for file {}",
source.specifier name
), ),
} }
let code = source.load()?;
let parsed = deno_ast::parse_module(ParseParams { let parsed = deno_ast::parse_module(ParseParams {
specifier: deno_core::url::Url::parse(source.specifier).unwrap(), specifier: deno_core::url::Url::parse(&name).unwrap(),
text_info: SourceTextInfo::from_string(code.as_str().to_owned()), text_info: SourceTextInfo::from_string(source.as_str().to_owned()),
media_type, media_type,
capture_tokens: false, capture_tokens: false,
scope_analysis: false, scope_analysis: false,
@ -97,7 +100,5 @@ pub fn maybe_transpile_source(
..Default::default() ..Default::default()
})?; })?;
source.code = Ok((transpiled_source.text.into(), None))
ExtensionFileSourceCode::Computed(transpiled_source.text.into());
Ok(())
} }

View file

@ -13,6 +13,7 @@ use deno_http::DefaultHttpPropertyExtractor;
use std::io::Write; use std::io::Write;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
use std::rc::Rc;
use std::sync::Arc; use std::sync::Arc;
#[derive(Clone)] #[derive(Clone)]
@ -204,7 +205,7 @@ pub fn create_runtime_snapshot(
// NOTE(bartlomieju): ordering is important here, keep it in sync with // NOTE(bartlomieju): ordering is important here, keep it in sync with
// `runtime/worker.rs`, `runtime/web_worker.rs` and `runtime/snapshot.rs`! // `runtime/worker.rs`, `runtime/web_worker.rs` and `runtime/snapshot.rs`!
let fs = std::sync::Arc::new(deno_fs::RealFs); let fs = std::sync::Arc::new(deno_fs::RealFs);
let mut extensions: Vec<Extension> = vec![ let extensions: Vec<Extension> = vec![
deno_webidl::deno_webidl::init_ops_and_esm(), deno_webidl::deno_webidl::init_ops_and_esm(),
deno_console::deno_console::init_ops_and_esm(), deno_console::deno_console::init_ops_and_esm(),
deno_url::deno_url::init_ops_and_esm(), deno_url::deno_url::init_ops_and_esm(),
@ -257,20 +258,14 @@ pub fn create_runtime_snapshot(
ops::web_worker::deno_web_worker::init_ops(), ops::web_worker::deno_web_worker::init_ops(),
]; ];
for extension in &mut extensions {
for source in extension.esm_files.to_mut() {
maybe_transpile_source(source).unwrap();
}
for source in extension.js_files.to_mut() {
maybe_transpile_source(source).unwrap();
}
}
let output = create_snapshot( let output = create_snapshot(
CreateSnapshotOptions { CreateSnapshotOptions {
cargo_manifest_dir: env!("CARGO_MANIFEST_DIR"), cargo_manifest_dir: env!("CARGO_MANIFEST_DIR"),
startup_snapshot: None, startup_snapshot: None,
extensions, extensions,
extension_transpiler: Some(Rc::new(|specifier, source| {
maybe_transpile_source(specifier, source)
})),
with_runtime_cb: Some(Box::new(|rt| { with_runtime_cb: Some(Box::new(|rt| {
let isolate = rt.v8_isolate(); let isolate = rt.v8_isolate();
let scope = &mut v8::HandleScope::new(isolate); let scope = &mut v8::HandleScope::new(isolate);

View file

@ -2,6 +2,7 @@
use crate::inspector_server::InspectorServer; use crate::inspector_server::InspectorServer;
use crate::ops; use crate::ops;
use crate::permissions::PermissionsContainer; use crate::permissions::PermissionsContainer;
use crate::shared::maybe_transpile_source;
use crate::shared::runtime; use crate::shared::runtime;
use crate::tokio_util::create_and_run_current_thread; use crate::tokio_util::create_and_run_current_thread;
use crate::worker::import_meta_resolve_callback; use crate::worker::import_meta_resolve_callback;
@ -498,16 +499,6 @@ impl WebWorker {
extension.esm_files = std::borrow::Cow::Borrowed(&[]); extension.esm_files = std::borrow::Cow::Borrowed(&[]);
extension.esm_entry_point = None; extension.esm_entry_point = None;
} }
#[cfg(not(feature = "only_snapshotted_js_sources"))]
{
use crate::shared::maybe_transpile_source;
for source in extension.esm_files.to_mut() {
maybe_transpile_source(source).unwrap();
}
for source in extension.js_files.to_mut() {
maybe_transpile_source(source).unwrap();
}
}
} }
extensions.extend(std::mem::take(&mut options.extensions)); extensions.extend(std::mem::take(&mut options.extensions));
@ -535,6 +526,9 @@ impl WebWorker {
shared_array_buffer_store: options.shared_array_buffer_store.clone(), shared_array_buffer_store: options.shared_array_buffer_store.clone(),
compiled_wasm_module_store: options.compiled_wasm_module_store.clone(), compiled_wasm_module_store: options.compiled_wasm_module_store.clone(),
extensions, extensions,
extension_transpiler: Some(Rc::new(|specifier, source| {
maybe_transpile_source(specifier, source)
})),
inspector: options.maybe_inspector_server.is_some(), inspector: options.maybe_inspector_server.is_some(),
feature_checker: Some(options.feature_checker.clone()), feature_checker: Some(options.feature_checker.clone()),
op_metrics_factory_fn, op_metrics_factory_fn,
@ -664,10 +658,7 @@ impl WebWorker {
&mut self, &mut self,
module_specifier: &ModuleSpecifier, module_specifier: &ModuleSpecifier,
) -> Result<ModuleId, AnyError> { ) -> Result<ModuleId, AnyError> {
self self.js_runtime.load_main_es_module(module_specifier).await
.js_runtime
.load_main_module(module_specifier, None)
.await
} }
/// Loads and instantiates specified JavaScript module as "side" module. /// Loads and instantiates specified JavaScript module as "side" module.
@ -675,10 +666,7 @@ impl WebWorker {
&mut self, &mut self,
module_specifier: &ModuleSpecifier, module_specifier: &ModuleSpecifier,
) -> Result<ModuleId, AnyError> { ) -> Result<ModuleId, AnyError> {
self self.js_runtime.load_side_es_module(module_specifier).await
.js_runtime
.load_side_module(module_specifier, None)
.await
} }
/// Loads, instantiates and executes specified JavaScript module. /// Loads, instantiates and executes specified JavaScript module.

View file

@ -45,6 +45,7 @@ use log::debug;
use crate::inspector_server::InspectorServer; use crate::inspector_server::InspectorServer;
use crate::ops; use crate::ops;
use crate::permissions::PermissionsContainer; use crate::permissions::PermissionsContainer;
use crate::shared::maybe_transpile_source;
use crate::shared::runtime; use crate::shared::runtime;
use crate::BootstrapOptions; use crate::BootstrapOptions;
@ -445,16 +446,6 @@ impl MainWorker {
extension.esm_files = std::borrow::Cow::Borrowed(&[]); extension.esm_files = std::borrow::Cow::Borrowed(&[]);
extension.esm_entry_point = None; extension.esm_entry_point = None;
} }
#[cfg(not(feature = "only_snapshotted_js_sources"))]
{
use crate::shared::maybe_transpile_source;
for source in extension.esm_files.to_mut() {
maybe_transpile_source(source).unwrap();
}
for source in extension.js_files.to_mut() {
maybe_transpile_source(source).unwrap();
}
}
} }
extensions.extend(std::mem::take(&mut options.extensions)); extensions.extend(std::mem::take(&mut options.extensions));
@ -481,6 +472,9 @@ impl MainWorker {
shared_array_buffer_store: options.shared_array_buffer_store.clone(), shared_array_buffer_store: options.shared_array_buffer_store.clone(),
compiled_wasm_module_store: options.compiled_wasm_module_store.clone(), compiled_wasm_module_store: options.compiled_wasm_module_store.clone(),
extensions, extensions,
extension_transpiler: Some(Rc::new(|specifier, source| {
maybe_transpile_source(specifier, source)
})),
inspector: options.maybe_inspector_server.is_some(), inspector: options.maybe_inspector_server.is_some(),
is_main: true, is_main: true,
feature_checker: Some(options.feature_checker.clone()), feature_checker: Some(options.feature_checker.clone()),
@ -579,10 +573,7 @@ impl MainWorker {
&mut self, &mut self,
module_specifier: &ModuleSpecifier, module_specifier: &ModuleSpecifier,
) -> Result<ModuleId, AnyError> { ) -> Result<ModuleId, AnyError> {
self self.js_runtime.load_main_es_module(module_specifier).await
.js_runtime
.load_main_module(module_specifier, None)
.await
} }
/// Loads and instantiates specified JavaScript module as "side" module. /// Loads and instantiates specified JavaScript module as "side" module.
@ -590,10 +581,7 @@ impl MainWorker {
&mut self, &mut self,
module_specifier: &ModuleSpecifier, module_specifier: &ModuleSpecifier,
) -> Result<ModuleId, AnyError> { ) -> Result<ModuleId, AnyError> {
self self.js_runtime.load_side_es_module(module_specifier).await
.js_runtime
.load_side_module(module_specifier, None)
.await
} }
/// Executes specified JavaScript module. /// Executes specified JavaScript module.