| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // This test should move to a language test once the apply method | 5 // This test should move to a language test once the apply method |
| 6 // gets into the specification. | 6 // gets into the specification. |
| 7 | 7 |
| 8 apply(Function function, ArgumentDescriptor args) { | 8 apply(Function function, ArgumentDescriptor args) { |
| 9 int argumentCount = 0; | 9 int argumentCount = 0; |
| 10 StringBuffer buffer = new StringBuffer(); | 10 StringBuffer buffer = new StringBuffer(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 throw new NoSuchMethodError(function, selectorName, arguments); | 38 throw new NoSuchMethodError(function, selectorName, arguments); |
| 39 } | 39 } |
| 40 // We bound 'this' to [function] because of how we compile | 40 // We bound 'this' to [function] because of how we compile |
| 41 // closures: escaped local variables are stored and accessed through | 41 // closures: escaped local variables are stored and accessed through |
| 42 // [function]. | 42 // [function]. |
| 43 return JS('var', '#.apply(#, #)', jsFunction, function, arguments); | 43 return JS('var', '#.apply(#, #)', jsFunction, function, arguments); |
| 44 } | 44 } |
| 45 | 45 |
| 46 class ArgumentDescriptor { | 46 class ArgumentDescriptor { |
| 47 final List positionalArguments; | 47 final List positionalArguments; |
| 48 final Map<String, Dynamic> namedArguments; | 48 final Map<String, dynamic> namedArguments; |
| 49 | 49 |
| 50 ArgumentDescriptor(this.positionalArguments, this.namedArguments); | 50 ArgumentDescriptor(this.positionalArguments, this.namedArguments); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void throwsNSME(function) { | 53 void throwsNSME(function) { |
| 54 Expect.throws(function, (e) => e is NoSuchMethodError); | 54 Expect.throws(function, (e) => e is NoSuchMethodError); |
| 55 } | 55 } |
| 56 | 56 |
| 57 main() { | 57 main() { |
| 58 var c1 = () => 'c1'; | 58 var c1 = () => 'c1'; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 apply(c6, new ArgumentDescriptor([], {'a': 3, 'b': 4}))); | 126 apply(c6, new ArgumentDescriptor([], {'a': 3, 'b': 4}))); |
| 127 Expect.equals('c6 4 3', | 127 Expect.equals('c6 4 3', |
| 128 apply(c6, new ArgumentDescriptor([], {'b': 3, 'a': 4}))); | 128 apply(c6, new ArgumentDescriptor([], {'b': 3, 'a': 4}))); |
| 129 Expect.equals('c6 2 3', | 129 Expect.equals('c6 2 3', |
| 130 apply(c6, new ArgumentDescriptor([], {'b': 3}))); | 130 apply(c6, new ArgumentDescriptor([], {'b': 3}))); |
| 131 throwsNSME(() => apply(c6, new ArgumentDescriptor([1], {'a': 1}))); | 131 throwsNSME(() => apply(c6, new ArgumentDescriptor([1], {'a': 1}))); |
| 132 throwsNSME(() => apply(c6, new ArgumentDescriptor([1], {}))); | 132 throwsNSME(() => apply(c6, new ArgumentDescriptor([1], {}))); |
| 133 throwsNSME(() => | 133 throwsNSME(() => |
| 134 apply(c6, new ArgumentDescriptor([], {'a': 1, 'b': 2, 'c': 3}))); | 134 apply(c6, new ArgumentDescriptor([], {'a': 1, 'b': 2, 'c': 3}))); |
| 135 } | 135 } |
| OLD | NEW |