summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-06-22 00:56:14 +0200
committerAndreas Kling <kling@serenityos.org>2021-06-22 01:17:15 +0200
commitd8e9a176cd2a33efa1aaabb71c7c2a98aea6ec34 (patch)
treebd5700adb72c6635f3f739dcd3cc57198ceec545 /Userland/Libraries
parentc6baeca6d7a99d0be3ce71833176a79607e4df57 (diff)
downloadserenity-d8e9a176cd2a33efa1aaabb71c7c2a98aea6ec34.zip
LibJS: Implement the NewDeclarativeEnvironment() abstract operation
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp9
-rw-r--r--Userland/Libraries/LibJS/Runtime/AbstractOperations.h1
-rw-r--r--Userland/Libraries/LibJS/Runtime/DeclarativeEnvironmentRecord.cpp5
-rw-r--r--Userland/Libraries/LibJS/Runtime/DeclarativeEnvironmentRecord.h1
4 files changed, 16 insertions, 0 deletions
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 <linusg@serenityos.org>
+ * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -8,6 +9,7 @@
#include <AK/Result.h>
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/BoundFunction.h>
+#include <LibJS/Runtime/DeclarativeEnvironmentRecord.h>
#include <LibJS/Runtime/ErrorTypes.h>
#include <LibJS/Runtime/Function.h>
#include <LibJS/Runtime/GlobalObject.h>
@@ -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<DeclarativeEnvironmentRecord>(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<FlyString, Variable> 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<FlyString, Variable> variables, EnvironmentRecord* parent_scope);
DeclarativeEnvironmentRecord(HashMap<FlyString, Variable> variables, EnvironmentRecord* parent_scope, EnvironmentRecordType);
virtual ~DeclarativeEnvironmentRecord() override;