Bug 792108 - Add more truthiness tests to ensure strict equality isn't affected by JSCLASS_EMULATES_UNDEFINED, and that falsy objects don't compare equal unless they're actually the same object. Just tests, they pass locally for me with the --tbpl driver option to do what Tinderbox does, r=sparky
authorJeff Walden <jwalden@mit.edu>
Tue, 18 Dec 2012 17:01:46 -0500
changeset 125550 62c52b199c9a566593444a029022f2783e88462f
parent 125549 ba2f2f5fb6b2f29948d0f35d961f8b84b8733f44
child 125551 a7d5ea538c57f4148ded6a1e8c2e3a21b57cb3c0
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssparky
bugs792108
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 792108 - Add more truthiness tests to ensure strict equality isn't affected by JSCLASS_EMULATES_UNDEFINED, and that falsy objects don't compare equal unless they're actually the same object. Just tests, they pass locally for me with the --tbpl driver option to do what Tinderbox does, r=sparky
js/src/jit-test/tests/truthiness/if-strict-equal-null.js
js/src/jit-test/tests/truthiness/if-strict-equal-undefined.js
js/src/jit-test/tests/truthiness/if-strict-not-equal-null.js
js/src/jit-test/tests/truthiness/if-strict-not-equal-undefined.js
js/src/jit-test/tests/truthiness/obj-obj-equal.js
js/src/jit-test/tests/truthiness/obj-obj-not-equal.js
js/src/jit-test/tests/truthiness/strict-equal-null.js
js/src/jit-test/tests/truthiness/strict-equal-undefined.js
js/src/jit-test/tests/truthiness/strict-not-equal-null.js
js/src/jit-test/tests/truthiness/strict-not-equal-undefined.js
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/truthiness/if-strict-equal-null.js
@@ -0,0 +1,46 @@
+var counterF = 0;
+
+function f(v, value)
+{
+  if (v === null)
+    counterF++;
+  assertEq(counterF, value,
+           "failed: " + v + " " + value);
+}
+
+f({}, 0);
+f({}, 0);
+f(null, 1);
+f(null, 2);
+f(undefined, 2);
+f(undefined, 2);
+f(objectEmulatingUndefined(), 2);
+f(objectEmulatingUndefined(), 2);
+f(Object.prototype, 2);
+f(Object.prototype, 2);
+
+var counterG = 0;
+
+function g(v, value)
+{
+  if (v === null)
+    counterG++;
+  assertEq(counterG, value,
+           "failed: " + v + " " + value);
+}
+
+g({}, 0);
+g({}, 0);
+
+var counterH = 0;
+
+function h(v, value)
+{
+  if (v === null)
+    counterH++;
+  assertEq(counterH, value,
+           "failed: " + v + " " + value);
+}
+
+h(objectEmulatingUndefined(), 0);
+h(objectEmulatingUndefined(), 0);
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/truthiness/if-strict-equal-undefined.js
@@ -0,0 +1,46 @@
+var counterF = 0;
+
+function f(v, value)
+{
+  if (v === undefined)
+    counterF++;
+  assertEq(counterF, value,
+           "failed: " + v + " " + value);
+}
+
+f({}, 0);
+f({}, 0);
+f(null, 0);
+f(null, 0);
+f(undefined, 1);
+f(undefined, 2);
+f(objectEmulatingUndefined(), 2);
+f(objectEmulatingUndefined(), 2);
+f(Object.prototype, 2);
+f(Object.prototype, 2);
+
+var counterG = 0;
+
+function g(v, value)
+{
+  if (v === undefined)
+    counterG++;
+  assertEq(counterG, value,
+           "failed: " + v + " " + value);
+}
+
+g({}, 0);
+g({}, 0);
+
+var counterH = 0;
+
+function h(v, value)
+{
+  if (v === undefined)
+    counterH++;
+  assertEq(counterH, value,
+           "failed: " + v + " " + value);
+}
+
+h(objectEmulatingUndefined(), 0);
+h(objectEmulatingUndefined(), 0);
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/truthiness/if-strict-not-equal-null.js
@@ -0,0 +1,46 @@
+var counterF = 0;
+
+function f(v, value)
+{
+  if (v !== null)
+    counterF++;
+  assertEq(counterF, value,
+           "failed: " + v + " " + value);
+}
+
+f({}, 1);
+f({}, 2);
+f(null, 2);
+f(null, 2);
+f(undefined, 3);
+f(undefined, 4);
+f(objectEmulatingUndefined(), 5);
+f(objectEmulatingUndefined(), 6);
+f(Object.prototype, 7);
+f(Object.prototype, 8);
+
+var counterG = 0;
+
+function g(v, value)
+{
+  if (v !== null)
+    counterG++;
+  assertEq(counterG, value,
+           "failed: " + v + " " + value);
+}
+
+g({}, 1);
+g({}, 2);
+
+var counterH = 0;
+
+function h(v, value)
+{
+  if (v !== null)
+    counterH++;
+  assertEq(counterH, value,
+           "failed: " + v + " " + value);
+}
+
+h(objectEmulatingUndefined(), 1);
+h(objectEmulatingUndefined(), 2);
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/truthiness/if-strict-not-equal-undefined.js
@@ -0,0 +1,46 @@
+var counterF = 0;
+
+function f(v, value)
+{
+  if (v !== undefined)
+    counterF++;
+  assertEq(counterF, value,
+           "failed: " + v + " " + value);
+}
+
+f({}, 1);
+f({}, 2);
+f(null, 3);
+f(null, 4);
+f(undefined, 4);
+f(undefined, 4);
+f(objectEmulatingUndefined(), 5);
+f(objectEmulatingUndefined(), 6);
+f(Object.prototype, 7);
+f(Object.prototype, 8);
+
+var counterG = 0;
+
+function g(v, value)
+{
+  if (v !== undefined)
+    counterG++;
+  assertEq(counterG, value,
+           "failed: " + v + " " + value);
+}
+
+g({}, 1);
+g({}, 2);
+
+var counterH = 0;
+
+function h(v, value)
+{
+  if (v !== undefined)
+    counterH++;
+  assertEq(counterH, value,
+           "failed: " + v + " " + value);
+}
+
+h(objectEmulatingUndefined(), 1);
+h(objectEmulatingUndefined(), 2);
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/truthiness/obj-obj-equal.js
@@ -0,0 +1,23 @@
+function f(v1, v2, value)
+{
+  var b = v1 == v2;
+  assertEq(b, value,
+           "failed: " + v1 + ", " + v2 + ": " + value);
+}
+
+var obj = {};
+var emul = objectEmulatingUndefined();
+
+f(obj, obj, true);
+f(obj, obj, true);
+f(emul, obj, false);
+f(emul, obj, false);
+f(obj, emul, false);
+f(obj, emul, false);
+f(Object.prototype, obj, false);
+f(Object.prototype, obj, false);
+f(emul, emul, true);
+f(objectEmulatingUndefined(), emul, false);
+f(objectEmulatingUndefined(), emul, false);
+f(emul, objectEmulatingUndefined(), false);
+f(emul, objectEmulatingUndefined(), false);
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/truthiness/obj-obj-not-equal.js
@@ -0,0 +1,23 @@
+function f(v1, v2, value)
+{
+  var b = v1 != v2;
+  assertEq(b, value,
+           "failed: " + v1 + ", " + v2 + ": " + value);
+}
+
+var obj = {};
+var emul = objectEmulatingUndefined();
+
+f(obj, obj, false);
+f(obj, obj, false);
+f(emul, obj, true);
+f(emul, obj, true);
+f(obj, emul, true);
+f(obj, emul, true);
+f(Object.prototype, obj, true);
+f(Object.prototype, obj, true);
+f(emul, emul, false);
+f(objectEmulatingUndefined(), emul, true);
+f(objectEmulatingUndefined(), emul, true);
+f(emul, objectEmulatingUndefined(), true);
+f(emul, objectEmulatingUndefined(), true);
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/truthiness/strict-equal-null.js
@@ -0,0 +1,37 @@
+function f(v, value)
+{
+  var b = v === null;
+  assertEq(b, value,
+           "failed: " + v + " " + value);
+}
+
+f({}, false);
+f({}, false);
+f(null, true);
+f(null, true);
+f(undefined, false);
+f(undefined, false);
+f(objectEmulatingUndefined(), false);
+f(objectEmulatingUndefined(), false);
+f(Object.prototype, false);
+f(Object.prototype, false);
+
+function g(v, value)
+{
+  var b = v === null;
+  assertEq(b, value,
+           "failed: " + v + " " + value);
+}
+
+g({}, false);
+g({}, false);
+
+function h(v, value)
+{
+  var b = v === null;
+  assertEq(b, value,
+           "failed: " + v + " " + value);
+}
+
+h(objectEmulatingUndefined(), false);
+h(objectEmulatingUndefined(), false);
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/truthiness/strict-equal-undefined.js
@@ -0,0 +1,37 @@
+function f(v, value)
+{
+  var b = v === undefined;
+  assertEq(b, value,
+           "failed: " + v + " " + value);
+}
+
+f({}, false);
+f({}, false);
+f(null, false);
+f(null, false);
+f(undefined, true);
+f(undefined, true);
+f(objectEmulatingUndefined(), false);
+f(objectEmulatingUndefined(), false);
+f(Object.prototype, false);
+f(Object.prototype, false);
+
+function g(v, value)
+{
+  var b = v === undefined;
+  assertEq(b, value,
+           "failed: " + v + " " + value);
+}
+
+g({}, false);
+g({}, false);
+
+function h(v, value)
+{
+  var b = v === undefined;
+  assertEq(b, value,
+           "failed: " + v + " " + value);
+}
+
+h(objectEmulatingUndefined(), false);
+h(objectEmulatingUndefined(), false);
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/truthiness/strict-not-equal-null.js
@@ -0,0 +1,37 @@
+function f(v, value)
+{
+  var b = v !== null;
+  assertEq(b, value,
+           "failed: " + v + " " + value);
+}
+
+f({}, true);
+f({}, true);
+f(null, false);
+f(null, false);
+f(undefined, true);
+f(undefined, true);
+f(objectEmulatingUndefined(), true);
+f(objectEmulatingUndefined(), true);
+f(Object.prototype, true);
+f(Object.prototype, true);
+
+function g(v, value)
+{
+  var b = v !== null;
+  assertEq(b, value,
+           "failed: " + v + " " + value);
+}
+
+g({}, true);
+g({}, true);
+
+function h(v, value)
+{
+  var b = v !== null;
+  assertEq(b, value,
+           "failed: " + v + " " + value);
+}
+
+h(objectEmulatingUndefined(), true);
+h(objectEmulatingUndefined(), true);
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/truthiness/strict-not-equal-undefined.js
@@ -0,0 +1,37 @@
+function f(v, value)
+{
+  var b = v !== undefined;
+  assertEq(b, value,
+           "failed: " + v + " " + value);
+}
+
+f({}, true);
+f({}, true);
+f(null, true);
+f(null, true);
+f(undefined, false);
+f(undefined, false);
+f(objectEmulatingUndefined(), true);
+f(objectEmulatingUndefined(), true);
+f(Object.prototype, true);
+f(Object.prototype, true);
+
+function g(v, value)
+{
+  var b = v !== undefined;
+  assertEq(b, value,
+           "failed: " + v + " " + value);
+}
+
+g({}, true);
+g({}, true);
+
+function h(v, value)
+{
+  var b = v !== undefined;
+  assertEq(b, value,
+           "failed: " + v + " " + value);
+}
+
+h(objectEmulatingUndefined(), true);
+h(objectEmulatingUndefined(), true);