| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'package:async_helper/async_helper.dart'; | 5 import 'package:async_helper/async_helper.dart'; |
| 6 import 'package:expect/expect.dart'; | 6 import 'package:expect/expect.dart'; |
| 7 import 'memory_compiler.dart'; | 7 import 'memory_compiler.dart'; |
| 8 | 8 |
| 9 // Use strict does not allow parameters or locals named "arguments" or "eval". | 9 // Use strict does not allow parameters or locals named "arguments" or "eval". |
| 10 | 10 |
| 11 const MEMORY_SOURCE_FILES = const { | 11 const MEMORY_SOURCE_FILES = const { |
| 12 'main.dart': ''' | 12 'main.dart': ''' |
| 13 class A { | 13 class A { |
| 14 final arguments; | 14 final arguments; |
| 15 final eval; | 15 final eval; |
| 16 A(this.arguments, this.eval); | 16 A(this.arguments, this.eval); |
| 17 | 17 |
| 18 foo(x, y) => this.arguments + this.eval; | 18 foo(x, y) => this.arguments + this.eval; |
| 19 } | 19 } |
| 20 | 20 |
| 21 class B { | 21 class B { |
| 22 foo(arguments, eval) => arguments + eval; | 22 foo(arguments, eval) => arguments + eval; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 35 main() { | 35 main() { |
| 36 var list = []; | 36 var list = []; |
| 37 for (int i = 0; i < 1000; i++) { | 37 for (int i = 0; i < 1000; i++) { |
| 38 list.add(new A(i, i + 1)); | 38 list.add(new A(i, i + 1)); |
| 39 list.add(new B()); | 39 list.add(new B()); |
| 40 list.add(new C()); | 40 list.add(new C()); |
| 41 } | 41 } |
| 42 for (int i = 0; i < list.length; i++) { | 42 for (int i = 0; i < list.length; i++) { |
| 43 print(list[i].foo(i, i + 1)); | 43 print(list[i].foo(i, i + 1)); |
| 44 } | 44 } |
| 45 }'''}; | 45 }''' |
| 46 }; |
| 46 | 47 |
| 47 main() { | 48 main() { |
| 48 OutputCollector collector = new OutputCollector(); | 49 OutputCollector collector = new OutputCollector(); |
| 49 asyncTest(() async { | 50 asyncTest(() async { |
| 50 await runCompiler( | 51 await runCompiler( |
| 51 memorySourceFiles: MEMORY_SOURCE_FILES, outputProvider: collector); | 52 memorySourceFiles: MEMORY_SOURCE_FILES, outputProvider: collector); |
| 52 String jsOutput = collector.getOutput('', 'js'); | 53 String jsOutput = collector.getOutput('', 'js'); |
| 53 | 54 |
| 54 // Skip comments. | 55 // Skip comments. |
| 55 List<String> lines = jsOutput.split("\n"); | 56 List<String> lines = jsOutput.split("\n"); |
| 56 RegExp commentLine = new RegExp(r' *//'); | 57 RegExp commentLine = new RegExp(r' *//'); |
| 57 String filtered = lines | 58 String filtered = |
| 58 .where((String line) => !commentLine.hasMatch(line)) | 59 lines.where((String line) => !commentLine.hasMatch(line)).join("\n"); |
| 59 .join("\n"); | |
| 60 | 60 |
| 61 // TODO(floitsch): we will need to adjust this filter if we start using | 61 // TODO(floitsch): we will need to adjust this filter if we start using |
| 62 // 'eval' or 'arguments' ourselves. Currently we disallow any 'eval' or | 62 // 'eval' or 'arguments' ourselves. Currently we disallow any 'eval' or |
| 63 // 'arguments'. | 63 // 'arguments'. |
| 64 RegExp re = new RegExp(r'[^\w$](arguments|eval)[^\w$]'); | 64 RegExp re = new RegExp(r'[^\w$](arguments|eval)[^\w$]'); |
| 65 Expect.isFalse(re.hasMatch(filtered)); | 65 Expect.isFalse(re.hasMatch(filtered)); |
| 66 }); | 66 }); |
| 67 } | 67 } |
| OLD | NEW |