From bc8d00c880756a46b0ce4c8bf0c89407a2de669c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 15 Jan 2024 02:28:46 +0100 Subject: chore: upgrade deno_core to 0.246.0 (#21904) --- runtime/web_worker.rs | 4 ++++ runtime/worker.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) (limited to 'runtime') diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index 11bcd328a..de32e3994 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -6,6 +6,7 @@ use crate::permissions::PermissionsContainer; use crate::shared::runtime; use crate::tokio_util::create_and_run_current_thread; use crate::worker::import_meta_resolve_callback; +use crate::worker::validate_import_attributes_callback; use crate::worker::FormatJsErrorFn; use crate::BootstrapOptions; use deno_broadcast_channel::InMemoryBroadcastChannel; @@ -547,6 +548,9 @@ impl WebWorker { import_meta_resolve_callback: Some(Box::new( import_meta_resolve_callback, )), + validate_import_attributes_cb: Some(Box::new( + validate_import_attributes_callback, + )), ..Default::default() }); diff --git a/runtime/worker.rs b/runtime/worker.rs index 1fac28c6a..2cb1ab491 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -1,4 +1,5 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::collections::HashMap; use std::rc::Rc; use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicI32; @@ -62,6 +63,32 @@ pub fn import_meta_resolve_callback( ) } +// TODO(bartlomieju): temporary measurement until we start supporting more +// module types +pub fn validate_import_attributes_callback( + scope: &mut v8::HandleScope, + attributes: &HashMap, +) { + for (key, value) in attributes { + let msg = if key != "type" { + Some(format!("\"{key}\" attribute is not supported.")) + } else if value != "json" { + Some(format!("\"{value}\" is not a valid module type.")) + } else { + None + }; + + let Some(msg) = msg else { + continue; + }; + + let message = v8::String::new(scope, &msg).unwrap(); + let exception = v8::Exception::type_error(scope, message); + scope.throw_exception(exception); + return; + } +} + #[derive(Clone, Default)] pub struct ExitCode(Arc); @@ -469,6 +496,9 @@ impl MainWorker { import_meta_resolve_callback: Some(Box::new( import_meta_resolve_callback, )), + validate_import_attributes_cb: Some(Box::new( + validate_import_attributes_callback, + )), ..Default::default() }); -- cgit v1.2.3