Skip to content

Commit

Permalink
deps: fix Array.prototype.forEach on v8 6.8
Browse files Browse the repository at this point in the history
This applies a variant of v8/v8@e1163c14f7e4fef2c549 to V8 6.8.

Original commit message:

    [Builtins] Array.prototype.forEach perf regression on dictionaries

    An unnecessary call to ToString() on the array index caused trips to
    the runtime. The fix also includes performance micro-benchmarks so
    we'll have a harder time regressing this case in future.

    [email protected]

    Bug: v8:8112
    Change-Id: I781e8b1bbe2eb56db961cf33b0dca8523868b83d
    Reviewed-on: https://chromium-review.googlesource.com/1213207
    Commit-Queue: Michael Stanton <[email protected]>
    Reviewed-by: Michael Stanton <[email protected]>
    Reviewed-by: Tobias Tebbi <[email protected]>
    Cr-Commit-Position: refs/heads/master@{#55733}

Refs: v8/v8@e1163c1
Fixes: #22859
PR-URL: #22899
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
ripsawridge authored and targos committed Sep 25, 2018
1 parent 16f7f52 commit 5d70652
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.30',
'v8_embedder_string': '-node.31',

# Enable disassembler for `--print-code` v8 options
'v8_enable_disassembler': 1,
Expand Down
15 changes: 8 additions & 7 deletions deps/v8/src/builtins/array.tq
Original file line number Diff line number Diff line change
Expand Up @@ -300,20 +300,21 @@ module array {

macro ArrayForEachTorqueContinuation(
context: Context, o: Object, len: Number, callbackfn: Callable,
thisArg: Object, initial_k: Smi): Object {
thisArg: Object, initial_k: Number): Object {
// 5. Let k be 0.
// 6. Repeat, while k < len
for (let k: Smi = initial_k; k < len; k = k + 1) {
for (let k: Number = initial_k; k < len; k = k + 1) {
// 6a. Let Pk be ! ToString(k).
let pK: String = ToString_Inline(context, k);
// k is guaranteed to be a positive integer, hence ToString is
// side-effect free and HasProperty/GetProperty do the conversion inline.

// 6b. Let kPresent be ? HasProperty(O, Pk).
let kPresent: Oddball = HasPropertyObject(o, pK, context, kHasProperty);
let kPresent: Oddball = HasPropertyObject(o, k, context, kHasProperty);

// 6c. If kPresent is true, then
if (kPresent == True) {
// 6c. i. Let kValue be ? Get(O, Pk).
let kValue: Object = GetProperty(context, o, pK);
let kValue: Object = GetProperty(context, o, k);

// 6c. ii. Perform ? Call(callbackfn, T, <kValue, k, O>).
Call(context, callbackfn, thisArg, kValue, k, o);
Expand Down Expand Up @@ -346,7 +347,7 @@ module array {
to: Object): Object {
try {
let callbackfn: Callable = cast<Callable>(callback) otherwise Unexpected;
let k: Smi = cast<Smi>(initialK) otherwise Unexpected;
let k: Number = cast<Number>(initialK) otherwise Unexpected;
let number_length: Number = cast<Number>(length) otherwise Unexpected;

return ArrayForEachTorqueContinuation(
Expand Down Expand Up @@ -446,7 +447,7 @@ module array {
let thisArg: Object = arguments.length > 1 ? arguments[1] : Undefined;

// Special cases.
let k: Smi = 0;
let k: Number = 0;
try {
return FastArrayForEach(context, o, len, callbackfn, thisArg)
otherwise Bailout;
Expand Down

0 comments on commit 5d70652

Please sign in to comment.