summaryrefslogtreecommitdiff
path: root/runtime/web_worker.rs
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2022-04-15 15:08:09 +0100
committerGitHub <noreply@github.com>2022-04-15 16:08:09 +0200
commit8b31fc23cd80de9baa62535e95367da7a21c9cfd (patch)
tree994748bd06ed5b4953929392107b6beaa1c1c337 /runtime/web_worker.rs
parentb4af648c1515a8e79d7a5d1b14d8a4ba9d966a72 (diff)
refactor: Move source map lookups to core (#14274)
The following transformations gradually faced by "JsError" have all been moved up front to "JsError::from_v8_exception()": - finding the first non-"deno:" source line; - moving "JsError::script_resource_name" etc. into the first error stack in case of syntax errors; - source mapping "JsError::script_resource_name" etc. when wrapping the error even though the frame locations are source mapped earlier; - removing "JsError::{script_resource_name,line_number,start_column,end_column}" entirely in favour of "js_error.frames.get(0)". We also no longer pass a js-side callback to "core/02_error.js" from cli. I avoided doing this on previous occasions because the source map lookups were in an awkward place.
Diffstat (limited to 'runtime/web_worker.rs')
-rw-r--r--runtime/web_worker.rs18
1 files changed, 12 insertions, 6 deletions
diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs
index 5d416b935..40b222417 100644
--- a/runtime/web_worker.rs
+++ b/runtime/web_worker.rs
@@ -29,6 +29,7 @@ use deno_core::ModuleLoader;
use deno_core::ModuleSpecifier;
use deno_core::RuntimeOptions;
use deno_core::SharedArrayBufferStore;
+use deno_core::SourceMapGetter;
use deno_tls::rustls::RootCertStore;
use deno_web::create_entangled_message_port;
use deno_web::BlobStore;
@@ -91,12 +92,15 @@ impl Serialize for WorkerControlEvent {
WorkerControlEvent::TerminalError(error)
| WorkerControlEvent::Error(error) => {
let value = match error.downcast_ref::<JsError>() {
- Some(js_error) => json!({
- "message": js_error.exception_message,
- "fileName": js_error.script_resource_name,
- "lineNumber": js_error.line_number,
- "columnNumber": js_error.start_column,
- }),
+ Some(js_error) => {
+ let frame = js_error.frames.first();
+ json!({
+ "message": js_error.exception_message,
+ "fileName": frame.map(|f| f.file_name.as_ref()),
+ "lineNumber": frame.map(|f| f.line_number.as_ref()),
+ "columnNumber": frame.map(|f| f.column_number.as_ref()),
+ })
+ }
None => json!({
"message": error.to_string(),
}),
@@ -320,6 +324,7 @@ pub struct WebWorkerOptions {
pub module_loader: Rc<dyn ModuleLoader>,
pub create_web_worker_cb: Arc<ops::worker_host::CreateWebWorkerCb>,
pub preload_module_cb: Arc<ops::worker_host::PreloadModuleCb>,
+ pub source_map_getter: Option<Box<dyn SourceMapGetter>>,
pub js_error_create_fn: Option<Rc<JsErrorCreateFn>>,
pub use_deno_namespace: bool,
pub worker_type: WebWorkerType,
@@ -436,6 +441,7 @@ impl WebWorker {
let mut js_runtime = JsRuntime::new(RuntimeOptions {
module_loader: Some(options.module_loader.clone()),
startup_snapshot: Some(js::deno_isolate_init()),
+ source_map_getter: options.source_map_getter,
js_error_create_fn: options.js_error_create_fn.clone(),
get_error_class_fn: options.get_error_class_fn,
shared_array_buffer_store: options.shared_array_buffer_store.clone(),