v8/test/mjsunit/array-join-index-getter-side-effects.js
peterwmwong 7cb6c81b8f [builtins] Fix Array.p.join handling of an index getter with side effects
When creating the buffer for the fall back, the initial entry was not
considered when calculating the size.

Bug: chromium:896181
Change-Id: I7f15bb1bdf31b3255db91b1fe8dcd68c76033980
Reviewed-on: https://chromium-review.googlesource.com/c/1286957
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Commit-Queue: Peter Wong <peter.wm.wong@gmail.com>
Cr-Commit-Position: refs/heads/master@{#56768}
2018-10-18 10:46:23 +00:00

109 lines
2.4 KiB
JavaScript

// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax
(function Throws() {
function TestError() {}
let callCount = 0;
const a = [0, 1];
Object.defineProperty(a, '0', {
configurable: true,
get() {
callCount++;
throw new TestError();
}
});
assertTrue(%HasDictionaryElements(a));
assertThrows(() => a.join(), TestError);
assertSame(1, callCount);
// Verifies cycle detection still works properly after thrown error.
Object.defineProperty(a, '0', {
configurable: true,
get() {
callCount++;
return 777;
}
});
assertSame('777,1', a.join());
assertSame(2, callCount);
})();
(function ArrayLengthIncreased() {
let callCount = 0;
const a = [1];
Object.defineProperty(a, '0', {
configurable: true,
get() {
callCount++;
a.push(2);
return 9;
}
});
assertSame('9', a.join());
assertSame(1, callCount);
// Verifies cycle detection still works properly after continuation.
assertSame('9,2', a.join());
assertSame(2, callCount);
})();
(function ArrayLengthIncreasedWithHole() {
let callCount = 0;
const a = [1, , 2];
Object.defineProperty(a, '1', {
configurable: true,
get() {
callCount++;
a.push(3);
}
});
assertSame('1,,2', a.join());
assertSame(1, callCount);
// Verifies cycle detection still works properly after continuation.
assertSame('1,,2,3', a.join());
assertSame(2, callCount);
})();
(function ArrayLengthDecreased() {
let callCount = 0;
const a = [0, 1];
Object.defineProperty(a, '0', {
configurable: true,
get() {
callCount++;
a.length = 1;
return 9;
}
});
assertSame('9,', a.join());
assertSame(1, callCount);
// Verifies cycle detection still works properly after continuation.
assertSame('9', a.join());
assertSame(2, callCount);
})();
(function ElementsKindChangedToHoley() {
let callCount = 0;
const a = [0, 1];
Object.defineProperty(a, '0', {
configurable: true,
get() {
callCount++;
a.length = 3;
return 9;
}
});
assertSame('9,1', a.join());
assertSame(1, callCount);
// Verifies cycle detection still works properly after continuation.
assertSame('9,1,', a.join());
assertSame(2, callCount);
})();