diff options
Diffstat (limited to 'testing/web-platform/tests/js')
17 files changed, 915 insertions, 0 deletions
diff --git a/testing/web-platform/tests/js/behaviours/SetPrototypeOf-window.html b/testing/web-platform/tests/js/behaviours/SetPrototypeOf-window.html new file mode 100644 index 000000000..0a6ec249f --- /dev/null +++ b/testing/web-platform/tests/js/behaviours/SetPrototypeOf-window.html @@ -0,0 +1,33 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<title>Test for [[SetPrototypeOf]] with Windows</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +test(function() { + assert_throws(new TypeError, function() { + Object.setPrototypeOf(window, window); + }, "Setting the prototype should throw"); +}, "Setting the prototype of a window to itself via setPrototypeOf"); + +test(function() { + assert_throws(new TypeError, function() { + window.__proto__ = window; + }, "Setting the prototype should throw"); +}, "Setting the prototype of a window to itself via __proto__"); + +test(function() { + assert_throws(new TypeError, function() { + Object.setPrototypeOf(window, Object.create(window)); + }, "Setting the prototype should throw"); +}, "Setting the prototype of a window to something that has the window on " + + "its proto chain via setPrototypeOf"); + +test(function() { + assert_throws(new TypeError, function() { + window.__proto__ = Object.create(window); + }, "Setting the prototype should throw"); +}, "Setting the prototype of a window to something that has the window on " + + "its proto chain via __proto__"); +</script> diff --git a/testing/web-platform/tests/js/builtins/Array.DefineOwnProperty.html b/testing/web-platform/tests/js/builtins/Array.DefineOwnProperty.html new file mode 100644 index 000000000..40ed00a4c --- /dev/null +++ b/testing/web-platform/tests/js/builtins/Array.DefineOwnProperty.html @@ -0,0 +1,24 @@ +<!doctype html> +<title>Array.[[DefineOwnProperty]]</title> +<link rel=author href=mailto:Ms2ger@gmail.com 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> diff --git a/testing/web-platform/tests/js/builtins/Array.prototype.join-order.html b/testing/web-platform/tests/js/builtins/Array.prototype.join-order.html new file mode 100644 index 000000000..e5589803a --- /dev/null +++ b/testing/web-platform/tests/js/builtins/Array.prototype.join-order.html @@ -0,0 +1,86 @@ +<!doctype html> +<title>Array.prototype.join</title> +<link rel=author href=mailto:Ms2ger@gmail.com 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, getter_name) { + 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 with this=" + format_value(that) + " and " + + "getter " + getter_name + ".") + 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 with this=" + + format_value(that) + " and getter " + getter_name + ".") + }); + interfaces.forEach(function(iface) { + delete iface.length; + }); +} + +// Step 2. +test(function() { + generateTest(function() { throw test_error; }, "function"); +}, "Step 2."); + +// Step 3. +test(function() { + generateTest(function() { + return { + valueOf: function() { throw test_error; } + }; + }, "valueOf"); + generateTest(function() { + return { + toString: function() { throw test_error; } + }; + }, "toString"); + generateTest(function() { + return { + valueOf: function() { throw test_error; }, + toString: function() { assert_unreached("toString should not be invoked if valueOf exists"); } + }; + }, "valueOf and toString"); +}, "Step 3."); +</script> diff --git a/testing/web-platform/tests/js/builtins/Math.max.html b/testing/web-platform/tests/js/builtins/Math.max.html new file mode 100644 index 000000000..a4a6ae27c --- /dev/null +++ b/testing/web-platform/tests/js/builtins/Math.max.html @@ -0,0 +1,13 @@ +<!doctype html> +<title>Math.max</title> +<link rel=author href=mailto:Ms2ger@gmail.com 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> diff --git a/testing/web-platform/tests/js/builtins/Math.maxmin.js b/testing/web-platform/tests/js/builtins/Math.maxmin.js new file mode 100644 index 000000000..a414465fb --- /dev/null +++ b/testing/web-platform/tests/js/builtins/Math.maxmin.js @@ -0,0 +1,57 @@ +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."); + test(function() { + var expected = { + "max": 0, + "min": -0 + } + assert_equals(Math[aFun](0, -0), expected[aFun]); + assert_equals(Math[aFun](-0, 0), expected[aFun]); + assert_equals(Math[aFun](0, 0), 0); + assert_equals(Math[aFun](-0, -0), -0); + }, "Should handle negative zero correctly."); +} diff --git a/testing/web-platform/tests/js/builtins/Math.min.html b/testing/web-platform/tests/js/builtins/Math.min.html new file mode 100644 index 000000000..4ae71b9d7 --- /dev/null +++ b/testing/web-platform/tests/js/builtins/Math.min.html @@ -0,0 +1,13 @@ +<!doctype html> +<title>Math.min</title> +<link rel=author href=mailto:Ms2ger@gmail.com 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> diff --git a/testing/web-platform/tests/js/builtins/Object.prototype.freeze.html b/testing/web-platform/tests/js/builtins/Object.prototype.freeze.html new file mode 100644 index 000000000..47a50b33d --- /dev/null +++ b/testing/web-platform/tests/js/builtins/Object.prototype.freeze.html @@ -0,0 +1,52 @@ +<!doctype html> +<!-- +Distributed under both the W3C Test Suite License [1] and the W3C +3-clause BSD License [2]. To contribute to a W3C Test Suite, see the +policies and contribution forms [3]. + +[1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license +[2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license +[3] http://www.w3.org/2004/10/27-testcases +--> +<html> +<head> +<meta charset="utf-8"> +<title>Object.freeze</title> +<link rel="author" title="Masaya Iseki" href="mailto:iseki.m.aa@gmail.com"> +<link rel="help" href="https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.freeze"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script> +test(function() { + [{}, []].forEach(function(that) { + assert_false(Object.isFrozen(that)); + that.prop = 'exist'; + + Object.freeze(that); + assert_false(Object.isExtensible(that)); + assert_true(Object.isSealed(that)); + assert_true(Object.isFrozen(that)); + + that.extension = 'This property should not be added'; + assert_equals(undefined, that.extension, 'Confirm to prevent adding property.'); + + that.prop = 'changed'; + assert_equals('exist', that.prop, + 'Confirm to prevent changing a property value.'); + + delete that.prop; + assert_equals('exist', that.prop, 'Confirm to prevent deleting a property.'); + }); +}); + + +test(function() { + ['foo', 42, null, undefined].forEach(function(that) { + assert_throws(new TypeError(), + function() { Object.freeze(that) }); + }); +}); +</script> + +</body> +</html> diff --git a/testing/web-platform/tests/js/builtins/Object.prototype.getOwnPropertyNames.html b/testing/web-platform/tests/js/builtins/Object.prototype.getOwnPropertyNames.html new file mode 100644 index 000000000..582f41ba1 --- /dev/null +++ b/testing/web-platform/tests/js/builtins/Object.prototype.getOwnPropertyNames.html @@ -0,0 +1,56 @@ +<!doctype html> +<title>Object.prototype.getOwnPropertyNames</title> +<link rel=help href=http://es5.github.io/#x15.2.3.4> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> + +<div id=log></div> +<script> +test(function () { + var obj = {0: 'a', 1: 'b', 2: 'c'}; + assert_array_equals( + Object.getOwnPropertyNames(obj).sort(), + ['0', '1', '2'] + ); +}, "object"); + +test(function () { + var arr = ['a', 'b', 'c']; + assert_array_equals( + Object.getOwnPropertyNames(arr).sort(), + ['0', '1', '2', 'length'] + ); +}, "array-like"); + +test(function () { + var obj = Object.create({}, { + getFoo: { + value: function() { return this.foo; }, + enumerable: false + } + }); + obj.foo = 1; + assert_array_equals( + Object.getOwnPropertyNames(obj).sort(), + ['foo', 'getFoo'] + ); +}, "non-enumerable property"); + +test(function() { + function ParentClass() {} + ParentClass.prototype.inheritedMethod = function() {}; + + function ChildClass() { + this.prop = 5; + this.method = function() {}; + } + ChildClass.prototype = new ParentClass; + ChildClass.prototype.prototypeMethod = function() {}; + + var obj = new ChildClass; + assert_array_equals( + Object.getOwnPropertyNames(obj).sort(), + ['method', 'prop'] + ); +}, 'items on the prototype chain are not listed'); +</script> diff --git a/testing/web-platform/tests/js/builtins/Object.prototype.hasOwnProperty-order.html b/testing/web-platform/tests/js/builtins/Object.prototype.hasOwnProperty-order.html new file mode 100644 index 000000000..e67cff612 --- /dev/null +++ b/testing/web-platform/tests/js/builtins/Object.prototype.hasOwnProperty-order.html @@ -0,0 +1,21 @@ +<!doctype html> +<title>Object.prototype.hasOwnProperty</title> +<link rel=author href=mailto:Ms2ger@gmail.com 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> diff --git a/testing/web-platform/tests/js/builtins/Object.prototype.hasOwnProperty-prototype-chain.html b/testing/web-platform/tests/js/builtins/Object.prototype.hasOwnProperty-prototype-chain.html new file mode 100644 index 000000000..402f1ae6f --- /dev/null +++ b/testing/web-platform/tests/js/builtins/Object.prototype.hasOwnProperty-prototype-chain.html @@ -0,0 +1,44 @@ +<!doctype html> +<!-- +Distributed under both the W3C Test Suite License [1] and the W3C +3-clause BSD License [2]. To contribute to a W3C Test Suite, see the +policies and contribution forms [3]. + +[1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license +[2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license +[3] http://www.w3.org/2004/10/27-testcases +--> +<html> +<head> +<meta charset="utf-8"> +<title>Object.prototype.hasOwnProperty: Check prototype chain</title> +<link rel="author" title="Masaya Iseki" href="mailto:iseki.m.aa@gmail.com"> +<link rel="help" href="https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.hasownproperty"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script> +test(function() { + [{}, []].forEach(function(that) { + that.prop = 'exists'; + assert_true(that.hasOwnProperty('prop')); + assert_true('hasOwnProperty' in that); + assert_false(that.hasOwnProperty('hasOwnProperty')); + }); +}); + +test(function() { + ['foo', 42].forEach(function(that) { + assert_false(that.hasOwnProperty('hasOwnProperty')); + }); +}); + +test(function() { + [null, undefined].forEach(function(that) { + assert_throws(new TypeError(), + function() { that.hasOwnProperty('hasOwnProperty'); }); + }); +}); +</script> + +</body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/js/builtins/Object.prototype.preventExtensions.html b/testing/web-platform/tests/js/builtins/Object.prototype.preventExtensions.html new file mode 100644 index 000000000..36ac328d2 --- /dev/null +++ b/testing/web-platform/tests/js/builtins/Object.prototype.preventExtensions.html @@ -0,0 +1,51 @@ +<!doctype html> +<!-- +Distributed under both the W3C Test Suite License [1] and the W3C +3-clause BSD License [2]. To contribute to a W3C Test Suite, see the +policies and contribution forms [3]. + +[1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license +[2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license +[3] http://www.w3.org/2004/10/27-testcases +--> +<html> +<head> +<meta charset="utf-8"> +<title>Object.preventExtensions</title> +<link rel="author" title="Masaya Iseki" href="mailto:iseki.m.aa@gmail.com"> +<link rel="help" href="https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.preventextensions"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script> +test(function() { + [{}, []].forEach(function(that){ + assert_true(Object.isExtensible(that)); + that.prop = 'exist'; + + Object.preventExtensions(that); + assert_false(Object.isExtensible(that)); + assert_false(Object.isFrozen(that)); + assert_false(Object.isSealed(that)); + + that.extension = 'This property should not be added'; + assert_equals(undefined, that.extension, 'Confirm to prevent adding property.'); + + that.prop = 'changed'; + assert_equals('changed', that.prop, + 'Confirm to be able to change a property value.'); + + delete that.prop; + assert_equals(undefined, that.prop, 'Confirm to be able to delete a property.'); + }); +}); + +test(function() { + ['foo', 42, null, undefined].forEach(function(that) { + assert_throws(new TypeError(), + function() { Object.preventExtensions(that) }); + }); +}); +</script> + +</body> +</html> diff --git a/testing/web-platform/tests/js/builtins/Object.prototype.seal.html b/testing/web-platform/tests/js/builtins/Object.prototype.seal.html new file mode 100644 index 000000000..446d62786 --- /dev/null +++ b/testing/web-platform/tests/js/builtins/Object.prototype.seal.html @@ -0,0 +1,51 @@ +<!doctype html> +<!-- +Distributed under both the W3C Test Suite License [1] and the W3C +3-clause BSD License [2]. To contribute to a W3C Test Suite, see the +policies and contribution forms [3]. + +[1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license +[2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license +[3] http://www.w3.org/2004/10/27-testcases +--> +<html> +<head> +<meta charset="utf-8"> +<title>Object.seal</title> +<link rel="author" title="Masaya Iseki" href="mailto:iseki.m.aa@gmail.com"> +<link rel="help" href="https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.seal"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script> +test(function() { + [{}, []].forEach(function(that) { + assert_false(Object.isSealed(that)); + that.prop = 'exist'; + + Object.seal(that); + assert_false(Object.isExtensible(that)); + assert_true(Object.isSealed(that)); + assert_false(Object.isFrozen(that)); + + that.extension = 'This property should not be added'; + assert_equals(undefined, that.extension, 'Confirm to prevent adding property.'); + + that.prop = 'changed'; + assert_equals('changed', that.prop, + 'Confirm to be able to change a property value.'); + + delete that.prop; + assert_equals('changed', that.prop, 'Confirm to prevent deleting a property.'); + }); +}); + +test(function() { + ['foo', 42, null, undefined].forEach(function(that) { + assert_throws(new TypeError(), + function() { Object.seal(that) }); + }); +}); +</script> + +</body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/js/builtins/Promise-incumbent-global-subframe.sub.html b/testing/web-platform/tests/js/builtins/Promise-incumbent-global-subframe.sub.html new file mode 100644 index 000000000..dde0ac953 --- /dev/null +++ b/testing/web-platform/tests/js/builtins/Promise-incumbent-global-subframe.sub.html @@ -0,0 +1,12 @@ +<!DOCTYPE html> +<iframe src="{{location[scheme]}}://{{domains[www2]}}:{{ports[http][0]}}{{location[path]}}/../Promise-incumbent-global-subsubframe.sub.html"></iframe> +<script> + document.domain = "{{host}}"; + onmessage = function(e) { + if (e.data == "start") { + frames[0].Promise.resolve().then(frames[0].postMessage.bind(frames[0], "start", "*")); + } else { + parent.postMessage(e.data, "*"); + } + } +</script> diff --git a/testing/web-platform/tests/js/builtins/Promise-incumbent-global-subsubframe.sub.html b/testing/web-platform/tests/js/builtins/Promise-incumbent-global-subsubframe.sub.html new file mode 100644 index 000000000..9edd9d278 --- /dev/null +++ b/testing/web-platform/tests/js/builtins/Promise-incumbent-global-subsubframe.sub.html @@ -0,0 +1,13 @@ +<!DOCTYPE html> +<script> + document.domain = "{{host}}"; + onmessage = function (e) { + parent.postMessage( + { + actual: e.origin, + expected: "{{location[scheme]}}://{{domains[www1]}}:{{ports[http][0]}}", + reason: "Incumbent should have been the caller of then()" + }, + "*"); + } +</script> diff --git a/testing/web-platform/tests/js/builtins/Promise-incumbent-global.sub.html b/testing/web-platform/tests/js/builtins/Promise-incumbent-global.sub.html new file mode 100644 index 000000000..6ae0a9fe5 --- /dev/null +++ b/testing/web-platform/tests/js/builtins/Promise-incumbent-global.sub.html @@ -0,0 +1,20 @@ +<!doctype html> +<meta charset=utf-8> +<title></title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<iframe src="{{location[scheme]}}://{{domains[www1]}}:{{ports[http][0]}}{{location[path]}}/../Promise-incumbent-global-subframe.sub.html"></iframe> +<script> + +var t = async_test("Check the incumbent global Promise callbacks are called with"); + +onload = t.step_func(function() { + onmessage = t.step_func_done(function(e) { + var d = e.data; + assert_equals(d.actual, d.expected, d.reason); + }); + + frames[0].postMessage("start", "*"); +}); + +</script> diff --git a/testing/web-platform/tests/js/builtins/Promise-subclassing.html b/testing/web-platform/tests/js/builtins/Promise-subclassing.html new file mode 100644 index 000000000..7264f4661 --- /dev/null +++ b/testing/web-platform/tests/js/builtins/Promise-subclassing.html @@ -0,0 +1,265 @@ +<!doctype html> +<meta charset=utf-8> +<title></title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script> + +var theLog = []; +var speciesGets = 0; +var speciesCalls = 0; +var constructorCalls = 0; +var constructorGets = 0; +var resolveCalls = 0; +var rejectCalls = 0; +var thenCalls = 0; +var catchCalls = 0; +var allCalls = 0; +var raceCalls = 0; +var nextCalls = 0; + +function takeLog() { + var oldLog = theLog; + theLog = []; + speciesGets = speciesCalls = constructorCalls = resolveCalls = + rejectCalls = thenCalls = catchCalls = allCalls = raceCalls = + nextCalls = constructorGets = 0; + return oldLog; +} + +function clearLog() { + takeLog(); +} + +function log(str) { + theLog.push(str); +} + +class LoggingPromise extends Promise { + constructor(func) { + super(func); + Object.defineProperty(this, "constructor", + { + get: function() { + ++constructorGets; + log(`Constructor get ${constructorGets}`); + return Object.getPrototypeOf(this).constructor; + } + }); + ++constructorCalls; + log(`Constructor ${constructorCalls}`); + } + + static get [Symbol.species]() { + ++speciesGets; + log(`Species get ${speciesGets}`); + return LoggingSpecies; + } + + static resolve(val) { + ++resolveCalls; + log(`Resolve ${resolveCalls}`); + return super.resolve(val); + } + + static reject(val) { + ++rejectCalls; + log(`Reject ${rejectCalls}`); + return super.reject(val); + } + + then(resolve, reject) { + ++thenCalls; + log(`Then ${thenCalls}`); + return super.then(resolve, reject); + } + + catch(handler) { + ++catchCalls; + log(`Catch ${catchCalls}`); + return super.catch(handler); + } + + static all(val) { + ++allCalls; + log(`All ${allCalls}`); + return super.all(val); + } + + static race(val) { + ++raceCalls; + log(`Race ${raceCalls}`); + return super.race(val); + } +} + +class LoggingIterable { + constructor(array) { + this.iter = array[Symbol.iterator](); + } + + get [Symbol.iterator]() { return () => this } + + next() { + ++nextCalls; + log(`Next ${nextCalls}`); + return this.iter.next(); + } +} + +class LoggingSpecies extends LoggingPromise { + constructor(func) { + ++speciesCalls; + log(`Species call ${speciesCalls}`); + super(func) + } +} + +class SpeciesLessPromise extends LoggingPromise { + static get [Symbol.species]() { + return undefined; + } +} + +promise_test(function testBasicConstructor() { + var p = new LoggingPromise((resolve) => resolve(5)); + var log = takeLog(); + assert_array_equals(log, ["Constructor 1"]); + assert_true(p instanceof LoggingPromise); + return p.then(function(arg) { + assert_equals(arg, 5); + }); +}, "Basic constructor behavior"); + +promise_test(function testPromiseRace() { + clearLog(); + var p = LoggingPromise.race(new LoggingIterable([1, 2])); + var log = takeLog(); + assert_array_equals(log, ["Race 1", "Constructor 1", + "Next 1", "Resolve 1", "Constructor 2", + "Then 1", "Constructor get 1", "Species get 1", "Species call 1", "Constructor 3", + "Next 2", "Resolve 2", "Constructor 4", + "Then 2", "Constructor get 2", "Species get 2", "Species call 2", "Constructor 5", + "Next 3"]); + assert_true(p instanceof LoggingPromise); + return p.then(function(arg) { + assert_true(arg == 1 || arg == 2); + }); +}, "Promise.race behavior"); + +promise_test(function testPromiseRaceNoSpecies() { + clearLog(); + var p = SpeciesLessPromise.race(new LoggingIterable([1, 2])); + var log = takeLog(); + assert_array_equals(log, ["Race 1", "Constructor 1", + "Next 1", "Resolve 1", "Constructor 2", + "Then 1", "Constructor get 1", + "Next 2", "Resolve 2", "Constructor 3", + "Then 2", "Constructor get 2", + "Next 3"]); + assert_true(p instanceof SpeciesLessPromise); + return p.then(function(arg) { + assert_true(arg == 1 || arg == 2); + }); +}, "Promise.race without species behavior"); + +promise_test(function testPromiseAll() { + clearLog(); + var p = LoggingPromise.all(new LoggingIterable([1, 2])); + var log = takeLog(); + assert_array_equals(log, ["All 1", "Constructor 1", + "Next 1", "Resolve 1", "Constructor 2", + "Then 1", "Constructor get 1", "Species get 1", "Species call 1", "Constructor 3", + "Next 2", "Resolve 2", "Constructor 4", + "Then 2", "Constructor get 2", "Species get 2", "Species call 2", "Constructor 5", + "Next 3"]); + assert_true(p instanceof LoggingPromise); + return p.then(function(arg) { + assert_array_equals(arg, [1, 2]); + }); +}, "Promise.all behavior"); + +promise_test(function testPromiseResolve() { + clearLog(); + var p = LoggingPromise.resolve(5); + var log = takeLog(); + assert_array_equals(log, ["Resolve 1", "Constructor 1"]); + var q = LoggingPromise.resolve(p); + assert_equals(p, q, + "Promise.resolve with same constructor should preserve identity"); + log = takeLog(); + assert_array_equals(log, ["Resolve 1", "Constructor get 1"]); + + var r = Promise.resolve(p); + log = takeLog(); + assert_array_equals(log, ["Constructor get 1"]); + assert_not_equals(p, r, + "Promise.resolve with different constructor should " + + "create a new Promise instance (1)") + var s = Promise.resolve(6); + var u = LoggingPromise.resolve(s); + log = takeLog(); + assert_array_equals(log, ["Resolve 1", "Constructor 1"]); + assert_not_equals(s, u, + "Promise.resolve with different constructor should " + + "create a new Promise instance (2)") + + Object.defineProperty(s, "constructor", { value: LoggingPromise }); + var v = LoggingPromise.resolve(s); + log = takeLog(); + assert_array_equals(log, ["Resolve 1"]); + assert_equals(v, s, "Faking the .constructor should work"); + assert_false(v instanceof LoggingPromise); + + var results = Promise.all([p, q, r, s, u, v]); + return results.then(function(arg) { + assert_array_equals(arg, [5, 5, 5, 6, 6, 6]); + }); +}, "Promise.resolve behavior"); + +promise_test(function testPromiseReject() { + clearLog(); + var p = LoggingPromise.reject(5); + var log = takeLog(); + assert_array_equals(log, ["Reject 1", "Constructor 1"]); + + return p.catch(function(arg) { + assert_equals(arg, 5); + }); +}, "Promise.reject behavior"); + +promise_test(function testPromiseThen() { + clearLog(); + var p = LoggingPromise.resolve(5); + var log = takeLog(); + assert_array_equals(log, ["Resolve 1", "Constructor 1"]); + + var q = p.then((x) => x*x); + log = takeLog(); + assert_array_equals(log, ["Then 1", "Constructor get 1", "Species get 1", + "Species call 1", "Constructor 1"]); + assert_true(q instanceof LoggingPromise); + + return q.then(function(arg) { + assert_equals(arg, 25); + }); +}, "Promise.then behavior"); + +promise_test(function testPromiseCatch() { + clearLog(); + var p = LoggingPromise.reject(5); + var log = takeLog(); + assert_array_equals(log, ["Reject 1", "Constructor 1"]); + + var q = p.catch((x) => x*x); + log = takeLog(); + assert_array_equals(log, ["Catch 1", "Then 1", "Constructor get 1", + "Species get 1", "Species call 1", "Constructor 1"]); + assert_true(q instanceof LoggingPromise); + + return q.then(function(arg) { + assert_equals(arg, 25); + }); +}, "Promise.catch behavior"); + +</script> diff --git a/testing/web-platform/tests/js/builtins/WeakMap.prototype-properties.html b/testing/web-platform/tests/js/builtins/WeakMap.prototype-properties.html new file mode 100644 index 000000000..ecf4a8e31 --- /dev/null +++ b/testing/web-platform/tests/js/builtins/WeakMap.prototype-properties.html @@ -0,0 +1,104 @@ +<!doctype html> +<title>WeakMap.prototype</title> +<link rel=author href=mailto:Ms2ger@gmail.com title=Ms2ger> +<link rel=help href=https://people.mozilla.org/~jorendorff/es6-draft.html#sec-properties-of-the-weakmap-prototype-object> +<link rel=help href=https://people.mozilla.org/~jorendorff/es6-draft.html#sec-functioninitialize> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<div id=log></div> +<script> +function assert_propdesc(obj, prop, Writable, Enumerable, Configurable) { + var propdesc = Object.getOwnPropertyDescriptor(obj, prop); + assert_equals(typeof propdesc, "object"); + assert_equals(propdesc.writable, Writable, "[[Writable]]"); + assert_equals(propdesc.enumerable, Enumerable, "[[Enumerable]]"); + assert_equals(propdesc.configurable, Configurable, "[[Configurable]]"); +} + +function test_length(fun, expected) { + test(function() { + assert_propdesc(WeakMap.prototype[fun], "length", false, false, true); + assert_equals(WeakMap.prototype[fun].length, expected); + }, "WeakMap.prototype." + fun + ".length") +} + +function test_thisval(fun, args) { + // Step 1-2 + test(function() { + assert_throws(new TypeError(), function() { + WeakMap.prototype[fun].apply(null, args); + }); + assert_throws(new TypeError(), function() { + WeakMap.prototype[fun].apply(undefined, args); + }); + }, "WeakMap.prototype." + fun + ": ToObject on this") + // Step 3 + test(function() { + assert_throws(new TypeError(), function() { + WeakMap.prototype[fun].apply({}, args); + }); + }, "WeakMap.prototype." + fun + ": this has no [[WeakMapData]] internal property") +} + +// In every case, the length property of a built-in Function object described +// in this clause has the attributes { [[Writable]]: false, [[Enumerable]]: +// false, [[Configurable]]: false }. Every other property described in this +// clause has the attributes { [[Writable]]: true, [[Enumerable]]: false, +// [[Configurable]]: true } unless otherwise specified. + +test(function() { + assert_equals(Object.getPrototypeOf(WeakMap.prototype), Object.prototype); +}, "The value of the [[Prototype]] internal property of the WeakMap prototype object is the standard built-in Object prototype object (15.2.4).") + +// 23.3.3.1 WeakMap.prototype.constructor +test(function() { + assert_equals(WeakMap.prototype.constructor, WeakMap); + assert_propdesc(WeakMap.prototype, "constructor", true, false, true); +}, "The initial value of WeakMap.prototype.constructor is the built-in WeakMap constructor.") + +// 23.3.3.2 WeakMap.prototype.delete ( key ) +test(function() { + assert_propdesc(WeakMap.prototype, "delete", true, false, true); + test_length("delete", 1); + // Step 1-3 + test_thisval("delete", [{}]); +}, "WeakMap.prototype.delete") + +// 23.3.3.3 WeakMap.prototype.get ( key ) +test(function() { + assert_propdesc(WeakMap.prototype, "get", true, false, true); + test_length("get", 1); + // Step 1-3 + test_thisval("get", [{}]); + + // Step 8 + test(function() { + var wm = new WeakMap(); + var key = {}; + var res = wm.get({}, {}); + assert_equals(res, undefined); + }, "WeakMap.prototype.get: return undefined"); +}, "WeakMap.prototype.get") + +// 23.3.3.4 Map.prototype.has ( key ) +test(function() { + assert_propdesc(WeakMap.prototype, "has", true, false, true); + test_length("has", 1); + // Step 1-3 + test_thisval("has", [{}]); +}, "WeakMap.prototype.has") + +// 23.3.3.5 Map.prototype.set ( key , value ) +test(function() { + assert_propdesc(WeakMap.prototype, "set", true, false, true); + test_length("set", 2); + // Step 1-3 + test_thisval("set", [{}, {}]); +}, "WeakMap.prototype.set") + +// 23.3.3.6 Map.prototype.@@toStringTag +test(function() { + assert_class_string(new WeakMap(), "WeakMap"); + assert_class_string(WeakMap.prototype, "WeakMap"); +}, "WeakMap.prototype.@@toStringTag") +</script> |