Skip to content

Commit 70db474

Browse files
trflynn89gmta
authored andcommitted
LibJS+LibWeb: Port interned bytecode strings to UTF-16
This was almost a no-op, except we intern JS exception messages. So the bulk of this patch is porting exception messages to UTF-16.
1 parent cf61171 commit 70db474

File tree

162 files changed

+1405
-1422
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+1405
-1422
lines changed

Libraries/LibJS/Bytecode/ASTCodegen.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,8 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> StringLiteral::generate
444444
Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> RegExpLiteral::generate_bytecode(Bytecode::Generator& generator, Optional<ScopedOperand> preferred_dst) const
445445
{
446446
Bytecode::Generator::SourceLocationScope scope(generator, *this);
447-
auto source_index = generator.intern_string(m_pattern.to_utf8_but_should_be_ported_to_utf16());
448-
auto flags_index = generator.intern_string(m_flags.to_utf8_but_should_be_ported_to_utf16());
447+
auto source_index = generator.intern_string(m_pattern);
448+
auto flags_index = generator.intern_string(m_flags);
449449
auto regex_index = generator.intern_regex(Bytecode::ParsedRegex {
450450
.regex = m_parsed_regex,
451451
.pattern = m_parsed_pattern,
@@ -1770,7 +1770,7 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> CallExpression::generat
17701770

17711771
Optional<Bytecode::StringTableIndex> expression_string_index;
17721772
if (auto expression_string = this->expression_string(); expression_string.has_value())
1773-
expression_string_index = generator.intern_string(expression_string->to_utf8_but_should_be_ported_to_utf16());
1773+
expression_string_index = generator.intern_string(expression_string.release_value());
17741774

17751775
bool has_spread = any_of(arguments(), [](auto& argument) { return argument.is_spread; });
17761776
auto dst = choose_dst(generator, preferred_dst);

Libraries/LibJS/Bytecode/Executable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class JS_API Executable final : public Cell {
9898

9999
Optional<IdentifierTableIndex> length_identifier;
100100

101-
String const& get_string(StringTableIndex index) const { return string_table->get(index); }
101+
Utf16String const& get_string(StringTableIndex index) const { return string_table->get(index); }
102102
Utf16FlyString const& get_identifier(IdentifierTableIndex index) const { return identifier_table->get(index); }
103103

104104
Optional<Utf16FlyString const&> get_identifier(Optional<IdentifierTableIndex> const& index) const

Libraries/LibJS/Bytecode/Generator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class Generator {
202202
return m_current_basic_block->is_terminated();
203203
}
204204

205-
StringTableIndex intern_string(String string)
205+
StringTableIndex intern_string(Utf16String string)
206206
{
207207
return m_string_table->insert(move(string));
208208
}

Libraries/LibJS/Bytecode/Interpreter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,8 +2264,8 @@ void NewRegExp::execute_impl(Bytecode::Interpreter& interpreter) const
22642264
new_regexp(
22652265
interpreter.vm(),
22662266
interpreter.current_executable().regex_table->get(m_regex_index),
2267-
Utf16String::from_utf8(interpreter.current_executable().get_string(m_source_index)),
2268-
Utf16String::from_utf8(interpreter.current_executable().get_string(m_flags_index))));
2267+
interpreter.current_executable().get_string(m_source_index),
2268+
interpreter.current_executable().get_string(m_flags_index)));
22692269
}
22702270

22712271
#define JS_DEFINE_NEW_BUILTIN_ERROR_OP(ErrorName) \

