mirror of
https://github.com/RGBCube/serenity
synced 2025-07-05 09:07:34 +00:00
LibJS: Consolidate error messages into ErrorTypes.h
Now, exceptions can be thrown with interpreter.throw_exception<T>(ErrorType:TYPE, "format", "args", "here").
This commit is contained in:
parent
9940a7f6de
commit
78155a6668
63 changed files with 439 additions and 223 deletions
|
@ -33,8 +33,8 @@ try {
|
|||
}, {
|
||||
error: TypeError,
|
||||
message: typeof value === "symbol"
|
||||
? "Can't convert symbol to BigInt"
|
||||
: `Can't convert ${value} to BigInt`
|
||||
? "Cannot convert symbol to BigInt"
|
||||
: `Cannot convert ${value} to BigInt`
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ try {
|
|||
Boolean.prototype.toString.call("foo");
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Not a Boolean"
|
||||
message: "Not a Boolean object"
|
||||
});
|
||||
|
||||
console.log("PASS");
|
||||
|
|
|
@ -12,7 +12,7 @@ try {
|
|||
Boolean.prototype.valueOf.call("foo");
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Not a Boolean"
|
||||
message: "Not a Boolean object"
|
||||
});
|
||||
|
||||
console.log("PASS");
|
||||
|
|
|
@ -104,7 +104,7 @@ try {
|
|||
});
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Accessor property descriptors cannot specify a value or writable key",
|
||||
message: "Accessor property descriptor cannot specify a value or writable key",
|
||||
});
|
||||
|
||||
assertThrowsError(() => {
|
||||
|
@ -114,7 +114,7 @@ try {
|
|||
});
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Accessor property descriptors cannot specify a value or writable key",
|
||||
message: "Accessor property descriptor cannot specify a value or writable key",
|
||||
});
|
||||
|
||||
console.log("PASS");
|
||||
|
|
|
@ -13,14 +13,14 @@ try {
|
|||
Object.entries(null);
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "ToObject on null or undefined.",
|
||||
message: "ToObject on null or undefined",
|
||||
});
|
||||
|
||||
assertThrowsError(() => {
|
||||
Object.entries(undefined);
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "ToObject on null or undefined.",
|
||||
message: "ToObject on null or undefined",
|
||||
});
|
||||
|
||||
let entries = Object.entries({ foo: 1, bar: 2, baz: 3 });
|
||||
|
|
|
@ -13,14 +13,14 @@ try {
|
|||
Object.keys(null);
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "ToObject on null or undefined.",
|
||||
message: "ToObject on null or undefined",
|
||||
});
|
||||
|
||||
assertThrowsError(() => {
|
||||
Object.keys(undefined);
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "ToObject on null or undefined.",
|
||||
message: "ToObject on null or undefined",
|
||||
});
|
||||
|
||||
let keys = Object.keys({ foo: 1, bar: 2, baz: 3 });
|
||||
|
|
|
@ -27,7 +27,7 @@ try {
|
|||
Object.defineProperty(o, "baz", { value: "baz" });
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Unable to define property on non-extensible object",
|
||||
message: "Cannot define property baz on non-extensible object",
|
||||
});
|
||||
|
||||
assert(o.baz === undefined);
|
||||
|
|
|
@ -10,12 +10,12 @@ try {
|
|||
message: "Object.setPrototypeOf requires at least two arguments",
|
||||
});
|
||||
|
||||
// assertThrowsError(() => {
|
||||
// Object.setPrototypeOf({}, "foo");
|
||||
// }, {
|
||||
// error: TypeError,
|
||||
// message: "Prototype must be null or object"
|
||||
// });
|
||||
assertThrowsError(() => {
|
||||
Object.setPrototypeOf({}, "foo");
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Prototype must be an object or null"
|
||||
});
|
||||
|
||||
o = {};
|
||||
p = {};
|
||||
|
@ -26,7 +26,7 @@ try {
|
|||
Object.setPrototypeOf(o, {});
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Object's setPrototypeOf method returned false"
|
||||
message: "Object's [[SetPrototypeOf]] method returned false"
|
||||
});
|
||||
assert(Object.setPrototypeOf(o, p) === o);
|
||||
|
||||
|
|
|
@ -13,14 +13,14 @@ try {
|
|||
Object.values(null);
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "ToObject on null or undefined.",
|
||||
message: "ToObject on null or undefined",
|
||||
});
|
||||
|
||||
assertThrowsError(() => {
|
||||
Object.values(undefined);
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "ToObject on null or undefined.",
|
||||
message: "ToObject on null or undefined",
|
||||
});
|
||||
|
||||
let values = Object.values({ foo: 1, bar: 2, baz: 3 });
|
||||
|
|
|
@ -62,7 +62,7 @@ try {
|
|||
Object.defineProperty(p, "foo", {});
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Proxy handler's defineProperty method returned false",
|
||||
message: "Object's [[DefineProperty]] method returned false",
|
||||
});
|
||||
|
||||
o = {};
|
||||
|
|
|
@ -47,7 +47,7 @@ try {
|
|||
delete p.foo;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Proxy handler's delete trap violates invariant: cannot report a non-configurable own property of the target as deleted",
|
||||
message: "Proxy handler's deleteProperty trap violates invariant: cannot report a non-configurable own property of the target as deleted",
|
||||
});
|
||||
|
||||
console.log("PASS");
|
||||
|
|
|
@ -53,7 +53,7 @@ try {
|
|||
"bar" in p;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Proxy handler's has trap violates invariant: a property cannot be reported as non-existent if it exist on the target and the target is non-extensible",
|
||||
message: "Proxy handler's has trap violates invariant: a property cannot be reported as non-existent if it exists on the target and the target is non-extensible",
|
||||
});
|
||||
|
||||
console.log("PASS");
|
||||
|
|
|
@ -30,7 +30,7 @@ try {
|
|||
Object.preventExtensions(p);
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Proxy preventExtensions handler returned false",
|
||||
message: "Object's [[PreventExtensions]] method returned false",
|
||||
});
|
||||
|
||||
o = {};
|
||||
|
|
|
@ -57,7 +57,7 @@ try {
|
|||
Object.setPrototypeOf(p, {});
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Object's setPrototypeOf method returned false"
|
||||
message: "Object's [[SetPrototypeOf]] method returned false",
|
||||
});
|
||||
assert(Object.getPrototypeOf(p) === childProto);
|
||||
|
||||
|
|
|
@ -7,14 +7,14 @@ try {
|
|||
new Proxy();
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Proxy requires at least two arguments",
|
||||
message: "Proxy constructor requires at least two arguments",
|
||||
});
|
||||
|
||||
assertThrowsError(() => {
|
||||
Proxy();
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Proxy must be called with the \"new\" operator",
|
||||
message: "Proxy must be called with the 'new' operator",
|
||||
});
|
||||
|
||||
assertThrowsError(() => {
|
||||
|
|
|
@ -21,7 +21,7 @@ try {
|
|||
Symbol.for(Symbol());
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Can't convert symbol to string",
|
||||
message: "Cannot convert symbol to string",
|
||||
});
|
||||
|
||||
console.log("PASS");
|
||||
|
|
|
@ -17,7 +17,7 @@ try {
|
|||
Symbol(Symbol('foo'));
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Can't convert symbol to string"
|
||||
message: "Cannot convert symbol to string"
|
||||
})
|
||||
|
||||
console.log("PASS");
|
||||
|
|
|
@ -11,14 +11,14 @@ try {
|
|||
s1 + "";
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Can't convert symbol to string",
|
||||
message: "Cannot convert symbol to string",
|
||||
});
|
||||
|
||||
assertThrowsError(() => {
|
||||
s1 + 1;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Can't convert symbol to number",
|
||||
message: "Cannot convert symbol to number",
|
||||
});
|
||||
|
||||
console.log("PASS");
|
||||
|
|
|
@ -13,7 +13,7 @@ try {
|
|||
Symbol.prototype.valueOf.call("foo");
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "object must be of type Symbol"
|
||||
message: "Not a Symbol object",
|
||||
});
|
||||
|
||||
console.log("PASS");
|
||||
|
|
|
@ -11,7 +11,7 @@ try {
|
|||
+bigint;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Can't convert BigInt to number"
|
||||
message: "Cannot convert BigInt to number"
|
||||
});
|
||||
|
||||
assert(12n + 34n === 46n);
|
||||
|
|
|
@ -6,73 +6,73 @@ try {
|
|||
1n + value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Can't use addition operator with BigInt and other type"
|
||||
message: "Cannot use addition operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
1n - value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Can't use subtraction operator with BigInt and other type"
|
||||
message: "Cannot use subtraction operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
1n * value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Can't use multiplication operator with BigInt and other type"
|
||||
message: "Cannot use multiplication operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
1n / value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Can't use division operator with BigInt and other type"
|
||||
message: "Cannot use division operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
1n % value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Can't use modulo operator with BigInt and other type"
|
||||
message: "Cannot use modulo operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
1n ** value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Can't use exponentiation operator with BigInt and other type"
|
||||
message: "Cannot use exponentiation operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
1n | value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Can't use bitwise OR operator with BigInt and other type"
|
||||
message: "Cannot use bitwise OR operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
1n & value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Can't use bitwise AND operator with BigInt and other type"
|
||||
message: "Cannot use bitwise AND operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
1n ^ value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Can't use bitwise XOR operator with BigInt and other type"
|
||||
message: "Cannot use bitwise XOR operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
1n << value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Can't use left-shift operator with BigInt and other type"
|
||||
message: "Cannot use left-shift operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
1n >> value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Can't use right-shift operator with BigInt and other type"
|
||||
message: "Cannot use right-shift operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
1n >>> value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Can't use unsigned right-shift operator with BigInt"
|
||||
message: "Cannot use unsigned right-shift operator with BigInt"
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ try {
|
|||
}
|
||||
}, {
|
||||
error: ReferenceError,
|
||||
message: "'foo' not known"
|
||||
message: "'foo' is not defined"
|
||||
});
|
||||
|
||||
assertThrowsError(() => {
|
||||
|
@ -16,7 +16,7 @@ try {
|
|||
}
|
||||
}, {
|
||||
error: ReferenceError,
|
||||
message: "'foo' not known"
|
||||
message: "'foo' is not defined"
|
||||
});
|
||||
|
||||
var loopCount = 0;
|
||||
|
@ -26,7 +26,7 @@ try {
|
|||
}
|
||||
}, {
|
||||
error: ReferenceError,
|
||||
message: "'foo' not known"
|
||||
message: "'foo' is not defined"
|
||||
});
|
||||
assert(loopCount === 1);
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ try {
|
|||
"prop" in value;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "'in' operator must be used on object"
|
||||
message: "'in' operator must be used on an object"
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ try {
|
|||
primitive.foo = "bar";
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Can't assign property foo to primitive value"
|
||||
message: "Cannot assign property foo to primitive value"
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ try {
|
|||
foo`bar${baz}`;
|
||||
}, {
|
||||
error: ReferenceError,
|
||||
message: "'foo' not known"
|
||||
message: "'foo' is not defined"
|
||||
});
|
||||
|
||||
assertThrowsError(() => {
|
||||
|
@ -13,7 +13,7 @@ try {
|
|||
foo`bar${baz}`;
|
||||
}, {
|
||||
error: ReferenceError,
|
||||
message: "'baz' not known"
|
||||
message: "'baz' is not defined"
|
||||
});
|
||||
|
||||
assertThrowsError(() => {
|
||||
|
|
|
@ -36,7 +36,7 @@ try {
|
|||
`${b}`;
|
||||
}, {
|
||||
error: ReferenceError,
|
||||
message: "'b' not known"
|
||||
message: "'b' is not defined",
|
||||
})
|
||||
|
||||
console.log("PASS");
|
||||
|
|
|
@ -5,7 +5,7 @@ try {
|
|||
++x;
|
||||
}, {
|
||||
error: ReferenceError,
|
||||
message: "'x' not known"
|
||||
message: "'x' is not defined",
|
||||
});
|
||||
|
||||
var n = 0;
|
||||
|
|
|
@ -7,7 +7,7 @@ try {
|
|||
constantValue = 2;
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Assignment to constant variable"
|
||||
message: "Invalid assignment to const variable"
|
||||
});
|
||||
assert(constantValue === 1);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue