| Index: src/runtime.js
|
| ===================================================================
|
| --- src/runtime.js (revision 3550)
|
| +++ src/runtime.js (working copy)
|
| @@ -114,30 +114,33 @@
|
| // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as
|
| // the result when either (or both) the operands are NaN.
|
| function COMPARE(x, ncr) {
|
| - // Fast case for numbers and strings.
|
| - if (IS_NUMBER(this) && IS_NUMBER(x)) {
|
| - return %NumberCompare(this, x, ncr);
|
| - }
|
| - if (IS_STRING(this) && IS_STRING(x)) {
|
| - return %StringCompare(this, x);
|
| - }
|
| + var left;
|
|
|
| - // If one of the operands is undefined, it will convert to NaN and
|
| - // thus the result should be as if one of the operands was NaN.
|
| - if (IS_UNDEFINED(this) || IS_UNDEFINED(x)) {
|
| + // Fast cases for string, numbers and undefined compares.
|
| + if (IS_STRING(this)) {
|
| + if (IS_STRING(x)) return %StringCompare(this, x);
|
| + if (IS_UNDEFINED(x)) return ncr;
|
| + left = this;
|
| + } else if (IS_NUMBER(this)) {
|
| + if (IS_NUMBER(x)) return %NumberCompare(this, x, ncr);
|
| + if (IS_UNDEFINED(x)) return ncr;
|
| + left = this;
|
| + } else if (IS_UNDEFINED(this)) {
|
| return ncr;
|
| + } else {
|
| + if (IS_UNDEFINED(x)) return ncr;
|
| + left = %ToPrimitive(this, NUMBER_HINT);
|
| }
|
|
|
| // Default implementation.
|
| - var a = %ToPrimitive(this, NUMBER_HINT);
|
| - var b = %ToPrimitive(x, NUMBER_HINT);
|
| - if (IS_STRING(a) && IS_STRING(b)) {
|
| - return %StringCompare(a, b);
|
| + var right = %ToPrimitive(x, NUMBER_HINT);
|
| + if (IS_STRING(left) && IS_STRING(right)) {
|
| + return %StringCompare(left, right);
|
| } else {
|
| - var a_number = %ToNumber(a);
|
| - var b_number = %ToNumber(b);
|
| - if (NUMBER_IS_NAN(a_number) || NUMBER_IS_NAN(b_number)) return ncr;
|
| - return %NumberCompare(a_number, b_number, ncr);
|
| + var left_number = %ToNumber(left);
|
| + var right_number = %ToNumber(right);
|
| + if (NUMBER_IS_NAN(left_number) || NUMBER_IS_NAN(right_number)) return ncr;
|
| + return %NumberCompare(left_number, right_number, ncr);
|
| }
|
| }
|
|
|
|
|