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

Revert "core: don't include_str extension js code (#10786)" (#14614)

This reverts commit 10e50a1207

Alternative to #13217, IMO the tradeoffs made by #10786 aren't worth it.

It breaks abstractions (crates being self-contained, deno_core without snapshotting etc...) and causes pain points / gotchas for both embedders & devs for a relatively minimal gain in incremental build time ...

Closes #11030
This commit is contained in:
Aaron O'Mullan 2022-05-15 13:27:56 +02:00 committed by GitHub
parent b08b1da6f4
commit f5c31b56e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 12 additions and 30 deletions

View file

@ -9,19 +9,14 @@ fn setup() -> Vec<Extension> {
vec![Extension::builder() vec![Extension::builder()
.js(vec![( .js(vec![(
"setup.js", "setup.js",
Box::new(|| { r#"
Ok(
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);
"# "#,
.into(),
)
}),
)]) )])
.build()] .build()]
} }

View file

@ -3,8 +3,7 @@ use crate::OpState;
use anyhow::Error; use anyhow::Error;
use std::task::Context; use std::task::Context;
pub type SourcePair = (&'static str, Box<SourceLoadFn>); pub type SourcePair = (&'static str, &'static str);
pub type SourceLoadFn = dyn Fn() -> Result<String, Error>;
pub type OpFnRef = v8::FunctionCallback; pub type OpFnRef = v8::FunctionCallback;
pub type OpMiddlewareFn = dyn Fn(OpDecl) -> OpDecl; pub type OpMiddlewareFn = dyn Fn(OpDecl) -> OpDecl;
pub type OpStateFn = dyn Fn(&mut OpState) -> Result<(), Error>; pub type OpStateFn = dyn Fn(&mut OpState) -> Result<(), Error>;
@ -169,9 +168,8 @@ impl ExtensionBuilder {
} }
} }
} }
/// Helps embed JS files in an extension. Returns Vec<(&'static str, Box<SourceLoadFn>)> /// Helps embed JS files in an extension. Returns Vec<(&'static str, &'static str)>
/// representing the filename and source code. This is only meant for extensions /// representing the filename and source code.
/// that will be snapshotted, as code will be loaded at runtime.
/// ///
/// Example: /// Example:
/// ```ignore /// ```ignore
@ -187,13 +185,7 @@ macro_rules! include_js_files {
vec![ vec![
$(( $((
concat!($prefix, "/", $file), concat!($prefix, "/", $file),
Box::new(|| { include_str!($file),
let c = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let path = c.join($file);
println!("cargo:rerun-if-changed={}", path.display());
let src = std::fs::read_to_string(path)?;
Ok(src)
}),
),)+ ),)+
] ]
}; };

View file

@ -491,9 +491,8 @@ impl JsRuntime {
for m in extensions.iter_mut() { for m in extensions.iter_mut() {
let js_files = m.init_js(); let js_files = m.init_js();
for (filename, source) in js_files { for (filename, source) in js_files {
let source = source()?;
// TODO(@AaronO): use JsRuntime::execute_static() here to move src off heap // TODO(@AaronO): use JsRuntime::execute_static() here to move src off heap
realm.execute_script(self, filename, &source)?; realm.execute_script(self, filename, source)?;
} }
} }
// Restore extensions // Restore extensions

View file

@ -11,9 +11,7 @@ fn setup() -> Vec<Extension> {
Extension::builder() Extension::builder()
.js(vec![( .js(vec![(
"setup", "setup",
Box::new(|| { "const { URL } = globalThis.__bootstrap.url;",
Ok(r#"const { URL } = globalThis.__bootstrap.url;"#.to_owned())
}),
)]) )])
.build(), .build(),
] ]

View file

@ -26,12 +26,10 @@ fn setup() -> Vec<Extension> {
deno_web::init::<Permissions>(BlobStore::default(), None), deno_web::init::<Permissions>(BlobStore::default(), None),
Extension::builder() Extension::builder()
.js(vec![ .js(vec![
("setup", ("setup", r#"
Box::new(|| Ok(r#" const { opNow, setTimeout, handleTimerMacrotask } = globalThis.__bootstrap.timers;
const { opNow, setTimeout, handleTimerMacrotask } = globalThis.__bootstrap.timers; Deno.core.setMacrotaskCallback(handleTimerMacrotask);
Deno.core.setMacrotaskCallback(handleTimerMacrotask); "#),
"#.to_owned())),
),
]) ])
.state(|state| { .state(|state| {
state.put(Permissions{}); state.put(Permissions{});