Libraries/LibJS/Bytecode/StringTable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
namespace JS::Bytecode {
1010

11-
StringTableIndex StringTable::insert(String string)
11+
StringTableIndex StringTable::insert(Utf16String string)
1212
{
1313
m_strings.append(move(string));
1414
return { static_cast<u32>(m_strings.size() - 1) };
1515
}
1616

17-
String const& StringTable::get(StringTableIndex index) const
17+
Utf16String const& StringTable::get(StringTableIndex index) const
1818
{
1919
return m_strings[index.value];
2020
}

Libraries/LibJS/Bytecode/StringTable.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#pragma once
88

99
#include <AK/DistinctNumeric.h>
10-
#include <AK/String.h>
10+
#include <AK/Utf16String.h>
1111
#include <AK/Vector.h>
1212

1313
namespace JS::Bytecode {
@@ -25,13 +25,13 @@ class StringTable {
2525
public:
2626
StringTable() = default;
2727

28-
StringTableIndex insert(String);
29-
String const& get(StringTableIndex) const;
28+
StringTableIndex insert(Utf16String);
29+
Utf16String const& get(StringTableIndex) const;
3030
void dump() const;
3131
bool is_empty() const { return m_strings.is_empty(); }
3232

3333
private:
34-
Vector<String> m_strings;
34+
Vector<Utf16String> m_strings;
3535
};
3636

3737
}

Libraries/LibJS/Runtime/AbstractOperations.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,8 +1802,8 @@ ThrowCompletionOr<Value> perform_import_call(VM& vm, Value specifier, Value opti
18021802
// a. If options is not an Object, then
18031803
if (!options.is_object()) {
18041804
// i. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
1805-
auto error = TypeError::create(realm, MUST(String::formatted(ErrorType::NotAnObject.message(), "options"sv)));
1806-
MUST(call(vm, *promise_capability->reject(), js_undefined(), error));
1805+
auto error = vm.throw_completion<TypeError>(ErrorType::NotAnObject, "options"sv);
1806+
MUST(call(vm, *promise_capability->reject(), js_undefined(), error.value()));
18071807

18081808
// ii. Return promiseCapability.[[Promise]].
18091809
return promise_capability->promise();
@@ -1818,8 +1818,8 @@ ThrowCompletionOr<Value> perform_import_call(VM& vm, Value specifier, Value opti
18181818
// i. If attributesObj is not an Object, then
18191819
if (!attributes_obj.is_object()) {
18201820
// 1. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
1821-
auto error = TypeError::create(realm, MUST(String::formatted(ErrorType::NotAnObject.message(), "with"sv)));
1822-
MUST(call(vm, *promise_capability->reject(), js_undefined(), error));
1821+
auto error = vm.throw_completion<TypeError>(ErrorType::NotAnObject, "with"sv);
1822+
MUST(call(vm, *promise_capability->reject(), js_undefined(), error.value()));
18231823

18241824
// 2. Return promiseCapability.[[Promise]].
18251825
return promise_capability->promise();
@@ -1842,8 +1842,8 @@ ThrowCompletionOr<Value> perform_import_call(VM& vm, Value specifier, Value opti
18421842
// a. If value is not a String, then
18431843
if (!value.is_string()) {
18441844
// i. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
1845-
auto error = TypeError::create(realm, MUST(String::formatted(ErrorType::NotAString.message(), "Import attribute value"sv)));
1846-
MUST(call(vm, *promise_capability->reject(), js_undefined(), error));
1845+
auto error = vm.throw_completion<TypeError>(ErrorType::NotAnObject, "Import attribute value"sv);
1846+
MUST(call(vm, *promise_capability->reject(), js_undefined(), error.value()));
18471847

18481848
// ii. Return promiseCapability.[[Promise]].
18491849
return promise_capability->promise();
@@ -1858,8 +1858,8 @@ ThrowCompletionOr<Value> perform_import_call(VM& vm, Value specifier, Value opti
18581858
// e. If AllImportAttributesSupported(attributes) is false, then
18591859
if (!all_import_attributes_supported(vm, attributes)) {
18601860
// i. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
1861-
auto error = TypeError::create(realm, MUST(String::formatted(ErrorType::ImportAttributeUnsupported.message())));
1862-
MUST(call(vm, *promise_capability->reject(), js_undefined(), error));
1861+
auto error = vm.throw_completion<TypeError>(ErrorType::ImportAttributeUnsupported);
1862+
MUST(call(vm, *promise_capability->reject(), js_undefined(), error.value()));
18631863

18641864
// ii. Return promiseCapability.[[Promise]].
18651865
return promise_capability->promise();

Libraries/LibJS/Runtime/AbstractOperations.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ struct YearWeek {
322322

323323
// 14.5.1.1 ToIntegerIfIntegral ( argument ), https://tc39.es/proposal-temporal/#sec-tointegerifintegral
324324
template<typename... Args>
325-
ThrowCompletionOr<double> to_integer_if_integral(VM& vm, Value argument, ErrorType error_type, Args&&... args)
325+
ThrowCompletionOr<double> to_integer_if_integral(VM& vm, Value argument, ErrorType const& error_type, Args&&... args)
326326
{
327327
// 1. Let number be ? ToNumber(argument).
328328
auto number = TRY(argument.to_number(vm));

Libraries/LibJS/Runtime/AsyncDisposableStackPrototype.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncDisposableStackPrototype::dispose_async)
115115
// 3. If asyncDisposableStack does not have an [[AsyncDisposableState]] internal slot, then
116116
if (!async_disposable_stack_value.is_object() || !is<AsyncDisposableStack>(async_disposable_stack_value.as_object())) {
117117
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
118-
auto error = TypeError::create(realm, MUST(String::formatted(ErrorType::NotAnObjectOfType.message(), display_name())));
119-
MUST(call(vm, *promise_capability->reject(), js_undefined(), error));
118+
auto error = vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, display_name());
119+
MUST(call(vm, *promise_capability->reject(), js_undefined(), error.value()));
120120

121121
// b. Return promiseCapability.[[Promise]].
122122
return promise_capability->promise();

Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::return_)
181181

182182
// 12. If Type(result) is not Object, then
183183
if (!result.is_object()) {
184-
auto error = TypeError::create(realm, TRY_OR_THROW_OOM(vm, String::formatted(ErrorType::NotAnObject.message(), "SyncIteratorReturnResult")));
184+
auto error = vm.throw_completion<TypeError>(ErrorType::NotAnObject, "SyncIteratorReturnResult");
185185
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
186-
MUST(call(vm, *promise_capability->reject(), js_undefined(), error));
186+
MUST(call(vm, *promise_capability->reject(), js_undefined(), error.value()));
187187

188188
// b. Return promiseCapability.[[Promise]].
189189
return promise_capability->promise();
@@ -230,8 +230,8 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::throw_)
230230
// f. NOTE: If closing syncIterator does not throw then the result of that operation is ignored, even if it yields a rejected promise.
231231

232232
// g. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
233-
auto error = TypeError::create(realm, MUST(String::formatted(ErrorType::IsUndefined.message(), "throw method")));
234-
MUST(call(vm, *promise_capability->reject(), js_undefined(), error));
233+
auto error = vm.throw_completion<TypeError>(ErrorType::IsUndefined, "throw method");
234+
MUST(call(vm, *promise_capability->reject(), js_undefined(), error.value()));
235235

236236
// h. Return promiseCapability.[[Promise]].
237237
return promise_capability->promise();
@@ -249,8 +249,8 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::throw_)
249249
// 12. If result is not an Object, then
250250
if (!result.is_object()) {
251251
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
252-
auto error = TypeError::create(realm, MUST(String::formatted(ErrorType::NotAnObject.message(), "SyncIteratorThrowResult")));
253-
MUST(call(vm, *promise_capability->reject(), js_undefined(), error));
252+
auto error = vm.throw_completion<TypeError>(ErrorType::NotAnObject, "SyncIteratorThrowResult");
253+
MUST(call(vm, *promise_capability->reject(), js_undefined(), error.value()));
254254

255255
// b. Return promiseCapability.[[Promise]].
256256
return promise_capability->promise();

0 commit comments

Comments
 (0)