summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/Error.h
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-04-12 00:08:28 +0200
committerAndreas Kling <kling@serenityos.org>2021-04-12 09:38:57 +0200
commitda177c6517ab0ba77facfe4ff5a078562f887e96 (patch)
tree33123a6ad6e98f09b4390796dc20f26458c0800e /Userland/Libraries/LibJS/Runtime/Error.h
parent6e9eb0a284661803d634ce0bd8c1656a156878bb (diff)
downloadserenity-da177c6517ab0ba77facfe4ff5a078562f887e96.zip
LibJS: Make Errors fully spec compliant
The previous handling of the name and message properties specifically was breaking websites that created their own error types and relied on the error prototype working correctly - not assuming an JS::Error this object, that is. The way it works now, and it is supposed to work, is: - Error.prototype.name and Error.prototype.message just have initial string values and are no longer getters/setters - When constructing an error with a message, we create a regular property on the newly created object, so a lookup of the message property will either get it from the object directly or go though the prototype chain - Internal m_name/m_message properties are no longer needed and removed This makes printing errors slightly more complicated, as we can no longer rely on the (safe) internal properties, and cannot trust a property lookup either - get_without_side_effects() is used to solve this, it's not perfect but something we can revisit later. I did some refactoring along the way, there was some really old stuff in there - accessing vm.call_frame().arguments[0] is not something we (have to) do anymore :^) Fixes #6245.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Error.h')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Error.h22
1 files changed, 7 insertions, 15 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Error.h b/Userland/Libraries/LibJS/Runtime/Error.h
index 3605825f1d..0c7e9ac66c 100644
--- a/Userland/Libraries/LibJS/Runtime/Error.h
+++ b/Userland/Libraries/LibJS/Runtime/Error.h
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2021, Linus Groh <mail@linusgroh.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -35,19 +36,10 @@ class Error : public Object {
JS_OBJECT(Error, Object);
public:
- static Error* create(GlobalObject&, const FlyString& name, const String& message);
+ static Error* create(GlobalObject&, const String& message = {});
- Error(const FlyString& name, const String& message, Object& prototype);
- virtual ~Error() override;
-
- const FlyString& name() const { return m_name; }
- const String& message() const { return m_message; }
-
- void set_name(const FlyString& name) { m_name = name; }
-
-private:
- FlyString m_name;
- String m_message;
+ explicit Error(Object& prototype);
+ virtual ~Error() override = default;
};
#define DECLARE_ERROR_SUBCLASS(ClassName, snake_name, PrototypeName, ConstructorName) \
@@ -55,10 +47,10 @@ private:
JS_OBJECT(ClassName, Error); \
\
public: \
- static ClassName* create(GlobalObject&, const String& message); \
+ static ClassName* create(GlobalObject&, const String& message = {}); \
\
- ClassName(const String& message, Object& prototype); \
- virtual ~ClassName() override; \
+ explicit ClassName(Object& prototype); \
+ virtual ~ClassName() override = default; \
};
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \