diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/jit-test/tests/warp/typeof-is.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/src/jit-test/tests/warp/typeof-is.js | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/warp/typeof-is.js b/js/src/jit-test/tests/warp/typeof-is.js new file mode 100644 index 0000000000..df41185769 --- /dev/null +++ b/js/src/jit-test/tests/warp/typeof-is.js @@ -0,0 +1,126 @@ +// Test case |typeof| folding in simple comparison contexts. + +// Create functions to test if |typeof x| is equal to a constant string. +// - Covers all possible |typeof| results, plus the invalid string "bad". +// - Covers all four possible equality comparison operators. +function createFunctions() { + return [ + "undefined", + "object", + "function", + "string", + "number", + "boolean", + "symbol", + "bigint", + "bad", + ].flatMap(type => [ + "==", + "===", + "!=", + "!==" + ].map(op => ({ + type, + equal: op[0] === "=", + fn: Function("thing", `return typeof thing ${op} "${type}"`) + }))); +} + +let functions = createFunctions(); + +function test() { + const ccwGlobal = newGlobal({newCompartment: true}); + const xs = [ + // "undefined" + // Plain undefined and object emulating undefined, including various proxy wrapper cases. + undefined, + createIsHTMLDDA(), + wrapWithProto(createIsHTMLDDA(), null), + ccwGlobal.eval("createIsHTMLDDA()"), + + // "object" + // Plain object and various proxy wrapper cases. + {}, + this, + new Proxy({}, {}), + wrapWithProto({}, null), + transplantableObject({proxy: true}).object, + ccwGlobal.Object(), + + // "function" + // Plain function and various proxy wrapper cases. + function(){}, + new Proxy(function(){}, {}), + new Proxy(createIsHTMLDDA(), {}), + wrapWithProto(function(){}, null), + ccwGlobal.Function(), + + // "string" + "", + + // "number" + // Int32 and Double numbers. + 0, + 1.23, + + // "boolean" + true, + + // "symbol" + Symbol(), + + // "bigint" + 0n, + ]; + + for (let i = 0; i < 200; ++i) { + let x = xs[i % xs.length]; + for (let {type, equal, fn} of functions) { + assertEq(fn(x), (typeof x === type) === equal); + } + } +} +for (let i = 0; i < 2; ++i) test(); + +// Fresh set of functions to gather new type info. +let functionsObject = createFunctions(); + +// Additional test when the input is always an object. +function testObject() { + const ccwGlobal = newGlobal({newCompartment: true}); + + // All elements of this array are objects to cover the case when |MTypeOf| has + // a |MIRType::Object| input. + const xs = [ + // "undefined" + // Object emulating undefined, including various proxy wrapper cases. + createIsHTMLDDA(), + wrapWithProto(createIsHTMLDDA(), null), + ccwGlobal.eval("createIsHTMLDDA()"), + + // "object" + // Plain object and various proxy wrapper cases. + {}, + this, + new Proxy({}, {}), + wrapWithProto({}, null), + transplantableObject({proxy: true}).object, + ccwGlobal.Object(), + + // "function" + // Plain function and various proxy wrapper cases. + function(){}, + new Proxy(function(){}, {}), + new Proxy(createIsHTMLDDA(), {}), + wrapWithProto(function(){}, null), + ccwGlobal.Function(), + ]; + + for (let i = 0; i < 200; ++i) { + let x = xs[i % xs.length]; + for (let {type, equal, fn} of functionsObject) { + assertEq(fn(x), (typeof x === type) === equal); + } + } +} +for (let i = 0; i < 2; ++i) testObject(); |