Skip to content

Commit

Permalink
feat: WebIDL derive macro (#1003)
Browse files Browse the repository at this point in the history
- adds a `WebIdlConverter` trait
  - implemented for Vec, to have sequence converters
  - implemented for Option, to have nullable converters
  - implemented for HashMap, to have record converters
  - implemented for integers
- implemented for floats, and creates `Unrestricted` structs for
unrestricted float and unrestricted double
  - implemented for booleans
  - implemented for string
  - creates new `ByteString` struct for bytestring conversion
  - creates new `BigInt` struct for bigint conversion
- adds a `WebIDL` derive macro, current only allowed on structs as a
dictionary converter and on enums as enum converters
  • Loading branch information
crowlKats authored Jan 2, 2025
1 parent 0231a18 commit e373639
Show file tree
Hide file tree
Showing 27 changed files with 2,814 additions and 53 deletions.
21 changes: 14 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ serde_v8 = { version = "0.236.0", path = "./serde_v8" }
deno_ast = { version = "=0.40.0", features = ["transpiling"] }
deno_core_icudata = "0.74.0"
deno_unsync = "0.4.1"
v8 = { version = "130.0.2", default-features = false }
v8 = { version = "130.0.4", default-features = false }

anyhow = "1"
bencher = "0.1"
Expand All @@ -40,6 +40,7 @@ cooked-waker = "5"
criterion = "0.5"
fastrand = "2"
futures = "0.3.21"
indexmap = "2.1.0"
libc = "0.2.126"
memoffset = ">=0.9"
num-bigint = { version = "0.4", features = ["rand"] }
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ deno_core_icudata = { workspace = true, optional = true }
deno_ops.workspace = true
deno_unsync.workspace = true
futures.workspace = true
indexmap = "2.1.0"
indexmap.workspace = true
libc.workspace = true
memoffset.workspace = true
parking_lot.workspace = true
Expand Down
9 changes: 8 additions & 1 deletion core/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,14 @@ impl std::error::Error for CustomError {}
/// If this error was crated with `custom_error()`, return the specified error
/// class name. In all other cases this function returns `None`.
pub fn get_custom_error_class(error: &Error) -> Option<&'static str> {
error.downcast_ref::<CustomError>().map(|e| e.class)
error
.downcast_ref::<CustomError>()
.map(|e| e.class)
.or_else(|| {
error
.downcast_ref::<crate::webidl::WebIdlError>()
.map(|_| "TypeError")
})
}

/// A wrapper around `anyhow::Error` that implements `std::error::Error`
Expand Down
5 changes: 3 additions & 2 deletions core/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ mod runtime;
mod source_map;
mod tasks;
mod web_timeout;
pub mod webidl;

// Re-exports
pub use anyhow;
pub use deno_ops::op2;
pub use deno_ops::WebIDL;
pub use deno_unsync as unsync;
pub use futures;
pub use parking_lot;
Expand All @@ -51,8 +54,6 @@ pub use sourcemap;
pub use url;
pub use v8;

pub use deno_ops::op2;

pub use crate::async_cancel::CancelFuture;
pub use crate::async_cancel::CancelHandle;
pub use crate::async_cancel::CancelTryFuture;
Expand Down
2 changes: 1 addition & 1 deletion core/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub mod ops_rust_to_v8;
mod setup;
mod snapshot;
pub mod stats;
pub(crate) mod v8_static_strings;
pub mod v8_static_strings;

#[cfg(all(test, not(miri)))]
mod tests;
Expand Down
3 changes: 2 additions & 1 deletion core/runtime/v8_static_strings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
#[macro_export]
macro_rules! v8_static_strings {
($($ident:ident = $str:literal),* $(,)?) => {
$(
Expand All @@ -7,7 +8,7 @@ macro_rules! v8_static_strings {
};
}

pub(crate) use v8_static_strings;
pub use v8_static_strings;

v8_static_strings!(
BUILD_CUSTOM_ERROR = "buildCustomError",
Expand Down
Loading

0 comments on commit e373639

Please sign in to comment.