diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp index cc193fa1b6a..52a1912599e 100644 --- a/Libraries/LibJS/AST.cpp +++ b/Libraries/LibJS/AST.cpp @@ -253,7 +253,7 @@ ThrowCompletionOr ClassField::class_element_evaluation }); // FIXME: A potential optimization is not creating the functions here since these are never directly accessible. - auto function_code = create_ast_node(m_initializer->source_range(), copy_initializer.release_nonnull(), name.to_utf8_but_should_be_ported_to_utf16()); + auto function_code = create_ast_node(m_initializer->source_range(), copy_initializer.release_nonnull(), move(name)); FunctionParsingInsights parsing_insights; parsing_insights.uses_this_from_environment = true; parsing_insights.uses_this = true; diff --git a/Libraries/LibJS/AST.h b/Libraries/LibJS/AST.h index 824c0c28031..a0a2c74b225 100644 --- a/Libraries/LibJS/AST.h +++ b/Libraries/LibJS/AST.h @@ -1563,7 +1563,7 @@ private: // 10.2.1.3 Runtime Semantics: EvaluateBody, https://tc39.es/ecma262/#sec-runtime-semantics-evaluatebody class ClassFieldInitializerStatement final : public Statement { public: - ClassFieldInitializerStatement(SourceRange source_range, NonnullRefPtr expression, FlyString field_name) + ClassFieldInitializerStatement(SourceRange source_range, NonnullRefPtr expression, Utf16FlyString field_name) : Statement(move(source_range)) , m_expression(move(expression)) , m_class_field_identifier_name(move(field_name)) @@ -1575,7 +1575,7 @@ public: private: NonnullRefPtr m_expression; - FlyString m_class_field_identifier_name; // [[ClassFieldIdentifierName]] + Utf16FlyString m_class_field_identifier_name; // [[ClassFieldIdentifierName]] }; class SpreadExpression final : public Expression { diff --git a/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Libraries/LibJS/Bytecode/ASTCodegen.cpp index baae42a262d..76878dd03aa 100644 --- a/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -2093,7 +2093,7 @@ Bytecode::CodeGenerationErrorOr> YieldExpression::genera // i. Let throw be ? GetMethod(iterator, "throw"). auto throw_method = generator.allocate_register(); - generator.emit(throw_method, iterator, generator.intern_identifier("throw"_fly_string)); + generator.emit(throw_method, iterator, generator.intern_identifier("throw"_utf16_fly_string)); // ii. If throw is not undefined, then auto& throw_method_is_defined_block = generator.make_block(); @@ -2178,7 +2178,7 @@ Bytecode::CodeGenerationErrorOr> YieldExpression::genera // ii. Let return be ? GetMethod(iterator, "return"). auto return_method = generator.allocate_register(); - generator.emit(return_method, iterator, generator.intern_identifier("return"_fly_string)); + generator.emit(return_method, iterator, generator.intern_identifier("return"_utf16_fly_string)); // iii. If return is undefined, then auto& return_is_undefined_block = generator.make_block(); @@ -2533,7 +2533,7 @@ Bytecode::CodeGenerationErrorOr> TaggedTemplateLiteral:: generator.emit_with_extra_operand_slots(raw_string_regs.size(), raw_strings_array, raw_string_regs); } - generator.emit(strings_array, generator.intern_identifier("raw"_fly_string), raw_strings_array, Bytecode::Op::PropertyKind::KeyValue, generator.next_property_lookup_cache()); + generator.emit(strings_array, generator.intern_identifier("raw"_utf16_fly_string), raw_strings_array, Bytecode::Op::PropertyKind::KeyValue, generator.next_property_lookup_cache()); auto arguments = generator.allocate_register(); if (!argument_regs.is_empty()) @@ -3578,7 +3578,7 @@ Bytecode::CodeGenerationErrorOr> ExportStatement::genera } if (is(*m_statement)) { - auto value = TRY(generator.emit_named_evaluation_if_anonymous_function(static_cast(*m_statement), generator.intern_identifier("default"_fly_string))); + auto value = TRY(generator.emit_named_evaluation_if_anonymous_function(static_cast(*m_statement), generator.intern_identifier("default"_utf16_fly_string))); if (!static_cast(*m_statement).has_name()) { generator.emit( @@ -3591,7 +3591,7 @@ Bytecode::CodeGenerationErrorOr> ExportStatement::genera // ExportDeclaration : export default AssignmentExpression ; VERIFY(is(*m_statement)); - auto value = TRY(generator.emit_named_evaluation_if_anonymous_function(static_cast(*m_statement), generator.intern_identifier("default"_fly_string))); + auto value = TRY(generator.emit_named_evaluation_if_anonymous_function(static_cast(*m_statement), generator.intern_identifier("default"_utf16_fly_string))); generator.emit( generator.intern_identifier(ExportStatement::local_name_for_default), value); diff --git a/Libraries/LibJS/Bytecode/Generator.cpp b/Libraries/LibJS/Bytecode/Generator.cpp index 8e16218f68c..83f0de839c8 100644 --- a/Libraries/LibJS/Bytecode/Generator.cpp +++ b/Libraries/LibJS/Bytecode/Generator.cpp @@ -911,26 +911,26 @@ void Generator::emit_set_variable(JS::Identifier const& identifier, ScopedOperan } } -static Optional expression_identifier(Expression const& expression) +static Optional expression_identifier(Expression const& expression) { if (expression.is_identifier()) { auto const& identifier = static_cast(expression); - return identifier.string().view().to_utf8_but_should_be_ported_to_utf16(); + return identifier.string().to_utf16_string(); } if (expression.is_numeric_literal()) { auto const& literal = static_cast(expression); - return literal.value().to_string_without_side_effects(); + return literal.value().to_utf16_string_without_side_effects(); } if (expression.is_string_literal()) { auto const& literal = static_cast(expression); - return MUST(String::formatted("'{}'", literal.value())); + return Utf16String::formatted("'{}'", literal.value()); } if (expression.is_member_expression()) { auto const& member_expression = static_cast(expression); - StringBuilder builder; + StringBuilder builder(StringBuilder::Mode::UTF16); if (auto identifier = expression_identifier(member_expression.object()); identifier.has_value()) builder.append(*identifier); @@ -942,7 +942,7 @@ static Optional expression_identifier(Expression const& expression) builder.appendff(".{}", *identifier); } - return builder.to_string_without_validation(); + return builder.to_utf16_string(); } return {}; @@ -1179,12 +1179,12 @@ void Generator::emit_put_by_value_with_this(ScopedOperand base, ScopedOperand pr void Generator::emit_iterator_value(ScopedOperand dst, ScopedOperand result) { - emit_get_by_id(dst, result, intern_identifier("value"_fly_string)); + emit_get_by_id(dst, result, intern_identifier("value"_utf16_fly_string)); } void Generator::emit_iterator_complete(ScopedOperand dst, ScopedOperand result) { - emit_get_by_id(dst, result, intern_identifier("done"_fly_string)); + emit_get_by_id(dst, result, intern_identifier("done"_utf16_fly_string)); } bool Generator::is_local_initialized(u32 local_index) const diff --git a/Libraries/LibJS/Bytecode/Generator.h b/Libraries/LibJS/Bytecode/Generator.h index 39cc90e218c..6146418867a 100644 --- a/Libraries/LibJS/Bytecode/Generator.h +++ b/Libraries/LibJS/Bytecode/Generator.h @@ -212,11 +212,6 @@ public: return m_regex_table->insert(move(regex)); } - IdentifierTableIndex intern_identifier(FlyString const& string) - { - return intern_identifier(Utf16FlyString::from_utf8(string)); - } - IdentifierTableIndex intern_identifier(Utf16FlyString string) { return m_identifier_table->insert(move(string));