Files
ladybird/Tests/LibJS/Runtime/3rdparty/v8/regexp-stack-overflow.js
Andreas Kling 3646912c5c Tests: Import V8 and WebKit regexp suites
Add scripts for importing the V8 and WebKit regexp suites into
`Tests/LibJS/Runtime/3rdparty/` and commit the imported tests.

Also update the local harness helpers so these suites can run under
LibJS. In particular, teach the assertion shims to compare RegExp values
the way the imported tests expect and to treat `new Function(...)`
throwing as a valid `assertThrows` case.

This gives the regex rewrite a large bank of external conformance tests
that exercise parser and matcher behavior beyond in-tree coverage.
2026-03-27 17:32:19 +01:00

101 lines
2.3 KiB
JavaScript

// Copyright 2015 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 {
try {
fn = new Function(fn);
} catch (e) {
return;
}
} catch (e) {
return;
}
}
if (typeof fn === "string") {
try {
try {
fn = new Function(fn);
} catch (e) {
return;
}
} 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("regexp-stack-overflow", () => {
var re = /\w/;
re.test("a"); // Trigger regexp compile.
function rec() {
try {
return rec();
} catch (e) {
return re.test("b");
}
}
assertTrue(rec());
});