diff --git a/Libraries/LibJS/Runtime/NativeFunction.cpp b/Libraries/LibJS/Runtime/NativeFunction.cpp index 37a44d42902..b29d792b1e0 100644 --- a/Libraries/LibJS/Runtime/NativeFunction.cpp +++ b/Libraries/LibJS/Runtime/NativeFunction.cpp @@ -33,7 +33,7 @@ void NativeFunction::visit_edges(Cell::Visitor& visitor) // 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. -GC::Ref NativeFunction::create(Realm& allocating_realm, Function(VM&)> behaviour, i32 length, PropertyKey const& name, Optional realm, Optional prototype, Optional const& prefix) +GC::Ref NativeFunction::create(Realm& allocating_realm, Function(VM&)> behaviour, i32 length, PropertyKey const& name, Optional realm, Optional const& prefix) { auto& vm = allocating_realm.vm(); @@ -42,8 +42,7 @@ GC::Ref NativeFunction::create(Realm& allocating_realm, Function realm = vm.current_realm(); // 2. If prototype is not present, set prototype to realm.[[Intrinsics]].[[%Function.prototype%]]. - if (!prototype.has_value()) - prototype = realm.value()->intrinsics().function_prototype(); + auto prototype = realm.value()->intrinsics().function_prototype(); // 3. Let internalSlotsList be a List containing the names of all the internal slots that 10.3 requires for the built-in function object that is about to be created. // 4. Append to internalSlotsList the elements of additionalInternalSlotsList. @@ -53,7 +52,7 @@ GC::Ref NativeFunction::create(Realm& allocating_realm, Function // 7. Set func.[[Extensible]] to true. // 8. Set func.[[Realm]] to realm. // 9. Set func.[[InitialName]] to null. - auto function = allocating_realm.create(GC::create_function(vm.heap(), move(behaviour)), prototype.value(), *realm.value()); + auto function = allocating_realm.create(GC::create_function(vm.heap(), move(behaviour)), prototype, *realm.value()); // 10. Perform SetFunctionLength(func, length). function->set_function_length(length); diff --git a/Libraries/LibJS/Runtime/NativeFunction.h b/Libraries/LibJS/Runtime/NativeFunction.h index db9faf9d4ae..6fab066c68b 100644 --- a/Libraries/LibJS/Runtime/NativeFunction.h +++ b/Libraries/LibJS/Runtime/NativeFunction.h @@ -21,7 +21,7 @@ class NativeFunction : public FunctionObject { GC_DECLARE_ALLOCATOR(NativeFunction); public: - static GC::Ref create(Realm&, ESCAPING Function(VM&)> behaviour, i32 length, PropertyKey const& name = FlyString {}, Optional = {}, Optional prototype = {}, Optional const& prefix = {}); + static GC::Ref create(Realm&, ESCAPING Function(VM&)> behaviour, i32 length, PropertyKey const& name = FlyString {}, Optional = {}, Optional const& prefix = {}); static GC::Ref create(Realm&, FlyString const& name, ESCAPING Function(VM&)>); virtual ~NativeFunction() override = default; diff --git a/Libraries/LibJS/Runtime/Object.cpp b/Libraries/LibJS/Runtime/Object.cpp index 606bd0cba90..e9c927057b8 100644 --- a/Libraries/LibJS/Runtime/Object.cpp +++ b/Libraries/LibJS/Runtime/Object.cpp @@ -1266,10 +1266,10 @@ void Object::define_native_accessor(Realm& realm, PropertyKey const& property_ke { FunctionObject* getter_function = nullptr; if (getter) - getter_function = NativeFunction::create(realm, move(getter), 0, property_key, &realm, {}, "get"sv); + getter_function = NativeFunction::create(realm, move(getter), 0, property_key, &realm, "get"sv); FunctionObject* setter_function = nullptr; if (setter) - setter_function = NativeFunction::create(realm, move(setter), 1, property_key, &realm, {}, "set"sv); + setter_function = NativeFunction::create(realm, move(setter), 1, property_key, &realm, "set"sv); return define_direct_accessor(property_key, getter_function, setter_function, attribute); }