From c503a28e192958028f46cfa21225df51c986d8ba Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Wed, 23 Jun 2021 13:59:17 +0100 Subject: [PATCH] LibJS: Make AggregateError inherit from Error This is our way of implementing the [[ErrorData]] internal slot, which is being used in Object.prototype.toString(). --- Userland/Libraries/LibJS/Runtime/AggregateError.cpp | 4 ++-- Userland/Libraries/LibJS/Runtime/AggregateError.h | 5 +++-- .../LibJS/Tests/builtins/Object/Object.prototype.toString.js | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/AggregateError.cpp b/Userland/Libraries/LibJS/Runtime/AggregateError.cpp index 98e62fe894..3048d5262e 100644 --- a/Userland/Libraries/LibJS/Runtime/AggregateError.cpp +++ b/Userland/Libraries/LibJS/Runtime/AggregateError.cpp @@ -5,7 +5,7 @@ */ #include -#include +#include #include namespace JS { @@ -16,7 +16,7 @@ AggregateError* AggregateError::create(GlobalObject& global_object) } AggregateError::AggregateError(Object& prototype) - : Object(prototype) + : Error(prototype) { } diff --git a/Userland/Libraries/LibJS/Runtime/AggregateError.h b/Userland/Libraries/LibJS/Runtime/AggregateError.h index 390a5ee520..85133fdede 100644 --- a/Userland/Libraries/LibJS/Runtime/AggregateError.h +++ b/Userland/Libraries/LibJS/Runtime/AggregateError.h @@ -6,12 +6,13 @@ #pragma once +#include #include namespace JS { -class AggregateError : public Object { - JS_OBJECT(AggregateError, Object); +class AggregateError : public Error { + JS_OBJECT(AggregateError, Error); public: static AggregateError* create(GlobalObject&); diff --git a/Userland/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toString.js b/Userland/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toString.js index 5bdd157de4..fc16b9984d 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toString.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toString.js @@ -10,6 +10,8 @@ test("result for various object types", () => { expect(oToString([])).toBe("[object Array]"); expect(oToString(function () {})).toBe("[object Function]"); expect(oToString(new Error())).toBe("[object Error]"); + expect(oToString(new TypeError())).toBe("[object Error]"); + expect(oToString(new AggregateError([]))).toBe("[object Error]"); expect(oToString(new Boolean())).toBe("[object Boolean]"); expect(oToString(new Number())).toBe("[object Number]"); expect(oToString(new Date())).toBe("[object Date]");