1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-26 00:59:24 -05:00

refactor: don't expose Deno[Deno.internal].core namespace (#18816)

This commit is contained in:
Bartek Iwańczuk 2023-04-26 19:57:38 +02:00 committed by GitHub
parent 2df6db36c8
commit 14aaa73c02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 95 additions and 61 deletions

View file

@ -198,7 +198,7 @@ fn recursive_permissions_pledge() {
let context = TestContext::default();
let output = context
.new_command()
.args("bench bench/recursive_permissions_pledge.js")
.args("bench --enable-testing-features-do-not-use bench/recursive_permissions_pledge.js")
.run();
output.assert_exit_code(1);
assert_contains!(

View file

@ -307,6 +307,7 @@ async fn inspector_break_on_first_line() {
let child = util::deno_cmd()
.arg("run")
.arg(inspect_flag_with_unique_port("--inspect-brk"))
.arg("--enable-testing-features-do-not-use")
.arg(script)
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())

View file

@ -28,6 +28,7 @@ fn js_unit_tests() {
.arg("--unstable")
.arg("--location=http://js-unit-tests/foo/bar")
.arg("--no-prompt")
.arg("--enable-testing-features-do-not-use")
.arg("-A")
.arg(util::tests_path().join("unit"))
.spawn()

View file

@ -118,7 +118,7 @@ itest!(dual_cjs_esm {
});
itest!(child_process_fork_test {
args: "run -A --quiet npm/child_process_fork_test/main.ts",
args: "run -A --quiet --enable-testing-features-do-not-use npm/child_process_fork_test/main.ts",
output: "npm/child_process_fork_test/main.out",
envs: env_vars_for_npm_tests(),
http_server: true,

View file

@ -213,7 +213,7 @@ itest!(_038_checkjs {
});
itest!(_042_dyn_import_evalcontext {
args: "run --quiet --allow-read --reload run/042_dyn_import_evalcontext.ts",
args: "run --quiet --allow-read --reload --enable-testing-features-do-not-use run/042_dyn_import_evalcontext.ts",
output: "run/042_dyn_import_evalcontext.ts.out",
});
@ -1161,25 +1161,25 @@ itest!(exit_error42 {
});
itest!(set_exit_code_0 {
args: "run --no-check --unstable run/set_exit_code_0.ts",
args: "run --no-check --unstable --enable-testing-features-do-not-use run/set_exit_code_0.ts",
output_str: Some(""),
exit_code: 0,
});
itest!(set_exit_code_1 {
args: "run --no-check --unstable run/set_exit_code_1.ts",
args: "run --no-check --unstable --enable-testing-features-do-not-use run/set_exit_code_1.ts",
output_str: Some(""),
exit_code: 42,
});
itest!(set_exit_code_2 {
args: "run --no-check --unstable run/set_exit_code_2.ts",
args: "run --no-check --unstable --enable-testing-features-do-not-use run/set_exit_code_2.ts",
output_str: Some(""),
exit_code: 42,
});
itest!(op_exit_op_set_exit_code_in_worker {
args: "run --no-check --unstable --allow-read run/op_exit_op_set_exit_code_in_worker.ts",
args: "run --no-check --unstable --allow-read --enable-testing-features-do-not-use run/op_exit_op_set_exit_code_in_worker.ts",
exit_code: 21,
output_str: Some(""),
});
@ -1197,7 +1197,7 @@ itest!(heapstats {
itest!(finalization_registry {
args:
"run --quiet --unstable --v8-flags=--expose-gc run/finalization_registry.js",
"run --quiet --unstable --enable-testing-features-do-not-use --v8-flags=--expose-gc run/finalization_registry.js",
output: "run/finalization_registry.js.out",
});
@ -2755,7 +2755,7 @@ itest!(long_data_url_formatting {
});
itest!(eval_context_throw_dom_exception {
args: "run run/eval_context_throw_dom_exception.js",
args: "run --enable-testing-features-do-not-use run/eval_context_throw_dom_exception.js",
output: "run/eval_context_throw_dom_exception.js.out",
});
@ -3117,115 +3117,115 @@ itest!(fetch_async_error_stack {
});
itest!(unstable_ffi_1 {
args: "run run/ffi/unstable_ffi_1.js",
args: "run --enable-testing-features-do-not-use run/ffi/unstable_ffi_1.js",
output: "run/ffi/unstable_ffi_1.js.out",
exit_code: 70,
});
itest!(unstable_ffi_2 {
args: "run run/ffi/unstable_ffi_2.js",
args: "run --enable-testing-features-do-not-use run/ffi/unstable_ffi_2.js",
output: "run/ffi/unstable_ffi_2.js.out",
exit_code: 70,
});
itest!(unstable_ffi_3 {
args: "run run/ffi/unstable_ffi_3.js",
args: "run --enable-testing-features-do-not-use run/ffi/unstable_ffi_3.js",
output: "run/ffi/unstable_ffi_3.js.out",
exit_code: 70,
});
itest!(unstable_ffi_4 {
args: "run run/ffi/unstable_ffi_4.js",
args: "run --enable-testing-features-do-not-use run/ffi/unstable_ffi_4.js",
output: "run/ffi/unstable_ffi_4.js.out",
exit_code: 70,
});
itest!(unstable_ffi_5 {
args: "run run/ffi/unstable_ffi_5.js",
args: "run --enable-testing-features-do-not-use run/ffi/unstable_ffi_5.js",
output: "run/ffi/unstable_ffi_5.js.out",
exit_code: 70,
});
itest!(unstable_ffi_6 {
args: "run run/ffi/unstable_ffi_6.js",
args: "run --enable-testing-features-do-not-use run/ffi/unstable_ffi_6.js",
output: "run/ffi/unstable_ffi_6.js.out",
exit_code: 70,
});
itest!(unstable_ffi_7 {
args: "run run/ffi/unstable_ffi_7.js",
args: "run --enable-testing-features-do-not-use run/ffi/unstable_ffi_7.js",
output: "run/ffi/unstable_ffi_7.js.out",
exit_code: 70,
});
itest!(unstable_ffi_8 {
args: "run run/ffi/unstable_ffi_8.js",
args: "run --enable-testing-features-do-not-use run/ffi/unstable_ffi_8.js",
output: "run/ffi/unstable_ffi_8.js.out",
exit_code: 70,
});
itest!(unstable_ffi_9 {
args: "run run/ffi/unstable_ffi_9.js",
args: "run --enable-testing-features-do-not-use run/ffi/unstable_ffi_9.js",
output: "run/ffi/unstable_ffi_9.js.out",
exit_code: 70,
});
itest!(unstable_ffi_10 {
args: "run run/ffi/unstable_ffi_10.js",
args: "run --enable-testing-features-do-not-use run/ffi/unstable_ffi_10.js",
output: "run/ffi/unstable_ffi_10.js.out",
exit_code: 70,
});
itest!(unstable_ffi_11 {
args: "run run/ffi/unstable_ffi_11.js",
args: "run --enable-testing-features-do-not-use run/ffi/unstable_ffi_11.js",
output: "run/ffi/unstable_ffi_11.js.out",
exit_code: 70,
});
itest!(unstable_ffi_12 {
args: "run run/ffi/unstable_ffi_12.js",
args: "run --enable-testing-features-do-not-use run/ffi/unstable_ffi_12.js",
output: "run/ffi/unstable_ffi_12.js.out",
exit_code: 70,
});
itest!(unstable_ffi_13 {
args: "run run/ffi/unstable_ffi_13.js",
args: "run --enable-testing-features-do-not-use run/ffi/unstable_ffi_13.js",
output: "run/ffi/unstable_ffi_13.js.out",
exit_code: 70,
});
itest!(unstable_ffi_14 {
args: "run run/ffi/unstable_ffi_14.js",
args: "run --enable-testing-features-do-not-use run/ffi/unstable_ffi_14.js",
output: "run/ffi/unstable_ffi_14.js.out",
exit_code: 70,
});
itest!(unstable_ffi_15 {
args: "run run/ffi/unstable_ffi_15.js",
args: "run --enable-testing-features-do-not-use run/ffi/unstable_ffi_15.js",
output: "run/ffi/unstable_ffi_15.js.out",
exit_code: 70,
});
itest!(unstable_ffi_16 {
args: "run run/ffi/unstable_ffi_16.js",
args: "run --enable-testing-features-do-not-use run/ffi/unstable_ffi_16.js",
output: "run/ffi/unstable_ffi_16.js.out",
exit_code: 70,
});
itest!(unstable_ffi_17 {
args: "run run/ffi/unstable_ffi_17.js",
args: "run --enable-testing-features-do-not-use run/ffi/unstable_ffi_17.js",
output: "run/ffi/unstable_ffi_17.js.out",
exit_code: 70,
});
itest!(unstable_ffi_18 {
args: "run run/ffi/unstable_ffi_18.js",
args: "run --enable-testing-features-do-not-use run/ffi/unstable_ffi_18.js",
output: "run/ffi/unstable_ffi_18.js.out",
exit_code: 70,
});
itest!(unstable_ffi_19 {
args: "run run/ffi/unstable_ffi_19.js",
args: "run --enable-testing-features-do-not-use run/ffi/unstable_ffi_19.js",
output: "run/ffi/unstable_ffi_19.js.out",
exit_code: 70,
});
@ -3248,7 +3248,7 @@ itest!(event_listener_error_handled {
// https://github.com/denoland/deno/pull/14159#issuecomment-1092285446
itest!(event_listener_error_immediate_exit {
args: "run --quiet run/event_listener_error_immediate_exit.ts",
args: "run --quiet --enable-testing-features-do-not-use run/event_listener_error_immediate_exit.ts",
output: "run/event_listener_error_immediate_exit.ts.out",
exit_code: 1,
});
@ -3256,7 +3256,7 @@ itest!(event_listener_error_immediate_exit {
// https://github.com/denoland/deno/pull/14159#issuecomment-1092285446
itest!(event_listener_error_immediate_exit_worker {
args:
"run --quiet --unstable -A run/event_listener_error_immediate_exit_worker.ts",
"run --quiet --unstable -A --enable-testing-features-do-not-use run/event_listener_error_immediate_exit_worker.ts",
output: "run/event_listener_error_immediate_exit_worker.ts.out",
exit_code: 1,
});
@ -4363,22 +4363,24 @@ fn permission_prompt_strips_ansi_codes_and_control_chars() {
)
});
util::with_pty(&["repl"], |mut console| {
console.write_line_raw(r#"const boldANSI = "\u001b[1m";"#);
console.expect("undefined");
console.write_line_raw(r#"const unboldANSI = "\u001b[22m";"#);
console.expect("undefined");
console.write_line_raw(r#"const prompt = `┌ ⚠️ ${boldANSI}Deno requests run access to "echo"${unboldANSI}\n ├ Requested by \`Deno.Command().output()`"#);
console.expect("undefined");
console.write_line_raw(r#"const moveANSIUp = "\u001b[1A";"#);
console.expect("undefined");
console.write_line_raw(r#"const clearANSI = "\u001b[2K";"#);
console.expect("undefined");
console.write_line_raw(r#"const moveANSIStart = "\u001b[1000D";"#);
console.expect("undefined");
util::with_pty(
&["repl", "--enable-testing-features-do-not-use"],
|mut console| {
console.write_line_raw(r#"const boldANSI = "\u001b[1m";"#);
console.expect("undefined");
console.write_line_raw(r#"const unboldANSI = "\u001b[22m";"#);
console.expect("undefined");
console.write_line_raw(r#"const prompt = `┌ ⚠️ ${boldANSI}Deno requests run access to "echo"${unboldANSI}\n ├ Requested by \`Deno.Command().output()`"#);
console.expect("undefined");
console.write_line_raw(r#"const moveANSIUp = "\u001b[1A";"#);
console.expect("undefined");
console.write_line_raw(r#"const clearANSI = "\u001b[2K";"#);
console.expect("undefined");
console.write_line_raw(r#"const moveANSIStart = "\u001b[1000D";"#);
console.expect("undefined");
console.write_line_raw(
r#"Deno[Deno.internal].core.ops.op_spawn_child({
console.write_line_raw(
r#"Deno[Deno.internal].core.ops.op_spawn_child({
cmd: "cat",
args: ["file.txt"],
clearEnv: false,
@ -4392,10 +4394,11 @@ fn permission_prompt_strips_ansi_codes_and_control_chars() {
signal: undefined,
windowsRawArguments: false,
}, moveANSIUp + clearANSI + moveANSIStart + prompt)"#,
);
);
console.expect(r#"┌ ⚠️ Deno requests run access to "cat""#);
});
console.expect(r#"┌ ⚠️ Deno requests run access to "cat""#);
},
);
}
itest!(node_builtin_modules_ts {

View file

@ -216,7 +216,7 @@ itest!(ops_sanitizer_timeout_failure {
});
itest!(ops_sanitizer_multiple_timeout_tests {
args: "test --trace-ops test/ops_sanitizer_multiple_timeout_tests.ts",
args: "test --trace-ops --enable-testing-features-do-not-use test/ops_sanitizer_multiple_timeout_tests.ts",
exit_code: 1,
output: "test/ops_sanitizer_multiple_timeout_tests.out",
});
@ -390,7 +390,7 @@ fn recursive_permissions_pledge() {
let context = TestContext::default();
let output = context
.new_command()
.args("test test/recursive_permissions_pledge.js")
.args("test --enable-testing-features-do-not-use test/recursive_permissions_pledge.js")
.run();
output.assert_exit_code(1);
assert_contains!(

View file

@ -954,7 +954,7 @@ pub async fn test_specifier(
if ps.options.trace_ops() {
worker.js_runtime.execute_script_static(
located_script_name!(),
"Deno[Deno.internal].core.enableOpCallTracing();",
"Deno[Deno.internal].enableOpCallTracing();",
)?;
}
worker.dispatch_load_event(located_script_name!())?;

View file

@ -453,7 +453,6 @@
BadResourcePrototype,
Interrupted,
InterruptedPrototype,
enableOpCallTracing,
isOpCallTracingEnabled,
opCallTraces,
refOp,
@ -507,8 +506,11 @@
});
ObjectAssign(globalThis.__bootstrap, { core });
const internals = {};
ObjectAssign(globalThis.__bootstrap, { internals });
ObjectAssign(globalThis.__bootstrap, {
internals: {
enableOpCallTracing,
},
});
ObjectAssign(globalThis.Deno, { core });
// Direct bindings on `globalThis`

View file

@ -479,6 +479,26 @@ impl JsRuntime {
}
}
}
// Cache bust plain JS (non-ES modules as well)
#[cfg(feature = "include_js_files_for_snapshotting")]
if snapshot_options != snapshot_util::SnapshotOptions::None {
let js_sources = options
.extensions
.iter()
.flat_map(|ext| match ext.get_js_sources() {
Some(s) => s.to_owned(),
None => vec![],
})
.collect::<Vec<ExtensionFileSource>>();
for source in js_sources {
use crate::ExtensionFileSourceCode;
if let ExtensionFileSourceCode::LoadedFromFsDuringSnapshot(path) =
&source.code
{
println!("cargo:rerun-if-changed={}", path.display())
}
}
}
Rc::new(crate::modules::ExtModuleLoader::new(
options.module_loader,

View file

@ -391,12 +391,6 @@ function promiseRejectMacrotaskCallback() {
let hasBootstrapped = false;
// Set up global properties shared by main and worker runtime.
ObjectDefineProperties(globalThis, windowOrWorkerGlobalScope);
// FIXME(bartlomieju): temporarily add whole `Deno.core` to
// `Deno[Deno.internal]` namespace. It should be removed and only necessary
// methods should be left there.
ObjectAssign(internals, {
core,
});
const internalSymbol = Symbol("Deno.internal");
const finalDenoNs = {
internal: internalSymbol,
@ -428,7 +422,7 @@ function bootstrapMainRuntime(runtimeOptions) {
13: v8Version,
14: userAgent,
15: inspectFlag,
// 16: enableTestingFeaturesFlag
16: enableTestingFeaturesFlag,
} = runtimeOptions;
performance.setTimeOrigin(DateNow());
@ -503,6 +497,12 @@ function bootstrapMainRuntime(runtimeOptions) {
ObjectAssign(finalDenoNs, denoNsUnstable);
}
// Add `Deno[Deno.internal].core` namespace if
// `--enable-testing-features-do-not-use` flag is set.
if (enableTestingFeaturesFlag) {
ObjectAssign(internals, { core });
}
// Setup `Deno` global - we're actually overriding already existing global
// `Deno` with `Deno` namespace from "./deno.ts".
ObjectDefineProperty(globalThis, "Deno", util.readOnly(finalDenoNs));
@ -612,6 +612,11 @@ function bootstrapWorkerRuntime(
noColor: util.readOnly(noColor),
args: util.readOnly(ObjectFreeze(args)),
});
// Add `Deno[Deno.internal].core` namespace if
// `--enable-testing-features-do-not-use` flag is set.
if (enableTestingFeaturesFlag) {
ObjectAssign(internals, { core });
}
// Setup `Deno` global - we're actually overriding already
// existing global `Deno` with `Deno` namespace from "./deno.ts".
ObjectDefineProperty(globalThis, "Deno", util.readOnly(finalDenoNs));

View file

@ -12,6 +12,7 @@ if (import.meta.main) {
const { stdout, stderr, code } = await new Deno.Command(Deno.execPath(), {
args: [
"run",
"--enable-testing-features-do-not-use",
"--allow-read",
"--allow-run",
"--allow-ffi",

View file

@ -31,6 +31,7 @@ fn napi_tests() {
.arg("--allow-env")
.arg("--allow-ffi")
.arg("--allow-run")
.arg("--enable-testing-features-do-not-use")
.spawn()
.unwrap()
.wait_with_output()