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

Unified Diff: tests/compiler/dart2js_native/native_class_fields_3_test.dart

Issue 12250002: dart2js: In minified mode shorter getter and setter names. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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
Index: tests/compiler/dart2js_native/native_class_fields_3_test.dart
diff --git a/tests/compiler/dart2js_native/native_class_fields_3_test.dart b/tests/compiler/dart2js_native/native_class_fields_3_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..a884dbf5a81e4c80192ece67f67eb2d0a19a0450
--- /dev/null
+++ b/tests/compiler/dart2js_native/native_class_fields_3_test.dart
@@ -0,0 +1,87 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
ngeoffray 2013/02/12 22:01:53 2011 -> 2013
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Verify that we can have fields with names that start with g and s even
+// though those names are reserved for getters and setters in minified mode.
+
+// Note: this works because end and send are both in the list of
+// reservedNativeProperties. In general we don't check arbitrary
+// names for clashes because it's hard - subclasses can force superclasses
+// to rename getters, and that can force unrelated classes to change their
+// getters too if they have a property that has the same name.
+class A native "*A" {
+ int bar;
+ int g;
+ int s;
+ int end;
+ int gend;
+ int send;
+ int gettersCalled;
+ int settersCalled;
+}
+
+
+void setup() native r"""
+function getter() {
+ this.gettersCalled++;
+ return 42;
+}
+
+function setter(x) {
+ this.settersCalled++;
+ return 314;
+}
+
+var descriptor = {
+ get: getter,
+ set: setter,
+ configurable: false,
+ writeable: false
+};
+
+function A(){
+ var a = Object.create(
+ { constructor: { name: 'A'}},
+ { bar: descriptor,
+ g: descriptor,
+ s: descriptor,
+ end: descriptor,
+ gend: descriptor,
+ send: descriptor
+ });
+ a.gettersCalled = 0;
+ a.settersCalled = 0;
+ return a;
+}
+
+makeA = function() { return new A; };
+""";
+
+A makeA() native;
+
+class B {
+}
+
+int inscrutable(int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1));
+
+main() {
+ setup();
+ var both = [makeA(), new B()];
+ var foo = both[inscrutable(0)];
+ Expect.equals(42, foo.bar);
+ Expect.equals(42, foo.g);
+ Expect.equals(42, foo.s);
+ Expect.equals(42, foo.end);
+ Expect.equals(42, foo.gend);
+ Expect.equals(42, foo.send);
+ Expect.equals(271, foo.bar = 271);
+ Expect.equals(271, foo.g = 271);
+ Expect.equals(271, foo.s = 271);
+ Expect.equals(271, foo.end = 271);
+ Expect.equals(271, foo.gend = 271);
+ Expect.equals(271, foo.send = 271);
+ Expect.equals(6, foo.gettersCalled);
+ Expect.equals(6, foo.settersCalled);
+}
+

Powered by Google App Engine
This is Rietveld 408576698