From df095afbcca06d550d2034393f421981b4bf0b47 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 19 Jun 2021 22:34:48 +0100 Subject: [PATCH] LibJS: Implement the OrdinaryCreateFromConstructor() abstract operation --- .../Libraries/LibJS/Runtime/AbstractOperations.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h index ffcff07c06..0dc1b641c1 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h @@ -8,6 +8,7 @@ #include #include +#include #include namespace JS { @@ -20,4 +21,15 @@ Function* species_constructor(GlobalObject&, Object const&, Function& default_co GlobalObject* get_function_realm(GlobalObject&, Function const&); Object* get_prototype_from_constructor(GlobalObject&, Function const& constructor, Object* (GlobalObject::*intrinsic_default_prototype)()); +// 10.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ), https://tc39.es/ecma262/#sec-ordinarycreatefromconstructor +template +T* ordinary_create_from_constructor(GlobalObject& global_object, Function const& constructor, Object* (GlobalObject::*intrinsic_default_prototype)(), Args&&... args) +{ + auto& vm = global_object.vm(); + auto* prototype = get_prototype_from_constructor(global_object, constructor, intrinsic_default_prototype); + if (vm.exception()) + return nullptr; + return global_object.heap().allocate(global_object, forward(args)..., *prototype); +} + }