Skip to content

Commit 8468178

Browse files
committed
LibJS: Convert FinalizationRegistryPrototype funcs to ThrowCompletionOr
1 parent 909e13c commit 8468178

File tree

2 files changed

+22
-32
lines changed

2 files changed

+22
-32
lines changed

Userland/Libraries/LibJS/Runtime/FinalizationRegistryPrototype.cpp

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ void FinalizationRegistryPrototype::initialize(GlobalObject& global_object)
2020
Object::initialize(global_object);
2121
u8 attr = Attribute::Writable | Attribute::Configurable;
2222

23-
define_old_native_function(vm.names.cleanupSome, cleanup_some, 0, attr);
24-
define_old_native_function(vm.names.register_, register_, 2, attr);
25-
define_old_native_function(vm.names.unregister, unregister, 1, attr);
23+
define_native_function(vm.names.cleanupSome, cleanup_some, 0, attr);
24+
define_native_function(vm.names.register_, register_, 2, attr);
25+
define_native_function(vm.names.unregister, unregister, 1, attr);
2626

2727
// 26.2.3.4 FinalizationRegistry.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-finalization-registry.prototype-@@tostringtag
2828
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), vm.names.FinalizationRegistry.as_string()), Attribute::Configurable);
@@ -33,59 +33,49 @@ FinalizationRegistryPrototype::~FinalizationRegistryPrototype()
3333
}
3434

3535
// @STAGE 2@ FinalizationRegistry.prototype.cleanupSome ( [ callback ] ), https://github.com/tc39/proposal-cleanup-some/blob/master/spec/finalization-registry.html
36-
JS_DEFINE_OLD_NATIVE_FUNCTION(FinalizationRegistryPrototype::cleanup_some)
36+
JS_DEFINE_NATIVE_FUNCTION(FinalizationRegistryPrototype::cleanup_some)
3737
{
38-
auto* finalization_registry = TRY_OR_DISCARD(typed_this_object(global_object));
38+
auto* finalization_registry = TRY(typed_this_object(global_object));
3939

4040
auto callback = vm.argument(0);
41-
if (vm.argument_count() > 0 && !callback.is_function()) {
42-
vm.throw_exception<TypeError>(global_object, ErrorType::NotAFunction, callback.to_string_without_side_effects());
43-
return {};
44-
}
41+
if (vm.argument_count() > 0 && !callback.is_function())
42+
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAFunction, callback.to_string_without_side_effects());
4543

4644
finalization_registry->cleanup(callback.is_undefined() ? nullptr : &callback.as_function());
4745

4846
return js_undefined();
4947
}
5048

5149
// 26.2.3.2 FinalizationRegistry.prototype.register ( target, heldValue [ , unregisterToken ] ), https://tc39.es/ecma262/#sec-finalization-registry.prototype.register
52-
JS_DEFINE_OLD_NATIVE_FUNCTION(FinalizationRegistryPrototype::register_)
50+
JS_DEFINE_NATIVE_FUNCTION(FinalizationRegistryPrototype::register_)
5351
{
54-
auto* finalization_registry = TRY_OR_DISCARD(typed_this_object(global_object));
52+
auto* finalization_registry = TRY(typed_this_object(global_object));
5553

5654
auto target = vm.argument(0);
57-
if (!target.is_object()) {
58-
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObject, target.to_string_without_side_effects());
59-
return {};
60-
}
55+
if (!target.is_object())
56+
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAnObject, target.to_string_without_side_effects());
6157

6258
auto held_value = vm.argument(1);
63-
if (same_value(target, held_value)) {
64-
vm.throw_exception<TypeError>(global_object, ErrorType::FinalizationRegistrySameTargetAndValue);
65-
return {};
66-
}
59+
if (same_value(target, held_value))
60+
return vm.throw_completion<TypeError>(global_object, ErrorType::FinalizationRegistrySameTargetAndValue);
6761

6862
auto unregister_token = vm.argument(2);
69-
if (!unregister_token.is_object() && !unregister_token.is_undefined()) {
70-
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObject, unregister_token.to_string_without_side_effects());
71-
return {};
72-
}
63+
if (!unregister_token.is_object() && !unregister_token.is_undefined())
64+
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAnObject, unregister_token.to_string_without_side_effects());
7365

7466
finalization_registry->add_finalization_record(target.as_cell(), held_value, unregister_token.is_undefined() ? nullptr : &unregister_token.as_object());
7567

7668
return js_undefined();
7769
}
7870

7971
// 26.2.3.3 FinalizationRegistry.prototype.unregister ( unregisterToken ), https://tc39.es/ecma262/#sec-finalization-registry.prototype.unregister
80-
JS_DEFINE_OLD_NATIVE_FUNCTION(FinalizationRegistryPrototype::unregister)
72+
JS_DEFINE_NATIVE_FUNCTION(FinalizationRegistryPrototype::unregister)
8173
{
82-
auto* finalization_registry = TRY_OR_DISCARD(typed_this_object(global_object));
74+
auto* finalization_registry = TRY(typed_this_object(global_object));
8375

8476
auto unregister_token = vm.argument(0);
85-
if (!unregister_token.is_object()) {
86-
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObject, unregister_token.to_string_without_side_effects());
87-
return {};
88-
}
77+
if (!unregister_token.is_object())
78+
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAnObject, unregister_token.to_string_without_side_effects());
8979

9080
return Value(finalization_registry->remove_by_token(unregister_token.as_object()));
9181
}

Userland/Libraries/LibJS/Runtime/FinalizationRegistryPrototype.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ class FinalizationRegistryPrototype final : public PrototypeObject<FinalizationR
2020
virtual ~FinalizationRegistryPrototype() override;
2121

2222
private:
23-
JS_DECLARE_OLD_NATIVE_FUNCTION(cleanup_some);
24-
JS_DECLARE_OLD_NATIVE_FUNCTION(register_);
25-
JS_DECLARE_OLD_NATIVE_FUNCTION(unregister);
23+
JS_DECLARE_NATIVE_FUNCTION(cleanup_some);
24+
JS_DECLARE_NATIVE_FUNCTION(register_);
25+
JS_DECLARE_NATIVE_FUNCTION(unregister);
2626
};
2727

2828
}

0 commit comments

Comments
 (0)