Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(672)

Unified Diff: test/mjsunit/harmony/class-fields-syntax.js

Issue 2330473002: Class fields, part 3 (backends)
Patch Set: bytecode test Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/mjsunit/harmony/class-fields-super.js ('k') | test/mjsunit/harmony/class-fields-to-name.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/class-fields-syntax.js
diff --git a/test/mjsunit/harmony/class-fields-syntax.js b/test/mjsunit/harmony/class-fields-syntax.js
new file mode 100644
index 0000000000000000000000000000000000000000..39146c23b5307e5d5164984e5d4d643336aefcc6
--- /dev/null
+++ b/test/mjsunit/harmony/class-fields-syntax.js
@@ -0,0 +1,163 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --harmony-class-fields
+
+// ASI
+
+{
+ class C {
+ a = 0
+ b(){}
+ }
+
+ let c = new C;
+ assertArrayEquals(['constructor', 'b'], Object.getOwnPropertyNames(C.prototype));
+ assertArrayEquals(['a'], Object.getOwnPropertyNames(c));
+}
+
+{
+ class C {
+ a
+ b(){}
+ }
+
+ let c = new C;
+ assertArrayEquals(['constructor', 'b'], Object.getOwnPropertyNames(C.prototype));
+ assertArrayEquals(['a'], Object.getOwnPropertyNames(c));
+}
+
+{
+ class C {
+ a
+ b
+ }
+
+ let c = new C;
+ assertArrayEquals(['constructor'], Object.getOwnPropertyNames(C.prototype));
+ assertArrayEquals(['a', 'b'], Object.getOwnPropertyNames(c));
+}
+
+{
+ class C {
+ a
+ *b(){}
+ }
+
+ let c = new C;
+ assertArrayEquals(['constructor', 'b'], Object.getOwnPropertyNames(C.prototype));
+ assertArrayEquals(['a'], Object.getOwnPropertyNames(c));
+}
+
+{
+ class C {
+ a
+ ['b'](){}
+ }
+
+ let c = new C;
+ assertArrayEquals(['constructor', 'b'], Object.getOwnPropertyNames(C.prototype));
+ assertArrayEquals(['a'], Object.getOwnPropertyNames(c));
+}
+
+{
+ class C { // a property named 'a' and a property named 'get'
+ a
+ get
+ }
+
+ let c = new C;
+ assertArrayEquals(['constructor'], Object.getOwnPropertyNames(C.prototype));
+ assertArrayEquals(['a', 'get'], Object.getOwnPropertyNames(c));
+}
+
+{
+ class C {
+ get
+ *a(){}
+ }
+
+ let c = new C;
+ assertArrayEquals(['constructor', 'a'], Object.getOwnPropertyNames(C.prototype));
+ assertArrayEquals(['get'], Object.getOwnPropertyNames(c));
+}
+
+{
+ class C { // a single static property named 'a'
+ static
+ a
+ }
+
+ let c = new C;
+ //assertArrayEquals(['length', 'name', 'prototype', 'a'], Object.getOwnPropertyNames(C)); // TODO(bakkot) re-enable once no longer using fields to communicate
+ assertArrayEquals([], Object.getOwnPropertyNames(c));
+}
+
+{
+ class C { // a property named 'a' and a property named 'static'
+ a
+ static
+ }
+
+ let c = new C;
+ //assertArrayEquals(['length', 'name', 'prototype'], Object.getOwnPropertyNames(C)); // TODO(bakkot) re-enable once no longer using fields to communicate
+ assertArrayEquals(['a', 'static'], Object.getOwnPropertyNames(c));
+}
+
+
+// ASI non-examples / errors
+
+assertThrows(() => eval(`
+ class C { a b }
+`)); // There is no line terminator after 'a', so ASI does not occur
+
+assertThrows(() => eval(`
+ class C {
+ a = 0
+ *b(){}
+ }
+`)); // '*' may follow 0 in an AssignmentExpression, so no ASI occurs after 0
+
+assertThrows(() => eval(`
+ class C {
+ a = 0
+ ['b'](){}
+ }
+`)); // '[' may follow 0 in an AssignmentExpression, so no ASI occurs after 0
+
+assertThrows(() => eval(`
+ class C {
+ get
+ a
+ }
+`)); // 'a' may follow 'get' in a MethodDefinition, so no ASI occurs after 'get'
+
+
+// Forbid static properties named 'prototype'
+
+// assertThrows(() => eval(`
+// class C {
+// static prototype;
+// }
+// `), SyntaxError); // TODO(bakkot) re-enable once this restriction is spec'd and added
+
+// assertThrows(() => eval(`
+// class C {
+// static prototype;
+// }
+// `), TypeError); // TODO(bakkot) re-enable once this restriction is spec'd and added
+
+
+// Non-examples
+
+{
+ class C { // a getter for 'a' on C.prototype; this is pre-existing syntax
+ get
+ a(){}
+ }
+
+ let c = new C;
+ assertTrue(Object.getOwnPropertyDescriptor(C.prototype, 'a').hasOwnProperty('get'));
+ assertArrayEquals([], Object.getOwnPropertyNames(c));
+}
« no previous file with comments | « test/mjsunit/harmony/class-fields-super.js ('k') | test/mjsunit/harmony/class-fields-to-name.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698