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

Unified Diff: test/mjsunit/harmony/class-fields-scoping.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-proxy.js ('k') | test/mjsunit/harmony/class-fields-super.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/class-fields-scoping.js
diff --git a/test/mjsunit/harmony/class-fields-scoping.js b/test/mjsunit/harmony/class-fields-scoping.js
new file mode 100644
index 0000000000000000000000000000000000000000..0eb953f77bafbd4fd060feee90875b8b0eff56eb
--- /dev/null
+++ b/test/mjsunit/harmony/class-fields-scoping.js
@@ -0,0 +1,314 @@
+// 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
+
+// this
+{
+ class C {
+ a = this;
+ }
+
+ let c = new C;
+ assertEquals(c, c.a);
+}
+
+{
+ class C {
+ static a = this;
+ }
+ assertEquals(C, C.a);
+}
+
+{
+ let sigil = {};
+
+ function outer() {
+ let stored = null;
+ class C {
+ [stored = this] = 0;
+ }
+
+ assertEquals(sigil, stored);
+ }
+
+ outer.call(sigil);
+}
+
+// super
+{
+ class Base {
+ m() {
+ return 0;
+ }
+ }
+
+ class Derived extends Base {
+ m() {
+ return 1;
+ }
+ a = super.m();
+ }
+
+ let c = new Derived;
+ assertEquals(0, c.a);
+}
+
+{
+ class Base {
+ static m() {
+ return 0;
+ }
+ }
+
+ class Derived extends Base {
+ static m() {
+ return 1;
+ }
+ static a = super.m();
+ }
+
+ assertEquals(0, Derived.a);
+}
+
+{
+ let stored = null;
+
+ class OuterBase {
+ m() {
+ return 0;
+ }
+ }
+
+ class OuterDerived extends OuterBase {
+ m() {
+ return 1;
+ }
+
+ constructor() {
+ super();
+
+ class InnerBase {
+ m() {
+ return 2;
+ }
+ }
+
+ class InnerDerived extends InnerBase {
+ m() {
+ return 3;
+ }
+ [stored = super.m()] = 0;
+ }
+ }
+ }
+
+ new OuterDerived;
+
+ assertEquals(0, stored);
+}
+
+// new.target
+{
+ function outer() {
+ class C {
+ a = new.target;
+ }
+
+ let c = new C;
+ assertTrue(c.hasOwnProperty('a'));
+ assertEquals(undefined, c.a);
+ }
+
+ new outer;
+}
+
+{
+ function outer() {
+ class C {
+ static a = new.target;
+ }
+
+ assertTrue(C.hasOwnProperty('a'));
+ assertEquals(undefined, C.a);
+ }
+
+ new outer;
+}
+
+{
+ function outer() {
+ let stored = null;
+
+ class C {
+ [stored = new.target] = 0;
+ }
+ assertEquals(outer, stored);
+ }
+
+ new outer;
+}
+
+// arguments
+{
+ function outer() {
+ let stored_outer = arguments;
+ let stored_ctor;
+
+ class C {
+ a = arguments;
+
+ constructor() {
+ stored_ctor = arguments;
+ }
+ }
+
+ let c = new C;
+ assertEquals('[object Arguments]', Object.prototype.toString.call(c.a));
+ assertFalse(stored_outer === c.a);
+ assertFalse(stored_ctor === c.a);
+ }
+
+ outer();
+}
+
+{
+ function outer() {
+ let stored_outer = arguments;
+
+ class C {
+ static a = arguments;
+ }
+
+ assertEquals('[object Arguments]', Object.prototype.toString.call(C.a));
+ assertFalse(stored_outer === C.a);
+ }
+
+ outer();
+}
+
+{
+ function outer() {
+ let stored = null;
+
+ class C {
+ [stored = arguments] = 0;
+ }
+
+ assertEquals(arguments, stored);
+ }
+
+ outer();
+}
+
+
+// ctor params
+{
+ let b = 0;
+ class C {
+ a = b;
+
+ constructor(b) {}
+ }
+
+ let c = new C(1);
+ assertEquals(0, c.a);
+}
+
+// class declaration name
+{
+ class C {
+ a = C;
+ }
+ let stored_class = C;
+ C = null;
+
+ let c = new stored_class;
+ assertEquals(stored_class, c.a);
+}
+
+{
+ class C {
+ static a = () => C;
+ }
+ let stored_class = C;
+ C = null;
+
+ assertEquals(stored_class, stored_class.a());
+}
+
+{
+ let stored = null;
+
+ class C {
+ [stored = () => C] = 0;
+ }
+ let stored_class = C;
+ C = null;
+
+ assertEquals(stored_class, stored());
+}
+
+{
+ assertThrows(() => {
+ class C {
+ static a = C;
+ }
+ }, ReferenceError);
+}
+
+{
+ assertThrows(() => {
+ class C {
+ [C] = 0;
+ }
+ }, ReferenceError);
+}
+
+// class expression name
+{
+ let C = null;
+ let stored_class = class C {
+ a = C;
+ }
+
+ let c = new stored_class;
+ assertEquals(stored_class, c.a);
+}
+
+{
+ let C = null;
+ let stored_class = class C {
+ static a = () => C;
+ }
+
+ assertEquals(stored_class, stored_class.a());
+}
+
+{
+ let C = null;
+ let stored = null;
+
+ let stored_class = class C {
+ [stored = () => C] = 0;
+ };
+
+ assertEquals(stored_class, stored());
+}
+
+{
+ assertThrows(() => (
+ class C {
+ static a = C;
+ }
+ ), ReferenceError);
+}
+
+{
+ assertThrows(() => (
+ class C {
+ [C] = 0;
+ }
+ ), ReferenceError);
+}
« no previous file with comments | « test/mjsunit/harmony/class-fields-proxy.js ('k') | test/mjsunit/harmony/class-fields-super.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698