Skip to content

Commit b97837b

Browse files
Implement Default for JS types (#2626)
* Add Default impls for WebIDL types with zero-argument constructors * Implement Default for js-sys types where it's appropriate * Implement Default for JsValue * Remove some `Default` impls to better match Rust
1 parent c2f6b00 commit b97837b

File tree

319 files changed

+1738
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

319 files changed

+1738
-1
lines changed

crates/js-sys/src/lib.rs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,12 @@ where
502502
}
503503
}
504504

505+
impl Default for Array {
506+
fn default() -> Self {
507+
Self::new()
508+
}
509+
}
510+
505511
// ArrayBuffer
506512
#[wasm_bindgen]
507513
extern "C" {
@@ -817,6 +823,12 @@ impl fmt::Debug for Boolean {
817823
}
818824
}
819825

826+
impl Default for Boolean {
827+
fn default() -> Self {
828+
Self::from(bool::default())
829+
}
830+
}
831+
820832
// DataView
821833
#[wasm_bindgen]
822834
extern "C" {
@@ -1253,6 +1265,12 @@ impl Function {
12531265
}
12541266
}
12551267

1268+
impl Default for Function {
1269+
fn default() -> Self {
1270+
Self::new_no_args("")
1271+
}
1272+
}
1273+
12561274
// Generator
12571275
#[wasm_bindgen]
12581276
extern "C" {
@@ -1350,6 +1368,12 @@ extern "C" {
13501368
pub fn size(this: &Map) -> u32;
13511369
}
13521370

1371+
impl Default for Map {
1372+
fn default() -> Self {
1373+
Self::new()
1374+
}
1375+
}
1376+
13531377
// Map Iterator
13541378
#[wasm_bindgen]
13551379
extern "C" {
@@ -1982,6 +2006,12 @@ impl fmt::Debug for Number {
19822006
}
19832007
}
19842008

2009+
impl Default for Number {
2010+
fn default() -> Self {
2011+
Self::from(f64::default())
2012+
}
2013+
}
2014+
19852015
// Date.
19862016
#[wasm_bindgen]
19872017
extern "C" {
@@ -2692,6 +2722,12 @@ impl PartialEq for Object {
26922722

26932723
impl Eq for Object {}
26942724

2725+
impl Default for Object {
2726+
fn default() -> Self {
2727+
Self::new()
2728+
}
2729+
}
2730+
26952731
// Proxy
26962732
#[wasm_bindgen]
26972733
extern "C" {
@@ -3162,6 +3198,12 @@ extern "C" {
31623198
pub fn size(this: &Set) -> u32;
31633199
}
31643200

3201+
impl Default for Set {
3202+
fn default() -> Self {
3203+
Self::new(&JsValue::UNDEFINED)
3204+
}
3205+
}
3206+
31653207
// SetIterator
31663208
#[wasm_bindgen]
31673209
extern "C" {
@@ -3294,6 +3336,12 @@ extern "C" {
32943336
pub fn delete(this: &WeakMap, key: &Object) -> bool;
32953337
}
32963338

3339+
impl Default for WeakMap {
3340+
fn default() -> Self {
3341+
Self::new()
3342+
}
3343+
}
3344+
32973345
// WeakSet
32983346
#[wasm_bindgen]
32993347
extern "C" {
@@ -3328,6 +3376,12 @@ extern "C" {
33283376
pub fn delete(this: &WeakSet, value: &Object) -> bool;
33293377
}
33303378

3379+
impl Default for WeakSet {
3380+
fn default() -> Self {
3381+
Self::new()
3382+
}
3383+
}
3384+
33313385
#[allow(non_snake_case)]
33323386
pub mod WebAssembly {
33333387
use super::*;
@@ -4502,6 +4556,15 @@ pub mod Intl {
45024556
pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
45034557
}
45044558

4559+
impl Default for Collator {
4560+
fn default() -> Self {
4561+
Self::new(
4562+
&JsValue::UNDEFINED.unchecked_into(),
4563+
&JsValue::UNDEFINED.unchecked_into(),
4564+
)
4565+
}
4566+
}
4567+
45054568
// Intl.DateTimeFormat
45064569
#[wasm_bindgen]
45074570
extern "C" {
@@ -4553,6 +4616,15 @@ pub mod Intl {
45534616
pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
45544617
}
45554618

4619+
impl Default for DateTimeFormat {
4620+
fn default() -> Self {
4621+
Self::new(
4622+
&JsValue::UNDEFINED.unchecked_into(),
4623+
&JsValue::UNDEFINED.unchecked_into(),
4624+
)
4625+
}
4626+
}
4627+
45564628
// Intl.NumberFormat
45574629
#[wasm_bindgen]
45584630
extern "C" {
@@ -4603,6 +4675,15 @@ pub mod Intl {
46034675
pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
46044676
}
46054677

4678+
impl Default for NumberFormat {
4679+
fn default() -> Self {
4680+
Self::new(
4681+
&JsValue::UNDEFINED.unchecked_into(),
4682+
&JsValue::UNDEFINED.unchecked_into(),
4683+
)
4684+
}
4685+
}
4686+
46064687
// Intl.PluralRules
46074688
#[wasm_bindgen]
46084689
extern "C" {
@@ -4644,6 +4725,15 @@ pub mod Intl {
46444725
#[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf)]
46454726
pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
46464727
}
4728+
4729+
impl Default for PluralRules {
4730+
fn default() -> Self {
4731+
Self::new(
4732+
&JsValue::UNDEFINED.unchecked_into(),
4733+
&JsValue::UNDEFINED.unchecked_into(),
4734+
)
4735+
}
4736+
}
46474737
}
46484738

46494739
// Promise
@@ -5055,6 +5145,12 @@ macro_rules! arrays {
50555145
unsafe { $name::new(&$name::view(slice)) }
50565146
}
50575147
}
5148+
5149+
impl Default for $name {
5150+
fn default() -> Self {
5151+
Self::new(&JsValue::UNDEFINED.unchecked_into())
5152+
}
5153+
}
50585154
)*);
50595155
}
50605156

crates/web-sys/src/features/gen_AddEventListenerOptions.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,8 @@ impl AddEventListenerOptions {
6767
self
6868
}
6969
}
70+
impl Default for AddEventListenerOptions {
71+
fn default() -> Self {
72+
Self::new()
73+
}
74+
}

crates/web-sys/src/features/gen_AnalyserOptions.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,8 @@ impl AnalyserOptions {
141141
self
142142
}
143143
}
144+
impl Default for AnalyserOptions {
145+
fn default() -> Self {
146+
Self::new()
147+
}
148+
}

crates/web-sys/src/features/gen_AnimationEventInit.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,8 @@ impl AnimationEventInit {
122122
self
123123
}
124124
}
125+
impl Default for AnimationEventInit {
126+
fn default() -> Self {
127+
Self::new()
128+
}
129+
}

crates/web-sys/src/features/gen_AnimationPlaybackEventInit.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,8 @@ impl AnimationPlaybackEventInit {
105105
self
106106
}
107107
}
108+
impl Default for AnimationPlaybackEventInit {
109+
fn default() -> Self {
110+
Self::new()
111+
}
112+
}

crates/web-sys/src/features/gen_AssignedNodesOptions.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,8 @@ impl AssignedNodesOptions {
3737
self
3838
}
3939
}
40+
impl Default for AssignedNodesOptions {
41+
fn default() -> Self {
42+
Self::new()
43+
}
44+
}

