1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 18:20:43 +09:00

LibJS: Add Boolean constructor object

This commit is contained in:
Jack Karamanian 2020-04-06 22:51:16 -05:00 committed by Andreas Kling
parent 57bd194e5a
commit edae926cb0
Notes: sideshowbarker 2024-07-19 07:50:30 +09:00
16 changed files with 400 additions and 0 deletions

View file

@ -0,0 +1,35 @@
try {
assert(Boolean.length === 1);
assert(typeof new Boolean() === "object");
assert(new Boolean().valueOf() === false);
var foo = new Boolean(true);
var bar = new Boolean(true);
assert(foo !== bar);
assert(foo.valueOf() === bar.valueOf());
assert(new Boolean(true).toString() === "true");
assert(new Boolean(false).toString() === "false");
assert(typeof Boolean() === "boolean");
assert(typeof Boolean(true) === "boolean");
assert(Boolean() === false);
assert(Boolean(false) === false);
assert(Boolean(null) === false);
assert(Boolean(undefined) === false);
assert(Boolean(NaN) === false);
assert(Boolean("") === false);
assert(Boolean(0.0) === false);
assert(Boolean(-0.0) === false);
assert(Boolean(true) === true);
assert(Boolean("0") === true);
assert(Boolean({}) === true);
assert(Boolean([]) === true);
assert(Boolean(1)) === true;
console.log("PASS");
} catch (err) {
console.log("FAIL: " + err);
}

View file

@ -0,0 +1,8 @@
try {
assert(typeof Boolean.prototype === "object");
assert(Boolean.prototype.valueOf() === false);
console.log("PASS");
} catch (err) {
console.log("FAIL: " + err);
}

View file

@ -0,0 +1,23 @@
try {
var foo = true;
assert(foo.toString() === "true");
assert(true.toString() === "true");
assert(Boolean.prototype.toString.call(true) === "true");
assert(Boolean.prototype.toString.call(false) === "false");
let error = null;
try {
Boolean.prototype.toString.call("foo");
} catch (err) {
error = err;
}
assert(error instanceof Error);
assert(error.name === "TypeError");
assert(error.message === "Not a Boolean");
console.log("PASS");
} catch (err) {
console.log("FAIL: " + err);
}

View file

@ -0,0 +1,23 @@
try {
var foo = true;
assert(foo.valueOf() === true);
assert(true.valueOf() === true);
assert(Boolean.prototype.valueOf.call(true) === true);
assert(Boolean.prototype.valueOf.call(false) === false);
let error = null;
try {
Boolean.prototype.valueOf.call("foo");
} catch (err) {
error = err;
}
assert(error instanceof Error);
assert(error.name === "TypeError");
assert(error.message === "Not a Boolean");
console.log("PASS");
} catch (err) {
console.log("FAIL: " + err);
}