diff options
author | Linus Groh <mail@linusgroh.de> | 2022-12-13 20:49:50 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-12-14 09:59:45 +0000 |
commit | d21ac9d820e18bca0e46164d93381467ec2eab5e (patch) | |
tree | 3497d9a72a9157b847c83b49c6c3e22281e19a5e /Userland/Libraries/LibJS/Runtime | |
parent | 73efdb1cc4b0b7e64f8a876d1790592a0ec1eb67 (diff) | |
download | serenity-d21ac9d820e18bca0e46164d93381467ec2eab5e.zip |
LibJS: Convert Error::create() to NonnullGCPtr
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Error.cpp | 44 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Error.h | 26 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Promise.cpp | 2 |
4 files changed, 38 insertions, 38 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp index 4a06c9deda..9645d91bd9 100644 --- a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp @@ -135,7 +135,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::return_) // 11. If Type(result) is not Object, then if (!result.is_object()) { - auto* error = TypeError::create(realm, DeprecatedString::formatted(ErrorType::NotAnObject.message(), "SyncIteratorReturnResult")); + auto error = TypeError::create(realm, DeprecatedString::formatted(ErrorType::NotAnObject.message(), "SyncIteratorReturnResult")); // a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »). MUST(call(vm, *promise_capability->reject(), js_undefined(), error)); // b. Return promiseCapability.[[Promise]]. @@ -183,7 +183,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::throw_) // 11. If Type(result) is not Object, then if (!result.is_object()) { - auto* error = TypeError::create(realm, DeprecatedString::formatted(ErrorType::NotAnObject.message(), "SyncIteratorThrowResult")); + auto error = TypeError::create(realm, DeprecatedString::formatted(ErrorType::NotAnObject.message(), "SyncIteratorThrowResult")); // a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »). MUST(call(vm, *promise_capability->reject(), js_undefined(), error)); diff --git a/Userland/Libraries/LibJS/Runtime/Error.cpp b/Userland/Libraries/LibJS/Runtime/Error.cpp index 2579c35740..c5052d6cca 100644 --- a/Userland/Libraries/LibJS/Runtime/Error.cpp +++ b/Userland/Libraries/LibJS/Runtime/Error.cpp @@ -14,15 +14,15 @@ namespace JS { -Error* Error::create(Realm& realm) +NonnullGCPtr<Error> Error::create(Realm& realm) { - return realm.heap().allocate<Error>(realm, *realm.intrinsics().error_prototype()); + return *realm.heap().allocate<Error>(realm, *realm.intrinsics().error_prototype()); } -Error* Error::create(Realm& realm, DeprecatedString const& message) +NonnullGCPtr<Error> Error::create(Realm& realm, DeprecatedString const& message) { auto& vm = realm.vm(); - auto* error = Error::create(realm); + auto error = Error::create(realm); u8 attr = Attribute::Writable | Attribute::Configurable; error->define_direct_property(vm.names.message, PrimitiveString::create(vm, message), attr); return error; @@ -98,24 +98,24 @@ DeprecatedString Error::stack_string() const return stack_string_builder.build(); } -#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ - ClassName* ClassName::create(Realm& realm) \ - { \ - return realm.heap().allocate<ClassName>(realm, *realm.intrinsics().snake_name##_prototype()); \ - } \ - \ - ClassName* ClassName::create(Realm& realm, DeprecatedString const& message) \ - { \ - auto& vm = realm.vm(); \ - auto* error = ClassName::create(realm); \ - u8 attr = Attribute::Writable | Attribute::Configurable; \ - error->define_direct_property(vm.names.message, PrimitiveString::create(vm, message), attr); \ - return error; \ - } \ - \ - ClassName::ClassName(Object& prototype) \ - : Error(prototype) \ - { \ +#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ + NonnullGCPtr<ClassName> ClassName::create(Realm& realm) \ + { \ + return *realm.heap().allocate<ClassName>(realm, *realm.intrinsics().snake_name##_prototype()); \ + } \ + \ + NonnullGCPtr<ClassName> ClassName::create(Realm& realm, DeprecatedString const& message) \ + { \ + auto& vm = realm.vm(); \ + auto error = ClassName::create(realm); \ + u8 attr = Attribute::Writable | Attribute::Configurable; \ + error->define_direct_property(vm.names.message, PrimitiveString::create(vm, message), attr); \ + return error; \ + } \ + \ + ClassName::ClassName(Object& prototype) \ + : Error(prototype) \ + { \ } JS_ENUMERATE_NATIVE_ERRORS diff --git a/Userland/Libraries/LibJS/Runtime/Error.h b/Userland/Libraries/LibJS/Runtime/Error.h index 80981ff81e..994aa76759 100644 --- a/Userland/Libraries/LibJS/Runtime/Error.h +++ b/Userland/Libraries/LibJS/Runtime/Error.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> - * Copyright (c) 2021, Linus Groh <linusg@serenityos.org> + * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -23,8 +23,8 @@ class Error : public Object { JS_OBJECT(Error, Object); public: - static Error* create(Realm&); - static Error* create(Realm&, DeprecatedString const& message); + static NonnullGCPtr<Error> create(Realm&); + static NonnullGCPtr<Error> create(Realm&, DeprecatedString const& message); virtual ~Error() override = default; @@ -45,16 +45,16 @@ private: // NOTE: Making these inherit from Error is not required by the spec but // our way of implementing the [[ErrorData]] internal slot, which is // used in Object.prototype.toString(). -#define DECLARE_NATIVE_ERROR(ClassName, snake_name, PrototypeName, ConstructorName) \ - class ClassName final : public Error { \ - JS_OBJECT(ClassName, Error); \ - \ - public: \ - static ClassName* create(Realm&); \ - static ClassName* create(Realm&, DeprecatedString const& message); \ - \ - explicit ClassName(Object& prototype); \ - virtual ~ClassName() override = default; \ +#define DECLARE_NATIVE_ERROR(ClassName, snake_name, PrototypeName, ConstructorName) \ + class ClassName final : public Error { \ + JS_OBJECT(ClassName, Error); \ + \ + public: \ + static NonnullGCPtr<ClassName> create(Realm&); \ + static NonnullGCPtr<ClassName> create(Realm&, DeprecatedString const& message); \ + \ + explicit ClassName(Object& prototype); \ + virtual ~ClassName() override = default; \ }; #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ diff --git a/Userland/Libraries/LibJS/Runtime/Promise.cpp b/Userland/Libraries/LibJS/Runtime/Promise.cpp index daee59051d..3d62d1fa42 100644 --- a/Userland/Libraries/LibJS/Runtime/Promise.cpp +++ b/Userland/Libraries/LibJS/Runtime/Promise.cpp @@ -97,7 +97,7 @@ Promise::ResolvingFunctions Promise::create_resolving_functions() dbgln_if(PROMISE_DEBUG, "[Promise @ {} / PromiseResolvingFunction]: Promise can't be resolved with itself, rejecting with error", &promise); // a. Let selfResolutionError be a newly created TypeError object. - auto* self_resolution_error = TypeError::create(realm, "Cannot resolve promise with itself"); + auto self_resolution_error = TypeError::create(realm, "Cannot resolve promise with itself"); // b. Perform RejectPromise(promise, selfResolutionError). promise.reject(self_resolution_error); |