From 2a65db7c1253e4a070e8ac101faa2404dc7af99e Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Mon, 13 Apr 2020 02:19:53 -0700 Subject: 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. --- Libraries/LibJS/Runtime/Error.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Libraries/LibJS/Runtime/Error.h') 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"; } -- cgit v1.2.3