| 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 171 } | 171 } | 
| 172 | 172 | 
| 173 | 173 | 
| 174 // Left operand (this) is already a string. | 174 // Left operand (this) is already a string. | 
| 175 function STRING_ADD_LEFT(y) { | 175 function STRING_ADD_LEFT(y) { | 
| 176   if (!IS_STRING(y)) { | 176   if (!IS_STRING(y)) { | 
| 177     if (IS_STRING_WRAPPER(y)) { | 177     if (IS_STRING_WRAPPER(y)) { | 
| 178       y = %_ValueOf(y); | 178       y = %_ValueOf(y); | 
| 179     } else { | 179     } else { | 
| 180       y = IS_NUMBER(y) | 180       y = IS_NUMBER(y) | 
| 181           ? %NumberToString(y) | 181           ? %_NumberToString(y) | 
| 182           : %ToString(%ToPrimitive(y, NO_HINT)); | 182           : %ToString(%ToPrimitive(y, NO_HINT)); | 
| 183     } | 183     } | 
| 184   } | 184   } | 
| 185   return %_StringAdd(this, y); | 185   return %_StringAdd(this, y); | 
| 186 } | 186 } | 
| 187 | 187 | 
| 188 | 188 | 
| 189 // Right operand (y) is already a string. | 189 // Right operand (y) is already a string. | 
| 190 function STRING_ADD_RIGHT(y) { | 190 function STRING_ADD_RIGHT(y) { | 
| 191   var x = this; | 191   var x = this; | 
| 192   if (!IS_STRING(x)) { | 192   if (!IS_STRING(x)) { | 
| 193     if (IS_STRING_WRAPPER(x)) { | 193     if (IS_STRING_WRAPPER(x)) { | 
| 194       x = %_ValueOf(x); | 194       x = %_ValueOf(x); | 
| 195     } else { | 195     } else { | 
| 196       x = IS_NUMBER(x) | 196       x = IS_NUMBER(x) | 
| 197           ? %NumberToString(x) | 197           ? %_NumberToString(x) | 
| 198           : %ToString(%ToPrimitive(x, NO_HINT)); | 198           : %ToString(%ToPrimitive(x, NO_HINT)); | 
| 199     } | 199     } | 
| 200   } | 200   } | 
| 201   return %_StringAdd(x, y); | 201   return %_StringAdd(x, y); | 
| 202 } | 202 } | 
| 203 | 203 | 
| 204 | 204 | 
| 205 // ECMA-262, section 11.6.2, page 50. | 205 // ECMA-262, section 11.6.2, page 50. | 
| 206 function SUB(y) { | 206 function SUB(y) { | 
| 207   var x = IS_NUMBER(this) ? this : %ToNumber(this); | 207   var x = IS_NUMBER(this) ? this : %ToNumber(this); | 
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 522   if (IS_STRING(x)) return %StringToNumber(x); | 522   if (IS_STRING(x)) return %StringToNumber(x); | 
| 523   if (IS_BOOLEAN(x)) return x ? 1 : 0; | 523   if (IS_BOOLEAN(x)) return x ? 1 : 0; | 
| 524   if (IS_UNDEFINED(x)) return $NaN; | 524   if (IS_UNDEFINED(x)) return $NaN; | 
| 525   return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x)); | 525   return (IS_NULL(x)) ? 0 : ToNumber(%DefaultNumber(x)); | 
| 526 } | 526 } | 
| 527 | 527 | 
| 528 | 528 | 
| 529 // ECMA-262, section 9.8, page 35. | 529 // ECMA-262, section 9.8, page 35. | 
| 530 function ToString(x) { | 530 function ToString(x) { | 
| 531   if (IS_STRING(x)) return x; | 531   if (IS_STRING(x)) return x; | 
| 532   if (IS_NUMBER(x)) return %NumberToString(x); | 532   if (IS_NUMBER(x)) return %_NumberToString(x); | 
| 533   if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; | 533   if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; | 
| 534   if (IS_UNDEFINED(x)) return 'undefined'; | 534   if (IS_UNDEFINED(x)) return 'undefined'; | 
| 535   return (IS_NULL(x)) ? 'null' : %ToString(%DefaultString(x)); | 535   return (IS_NULL(x)) ? 'null' : %ToString(%DefaultString(x)); | 
| 536 } | 536 } | 
| 537 | 537 | 
| 538 | 538 | 
| 539 // ECMA-262, section 9.9, page 36. | 539 // ECMA-262, section 9.9, page 36. | 
| 540 function ToObject(x) { | 540 function ToObject(x) { | 
| 541   if (IS_STRING(x)) return new $String(x); | 541   if (IS_STRING(x)) return new $String(x); | 
| 542   if (IS_NUMBER(x)) return new $Number(x); | 542   if (IS_NUMBER(x)) return new $Number(x); | 
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 638   throw %MakeTypeError('cannot_convert_to_primitive', []); | 638   throw %MakeTypeError('cannot_convert_to_primitive', []); | 
| 639 } | 639 } | 
| 640 | 640 | 
| 641 | 641 | 
| 642 // NOTE: Setting the prototype for Array must take place as early as | 642 // NOTE: Setting the prototype for Array must take place as early as | 
| 643 // possible due to code generation for array literals.  When | 643 // possible due to code generation for array literals.  When | 
| 644 // generating code for a array literal a boilerplate array is created | 644 // generating code for a array literal a boilerplate array is created | 
| 645 // that is cloned when running the code.  It is essiential that the | 645 // that is cloned when running the code.  It is essiential that the | 
| 646 // boilerplate gets the right prototype. | 646 // boilerplate gets the right prototype. | 
| 647 %FunctionSetPrototype($Array, new $Array(0)); | 647 %FunctionSetPrototype($Array, new $Array(0)); | 
| OLD | NEW | 
|---|