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:
parent
57bd194e5a
commit
edae926cb0
Notes:
sideshowbarker
2024-07-19 07:50:30 +09:00
Author: https://github.com/jack-karamanian
Commit: edae926cb0
Pull-request: https://github.com/SerenityOS/serenity/pull/1682
Reviewed-by: https://github.com/bgianfo
16 changed files with 400 additions and 0 deletions
35
Libraries/LibJS/Tests/Boolean.js
Normal file
35
Libraries/LibJS/Tests/Boolean.js
Normal 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);
|
||||
}
|
8
Libraries/LibJS/Tests/Boolean.prototype.js
Normal file
8
Libraries/LibJS/Tests/Boolean.prototype.js
Normal 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);
|
||||
}
|
23
Libraries/LibJS/Tests/Boolean.prototype.toString.js
Normal file
23
Libraries/LibJS/Tests/Boolean.prototype.toString.js
Normal 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);
|
||||
}
|
23
Libraries/LibJS/Tests/Boolean.prototype.valueOf.js
Normal file
23
Libraries/LibJS/Tests/Boolean.prototype.valueOf.js
Normal 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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue