|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 |
|
3 /* |
|
4 * Any copyright is dedicated to the Public Domain. |
|
5 * http://creativecommons.org/licenses/publicdomain/ |
|
6 */ |
|
7 |
|
8 var obj = {} |
|
9 |
|
10 function strict() { "use strict"; return this; } |
|
11 assertEq(strict.call(""), ""); |
|
12 assertEq(strict.call(true), true); |
|
13 assertEq(strict.call(42), 42); |
|
14 assertEq(strict.call(null), null); |
|
15 assertEq(strict.call(undefined), undefined); |
|
16 assertEq(strict.call(obj), obj); |
|
17 assertEq(new strict() instanceof Object, true); |
|
18 |
|
19 /* |
|
20 * The compiler internally converts x['foo'] to x.foo. Writing x[s] where |
|
21 * s='foo' is enough to throw it off the scent for now. |
|
22 */ |
|
23 var strictString = 'strict'; |
|
24 |
|
25 Boolean.prototype.strict = strict; |
|
26 assertEq(true.strict(), true); |
|
27 assertEq(true[strictString](), true); |
|
28 |
|
29 Number.prototype.strict = strict; |
|
30 assertEq((42).strict(), 42); |
|
31 assertEq(42[strictString](), 42); |
|
32 |
|
33 String.prototype.strict = strict; |
|
34 assertEq("".strict(), ""); |
|
35 assertEq(""[strictString](), ""); |
|
36 |
|
37 function lenient() { return this; } |
|
38 assertEq(lenient.call("") instanceof String, true); |
|
39 assertEq(lenient.call(true) instanceof Boolean, true); |
|
40 assertEq(lenient.call(42) instanceof Number, true); |
|
41 assertEq(lenient.call(null), this); |
|
42 assertEq(lenient.call(undefined), this); |
|
43 assertEq(lenient.call(obj), obj); |
|
44 assertEq(new lenient() instanceof Object, true); |
|
45 |
|
46 var lenientString = 'lenient'; |
|
47 |
|
48 Boolean.prototype.lenient = lenient; |
|
49 assertEq(true.lenient() instanceof Boolean, true); |
|
50 assertEq(true[lenientString]() instanceof Boolean, true); |
|
51 |
|
52 Number.prototype.lenient = lenient; |
|
53 assertEq(42[lenientString]() instanceof Number, true); |
|
54 |
|
55 String.prototype.lenient = lenient; |
|
56 assertEq(""[lenientString]() instanceof String, true); |
|
57 |
|
58 reportCompare(true, true); |