if (IS_STRING(this)) {
if (!IS_STRING(x)) return 1; // not equal
return %StringEquals(this, x);
- }
+ }
if (IS_NUMBER(this)) {
if (!IS_NUMBER(x)) return 1; // not equal
return %NumberEquals(this, x);
- }
+ }
// If anything else gets here, we just do simple identity check.
// Objects (including functions), null, undefined and booleans were
// Default implementation.
var a = %ToPrimitive(this, NO_HINT);
var b = %ToPrimitive(x, NO_HINT);
-
+
if (IS_STRING(a)) {
return %StringAdd(a, %ToString(b));
} else if (IS_STRING(b)) {
// Left operand (this) is already a string.
-function STRING_ADD_LEFT(x) {
- x = %ToString(%ToPrimitive(x, NO_HINT));
- return %StringAdd(this, x);
+function STRING_ADD_LEFT(y) {
+ if (!IS_STRING(y)) y = %ToString(%ToPrimitive(y, NO_HINT));
+ return %StringAdd(this, y);
}
-// Right operand (x) is already a string.
-function STRING_ADD_RIGHT(x) {
- var a = %ToString(%ToPrimitive(this, NO_HINT));
- return %StringAdd(a, x);
+// Right operand (y) is already a string.
+function STRING_ADD_RIGHT(y) {
+ var x = IS_STRING(this) ? this : %ToString(%ToPrimitive(this, NO_HINT));
+ return %StringAdd(x, y);
}
// ECMA-262, section 11.6.2, page 50.
-function SUB(x) {
- return %NumberSub(%ToNumber(this), %ToNumber(x));
+function SUB(y) {
+ var x = IS_NUMBER(this) ? this : %ToNumber(this);
+ if (!IS_NUMBER(y)) y = %ToNumber(y);
+ return %NumberSub(x, y);
}
// ECMA-262, section 11.5.1, page 48.
-function MUL(x) {
- return %NumberMul(%ToNumber(this), %ToNumber(x));
+function MUL(y) {
+ var x = IS_NUMBER(this) ? this : %ToNumber(this);
+ if (!IS_NUMBER(y)) y = %ToNumber(y);
+ return %NumberMul(x, y);
}
// ECMA-262, section 11.5.2, page 49.
-function DIV(x) {
- return %NumberDiv(%ToNumber(this), %ToNumber(x));
+function DIV(y) {
+ var x = IS_NUMBER(this) ? this : %ToNumber(this);
+ if (!IS_NUMBER(y)) y = %ToNumber(y);
+ return %NumberDiv(x, y);
}
// ECMA-262, section 11.5.3, page 49.
-function MOD(x) {
- return %NumberMod(%ToNumber(this), %ToNumber(x));
+function MOD(y) {
+ var x = IS_NUMBER(this) ? this : %ToNumber(this);
+ if (!IS_NUMBER(y)) y = %ToNumber(y);
+ return %NumberMod(x, y);
}
*/
// ECMA-262, section 11.10, page 57.
-function BIT_OR(x) {
- return %NumberOr(%ToNumber(this), %ToNumber(x));
+function BIT_OR(y) {
+ var x = IS_NUMBER(this) ? this : %ToNumber(this);
+ if (!IS_NUMBER(y)) y = %ToNumber(y);
+ return %NumberOr(x, y);
}
// ECMA-262, section 11.10, page 57.
-function BIT_AND(x) {
- return %NumberAnd(%ToNumber(this), %ToNumber(x));
+function BIT_AND(y) {
+ var x;
+ if (IS_NUMBER(this)) {
+ x = this;
+ } else {
+ x = %ToNumber(this);
+ // Optimize for the case where we end up AND'ing a value
+ // that doesn't convert to a number. This is common in
+ // certain benchmarks.
+ if (NUMBER_IS_NAN(x)) return 0;
+ }
+ if (!IS_NUMBER(y)) y = %ToNumber(y);
+ return %NumberAnd(x, y);
}
// ECMA-262, section 11.10, page 57.
-function BIT_XOR(x) {
- return %NumberXor(%ToNumber(this), %ToNumber(x));
+function BIT_XOR(y) {
+ var x = IS_NUMBER(this) ? this : %ToNumber(this);
+ if (!IS_NUMBER(y)) y = %ToNumber(y);
+ return %NumberXor(x, y);
}
// ECMA-262, section 11.4.7, page 47.
function UNARY_MINUS() {
- return %NumberUnaryMinus(%ToNumber(this));
+ var x = IS_NUMBER(this) ? this : %ToNumber(this);
+ return %NumberUnaryMinus(x);
}
// ECMA-262, section 11.4.8, page 48.
function BIT_NOT() {
- return %NumberNot(%ToNumber(this));
+ var x = IS_NUMBER(this) ? this : %ToNumber(this);
+ return %NumberNot(x);
}
// ECMA-262, section 11.7.1, page 51.
-function SHL(x) {
- return %NumberShl(%ToNumber(this), %ToNumber(x));
+function SHL(y) {
+ var x = IS_NUMBER(this) ? this : %ToNumber(this);
+ if (!IS_NUMBER(y)) y = %ToNumber(y);
+ return %NumberShl(x, y);
}
// ECMA-262, section 11.7.2, page 51.
-function SAR(x) {
- return %NumberSar(%ToNumber(this), %ToNumber(x));
+function SAR(y) {
+ var x;
+ if (IS_NUMBER(this)) {
+ x = this;
+ } else {
+ x = %ToNumber(this);
+ // Optimize for the case where we end up shifting a value
+ // that doesn't convert to a number. This is common in
+ // certain benchmarks.
+ if (NUMBER_IS_NAN(x)) return 0;
+ }
+ if (!IS_NUMBER(y)) y = %ToNumber(y);
+ return %NumberSar(x, y);
}
// ECMA-262, section 11.7.3, page 52.
-function SHR(x) {
- return %NumberShr(%ToNumber(this), %ToNumber(x));
+function SHR(y) {
+ var x = IS_NUMBER(this) ? this : %ToNumber(this);
+ if (!IS_NUMBER(y)) y = %ToNumber(y);
+ return %NumberShr(x, y);
}