From f445f2a1fa024ef36a829cae69ac23ef1c8cc692 Mon Sep 17 00:00:00 2001 From: Adam Klein Date: Wed, 4 Sep 2024 10:43:10 -0700 Subject: [PATCH] Fix null-handling for `equals` in test and polyfill Equals specifically allows null inputs. Update the JS API tests and the polyfill to match. --- test/js-api/js-string/basic.tentative.any.js | 4 ++-- test/js-api/js-string/polyfill.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/js-api/js-string/basic.tentative.any.js b/test/js-api/js-string/basic.tentative.any.js index 6275aacd..de4a21c9 100644 --- a/test/js-api/js-string/basic.tentative.any.js +++ b/test/js-api/js-string/basic.tentative.any.js @@ -168,7 +168,7 @@ function assert_throws_if(func, shouldThrow, constructor) { } catch (e) { error = e; } - assert_equals(error !== null, shouldThrow); + assert_equals(error !== null, shouldThrow, "shouldThrow mismatch"); if (shouldThrow && error !== null) { assert_true(error instanceof constructor); } @@ -275,7 +275,7 @@ test(() => { builtinExports['equals'], polyfillExports['equals'], a, a - ), !isString, WebAssembly.RuntimeError); + ), a !== null && !isString, WebAssembly.RuntimeError); assert_throws_if(() => assert_same_behavior( builtinExports['compare'], diff --git a/test/js-api/js-string/polyfill.js b/test/js-api/js-string/polyfill.js index e1823689..7a00d428 100644 --- a/test/js-api/js-string/polyfill.js +++ b/test/js-api/js-string/polyfill.js @@ -155,8 +155,8 @@ this.polyfillImports = { return string.substring(startIndex, endIndex); }, equals: (stringA, stringB) => { - throwIfNotString(stringA); - throwIfNotString(stringB); + if (stringA !== null) throwIfNotString(stringA); + if (stringB !== null) throwIfNotString(stringB); return stringA === stringB; }, compare: (stringA, stringB) => {