summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/array-tolocalestring.js
blob: a5f856907af0c509162da90e4f02fefa11e1a7c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// 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());
})();