| 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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 /* ------------------------------------- | 389 /* ------------------------------------- |
| 390 - - - C o n v e r s i o n s - - - | 390 - - - C o n v e r s i o n s - - - |
| 391 ------------------------------------- | 391 ------------------------------------- |
| 392 */ | 392 */ |
| 393 | 393 |
| 394 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, | 394 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, |
| 395 // (1) for number hint, and (2) for string hint. | 395 // (1) for number hint, and (2) for string hint. |
| 396 function ToPrimitive(x, hint) { | 396 function ToPrimitive(x, hint) { |
| 397 // Fast case check. | 397 // Fast case check. |
| 398 if (IS_STRING(x)) return x; | 398 if (IS_STRING(x)) return x; |
| 399 if ((hint != NUMBER_HINT) && %IsStringClass(x)) return %_ValueOf(x); | |
| 400 // Normal behaior. | 399 // Normal behaior. |
| 401 if (!IS_OBJECT(x) && !IS_FUNCTION(x)) return x; | 400 if (!IS_OBJECT(x) && !IS_FUNCTION(x)) return x; |
| 402 if (x == null) return x; // check for null, undefined | 401 if (x == null) return x; // check for null, undefined |
| 403 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT; | 402 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT; |
| 404 return (hint == NUMBER_HINT) ? %DefaultNumber(x) : %DefaultString(x); | 403 return (hint == NUMBER_HINT) ? %DefaultNumber(x) : %DefaultString(x); |
| 405 } | 404 } |
| 406 | 405 |
| 407 | 406 |
| 408 // ECMA-262, section 9.3, page 31. | 407 // ECMA-262, section 9.3, page 31. |
| 409 function ToNumber(x) { | 408 function ToNumber(x) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 throw %MakeTypeError('cannot_convert_to_primitive', []); | 515 throw %MakeTypeError('cannot_convert_to_primitive', []); |
| 517 } | 516 } |
| 518 | 517 |
| 519 | 518 |
| 520 // NOTE: Setting the prototype for Array must take place as early as | 519 // NOTE: Setting the prototype for Array must take place as early as |
| 521 // possible due to code generation for array literals. When | 520 // possible due to code generation for array literals. When |
| 522 // generating code for a array literal a boilerplate array is created | 521 // generating code for a array literal a boilerplate array is created |
| 523 // that is cloned when running the code. It is essiential that the | 522 // that is cloned when running the code. It is essiential that the |
| 524 // boilerplate gets the right prototype. | 523 // boilerplate gets the right prototype. |
| 525 %FunctionSetPrototype($Array, new $Array(0)); | 524 %FunctionSetPrototype($Array, new $Array(0)); |
| OLD | NEW |