summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Symbol/for
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/Symbol/for')
-rw-r--r--js/src/tests/test262/built-ins/Symbol/for/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/Symbol/for/create-value.js26
-rw-r--r--js/src/tests/test262/built-ins/Symbol/for/cross-realm.js21
-rw-r--r--js/src/tests/test262/built-ins/Symbol/for/description.js20
-rw-r--r--js/src/tests/test262/built-ins/Symbol/for/length.js32
-rw-r--r--js/src/tests/test262/built-ins/Symbol/for/name.js29
-rw-r--r--js/src/tests/test262/built-ins/Symbol/for/not-a-constructor.js31
-rw-r--r--js/src/tests/test262/built-ins/Symbol/for/prop-desc.js20
-rw-r--r--js/src/tests/test262/built-ins/Symbol/for/retrieve-value.js25
-rw-r--r--js/src/tests/test262/built-ins/Symbol/for/shell.js0
-rw-r--r--js/src/tests/test262/built-ins/Symbol/for/to-string-err.js27
11 files changed, 231 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Symbol/for/browser.js b/js/src/tests/test262/built-ins/Symbol/for/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Symbol/for/browser.js
diff --git a/js/src/tests/test262/built-ins/Symbol/for/create-value.js b/js/src/tests/test262/built-ins/Symbol/for/create-value.js
new file mode 100644
index 0000000000..68eabf199b
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Symbol/for/create-value.js
@@ -0,0 +1,26 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-symbol.for
+description: Creation of a unique Symbol value
+info: |
+ 1. Let stringKey be ? ToString(key).
+ 2. For each element e of the GlobalSymbolRegistry List,
+ a. If SameValue(e.[[Key]], stringKey) is true, return e.[[Symbol]].
+ 3. Assert: GlobalSymbolRegistry does not currently contain an entry for
+ stringKey.
+ 4. Let newSymbol be a new unique Symbol value whose [[Description]] value
+ is stringKey.
+ 5. Append the Record { [[Key]]: stringKey, [[Symbol]]: newSymbol } to the
+ GlobalSymbolRegistry List.
+ 6. Return newSymbol.
+features: [Symbol]
+---*/
+
+var canonical = Symbol.for('s');
+
+assert.sameValue(typeof canonical, 'symbol');
+assert.notSameValue(canonical, Symbol('s'));
+assert.notSameValue(canonical, Symbol.for('y'));
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Symbol/for/cross-realm.js b/js/src/tests/test262/built-ins/Symbol/for/cross-realm.js
new file mode 100644
index 0000000000..072ab74124
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Symbol/for/cross-realm.js
@@ -0,0 +1,21 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-symbol.for
+description: Global symbol registry is shared by all realms
+info: |
+ The GlobalSymbolRegistry is a List that is globally available. It is shared
+ by all realms. Prior to the evaluation of any ECMAScript code it is
+ initialized as a new empty List.
+features: [cross-realm, Symbol]
+---*/
+
+var OSymbol = $262.createRealm().global.Symbol;
+var parent = Symbol.for('parent');
+var child = OSymbol.for('child');
+
+assert.notSameValue(Symbol.for, OSymbol.for);
+assert.sameValue(parent, OSymbol.for('parent'));
+assert.sameValue(Symbol.for('child'), child);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Symbol/for/description.js b/js/src/tests/test262/built-ins/Symbol/for/description.js
new file mode 100644
index 0000000000..0a2b007626
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Symbol/for/description.js
@@ -0,0 +1,20 @@
+// Copyright (C) 2021 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-symbol.for
+description: Assigns the string value to the [[Description]] slot
+info: |
+ 1. Let stringKey be ? ToString(key).
+ [...]
+ 4. Let newSymbol be a new unique Symbol value whose [[Description]] value
+ is stringKey.
+ [...]
+ 6. Return newSymbol.
+features: [Symbol, Symbol.prototype.description]
+---*/
+
+var symbol = Symbol.for({toString: function() { return 'test262'; }});
+
+assert.sameValue(symbol.description, 'test262');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Symbol/for/length.js b/js/src/tests/test262/built-ins/Symbol/for/length.js
new file mode 100644
index 0000000000..5875d22702
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Symbol/for/length.js
@@ -0,0 +1,32 @@
+// Copyright (C) 2015 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+es6id: 19.4.2.1
+description: >
+ Symbol.for.length is 1.
+info: |
+ Symbol.for ( key )
+
+ 17 ECMAScript Standard Built-in Objects:
+ Every built-in Function object, including constructors, has a length
+ property whose value is an integer. Unless otherwise specified, this
+ value is equal to the largest number of named arguments shown in the
+ subclause headings for the function description, including optional
+ parameters. However, rest parameters shown using the form “...name”
+ are not included in the default argument count.
+
+ Unless otherwise specified, the length property of a built-in Function
+ object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
+ [[Configurable]]: true }.
+includes: [propertyHelper.js]
+features: [Symbol]
+---*/
+
+assert.sameValue(Symbol.for.length, 1);
+
+verifyNotEnumerable(Symbol.for, "length");
+verifyNotWritable(Symbol.for, "length");
+verifyConfigurable(Symbol.for, "length");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Symbol/for/name.js b/js/src/tests/test262/built-ins/Symbol/for/name.js
new file mode 100644
index 0000000000..fce43732c0
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Symbol/for/name.js
@@ -0,0 +1,29 @@
+// Copyright (C) 2015 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+es6id: 19.4.2.1
+description: >
+ Symbol.for.name is "for".
+info: |
+ Symbol.for ( key )
+
+ 17 ECMAScript Standard Built-in Objects:
+ Every built-in Function object, including constructors, that is not
+ identified as an anonymous function has a name property whose value
+ is a String.
+
+ Unless otherwise specified, the name property of a built-in Function
+ object, if it exists, has the attributes { [[Writable]]: false,
+ [[Enumerable]]: false, [[Configurable]]: true }.
+includes: [propertyHelper.js]
+features: [Symbol]
+---*/
+
+assert.sameValue(Symbol.for.name, "for");
+
+verifyNotEnumerable(Symbol.for, "name");
+verifyNotWritable(Symbol.for, "name");
+verifyConfigurable(Symbol.for, "name");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Symbol/for/not-a-constructor.js b/js/src/tests/test262/built-ins/Symbol/for/not-a-constructor.js
new file mode 100644
index 0000000000..a90a09e9a3
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Symbol/for/not-a-constructor.js
@@ -0,0 +1,31 @@
+// Copyright (C) 2020 Rick Waldron. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-ecmascript-standard-built-in-objects
+description: >
+ Symbol.for does not implement [[Construct]], is not new-able
+info: |
+ ECMAScript Function Objects
+
+ Built-in function objects that are not identified as constructors do not
+ implement the [[Construct]] internal method unless otherwise specified in
+ the description of a particular function.
+
+ sec-evaluatenew
+
+ ...
+ 7. If IsConstructor(constructor) is false, throw a TypeError exception.
+ ...
+includes: [isConstructor.js]
+features: [Reflect.construct, Symbol, arrow-function]
+---*/
+
+assert.sameValue(isConstructor(Symbol.for), false, 'isConstructor(Symbol.for) must return false');
+
+assert.throws(TypeError, () => {
+ new Symbol.for();
+}, '`new Symbol.for()` throws TypeError');
+
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Symbol/for/prop-desc.js b/js/src/tests/test262/built-ins/Symbol/for/prop-desc.js
new file mode 100644
index 0000000000..119799e90b
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Symbol/for/prop-desc.js
@@ -0,0 +1,20 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-symbol.for
+description: Property descriptor
+info: |
+ Every other data property described in clauses 18 through 26 and in Annex
+ B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false,
+ [[Configurable]]: true } unless otherwise specified.
+includes: [propertyHelper.js]
+features: [Symbol]
+---*/
+
+assert.sameValue(typeof Symbol.for, 'function');
+
+verifyNotEnumerable(Symbol, 'for');
+verifyWritable(Symbol, 'for');
+verifyConfigurable(Symbol, 'for');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Symbol/for/retrieve-value.js b/js/src/tests/test262/built-ins/Symbol/for/retrieve-value.js
new file mode 100644
index 0000000000..444b525038
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Symbol/for/retrieve-value.js
@@ -0,0 +1,25 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-symbol.for
+description: Retrieval of previously-created value
+info: |
+ 1. Let stringKey be ? ToString(key).
+ 2. For each element e of the GlobalSymbolRegistry List,
+ a. If SameValue(e.[[Key]], stringKey) is true, return e.[[Symbol]].
+ 3. Assert: GlobalSymbolRegistry does not currently contain an entry for
+ stringKey.
+ 4. Let newSymbol be a new unique Symbol value whose [[Description]] value
+ is stringKey.
+ 5. Append the Record { [[Key]]: stringKey, [[Symbol]]: newSymbol } to the
+ GlobalSymbolRegistry List.
+ 6. Return newSymbol.
+features: [Symbol]
+---*/
+
+var canonical = Symbol.for('s');
+
+assert.sameValue(typeof canonical, 'symbol');
+assert.sameValue(canonical, Symbol.for('s'));
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Symbol/for/shell.js b/js/src/tests/test262/built-ins/Symbol/for/shell.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Symbol/for/shell.js
diff --git a/js/src/tests/test262/built-ins/Symbol/for/to-string-err.js b/js/src/tests/test262/built-ins/Symbol/for/to-string-err.js
new file mode 100644
index 0000000000..9cd2a121a9
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Symbol/for/to-string-err.js
@@ -0,0 +1,27 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-symbol.for
+description: Error resulting from string coercion of first argument
+info: |
+ 1. Let stringKey be ? ToString(key).
+features: [Symbol]
+---*/
+
+var subject = {
+ toString: function() {
+ throw new Test262Error();
+ }
+};
+
+assert.throws(Test262Error, function() {
+ Symbol.for(subject);
+});
+
+subject = Symbol('s');
+
+assert.throws(TypeError, function() {
+ Symbol.for(subject);
+});
+
+reportCompare(0, 0);