mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:47:44 +00:00
LibJS: Convert Error::create() to NonnullGCPtr
This commit is contained in:
parent
73efdb1cc4
commit
d21ac9d820
5 changed files with 41 additions and 41 deletions
|
@ -3391,7 +3391,7 @@ Completion ImportCall::execute(Interpreter& interpreter) const
|
||||||
if (!options_value.is_undefined()) {
|
if (!options_value.is_undefined()) {
|
||||||
// a. If Type(options) is not Object,
|
// a. If Type(options) is not Object,
|
||||||
if (!options_value.is_object()) {
|
if (!options_value.is_object()) {
|
||||||
auto* error = TypeError::create(realm, DeprecatedString::formatted(ErrorType::NotAnObject.message(), "ImportOptions"));
|
auto error = TypeError::create(realm, DeprecatedString::formatted(ErrorType::NotAnObject.message(), "ImportOptions"));
|
||||||
// i. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
|
// i. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
|
||||||
MUST(call(vm, *promise_capability->reject(), js_undefined(), error));
|
MUST(call(vm, *promise_capability->reject(), js_undefined(), error));
|
||||||
|
|
||||||
|
@ -3407,7 +3407,7 @@ Completion ImportCall::execute(Interpreter& interpreter) const
|
||||||
if (!assertion_object.is_undefined()) {
|
if (!assertion_object.is_undefined()) {
|
||||||
// i. If Type(assertionsObj) is not Object,
|
// i. If Type(assertionsObj) is not Object,
|
||||||
if (!assertion_object.is_object()) {
|
if (!assertion_object.is_object()) {
|
||||||
auto* error = TypeError::create(realm, DeprecatedString::formatted(ErrorType::NotAnObject.message(), "ImportOptionsAssertions"));
|
auto error = TypeError::create(realm, DeprecatedString::formatted(ErrorType::NotAnObject.message(), "ImportOptionsAssertions"));
|
||||||
// 1. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
|
// 1. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
|
||||||
MUST(call(vm, *promise_capability->reject(), js_undefined(), error));
|
MUST(call(vm, *promise_capability->reject(), js_undefined(), error));
|
||||||
|
|
||||||
|
@ -3432,7 +3432,7 @@ Completion ImportCall::execute(Interpreter& interpreter) const
|
||||||
|
|
||||||
// 3. If Type(value) is not String, then
|
// 3. If Type(value) is not String, then
|
||||||
if (!value.is_string()) {
|
if (!value.is_string()) {
|
||||||
auto* error = TypeError::create(realm, DeprecatedString::formatted(ErrorType::NotAString.message(), "Import Assertion option value"));
|
auto error = TypeError::create(realm, DeprecatedString::formatted(ErrorType::NotAString.message(), "Import Assertion option value"));
|
||||||
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
|
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
|
||||||
MUST(call(vm, *promise_capability->reject(), js_undefined(), error));
|
MUST(call(vm, *promise_capability->reject(), js_undefined(), error));
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::return_)
|
||||||
|
|
||||||
// 11. If Type(result) is not Object, then
|
// 11. If Type(result) is not Object, then
|
||||||
if (!result.is_object()) {
|
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 »).
|
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
|
||||||
MUST(call(vm, *promise_capability->reject(), js_undefined(), error));
|
MUST(call(vm, *promise_capability->reject(), js_undefined(), error));
|
||||||
// b. Return promiseCapability.[[Promise]].
|
// b. Return promiseCapability.[[Promise]].
|
||||||
|
@ -183,7 +183,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::throw_)
|
||||||
|
|
||||||
// 11. If Type(result) is not Object, then
|
// 11. If Type(result) is not Object, then
|
||||||
if (!result.is_object()) {
|
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 »).
|
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
|
||||||
MUST(call(vm, *promise_capability->reject(), js_undefined(), error));
|
MUST(call(vm, *promise_capability->reject(), js_undefined(), error));
|
||||||
|
|
||||||
|
|
|
@ -14,15 +14,15 @@
|
||||||
|
|
||||||
namespace JS {
|
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& vm = realm.vm();
|
||||||
auto* error = Error::create(realm);
|
auto error = Error::create(realm);
|
||||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||||
error->define_direct_property(vm.names.message, PrimitiveString::create(vm, message), attr);
|
error->define_direct_property(vm.names.message, PrimitiveString::create(vm, message), attr);
|
||||||
return error;
|
return error;
|
||||||
|
@ -98,24 +98,24 @@ DeprecatedString Error::stack_string() const
|
||||||
return stack_string_builder.build();
|
return stack_string_builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
||||||
ClassName* ClassName::create(Realm& realm) \
|
NonnullGCPtr<ClassName> ClassName::create(Realm& realm) \
|
||||||
{ \
|
{ \
|
||||||
return realm.heap().allocate<ClassName>(realm, *realm.intrinsics().snake_name##_prototype()); \
|
return *realm.heap().allocate<ClassName>(realm, *realm.intrinsics().snake_name##_prototype()); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
ClassName* ClassName::create(Realm& realm, DeprecatedString const& message) \
|
NonnullGCPtr<ClassName> ClassName::create(Realm& realm, DeprecatedString const& message) \
|
||||||
{ \
|
{ \
|
||||||
auto& vm = realm.vm(); \
|
auto& vm = realm.vm(); \
|
||||||
auto* error = ClassName::create(realm); \
|
auto error = ClassName::create(realm); \
|
||||||
u8 attr = Attribute::Writable | Attribute::Configurable; \
|
u8 attr = Attribute::Writable | Attribute::Configurable; \
|
||||||
error->define_direct_property(vm.names.message, PrimitiveString::create(vm, message), attr); \
|
error->define_direct_property(vm.names.message, PrimitiveString::create(vm, message), attr); \
|
||||||
return error; \
|
return error; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
ClassName::ClassName(Object& prototype) \
|
ClassName::ClassName(Object& prototype) \
|
||||||
: Error(prototype) \
|
: Error(prototype) \
|
||||||
{ \
|
{ \
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_ENUMERATE_NATIVE_ERRORS
|
JS_ENUMERATE_NATIVE_ERRORS
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
* 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
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -23,8 +23,8 @@ class Error : public Object {
|
||||||
JS_OBJECT(Error, Object);
|
JS_OBJECT(Error, Object);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static Error* create(Realm&);
|
static NonnullGCPtr<Error> create(Realm&);
|
||||||
static Error* create(Realm&, DeprecatedString const& message);
|
static NonnullGCPtr<Error> create(Realm&, DeprecatedString const& message);
|
||||||
|
|
||||||
virtual ~Error() override = default;
|
virtual ~Error() override = default;
|
||||||
|
|
||||||
|
@ -45,16 +45,16 @@ private:
|
||||||
// NOTE: Making these inherit from Error is not required by the spec but
|
// NOTE: Making these inherit from Error is not required by the spec but
|
||||||
// our way of implementing the [[ErrorData]] internal slot, which is
|
// our way of implementing the [[ErrorData]] internal slot, which is
|
||||||
// used in Object.prototype.toString().
|
// used in Object.prototype.toString().
|
||||||
#define DECLARE_NATIVE_ERROR(ClassName, snake_name, PrototypeName, ConstructorName) \
|
#define DECLARE_NATIVE_ERROR(ClassName, snake_name, PrototypeName, ConstructorName) \
|
||||||
class ClassName final : public Error { \
|
class ClassName final : public Error { \
|
||||||
JS_OBJECT(ClassName, Error); \
|
JS_OBJECT(ClassName, Error); \
|
||||||
\
|
\
|
||||||
public: \
|
public: \
|
||||||
static ClassName* create(Realm&); \
|
static NonnullGCPtr<ClassName> create(Realm&); \
|
||||||
static ClassName* create(Realm&, DeprecatedString const& message); \
|
static NonnullGCPtr<ClassName> create(Realm&, DeprecatedString const& message); \
|
||||||
\
|
\
|
||||||
explicit ClassName(Object& prototype); \
|
explicit ClassName(Object& prototype); \
|
||||||
virtual ~ClassName() override = default; \
|
virtual ~ClassName() override = default; \
|
||||||
};
|
};
|
||||||
|
|
||||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
||||||
|
|
|
@ -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);
|
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.
|
// 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).
|
// b. Perform RejectPromise(promise, selfResolutionError).
|
||||||
promise.reject(self_resolution_error);
|
promise.reject(self_resolution_error);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue