Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: don't use deno.core.ops in jupyter,bench,test,lint #27482

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ repository = "https://github.com/denoland/deno"

[workspace.dependencies]
deno_ast = { version = "=0.44.0", features = ["transpiling"] }
deno_core = { version = "0.327.0" }
deno_core = { version = "0.327.0", git = "https://github.com/nathanwhit/deno_core", branch = "execute-virtual-ops-module" }

deno_bench_util = { version = "0.178.0", path = "./bench_util" }
deno_config = { version = "=0.41.0", features = ["workspace", "sync"] }
Expand Down
12 changes: 0 additions & 12 deletions cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,18 +490,6 @@ impl DenoSubcommand {
pub fn is_run(&self) -> bool {
matches!(self, Self::Run(_))
}

// Returns `true` if the subcommand depends on testing infrastructure.
pub fn needs_test(&self) -> bool {
matches!(
self,
Self::Test(_)
| Self::Jupyter(_)
| Self::Repl(_)
| Self::Bench(_)
| Self::Lsp
)
}
}

impl Default for DenoSubcommand {
Expand Down
12 changes: 6 additions & 6 deletions cli/js/40_bench.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// deno-lint-ignore-file

import {
op_bench_get_origin,
op_bench_now,
op_dispatch_bench_event,
op_register_bench,
} from "ext:core/ops";
import { core, primordials } from "ext:core/mod.js";
import {
escapeName,
Expand All @@ -9,12 +15,6 @@ import {
} from "ext:cli/40_test_common.js";
import { Console } from "ext:deno_console/01_console.js";
import { setExitHandler } from "ext:runtime/30_os.js";
const {
op_register_bench,
op_bench_get_origin,
op_dispatch_bench_event,
op_bench_now,
} = core.ops;
const {
ArrayPrototypePush,
Error,
Expand Down
17 changes: 10 additions & 7 deletions cli/js/40_jupyter.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@
* }, { raw: true });
* ```
*/
import { core, internals } from "ext:core/mod.js";
import { internals } from "ext:core/mod.js";
import {
op_base64_encode,
op_jupyter_broadcast,
op_jupyter_input,
} from "ext:core/ops";

const $display = Symbol.for("Jupyter.display");

Expand Down Expand Up @@ -281,12 +286,12 @@ async function format(obj) {
}
if (isJpg(obj)) {
return {
"image/jpeg": core.ops.op_base64_encode(obj),
"image/jpeg": op_base64_encode(obj),
};
}
if (isPng(obj)) {
return {
"image/png": core.ops.op_base64_encode(obj),
"image/png": op_base64_encode(obj),
};
}
if (isSVGElementLike(obj)) {
Expand Down Expand Up @@ -380,11 +385,11 @@ function image(obj) {
}

if (isJpg(obj)) {
return makeDisplayable({ "image/jpeg": core.ops.op_base64_encode(obj) });
return makeDisplayable({ "image/jpeg": op_base64_encode(obj) });
}

if (isPng(obj)) {
return makeDisplayable({ "image/png": core.ops.op_base64_encode(obj) });
return makeDisplayable({ "image/png": op_base64_encode(obj) });
}

throw new TypeError(
Expand Down Expand Up @@ -415,8 +420,6 @@ async function formatInner(obj, raw) {
internals.jupyter = { formatInner };

function enableJupyter() {
const { op_jupyter_broadcast, op_jupyter_input } = core.ops;

function input(
prompt,
password,
Expand Down
8 changes: 4 additions & 4 deletions cli/js/40_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import { core, primordials } from "ext:core/mod.js";
import { escapeName, withPermissions } from "ext:cli/40_test_common.js";

// TODO(mmastrac): We cannot import these from "ext:core/ops" yet
const {
op_register_test_step,
import {
op_register_test,
op_register_test_step,
op_test_event_step_result_failed,
op_test_event_step_result_ignored,
op_test_event_step_result_ok,
op_test_event_step_wait,
op_test_get_origin,
} = core.ops;
} from "ext:core/ops";

const {
ArrayPrototypeFilter,
ArrayPrototypePush,
Expand Down
8 changes: 6 additions & 2 deletions cli/js/40_test_common.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import {
op_pledge_test_permissions,
op_restore_test_permissions,
} from "ext:core/ops";
import { core, primordials } from "ext:core/mod.js";
import { serializePermissions } from "ext:runtime/10_permissions.js";
const ops = core.ops;
Expand Down Expand Up @@ -38,13 +42,13 @@ export function escapeName(name) {
}

export function pledgePermissions(permissions) {
return ops.op_pledge_test_permissions(
return op_pledge_test_permissions(
serializePermissions(permissions),
);
}

export function restorePermissions(token) {
ops.op_restore_test_permissions(token);
op_restore_test_permissions(token);
}

export function withPermissions(fn, permissions) {
Expand Down
1 change: 1 addition & 0 deletions cli/ops/jupyter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use tokio::sync::mpsc;
use crate::tools::jupyter::server::StdinConnectionProxy;

deno_core::extension!(deno_jupyter,
deps = [deno_web],
ops = [
op_jupyter_broadcast,
op_jupyter_input,
Expand Down
2 changes: 1 addition & 1 deletion cli/ops/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ deno_core::extension!(deno_test,
state = |state, options| {
state.put(options.sender);
state.put(TestContainer::default());
},
}
);

#[derive(Clone)]
Expand Down
42 changes: 25 additions & 17 deletions cli/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,24 +643,32 @@ impl CliMainWorkerFactory {
options,
);

if self.shared.subcommand.needs_test() {
macro_rules! test_file {
($($file:literal),*) => {
$(worker.js_runtime.lazy_load_es_module_with_code(
concat!("ext:cli/", $file),
deno_core::ascii_str_include!(concat!("js/", $file)),
)?;)*
}
macro_rules! test_file {
($($file:literal),*) => {
$(worker.js_runtime.lazy_load_es_module_with_code(
concat!("ext:cli/", $file),
deno_core::ascii_str_include!(concat!("js/", $file)),
)?;)*
}
}
match &self.shared.subcommand {
DenoSubcommand::Test(_) => {
test_file!("40_test_common.js", "40_test.js");
}
DenoSubcommand::Bench(_) => {
test_file!("40_test_common.js", "40_bench.js");
}
DenoSubcommand::Jupyter(_) => {
test_file!("40_test_common.js", "40_test.js", "40_jupyter.js");
}

DenoSubcommand::Repl(_) => {
test_file!("40_test_common.js", "40_test.js");
}
DenoSubcommand::Lint(_) => {
test_file!("40_lint_selector.js", "40_lint.js");
}
test_file!(
"40_test_common.js",
"40_test.js",
"40_bench.js",
"40_jupyter.js",
// TODO(bartlomieju): probably shouldn't include these files here?
"40_lint_selector.js",
"40_lint.js"
);
_ => {}
}

Ok(CliMainWorker {
Expand Down
36 changes: 18 additions & 18 deletions runtime/js/99_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,33 +515,33 @@ function shimTemporalDurationToLocaleString() {
// "virtual op module" (`ext:core/ops`).
const NOT_IMPORTED_OPS = [
// Related to `Deno.bench()` API
"op_bench_now",
"op_dispatch_bench_event",
"op_register_bench",
"op_bench_get_origin",
// "op_bench_now",
// "op_dispatch_bench_event",
// "op_register_bench",
// "op_bench_get_origin",

// Related to `Deno.jupyter` API
"op_jupyter_broadcast",
"op_jupyter_input",
// "op_jupyter_broadcast",
// "op_jupyter_input",
// Used in jupyter API
"op_base64_encode",

// Used in the lint API
"op_lint_create_serialized_ast",

// Related to `Deno.test()` API
"op_test_event_step_result_failed",
"op_test_event_step_result_ignored",
"op_test_event_step_result_ok",
"op_test_event_step_wait",
"op_test_op_sanitizer_collect",
"op_test_op_sanitizer_finish",
"op_test_op_sanitizer_get_async_message",
"op_test_op_sanitizer_report",
"op_restore_test_permissions",
"op_register_test_step",
"op_register_test",
"op_test_get_origin",
// "op_test_event_step_result_failed",
// "op_test_event_step_result_ignored",
// "op_test_event_step_result_ok",
// "op_test_event_step_wait",
// "op_test_op_sanitizer_collect",
// "op_test_op_sanitizer_finish",
// "op_test_op_sanitizer_get_async_message",
// "op_test_op_sanitizer_report",
// "op_restore_test_permissions",
// "op_register_test_step",
// "op_register_test",
// "op_test_get_origin",
"op_pledge_test_permissions",

// TODO(bartlomieju): used in various integration tests - figure out a way
Expand Down
Loading
Loading