mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:37:45 +00:00
LibJS: Add "name" property to functions
This commit is contained in:
parent
d007e8d00f
commit
99be27b4a1
16 changed files with 118 additions and 16 deletions
|
@ -2,15 +2,16 @@ load("test-common.js");
|
|||
|
||||
try {
|
||||
assert(Array.length === 1);
|
||||
assert(Array.name === "Array");
|
||||
assert(Array.prototype.length === 0);
|
||||
|
||||
assert(typeof Array() === "object");
|
||||
assert(typeof new Array() === "object");
|
||||
|
||||
x = new Array(5);
|
||||
|
||||
assert(x.length === 5);
|
||||
var a = new Array(5);
|
||||
assert(a.length === 5);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e.message);
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@ load("test-common.js");
|
|||
|
||||
try {
|
||||
assert(Boolean.length === 1);
|
||||
assert(Boolean.name === "Boolean");
|
||||
assert(Boolean.prototype.length === undefined);
|
||||
|
||||
assert(typeof new Boolean() === "object");
|
||||
assert(new Boolean().valueOf() === false);
|
||||
|
||||
|
|
11
Libraries/LibJS/Tests/Date.js
Normal file
11
Libraries/LibJS/Tests/Date.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Date.length === 7);
|
||||
assert(Date.name === "Date");
|
||||
assert(Date.prototype.length === undefined);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
|
@ -1,6 +1,10 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Error.length === 1);
|
||||
assert(Error.name === "Error");
|
||||
assert(Error.prototype.length === undefined);
|
||||
|
||||
var e;
|
||||
|
||||
e = Error();
|
||||
|
|
|
@ -2,7 +2,9 @@ load("test-common.js");
|
|||
|
||||
try {
|
||||
assert(Function.length === 1);
|
||||
assert(Function.name === "Function");
|
||||
assert(Function.prototype.length === 0);
|
||||
assert(Function.prototype.name === "");
|
||||
|
||||
assert(typeof Function() === "function");
|
||||
assert(typeof new Function() === "function");
|
||||
|
@ -21,6 +23,7 @@ try {
|
|||
assert(new Function("return typeof Function()")() === "function");
|
||||
assert(new Function("x", "return function (y) { return x + y };")(1)(2) === 3);
|
||||
|
||||
assert(new Function().name === "anonymous");
|
||||
assert(new Function().toString() === "function anonymous() {\n ???\n}");
|
||||
|
||||
console.log("PASS");
|
||||
|
|
|
@ -2,8 +2,12 @@ load("test-common.js");
|
|||
|
||||
try {
|
||||
assert(Number.length === 1);
|
||||
assert(Number.name === "Number");
|
||||
assert(Number.prototype.length === undefined);
|
||||
|
||||
assert(typeof Number() === "number");
|
||||
assert(typeof new Number() === "object");
|
||||
|
||||
assert(Number() === 0);
|
||||
assert(new Number().valueOf() === 0);
|
||||
assert(Number("42") === 42);
|
||||
|
|
14
Libraries/LibJS/Tests/Object.js
Normal file
14
Libraries/LibJS/Tests/Object.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Object.length === 1);
|
||||
assert(Object.name === "Object");
|
||||
assert(Object.prototype.length === undefined);
|
||||
|
||||
assert(typeof Object() === "object");
|
||||
assert(typeof new Object() === "object");
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
23
Libraries/LibJS/Tests/String.js
Normal file
23
Libraries/LibJS/Tests/String.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(String.length === 1);
|
||||
assert(String.name === "String");
|
||||
assert(String.prototype.length === 0);
|
||||
|
||||
assert(typeof String() === "string");
|
||||
assert(typeof new String() === "object");
|
||||
|
||||
assert(String() === "");
|
||||
assert(new String().valueOf() === "");
|
||||
assert(String("foo") === "foo");
|
||||
assert(new String("foo").valueOf() === "foo");
|
||||
assert(String(123) === "123");
|
||||
assert(new String(123).valueOf() === "123");
|
||||
assert(String(123) === "123");
|
||||
assert(new String(123).valueOf() === "123");
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
21
Libraries/LibJS/Tests/function-name.js
Normal file
21
Libraries/LibJS/Tests/function-name.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
var f = function () { }
|
||||
assert(f.name === "");
|
||||
assert((f.name = "f") === "f");
|
||||
assert(f.name === "");
|
||||
|
||||
function foo() { }
|
||||
assert(foo.name === "foo");
|
||||
assert((foo.name = "bar") === "bar");
|
||||
assert(foo.name === "foo");
|
||||
|
||||
assert(console.log.name === "log");
|
||||
assert((console.log.name = "warn") === "warn");
|
||||
assert(console.log.name === "log");
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue