mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:37:35 +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:
parent
f8cb4f9686
commit
60adeb11c9
2 changed files with 8 additions and 8 deletions
|
@ -52,7 +52,7 @@ void GeneratorObject::visit_edges(Cell::Visitor& visitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 27.5.3.2 GeneratorValidate ( generator, generatorBrand ), https://tc39.es/ecma262/#sec-generatorvalidate
|
// 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]]).
|
// 1. Perform ? RequireInternalSlot(generator, [[GeneratorState]]).
|
||||||
// 2. Perform ? RequireInternalSlot(generator, [[GeneratorBrand]]).
|
// 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.
|
// 3. If generator.[[GeneratorBrand]] is not the same value as generatorBrand, throw a TypeError exception.
|
||||||
if (m_generator_brand != generator_brand)
|
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.
|
// 4. Assert: generator also has a [[GeneratorContext]] internal slot.
|
||||||
// NOTE: Done by already being a GeneratorObject.
|
// 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
|
// 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).
|
// 1. Let state be ? GeneratorValidate(generator, generatorBrand).
|
||||||
auto state = TRY(validate(vm, generator_brand));
|
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
|
// 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.
|
// Not part of the spec, but the spec assumes abruptCompletion.[[Value]] is not empty.
|
||||||
VERIFY(abrupt_completion.value().has_value());
|
VERIFY(abrupt_completion.value().has_value());
|
||||||
|
|
|
@ -20,8 +20,8 @@ public:
|
||||||
virtual ~GeneratorObject() override = default;
|
virtual ~GeneratorObject() override = default;
|
||||||
void visit_edges(Cell::Visitor&) override;
|
void visit_edges(Cell::Visitor&) override;
|
||||||
|
|
||||||
ThrowCompletionOr<Value> resume(VM&, Value value, Optional<DeprecatedString> generator_brand);
|
ThrowCompletionOr<Value> resume(VM&, Value value, Optional<StringView> const& generator_brand);
|
||||||
ThrowCompletionOr<Value> resume_abrupt(VM&, JS::Completion abrupt_completion, Optional<DeprecatedString> generator_brand);
|
ThrowCompletionOr<Value> resume_abrupt(VM&, JS::Completion abrupt_completion, Optional<StringView> const& generator_brand);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GeneratorObject(Realm&, Object& prototype, ExecutionContext);
|
GeneratorObject(Realm&, Object& prototype, ExecutionContext);
|
||||||
|
@ -33,7 +33,7 @@ private:
|
||||||
Completed,
|
Completed,
|
||||||
};
|
};
|
||||||
|
|
||||||
ThrowCompletionOr<GeneratorState> validate(VM&, Optional<DeprecatedString> const& generator_brand);
|
ThrowCompletionOr<GeneratorState> validate(VM&, Optional<StringView> const& generator_brand);
|
||||||
ThrowCompletionOr<Value> execute(VM&, JS::Completion const& completion);
|
ThrowCompletionOr<Value> execute(VM&, JS::Completion const& completion);
|
||||||
|
|
||||||
ExecutionContext m_execution_context;
|
ExecutionContext m_execution_context;
|
||||||
|
@ -41,7 +41,7 @@ private:
|
||||||
Value m_previous_value;
|
Value m_previous_value;
|
||||||
Optional<Bytecode::RegisterWindow> m_frame;
|
Optional<Bytecode::RegisterWindow> m_frame;
|
||||||
GeneratorState m_generator_state { GeneratorState::SuspendedStart };
|
GeneratorState m_generator_state { GeneratorState::SuspendedStart };
|
||||||
Optional<DeprecatedString> m_generator_brand;
|
Optional<StringView> m_generator_brand;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue