diff --git a/Meta/import-v8-regexp-tests.py b/Meta/import-v8-regexp-tests.py index f01f16ba1c..3c5387cea4 100644 --- a/Meta/import-v8-regexp-tests.py +++ b/Meta/import-v8-regexp-tests.py @@ -19,6 +19,9 @@ V8_COMPAT_SHIM = """\ function assertEquals(expected, actual, msg) { if (Array.isArray(expected) && Array.isArray(actual)) { expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { + expect(actual.source).toBe(expected.source); + expect(actual.flags).toBe(expected.flags); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -43,11 +46,19 @@ function assertNotNull(val, msg) { } function assertThrows(fn, type_opt, msg_opt) { - expect(fn).toThrow(); + if (typeof fn === "string") { + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); + } } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { @@ -90,8 +101,11 @@ SKIP_FILES = { # parse errors in other engines. "regexp-14098.js", "regexp-444637793.js", - # Uses regex literal syntax that triggers parse errors in our engine. - "regexp-unicode-sets.js", + # Tests V8-specific error message wording ("incompatible receiver"), we correctly throw but use different message. + "es6/regexp-tostring.js", + # Tests V8's non-i18n build behavior. Spec-compliant engines (including ours) behave differently - we correctly + # case-fold all cases. + "es6/unicode-regexp-ignore-case-noi18n.js", # Multi-file dependency (lu-ui0..9 depend on testCodePointRange from lu-ui). "harmony/regexp-property-lu-ui0.js", "harmony/regexp-property-lu-ui1.js", @@ -106,37 +120,11 @@ SKIP_FILES = { } # Tests that crash or hang -- use test.skip() so they don't block the suite. -SKIP_TESTS = { - # Hangs: catastrophic backtracking tests that rely on V8-specific - # optimizations to terminate in reasonable time. - "regexp-capture-3", - # Crashes (SIGSEGV). - "regexp-capture", -} +SKIP_TESTS = {} # Tests that fail but should be tracked -- use test.xfail() so we notice # when they start passing. -XFAIL_TESTS = { - "es6/regexp-constructor", - "es6/regexp-tostring", - "es6/unicode-escapes-in-regexps", - "es6/unicode-regexp-backrefs", - "es6/unicode-regexp-ignore-case-noi18n", - "es6/unicode-regexp-restricted-syntax", - "es6/unicode-regexp-zero-length", - "regexp-duplicate-named-groups", - "regexp-lookahead", - "regexp-multiline", - "regexp-sort", - "regexp-UC16", - "harmony/regexp-property-binary", - "harmony/regexp-property-char-class", - "harmony/regexp-property-enumerated", - "harmony/regexp-property-exact-match", - "harmony/regexp-property-general-category", - "harmony/regexp-property-invalid", - "harmony/regexp-property-special", -} +XFAIL_TESTS = {} def should_skip(content): diff --git a/Tests/LibJS/Runtime/3rdparty/v8/es6/array-concat-spreadable-regexp.js b/Tests/LibJS/Runtime/3rdparty/v8/es6/array-concat-spreadable-regexp.js index 39688bcd92..6cc3abe321 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/es6/array-concat-spreadable-regexp.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/es6/array-concat-spreadable-regexp.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-constructor.js b/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-constructor.js index c66d15b504..cb6f4c85a4 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-constructor.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-constructor.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-flags.js b/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-flags.js index d143871b49..69f6ffaf84 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-flags.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-flags.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-match-lastindex.js b/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-match-lastindex.js index 3fe08ce967..f5fdd21974 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-match-lastindex.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-match-lastindex.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-prototype.js b/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-prototype.js index f7b49ef014..66202a8825 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-prototype.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-prototype.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-replace-lastindex.js b/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-replace-lastindex.js index df0b20933b..efaba004a5 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-replace-lastindex.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-replace-lastindex.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-sticky.js b/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-sticky.js index ab4a03258f..32d6e90fa6 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-sticky.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-sticky.js @@ -28,11 +28,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -58,17 +58,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-tolength.js b/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-tolength.js index 1d53754f94..317c9fc3d9 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-tolength.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-tolength.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-tostring.js b/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-tostring.js deleted file mode 100644 index 19fb6bf73d..0000000000 --- a/Tests/LibJS/Runtime/3rdparty/v8/es6/regexp-tostring.js +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright 2016 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// V8 assertion compatibility shim for Ladybird's test-js harness - -function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { - expect(actual.source).toBe(expected.source); - expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); - } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { - expect(actual).toEqual(expected); - } else { - expect(actual).toBe(expected); - } -} - -function assertTrue(val, msg) { - expect(val).toBeTrue(); -} - -function assertFalse(val, msg) { - expect(val).toBeFalse(); -} - -function assertNull(val, msg) { - expect(val).toBeNull(); -} - -function assertNotNull(val, msg) { - expect(val).not.toBeNull(); -} - -function assertThrows(fn, type_opt, msg_opt) { - if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } - expect(fn).toThrow(); -} - -function assertDoesNotThrow(fn, msg) { - fn(); -} - -function assertInstanceof(val, type, msg) { - expect(val instanceof type).toBeTrue(); -} - -function assertUnreachable(msg) { - expect().fail("unreachable" + (msg ? ": " + msg : "")); -} - -function assertEarlyError(code) { - assertThrows(() => new Function(code)); -} - -function assertThrowsAtRuntime(code, type_opt) { - const f = new Function(code); - assertThrows(f, type_opt); -} - -function assertArrayEquals(expected, actual) { - expect(actual).toEqual(expected); -} - -test.xfail("es6/regexp-tostring", () => { - var log = []; - - var fake = { - get source() { - log.push("p"); - return { - toString: function () { - log.push("ps"); - return "pattern"; - }, - }; - }, - get flags() { - log.push("f"); - return { - toString: function () { - log.push("fs"); - return "flags"; - }, - }; - }, - }; - - function testThrows(x) { - try { - RegExp.prototype.toString.call(x); - } catch (e) { - assertTrue(/incompatible receiver/.test(e.message)); - return; - } - assertUnreachable(); - } - - testThrows(1); - testThrows(null); - Number.prototype.source = "a"; - Number.prototype.flags = "b"; - testThrows(1); - - assertEquals("/pattern/flags", RegExp.prototype.toString.call(fake)); - assertEquals(["p", "ps", "f", "fs"], log); - - // Monkey-patching is also possible on RegExp instances - - let weird = /foo/; - Object.defineProperty(weird, "flags", { value: "bar" }); - Object.defineProperty(weird, "source", { value: "baz" }); - assertEquals("/baz/bar", weird.toString()); - - assertEquals("/(?:)/", RegExp.prototype.toString()); - assertEquals("(?:)", RegExp.prototype.source); - assertEquals("", RegExp.prototype.flags); -}); diff --git a/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-escapes-in-regexps.js b/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-escapes-in-regexps.js index d67e33513f..9d9e0a3ed8 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-escapes-in-regexps.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-escapes-in-regexps.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-backrefs.js b/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-backrefs.js index 1a309fa18e..e90dd9bf89 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-backrefs.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-backrefs.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-ignore-case-noi18n.js b/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-ignore-case-noi18n.js deleted file mode 100644 index f1bc82fe51..0000000000 --- a/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-ignore-case-noi18n.js +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright 2016 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// V8 assertion compatibility shim for Ladybird's test-js harness - -function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { - expect(actual.source).toBe(expected.source); - expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); - } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { - expect(actual).toEqual(expected); - } else { - expect(actual).toBe(expected); - } -} - -function assertTrue(val, msg) { - expect(val).toBeTrue(); -} - -function assertFalse(val, msg) { - expect(val).toBeFalse(); -} - -function assertNull(val, msg) { - expect(val).toBeNull(); -} - -function assertNotNull(val, msg) { - expect(val).not.toBeNull(); -} - -function assertThrows(fn, type_opt, msg_opt) { - if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } - expect(fn).toThrow(); -} - -function assertDoesNotThrow(fn, msg) { - fn(); -} - -function assertInstanceof(val, type, msg) { - expect(val instanceof type).toBeTrue(); -} - -function assertUnreachable(msg) { - expect().fail("unreachable" + (msg ? ": " + msg : "")); -} - -function assertEarlyError(code) { - assertThrows(() => new Function(code)); -} - -function assertThrowsAtRuntime(code, type_opt) { - const f = new Function(code); - assertThrows(f, type_opt); -} - -function assertArrayEquals(expected, actual) { - expect(actual).toEqual(expected); -} - -test.xfail("es6/unicode-regexp-ignore-case-noi18n", () => { - assertTrue(/[a]/iu.test("\u{20a0}a")); - assertTrue(/[a]/iu.test("\u{20a0}A")); - assertTrue(/[A]/iu.test("\u{20a0}a")); - assertTrue(/[A]/iu.test("\u{20a0}A")); - - // Non-unicode use toUpperCase mappings. - assertFalse(/[\u00e5]/i.test("\u212b")); - assertFalse(/[\u212b]/i.test("\u00e5\u1234")); - assertFalse(/[\u212b]/i.test("\u00e5")); - - assertTrue("\u212b".toLowerCase() == "\u00e5"); - assertTrue("\u00c5".toLowerCase() == "\u00e5"); - assertTrue("\u00e5".toUpperCase() == "\u00c5"); - - // Unicode uses case folding mappings. - assertFalse(/\u00e5/iu.test("\u212b")); - assertTrue(/\u00e5/iu.test("\u00c5")); - assertTrue(/\u00e5/iu.test("\u00e5")); - assertFalse(/\u00e5/iu.test("\u212b")); - assertTrue(/\u00c5/iu.test("\u00e5")); - assertFalse(/\u00c5/iu.test("\u212b")); - assertTrue(/\u00c5/iu.test("\u00c5")); - assertFalse(/\u212b/iu.test("\u00c5")); - assertFalse(/\u212b/iu.test("\u00e5")); - assertTrue(/\u212b/iu.test("\u212b")); - - // Non-BMP. - assertFalse(/\u{10400}/i.test("\u{10428}")); - assertFalse(/\u{10400}/iu.test("\u{10428}")); - assertFalse(/\ud801\udc00/iu.test("\u{10428}")); - assertFalse(/[\u{10428}]/iu.test("\u{10400}")); - assertFalse(/[\ud801\udc28]/iu.test("\u{10400}")); - assertEquals(["\uff21\u{10400}"], /[\uff40-\u{10428}]+/iu.exec("\uff21\u{10400}abc")); - - // TODO(v8:10120): Investigate why these don't behave as expected. - { - // Should be: - // assertEquals(["abc"], /[^\uff40-\u{10428}]+/ui.exec("\uff21\u{10400}abc\uff23")); - // - // But is: - assertEquals(["\u{ff21}"], /[^\uff40-\u{10428}]+/iu.exec("\uff21\u{10400}abc\uff23")); - } - - assertEquals(["\uff53\u24bb"], /[\u24d5-\uff33]+/iu.exec("\uff54\uff53\u24bb\u24ba")); - - // Full mappings are ignored. - assertFalse(/\u00df/iu.test("SS")); - assertFalse(/\u1f8d/iu.test("\u1f05\u03b9")); - - // Simple mappings. - assertFalse(/\u1f8d/iu.test("\u1f85")); - - // Common mappings. - assertTrue(/\u1f6b/iu.test("\u1f63")); - - // Back references. - assertNull(/(.)\1\1/iu.exec("\u00e5\u212b\u00c5")); - assertNull(/(.)\1/iu.exec("\u{118aa}\u{118ca}")); - - // Non-Latin1 maps to Latin1. - assertNull(/^\u017F/iu.exec("s")); - assertNull(/^\u017F/iu.exec("s\u1234")); - assertNull(/^a[\u017F]/iu.exec("as")); - assertNull(/^a[\u017F]/iu.exec("as\u1234")); -}); diff --git a/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-ignore-case.js b/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-ignore-case.js index 37efb2b611..351aef0a8e 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-ignore-case.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-ignore-case.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-last-index.js b/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-last-index.js index ab32a100b4..67e88b1ef3 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-last-index.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-last-index.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-restricted-syntax.js b/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-restricted-syntax.js index 46ad097ea9..a135edcc16 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-restricted-syntax.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-restricted-syntax.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-unanchored-advance.js b/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-unanchored-advance.js index 10537e4802..9b594a9bbc 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-unanchored-advance.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-unanchored-advance.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-zero-length.js b/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-zero-length.js index 303df0025e..a53786787b 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-zero-length.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/es6/unicode-regexp-zero-length.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-change-exec.js b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-change-exec.js index da11cd5f2f..6c5aee4912 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-change-exec.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-change-exec.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-dotall.js b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-dotall.js index 8b0653351c..db7263369d 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-dotall.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-dotall.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-binary.js b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-binary.js index c0137e4f33..73396d2ed1 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-binary.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-binary.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-char-class.js b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-char-class.js index ac3b5dd4fa..8421ee6a3e 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-char-class.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-char-class.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-enumerated.js b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-enumerated.js index a28e48cefd..6de456a3ea 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-enumerated.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-enumerated.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { @@ -69,7 +70,7 @@ function assertArrayEquals(expected, actual) { expect(actual).toEqual(expected); } -test.xfail("harmony/regexp-property-enumerated", () => { +test("harmony/regexp-property-enumerated", () => { assertThrows("/\\p{Bidi_Class=L}+/u"); assertThrows("/\\p{bc=Left_To_Right}+/u"); assertThrows("/\\p{bc=AL}+/u"); diff --git a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-exact-match.js b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-exact-match.js index 9b826f9752..7b35834c80 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-exact-match.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-exact-match.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { @@ -69,7 +70,7 @@ function assertArrayEquals(expected, actual) { expect(actual).toEqual(expected); } -test.xfail("harmony/regexp-property-exact-match", () => { +test("harmony/regexp-property-exact-match", () => { assertThrows("/\\p{In CJK}/u"); assertThrows("/\\p{InCJKUnifiedIdeographs}/u"); assertThrows("/\\p{InCJK}/u"); diff --git a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-general-category.js b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-general-category.js index 7101051ffb..3fbcd0f4fd 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-general-category.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-general-category.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-invalid.js b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-invalid.js index 48389dde83..f8b905acb5 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-invalid.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-invalid.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-lu-ui.js b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-lu-ui.js index f96f1c7a89..eecca9e806 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-lu-ui.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-lu-ui.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-script-extensions.js b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-script-extensions.js index 8a235ddf85..f0c82b7399 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-script-extensions.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-script-extensions.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-scripts.js b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-scripts.js index 69bf60f4c8..5ad114fcbc 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-scripts.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-scripts.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-special.js b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-special.js index e70c0516a7..459a6a0047 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-special.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/harmony/regexp-property-special.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,17 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - fn = new Function(fn); - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-UC16.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-UC16.js index b20a5180f3..e4f3406099 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-UC16.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-UC16.js @@ -28,11 +28,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -58,32 +58,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-boyer-moore.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-boyer-moore.js index 5f4fbdf262..e6a1ceaee6 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-boyer-moore.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-boyer-moore.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,32 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-cache-replace.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-cache-replace.js index e326d95577..129a1f5250 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-cache-replace.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-cache-replace.js @@ -28,11 +28,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -58,32 +58,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-call-as-function.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-call-as-function.js index 34991b93cd..57b426e2be 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-call-as-function.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-call-as-function.js @@ -28,11 +28,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -58,32 +58,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-capture-3.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-capture-3.js index 667199f470..86cab72e3f 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-capture-3.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-capture-3.js @@ -28,11 +28,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -58,32 +58,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { @@ -107,7 +93,7 @@ function assertArrayEquals(expected, actual) { expect(actual).toEqual(expected); } -test.skip("regexp-capture-3", () => { +test("regexp-capture-3", () => { function oneMatch(re) { "abcd".replace(re, function () {}); assertEquals("abcd", RegExp.input); diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-capture-4.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-capture-4.js index 055cb7cf81..50bb6f5e2d 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-capture-4.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-capture-4.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,32 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-capture.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-capture.js index 150be4499d..f66a366918 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-capture.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-capture.js @@ -28,11 +28,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -58,32 +58,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { @@ -107,7 +93,7 @@ function assertArrayEquals(expected, actual) { expect(actual).toEqual(expected); } -test.skip("regexp-capture", () => { +test("regexp-capture", () => { assertEquals(true, /(x)?\1y/.test("y")); assertEquals(["y", undefined], /(x)?\1y/.exec("y")); assertEquals(["y", undefined], /(x)?y/.exec("y")); diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-captures.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-captures.js index e5ea61648f..d76002ea72 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-captures.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-captures.js @@ -28,11 +28,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -58,32 +58,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-compile.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-compile.js index 19e51d5133..f5d5d34e80 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-compile.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-compile.js @@ -28,11 +28,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -58,32 +58,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-duplicate-named-groups.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-duplicate-named-groups.js index 682976c68c..b83fa824fa 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-duplicate-named-groups.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-duplicate-named-groups.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,32 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-global.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-global.js index f67dbdae4c..5c9504db80 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-global.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-global.js @@ -28,11 +28,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -58,32 +58,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-indexof.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-indexof.js index 3fc2adcd3a..9b8a342000 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-indexof.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-indexof.js @@ -28,11 +28,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -58,32 +58,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-lastIndex.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-lastIndex.js index 35d8e79090..8a63fa8093 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-lastIndex.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-lastIndex.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,32 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-lookahead.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-lookahead.js index b280eb15b6..e617e79324 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-lookahead.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-lookahead.js @@ -28,11 +28,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -58,32 +58,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-loop-capture.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-loop-capture.js index c28bdcc111..3bd2ee5205 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-loop-capture.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-loop-capture.js @@ -28,11 +28,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -58,32 +58,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-modifiers.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-modifiers.js index 6177f8f318..9b52e431d9 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-modifiers.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-modifiers.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,32 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-multiline.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-multiline.js index baa20c7240..3ff92c580b 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-multiline.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-multiline.js @@ -28,11 +28,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -58,32 +58,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-exec.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-exec.js index 0b9d3639df..7c6cf7f9f4 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-exec.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-exec.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,32 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-symbol-match-all.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-symbol-match-all.js index de51a3c2b0..2cd786a80f 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-symbol-match-all.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-symbol-match-all.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,32 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-symbol-match.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-symbol-match.js index b2de6af740..d60109dff7 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-symbol-match.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-symbol-match.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,32 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-symbol-replace.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-symbol-replace.js index ddd443bf9d..6ff584fa2e 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-symbol-replace.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-symbol-replace.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,32 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-symbol-search.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-symbol-search.js index 00154b15b2..019d3c9020 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-symbol-search.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-symbol-search.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,32 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-symbol-split.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-symbol-split.js index 634f85d478..dc47d11518 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-symbol-split.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-override-symbol-split.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,32 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-peephole.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-peephole.js index 15254ba829..a7b8212695 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-peephole.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-peephole.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,32 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-regexpexec.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-regexpexec.js index ba2ea98048..6c596eff88 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-regexpexec.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-regexpexec.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,32 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-results-cache.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-results-cache.js index d406920a8c..810e003300 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-results-cache.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-results-cache.js @@ -28,11 +28,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -58,32 +58,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-sort.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-sort.js index 27ff6f74c3..c8d5f291e6 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-sort.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-sort.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,32 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-stack-overflow.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-stack-overflow.js index e8724780a8..8831255ca4 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-stack-overflow.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-stack-overflow.js @@ -5,11 +5,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -35,32 +35,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-standalones.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-standalones.js index 8ce635d735..97626113bc 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-standalones.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-standalones.js @@ -28,11 +28,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -58,32 +58,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-static.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-static.js index 8128a88c1c..a3e8e58f99 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-static.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-static.js @@ -28,11 +28,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -58,32 +58,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-string-methods.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-string-methods.js index 1c6298ff90..0bc3071dc5 100644 --- a/Tests/LibJS/Runtime/3rdparty/v8/regexp-string-methods.js +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-string-methods.js @@ -28,11 +28,11 @@ // V8 assertion compatibility shim for Ladybird's test-js harness function assertEquals(expected, actual, msg) { - if (expected instanceof RegExp && actual instanceof RegExp) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { expect(actual.source).toBe(expected.source); expect(actual.flags).toBe(expected.flags); - } else if (Array.isArray(expected) && Array.isArray(actual)) { - expect(actual).toEqual(expected); } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { expect(actual).toEqual(expected); } else { @@ -58,32 +58,18 @@ function assertNotNull(val, msg) { function assertThrows(fn, type_opt, msg_opt) { if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); } - if (typeof fn === "string") { - try { - try { - fn = new Function(fn); - } catch (e) { - return; - } - } catch (e) { - return; - } - } - expect(fn).toThrow(); } function assertDoesNotThrow(fn, msg) { - fn(); + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } } function assertInstanceof(val, type, msg) { diff --git a/Tests/LibJS/Runtime/3rdparty/v8/regexp-unicode-sets.js b/Tests/LibJS/Runtime/3rdparty/v8/regexp-unicode-sets.js new file mode 100644 index 0000000000..b2298be90c --- /dev/null +++ b/Tests/LibJS/Runtime/3rdparty/v8/regexp-unicode-sets.js @@ -0,0 +1,323 @@ +// Copyright 2022 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// V8 assertion compatibility shim for Ladybird's test-js harness + +function assertEquals(expected, actual, msg) { + if (Array.isArray(expected) && Array.isArray(actual)) { + expect(actual).toEqual(expected); + } else if (expected instanceof RegExp && actual instanceof RegExp) { + expect(actual.source).toBe(expected.source); + expect(actual.flags).toBe(expected.flags); + } else if (expected !== null && typeof expected === "object" && actual !== null && typeof actual === "object") { + expect(actual).toEqual(expected); + } else { + expect(actual).toBe(expected); + } +} + +function assertTrue(val, msg) { + expect(val).toBeTrue(); +} + +function assertFalse(val, msg) { + expect(val).toBeFalse(); +} + +function assertNull(val, msg) { + expect(val).toBeNull(); +} + +function assertNotNull(val, msg) { + expect(val).not.toBeNull(); +} + +function assertThrows(fn, type_opt, msg_opt) { + if (typeof fn === "string") { + expect(() => eval(fn)).toThrow(); + } else { + expect(fn).toThrow(); + } +} + +function assertDoesNotThrow(fn, msg) { + if (typeof fn === "string") { + eval(fn); + } else { + fn(); + } +} + +function assertInstanceof(val, type, msg) { + expect(val instanceof type).toBeTrue(); +} + +function assertUnreachable(msg) { + expect().fail("unreachable" + (msg ? ": " + msg : "")); +} + +function assertEarlyError(code) { + assertThrows(() => new Function(code)); +} + +function assertThrowsAtRuntime(code, type_opt) { + const f = new Function(code); + assertThrows(f, type_opt); +} + +function assertArrayEquals(expected, actual) { + expect(actual).toEqual(expected); +} + +test("regexp-unicode-sets", () => { + assertEarlyError("/./uv"); + assertThrowsAtRuntime("new RegExp('.','uv')", SyntaxError); + + assertEquals("v", /./v.flags); + assertTrue(/./v.unicodeSets); + + // Characters that require escaping within a character class in /v mode + assertEarlyError("/[(]/v"); + assertEarlyError("/[)]/v"); + assertEarlyError("/[[]/v"); + assertEarlyError("/[]]/v"); + assertEarlyError("/[{]/v"); + assertEarlyError("/[}]/v"); + assertEarlyError("/[/]/v"); + assertEarlyError("/[-]/v"); + // Need to escape the backslash, as assertEarlyError uses eval(). + assertEarlyError("/[\\]/v"); + assertEarlyError("/[|]/v"); + + assertEarlyError("/[&&]/v"); + assertEarlyError("/[!!]/v"); + assertEarlyError("/[##]/v"); + assertEarlyError("/[$$]/v"); + assertEarlyError("/[%%]/v"); + assertEarlyError("/[**]/v"); + assertEarlyError("/[++]/v"); + assertEarlyError("/[,,]/v"); + assertEarlyError("/[..]/v"); + assertEarlyError("/[::]/v"); + assertEarlyError("/[;;]/v"); + assertEarlyError("/[<<]/v"); + assertEarlyError("/[==]/v"); + assertEarlyError("/[>>]/v"); + assertEarlyError("/[??]/v"); + assertEarlyError("/[@@]/v"); + // The first ^ negates the class. The following two are not valid. + assertEarlyError("/[^^^]/v"); + assertEarlyError("/[``]/v"); + assertEarlyError("/[~~]/v"); + + assertEarlyError("/[a&&&]/v"); + assertEarlyError("/[&&&a]/v"); + + // Unterminated string disjunction. + assertEarlyError("/[\\q{foo]/v"); + assertEarlyError("/[\\q{foo|]/v"); + + // Negating classes containing strings is not allowed. + assertEarlyError("/[^\\q{foo}]/v"); + assertEarlyError("/[^\\q{}]/v"); // Empty string counts as string. + assertEarlyError("/[^[\\q{foo}]]/v"); + assertEarlyError("/[^[\\p{Basic_Emoji}]/v"); + assertEarlyError("/[^\\q{foo}&&\\q{bar}]/v"); + assertEarlyError("/[^\\q{foo}--\\q{bar}]/v"); + // Exceptions when negating the class is allowed: + // The "string" contains only single characters. + /[^\q{a|b|c}]/v; + // Not all operands of an intersection contain strings. + /[^\q{foo}&&\q{bar}&&a]/v; + // The first operand of a subtraction doesn't contain strings. + /[^a--\q{foo}--\q{bar}]/v; + + // Negated properties of strings are not allowed. + assertEarlyError("/\\P{Basic_Emoji}/v"); + assertEarlyError("/\\P{Emoji_Keycap_Sequence}/v"); + assertEarlyError("/\\P{RGI_Emoji_Modifier_Sequence}/v"); + assertEarlyError("/\\P{RGI_Emoji_Flag_Sequence}/v"); + assertEarlyError("/\\P{RGI_Emoji_Tag_Sequence}/v"); + assertEarlyError("/\\P{RGI_Emoji_ZWJ_Sequence}/v"); + assertEarlyError("/\\P{RGI_Emoji}/v"); + + // Invalid identity escape in string disjunction. + assertEarlyError("/[\\q{\\w}]/v"); + + const allAscii = Array.from({ length: 127 }, (v, i) => { + return String.fromCharCode(i); + }); + + function check(re, expectMatch, expectNoMatch = [], negationValid = true) { + if (expectNoMatch === undefined) { + const expectSet = new Set( + expectMatch.map(val => { + return typeof val == "number" ? String(val) : val; + }) + ); + expectNoMatch = allAscii.filter(val => !expectSet.has(val)); + } + for (const match of expectMatch) { + assertTrue(re.test(match), `${re}.test(${match})`); + } + for (const noMatch of expectNoMatch) { + assertFalse(re.test(noMatch), `${re}.test(${noMatch})`); + } + if (!negationValid) { + // Negation of classes containing strings is an error. + const negated = `[^${re.source}]`; + assertThrows( + () => { + new RegExp(negated, `${re.flags}`); + }, + SyntaxError, + `Invalid regular expression: /${negated}/${re.flags}: ` + `Negated character class may contain strings` + ); + } else { + // Nest the current RegExp in a negated class and check expectations are + // inversed. + const inverted = new RegExp(`[^${re.source}]`, re.flags); + for (const match of expectMatch) { + assertFalse(inverted.test(match), `${inverted}.test(${match})`); + } + for (const noMatch of expectNoMatch) { + assertTrue(inverted.test(noMatch), `${inverted}.test(${noMatch})`); + } + } + } + + // Union with nested class + check(/[\da-f[xy][^[^z]]]/v, Array.from("0123456789abcdefxyz"), Array.from("ghijklmnopqrstuv!?")); + + // Intersections + check(/[\d&&[0-9]]/v, Array.from("0123456789"), []); + check(/[\d&&0]/v, [0], Array.from("123456789")); + check(/[\d&&9]/v, [9], Array.from("012345678")); + check(/[\d&&[02468]]/v, Array.from("02468"), Array.from("13579")); + check(/[\d&&[13579]]/v, Array.from("13579"), Array.from("02468")); + check(/[\w&&[^a-zA-Z_]]/v, Array.from("0123456789"), Array.from("abcdxyzABCDXYZ_!?")); + check(/[^\w&&[a-zA-Z_]]/v, Array.from("0123456789!?"), Array.from("abcdxyzABCDXYZ_")); + + // Subtractions + check(/[\d--[!-%]]/v, Array.from("0123456789")); + check(/[\d--[A-Z]]/v, Array.from("0123456789")); + check(/[\d--[0-9]]/v, []); + check(/[\d--[\w]]/v, []); + check(/[\d--0]/v, Array.from("123456789")); + check(/[\d--9]/v, Array.from("012345678")); + check(/[[\d[a-c]]--9]/v, Array.from("012345678abc")); + check(/[\d--[02468]]/v, Array.from("13579")); + check(/[\d--[13579]]/v, Array.from("02468")); + check(/[[3-7]--[0-9]]/v, []); + check(/[[3-7]--[0-7]]/v, []); + check(/[[3-7]--[3-9]]/v, []); + check(/[[3-79]--[0-7]]/v, [9]); + check(/[[3-79]--[3-9]]/v, []); + check(/[[3-7]--[0-3]]/v, Array.from("4567")); + check(/[[3-7]--[0-5]]/v, Array.from("67")); + check(/[[3-7]--[7-9]]/v, Array.from("3456")); + check(/[[3-7]--[5-9]]/v, Array.from("34")); + check(/[[3-7a-c]--[0-3]]/v, Array.from("4567abc")); + check(/[[3-7a-c]--[0-5]]/v, Array.from("67abc")); + check(/[[3-7a-c]--[7-9]]/v, Array.from("3456abc")); + check(/[[3-7a-c]--[5-9]]/v, Array.from("34abc")); + check(/[[2-8]--[0-3]--5--[7-9]]/v, Array.from("46")); + check(/[[2-57-8]--[0-3]--[5-7]]/v, Array.from("48")); + check(/[[0-57-8]--[1-34]--[5-7]]/v, Array.from("08")); + check(/[\d--[^02468]]/v, Array.from("02468")); + check(/[\d--[^13579]]/v, Array.from("13579")); + check(/[[a-c]--\0]/v, Array.from("abc")); + + // Ignore-Case + check(/[Ā-č]/v, Array.from("ĀāĂ㥹Ćć"), Array.from("abc")); + check(/[ĀĂĄĆ]/iv, Array.from("ĀāĂ㥹Ćć"), Array.from("abc")); + check(/[āăąć]/iv, Array.from("ĀāĂ㥹Ćć"), Array.from("abc")); + + // Ignore-Case intersections + check(/[\w&&[^a-z_]]/iv, Array.from("0123456789"), Array.from("abcdxyzABCDXYZ_!?")); + check(/[^\w&&[a-z_]]/iv, Array.from("0123456789!?"), Array.from("abcdxyzABCDXYZ_")); + check(/[K&&K]/iv, Array.from("KkK")); // K && U+212A (Kelvin Sign) + check(/[K&&K]/iv, Array.from("KkK")); // U+212A (Kelvin Sign) && K + check(/[K&&\u{212A}]/iv, Array.from("Kk\u{212A}")); + check(/[\u{212A}&&K]/iv, Array.from("Kk\u{212A}")); + + // Ignore-Case subtractions + check(/[\d--[A-Z]]/iv, Array.from("0123456789"), Array.from("abcdEFGH")); + check(/[[\d[a-c]]--9]/iv, Array.from("012345678abcABC"), Array.from("9xX")); + check(/[K--K]/iv, [], Array.from("KkK")); // K -- U+212A (Kelvin Sign) + check(/[K--k]/iv, [], Array.from("KkK")); // U+212A (Kelvin Sign) -- k + check(/[K--\u{212A}]/iv, [], Array.from("KkK")); + check(/[\u{212A}--k]/iv, [], Array.from("KkK")); + + // String disjunctions + check(/[\q{foo|bar|0|5}]/v, ["foo", "bar", 0, 5], ["fo", "baz"], false); + check(/[\q{foo|bar}[05]]/v, ["foo", "bar", 0, 5], ["fo", "baz"], false); + check(/[\q{foo|bar|0|5}&&\q{bar}]/v, ["bar"], ["foo", 0, 5, "fo", "baz"], false); + // The second operand of the intersection doesn't contain strings, so the result + // will not contain strings and therefore negation is valid. + check(/[\q{foo|bar|0|5}&&\d]/v, [0, 5], ["foo", "bar", "fo", "baz"], true); + check(/[\q{foo|bar|0|5}--\q{foo}]/v, ["bar", 0, 5], ["foo", "fo", "baz"], false); + check(/[\q{foo|bar|0|5}--\d]/v, ["foo", "bar"], [0, 5, "fo", "baz"], false); + check(/[\q{foo|bar|3|2|0}--\d]/v, ["foo", "bar"], [0, 1, 2, 3, 4, 5, "fo", "baz"], false); + + check(/[\q{foo|bar|0|5}&&\q{bAr}]/iv, ["bar", "bAr", "BAR"], ["foo", 0, 5, "fo", "baz"], false); + check(/[\q{foo|bar|0|5}--\q{FoO}]/iv, ["bar", "bAr", "BAR", 0, 5], ["foo", "FOO", "fo", "baz"], false); + + check(/[\q{ĀĂĄĆ|AaAc}&&\q{āăąć}]/iv, ["ĀĂĄĆ", "āăąć"], ["AaAc"], false); + check(/[\q{ĀĂĄĆ|AaAc}--\q{āăąć}]/iv, ["AaAc", "aAaC"], ["ĀĂĄĆ", "āăąć"], false); + + // Empty nested classes. + check(/[a-c\q{foo|bar}[]]/v, ["a", "b", "c", "foo", "bar"], [], false); + check(/[[a-c\q{foo|bar}]&&[]]/v, [], ["a", "b", "c", "foo", "bar"], true); + check(/[[a-c\q{foo|bar}]--[]]/v, ["a", "b", "c", "foo", "bar"], [], false); + check(/[[]&&[a-c\q{foo|bar}]]/v, [], ["a", "b", "c", "foo", "bar"], true); + check(/[[]--[a-c\q{foo|bar}]]/v, [], ["a", "b", "c", "foo", "bar"], true); + + // Empty string disjunctions matches nothing, but succeeds. + let res = /[\q{}]/v.exec("foo"); + assertNotNull(res); + assertEquals(1, res.length); + assertEquals("", res[0]); + + // Ensure longest strings are matched first. + assertEquals(["xyz"], /[a-c\q{W|xy|xyz}]/v.exec("xyzabc")); + assertEquals(["xyz"], /[a-c\q{W|xyz|xy}]/v.exec("xyzabc")); + assertEquals(["xyz"], /[\q{W|xyz|xy}a-c]/v.exec("xyzabc")); + // Empty string is last. + assertEquals(["a"], /[\q{W|}a-c]/v.exec("abc")); + + // Some more sophisticated tests taken from + // https://v8.dev/features/regexp-v-flag + assertTrue(/^\p{RGI_Emoji}$/v.test("⚽")); + assertTrue(/^\p{RGI_Emoji}$/v.test("👨🏾‍⚕️")); + assertFalse(/[\p{Script_Extensions=Greek}--π]/v.test("π")); + assertFalse(/[\p{Script_Extensions=Greek}--[αβγ]]/v.test("α")); + assertFalse(/[\p{Script_Extensions=Greek}--[α-γ]]/v.test("β")); + assertTrue(/[\p{Decimal_Number}--[0-9]]/v.test("𑜹")); + assertFalse(/[\p{Decimal_Number}--[0-9]]/v.test("4")); + assertTrue(/^\p{RGI_Emoji_Tag_Sequence}$/v.test("🏴󠁧󠁢󠁳󠁣󠁴󠁿")); + assertFalse(/^[\p{RGI_Emoji_Tag_Sequence}--\q{🏴󠁧󠁢󠁳󠁣󠁴󠁿}]$/v.test("🏴󠁧󠁢󠁳󠁣󠁴󠁿")); + assertTrue(/[\p{Script_Extensions=Greek}&&\p{Letter}]/v.test("π")); + assertFalse(/[\p{Script_Extensions=Greek}&&\p{Letter}]/v.test("𐆊")); + assertTrue(/[\p{White_Space}&&\p{ASCII}]/v.test("\n")); + assertFalse(/[\p{White_Space}&&\p{ASCII}]/v.test("\u2028")); + assertTrue(/[\p{Script_Extensions=Mongolian}&&\p{Number}]/v.test("᠗")); + assertFalse(/[\p{Script_Extensions=Mongolian}&&\p{Number}]/v.test("ᠴ")); + assertTrue(/^[\p{Emoji_Keycap_Sequence}\p{ASCII}\q{🇧🇪|abc}xyz0-9]$/v.test("4️⃣")); + assertTrue(/^[\p{Emoji_Keycap_Sequence}\p{ASCII}\q{🇧🇪|abc}xyz0-9]$/v.test("_")); + assertTrue(/^[\p{Emoji_Keycap_Sequence}\p{ASCII}\q{🇧🇪|abc}xyz0-9]$/v.test("🇧🇪")); + assertTrue(/^[\p{Emoji_Keycap_Sequence}\p{ASCII}\q{🇧🇪|abc}xyz0-9]$/v.test("abc")); + assertTrue(/^[\p{Emoji_Keycap_Sequence}\p{ASCII}\q{🇧🇪|abc}xyz0-9]$/v.test("x")); + assertTrue(/^[\p{Emoji_Keycap_Sequence}\p{ASCII}\q{🇧🇪|abc}xyz0-9]$/v.test("4")); + assertTrue(/[\p{RGI_Emoji_Flag_Sequence}\p{RGI_Emoji_Tag_Sequence}]/v.test("🇧🇪")); + assertTrue(/[\p{RGI_Emoji_Flag_Sequence}\p{RGI_Emoji_Tag_Sequence}]/v.test("🏴󠁧󠁢󠁥󠁮󠁧󠁿")); + assertTrue(/[\p{RGI_Emoji_Flag_Sequence}\p{RGI_Emoji_Tag_Sequence}]/v.test("🇨🇭")); + assertTrue(/[\p{RGI_Emoji_Flag_Sequence}\p{RGI_Emoji_Tag_Sequence}]/v.test("🏴󠁧󠁢󠁷󠁬󠁳󠁿")); + + // Check new case-folding semantics. + assertEquals("XXXXXX4#", "aAbBcC4#".replaceAll(/\p{Lowercase_Letter}/giv, "X")); + assertEquals("XXXXXX4#", "aAbBcC4#".replaceAll(/[^\P{Lowercase_Letter}]/giv, "X")); + assertFalse(/\P{ASCII}/iv.test("K")); + assertFalse(/^\P{Lowercase}/iv.test("A")); +});