| 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 library _js_helper; | 5 library _js_helper; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:_foreign_helper' show DART_CLOSURE_TO_JS, | 8 import 'dart:_foreign_helper' show DART_CLOSURE_TO_JS, |
| 9 JS, | 9 JS, |
| 10 JS_CALL_IN_ISOLATE, | 10 JS_CALL_IN_ISOLATE, |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 | 518 |
| 519 static void setProperty(object, key, value) { | 519 static void setProperty(object, key, value) { |
| 520 if (object == null || object is bool || object is num || object is String) { | 520 if (object == null || object is bool || object is num || object is String) { |
| 521 throw new ArgumentError(object); | 521 throw new ArgumentError(object); |
| 522 } | 522 } |
| 523 JS('void', '#[#] = #', object, key, value); | 523 JS('void', '#[#] = #', object, key, value); |
| 524 } | 524 } |
| 525 | 525 |
| 526 static applyFunction(Function function, | 526 static applyFunction(Function function, |
| 527 List positionalArguments, | 527 List positionalArguments, |
| 528 Map<Symbol, dynamic> namedArguments) { | 528 Map<String, dynamic> namedArguments) { |
| 529 int argumentCount = 0; | 529 int argumentCount = 0; |
| 530 StringBuffer buffer = new StringBuffer(); | 530 StringBuffer buffer = new StringBuffer(); |
| 531 List arguments = []; | 531 List arguments = []; |
| 532 | 532 |
| 533 if (positionalArguments != null) { | 533 if (positionalArguments != null) { |
| 534 argumentCount += positionalArguments.length; | 534 argumentCount += positionalArguments.length; |
| 535 arguments.addAll(positionalArguments); | 535 arguments.addAll(positionalArguments); |
| 536 } | 536 } |
| 537 | 537 |
| 538 // Sort the named arguments to get the right selector name and | 538 // Sort the named arguments to get the right selector name and |
| 539 // arguments order. | 539 // arguments order. |
| 540 if (namedArguments != null && !namedArguments.isEmpty) { | 540 if (namedArguments != null && !namedArguments.isEmpty) { |
| 541 // Call new List.from to make sure we get a JavaScript array. | 541 // Call new List.from to make sure we get a JavaScript array. |
| 542 List<Symbol> listOfNamedArguments = | 542 List<String> listOfNamedArguments = |
| 543 new List<Symbol>.from(namedArguments.keys); | 543 new List<String>.from(namedArguments.keys); |
| 544 argumentCount += namedArguments.length; | 544 argumentCount += namedArguments.length; |
| 545 // We're sorting on strings, and the behavior is the same between | 545 // We're sorting on strings, and the behavior is the same between |
| 546 // Dart string sort and JS string sort. To avoid needing the Dart | 546 // Dart string sort and JS string sort. To avoid needing the Dart |
| 547 // sort implementation, we use the JavaScript one instead. | 547 // sort implementation, we use the JavaScript one instead. |
| 548 JS('void', '#.sort()', listOfNamedArguments); | 548 JS('void', '#.sort()', listOfNamedArguments); |
| 549 listOfNamedArguments.forEach((Symbol name) { | 549 listOfNamedArguments.forEach((String name) { |
| 550 buffer.write('\$$name'); | 550 buffer.write('\$$name'); |
| 551 arguments.add(namedArguments[name]); | 551 arguments.add(namedArguments[name]); |
| 552 }); | 552 }); |
| 553 } | 553 } |
| 554 | 554 |
| 555 String selectorName = 'call\$$argumentCount$buffer'; | 555 String selectorName = 'call\$$argumentCount$buffer'; |
| 556 var jsFunction = JS('var', '#[#]', function, selectorName); | 556 var jsFunction = JS('var', '#[#]', function, selectorName); |
| 557 if (jsFunction == null) { | 557 if (jsFunction == null) { |
| 558 throw new NoSuchMethodError(function, selectorName, arguments, {}); | 558 throw new NoSuchMethodError(function, selectorName, arguments, {}); |
| 559 } | 559 } |
| (...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1381 expectedArgumentNames); | 1381 expectedArgumentNames); |
| 1382 } | 1382 } |
| 1383 | 1383 |
| 1384 /** | 1384 /** |
| 1385 * Called by generated code when a static field's initializer references the | 1385 * Called by generated code when a static field's initializer references the |
| 1386 * field that is currently being initialized. | 1386 * field that is currently being initialized. |
| 1387 */ | 1387 */ |
| 1388 void throwCyclicInit(String staticName) { | 1388 void throwCyclicInit(String staticName) { |
| 1389 throw new RuntimeError("Cyclic initialization for static $staticName"); | 1389 throw new RuntimeError("Cyclic initialization for static $staticName"); |
| 1390 } | 1390 } |
| OLD | NEW |