js/src/tests/ecma_5/Expressions/primitive-this-boxing-behavior.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:5dedcbf69265
1 // Any copyright is dedicated to the Public Domain.
2 // http://creativecommons.org/licenses/publicdomain/
3
4 //-----------------------------------------------------------------------------
5 var BUGNUMBER = 732669;
6 var summary = "Primitive values don't box correctly";
7
8 print(BUGNUMBER + ": " + summary);
9
10 /**************
11 * BEGIN TEST *
12 **************/
13
14 var t;
15 function returnThis() { return this; }
16
17 // Boolean
18
19 Boolean.prototype.method = returnThis;
20 t = true.method();
21 assertEq(t !== Boolean.prototype, true);
22 assertEq(t.toString(), "true");
23
24 Object.defineProperty(Boolean.prototype, "property", { get: returnThis, configurable: true });
25 t = false.property;
26 assertEq(t !== Boolean.prototype, true);
27 assertEq(t.toString(), "false");
28
29 delete Boolean.prototype.method;
30 delete Boolean.prototype.property;
31
32
33 // Number
34
35 Number.prototype.method = returnThis;
36 t = 5..method();
37 assertEq(t !== Number.prototype, true);
38 assertEq(t.toString(), "5");
39
40 Object.defineProperty(Number.prototype, "property", { get: returnThis, configurable: true });
41 t = 17..property;
42 assertEq(t !== Number.prototype, true);
43 assertEq(t.toString(), "17");
44
45 delete Number.prototype.method;
46 delete Number.prototype.property;
47
48
49 // String
50
51 String.prototype.method = returnThis;
52 t = "foo".method();
53 assertEq(t !== String.prototype, true);
54 assertEq(t.toString(), "foo");
55
56 Object.defineProperty(String.prototype, "property", { get: returnThis, configurable: true });
57 t = "bar".property;
58 assertEq(t !== String.prototype, true);
59 assertEq(t.toString(), "bar");
60
61 delete String.prototype.method;
62 delete String.prototype.property;
63
64
65 // Object
66
67 Object.prototype.method = returnThis;
68
69 t = true.method();
70 assertEq(t !== Object.prototype, true);
71 assertEq(t !== Boolean.prototype, true);
72 assertEq(t.toString(), "true");
73
74 t = 42..method();
75 assertEq(t !== Object.prototype, true);
76 assertEq(t !== Number.prototype, true);
77 assertEq(t.toString(), "42");
78
79 t = "foo".method();
80 assertEq(t !== Object.prototype, true);
81 assertEq(t !== String.prototype, true);
82 assertEq(t.toString(), "foo");
83
84 Object.defineProperty(Object.prototype, "property", { get: returnThis, configurable: true });
85
86 t = false.property;
87 assertEq(t !== Object.prototype, true);
88 assertEq(t !== Boolean.prototype, true);
89 assertEq(t.toString(), "false");
90
91 t = 8675309..property;
92 assertEq(t !== Object.prototype, true);
93 assertEq(t !== Number.prototype, true);
94 assertEq(t.toString(), "8675309");
95
96 t = "bar".property;
97 assertEq(t !== Object.prototype, true);
98 assertEq(t !== String.prototype, true);
99 assertEq(t.toString(), "bar");
100
101 /******************************************************************************/
102
103 if (typeof reportCompare === "function")
104 reportCompare(true, true);
105
106 print("Tests complete");

mercurial