tizen beta release
[profile/ivi/webkit-efl.git] / LayoutTests / fast / js / script-tests / strict-callback-this.js
1 description(
2 "This tests that a call to array/string prototype methods pass the correct this value (undefined) to strict callees."
3 );
4
5 var undefinedString = String(undefined);
6 var globalObjectString = String(this);
7
8 function strictThrowThisString()
9 {
10     "use strict";
11     throw String(this);
12 }
13
14 function nonstrictThrowThisString()
15 {
16     throw String(this);
17 }
18
19 function testArrayPrototypeSort(callback)
20 {
21     try {
22         [1,2].sort(callback);
23     } catch (e) {
24         return e;
25     }
26     return "FAILED";
27 }
28
29 function testArrayPrototypeFilter(callback)
30 {
31     try {
32         [1,2].filter(callback);
33     } catch (e) {
34         return e;
35     }
36     return "FAILED";
37 }
38
39 function testArrayPrototypeMap(callback)
40 {
41     try {
42         [1,2].map(callback);
43     } catch (e) {
44         return e;
45     }
46     return "FAILED";
47 }
48
49 function testArrayPrototypeEvery(callback)
50 {
51     try {
52         [1,2].every(callback);
53     } catch (e) {
54         return e;
55     }
56     return "FAILED";
57 }
58
59 function testArrayPrototypeForEach(callback)
60 {
61     try {
62         [1,2].forEach(callback);
63     } catch (e) {
64         return e;
65     }
66     return "FAILED";
67 }
68
69 function testArrayPrototypeSome(callback)
70 {
71     try {
72         [1,2].some(callback);
73     } catch (e) {
74         return e;
75     }
76     return "FAILED";
77 }
78
79 function testStringPrototypeReplace(callback)
80 {
81     try {
82         "1,2".replace('1', callback);
83     } catch (e) {
84         return e;
85     }
86     return "FAILED";
87 }
88
89 shouldBe('testArrayPrototypeSort(strictThrowThisString)', 'undefinedString');
90 shouldBe('testArrayPrototypeFilter(strictThrowThisString)', 'undefinedString');
91 shouldBe('testArrayPrototypeMap(strictThrowThisString)', 'undefinedString');
92 shouldBe('testArrayPrototypeEvery(strictThrowThisString)', 'undefinedString');
93 shouldBe('testArrayPrototypeForEach(strictThrowThisString)', 'undefinedString');
94 shouldBe('testArrayPrototypeSome(strictThrowThisString)', 'undefinedString');
95 shouldBe('testStringPrototypeReplace(strictThrowThisString)', 'undefinedString');
96
97 shouldBe('testArrayPrototypeSort(nonstrictThrowThisString)', 'globalObjectString');
98 shouldBe('testArrayPrototypeFilter(nonstrictThrowThisString)', 'globalObjectString');
99 shouldBe('testArrayPrototypeMap(nonstrictThrowThisString)', 'globalObjectString');
100 shouldBe('testArrayPrototypeEvery(nonstrictThrowThisString)', 'globalObjectString');
101 shouldBe('testArrayPrototypeForEach(nonstrictThrowThisString)', 'globalObjectString');
102 shouldBe('testArrayPrototypeSome(nonstrictThrowThisString)', 'globalObjectString');
103 shouldBe('testStringPrototypeReplace(nonstrictThrowThisString)', 'globalObjectString');