mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
LibJS: Make Value::as_string() return a PrimitiveString reference
This commit is contained in:
parent
75f246dde8
commit
698652a548
5 changed files with 15 additions and 15 deletions
|
@ -1051,7 +1051,7 @@ Value ObjectExpression::execute(Interpreter& interpreter) const
|
|||
object->put(it.key, obj_to_spread.get(it.key));
|
||||
}
|
||||
} else if (key_result.is_string()) {
|
||||
auto& str_to_spread = key_result.as_string()->string();
|
||||
auto& str_to_spread = key_result.as_string().string();
|
||||
|
||||
for (size_t i = 0; i < str_to_spread.length(); i++) {
|
||||
object->put_by_index(i, js_string(interpreter, str_to_spread.substring(i, 1)));
|
||||
|
@ -1176,7 +1176,7 @@ Value ArrayExpression::execute(Interpreter& interpreter) const
|
|||
if (value.is_string() || (value.is_object() && value.as_object().is_string_object())) {
|
||||
String string_to_spread;
|
||||
if (value.is_string())
|
||||
string_to_spread = value.as_string()->string();
|
||||
string_to_spread = value.as_string().string();
|
||||
else
|
||||
string_to_spread = static_cast<const StringObject&>(value.as_object()).primitive_string().string();
|
||||
for (size_t i = 0; i < string_to_spread.length(); ++i)
|
||||
|
|
|
@ -194,7 +194,7 @@ enum class PadPlacement {
|
|||
|
||||
static Value pad_string(Interpreter& interpreter, Object* object, PadPlacement placement)
|
||||
{
|
||||
auto string = object->to_string().as_string()->string();
|
||||
auto string = object->to_string().as_string().string();
|
||||
if (interpreter.argument(0).to_number().is_nan()
|
||||
|| interpreter.argument(0).to_number().is_undefined()
|
||||
|| interpreter.argument(0).to_number().to_i32() < 0) {
|
||||
|
@ -246,7 +246,7 @@ enum class TrimMode {
|
|||
|
||||
static Value trim_string(Interpreter& interpreter, const Object& object, TrimMode mode)
|
||||
{
|
||||
auto& string = object.to_string().as_string()->string();
|
||||
auto& string = object.to_string().as_string().string();
|
||||
|
||||
size_t substring_start = 0;
|
||||
size_t substring_length = string.length();
|
||||
|
@ -311,7 +311,7 @@ Value StringPrototype::concat(Interpreter& interpreter)
|
|||
auto* this_object = interpreter.this_value().to_object(interpreter.heap());
|
||||
if (!this_object)
|
||||
return {};
|
||||
auto& string = this_object->to_string().as_string()->string();
|
||||
auto& string = this_object->to_string().as_string().string();
|
||||
|
||||
StringBuilder builder;
|
||||
builder.append(string);
|
||||
|
@ -330,7 +330,7 @@ Value StringPrototype::substring(Interpreter& interpreter)
|
|||
if (!this_object)
|
||||
return {};
|
||||
|
||||
auto& string = this_object->to_string().as_string()->string();
|
||||
auto& string = this_object->to_string().as_string().string();
|
||||
|
||||
if (interpreter.argument_count() == 0)
|
||||
return js_string(interpreter, string);
|
||||
|
@ -377,7 +377,7 @@ Value StringPrototype::includes(Interpreter& interpreter)
|
|||
if (!this_object)
|
||||
return {};
|
||||
|
||||
auto& string = this_object->to_string().as_string()->string();
|
||||
auto& string = this_object->to_string().as_string().string();
|
||||
auto search_string = interpreter.argument(0).to_string();
|
||||
i32 position = 0;
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ bool Value::to_boolean() const
|
|||
case Type::Undefined:
|
||||
return false;
|
||||
case Type::String:
|
||||
return !as_string()->string().is_empty();
|
||||
return !as_string().string().is_empty();
|
||||
case Type::Object:
|
||||
return true;
|
||||
default:
|
||||
|
@ -144,7 +144,7 @@ Value Value::to_number() const
|
|||
return Value(0);
|
||||
case Type::String: {
|
||||
// FIXME: Trim whitespace beforehand
|
||||
auto& string = as_string()->string();
|
||||
auto& string = as_string().string();
|
||||
if (string.is_empty())
|
||||
return Value(0);
|
||||
if (string == "Infinity" || string == "+Infinity")
|
||||
|
@ -334,7 +334,7 @@ Value typed_eq(Interpreter&, Value lhs, Value rhs)
|
|||
case Value::Type::Number:
|
||||
return Value(lhs.as_double() == rhs.as_double());
|
||||
case Value::Type::String:
|
||||
return Value(lhs.as_string()->string() == rhs.as_string()->string());
|
||||
return Value(lhs.as_string().string() == rhs.as_string().string());
|
||||
case Value::Type::Boolean:
|
||||
return Value(lhs.as_bool() == rhs.as_bool());
|
||||
case Value::Type::Object:
|
||||
|
|
|
@ -139,16 +139,16 @@ public:
|
|||
return *m_value.as_object;
|
||||
}
|
||||
|
||||
PrimitiveString* as_string()
|
||||
PrimitiveString& as_string()
|
||||
{
|
||||
ASSERT(is_string());
|
||||
return m_value.as_string;
|
||||
return *m_value.as_string;
|
||||
}
|
||||
|
||||
const PrimitiveString* as_string() const
|
||||
const PrimitiveString& as_string() const
|
||||
{
|
||||
ASSERT(is_string());
|
||||
return m_value.as_string;
|
||||
return *m_value.as_string;
|
||||
}
|
||||
|
||||
Cell* as_cell()
|
||||
|
|
|
@ -322,7 +322,7 @@ JS::Value ReplObject::load_file(JS::Interpreter& interpreter)
|
|||
return JS::Value(false);
|
||||
|
||||
for (auto& file : interpreter.call_frame().arguments) {
|
||||
String file_name = file.as_string()->string();
|
||||
String file_name = file.as_string().string();
|
||||
auto js_file = Core::File::construct(file_name);
|
||||
if (!js_file->open(Core::IODevice::ReadOnly)) {
|
||||
fprintf(stderr, "Failed to open %s: %s\n", file_name.characters(), js_file->error_string());
|
||||
|
|
Loading…
Add table
Reference in a new issue