diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-01-15 02:28:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-14 18:28:46 -0700 |
commit | bc8d00c880756a46b0ce4c8bf0c89407a2de669c (patch) | |
tree | 03f41df566a3f171f9eec2a63e44ec0f5c25057a /runtime/worker.rs | |
parent | 5143b9e7d3f72e6cc23f8381295df17ff1235f53 (diff) |
chore: upgrade deno_core to 0.246.0 (#21904)
Diffstat (limited to 'runtime/worker.rs')
-rw-r--r-- | runtime/worker.rs | 30 |
1 files changed, 30 insertions, 0 deletions
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<String, String>, +) { + 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<AtomicI32>); @@ -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() }); |