From d8e9a176cd2a33efa1aaabb71c7c2a98aea6ec34 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 22 Jun 2021 00:56:14 +0200 Subject: [PATCH] LibJS: Implement the NewDeclarativeEnvironment() abstract operation --- Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp | 9 +++++++++ Userland/Libraries/LibJS/Runtime/AbstractOperations.h | 1 + .../LibJS/Runtime/DeclarativeEnvironmentRecord.cpp | 5 +++++ .../LibJS/Runtime/DeclarativeEnvironmentRecord.h | 1 + 4 files changed, 16 insertions(+) diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp index da23099f6d..4833161962 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2020-2021, Linus Groh + * Copyright (c) 2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -8,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -156,4 +158,11 @@ Object* get_prototype_from_constructor(GlobalObject& global_object, Function con return &prototype.as_object(); } +// 9.1.2.2 NewDeclarativeEnvironment ( E ), https://tc39.es/ecma262/#sec-newdeclarativeenvironment +DeclarativeEnvironmentRecord* new_declarative_environment(EnvironmentRecord& environment_record) +{ + auto& global_object = environment_record.global_object(); + return global_object.heap().allocate(global_object, &environment_record); +} + } diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h index 0dc1b641c1..69b0533477 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h @@ -13,6 +13,7 @@ namespace JS { +DeclarativeEnvironmentRecord* new_declarative_environment(EnvironmentRecord&); Value require_object_coercible(GlobalObject&, Value); Function* get_method(GlobalObject& global_object, Value, PropertyName const&); size_t length_of_array_like(GlobalObject&, Object const&); diff --git a/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironmentRecord.cpp b/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironmentRecord.cpp index a35e50e7a6..fadf235f85 100644 --- a/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironmentRecord.cpp +++ b/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironmentRecord.cpp @@ -24,6 +24,11 @@ DeclarativeEnvironmentRecord::DeclarativeEnvironmentRecord(EnvironmentRecordType { } +DeclarativeEnvironmentRecord::DeclarativeEnvironmentRecord(EnvironmentRecord* parent_scope) + : EnvironmentRecord(parent_scope) +{ +} + DeclarativeEnvironmentRecord::DeclarativeEnvironmentRecord(HashMap variables, EnvironmentRecord* parent_scope) : EnvironmentRecord(parent_scope) , m_variables(move(variables)) diff --git a/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironmentRecord.h b/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironmentRecord.h index 502f961a77..5841be9917 100644 --- a/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironmentRecord.h +++ b/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironmentRecord.h @@ -32,6 +32,7 @@ public: DeclarativeEnvironmentRecord(); DeclarativeEnvironmentRecord(EnvironmentRecordType); + explicit DeclarativeEnvironmentRecord(EnvironmentRecord* parent_scope); DeclarativeEnvironmentRecord(HashMap variables, EnvironmentRecord* parent_scope); DeclarativeEnvironmentRecord(HashMap variables, EnvironmentRecord* parent_scope, EnvironmentRecordType); virtual ~DeclarativeEnvironmentRecord() override;