소스 검색

LibJS: Implement the GetPrototypeFromConstructor() abstract operation

Linus Groh 4 년 전
부모
커밋
500818e73d
2개의 변경된 파일17개의 추가작업 그리고 0개의 파일을 삭제
  1. 16 0
      Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
  2. 1 0
      Userland/Libraries/LibJS/Runtime/AbstractOperations.h

+ 16 - 0
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();
+}
+
 }

+ 1 - 0
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)());
 
 }