From 6d7f557aedd7f4f7f70f1e1d0ba03ce95c7d88b7 Mon Sep 17 00:00:00 2001 From: Bill Budge Date: Tue, 2 Nov 2021 16:36:41 -0700 Subject: [PATCH 1/2] Let the VM convert JS values to the proper floating point type --- src/embind/embind.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/embind/embind.js b/src/embind/embind.js index 4846dfd7c59cd..f5c637ff9a9e4 100644 --- a/src/embind/embind.js +++ b/src/embind/embind.js @@ -641,11 +641,8 @@ var LibraryEmbind = { return value; }, 'toWireType': function(destructors, value) { - // todo: Here we have an opportunity for -O3 level "unsafe" optimizations: we could - // avoid the following if() and assume value is of proper type. - if (typeof value !== "number" && typeof value !== "boolean") { - throw new TypeError('Cannot convert "' + _embind_repr(value) + '" to ' + this.name); - } + // The VM will perform JS to Wasm value conversion, according to the spec: + // https://www.w3.org/TR/wasm-js-api-1/#towebassemblyvalue return value; }, 'argPackAdvance': 8, From 7bcdda4ad0213e97952e05e0341400c5b9c2b842 Mon Sep 17 00:00:00 2001 From: Bill Budge Date: Thu, 4 Nov 2021 11:32:45 -0700 Subject: [PATCH 2/2] Add old code gated by ASSERTIONS. --- src/embind/embind.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/embind/embind.js b/src/embind/embind.js index 822cd4268c340..c6f8c4fa79488 100644 --- a/src/embind/embind.js +++ b/src/embind/embind.js @@ -642,6 +642,11 @@ var LibraryEmbind = { return value; }, 'toWireType': function(destructors, value) { +#if ASSERTIONS + if (typeof value !== "number" && typeof value !== "boolean") { + throw new TypeError('Cannot convert "' + _embind_repr(value) + '" to ' + this.name); + } +#endif // The VM will perform JS to Wasm value conversion, according to the spec: // https://www.w3.org/TR/wasm-js-api-1/#towebassemblyvalue return value;