2021-06-19 23:45:00 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Forward.h>
|
|
|
|
#include <LibJS/Forward.h>
|
2021-06-20 00:34:48 +03:00
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
2021-06-19 23:45:00 +03:00
|
|
|
#include <LibJS/Runtime/Value.h>
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2021-06-22 01:56:14 +03:00
|
|
|
DeclarativeEnvironmentRecord* new_declarative_environment(EnvironmentRecord&);
|
2021-06-22 02:14:27 +03:00
|
|
|
ObjectEnvironmentRecord* new_object_environment(Object&, bool is_with_environment, EnvironmentRecord*);
|
2021-06-22 14:30:48 +03:00
|
|
|
EnvironmentRecord& get_this_environment(VM&);
|
|
|
|
Object* get_super_constructor(VM&);
|
2021-06-19 23:45:00 +03:00
|
|
|
Value require_object_coercible(GlobalObject&, Value);
|
|
|
|
size_t length_of_array_like(GlobalObject&, Object const&);
|
|
|
|
MarkedValueList create_list_from_array_like(GlobalObject&, Value, AK::Function<Result<void, ErrorType>(Value)> = {});
|
2021-06-27 22:48:34 +03:00
|
|
|
FunctionObject* species_constructor(GlobalObject&, Object const&, FunctionObject& default_constructor);
|
|
|
|
GlobalObject* get_function_realm(GlobalObject&, FunctionObject const&);
|
|
|
|
Object* get_prototype_from_constructor(GlobalObject&, FunctionObject const& constructor, Object* (GlobalObject::*intrinsic_default_prototype)());
|
2021-06-19 23:45:00 +03:00
|
|
|
|
2021-06-20 06:13:53 +03:00
|
|
|
enum class CallerMode {
|
|
|
|
Strict,
|
|
|
|
NonStrict
|
|
|
|
};
|
|
|
|
enum class EvalMode {
|
|
|
|
Direct,
|
|
|
|
Indirect
|
|
|
|
};
|
|
|
|
Value perform_eval(Value, GlobalObject&, CallerMode, EvalMode);
|
|
|
|
|
2021-06-20 00:34:48 +03:00
|
|
|
// 10.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ), https://tc39.es/ecma262/#sec-ordinarycreatefromconstructor
|
|
|
|
template<typename T, typename... Args>
|
2021-06-27 22:48:34 +03:00
|
|
|
T* ordinary_create_from_constructor(GlobalObject& global_object, FunctionObject const& constructor, Object* (GlobalObject::*intrinsic_default_prototype)(), Args&&... args)
|
2021-06-20 00:34:48 +03:00
|
|
|
{
|
|
|
|
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<T>(global_object, forward<Args>(args)..., *prototype);
|
|
|
|
}
|
|
|
|
|
2021-06-19 23:45:00 +03:00
|
|
|
}
|