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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 | 267 |
268 // ECMA-262, section 11.8.7, page 54. | 268 // ECMA-262, section 11.8.7, page 54. |
269 function IN(x) { | 269 function IN(x) { |
270 if (x == null || (!IS_OBJECT(x) && !IS_FUNCTION(x))) { | 270 if (x == null || (!IS_OBJECT(x) && !IS_FUNCTION(x))) { |
271 throw %MakeTypeError('invalid_in_operator_use', [this, x]); | 271 throw %MakeTypeError('invalid_in_operator_use', [this, x]); |
272 } | 272 } |
273 return %_IsNonNegativeSmi(this) ? %HasElement(x, this) : %HasProperty(x, %ToSt
ring(this)); | 273 return %_IsNonNegativeSmi(this) ? %HasElement(x, this) : %HasProperty(x, %ToSt
ring(this)); |
274 } | 274 } |
275 | 275 |
276 | 276 |
277 // ECMA-262, section 11.8.6, page 54. | 277 // ECMA-262, section 11.8.6, page 54. To make the implementation more |
| 278 // efficient, the return value should be zero if the 'this' is an |
| 279 // instance of F, and non-zero if not. This makes it possible to avoid |
| 280 // an expensive ToBoolean conversion in the generated code. |
278 function INSTANCE_OF(F) { | 281 function INSTANCE_OF(F) { |
279 var V = this; | 282 var V = this; |
280 if (!IS_FUNCTION(F)) { | 283 if (!IS_FUNCTION(F)) { |
281 throw %MakeTypeError('instanceof_function_expected', [V]); | 284 throw %MakeTypeError('instanceof_function_expected', [V]); |
282 } | 285 } |
283 | 286 |
284 // If V is not an object, return false. | 287 // If V is not an object, return false. |
285 if (IS_NULL(V) || (!IS_OBJECT(V) && !IS_FUNCTION(V))) { | 288 if (IS_NULL(V) || (!IS_OBJECT(V) && !IS_FUNCTION(V))) { |
286 return false; | 289 return 1; |
287 } | 290 } |
288 | 291 |
289 // Get the prototype of F; if it is not an object, throw an error. | 292 // Get the prototype of F; if it is not an object, throw an error. |
290 var O = F.prototype; | 293 var O = F.prototype; |
291 if (IS_NULL(O) || (!IS_OBJECT(O) && !IS_FUNCTION(O))) { | 294 if (IS_NULL(O) || (!IS_OBJECT(O) && !IS_FUNCTION(O))) { |
292 throw %MakeTypeError('instanceof_nonobject_proto', [O]); | 295 throw %MakeTypeError('instanceof_nonobject_proto', [O]); |
293 } | 296 } |
294 | 297 |
295 // Return whether or not O is in the prototype chain of V. | 298 // Return whether or not O is in the prototype chain of V. |
296 return %IsInPrototypeChain(O, V); | 299 return %IsInPrototypeChain(O, V) ? 0 : 1; |
297 } | 300 } |
298 | 301 |
299 | 302 |
300 // Get an array of property keys for the given object. Used in | 303 // Get an array of property keys for the given object. Used in |
301 // for-in statements. | 304 // for-in statements. |
302 function GET_KEYS() { | 305 function GET_KEYS() { |
303 return %GetPropertyNames(this); | 306 return %GetPropertyNames(this); |
304 } | 307 } |
305 | 308 |
306 | 309 |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 throw %MakeTypeError('cannot_convert_to_primitive', []); | 518 throw %MakeTypeError('cannot_convert_to_primitive', []); |
516 } | 519 } |
517 | 520 |
518 | 521 |
519 // NOTE: Setting the prototype for Array must take place as early as | 522 // NOTE: Setting the prototype for Array must take place as early as |
520 // possible due to code generation for array literals. When | 523 // possible due to code generation for array literals. When |
521 // generating code for a array literal a boilerplate array is created | 524 // generating code for a array literal a boilerplate array is created |
522 // that is cloned when running the code. It is essiential that the | 525 // that is cloned when running the code. It is essiential that the |
523 // boilerplate gets the right prototype. | 526 // boilerplate gets the right prototype. |
524 %FunctionSetPrototype($Array, new $Array(0)); | 527 %FunctionSetPrototype($Array, new $Array(0)); |
OLD | NEW |