OLD | NEW |
---|---|
(Empty) | |
1 var array; | |
Mads Ager (chromium)
2009/05/04 12:20:31
Copyright header and a description of the "problem
| |
2 | |
3 array = [ | |
4 "toString", "toLocaleString", "join", "pop", "push", "concat", "reverse", | |
5 "shift", "unshift", "slice", "splice", "sort", "filter", "forEach", "some", | |
6 "every", "map", "indexOf", "lastIndexOf", "reduce", "reduceRight"]; | |
7 CheckJSCSemantics(Array.prototype, array, "Array prototype"); | |
8 | |
9 array = [ | |
10 "toString", "toDateString", "toTimeString", "toLocaleString", | |
11 "toLocaleDateString", "toLocaleTimeString", "valueOf", "getTime", | |
12 "getFullYear", "getUTCFullYear", "getMonth", "getUTCMonth", "getDate", | |
13 "getUTCDate", "getDay", "getUTCDay", "getHours", "getUTCHours", "getMinutes", | |
14 "getUTCMinutes", "getSeconds", "getUTCSeconds", "getMilliseconds", | |
15 "getUTCMilliseconds", "getTimezoneOffset", "setTime", "setMilliseconds", | |
16 "setUTCMilliseconds", "setSeconds", "setUTCSeconds", "setMinutes", | |
17 "setUTCMinutes", "setHours", "setUTCHours", "setDate", "setUTCDate", | |
18 "setMonth", "setUTCMonth", "setFullYear", "setUTCFullYear", "toGMTString", | |
19 "toUTCString", "getYear", "setYear", "toISOString", "toJSON"]; | |
20 CheckJSCSemantics(Date.prototype, array, "Date prototype"); | |
21 | |
22 array = [ | |
23 "random", "abs", "acos", "asin", "atan", "ceil", "cos", "exp", "floor", "log", | |
24 "round", "sin", "sqrt", "tan", "atan2", "pow", "max", "min"]; | |
25 CheckJSCSemantics(Math, array, "Math1"); | |
26 | |
27 CheckEcmaSemantics(Date, ["UTC", "parse", "now"], "Date"); | |
28 | |
29 array = [ | |
30 "E", "LN10", "LN2", "LOG2E", "LOG10E", "PI", "SQRT1_2", "SQRT2"]; | |
31 CheckDontDelete(Math, array, "Math2"); | |
32 | |
33 array = [ | |
34 "escape", "unescape", "decodeURI", "decodeURIComponent", "encodeURI", | |
35 "encodeURIComponent", "isNaN", "isFinite", "parseInt", "parseFloat", "eval", | |
36 "execScript"]; | |
37 CheckEcmaSemantics(this, array, "Global"); | |
38 CheckReadOnlyAttr(this, "Infinity"); | |
39 | |
40 array = ["exec", "test", "toString", "compile"]; | |
41 CheckEcmaSemantics(RegExp.prototype, array, "RegExp prototype"); | |
42 | |
43 array = [ | |
44 "toString", "toLocaleString", "valueOf", | |
45 //"hasOwnProperty", | |
46 "isPrototypeOf", "propertyIsEnumerable", "__defineGetter__", | |
47 "__lookupGetter__", "__defineSetter__", "__lookupSetter__"]; | |
48 CheckEcmaSemantics(Object.prototype, array, "Object prototype"); | |
49 | |
50 array = [ | |
51 "toString", "valueOf", "toJSON"]; | |
52 CheckEcmaSemantics(Boolean.prototype, array, "Boolean prototype"); | |
53 | |
54 array = [ | |
55 "toString", "toLocaleString", "valueOf", "toFixed", "toExponential", | |
56 "toPrecision", "toJSON"]; | |
57 CheckEcmaSemantics(Number.prototype, array, "Number prototype"); | |
58 | |
59 CheckEcmaSemantics(Function.prototype, ["toString"], "Function prototype"); | |
60 | |
61 array = [ | |
62 "charAt", "charCodeAt", "concat", "indexOf", | |
63 "lastIndexOf", "localeCompare", "match", "replace", "search", "slice", | |
64 "split", "substring", "substr", "toLowerCase", "toLocaleLowerCase", | |
65 "toUpperCase", "toLocaleUpperCase", "link", "anchor", "fontcolor", "fontsize", | |
66 "big", "blink", "bold", "fixed", "italics", "small", "strike", "sub", "sup", | |
67 "toJSON", "toString", "valueOf"]; | |
68 CheckJSCSemantics(String.prototype, array, "String prototype"); | |
69 CheckEcmaSemantics(String, ["fromCharCode"], "String"); | |
70 | |
71 | |
72 function CheckEcmaSemantics(type, props, name) { | |
73 print(name); | |
74 for (var i = 0; i < props.length; i++) { | |
75 CheckDeletable(type, props[i]); | |
76 } | |
77 } | |
78 | |
79 | |
80 function CheckJSCSemantics(type, props, name) { | |
81 print(name); | |
82 for (var i = 0; i < props.length; i++) { | |
83 CheckNotDeletable(type, props[i]); | |
84 } | |
85 } | |
86 | |
87 | |
88 function CheckDontDelete(type, props, name) { | |
89 print(name); | |
90 for (var i = 0; i < props.length; i++) { | |
91 CheckDontDeleteAttr(type, props[i]); | |
92 } | |
93 } | |
94 | |
95 | |
96 function CheckDeletable(type, prop) { | |
97 var old = type[prop]; | |
98 if (!type[prop]) return; | |
99 assertTrue(type.hasOwnProperty(prop), "inherited: " + prop); | |
100 var deleted = delete type[prop]; | |
101 assertTrue(deleted, "delete operator returned false: " + prop); | |
102 assertFalse(type.hasOwnProperty(prop), "still there after delete: " + prop); | |
103 type[prop] = "foo"; | |
104 assertEquals("foo", type[prop], "not overwritable: " + prop); | |
105 } | |
106 | |
107 | |
108 function CheckNotDeletable(type, prop) { | |
109 var old = type[prop]; | |
110 if (!type[prop]) return; | |
111 assertTrue(type.hasOwnProperty(prop), "inherited: " + prop); | |
112 var deleted = delete type[prop]; | |
113 // Comment this next line to pass the test on JSC: | |
114 assertFalse(deleted, "delete operator returned true: " + prop); | |
115 assertTrue(type.hasOwnProperty(prop), "not there after delete: " + prop); | |
116 type[prop] = "foo"; | |
117 assertEquals("foo", type[prop], "not overwritable: " + prop); | |
118 } | |
119 | |
120 | |
121 function CheckDontDeleteAttr(type, prop) { | |
122 var old = type[prop]; | |
123 if (!type[prop]) return; | |
124 assertTrue(type.hasOwnProperty(prop), "inherited: " + prop); | |
125 var deleted = delete type[prop]; | |
126 assertFalse(deleted, "delete operator returned true: " + prop); | |
127 assertTrue(type.hasOwnProperty(prop), "not there after delete: " + prop); | |
128 type[prop] = "foo"; | |
129 assertFalse("foo" == type[prop], "overwritable: " + prop); | |
130 } | |
131 | |
132 | |
133 function CheckReadOnlyAttr(type, prop) { | |
134 var old = type[prop]; | |
135 if (!type[prop]) return; | |
136 assertTrue(type.hasOwnProperty(prop), "inherited: " + prop); | |
137 var deleted = delete type[prop]; | |
138 assertFalse(deleted, "delete operator returned true: " + prop); | |
139 assertTrue(type.hasOwnProperty(prop), "not there after delete: " + prop); | |
140 type[prop] = "foo"; | |
141 assertEquals("foo", type[prop], "overwritable: " + prop); | |
142 } | |
143 | |
144 print("OK"); | |
OLD | NEW |