|
@@ -17,7 +17,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.
|
|
|
-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)
|
|
|
+NonnullGCPtr<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)
|
|
|
{
|
|
|
auto& vm = allocating_realm.vm();
|
|
|
|
|
@@ -37,7 +37,7 @@ NonnullGCPtr<NativeFunction> NativeFunction::create(Realm& allocating_realm, Saf
|
|
|
// 7. Set func.[[Extensible]] to true.
|
|
|
// 8. Set func.[[Realm]] to realm.
|
|
|
// 9. Set func.[[InitialName]] to null.
|
|
|
- auto function = allocating_realm.heap().allocate<NativeFunction>(allocating_realm, move(behaviour), prototype.value(), *realm.value());
|
|
|
+ auto function = allocating_realm.heap().allocate<NativeFunction>(allocating_realm, JS::create_heap_function(vm.heap(), move(behaviour)), prototype.value(), *realm.value());
|
|
|
|
|
|
// 10. Perform SetFunctionLength(func, length).
|
|
|
function->set_function_length(length);
|
|
@@ -52,12 +52,12 @@ NonnullGCPtr<NativeFunction> NativeFunction::create(Realm& allocating_realm, Saf
|
|
|
return function;
|
|
|
}
|
|
|
|
|
|
-NonnullGCPtr<NativeFunction> NativeFunction::create(Realm& realm, DeprecatedFlyString const& name, SafeFunction<ThrowCompletionOr<Value>(VM&)> function)
|
|
|
+NonnullGCPtr<NativeFunction> NativeFunction::create(Realm& realm, DeprecatedFlyString const& name, Function<ThrowCompletionOr<Value>(VM&)> function)
|
|
|
{
|
|
|
- return realm.heap().allocate<NativeFunction>(realm, name, move(function), realm.intrinsics().function_prototype());
|
|
|
+ return realm.heap().allocate<NativeFunction>(realm, name, JS::create_heap_function(realm.heap(), move(function)), realm.intrinsics().function_prototype());
|
|
|
}
|
|
|
|
|
|
-NativeFunction::NativeFunction(SafeFunction<ThrowCompletionOr<Value>(VM&)> native_function, Object* prototype, Realm& realm)
|
|
|
+NativeFunction::NativeFunction(JS::GCPtr<JS::HeapFunction<ThrowCompletionOr<Value>(VM&)>> native_function, Object* prototype, Realm& realm)
|
|
|
: FunctionObject(realm, prototype)
|
|
|
, m_native_function(move(native_function))
|
|
|
, m_realm(&realm)
|
|
@@ -74,7 +74,7 @@ NativeFunction::NativeFunction(Object& prototype)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
-NativeFunction::NativeFunction(DeprecatedFlyString name, SafeFunction<ThrowCompletionOr<Value>(VM&)> native_function, Object& prototype)
|
|
|
+NativeFunction::NativeFunction(DeprecatedFlyString name, JS::GCPtr<JS::HeapFunction<ThrowCompletionOr<Value>(VM&)>> native_function, Object& prototype)
|
|
|
: FunctionObject(prototype)
|
|
|
, m_name(move(name))
|
|
|
, m_native_function(move(native_function))
|
|
@@ -219,7 +219,8 @@ ThrowCompletionOr<NonnullGCPtr<Object>> NativeFunction::internal_construct(Marke
|
|
|
|
|
|
ThrowCompletionOr<Value> NativeFunction::call()
|
|
|
{
|
|
|
- return m_native_function(vm());
|
|
|
+ VERIFY(m_native_function);
|
|
|
+ return m_native_function->function()(vm());
|
|
|
}
|
|
|
|
|
|
ThrowCompletionOr<NonnullGCPtr<Object>> NativeFunction::construct(FunctionObject&)
|