Update to V8 with partial snapshots. This is taken from the partial_snapshot branch of V8.
diff --git a/src/runtime.js b/src/runtime.js
index c4c855e..10ef98e 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -506,6 +506,16 @@
}
+// ECMA-262, section 9.2, page 30
+function ToBoolean(x) {
+ if (IS_BOOLEAN(x)) return x;
+ if (IS_STRING(x)) return x.length != 0;
+ if (x == null) return false;
+ if (IS_NUMBER(x)) return !((x == 0) || NUMBER_IS_NAN(x));
+ return true;
+}
+
+
// ECMA-262, section 9.3, page 31.
function ToNumber(x) {
if (IS_NUMBER(x)) return x;
@@ -526,16 +536,6 @@
}
-// ... where did this come from?
-function ToBoolean(x) {
- if (IS_BOOLEAN(x)) return x;
- if (IS_STRING(x)) return x.length != 0;
- if (x == null) return false;
- if (IS_NUMBER(x)) return !((x == 0) || NUMBER_IS_NAN(x));
- return true;
-}
-
-
// ECMA-262, section 9.9, page 36.
function ToObject(x) {
if (IS_STRING(x)) return new $String(x);
@@ -569,6 +569,25 @@
}
+// ES5, section 9.12
+function SameValue(x, y) {
+ if (typeof x != typeof y) return false;
+ if (IS_NULL_OR_UNDEFINED(x)) return true;
+ if (IS_NUMBER(x)) {
+ if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true;
+ // x is +0 and y is -0 or vice versa
+ if (x === 0 && y === 0 && !%_IsSmi(x) && !%_IsSmi(y) &&
+ ((1 / x < 0 && 1 / y > 0) || (1 / x > 0 && 1 / y < 0))) {
+ return false;
+ }
+ return x == y;
+ }
+ if (IS_STRING(x)) return %StringEquals(x, y);
+ if (IS_BOOLEAN(x))return %NumberEquals(%ToNumber(x),%ToNumber(y));
+
+ return %_ObjectEquals(x, y);
+}
+
/* ---------------------------------
- - - U t i l i t i e s - - -