1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:38:12 +00:00

LibJS: Convert GeneratorObject's [[GeneratorBrand]] to a StringView

This optional parameter is not currently set by any caller, but will be
for the Iterator Helpers proposal. In all specs, this parameter is a
static string, so we can just use a StringView rather than allocating a
(Deprecated)String on each invocation.

This also changes this optional parameter to be passed by const-ref, as
it does not need to be copied.
This commit is contained in:
Timothy Flynn 2023-07-16 14:33:20 -04:00 committed by Linus Groh
parent f8cb4f9686
commit 60adeb11c9
2 changed files with 8 additions and 8 deletions

View file

@ -52,7 +52,7 @@ void GeneratorObject::visit_edges(Cell::Visitor& visitor)
}
// 27.5.3.2 GeneratorValidate ( generator, generatorBrand ), https://tc39.es/ecma262/#sec-generatorvalidate
ThrowCompletionOr<GeneratorObject::GeneratorState> GeneratorObject::validate(VM& vm, Optional<DeprecatedString> const& generator_brand)
ThrowCompletionOr<GeneratorObject::GeneratorState> GeneratorObject::validate(VM& vm, Optional<StringView> const& generator_brand)
{
// 1. Perform ? RequireInternalSlot(generator, [[GeneratorState]]).
// 2. Perform ? RequireInternalSlot(generator, [[GeneratorBrand]]).
@ -60,7 +60,7 @@ ThrowCompletionOr<GeneratorObject::GeneratorState> GeneratorObject::validate(VM&
// 3. If generator.[[GeneratorBrand]] is not the same value as generatorBrand, throw a TypeError exception.
if (m_generator_brand != generator_brand)
return vm.throw_completion<TypeError>(ErrorType::GeneratorBrandMismatch, m_generator_brand.value_or("<empty>"), generator_brand.value_or("<empty>"));
return vm.throw_completion<TypeError>(ErrorType::GeneratorBrandMismatch, m_generator_brand.value_or("<empty>"sv), generator_brand.value_or("<empty>"sv));
// 4. Assert: generator also has a [[GeneratorContext]] internal slot.
// NOTE: Done by already being a GeneratorObject.
@ -140,7 +140,7 @@ ThrowCompletionOr<Value> GeneratorObject::execute(VM& vm, Completion const& comp
}
// 27.5.3.3 GeneratorResume ( generator, value, generatorBrand ), https://tc39.es/ecma262/#sec-generatorresume
ThrowCompletionOr<Value> GeneratorObject::resume(VM& vm, Value value, Optional<DeprecatedString> generator_brand)
ThrowCompletionOr<Value> GeneratorObject::resume(VM& vm, Value value, Optional<StringView> const& generator_brand)
{
// 1. Let state be ? GeneratorValidate(generator, generatorBrand).
auto state = TRY(validate(vm, generator_brand));
@ -179,7 +179,7 @@ ThrowCompletionOr<Value> GeneratorObject::resume(VM& vm, Value value, Optional<D
}
// 27.5.3.4 GeneratorResumeAbrupt ( generator, abruptCompletion, generatorBrand ), https://tc39.es/ecma262/#sec-generatorresumeabrupt
ThrowCompletionOr<Value> GeneratorObject::resume_abrupt(JS::VM& vm, JS::Completion abrupt_completion, Optional<AK::DeprecatedString> generator_brand)
ThrowCompletionOr<Value> GeneratorObject::resume_abrupt(JS::VM& vm, JS::Completion abrupt_completion, Optional<StringView> const& generator_brand)
{
// Not part of the spec, but the spec assumes abruptCompletion.[[Value]] is not empty.
VERIFY(abrupt_completion.value().has_value());