v8/test/mjsunit/array-tolocalestring.js
peterwmwong 952c097679 [builtins] Port Array.p.join to Torque.
This also includes ports of Array.p.toString and Array.p.toLocaleString.
Many parts of the old JS implementation are preserved, because
TypedArray.p.join still relies on it.  These will be removed once
TypedArray.p.join is ported to Torque.

To simplify implementation, special handling of extremely sparse arrays
has been removed.

Performance improvements vary by array size, elements, and sparse-ness.
Some quick numbers and graphs are here:
https://docs.google.com/spreadsheets/d/125VLmRMudk8XaomLCsZQ1ewc94WCqht-8GQwU3s9BW8/edit#gid=2087673710

Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;luci.v8.try:v8_linux_noi18n_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ia4069a068403ce36676c37401d349aefc976b045
Reviewed-on: https://chromium-review.googlesource.com/c/1196693
Commit-Queue: Peter Wong <peter.wm.wong@gmail.com>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56699}
2018-10-16 13:56:31 +00:00

73 lines
1.5 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.
(function CycleDetection() {
const arr = [
{
toLocaleString() {
return [1, arr];
}
}
];
assertSame('1,', arr.toLocaleString());
assertSame('1,', arr.toLocaleString());
})();
(function ThrowsError(){
function TestError() {}
const arr = [];
const obj = {
toLocaleString(){
throw new TestError();
}
};
arr[0] = obj;
assertThrows(() => arr.toLocaleString(), TestError);
// Verifies cycle detection still works properly after thrown error.
arr[0] = {
toLocaleString() {
return 1;
}
};
assertSame('1', arr.toLocaleString());
})();
(function AccessThrowsError(){
function TestError() {}
const arr = [];
const obj = {
get toLocaleString(){
throw new TestError();
}
};
arr[0] = obj;
assertThrows(() => arr.toLocaleString(), TestError);
// Verifies cycle detection still works properly after thrown error.
arr[0] = {
toLocaleString() {
return 1;
}
};
assertSame('1', arr.toLocaleString());
})();
(function NotCallable(){
const arr = [];
const obj = {
toLocaleString: 7
}
arr[0] = obj;
assertThrows(() => arr.toLocaleString(), TypeError, '7 is not a function');
// Verifies cycle detection still works properly after thrown error.
arr[0] = {
toLocaleString() {
return 1;
}
};
assertSame('1', arr.toLocaleString());
})();