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

Unified Diff: tests/compiler/dart2js/use_strict_test.dart

Issue 929503004: dart2js: Don't emit fields that are named "eval" or "arguments". (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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
« no previous file with comments | « pkg/compiler/lib/src/js_backend/namer.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/compiler/dart2js/use_strict_test.dart
diff --git a/tests/compiler/dart2js/use_strict_test.dart b/tests/compiler/dart2js/use_strict_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..777c77c4c70cfe3bccc07c969f233cc32cfc0c85
--- /dev/null
+++ b/tests/compiler/dart2js/use_strict_test.dart
@@ -0,0 +1,68 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// 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.
+
+import 'dart:async';
+
+import 'package:async_helper/async_helper.dart';
+import 'package:expect/expect.dart';
+import 'memory_compiler.dart';
+
+// Use strict does not allow parameters or locals named "arguments" or "eval".
+
+const MEMORY_SOURCE_FILES = const {
+ 'main.dart': '''
+ class A {
+ final arguments;
+ final eval;
+ A(this.arguments, this.eval);
+
+ foo(x, y) => this.arguments + this.eval;
+ }
+
+ class B {
+ foo(arguments, eval) => arguments + eval;
+ }
+
+ class C {
+ foo(var x, var y) {
+ var arguments, eval;
+ arguments = x + y;
+ eval = x - y;
+ if (arguments < eval) return arguments;
+ return eval;
+ }
+ }
+
+ main() {
+ var list = [];
+ for (int i = 0; i < 1000; i++) {
+ list.add(new A(i, i + 1));
+ list.add(new B());
+ list.add(new C());
+ }
+ for (int i = 0; i < list.length; i++) {
+ print(list[i].foo(i, i + 1));
+ }
+ }'''};
+
+main() {
+ OutputCollector collector = new OutputCollector();
+ var compiler = compilerFor(MEMORY_SOURCE_FILES, outputProvider: collector);
+ asyncTest(() => compiler.run(Uri.parse('memory:main.dart')).then((_) {
+ String jsOutput = collector.getOutput('', 'js');
+
+ // Skip comments.
+ List<String> lines = jsOutput.split("\n");
+ RegExp commentLine = new RegExp(r' *//');
+ String filtered = lines
+ .where((String line) => !commentLine.hasMatch(line))
+ .join("\n");
+
+ // TODO(floitsch): we will need to adjust this filter if we start using
+ // 'eval' or 'arguments' ourselves. Currently we disallow any 'eval' or
+ // 'arguments'.
+ RegExp re = new RegExp(r'[^\w$](arguments|eval)[^\w$]');
+ Expect.isFalse(re.hasMatch(filtered));
+ }));
+}
« no previous file with comments | « pkg/compiler/lib/src/js_backend/namer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698