summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Interpreter.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-03-15 15:11:13 +0100
committerAndreas Kling <kling@serenityos.org>2020-03-15 15:11:13 +0100
commit8dc6416bbadfadec000ffeac6559caaeda14569b (patch)
tree0adb86c6ae8f26594d99ce8b988b10fc7e491f1e /Libraries/LibJS/Interpreter.cpp
parent9b4358e150a10d75f3cee2ef6dac336c7fb9ca06 (diff)
downloadserenity-8dc6416bbadfadec000ffeac6559caaeda14569b.zip
LibJS: Use the same StringPrototype globally
To make sure that everyone has the same instance of StringPrototype, hang a global prototype off of the Interpreter that can be fetched when constructing new StringObjects.
Diffstat (limited to 'Libraries/LibJS/Interpreter.cpp')
-rw-r--r--Libraries/LibJS/Interpreter.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/Libraries/LibJS/Interpreter.cpp b/Libraries/LibJS/Interpreter.cpp
index f08839d5d2..903f7fbc9f 100644
--- a/Libraries/LibJS/Interpreter.cpp
+++ b/Libraries/LibJS/Interpreter.cpp
@@ -30,6 +30,7 @@
#include <LibJS/Interpreter.h>
#include <LibJS/NativeFunction.h>
#include <LibJS/Object.h>
+#include <LibJS/StringPrototype.h>
#include <LibJS/Value.h>
namespace JS {
@@ -38,6 +39,7 @@ Interpreter::Interpreter()
: m_heap(*this)
{
m_global_object = heap().allocate<GlobalObject>();
+ m_string_prototype = heap().allocate<StringPrototype>();
}
Interpreter::~Interpreter()
@@ -137,6 +139,7 @@ Value Interpreter::get_variable(const String& name)
void Interpreter::collect_roots(Badge<Heap>, HashTable<Cell*>& roots)
{
roots.set(m_global_object);
+ roots.set(m_string_prototype);
for (auto& scope : m_scope_stack) {
for (auto& it : scope.variables) {