diff options
author | Linus Groh <mail@linusgroh.de> | 2022-09-25 19:11:55 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-09-27 14:56:17 +0100 |
commit | e68e92b3041eb914fd22f7e690b914f7f99c2e3e (patch) | |
tree | d9dc12ab3beb93bfb4fbfd7bb671b0a5baebaba2 | |
parent | 00fa71725b023c1561247b56317ec9d060a891c7 (diff) | |
download | serenity-e68e92b3041eb914fd22f7e690b914f7f99c2e3e.zip |
LibJS: Make JS::NativeFunction use JS::SafeFunction internally
This still needs a project-wide cleanup to remove handles captured in
lambdas, which is now longer required.
For now, this will be used in the next commit implementing promise AOs
from Web IDL, which make heavy use of deferred callbacks.
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/NativeFunction.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/NativeFunction.h | 12 |
2 files changed, 10 insertions, 10 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp b/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp index a8ee8e7883..ddc0bed9b9 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, Function<ThrowCompletionOr<Value>(VM&)> behaviour, i32 length, PropertyKey const& name, Optional<Realm*> realm, Optional<Object*> prototype, Optional<StringView> const& prefix) +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(); @@ -51,12 +51,12 @@ NativeFunction* NativeFunction::create(Realm& allocating_realm, Function<ThrowCo return function; } -NativeFunction* NativeFunction::create(Realm& realm, FlyString const& name, Function<ThrowCompletionOr<Value>(VM&)> function) +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()); } -NativeFunction::NativeFunction(Function<ThrowCompletionOr<Value>(VM&)> native_function, Object* prototype, Realm& realm) +NativeFunction::NativeFunction(SafeFunction<ThrowCompletionOr<Value>(VM&)> native_function, Object* prototype, Realm& realm) : FunctionObject(realm, prototype) , m_native_function(move(native_function)) , m_realm(&realm) @@ -73,7 +73,7 @@ NativeFunction::NativeFunction(Object& prototype) { } -NativeFunction::NativeFunction(FlyString name, Function<ThrowCompletionOr<Value>(VM&)> native_function, Object& prototype) +NativeFunction::NativeFunction(FlyString name, SafeFunction<ThrowCompletionOr<Value>(VM&)> native_function, Object& prototype) : FunctionObject(prototype) , m_name(move(name)) , m_native_function(move(native_function)) diff --git a/Userland/Libraries/LibJS/Runtime/NativeFunction.h b/Userland/Libraries/LibJS/Runtime/NativeFunction.h index 510a255d42..4e15d89bf5 100644 --- a/Userland/Libraries/LibJS/Runtime/NativeFunction.h +++ b/Userland/Libraries/LibJS/Runtime/NativeFunction.h @@ -8,11 +8,11 @@ #pragma once #include <AK/Badge.h> -#include <AK/Function.h> #include <AK/Optional.h> #include <LibJS/Runtime/Completion.h> #include <LibJS/Runtime/FunctionObject.h> #include <LibJS/Runtime/PropertyKey.h> +#include <LibJS/SafeFunction.h> namespace JS { @@ -20,8 +20,8 @@ class NativeFunction : public FunctionObject { JS_OBJECT(NativeFunction, FunctionObject); public: - static NativeFunction* create(Realm&, Function<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, Function<ThrowCompletionOr<Value>(VM&)>); + 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&)>); virtual void initialize(Realm&) override { } virtual ~NativeFunction() override = default; @@ -44,8 +44,8 @@ public: protected: NativeFunction(FlyString name, Object& prototype); - NativeFunction(Function<ThrowCompletionOr<Value>(VM&)>, Object* prototype, Realm& realm); - NativeFunction(FlyString name, Function<ThrowCompletionOr<Value>(VM&)>, Object& prototype); + NativeFunction(SafeFunction<ThrowCompletionOr<Value>(VM&)>, Object* prototype, Realm& realm); + NativeFunction(FlyString name, SafeFunction<ThrowCompletionOr<Value>(VM&)>, Object& prototype); explicit NativeFunction(Object& prototype); private: @@ -53,7 +53,7 @@ private: FlyString m_name; Optional<FlyString> m_initial_name; // [[InitialName]] - Function<ThrowCompletionOr<Value>(VM&)> m_native_function; + SafeFunction<ThrowCompletionOr<Value>(VM&)> m_native_function; Realm* m_realm { nullptr }; }; |