summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-12-13 20:49:50 +0000
committerLinus Groh <mail@linusgroh.de>2022-12-14 09:59:45 +0000
commitb42e293ddda5810578b5e1f3f5d3eb2ef0a1864c (patch)
tree2fc5ef0a00cbfaa0efee58e05f5c1e24b26c1ac9 /Userland
parent9846d23c79f97d7a14a9ebc38483de1414941693 (diff)
downloadserenity-b42e293ddda5810578b5e1f3f5d3eb2ef0a1864c.zip
LibJS: Convert NativeFunction::create() to NonnullGCPtr
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/CyclicModule.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Completion.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/NativeFunction.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/NativeFunction.h4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Object.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseCapability.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/VM.cpp4
-rw-r--r--Userland/Libraries/LibWeb/WebIDL/Promise.cpp4
13 files changed, 23 insertions, 23 deletions
diff --git a/Userland/Libraries/LibJS/CyclicModule.cpp b/Userland/Libraries/LibJS/CyclicModule.cpp
index 4ec4565f40..abea38be05 100644
--- a/Userland/Libraries/LibJS/CyclicModule.cpp
+++ b/Userland/Libraries/LibJS/CyclicModule.cpp
@@ -473,7 +473,7 @@ void CyclicModule::execute_async_module(VM& vm)
};
// 5. Let onFulfilled be CreateBuiltinFunction(fulfilledClosure, 0, "", « »).
- auto* on_fulfilled = NativeFunction::create(realm, move(fulfilled_closure), 0, "");
+ auto on_fulfilled = NativeFunction::create(realm, move(fulfilled_closure), 0, "");
// 6. Let rejectedClosure be a new Abstract Closure with parameters (error) that captures module and performs the following steps when called:
auto rejected_closure = [&](VM& vm) -> ThrowCompletionOr<Value> {
@@ -487,7 +487,7 @@ void CyclicModule::execute_async_module(VM& vm)
};
// 7. Let onRejected be CreateBuiltinFunction(rejectedClosure, 0, "", « »).
- auto* on_rejected = NativeFunction::create(realm, move(rejected_closure), 0, "");
+ auto on_rejected = NativeFunction::create(realm, move(rejected_closure), 0, "");
// 8. Perform PerformPromiseThen(capability.[[Promise]], onFulfilled, onRejected).
verify_cast<Promise>(capability->promise().ptr())->perform_then(on_fulfilled, on_rejected, {});
diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp
index 9645d91bd9..0b5e38bf60 100644
--- a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp
@@ -56,7 +56,7 @@ static Object* async_from_sync_iterator_continuation(VM& vm, Object& result, Pro
// 9. Let onFulfilled be CreateBuiltinFunction(unwrap, 1, "", « »).
// 10. NOTE: onFulfilled is used when processing the "value" property of an IteratorResult object in order to wait for its value if it is a promise and re-package the result in a new "unwrapped" IteratorResult object.
- auto* on_fulfilled = NativeFunction::create(realm, move(unwrap), 1, "");
+ auto on_fulfilled = NativeFunction::create(realm, move(unwrap), 1, "");
// 11. Perform PerformPromiseThen(valueWrapper, onFulfilled, undefined, promiseCapability).
verify_cast<Promise>(value_wrapper)->perform_then(move(on_fulfilled), js_undefined(), &promise_capability);
diff --git a/Userland/Libraries/LibJS/Runtime/Completion.cpp b/Userland/Libraries/LibJS/Runtime/Completion.cpp
index f09ac80125..3b1db9a70b 100644
--- a/Userland/Libraries/LibJS/Runtime/Completion.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Completion.cpp
@@ -62,7 +62,7 @@ ThrowCompletionOr<Value> await(VM& vm, Value value)
};
// 4. Let onFulfilled be CreateBuiltinFunction(fulfilledClosure, 1, "", « »).
- auto* on_fulfilled = NativeFunction::create(realm, move(fulfilled_closure), 1, "");
+ auto on_fulfilled = NativeFunction::create(realm, move(fulfilled_closure), 1, "");
// 5. Let rejectedClosure be a new Abstract Closure with parameters (reason) that captures asyncContext and performs the following steps when called:
auto rejected_closure = [&success, &result](VM& vm) -> ThrowCompletionOr<Value> {
@@ -86,7 +86,7 @@ ThrowCompletionOr<Value> await(VM& vm, Value value)
};
// 6. Let onRejected be CreateBuiltinFunction(rejectedClosure, 1, "", « »).
- auto* on_rejected = NativeFunction::create(realm, move(rejected_closure), 1, "");
+ auto on_rejected = NativeFunction::create(realm, move(rejected_closure), 1, "");
// 7. Perform PerformPromiseThen(promise, onFulfilled, onRejected).
auto* promise = verify_cast<Promise>(promise_object);
diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp
index ad933ebb8f..04c6e90766 100644
--- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp
@@ -736,7 +736,7 @@ void async_block_start(VM& vm, NonnullRefPtr<Statement> const& async_body, Promi
auto& running_context = vm.running_execution_context();
// 3. Set the code evaluation state of asyncContext such that when evaluation is resumed for that execution context the following steps will be performed:
- auto* execution_steps = NativeFunction::create(realm, "", [&async_body, &promise_capability](auto& vm) -> ThrowCompletionOr<Value> {
+ auto execution_steps = NativeFunction::create(realm, "", [&async_body, &promise_capability](auto& vm) -> ThrowCompletionOr<Value> {
// a. Let result be the result of evaluating asyncBody.
auto result = async_body->execute(vm.interpreter());
diff --git a/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp b/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp
index ddc0bed9b9..8a50e3ad3c 100644
--- a/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp
+++ b/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp
@@ -16,7 +16,7 @@ namespace JS {
// 10.3.3 CreateBuiltinFunction ( behaviour, length, name, additionalInternalSlotsList [ , realm [ , prototype [ , prefix ] ] ] ), https://tc39.es/ecma262/#sec-createbuiltinfunction
// NOTE: This doesn't consider additionalInternalSlotsList, which is rarely used, and can either be implemented using only the `function` lambda, or needs a NativeFunction subclass.
-NativeFunction* NativeFunction::create(Realm& allocating_realm, SafeFunction<ThrowCompletionOr<Value>(VM&)> behaviour, i32 length, PropertyKey const& name, Optional<Realm*> realm, Optional<Object*> prototype, Optional<StringView> const& prefix)
+NonnullGCPtr<NativeFunction> NativeFunction::create(Realm& allocating_realm, SafeFunction<ThrowCompletionOr<Value>(VM&)> behaviour, i32 length, PropertyKey const& name, Optional<Realm*> realm, Optional<Object*> prototype, Optional<StringView> const& prefix)
{
auto& vm = allocating_realm.vm();
@@ -48,12 +48,12 @@ NativeFunction* NativeFunction::create(Realm& allocating_realm, SafeFunction<Thr
function->set_function_name(name, prefix);
// 13. Return func.
- return function;
+ return *function;
}
-NativeFunction* NativeFunction::create(Realm& realm, FlyString const& name, SafeFunction<ThrowCompletionOr<Value>(VM&)> function)
+NonnullGCPtr<NativeFunction> NativeFunction::create(Realm& realm, FlyString const& name, SafeFunction<ThrowCompletionOr<Value>(VM&)> function)
{
- return realm.heap().allocate<NativeFunction>(realm, name, move(function), *realm.intrinsics().function_prototype());
+ return *realm.heap().allocate<NativeFunction>(realm, name, move(function), *realm.intrinsics().function_prototype());
}
NativeFunction::NativeFunction(SafeFunction<ThrowCompletionOr<Value>(VM&)> native_function, Object* prototype, Realm& realm)
diff --git a/Userland/Libraries/LibJS/Runtime/NativeFunction.h b/Userland/Libraries/LibJS/Runtime/NativeFunction.h
index 4e15d89bf5..b436412922 100644
--- a/Userland/Libraries/LibJS/Runtime/NativeFunction.h
+++ b/Userland/Libraries/LibJS/Runtime/NativeFunction.h
@@ -20,8 +20,8 @@ class NativeFunction : public FunctionObject {
JS_OBJECT(NativeFunction, FunctionObject);
public:
- static NativeFunction* create(Realm&, SafeFunction<ThrowCompletionOr<Value>(VM&)> behaviour, i32 length, PropertyKey const& name, Optional<Realm*> = {}, Optional<Object*> prototype = {}, Optional<StringView> const& prefix = {});
- static NativeFunction* create(Realm&, FlyString const& name, SafeFunction<ThrowCompletionOr<Value>(VM&)>);
+ static NonnullGCPtr<NativeFunction> create(Realm&, SafeFunction<ThrowCompletionOr<Value>(VM&)> behaviour, i32 length, PropertyKey const& name, Optional<Realm*> = {}, Optional<Object*> prototype = {}, Optional<StringView> const& prefix = {});
+ static NonnullGCPtr<NativeFunction> create(Realm&, FlyString const& name, SafeFunction<ThrowCompletionOr<Value>(VM&)>);
virtual void initialize(Realm&) override { }
virtual ~NativeFunction() override = default;
diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp
index d9e626c976..249d94e083 100644
--- a/Userland/Libraries/LibJS/Runtime/Object.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Object.cpp
@@ -1191,7 +1191,7 @@ Value Object::get_without_side_effects(PropertyKey const& property_key) const
void Object::define_native_function(Realm& realm, PropertyKey const& property_key, SafeFunction<ThrowCompletionOr<Value>(VM&)> native_function, i32 length, PropertyAttributes attribute)
{
- auto* function = NativeFunction::create(realm, move(native_function), length, property_key, &realm);
+ auto function = NativeFunction::create(realm, move(native_function), length, property_key, &realm);
define_direct_property(property_key, function, attribute);
}
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseCapability.cpp b/Userland/Libraries/LibJS/Runtime/PromiseCapability.cpp
index 91ac594792..0d57ea1f08 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseCapability.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PromiseCapability.cpp
@@ -75,7 +75,7 @@ ThrowCompletionOr<NonnullGCPtr<PromiseCapability>> new_promise_capability(VM& vm
};
// 5. Let executor be CreateBuiltinFunction(executorClosure, 2, "", « »).
- auto* executor = NativeFunction::create(realm, move(executor_closure), 2, "");
+ auto executor = NativeFunction::create(realm, move(executor_closure), 2, "");
// 6. Let promise be ? Construct(C, « executor »).
auto* promise = TRY(construct(vm, constructor.as_function(), executor));
diff --git a/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp b/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp
index ff349e8e00..fd0b05f543 100644
--- a/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp
@@ -122,7 +122,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
};
// iv. Let valueThunk be CreateBuiltinFunction(returnValue, 0, "", « »).
- auto* value_thunk = NativeFunction::create(realm, move(return_value), 0, "");
+ auto value_thunk = NativeFunction::create(realm, move(return_value), 0, "");
// v. Return ? Invoke(promise, "then", « valueThunk »).
return TRY(Value(promise).invoke(vm, vm.names.then, value_thunk));
@@ -151,7 +151,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
};
// iv. Let thrower be CreateBuiltinFunction(throwReason, 0, "", « »).
- auto* thrower = NativeFunction::create(realm, move(throw_reason), 0, "");
+ auto thrower = NativeFunction::create(realm, move(throw_reason), 0, "");
// v. Return ? Invoke(promise, "then", « thrower »).
return TRY(Value(promise).invoke(vm, vm.names.then, thrower));
diff --git a/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp
index f6d351330c..55a56f50c4 100644
--- a/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp
@@ -84,7 +84,7 @@ JS_DEFINE_NATIVE_FUNCTION(ProxyConstructor::revocable)
// 3. Let revoker be CreateBuiltinFunction(revokerClosure, 0, "", « [[RevocableProxy]] »).
// 4. Set revoker.[[RevocableProxy]] to p.
- auto* revoker = NativeFunction::create(realm, move(revoker_closure), 0, "");
+ auto revoker = NativeFunction::create(realm, move(revoker_closure), 0, "");
// 5. Let result be OrdinaryObjectCreate(%Object.prototype%).
auto* result = Object::create(realm, realm.intrinsics().object_prototype());
diff --git a/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp b/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp
index cc5d552410..fcf1943506 100644
--- a/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp
@@ -264,14 +264,14 @@ ThrowCompletionOr<Value> shadow_realm_import_value(VM& vm, DeprecatedString spec
// 10. Let onFulfilled be CreateBuiltinFunction(steps, 1, "", « [[ExportNameString]] », callerRealm).
// 11. Set onFulfilled.[[ExportNameString]] to exportNameString.
- auto* on_fulfilled = NativeFunction::create(realm, move(steps), 1, "", &caller_realm);
+ auto on_fulfilled = NativeFunction::create(realm, move(steps), 1, "", &caller_realm);
// 12. Let promiseCapability be ! NewPromiseCapability(%Promise%).
auto promise_capability = MUST(new_promise_capability(vm, realm.intrinsics().promise_constructor()));
// NOTE: Even though the spec tells us to use %ThrowTypeError%, it's not observable if we actually do.
// Throw a nicer TypeError forwarding the import error message instead (we know the argument is an Error object).
- auto* throw_type_error = NativeFunction::create(realm, {}, [](auto& vm) -> ThrowCompletionOr<Value> {
+ auto throw_type_error = NativeFunction::create(realm, {}, [](auto& vm) -> ThrowCompletionOr<Value> {
return vm.template throw_completion<TypeError>(vm.argument(0).as_object().get_without_side_effects(vm.names.message).as_string().deprecated_string());
});
diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp
index 9b91ad1442..4b6620098e 100644
--- a/Userland/Libraries/LibJS/Runtime/VM.cpp
+++ b/Userland/Libraries/LibJS/Runtime/VM.cpp
@@ -1043,7 +1043,7 @@ void VM::finish_dynamic_import(ScriptOrModule referencing_script_or_module, Modu
};
// 2. Let onFulfilled be CreateBuiltinFunction(fulfilledClosure, 0, "", « »).
- auto* on_fulfilled = NativeFunction::create(realm, move(fulfilled_closure), 0, "");
+ auto on_fulfilled = NativeFunction::create(realm, move(fulfilled_closure), 0, "");
// 3. Let rejectedClosure be a new Abstract Closure with parameters (error) that captures promiseCapability and performs the following steps when called:
auto rejected_closure = [&promise_capability](VM& vm) -> ThrowCompletionOr<Value> {
@@ -1057,7 +1057,7 @@ void VM::finish_dynamic_import(ScriptOrModule referencing_script_or_module, Modu
};
// 4. Let onRejected be CreateBuiltinFunction(rejectedClosure, 0, "", « »).
- auto* on_rejected = NativeFunction::create(realm, move(rejected_closure), 0, "");
+ auto on_rejected = NativeFunction::create(realm, move(rejected_closure), 0, "");
// 5. Perform PerformPromiseThen(innerPromise, onFulfilled, onRejected).
inner_promise->perform_then(on_fulfilled, on_rejected, {});
diff --git a/Userland/Libraries/LibWeb/WebIDL/Promise.cpp b/Userland/Libraries/LibWeb/WebIDL/Promise.cpp
index 795fac1bc9..bf98fcda24 100644
--- a/Userland/Libraries/LibWeb/WebIDL/Promise.cpp
+++ b/Userland/Libraries/LibWeb/WebIDL/Promise.cpp
@@ -108,7 +108,7 @@ JS::NonnullGCPtr<JS::Promise> react_to_promise(JS::PromiseCapability const& prom
};
// 2. Let onFulfilled be CreateBuiltinFunction(onFulfilledSteps, « »):
- auto* on_fulfilled = JS::NativeFunction::create(realm, move(on_fulfilled_steps), 1, "");
+ auto on_fulfilled = JS::NativeFunction::create(realm, move(on_fulfilled_steps), 1, "");
// 3. Let onRejectedSteps be the following steps given argument R:
auto on_rejected_steps = [&realm, on_rejected_callback = move(on_rejected_callback)](JS::VM& vm) -> JS::ThrowCompletionOr<JS::Value> {
@@ -125,7 +125,7 @@ JS::NonnullGCPtr<JS::Promise> react_to_promise(JS::PromiseCapability const& prom
};
// 4. Let onRejected be CreateBuiltinFunction(onRejectedSteps, « »):
- auto* on_rejected = JS::NativeFunction::create(realm, move(on_rejected_steps), 1, "");
+ auto on_rejected = JS::NativeFunction::create(realm, move(on_rejected_steps), 1, "");
// 5. Let constructor be promise.[[Promise]].[[Realm]].[[Intrinsics]].[[%Promise%]].
auto* constructor = realm.intrinsics().promise_constructor();