Skip to content

Commit e373639

Browse files
authored
feat: WebIDL derive macro (#1003)
- 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
1 parent 0231a18 commit e373639

File tree

27 files changed

+2814
-53
lines changed

27 files changed

+2814
-53
lines changed

Cargo.lock

Lines changed: 14 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ serde_v8 = { version = "0.236.0", path = "./serde_v8" }
2828
deno_ast = { version = "=0.40.0", features = ["transpiling"] }
2929
deno_core_icudata = "0.74.0"
3030
deno_unsync = "0.4.1"
31-
v8 = { version = "130.0.2", default-features = false }
31+
v8 = { version = "130.0.4", default-features = false }
3232

3333
anyhow = "1"
3434
bencher = "0.1"
@@ -40,6 +40,7 @@ cooked-waker = "5"
4040
criterion = "0.5"
4141
fastrand = "2"
4242
futures = "0.3.21"
43+
indexmap = "2.1.0"
4344
libc = "0.2.126"
4445
memoffset = ">=0.9"
4546
num-bigint = { version = "0.4", features = ["rand"] }

core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ deno_core_icudata = { workspace = true, optional = true }
3535
deno_ops.workspace = true
3636
deno_unsync.workspace = true
3737
futures.workspace = true
38-
indexmap = "2.1.0"
38+
indexmap.workspace = true
3939
libc.workspace = true
4040
memoffset.workspace = true
4141
parking_lot.workspace = true

core/error.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,14 @@ impl std::error::Error for CustomError {}
9797
/// If this error was crated with `custom_error()`, return the specified error
9898
/// class name. In all other cases this function returns `None`.
9999
pub fn get_custom_error_class(error: &Error) -> Option<&'static str> {
100-
error.downcast_ref::<CustomError>().map(|e| e.class)
100+
error
101+
.downcast_ref::<CustomError>()
102+
.map(|e| e.class)
103+
.or_else(|| {
104+
error
105+
.downcast_ref::<crate::webidl::WebIdlError>()
106+
.map(|_| "TypeError")
107+
})
101108
}
102109

103110
/// A wrapper around `anyhow::Error` that implements `std::error::Error`

core/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ mod runtime;
3232
mod source_map;
3333
mod tasks;
3434
mod web_timeout;
35+
pub mod webidl;
3536

3637
// Re-exports
3738
pub use anyhow;
39+
pub use deno_ops::op2;
40+
pub use deno_ops::WebIDL;
3841
pub use deno_unsync as unsync;
3942
pub use futures;
4043
pub use parking_lot;
@@ -51,8 +54,6 @@ pub use sourcemap;
5154
pub use url;
5255
pub use v8;
5356

54-
pub use deno_ops::op2;
55-
5657
pub use crate::async_cancel::CancelFuture;
5758
pub use crate::async_cancel::CancelHandle;
5859
pub use crate::async_cancel::CancelTryFuture;

core/runtime/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub mod ops_rust_to_v8;
1010
mod setup;
1111
mod snapshot;
1212
pub mod stats;
13-
pub(crate) mod v8_static_strings;
13+
pub mod v8_static_strings;
1414

1515
#[cfg(all(test, not(miri)))]
1616
mod tests;

core/runtime/v8_static_strings.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2+
#[macro_export]
23
macro_rules! v8_static_strings {
34
($($ident:ident = $str:literal),* $(,)?) => {
45
$(
@@ -7,7 +8,7 @@ macro_rules! v8_static_strings {
78
};
89
}
910

10-
pub(crate) use v8_static_strings;
11+
pub use v8_static_strings;
1112

1213
v8_static_strings!(
1314
BUILD_CUSTOM_ERROR = "buildCustomError",

0 commit comments

Comments
 (0)