summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Runtime/Error.h
diff options
context:
space:
mode:
authorBrian Gianforcaro <b.gianfo@gmail.com>2020-04-13 02:19:53 -0700
committerGitHub <noreply@github.com>2020-04-13 11:19:53 +0200
commit2a65db7c1253e4a070e8ac101faa2404dc7af99e (patch)
tree5110a338d908725df5e120e05e68275ea0f6e27e /Libraries/LibJS/Runtime/Error.h
parent984c290ec04806ba187e4789e2b63d5dfc26c1a4 (diff)
downloadserenity-2a65db7c1253e4a070e8ac101faa2404dc7af99e.zip
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.
Diffstat (limited to 'Libraries/LibJS/Runtime/Error.h')
-rw-r--r--Libraries/LibJS/Runtime/Error.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/Libraries/LibJS/Runtime/Error.h b/Libraries/LibJS/Runtime/Error.h
index 76615b4b9e..ac15e7bbbd 100644
--- a/Libraries/LibJS/Runtime/Error.h
+++ b/Libraries/LibJS/Runtime/Error.h
@@ -39,6 +39,8 @@ public:
const FlyString& name() const { return m_name; }
const String& message() const { return m_message; }
+ void set_name(const FlyString& name) { m_name = name; }
+
private:
virtual bool is_error() const final { return true; }
virtual const char* class_name() const override { return "Error"; }