1
Fork 0
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:
Linus Groh 2020-05-02 19:18:55 +01:00 committed by Andreas Kling
parent d007e8d00f
commit 99be27b4a1
16 changed files with 118 additions and 16 deletions

View file

@ -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);
}

View file

@ -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);

View 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);
}

View file

@ -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();

View file

@ -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");

View file

@ -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);

View 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);
}

View 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);
}

View 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);
}