crates/web-sys/src/features/gen_AudioBufferSourceOptions.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,8 @@ impl AudioBufferSourceOptions {
113113
self
114114
}
115115
}
116+
impl Default for AudioBufferSourceOptions {
117+
fn default() -> Self {
118+
Self::new()
119+
}
120+
}

crates/web-sys/src/features/gen_AudioConfiguration.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,8 @@ impl AudioConfiguration {
8888
self
8989
}
9090
}
91+
impl Default for AudioConfiguration {
92+
fn default() -> Self {
93+
Self::new()
94+
}
95+
}

crates/web-sys/src/features/gen_AudioContextOptions.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,8 @@ impl AudioContextOptions {
3737
self
3838
}
3939
}
40+
impl Default for AudioContextOptions {
41+
fn default() -> Self {
42+
Self::new()
43+
}
44+
}

crates/web-sys/src/features/gen_AudioNodeOptions.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,8 @@ impl AudioNodeOptions {
7373
self
7474
}
7575
}
76+
impl Default for AudioNodeOptions {
77+
fn default() -> Self {
78+
Self::new()
79+
}
80+
}

crates/web-sys/src/features/gen_AudioWorkletNodeOptions.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,8 @@ impl AudioWorkletNodeOptions {
141141
self
142142
}
143143
}
144+
impl Default for AudioWorkletNodeOptions {
145+
fn default() -> Self {
146+
Self::new()
147+
}
148+
}

