Files
rust_browser/tests/external/js262/test262/harness/assert.js
Zachary D. Rowitsch 9e0bbe37fc
All checks were successful
ci / fast (linux) (push) Successful in 6m19s
Add Test262 integration (Phase A): function properties, harness, 50 real tests
Add function property support to the JS engine (fn.prop = val, fn.prop,
fn.method()) enabling the Test262 assert harness pattern. Implement Test262
execution mode in the JS262 harness with simplified sta.js/assert.js shims.
Vendor 50 real tc39/test262 tests via curation script (35 pass, 15 known_fail).

Engine changes:
- JsObject: add Debug impl and has() method for presence checks
- JsFunction: add properties field (Rc-shared JsObject)
- Interpreter: handle function property get/set/call/compound-assign/update
  with user-property-over-builtin precedence

Harness changes:
- Add Test262 variant to Js262Mode with relaxed manifest validation
- Implement run_test262_case with harness prepending and error classification
- Create sta.js (Test262Error shim) and assert.js (assert.sameValue etc.)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 19:28:47 -05:00

64 lines
1.9 KiB
JavaScript

// Test262 harness shim: assert.js
// Uses function + property assignment (requires function property support).
// Implements SameValue semantics per ES2015 7.2.10.
function assert(mustBeTrue, message) {
if (!mustBeTrue) {
if (typeof message === "undefined") {
message = "Expected true but got false";
}
throw "Test262Error: " + message;
}
}
// SameValue(x, y) per ES2015 7.2.10:
// SameValue(NaN, NaN) = true (unlike ===)
// SameValue(+0, -0) = false (unlike ===)
assert._isSameValue = function(a, b) {
// NaN check: NaN is the only value where x !== x
if (a !== a && b !== b) {
return true;
}
// +0 / -0 check: 1/+0 = +Infinity, 1/-0 = -Infinity
if (a === 0 && b === 0) {
return 1/a === 1/b;
}
return a === b;
};
assert.sameValue = function(actual, expected, message) {
if (!assert._isSameValue(actual, expected)) {
if (typeof message === "undefined") {
message = "Expected SameValue(" + actual + ", " + expected + ") to be true";
}
throw "Test262Error: " + message;
}
};
assert.notSameValue = function(actual, unexpected, message) {
if (assert._isSameValue(actual, unexpected)) {
if (typeof message === "undefined") {
message = "Expected SameValue(" + actual + ", " + unexpected + ") to be false";
}
throw "Test262Error: " + message;
}
};
assert.throws = function(expectedErrorConstructor, func, message) {
var threw = false;
try {
func();
} catch(e) {
threw = true;
// NOTE: We cannot check `e instanceof expectedErrorConstructor`
// because instanceof is not yet supported. This shim only verifies
// that SOMETHING was thrown.
}
if (!threw) {
if (typeof message === "undefined") {
message = "Expected function to throw";
}
throw "Test262Error: " + message;
}
};