forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray-large.js
More file actions
60 lines (53 loc) · 1.76 KB
/
array-large.js
File metadata and controls
60 lines (53 loc) · 1.76 KB
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
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// RUN: %hermes -target=HBC -O %s | %FileCheck --match-full-lines %s
// RUN: %hermes -target=HBC -O -emit-binary -out %t.hbc %s && %hermes %t.hbc | %FileCheck --match-full-lines %s
print("Array.prototype.join with a large array should throw RangeError")
// CHECK-LABEL: Array.prototype.join with a large array should throw RangeError
var v = [];
// This number is chosen carefully to be 1 more than the max elements that
// JSArray supports with GenGC and MallocGC (NCGen has a smaller max).
v.length = 4294966272 + 1;
try {
// Trying to stringify this leads to Array.join() trying to allocate an
// array that is too large.
++v;
print("Succeeded");
} catch (e) {
print("Caught", e.name, e.message);
}
//CHECK: Caught{{.*}}
print("Array.prototype.join with a large string should throw RangeError")
// CHECK-LABEL: Array.prototype.join with a large string should throw RangeError
var str = " ";
for(var i = 0; i < 20; ++i)
str += str;
v = [];
v.length = 500;
try {
// This produces a 500MB string, which should throw an exception.
v.join(str);
print("Succeeded");
} catch (e) {
print("Caught", e.name, e.message);
}
//CHECK-NEXT: Caught{{.*}}
print("Array.prototype.toLocaleString with an array of large strings should throw RangeError")
// CHECK-LABEL: Array.prototype.toLocaleString with an array of large strings should throw RangeError
var a = 'a';
for (var i = 0; i < 28; ++i) {
a = a + a;
}
print(a.length);
// CHECK-NEXT: 268435456
try {
[a, a, a].toLocaleString();
print("Succeeded");
} catch (e) {
print("Caught", e.name, e.message);
}
//CHECK-NEXT: Caught RangeError{{.*}}