summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_7/Object
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/tests/ecma_7/Object
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/tests/ecma_7/Object')
-rw-r--r--js/src/tests/ecma_7/Object/browser.js0
-rw-r--r--js/src/tests/ecma_7/Object/defineGetter-defineSetter.js92
-rw-r--r--js/src/tests/ecma_7/Object/entries.js94
-rw-r--r--js/src/tests/ecma_7/Object/shell.js0
-rw-r--r--js/src/tests/ecma_7/Object/values.js94
5 files changed, 280 insertions, 0 deletions
diff --git a/js/src/tests/ecma_7/Object/browser.js b/js/src/tests/ecma_7/Object/browser.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/ecma_7/Object/browser.js
diff --git a/js/src/tests/ecma_7/Object/defineGetter-defineSetter.js b/js/src/tests/ecma_7/Object/defineGetter-defineSetter.js
new file mode 100644
index 000000000..b2bb21f67
--- /dev/null
+++ b/js/src/tests/ecma_7/Object/defineGetter-defineSetter.js
@@ -0,0 +1,92 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/
+ */
+
+let count = 0;
+let verifyProxy = new Proxy({}, {
+ defineProperty(target, property, descriptor) {
+ assertEq(property, "x");
+
+ assertEq(descriptor.enumerable, true);
+ assertEq(descriptor.configurable, true);
+
+ if ("set" in descriptor)
+ assertEq(descriptor.set, Object.prototype.__defineSetter__);
+ else
+ assertEq(descriptor.get, Object.prototype.__defineGetter__);
+
+ assertEq(Object.keys(descriptor).length, 3);
+
+ count++;
+ return true;
+ }
+});
+
+for (let define of [Object.prototype.__defineGetter__, Object.prototype.__defineSetter__]) {
+ // null/undefined |this| value
+ for (let thisv of [undefined, null])
+ assertThrowsInstanceOf(() => define.call(thisv, "x", define), TypeError);
+
+ // non-callable getter/setter
+ let nonCallable = [{}, [], new Proxy({}, {})];
+ for (let value of nonCallable)
+ assertThrowsInstanceOf(() => define.call(verifyProxy, "x", value), TypeError);
+
+ // ToPropertyKey
+ let key = {
+ [Symbol.toPrimitive](hint) {
+ assertEq(hint, "string");
+ // Throws, because non-primitive is returned
+ return {};
+ },
+ valueOf() { throw "wrongly invoked"; },
+ toString() { throw "wrongly invoked"; }
+ };
+ assertThrowsInstanceOf(() => define.call(verifyProxy, key, define), TypeError);
+
+ key = {
+ [Symbol.toPrimitive](hint) {
+ assertEq(hint, "string");
+ return "x";
+ },
+ valueOf() { throw "wrongly invoked"; },
+ toString() { throw "wrongly invoked"; }
+ }
+ define.call(verifyProxy, key, define);
+
+ key = {
+ [Symbol.toPrimitive]: undefined,
+
+ valueOf() { throw "wrongly invoked"; },
+ toString() { return "x"; }
+ }
+ define.call(verifyProxy, key, define);
+
+ // Bog standard call
+ define.call(verifyProxy, "x", define);
+
+ let obj = {};
+ define.call(obj, "x", define);
+ let descriptor = Object.getOwnPropertyDescriptor(obj, "x");
+
+ assertEq(descriptor.enumerable, true);
+ assertEq(descriptor.configurable, true);
+
+ if (define == Object.prototype.__defineSetter__) {
+ assertEq(descriptor.get, undefined);
+ assertEq(descriptor.set, define);
+ } else {
+ assertEq(descriptor.get, define);
+ assertEq(descriptor.set, undefined);
+ }
+
+ assertEq(Object.keys(descriptor).length, 4);
+
+
+}
+
+// Number of calls that should succeed
+assertEq(count, 6);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/ecma_7/Object/entries.js b/js/src/tests/ecma_7/Object/entries.js
new file mode 100644
index 000000000..ee339ae23
--- /dev/null
+++ b/js/src/tests/ecma_7/Object/entries.js
@@ -0,0 +1,94 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/
+ */
+
+if ("entries" in Object) {
+ assertEq(Object.entries.length, 1);
+
+ var o, entries;
+
+ o = { a: 3, b: 2 };
+ entries = Object.entries(o);
+ assertDeepEq(entries, [["a", 3], ["b", 2]]);
+
+ o = { get a() { return 17; }, b: 2 };
+ entries = Object.entries(o),
+ assertDeepEq(entries, [["a", 17], ["b", 2]]);
+
+ o = { __iterator__: function() { return Iterator({a: 2, b: 3}); } };
+ entries = Object.entries(o);
+ assertDeepEq(entries, [["__iterator__", o.__iterator__]]);
+
+ o = { a: 1, b: 2 };
+ delete o.a;
+ o.a = 3;
+ entries = Object.entries(o);
+ assertDeepEq(entries, [["b", 2], ["a", 3]]);
+
+ o = [0, 1, 2];
+ entries = Object.entries(o);
+ assertDeepEq(entries, [["0", 0], ["1", 1], ["2", 2]]);
+
+ o = /./.exec("abc");
+ entries = Object.entries(o);
+ assertDeepEq(entries, [["0", "a"], ["index", 0], ["input", "abc"]]);
+
+ o = { a: 1, b: 2, c: 3 };
+ delete o.b;
+ o.b = 5;
+ entries = Object.entries(o);
+ assertDeepEq(entries, [["a", 1], ["c", 3], ["b", 5]]);
+
+ function f() { }
+ f.prototype.p = 1;
+ o = new f();
+ o.g = 1;
+ entries = Object.entries(o);
+ assertDeepEq(entries, [["g", 1]]);
+
+ var o = {get a() {delete this.b; return 1}, b: 2, c: 3};
+ entries = Object.entries(o);
+ assertDeepEq(entries, [["a", 1], ["c", 3]]);
+
+ assertThrowsInstanceOf(() => Object.entries(), TypeError);
+ assertThrowsInstanceOf(() => Object.entries(undefined), TypeError);
+ assertThrowsInstanceOf(() => Object.entries(null), TypeError);
+
+ assertDeepEq(Object.entries(1), []);
+ assertDeepEq(Object.entries(true), []);
+ if (typeof Symbol === "function")
+ assertDeepEq(Object.entries(Symbol("foo")), []);
+
+ assertDeepEq(Object.entries("foo"), [["0", "f"], ["1", "o"], ["2", "o"]]);
+
+ entries = Object.entries({
+ get a(){
+ Object.defineProperty(this, "b", {enumerable: false});
+ return "A";
+ },
+ b: "B"
+ });
+ assertDeepEq(entries, [["a", "A"]]);
+
+ let ownKeysCallCount = 0;
+ let getOwnPropertyDescriptorCalls = [];
+ let target = { a: 1, b: 2, c: 3 };
+ o = new Proxy(target, {
+ ownKeys() {
+ ownKeysCallCount++;
+ return ["c", "a"];
+ },
+ getOwnPropertyDescriptor(target, key) {
+ getOwnPropertyDescriptorCalls.push(key);
+ return Object.getOwnPropertyDescriptor(target, key);
+ }
+ });
+ entries = Object.entries(o);
+ assertEq(ownKeysCallCount, 1);
+ assertDeepEq(entries, [["c", 3], ["a", 1]]);
+ assertDeepEq(getOwnPropertyDescriptorCalls, ["c", "a"]);
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
diff --git a/js/src/tests/ecma_7/Object/shell.js b/js/src/tests/ecma_7/Object/shell.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/ecma_7/Object/shell.js
diff --git a/js/src/tests/ecma_7/Object/values.js b/js/src/tests/ecma_7/Object/values.js
new file mode 100644
index 000000000..78543c875
--- /dev/null
+++ b/js/src/tests/ecma_7/Object/values.js
@@ -0,0 +1,94 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/
+ */
+
+if ("values" in Object) {
+ assertEq(Object.values.length, 1);
+
+ var o, values;
+
+ o = { a: 3, b: 2 };
+ values = Object.values(o);
+ assertDeepEq(values, [3, 2]);
+
+ o = { get a() { return 17; }, b: 2 };
+ values = Object.values(o),
+ assertDeepEq(values, [17, 2]);
+
+ o = { __iterator__: function() { return Iterator({a: 2, b: 3}); } };
+ values = Object.values(o);
+ assertDeepEq(values, [o.__iterator__]);
+
+ o = { a: 1, b: 2 };
+ delete o.a;
+ o.a = 3;
+ values = Object.values(o);
+ assertDeepEq(values, [2, 3]);
+
+ o = [0, 1, 2];
+ values = Object.values(o);
+ assertDeepEq(values, [0, 1, 2]);
+
+ o = /./.exec("abc");
+ values = Object.values(o);
+ assertDeepEq(values, ["a", 0, "abc"]);
+
+ o = { a: 1, b: 2, c: 3 };
+ delete o.b;
+ o.b = 5;
+ values = Object.values(o);
+ assertDeepEq(values, [1, 3, 5]);
+
+ function f() { }
+ f.prototype.p = 1;
+ o = new f();
+ o.g = 1;
+ values = Object.values(o);
+ assertDeepEq(values, [1]);
+
+ var o = {get a() {delete this.b; return 1}, b: 2, c: 3};
+ values = Object.values(o);
+ assertDeepEq(values, [1, 3]);
+
+ assertThrowsInstanceOf(() => Object.values(), TypeError);
+ assertThrowsInstanceOf(() => Object.values(undefined), TypeError);
+ assertThrowsInstanceOf(() => Object.values(null), TypeError);
+
+ assertDeepEq(Object.values(1), []);
+ assertDeepEq(Object.values(true), []);
+ if (typeof Symbol === "function")
+ assertDeepEq(Object.values(Symbol("foo")), []);
+
+ assertDeepEq(Object.values("foo"), ["f", "o", "o"]);
+
+ values = Object.values({
+ get a(){
+ Object.defineProperty(this, "b", {enumerable: false});
+ return "A";
+ },
+ b: "B"
+ });
+ assertDeepEq(values, ["A"]);
+
+ let ownKeysCallCount = 0;
+ let getOwnPropertyDescriptorCalls = [];
+ let target = { a: 1, b: 2, c: 3 };
+ o = new Proxy(target, {
+ ownKeys() {
+ ownKeysCallCount++;
+ return ["c", "a"];
+ },
+ getOwnPropertyDescriptor(target, key) {
+ getOwnPropertyDescriptorCalls.push(key);
+ return Object.getOwnPropertyDescriptor(target, key);
+ }
+ });
+ values = Object.values(o);
+ assertEq(ownKeysCallCount, 1);
+ assertDeepEq(values, [3, 1]);
+ assertDeepEq(getOwnPropertyDescriptorCalls, ["c", "a"]);
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);