crates/web-sys/src/features/gen_AuthenticationExtensionsClientInputs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ impl AuthenticationExtensionsClientInputs {
3333
self
3434
}
3535
}
36+
impl Default for AuthenticationExtensionsClientInputs {
37+
fn default() -> Self {
38+
Self::new()
39+
}
40+
}

crates/web-sys/src/features/gen_AuthenticationExtensionsClientOutputs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ impl AuthenticationExtensionsClientOutputs {
3333
self
3434
}
3535
}
36+
impl Default for AuthenticationExtensionsClientOutputs {
37+
fn default() -> Self {
38+
Self::new()
39+
}
40+
}

crates/web-sys/src/features/gen_AuthenticatorSelectionCriteria.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,8 @@ impl AuthenticatorSelectionCriteria {
7373
self
7474
}
7575
}
76+
impl Default for AuthenticatorSelectionCriteria {
77+
fn default() -> Self {
78+
Self::new()
79+
}
80+
}

crates/web-sys/src/features/gen_AutocompleteInfo.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,8 @@ impl AutocompleteInfo {
8888
self
8989
}
9090
}
91+
impl Default for AutocompleteInfo {
92+
fn default() -> Self {
93+
Self::new()
94+
}
95+
}

crates/web-sys/src/features/gen_BaseComputedKeyframe.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,8 @@ impl BaseComputedKeyframe {
100100
self
101101
}
102102
}
103+
impl Default for BaseComputedKeyframe {
104+
fn default() -> Self {
105+
Self::new()
106+
}
107+
}

crates/web-sys/src/features/gen_BaseKeyframe.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,8 @@ impl BaseKeyframe {
8383
self
8484
}
8585
}
86+
impl Default for BaseKeyframe {
87+
fn default() -> Self {
88+
Self::new()
89+
}
90+
}

crates/web-sys/src/features/gen_BasePropertyIndexedKeyframe.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,8 @@ impl BasePropertyIndexedKeyframe {
6565
self
6666
}
6767
}
68+
impl Default for BasePropertyIndexedKeyframe {
69+
fn default() -> Self {
70+
Self::new()
71+
}
72+
}

crates/web-sys/src/features/gen_BasicCardRequest.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,8 @@ impl BasicCardRequest {
5454
self
5555
}
5656
}
57+
impl Default for BasicCardRequest {
58+
fn default() -> Self {
59+
Self::new()
60+
}
61+
}

crates/web-sys/src/features/gen_BiquadFilterOptions.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,8 @@ impl BiquadFilterOptions {
144144
self
145145
}
146146
}
147+
impl Default for BiquadFilterOptions {
148+
fn default() -> Self {
149+
Self::new()
150+
}
151+
}

crates/web-sys/src/features/gen_BlobEventInit.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,8 @@ impl BlobEventInit {
8585
self
8686
}
8787
}
88+
impl Default for BlobEventInit {
89+
fn default() -> Self {
90+
Self::new()
91+
}
92+
}

crates/web-sys/src/features/gen_BlobPropertyBag.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,8 @@ impl BlobPropertyBag {
5151
self
5252
}
5353
}
54+
impl Default for BlobPropertyBag {
55+
fn default() -> Self {
56+
Self::new()
57+
}
58+
}

crates/web-sys/src/features/gen_BlockParsingOptions.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,8 @@ impl BlockParsingOptions {
3737
self
3838
}
3939
}
40+
impl Default for BlockParsingOptions {
41+
fn default() -> Self {
42+
Self::new()
43+
}
44+
}

0 commit comments

Comments
 (0)