1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -05:00

refactor(cli): update to new deno_core promise/call methods (#21519)

This commit is contained in:
Matt Mastracci 2023-12-13 08:07:26 -07:00 committed by GitHub
parent 461ef6bdd8
commit 76a6ea5775
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 60 additions and 71 deletions

19
Cargo.lock generated
View file

@ -681,6 +681,12 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
[[package]]
name = "cooked-waker"
version = "5.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147be55d677052dabc6b22252d5dd0fd4c29c8c27aa4f2fbef0f94aa003b406f"
[[package]]
name = "core-foundation"
version = "0.9.4"
@ -1128,12 +1134,13 @@ dependencies = [
[[package]]
name = "deno_core"
version = "0.237.0"
version = "0.238.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2ea708c221abdb5734e3c4b72075379c3046eb0ac54afa0ecb5e58509cce72c"
checksum = "0ded8b759e4435aa0929913909dd6c482ed6042dae19c53260e1caf9d55b37a9"
dependencies = [
"anyhow",
"bytes",
"cooked-waker",
"deno_ops",
"deno_unsync 0.3.0",
"futures",
@ -1559,9 +1566,9 @@ dependencies = [
[[package]]
name = "deno_ops"
version = "0.113.0"
version = "0.114.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5b9c0f6360795fb625774a8b5955c87c470c43159670cf5d2052df5ce9d84bc"
checksum = "168a929496191fdd8e91f898c8454429df4d5489597777d89f47897f6a37da6b"
dependencies = [
"proc-macro-rules",
"proc-macro2",
@ -5084,9 +5091,9 @@ dependencies = [
[[package]]
name = "serde_v8"
version = "0.146.0"
version = "0.147.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78309bd1ec4d14d165f271e203bdc45ad5bf45525da57bb70901f57942f6c0f7"
checksum = "2af950d83e1c70b762d48fa7a869d6db9a4f191548dfd666fa4e62f2229e1dce"
dependencies = [
"bytes",
"derive_more",

View file

@ -41,7 +41,7 @@ repository = "https://github.com/denoland/deno"
[workspace.dependencies]
deno_ast = { version = "0.31.6", features = ["transpiling"] }
deno_core = { version = "0.237.0" }
deno_core = { version = "0.238.0" }
deno_runtime = { version = "0.135.0", path = "./runtime" }
napi_sym = { version = "0.57.0", path = "./cli/napi/sym" }

View file

@ -3,6 +3,7 @@ use bencher::Bencher;
use deno_core::v8;
use deno_core::Extension;
use deno_core::JsRuntime;
use deno_core::PollEventLoopOptions;
use deno_core::RuntimeOptions;
use crate::profiling::is_profiling;
@ -116,5 +117,8 @@ pub fn bench_js_async_with(
async fn inner_async(src: &'static str, runtime: &mut JsRuntime) {
runtime.execute_script_static("inner_loop", src).unwrap();
runtime.run_event_loop(false).await.unwrap();
runtime
.run_event_loop(PollEventLoopOptions::default())
.await
.unwrap();
}

View file

@ -869,7 +869,11 @@ async fn inspector_break_on_first_line_in_test() {
.await;
assert_starts_with!(&tester.stdout_line(), "running 1 test from");
assert!(&tester.stdout_line().contains("basic test ... ok"));
let line = tester.stdout_line();
assert!(
&line.contains("basic test ... ok"),
"Missing content: {line}"
);
tester.child.kill().unwrap();
tester.child.wait().unwrap();

View file

@ -31,6 +31,7 @@ use deno_core::unsync::spawn;
use deno_core::unsync::spawn_blocking;
use deno_core::v8;
use deno_core::ModuleSpecifier;
use deno_core::PollEventLoopOptions;
use deno_runtime::permissions::Permissions;
use deno_runtime::permissions::PermissionsContainer;
use deno_runtime::tokio_util::create_and_run_current_thread;
@ -254,7 +255,11 @@ async fn bench_specifier_inner(
}))?;
for (desc, function) in benchmarks {
sender.send(BenchEvent::Wait(desc.id))?;
let result = worker.js_runtime.call_and_await(&function).await?;
let call = worker.js_runtime.call(&function);
let result = worker
.js_runtime
.with_event_loop_promise(call, PollEventLoopOptions::default())
.await?;
let scope = &mut worker.js_runtime.handle_scope();
let result = v8::Local::new(scope, result);
let result = serde_v8::from_v8::<BenchResult>(scope, result)?;

View file

@ -202,14 +202,11 @@ impl ReplSession {
worker
.js_runtime
.with_event_loop(
.with_event_loop_future(
session
.post_message::<()>("Runtime.enable", None)
.boxed_local(),
PollEventLoopOptions {
wait_for_inspector: false,
..Default::default()
},
PollEventLoopOptions::default(),
)
.await?;
@ -298,14 +295,14 @@ impl ReplSession {
self
.worker
.js_runtime
.with_event_loop(
.with_event_loop_future(
self.session.post_message(method, params).boxed_local(),
PollEventLoopOptions {
wait_for_inspector: false,
// NOTE(bartlomieju): this is an important bit; we don't want to pump V8
// message loop here, so that GC won't run. Otherwise, the resulting
// object might be GC'ed before we have a chance to inspect it.
pump_v8_message_loop: false,
..Default::default()
},
)
.await

View file

@ -498,12 +498,9 @@ async fn test_specifier_inner(
if let Some(coverage_collector) = coverage_collector.as_mut() {
worker
.js_runtime
.with_event_loop(
.with_event_loop_future(
coverage_collector.stop_collecting().boxed_local(),
PollEventLoopOptions {
wait_for_inspector: false,
..Default::default()
},
PollEventLoopOptions::default(),
)
.await?;
}
@ -574,11 +571,18 @@ pub async fn run_tests_for_worker(
// but haven't responded to settle.
let waker = noop_waker();
let mut cx = Context::from_waker(&waker);
let _ = worker.js_runtime.poll_event_loop(&mut cx, false);
let _ = worker
.js_runtime
.poll_event_loop(&mut cx, PollEventLoopOptions::default());
}
let earlier = SystemTime::now();
let result = match worker.js_runtime.call_and_await(&function).await {
let call = worker.js_runtime.call(&function);
let result = match worker
.js_runtime
.with_event_loop_promise(call, PollEventLoopOptions::default())
.await
{
Ok(r) => r,
Err(error) => {
if error.is::<JsError>() {

View file

@ -211,12 +211,9 @@ impl CliMainWorker {
self
.worker
.js_runtime
.with_event_loop(
.with_event_loop_future(
coverage_collector.stop_collecting().boxed_local(),
PollEventLoopOptions {
wait_for_inspector: false,
..Default::default()
},
PollEventLoopOptions::default(),
)
.await?;
}
@ -224,12 +221,9 @@ impl CliMainWorker {
self
.worker
.js_runtime
.with_event_loop(
.with_event_loop_future(
hmr_runner.stop().boxed_local(),
PollEventLoopOptions {
wait_for_inspector: false,
..Default::default()
},
PollEventLoopOptions::default(),
)
.await?;
}
@ -340,12 +334,9 @@ impl CliMainWorker {
self
.worker
.js_runtime
.with_event_loop(
.with_event_loop_future(
coverage_collector.start_collecting().boxed_local(),
PollEventLoopOptions {
wait_for_inspector: false,
..Default::default()
},
PollEventLoopOptions::default(),
)
.await?;
Ok(Some(coverage_collector))
@ -371,12 +362,9 @@ impl CliMainWorker {
self
.worker
.js_runtime
.with_event_loop(
.with_event_loop_future(
hmr_runner.start().boxed_local(),
PollEventLoopOptions {
wait_for_inspector: false,
..Default::default()
},
PollEventLoopOptions::default(),
)
.await?;

View file

@ -691,7 +691,7 @@ impl WebWorker {
maybe_result
}
event_loop_result = self.js_runtime.run_event_loop(false) => {
event_loop_result = self.js_runtime.run_event_loop(PollEventLoopOptions::default()) => {
event_loop_result?;
receiver.await
}
@ -706,10 +706,7 @@ impl WebWorker {
id: ModuleId,
) -> Result<(), AnyError> {
let mut receiver = self.js_runtime.mod_evaluate(id);
let poll_options = PollEventLoopOptions {
wait_for_inspector: false,
..Default::default()
};
let poll_options = PollEventLoopOptions::default();
tokio::select! {
biased;
@ -741,7 +738,7 @@ impl WebWorker {
self.internal_handle.terminate_waker.register(cx.waker());
match self.js_runtime.poll_event_loop2(cx, poll_options) {
match self.js_runtime.poll_event_loop(cx, poll_options) {
Poll::Ready(r) => {
// If js ended because we are terminating, just return Ok
if self.internal_handle.terminate_if_needed() {

View file

@ -3,8 +3,6 @@ use std::rc::Rc;
use std::sync::atomic::AtomicI32;
use std::sync::atomic::Ordering::Relaxed;
use std::sync::Arc;
use std::task::Context;
use std::task::Poll;
use std::time::Duration;
use std::time::Instant;
@ -561,10 +559,9 @@ impl MainWorker {
) -> Result<(), AnyError> {
match tokio::time::timeout(
duration,
self.js_runtime.run_event_loop2(PollEventLoopOptions {
wait_for_inspector: false,
pump_v8_message_loop: true,
}),
self
.js_runtime
.run_event_loop(PollEventLoopOptions::default()),
)
.await
{
@ -613,27 +610,13 @@ impl MainWorker {
self.js_runtime.inspector().borrow().create_local_session()
}
pub fn poll_event_loop(
&mut self,
cx: &mut Context,
wait_for_inspector: bool,
) -> Poll<Result<(), AnyError>> {
self.js_runtime.poll_event_loop2(
cx,
deno_core::PollEventLoopOptions {
wait_for_inspector,
..Default::default()
},
)
}
pub async fn run_event_loop(
&mut self,
wait_for_inspector: bool,
) -> Result<(), AnyError> {
self
.js_runtime
.run_event_loop2(deno_core::PollEventLoopOptions {
.run_event_loop(deno_core::PollEventLoopOptions {
wait_for_inspector,
..Default::default()
})