Skip to content

Commit 5d2d399

Browse files
committed
gate Symbol.dispose generation behind WASM_BINDGEN_SYMBOL_DISPOSE env var, update tests to reflect lack of said var
1 parent 905e636 commit 5d2d399

File tree

8 files changed

+15
-28
lines changed

8 files changed

+15
-28
lines changed

crates/cli-support/src/js/mod.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,15 +1080,20 @@ impl<'a> Context<'a> {
10801080
const ptr = this.__destroy_into_raw();
10811081
wasm.{}(ptr, 0);
10821082
}}
1083-
1084-
[Symbol.dispose]() {{
1085-
this.free();
1086-
}}
10871083
",
10881084
wasm_bindgen_shared::free_function(name),
10891085
));
10901086
ts_dst.push_str(" free(): void;\n");
1091-
ts_dst.push_str(" [Symbol.dispose](): void;\n");
1087+
if self.config.symbol_dispose {
1088+
dst.push_str(
1089+
"
1090+
[Symbol.dispose]() {{
1091+
this.free();
1092+
}}
1093+
",
1094+
);
1095+
ts_dst.push_str(" [Symbol.dispose](): void;\n");
1096+
}
10921097
dst.push_str(&class.contents);
10931098
ts_dst.push_str(&class.typescript);
10941099

@@ -1495,7 +1500,7 @@ impl<'a> Context<'a> {
14951500
if !self.should_write_global("symbol_dispose") {
14961501
return Ok(());
14971502
}
1498-
self.global(&"if(!Symbol.dispose) { Symbol.dispose = Symbol('Symbol.dispose'); }");
1503+
self.global("if(!Symbol.dispose) { Symbol.dispose = Symbol('Symbol.dispose'); }");
14991504
Ok(())
15001505
}
15011506

@@ -2490,7 +2495,7 @@ impl<'a> Context<'a> {
24902495
pub fn generate(&mut self) -> Result<(), Error> {
24912496
self.prestore_global_import_identifiers()?;
24922497
// conditionally override Symbol.dispose
2493-
if !self.aux.structs.is_empty() {
2498+
if self.config.symbol_dispose && !self.aux.structs.is_empty() {
24942499
self.expose_symbol_dispose()?;
24952500
}
24962501
for (id, adapter) in crate::sorted_iter(&self.wit.adapters) {

crates/cli-support/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub struct Bindgen {
4242
multi_value: bool,
4343
encode_into: EncodeInto,
4444
split_linked_modules: bool,
45+
symbol_dispose: bool,
4546
}
4647

4748
pub struct Output {
@@ -88,6 +89,7 @@ impl Bindgen {
8889
let externref =
8990
env::var("WASM_BINDGEN_ANYREF").is_ok() || env::var("WASM_BINDGEN_EXTERNREF").is_ok();
9091
let multi_value = env::var("WASM_BINDGEN_MULTI_VALUE").is_ok();
92+
let symbol_dispose = env::var("WASM_BINDGEN_SYMBOL_DISPOSE").is_ok();
9193
Bindgen {
9294
input: Input::None,
9395
out_name: None,
@@ -109,6 +111,7 @@ impl Bindgen {
109111
encode_into: EncodeInto::Test,
110112
omit_default_module_path: true,
111113
split_linked_modules: false,
114+
symbol_dispose,
112115
}
113116
}
114117

crates/cli/tests/reference/builder.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55
export class ClassBuilder {
66
free(): void;
7-
[Symbol.dispose](): void;
87
/**
98
* @returns {ClassBuilder}
109
*/

crates/cli/tests/reference/builder.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ export function __wbg_set_wasm(val) {
44
}
55

66

7-
if(!Symbol.dispose) { Symbol.dispose = Symbol('Symbol.dispose'); }
8-
97
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
108

119
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
@@ -52,10 +50,6 @@ export class ClassBuilder {
5250
const ptr = this.__destroy_into_raw();
5351
wasm.__wbg_classbuilder_free(ptr, 0);
5452
}
55-
56-
[Symbol.dispose]() {
57-
this.free();
58-
}
5953
/**
6054
* @returns {ClassBuilder}
6155
*/

crates/cli/tests/reference/constructor.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55
export class ClassConstructor {
66
free(): void;
7-
[Symbol.dispose](): void;
87
/**
98
*/
109
constructor();

crates/cli/tests/reference/constructor.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ export function __wbg_set_wasm(val) {
44
}
55

66

7-
if(!Symbol.dispose) { Symbol.dispose = Symbol('Symbol.dispose'); }
8-
97
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
108

119
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
@@ -44,10 +42,6 @@ export class ClassConstructor {
4442
const ptr = this.__destroy_into_raw();
4543
wasm.__wbg_classconstructor_free(ptr, 0);
4644
}
47-
48-
[Symbol.dispose]() {
49-
this.free();
50-
}
5145
/**
5246
*/
5347
constructor() {

crates/cli/tests/reference/raw.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export function test1(test: number): number;
99
*/
1010
export class Test {
1111
free(): void;
12-
[Symbol.dispose](): void;
1312
/**
1413
* @param {number} test
1514
* @returns {Test}

crates/cli/tests/reference/raw.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ export function __wbg_set_wasm(val) {
66
}
77

88

9-
if(!Symbol.dispose) { Symbol.dispose = Symbol('Symbol.dispose'); }
10-
119
const heap = new Array(128).fill(undefined);
1210

1311
heap.push(undefined, null, true, false);
@@ -91,10 +89,6 @@ export class Test {
9189
const ptr = this.__destroy_into_raw();
9290
wasm.__wbg_test_free(ptr, 0);
9391
}
94-
95-
[Symbol.dispose]() {
96-
this.free();
97-
}
9892
/**
9993
* @param {number} test
10094
* @returns {Test}

0 commit comments

Comments
 (0)