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

fix: support npm:bindings and npm:callsites packages #24727

Merged
Merged
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
28 changes: 19 additions & 9 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 @@ -44,7 +44,7 @@ repository = "https://github.com/denoland/deno"

[workspace.dependencies]
deno_ast = { version = "=0.40.0", features = ["transpiling"] }
deno_core = { version = "0.298.0" }
deno_core = { version = "0.299.0" }

deno_bench_util = { version = "0.156.0", path = "./bench_util" }
deno_lockfile = "0.20.0"
Expand Down
3 changes: 1 addition & 2 deletions cli/util/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ mod task_queue;
mod value_creator;

pub use async_flag::AsyncFlag;
pub use deno_core::unsync::sync::AtomicFlag;
pub use sync_read_async_write_lock::SyncReadAsyncWriteLock;
pub use task_queue::TaskQueue;
pub use task_queue::TaskQueuePermit;
pub use value_creator::MultiRuntimeAsyncValueCreator;
// todo(dsherret): this being in the unsync module is slightly confusing, but it's Sync
pub use deno_core::unsync::AtomicFlag;
105 changes: 15 additions & 90 deletions runtime/fmt_errors.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
//! This mod provides DenoError to unify errors across Deno.
use deno_core::error::format_file_name;
use deno_core::error::format_frame;
use deno_core::error::JsError;
use deno_core::error::JsStackFrame;
use deno_terminal::colors::cyan;
use deno_terminal::colors::italic_bold;
use deno_terminal::colors::red;
Expand All @@ -21,96 +20,22 @@ struct IndexedErrorReference<'a> {
index: usize,
}

// Keep in sync with `/core/error.js`.
pub fn format_location(frame: &JsStackFrame) -> String {
let _internal = frame
.file_name
.as_ref()
.map(|f| f.starts_with("ext:"))
.unwrap_or(false);
if frame.is_native {
return cyan("native").to_string();
}
let mut result = String::new();
let file_name = frame.file_name.clone().unwrap_or_default();
if !file_name.is_empty() {
result += &cyan(&format_file_name(&file_name)).to_string();
} else {
if frame.is_eval {
result +=
&(cyan(&frame.eval_origin.as_ref().unwrap()).to_string() + ", ");
}
result += &cyan("<anonymous>").to_string();
}
if let Some(line_number) = frame.line_number {
write!(result, ":{}", yellow(&line_number.to_string())).unwrap();
if let Some(column_number) = frame.column_number {
write!(result, ":{}", yellow(&column_number.to_string())).unwrap();
}
}
result
}

fn format_frame(frame: &JsStackFrame) -> String {
let _internal = frame
.file_name
.as_ref()
.map(|f| f.starts_with("ext:"))
.unwrap_or(false);
let is_method_call =
!(frame.is_top_level.unwrap_or_default() || frame.is_constructor);
let mut result = String::new();
if frame.is_async {
result += "async ";
}
if frame.is_promise_all {
result += &italic_bold(&format!(
"Promise.all (index {})",
frame.promise_index.unwrap_or_default()
))
.to_string();
return result;
}
if is_method_call {
let mut formatted_method = String::new();
if let Some(function_name) = &frame.function_name {
if let Some(type_name) = &frame.type_name {
if !function_name.starts_with(type_name) {
write!(formatted_method, "{type_name}.").unwrap();
}
}
formatted_method += function_name;
if let Some(method_name) = &frame.method_name {
if !function_name.ends_with(method_name) {
write!(formatted_method, " [as {method_name}]").unwrap();
}
}
} else {
if let Some(type_name) = &frame.type_name {
write!(formatted_method, "{type_name}.").unwrap();
struct AnsiColors;

impl deno_core::error::ErrorFormat for AnsiColors {
fn fmt_element(
element: deno_core::error::ErrorElement,
s: &str,
) -> std::borrow::Cow<'_, str> {
use deno_core::error::ErrorElement::*;
match element {
Anonymous | NativeFrame | FileName | EvalOrigin => {
cyan(s).to_string().into()
}
if let Some(method_name) = &frame.method_name {
formatted_method += method_name
} else {
formatted_method += "<anonymous>";
}
}
result += &italic_bold(&formatted_method).to_string();
} else if frame.is_constructor {
result += "new ";
if let Some(function_name) = &frame.function_name {
write!(result, "{}", italic_bold(&function_name)).unwrap();
} else {
result += &cyan("<anonymous>").to_string();
LineNumber | ColumnNumber => yellow(s).to_string().into(),
FunctionName | PromiseAll => italic_bold(s).to_string().into(),
}
} else if let Some(function_name) = &frame.function_name {
result += &italic_bold(&function_name).to_string();
} else {
result += &format_location(frame);
return result;
}
write!(result, " ({})", format_location(frame)).unwrap();
result
}

/// Take an optional source line and associated information to format it into
Expand Down Expand Up @@ -254,7 +179,7 @@ fn format_js_error_inner(
0,
));
for frame in &js_error.frames {
write!(s, "\n at {}", format_frame(frame)).unwrap();
write!(s, "\n at {}", format_frame::<AnsiColors>(frame)).unwrap();
}
if let Some(cause) = &js_error.cause {
let is_caused_by_circular = circular
Expand Down