summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-06-19 22:27:53 +0100
committerAndreas Kling <kling@serenityos.org>2021-06-20 12:12:39 +0200
commit500818e73d16747cdbbccd363568d5d28277c7b8 (patch)
treeab7f36007c9c50caf2059ff3bf47359d9218f7f3
parent6312627218b9eb48d5dc0c719b860cc9862aa7fd (diff)
downloadserenity-500818e73d16747cdbbccd363568d5d28277c7b8.zip
LibJS: Implement the GetPrototypeFromConstructor() abstract operation
-rw-r--r--Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp16
-rw-r--r--Userland/Libraries/LibJS/Runtime/AbstractOperations.h1
2 files changed, 17 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
index f9a483f6e6..da23099f6d 100644
--- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
+++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
@@ -140,4 +140,20 @@ GlobalObject* get_function_realm(GlobalObject& global_object, Function const& fu
return &global_object;
}
+// 10.1.14 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
+Object* get_prototype_from_constructor(GlobalObject& global_object, Function const& constructor, Object* (GlobalObject::*intrinsic_default_prototype)())
+{
+ auto& vm = global_object.vm();
+ auto prototype = constructor.get(vm.names.prototype);
+ if (vm.exception())
+ return nullptr;
+ if (!prototype.is_object()) {
+ auto* realm = get_function_realm(global_object, constructor);
+ if (vm.exception())
+ return nullptr;
+ prototype = (realm->*intrinsic_default_prototype)();
+ }
+ return &prototype.as_object();
+}
+
}
diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h
index ede34dea1f..ffcff07c06 100644
--- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h
+++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h
@@ -18,5 +18,6 @@ size_t length_of_array_like(GlobalObject&, Object const&);
MarkedValueList create_list_from_array_like(GlobalObject&, Value, AK::Function<Result<void, ErrorType>(Value)> = {});
Function* species_constructor(GlobalObject&, Object const&, Function& default_constructor);
GlobalObject* get_function_realm(GlobalObject&, Function const&);
+Object* get_prototype_from_constructor(GlobalObject&, Function const& constructor, Object* (GlobalObject::*intrinsic_default_prototype)());
}