Add some of my tests.
authorMs2ger <ms2ger@gmail.com>
Tue, 19 Jun 2012 15:05:08 +0200
changeset 3 852ea5468c83
parent 2 2b7b097178a6
child 4 bf48376a006b
Add some of my tests.
builtins/Array.DefineOwnProperty.html
builtins/Array.prototype.join-order.html
builtins/MANIFEST
builtins/Math.max.html
builtins/Math.maxmin.js
builtins/Math.min.html
builtins/Object.prototype.hasOwnProperty-order.html
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/builtins/Array.DefineOwnProperty.html	Tue Jun 19 15:05:08 2012 +0200
@@ -0,0 +1,25 @@
+<!doctype html>
+<title>Array.[[DefineOwnProperty]]</title>
+<link rel=author href=mailto:[email protected] title=Ms2ger>
+<link rel=help href=http://es5.github.com/#x15.4.5.1>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+
+<div id=log></div>
+<script>
+test(function() {
+  var arr = new Array;
+  assert_equals(arr.length, 0);
+
+  var called = 0;
+  Object.defineProperty(arr, 0, { get: function() { ++called; return 7 } });
+  assert_equals(arr.length, 1);
+  assert_equals(called, 0);
+
+  assert_equals(arr[0], 7);
+  assert_equals(called, 1);
+
+  assert_equals(String(arr), "7");
+  assert_equals(called, 2);
+});
+</script>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/builtins/Array.prototype.join-order.html	Tue Jun 19 15:05:08 2012 +0200
@@ -0,0 +1,82 @@
+<!doctype html>
+<title>Array.prototype.join</title>
+<link rel=author href=mailto:[email protected] title=Ms2ger>
+<link rel=help href=http://es5.github.com/#x15.4.4.5>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+
+<div id=log></div>
+<script>
+var test_error = { name: "test" };
+
+// Step 1.
+test(function() {
+  assert_throws(new TypeError(), function() {
+    [].join.call(null, {
+      toString: function() { assert_unreached(); }
+    });
+  });
+  assert_throws(new TypeError(), function() {
+    [].join.call(undefined, {
+      toString: function() { assert_unreached(); }
+    });
+  });
+}, "Array.prototype.join must call ToObject before looking at the separator argument.")
+
+var generateTest = function(throwing_getter) {
+  var throwing_object = {};
+  var interfaces = [Boolean, Number];
+
+  var objects = interfaces.map(function(p) { return p.prototype; });
+  objects.push(throwing_object);
+  objects.forEach(function(object) {
+    Object.defineProperty(object, "length", {
+      get: throwing_getter,
+      configurable: true
+    });
+  });
+
+  [throwing_object, true, false, 0, 1, Math.PI].forEach(function(that) {
+    test(function() {
+      assert_throws(test_error, function() {
+        [].join.call(that, ",");
+      });
+    }, "Array.prototype.join must forward the exception from the this object's length property")
+    test(function() {
+      assert_throws(test_error, function() {
+        [].join.call(that, {
+          toString: function() { assert_unreached(); }
+        });
+      });
+    }, "Array.prototype.join must get the this object's length property before looking at the separator argument.")
+  });
+  interfaces.forEach(function(iface) {
+    delete iface.length;
+  });
+}
+
+// Step 2.
+test(function() {
+  generateTest(function() { throw test_error; });
+}, "Step 2.");
+
+// Step 3.
+test(function() {
+  generateTest(function() {
+    return {
+      valueOf: function() { throw test_error; }
+    };
+  });
+  generateTest(function() {
+    return {
+      toString: function() { throw test_error; }
+    };
+  });
+  generateTest(function() {
+    return {
+      valueOf: function() { throw test_error; },
+      toString: function() { assert_notreached("toString should not be invoked if valueOf exists"); }
+    };
+  });
+}, "Step 3.");
+</script>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/builtins/MANIFEST	Tue Jun 19 15:05:08 2012 +0200
@@ -0,0 +1,6 @@
+Array.DefineOwnProperty.html
+Array.prototype.join-order.html
+Math.max.html
+support Math.maxmin.js
+Math.min.html
+Object.prototype.hasOwnProperty-order.html
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/builtins/Math.max.html	Tue Jun 19 15:05:08 2012 +0200
@@ -0,0 +1,13 @@
+<!doctype html>
+<title>Math.max</title>
+<link rel=author href=mailto:[email protected] title=Ms2ger>
+<link rel=help href=http://es5.github.com/#x15.8.2>
+<link rel=help href=http://es5.github.com/#x15.8.2.11>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+
+<div id=log></div>
+<script src=Math.maxmin.js></script>
+<script>
+testMathMaxMin("max");
+</script>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/builtins/Math.maxmin.js	Tue Jun 19 15:05:08 2012 +0200
@@ -0,0 +1,47 @@
+function testMathMaxMin(aFun) {
+  var test_error = { name: "test" };
+  test(function() {
+    assert_throws(test_error, function() {
+      Math[aFun](NaN, {
+        valueOf: function() {
+          throw test_error;
+        }
+      });
+    });
+  }, "ToNumber should be called on all arguments: NaN.");
+  test(function() {
+    assert_throws(test_error, function() {
+      Math[aFun](-Infinity, {
+        valueOf: function() {
+          throw test_error;
+        }
+      });
+    });
+  }, "ToNumber should be called on all arguments: -Infinity.");
+  test(function() {
+    assert_throws(test_error, function() {
+      Math[aFun](Infinity, {
+        valueOf: function() {
+          throw test_error;
+        }
+      });
+    });
+  }, "ToNumber should be called on all arguments: Infinity.");
+  test(function() {
+    assert_throws(test_error, function() {
+      Math[aFun]({
+        valueOf: function() {
+          throw test_error;
+        }
+      },
+      {
+        valueOf: function() {
+          throw 7;
+        }
+      });
+    });
+  }, "ToNumber should be called left to right.");
+  test(function() {
+    assert_equals(Math[aFun]("1"), 1);
+  }, "Should return a number.");
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/builtins/Math.min.html	Tue Jun 19 15:05:08 2012 +0200
@@ -0,0 +1,13 @@
+<!doctype html>
+<title>Math.min</title>
+<link rel=author href=mailto:[email protected] title=Ms2ger>
+<link rel=help href=http://es5.github.com/#x15.8.2>
+<link rel=help href=http://es5.github.com/#x15.8.2.12>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+
+<div id=log></div>
+<script src=Math.maxmin.js></script>
+<script>
+testMathMaxMin("min");
+</script>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/builtins/Object.prototype.hasOwnProperty-order.html	Tue Jun 19 15:05:08 2012 +0200
@@ -0,0 +1,21 @@
+<!doctype html>
+<title>Object.prototype.hasOwnProperty</title>
+<link rel=author href=mailto:[email protected] title=Ms2ger>
+<link rel=help href=http://es5.github.com/#x15.4.4.5>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+
+<div id=log></div>
+<script>
+var test_error = { name: "test" };
+
+test(function() {
+  [null, undefined, {}].forEach(function(that) {
+    test(function() {
+      assert_throws(test_error, function() {
+        ({}).hasOwnProperty.call(that, { toString: function() { throw test_error; } });
+      });
+    });
+  });
+});
+</script>