summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/language/expressions/class/private-static-field-multiple-evaluations-of-class-realm.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/tests/test262/language/expressions/class/private-static-field-multiple-evaluations-of-class-realm.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/language/expressions/class/private-static-field-multiple-evaluations-of-class-realm.js')
-rw-r--r--js/src/tests/test262/language/expressions/class/private-static-field-multiple-evaluations-of-class-realm.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/expressions/class/private-static-field-multiple-evaluations-of-class-realm.js b/js/src/tests/test262/language/expressions/class/private-static-field-multiple-evaluations-of-class-realm.js
new file mode 100644
index 0000000000..b8e87836e8
--- /dev/null
+++ b/js/src/tests/test262/language/expressions/class/private-static-field-multiple-evaluations-of-class-realm.js
@@ -0,0 +1,76 @@
+// |reftest| shell-option(--enable-private-fields) skip-if(!xulRuntime.shell) -- requires shell-options
+// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+description: Every new evaluation of a class creates a different Private Name (private static field)
+esid: sec-runtime-semantics-evaluate-name
+info: |
+ ClassElementName : PrivateIdentifier
+ 1. Let privateIdentifier be StringValue of PrivateIdentifier.
+ 2. Let privateName be NewPrivateName(privateIdentifier).
+ 3. Let scope be the running execution context's PrivateEnvironment.
+ 4. Let scopeEnvRec be scope's EnvironmentRecord.
+ 5. Perform ! scopeEnvRec.InitializeBinding(privateIdentifier, privateName).
+ 6. Return privateName.
+
+ ClassTail : ClassHeritage { ClassBody }
+ ...
+ 27. Let staticFields be a new empty List.
+ 28. For each ClassElement e in order from elements,
+ a. If IsStatic of e is false, then
+ ...
+ b. Else,
+ i. Let field be the result of performing PropertyDefinitionEvaluation for m ClassElementEvaluation for e with arguments F and false.
+ c. If field is an abrupt completion, then
+ ...
+ d. If field is not empty,
+ i. If IsStatic of e is false, append field to instanceFields.
+ ii. Otherwise, append field to staticFields.
+ ...
+ 34. For each item fieldRecord in order from staticFields,
+ a. Perform ? DefineField(F, field).
+ ...
+
+ DefineField(receiver, fieldRecord)
+ ...
+ 8. If fieldName is a Private Name,
+ a. Perform ? PrivateFieldAdd(fieldName, receiver, initValue).
+features: [class, class-static-fields-private, cross-realm]
+flags: [noStrict]
+---*/
+
+let global1 = $262.createRealm().global;
+let global2 = $262.createRealm().global;
+let eval1 = global1.eval;
+let eval2 = global2.eval;
+
+let classStringExpression = `(
+class {
+ static #m = 'test262';
+
+ static access() {
+ return this.#m;
+ }
+}
+)`;
+
+let evalClass = function (_eval) {
+ return _eval(classStringExpression);
+};
+
+let C1 = evalClass(eval1);
+let C2 = evalClass(eval2);
+
+assert.sameValue(C1.access(), 'test262');
+assert.sameValue(C2.access(), 'test262');
+
+assert.throws(global1.TypeError, function() {
+ C1.access.call(C2);
+}, 'invalid access of c1 private static field');
+
+assert.throws(global2.TypeError, function() {
+ C2.access.call(C1);
+}, 'invalid access of c2 private static field');
+
+reportCompare(0, 0);