Commit a76fe168 authored by Benedikt Meurer's avatar Benedikt Meurer Committed by Benedikt Meurer

[csa] Improve IteratorBuiltinsAssembler::IteratorStep a bit.

For the fast case we can avoid the instance type check, since the map
check covers that. We also don't need to call out to the ToBoolean
builtin in general, but just use the BranchIfToBooleanIsTrue logic.

Plus in the fast case, we don't know that the JSIteratorResult::done is
a boolean, since the map doesn't guard this assumption, so we also need
to do a proper BranchIfToBooleanIsTrue in that case.

Bug: v8:5269
Change-Id: I36f0d0841472c02f8030f9ce067d20326c9388bd
Reviewed-on: https://chromium-review.googlesource.com/778882Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49482}
parent f0ceb9f2
......@@ -57,43 +57,33 @@ Node* IteratorBuiltinsAssembler::IteratorStep(Node* context, Node* iterator,
// 3. If Type(result) is not Object, throw a TypeError exception.
Label if_notobject(this, Label::kDeferred), return_result(this);
GotoIf(TaggedIsSmi(result), &if_notobject);
GotoIfNot(IsJSReceiver(result), &if_notobject);
VARIABLE(var_done, MachineRepresentation::kTagged);
Node* result_map = LoadMap(result);
if (fast_iterator_result_map != nullptr) {
// Fast iterator result case:
Label if_generic(this);
// 4. Return result.
Node* map = LoadMap(result);
GotoIfNot(WordEqual(map, fast_iterator_result_map), &if_generic);
GotoIfNot(WordEqual(result_map, fast_iterator_result_map), &if_generic);
// IteratorComplete
// 2. Return ToBoolean(? Get(iterResult, "done")).
Node* done = LoadObjectField(result, JSIteratorResult::kDoneOffset);
CSA_ASSERT(this, IsBoolean(done));
var_done.Bind(done);
Goto(&return_result);
BranchIfToBooleanIsTrue(done, if_done, &return_result);
BIND(&if_generic);
}
// Generic iterator result case:
{
// 3. If Type(result) is not Object, throw a TypeError exception.
GotoIfNot(IsJSReceiverMap(result_map), &if_notobject);
// IteratorComplete
// 2. Return ToBoolean(? Get(iterResult, "done")).
Node* done = GetProperty(context, result, factory()->done_string());
GotoIfException(done, if_exception, exception);
var_done.Bind(done);
Label to_boolean(this, Label::kDeferred);
GotoIf(TaggedIsSmi(done), &to_boolean);
Branch(IsBoolean(done), &return_result, &to_boolean);
BIND(&to_boolean);
var_done.Bind(CallBuiltin(Builtins::kToBoolean, context, done));
Goto(&return_result);
BranchIfToBooleanIsTrue(done, if_done, &return_result);
}
BIND(&if_notobject);
......@@ -105,7 +95,6 @@ Node* IteratorBuiltinsAssembler::IteratorStep(Node* context, Node* iterator,
}
BIND(&return_result);
GotoIf(IsTrue(var_done.value()), if_done);
return result;
}
......
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