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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 if (!IS_NUMBER(y)) y = %ToNumber(y); | 217 if (!IS_NUMBER(y)) y = %ToNumber(y); |
218 return %NumberOr(x, y); | 218 return %NumberOr(x, y); |
219 } | 219 } |
220 | 220 |
221 | 221 |
222 // ECMA-262, section 11.10, page 57. | 222 // ECMA-262, section 11.10, page 57. |
223 function BIT_AND(y) { | 223 function BIT_AND(y) { |
224 var x; | 224 var x; |
225 if (IS_NUMBER(this)) { | 225 if (IS_NUMBER(this)) { |
226 x = this; | 226 x = this; |
| 227 if (!IS_NUMBER(y)) y = %ToNumber(y); |
227 } else { | 228 } else { |
228 x = %ToNumber(this); | 229 x = %ToNumber(this); |
| 230 // Make sure to convert the right operand to a number before |
| 231 // bailing out in the fast case, but after converting the |
| 232 // left operand. This ensures that valueOf methods on the right |
| 233 // operand are always executed. |
| 234 if (!IS_NUMBER(y)) y = %ToNumber(y); |
229 // Optimize for the case where we end up AND'ing a value | 235 // Optimize for the case where we end up AND'ing a value |
230 // that doesn't convert to a number. This is common in | 236 // that doesn't convert to a number. This is common in |
231 // certain benchmarks. | 237 // certain benchmarks. |
232 if (NUMBER_IS_NAN(x)) return 0; | 238 if (NUMBER_IS_NAN(x)) return 0; |
233 } | 239 } |
234 if (!IS_NUMBER(y)) y = %ToNumber(y); | |
235 return %NumberAnd(x, y); | 240 return %NumberAnd(x, y); |
236 } | 241 } |
237 | 242 |
238 | 243 |
239 // ECMA-262, section 11.10, page 57. | 244 // ECMA-262, section 11.10, page 57. |
240 function BIT_XOR(y) { | 245 function BIT_XOR(y) { |
241 var x = IS_NUMBER(this) ? this : %ToNumber(this); | 246 var x = IS_NUMBER(this) ? this : %ToNumber(this); |
242 if (!IS_NUMBER(y)) y = %ToNumber(y); | 247 if (!IS_NUMBER(y)) y = %ToNumber(y); |
243 return %NumberXor(x, y); | 248 return %NumberXor(x, y); |
244 } | 249 } |
(...skipping 19 matching lines...) Expand all Loading... |
264 if (!IS_NUMBER(y)) y = %ToNumber(y); | 269 if (!IS_NUMBER(y)) y = %ToNumber(y); |
265 return %NumberShl(x, y); | 270 return %NumberShl(x, y); |
266 } | 271 } |
267 | 272 |
268 | 273 |
269 // ECMA-262, section 11.7.2, page 51. | 274 // ECMA-262, section 11.7.2, page 51. |
270 function SAR(y) { | 275 function SAR(y) { |
271 var x; | 276 var x; |
272 if (IS_NUMBER(this)) { | 277 if (IS_NUMBER(this)) { |
273 x = this; | 278 x = this; |
| 279 if (!IS_NUMBER(y)) y = %ToNumber(y); |
274 } else { | 280 } else { |
275 x = %ToNumber(this); | 281 x = %ToNumber(this); |
| 282 // Make sure to convert the right operand to a number before |
| 283 // bailing out in the fast case, but after converting the |
| 284 // left operand. This ensures that valueOf methods on the right |
| 285 // operand are always executed. |
| 286 if (!IS_NUMBER(y)) y = %ToNumber(y); |
276 // Optimize for the case where we end up shifting a value | 287 // Optimize for the case where we end up shifting a value |
277 // that doesn't convert to a number. This is common in | 288 // that doesn't convert to a number. This is common in |
278 // certain benchmarks. | 289 // certain benchmarks. |
279 if (NUMBER_IS_NAN(x)) return 0; | 290 if (NUMBER_IS_NAN(x)) return 0; |
280 } | 291 } |
281 if (!IS_NUMBER(y)) y = %ToNumber(y); | |
282 return %NumberSar(x, y); | 292 return %NumberSar(x, y); |
283 } | 293 } |
284 | 294 |
285 | 295 |
286 // ECMA-262, section 11.7.3, page 52. | 296 // ECMA-262, section 11.7.3, page 52. |
287 function SHR(y) { | 297 function SHR(y) { |
288 var x = IS_NUMBER(this) ? this : %ToNumber(this); | 298 var x = IS_NUMBER(this) ? this : %ToNumber(this); |
289 if (!IS_NUMBER(y)) y = %ToNumber(y); | 299 if (!IS_NUMBER(y)) y = %ToNumber(y); |
290 return %NumberShr(x, y); | 300 return %NumberShr(x, y); |
291 } | 301 } |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 throw %MakeTypeError('cannot_convert_to_primitive', []); | 578 throw %MakeTypeError('cannot_convert_to_primitive', []); |
569 } | 579 } |
570 | 580 |
571 | 581 |
572 // NOTE: Setting the prototype for Array must take place as early as | 582 // NOTE: Setting the prototype for Array must take place as early as |
573 // possible due to code generation for array literals. When | 583 // possible due to code generation for array literals. When |
574 // generating code for a array literal a boilerplate array is created | 584 // generating code for a array literal a boilerplate array is created |
575 // that is cloned when running the code. It is essiential that the | 585 // that is cloned when running the code. It is essiential that the |
576 // boilerplate gets the right prototype. | 586 // boilerplate gets the right prototype. |
577 %FunctionSetPrototype($Array, new $Array(0)); | 587 %FunctionSetPrototype($Array, new $Array(0)); |
OLD | NEW |