summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/fields/ergonomic-1.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/jit-test/tests/fields/ergonomic-1.js')
-rw-r--r--js/src/jit-test/tests/fields/ergonomic-1.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/fields/ergonomic-1.js b/js/src/jit-test/tests/fields/ergonomic-1.js
new file mode 100644
index 0000000000..7aa75ab30b
--- /dev/null
+++ b/js/src/jit-test/tests/fields/ergonomic-1.js
@@ -0,0 +1,69 @@
+class Base {
+ constructor(o) {
+ return o;
+ }
+}
+
+class A extends Base {
+ #x = 12;
+ #y = 13;
+ static has(o) {
+ return A.evalStr(o, '#x in o');
+ }
+
+ static evalStr(o, str) {
+ return eval(str);
+ }
+}
+
+var obj = {};
+assertEq(A.has(obj), false);
+new A(obj);
+assertEq(A.has(obj), true);
+
+A.evalStr(obj, `#x in o in o`) // 'false' in o
+
+function assertSyntaxError(functionText) {
+ let threw = false;
+ let exception = undefined;
+ try {
+ A.evalStr({}, functionText)
+ } catch (e) {
+ exception = e;
+ threw = true;
+ }
+ assertEq(threw, true);
+ assertEq(exception instanceof SyntaxError, true);
+}
+
+assertSyntaxError(`#x`);
+assertSyntaxError(`#x == undefined`);
+assertSyntaxError(`1 + #x in o`)
+assertSyntaxError(`#z in o`);
+
+assertSyntaxError(`for (#x in o) { return 1;}`)
+assertSyntaxError(`!#x in o`)
+assertSyntaxError(`+#x in o`)
+assertSyntaxError(`-#x in o`)
+assertSyntaxError(`~#x in o`)
+assertSyntaxError(`void #x in o`)
+assertSyntaxError(`typeof #x in o`)
+assertSyntaxError(`++#x in o`)
+assertSyntaxError(`--#x in o`)
+
+assertSyntaxError(`#x in #y in o`)
+assertSyntaxError(`{} instanceof #x in o`)
+assertSyntaxError(`10 > #x in o`)
+var threw = true
+try {
+ eval(`class Async {
+ #x;
+ async func(o) {
+ await #x in o;
+ }
+ }`);
+ threw = false;
+} catch (e) {
+ assertEq(e instanceof SyntaxError, true);
+}
+assertEq(threw, true);