Commit 934fdb0a authored by Marja Hölttä's avatar Marja Hölttä Committed by Commit Bot

[cleanup] Refactor IterableToFixedArrayForWasm

It doesn't need to implement its own iteration logic, if we refactor a bit.

BUG=v8:10425

Change-Id: I9b33911c2fab9ac85cae847473dbef0c2e88ea96
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2153224Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran  <gsathya@chromium.org>
Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67232}
parent 1fc4cb84
......@@ -178,14 +178,24 @@ void IteratorBuiltinsAssembler::IteratorCloseOnException(
TNode<JSArray> IteratorBuiltinsAssembler::IterableToList(
TNode<Context> context, TNode<Object> iterable, TNode<Object> iterator_fn) {
GrowableFixedArray values(state());
FillFixedArrayFromIterable(context, iterable, iterator_fn, &values);
return values.ToJSArray(context);
}
void IteratorBuiltinsAssembler::FillFixedArrayFromIterable(
TNode<Context> context, TNode<Object> iterable, TNode<Object> iterator_fn,
GrowableFixedArray* values) {
// 1. Let iteratorRecord be ? GetIterator(items, method).
IteratorRecord iterator_record = GetIterator(context, iterable, iterator_fn);
// 2. Let values be a new empty List.
GrowableFixedArray values(state());
Label loop_start(
this, {values.var_array(), values.var_length(), values.var_capacity()}),
// The GrowableFixedArray has already been created. It's ok if we do this step
// out of order, since creating an empty List is not observable.
Label loop_start(this, {values->var_array(), values->var_length(),
values->var_capacity()}),
done(this);
Goto(&loop_start);
// 3. Let next be true.
......@@ -198,12 +208,11 @@ TNode<JSArray> IteratorBuiltinsAssembler::IterableToList(
// i. Let nextValue be ? IteratorValue(next).
TNode<Object> next_value = IteratorValue(context, next);
// ii. Append nextValue to the end of the List values.
values.Push(next_value);
values->Push(next_value);
Goto(&loop_start);
}
BIND(&done);
return values.ToJSArray(context);
}
TF_BUILTIN(IterableToList, IteratorBuiltinsAssembler) {
......@@ -220,25 +229,12 @@ TF_BUILTIN(IterableToFixedArrayForWasm, IteratorBuiltinsAssembler) {
TNode<Smi> expected_length = CAST(Parameter(Descriptor::kExpectedLength));
TNode<Object> iterator_fn = GetIteratorMethod(context, iterable);
IteratorRecord iterator_record = GetIterator(context, iterable, iterator_fn);
GrowableFixedArray values(state());
Label loop_start(
this, {values.var_array(), values.var_length(), values.var_capacity()}),
compare_length(this), done(this);
Goto(&loop_start);
BIND(&loop_start);
{
TNode<JSReceiver> next =
IteratorStep(context, iterator_record, &compare_length);
TNode<Object> next_value = IteratorValue(context, next);
values.Push(next_value);
Goto(&loop_start);
}
Label done(this);
FillFixedArrayFromIterable(context, iterable, iterator_fn, &values);
BIND(&compare_length);
GotoIf(WordEqual(SmiUntag(expected_length), values.var_length()->value()),
&done);
Return(CallRuntime(
......
......@@ -12,6 +12,8 @@ namespace internal {
using compiler::Node;
class GrowableFixedArray;
class IteratorBuiltinsAssembler : public CodeStubAssembler {
public:
explicit IteratorBuiltinsAssembler(compiler::CodeAssemblerState* state)
......@@ -65,6 +67,11 @@ class IteratorBuiltinsAssembler : public CodeStubAssembler {
TNode<JSArray> IterableToList(TNode<Context> context, TNode<Object> iterable,
TNode<Object> iterator_fn);
void FillFixedArrayFromIterable(TNode<Context> context,
TNode<Object> iterable,
TNode<Object> iterator_fn,
GrowableFixedArray* values);
// Currently at https://tc39.github.io/proposal-intl-list-format/
// #sec-createstringlistfromiterable
TNode<JSArray> StringListFromIterable(TNode<Context> context,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment