mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-09 17:44:56 +09:00
LibJS: Implement Error.prototype.name setter (#1776)
The MDN example for creating a custom error type in javascript uses: function CustomError(foo, message, fileName, lineNumber) { var instance = new Error(message, fileName, lineNumber); instance.name = 'CustomError'; instance.foo = foo; Object.setPrototypeOf(instance, Object.getPrototypeOf(this)); return instance; } The name property on the Error prototype needs to be settable for this to work properly.
This commit is contained in:
parent
984c290ec0
commit
2a65db7c12
Notes:
sideshowbarker
2024-07-19 07:38:25 +09:00
Author: https://github.com/bgianfo
Commit: 2a65db7c12
Pull-request: https://github.com/SerenityOS/serenity/pull/1776
Reviewed-by: https://github.com/awesomekling
4 changed files with 30 additions and 1 deletions
12
Libraries/LibJS/Tests/Error.prototype.name.js
Normal file
12
Libraries/LibJS/Tests/Error.prototype.name.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
try {
|
||||
var changedInstance = new Error("");
|
||||
changedInstance.name = 'NewCustomError';
|
||||
assert(changedInstance.name === "NewCustomError");
|
||||
|
||||
var normalInstance = new Error("");
|
||||
assert(normalInstance.name === "Error");
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e.message);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue