Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / js / script-tests / array-sort-exception.js
blob522261ba0775652d8a9f32637b23c989f1ed0f1d
1 description(
2 "Test of array sort with toString() override that throws exception."
3 );
5 var size = 200;
6 var digits = 3;
7 var exceptionString = 'From toString()';
8 var catchArg = "";
10 var a = new Array(size);
12 function do_gc() {
13 if (window.GCController)
14 return GCController.collect();
16 for (var i = 0; i < 1000; i++)
17 new String(i);
20 function Item(val) {
21 this.value = val;
24 function toString_throw() {
25 var s = this.value.toString();
27 if (this.value >= size/2)
28 throw(exceptionString);
30 s = ('0000' + s).slice(-digits);
32 return s;
35 function test() {
36 for (var i = 0; i < a.length; i++) {
37 a[i] = new Item(a.length - i - 1);
38 a[i].toString = toString_throw;
41 try {
42 a.sort();
43 } catch(err) {
44 catchArg = err;
45 shouldBe("catchArg", "exceptionString");
47 do_gc();
49 return;
52 debug('ERROR: Never got toString() exception');
55 test();