OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 function InstallFunctions(object, attributes, functions) { | 49 function InstallFunctions(object, attributes, functions) { |
50 if (functions.length >= 8) { | 50 if (functions.length >= 8) { |
51 %OptimizeObjectForAddingMultipleProperties(object, functions.length >> 1); | 51 %OptimizeObjectForAddingMultipleProperties(object, functions.length >> 1); |
52 } | 52 } |
53 for (var i = 0; i < functions.length; i += 2) { | 53 for (var i = 0; i < functions.length; i += 2) { |
54 var key = functions[i]; | 54 var key = functions[i]; |
55 var f = functions[i + 1]; | 55 var f = functions[i + 1]; |
56 %FunctionSetName(f, key); | 56 %FunctionSetName(f, key); |
57 %FunctionRemovePrototype(f); | 57 %FunctionRemovePrototype(f); |
58 %SetProperty(object, key, f, attributes); | 58 %SetProperty(object, key, f, attributes); |
59 %SetES5Flag(f); | 59 %SetNativeFlag(f); |
60 } | 60 } |
61 %ToFastProperties(object); | 61 %ToFastProperties(object); |
62 } | 62 } |
63 | 63 |
64 // Emulates JSC by installing functions on a hidden prototype that | 64 // Emulates JSC by installing functions on a hidden prototype that |
65 // lies above the current object/prototype. This lets you override | 65 // lies above the current object/prototype. This lets you override |
66 // functions on String.prototype etc. and then restore the old function | 66 // functions on String.prototype etc. and then restore the old function |
67 // with delete. See http://code.google.com/p/chromium/issues/detail?id=1717 | 67 // with delete. See http://code.google.com/p/chromium/issues/detail?id=1717 |
68 function InstallFunctionsOnHiddenPrototype(object, attributes, functions) { | 68 function InstallFunctionsOnHiddenPrototype(object, attributes, functions) { |
69 var hidden_prototype = new $Object(); | 69 var hidden_prototype = new $Object(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 function GlobalParseFloat(string) { | 125 function GlobalParseFloat(string) { |
126 string = TO_STRING_INLINE(string); | 126 string = TO_STRING_INLINE(string); |
127 if (%_HasCachedArrayIndex(string)) return %_GetCachedArrayIndex(string); | 127 if (%_HasCachedArrayIndex(string)) return %_GetCachedArrayIndex(string); |
128 return %StringParseFloat(string); | 128 return %StringParseFloat(string); |
129 } | 129 } |
130 | 130 |
131 | 131 |
132 function GlobalEval(x) { | 132 function GlobalEval(x) { |
133 if (!IS_STRING(x)) return x; | 133 if (!IS_STRING(x)) return x; |
134 | 134 |
| 135 var receiver = this; |
135 var global_receiver = %GlobalReceiver(global); | 136 var global_receiver = %GlobalReceiver(global); |
136 var this_is_global_receiver = (this === global_receiver); | 137 |
| 138 if (receiver == null && !IS_UNDETECTABLE(receiver)) { |
| 139 receiver = global_receiver; |
| 140 } |
| 141 |
| 142 var this_is_global_receiver = (receiver === global_receiver); |
137 var global_is_detached = (global === global_receiver); | 143 var global_is_detached = (global === global_receiver); |
138 | 144 |
| 145 // For consistency with JSC we require the global object passed to |
| 146 // eval to be the global object from which 'eval' originated. This |
| 147 // is not mandated by the spec. |
139 if (!this_is_global_receiver || global_is_detached) { | 148 if (!this_is_global_receiver || global_is_detached) { |
140 throw new $EvalError('The "this" object passed to eval must ' + | 149 throw new $EvalError('The "this" object passed to eval must ' + |
141 'be the global object from which eval originated'); | 150 'be the global object from which eval originated'); |
142 } | 151 } |
143 | 152 |
144 var f = %CompileString(x); | 153 var f = %CompileString(x); |
145 if (!IS_FUNCTION(f)) return f; | 154 if (!IS_FUNCTION(f)) return f; |
146 | 155 |
147 return %_CallFunction(this, f); | 156 return %_CallFunction(receiver, f); |
148 } | 157 } |
149 | 158 |
150 | 159 |
151 // ---------------------------------------------------------------------------- | 160 // ---------------------------------------------------------------------------- |
152 | 161 |
153 | 162 |
154 function SetupGlobal() { | 163 function SetupGlobal() { |
155 // ECMA 262 - 15.1.1.1. | 164 // ECMA 262 - 15.1.1.1. |
156 %SetProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE); | 165 %SetProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE); |
157 | 166 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 248 |
240 | 249 |
241 // ECMA-262 - 15.2.4.6 | 250 // ECMA-262 - 15.2.4.6 |
242 function ObjectPropertyIsEnumerable(V) { | 251 function ObjectPropertyIsEnumerable(V) { |
243 return %IsPropertyEnumerable(ToObject(this), ToString(V)); | 252 return %IsPropertyEnumerable(ToObject(this), ToString(V)); |
244 } | 253 } |
245 | 254 |
246 | 255 |
247 // Extensions for providing property getters and setters. | 256 // Extensions for providing property getters and setters. |
248 function ObjectDefineGetter(name, fun) { | 257 function ObjectDefineGetter(name, fun) { |
249 if (this == null && !IS_UNDETECTABLE(this)) { | 258 var receiver = this; |
250 throw new $TypeError('Object.prototype.__defineGetter__: this is Null'); | 259 if (receiver == null && !IS_UNDETECTABLE(receiver)) { |
| 260 receiver = %GlobalReceiver(global); |
251 } | 261 } |
252 if (!IS_FUNCTION(fun)) { | 262 if (!IS_FUNCTION(fun)) { |
253 throw new $TypeError('Object.prototype.__defineGetter__: Expecting function'
); | 263 throw new $TypeError('Object.prototype.__defineGetter__: Expecting function'
); |
254 } | 264 } |
255 var desc = new PropertyDescriptor(); | 265 var desc = new PropertyDescriptor(); |
256 desc.setGet(fun); | 266 desc.setGet(fun); |
257 desc.setEnumerable(true); | 267 desc.setEnumerable(true); |
258 desc.setConfigurable(true); | 268 desc.setConfigurable(true); |
259 DefineOwnProperty(ToObject(this), ToString(name), desc, false); | 269 DefineOwnProperty(ToObject(receiver), ToString(name), desc, false); |
260 } | 270 } |
261 | 271 |
262 | 272 |
263 function ObjectLookupGetter(name) { | 273 function ObjectLookupGetter(name) { |
264 if (this == null && !IS_UNDETECTABLE(this)) { | 274 var receiver = this; |
265 throw new $TypeError('Object.prototype.__lookupGetter__: this is Null'); | 275 if (receiver == null && !IS_UNDETECTABLE(receiver)) { |
| 276 receiver = %GlobalReceiver(global); |
266 } | 277 } |
267 return %LookupAccessor(ToObject(this), ToString(name), GETTER); | 278 return %LookupAccessor(ToObject(receiver), ToString(name), GETTER); |
268 } | 279 } |
269 | 280 |
270 | 281 |
271 function ObjectDefineSetter(name, fun) { | 282 function ObjectDefineSetter(name, fun) { |
272 if (this == null && !IS_UNDETECTABLE(this)) { | 283 var receiver = this; |
273 throw new $TypeError('Object.prototype.__defineSetter__: this is Null'); | 284 if (receiver == null && !IS_UNDETECTABLE(receiver)) { |
| 285 receiver = %GlobalReceiver(global); |
274 } | 286 } |
275 if (!IS_FUNCTION(fun)) { | 287 if (!IS_FUNCTION(fun)) { |
276 throw new $TypeError( | 288 throw new $TypeError( |
277 'Object.prototype.__defineSetter__: Expecting function'); | 289 'Object.prototype.__defineSetter__: Expecting function'); |
278 } | 290 } |
279 var desc = new PropertyDescriptor(); | 291 var desc = new PropertyDescriptor(); |
280 desc.setSet(fun); | 292 desc.setSet(fun); |
281 desc.setEnumerable(true); | 293 desc.setEnumerable(true); |
282 desc.setConfigurable(true); | 294 desc.setConfigurable(true); |
283 DefineOwnProperty(ToObject(this), ToString(name), desc, false); | 295 DefineOwnProperty(ToObject(receiver), ToString(name), desc, false); |
284 } | 296 } |
285 | 297 |
286 | 298 |
287 function ObjectLookupSetter(name) { | 299 function ObjectLookupSetter(name) { |
288 if (this == null && !IS_UNDETECTABLE(this)) { | 300 var receiver = this; |
289 throw new $TypeError('Object.prototype.__lookupSetter__: this is Null'); | 301 if (receiver == null && !IS_UNDETECTABLE(receiver)) { |
| 302 receiver = %GlobalReceiver(global); |
290 } | 303 } |
291 return %LookupAccessor(ToObject(this), ToString(name), SETTER); | 304 return %LookupAccessor(ToObject(receiver), ToString(name), SETTER); |
292 } | 305 } |
293 | 306 |
294 | 307 |
295 function ObjectKeys(obj) { | 308 function ObjectKeys(obj) { |
296 if (!IS_SPEC_OBJECT(obj)) | 309 if (!IS_SPEC_OBJECT(obj)) |
297 throw MakeTypeError("obj_ctor_property_non_object", ["keys"]); | 310 throw MakeTypeError("obj_ctor_property_non_object", ["keys"]); |
298 return %LocalKeys(obj); | 311 return %LocalKeys(obj); |
299 } | 312 } |
300 | 313 |
301 | 314 |
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1301 // ---------------------------------------------------------------------------- | 1314 // ---------------------------------------------------------------------------- |
1302 | 1315 |
1303 function SetupFunction() { | 1316 function SetupFunction() { |
1304 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1317 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1305 "bind", FunctionBind, | 1318 "bind", FunctionBind, |
1306 "toString", FunctionToString | 1319 "toString", FunctionToString |
1307 )); | 1320 )); |
1308 } | 1321 } |
1309 | 1322 |
1310 SetupFunction(); | 1323 SetupFunction(); |
OLD | NEW |