summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_6/Expressions/ToPropertyKey-symbols.js
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_6/Expressions/ToPropertyKey-symbols.js
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_6/Expressions/ToPropertyKey-symbols.js')
-rw-r--r--js/src/tests/ecma_6/Expressions/ToPropertyKey-symbols.js90
1 files changed, 90 insertions, 0 deletions
diff --git a/js/src/tests/ecma_6/Expressions/ToPropertyKey-symbols.js b/js/src/tests/ecma_6/Expressions/ToPropertyKey-symbols.js
new file mode 100644
index 000000000..32b3994b3
--- /dev/null
+++ b/js/src/tests/ecma_6/Expressions/ToPropertyKey-symbols.js
@@ -0,0 +1,90 @@
+var symbols = [
+ Symbol(), Symbol("iterator"), Symbol.for("iterator"), Symbol.iterator
+];
+
+for (var sym of symbols) {
+ var key = {
+ toString() { return sym; }
+ };
+
+ // Test that ToPropertyKey can return a symbol in each of the following
+ // contexts.
+
+ // Computed property names.
+ var obj = {[key]: 13};
+ var found = Reflect.ownKeys(obj);
+ assertEq(found.length, 1);
+ assertEq(found[0], sym);
+
+ // Computed accessor property names.
+ var obj2 = {
+ get [key]() { return "got"; },
+ set [key](v) { this.v = v; }
+ };
+ assertEq(obj2[sym], "got");
+ obj2[sym] = 33;
+ assertEq(obj2.v, 33);
+
+ // Getting and setting properties.
+ assertEq(obj[key], 13);
+ obj[key] = 19;
+ assertEq(obj[sym], 19);
+ (function () { "use strict"; obj[key] = 20; })();
+ assertEq(obj[sym], 20);
+ obj[key]++;
+ assertEq(obj[sym], 21);
+
+ // Getting properties of primitive values.
+ Number.prototype[sym] = "success";
+ assertEq(Math.PI[key], "success");
+ delete Number.prototype[sym];
+
+ // Getting a super property.
+ class X {
+ [sym]() { return "X"; }
+ }
+ class Y extends X {
+ [sym]() { return super[key]() + "Y"; }
+ }
+ var y = new Y();
+ assertEq(y[sym](), "XY");
+
+ // Setting a super property.
+ class Z {
+ set [sym](v) {
+ this.self = this;
+ this.value = v;
+ }
+ }
+ class W extends Z {
+ set [sym](v) {
+ this.isW = true;
+ super[key] = v;
+ }
+ }
+ var w = new W();
+ w[key] = "ok";
+ assertEq(w.self, w);
+ assertEq(w.value, "ok");
+ assertEq(w.isW, true);
+
+ // Deleting properties.
+ obj = {[sym]: 1};
+ assertEq(delete obj[key], true);
+ assertEq(sym in obj, false);
+
+ // LHS of `in` expressions.
+ assertEq(key in {iterator: 0}, false);
+ assertEq(key in {[sym]: 0}, true);
+
+ // Methods of Object and Object.prototype
+ obj = {};
+ Object.defineProperty(obj, key, {value: "ok", enumerable: true});
+ assertEq(obj[sym], "ok");
+ assertEq(obj.hasOwnProperty(key), true);
+ assertEq(obj.propertyIsEnumerable(key), true);
+ var desc = Object.getOwnPropertyDescriptor(obj, key);
+ assertEq(desc.value, "ok");
+}
+
+reportCompare(0, 0);