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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 x = %ToPrimitive(x, NO_HINT); | 87 x = %ToPrimitive(x, NO_HINT); |
88 } | 88 } |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 // ECMA-262, section 11.9.4, page 56. | 92 // ECMA-262, section 11.9.4, page 56. |
93 function STRICT_EQUALS(x) { | 93 function STRICT_EQUALS(x) { |
94 if (IS_NUMBER(this)) { | 94 if (IS_NUMBER(this)) { |
95 if (!IS_NUMBER(x)) return 1; // not equal | 95 if (!IS_NUMBER(x)) return 1; // not equal |
96 return %NumberEquals(this, x); | 96 return %NumberEquals(this, x); |
97 } | 97 } else if (IS_STRING(this)) { |
bak
2008/10/10 06:23:44
What is up with excessive use of else parts.
retur
| |
98 | |
99 if (IS_STRING(this)) { | |
100 if (!IS_STRING(x)) return 1; // not equal | 98 if (!IS_STRING(x)) return 1; // not equal |
101 return %StringEquals(this, x); | 99 return %StringEquals(this, x); |
100 } else if (IS_UNDEFINED(this)) { | |
101 // Both undefined and undetectable. | |
102 return IS_UNDEFINED(x) ? 0 : 1; | |
103 } else { | |
104 // Objects, null, booleans and functions are all that's left. | |
105 // They can all be compared with a simple identity check. | |
106 return %_ObjectEquals(this, x) ? 0 : 1; | |
102 } | 107 } |
103 | |
104 if (IS_BOOLEAN(this)) { | |
105 if (!IS_BOOLEAN(x)) return 1; // not equal | |
106 if (this) return x ? 0 : 1; | |
107 else return x ? 1 : 0; | |
108 } | |
109 | |
110 if (IS_UNDEFINED(this)) { // both undefined and undetectable | |
111 return IS_UNDEFINED(x) ? 0 : 1; | |
112 } | |
113 | |
114 return %_ObjectEquals(this, x) ? 0 : 1; | |
115 } | 108 } |
116 | 109 |
117 | 110 |
118 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as | 111 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as |
119 // the result when either (or both) the operands are NaN. | 112 // the result when either (or both) the operands are NaN. |
120 function COMPARE(x, ncr) { | 113 function COMPARE(x, ncr) { |
121 // Fast case for numbers and strings. | 114 // Fast case for numbers and strings. |
122 if (IS_NUMBER(this) && IS_NUMBER(x)) { | 115 if (IS_NUMBER(this) && IS_NUMBER(x)) { |
123 return %NumberCompare(this, x, ncr); | 116 return %NumberCompare(this, x, ncr); |
124 } | 117 } |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
518 throw %MakeTypeError('cannot_convert_to_primitive', []); | 511 throw %MakeTypeError('cannot_convert_to_primitive', []); |
519 } | 512 } |
520 | 513 |
521 | 514 |
522 // NOTE: Setting the prototype for Array must take place as early as | 515 // NOTE: Setting the prototype for Array must take place as early as |
523 // possible due to code generation for array literals. When | 516 // possible due to code generation for array literals. When |
524 // generating code for a array literal a boilerplate array is created | 517 // generating code for a array literal a boilerplate array is created |
525 // that is cloned when running the code. It is essiential that the | 518 // that is cloned when running the code. It is essiential that the |
526 // boilerplate gets the right prototype. | 519 // boilerplate gets the right prototype. |
527 %FunctionSetPrototype($Array, new $Array(0)); | 520 %FunctionSetPrototype($Array, new $Array(0)); |
OLD | NEW |