diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp index f96b798c43..8d44ca0b9b 100644 --- a/Libraries/LibJS/AST.cpp +++ b/Libraries/LibJS/AST.cpp @@ -323,19 +323,19 @@ Value UnaryExpression::execute(Interpreter& interpreter) const case UnaryOp::Typeof: switch (lhs_result.type()) { case Value::Type::Undefined: - return js_string(interpreter.heap(), "undefined"); + return js_string(interpreter, "undefined"); case Value::Type::Null: // yes, this is on purpose. yes, this is how javascript works. // yes, it's silly. - return js_string(interpreter.heap(), "object"); + return js_string(interpreter, "object"); case Value::Type::Number: - return js_string(interpreter.heap(), "number"); + return js_string(interpreter, "number"); case Value::Type::String: - return js_string(interpreter.heap(), "string"); + return js_string(interpreter, "string"); case Value::Type::Object: - return js_string(interpreter.heap(), "object"); + return js_string(interpreter, "object"); case Value::Type::Boolean: - return js_string(interpreter.heap(), "boolean"); + return js_string(interpreter, "boolean"); } } @@ -806,7 +806,7 @@ Value MemberExpression::execute(Interpreter& interpreter) const Value StringLiteral::execute(Interpreter& interpreter) const { - return js_string(interpreter.heap(), m_value); + return js_string(interpreter, m_value); } Value NumericLiteral::execute(Interpreter&) const diff --git a/Libraries/LibJS/Runtime/DateConstructor.cpp b/Libraries/LibJS/Runtime/DateConstructor.cpp index b7cd08b1da..407c95d38d 100644 --- a/Libraries/LibJS/Runtime/DateConstructor.cpp +++ b/Libraries/LibJS/Runtime/DateConstructor.cpp @@ -50,7 +50,7 @@ Value DateConstructor::call(Interpreter& interpreter) auto date = construct(interpreter); if (!date.is_object()) return {}; - return js_string(interpreter.heap(), static_cast(date.as_object()).string()); + return js_string(interpreter, static_cast(date.as_object()).string()); } Value DateConstructor::construct(Interpreter& interpreter) diff --git a/Libraries/LibJS/Runtime/DatePrototype.cpp b/Libraries/LibJS/Runtime/DatePrototype.cpp index eb58b7b64c..5e75843e11 100644 --- a/Libraries/LibJS/Runtime/DatePrototype.cpp +++ b/Libraries/LibJS/Runtime/DatePrototype.cpp @@ -155,7 +155,7 @@ Value DatePrototype::to_date_string(Interpreter& interpreter) if (!this_object) return {}; auto string = this_object->date_string(); - return js_string(interpreter.heap(), move(string)); + return js_string(interpreter, move(string)); } Value DatePrototype::to_time_string(Interpreter& interpreter) @@ -164,7 +164,7 @@ Value DatePrototype::to_time_string(Interpreter& interpreter) if (!this_object) return {}; auto string = this_object->time_string(); - return js_string(interpreter.heap(), move(string)); + return js_string(interpreter, move(string)); } Value DatePrototype::to_string(Interpreter& interpreter) @@ -173,7 +173,7 @@ Value DatePrototype::to_string(Interpreter& interpreter) if (!this_object) return {}; auto string = this_object->string(); - return js_string(interpreter.heap(), move(string)); + return js_string(interpreter, move(string)); } } diff --git a/Libraries/LibJS/Runtime/ErrorPrototype.cpp b/Libraries/LibJS/Runtime/ErrorPrototype.cpp index da59c5a07c..f7be308bce 100644 --- a/Libraries/LibJS/Runtime/ErrorPrototype.cpp +++ b/Libraries/LibJS/Runtime/ErrorPrototype.cpp @@ -52,7 +52,7 @@ Value ErrorPrototype::name_getter(Interpreter& interpreter) return {}; if (!this_object->is_error()) return interpreter.throw_exception("TypeError", "Not an Error object"); - return js_string(interpreter.heap(), static_cast(this_object)->name()); + return js_string(interpreter, static_cast(this_object)->name()); } Value ErrorPrototype::message_getter(Interpreter& interpreter) @@ -62,7 +62,7 @@ Value ErrorPrototype::message_getter(Interpreter& interpreter) return {}; if (!this_object->is_error()) return interpreter.throw_exception("TypeError", "Not an Error object"); - return js_string(interpreter.heap(), static_cast(this_object)->message()); + return js_string(interpreter, static_cast(this_object)->message()); } Value ErrorPrototype::to_string(Interpreter& interpreter) @@ -82,10 +82,10 @@ Value ErrorPrototype::to_string(Interpreter& interpreter) message = object_message_property.value().to_string(); if (name.length() == 0) - return js_string(interpreter.heap(), message); + return js_string(interpreter, message); if (message.length() == 0) - return js_string(interpreter.heap(), name); - return js_string(interpreter.heap(), String::format("%s: %s", name.characters(), message.characters())); + return js_string(interpreter, name); + return js_string(interpreter, String::format("%s: %s", name.characters(), message.characters())); } } diff --git a/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Libraries/LibJS/Runtime/ObjectConstructor.cpp index 4b102a3829..d6a8808dac 100644 --- a/Libraries/LibJS/Runtime/ObjectConstructor.cpp +++ b/Libraries/LibJS/Runtime/ObjectConstructor.cpp @@ -67,10 +67,10 @@ Value ObjectConstructor::get_own_property_names(Interpreter& interpreter) if (object->is_array()) { auto* array = static_cast(object); for (i32 i = 0; i < array->length(); ++i) - result->push(js_string(interpreter.heap(), String::number(i))); + result->push(js_string(interpreter, String::number(i))); } for (auto& it : object->shape().property_table()) - result->push(js_string(interpreter.heap(), it.key)); + result->push(js_string(interpreter, it.key)); return result; } diff --git a/Libraries/LibJS/Runtime/PrimitiveString.cpp b/Libraries/LibJS/Runtime/PrimitiveString.cpp index cfba8c8872..76c8024121 100644 --- a/Libraries/LibJS/Runtime/PrimitiveString.cpp +++ b/Libraries/LibJS/Runtime/PrimitiveString.cpp @@ -25,6 +25,7 @@ */ #include +#include #include namespace JS { @@ -43,4 +44,9 @@ PrimitiveString* js_string(Heap& heap, String string) return heap.allocate(move(string)); } +PrimitiveString* js_string(Interpreter& interpreter, String string) +{ + return js_string(interpreter.heap(), string); +} + } diff --git a/Libraries/LibJS/Runtime/PrimitiveString.h b/Libraries/LibJS/Runtime/PrimitiveString.h index 6e9f9539d3..7ee314103f 100644 --- a/Libraries/LibJS/Runtime/PrimitiveString.h +++ b/Libraries/LibJS/Runtime/PrimitiveString.h @@ -45,5 +45,6 @@ private: }; PrimitiveString* js_string(Heap&, String); +PrimitiveString* js_string(Interpreter&, String); } diff --git a/Libraries/LibJS/Runtime/StringPrototype.cpp b/Libraries/LibJS/Runtime/StringPrototype.cpp index 6a2cd0e8bd..0d98a4f535 100644 --- a/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -59,8 +59,8 @@ Value StringPrototype::char_at(Interpreter& interpreter) ASSERT(this_object->is_string_object()); auto underlying_string = static_cast(this_object)->primitive_string()->string(); if (index < 0 || index >= static_cast(underlying_string.length())) - return js_string(interpreter.heap(), String::empty()); - return js_string(interpreter.heap(), underlying_string.substring(index, 1)); + return js_string(interpreter, String::empty()); + return js_string(interpreter, underlying_string.substring(index, 1)); } Value StringPrototype::repeat(Interpreter& interpreter) @@ -70,7 +70,7 @@ Value StringPrototype::repeat(Interpreter& interpreter) return {}; ASSERT(this_object->is_string_object()); if (!interpreter.argument_count()) - return js_string(interpreter.heap(), String::empty()); + return js_string(interpreter, String::empty()); i32 count = 0; count = interpreter.argument(0).to_i32(); if (count < 0) { @@ -81,7 +81,7 @@ Value StringPrototype::repeat(Interpreter& interpreter) StringBuilder builder; for (i32 i = 0; i < count; ++i) builder.append(string_object->primitive_string()->string()); - return js_string(interpreter.heap(), builder.to_string()); + return js_string(interpreter, builder.to_string()); } Value StringPrototype::starts_with(Interpreter& interpreter) diff --git a/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.cpp b/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.cpp index 5c095ccaa7..995d72c817 100644 --- a/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.cpp +++ b/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.cpp @@ -76,7 +76,7 @@ JS::Value CanvasRenderingContext2DWrapper::fill_style_getter(JS::Interpreter& in auto* impl = impl_from(interpreter); if (!impl) return {}; - return JS::js_string(interpreter.heap(), impl->fill_style()); + return JS::js_string(interpreter, impl->fill_style()); } void CanvasRenderingContext2DWrapper::fill_style_setter(JS::Interpreter& interpreter, JS::Value value) diff --git a/Libraries/LibWeb/Bindings/ElementWrapper.cpp b/Libraries/LibWeb/Bindings/ElementWrapper.cpp index a5e39aa4b9..5e0bac9e23 100644 --- a/Libraries/LibWeb/Bindings/ElementWrapper.cpp +++ b/Libraries/LibWeb/Bindings/ElementWrapper.cpp @@ -68,7 +68,7 @@ static Element* impl_from(JS::Interpreter& interpreter) JS::Value ElementWrapper::inner_html_getter(JS::Interpreter& interpreter) { if (auto* impl = impl_from(interpreter)) - return JS::js_string(interpreter.heap(), impl->inner_html()); + return JS::js_string(interpreter, impl->inner_html()); return {}; } @@ -81,7 +81,7 @@ void ElementWrapper::inner_html_setter(JS::Interpreter& interpreter, JS::Value v JS::Value ElementWrapper::id_getter(JS::Interpreter& interpreter) { if (auto* impl = impl_from(interpreter)) - return JS::js_string(interpreter.heap(), impl->attribute("id")); + return JS::js_string(interpreter, impl->attribute("id")); return {}; } diff --git a/Userland/js.cpp b/Userland/js.cpp index 067abc0cee..91ab6beddb 100644 --- a/Userland/js.cpp +++ b/Userland/js.cpp @@ -277,7 +277,7 @@ JS::Value ReplObject::repl_help(JS::Interpreter& interpreter) help_text.append(" help(): display this menu\n"); help_text.append(" load(files): Accepts file names as params to load into running session. For example repl.load(\"js/1.js\", \"js/2.js\", \"js/3.js\")\n"); String result = help_text.to_string(); - return js_string(interpreter.heap(), result); + return js_string(interpreter, result); } JS::Value ReplObject::load_file(JS::Interpreter& interpreter)