| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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:_js_embedded_names' show | 7 import 'dart:_js_embedded_names' show |
| 8 ALL_CLASSES, | 8 ALL_CLASSES, |
| 9 GET_ISOLATE_TAG, | 9 GET_ISOLATE_TAG, |
| 10 INTERCEPTED_NAMES, | 10 INTERCEPTED_NAMES, |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 /* | 747 /* |
| 748 if (name.length > 1 && identical(name.codeUnitAt(0), DOLLAR_CHAR_VALUE)) { | 748 if (name.length > 1 && identical(name.codeUnitAt(0), DOLLAR_CHAR_VALUE)) { |
| 749 name = name.substring(1); | 749 name = name.substring(1); |
| 750 } | 750 } |
| 751 */ | 751 */ |
| 752 return formatType(name, getRuntimeTypeInfo(object)); | 752 return formatType(name, getRuntimeTypeInfo(object)); |
| 753 } | 753 } |
| 754 | 754 |
| 755 /// In minified mode, uses the unminified names if available. | 755 /// In minified mode, uses the unminified names if available. |
| 756 static String objectToString(Object object) { | 756 static String objectToString(Object object) { |
| 757 String name = objectTypeName(object); | 757 // String name = objectTypeName(object); |
| 758 String name = JS('String', 'dart.typeName(dart.realRuntimeType(#))', object)
; |
| 758 return "Instance of '$name'"; | 759 return "Instance of '$name'"; |
| 759 } | 760 } |
| 760 | 761 |
| 761 static num dateNow() => JS('int', r'Date.now()'); | 762 static num dateNow() => JS('int', r'Date.now()'); |
| 762 | 763 |
| 763 static void initTicker() { | 764 static void initTicker() { |
| 764 if (timerFrequency != null) return; | 765 if (timerFrequency != null) return; |
| 765 // Start with low-resolution. We overwrite the fields if we find better. | 766 // Start with low-resolution. We overwrite the fields if we find better. |
| 766 timerFrequency = 1000; | 767 timerFrequency = 1000; |
| 767 timerTicks = dateNow; | 768 timerTicks = dateNow; |
| (...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1912 throw new Exception( | 1913 throw new Exception( |
| 1913 'Unsupported number of arguments for wrapped closure'); | 1914 'Unsupported number of arguments for wrapped closure'); |
| 1914 } | 1915 } |
| 1915 } | 1916 } |
| 1916 | 1917 |
| 1917 /** | 1918 /** |
| 1918 * Called by generated code to convert a Dart closure to a JS | 1919 * Called by generated code to convert a Dart closure to a JS |
| 1919 * closure when the Dart closure is passed to the DOM. | 1920 * closure when the Dart closure is passed to the DOM. |
| 1920 */ | 1921 */ |
| 1921 convertDartClosureToJS(closure, int arity) { | 1922 convertDartClosureToJS(closure, int arity) { |
| 1922 if (closure == null) return null; | 1923 // TODO(vsm): Dart2JS wraps closures to: |
| 1923 var function = JS('var', r'#.$identity', closure); | 1924 // (a) adjust the calling convention, and |
| 1924 if (JS('bool', r'!!#', function)) return function; | 1925 // (b) record the source isolate |
| 1925 | 1926 // Do we need either? |
| 1926 // We use $0 and $1 to not clash with variable names used by the | 1927 // See: https://github.com/dart-lang/dev_compiler/issues/164 |
| 1927 // compiler and/or minifier. | 1928 return closure; |
| 1928 function = JS('var', | |
| 1929 '(function(closure, arity, context, invoke) {' | |
| 1930 ' return function(a1, a2, a3, a4) {' | |
| 1931 ' return invoke(closure, context, arity, a1, a2, a3, a4);' | |
| 1932 ' };' | |
| 1933 '})(#,#,#,#)', | |
| 1934 closure, | |
| 1935 arity, | |
| 1936 // Capture the current isolate now. Remember that "#" | |
| 1937 // in JS is simply textual substitution of compiled | |
| 1938 // expressions. | |
| 1939 JS_CURRENT_ISOLATE_CONTEXT(), | |
| 1940 DART_CLOSURE_TO_JS(invokeClosure)); | |
| 1941 | |
| 1942 JS('void', r'#.$identity = #', closure, function); | |
| 1943 return function; | |
| 1944 } | 1929 } |
| 1945 | 1930 |
| 1946 /** | 1931 /** |
| 1947 * Super class for Dart closures. | 1932 * Super class for Dart closures. |
| 1948 */ | 1933 */ |
| 1949 abstract class Closure implements Function { | 1934 abstract class Closure implements Function { |
| 1950 // TODO(ahe): These constants must be in sync with | 1935 // TODO(ahe): These constants must be in sync with |
| 1951 // reflection_data_parser.dart. | 1936 // reflection_data_parser.dart. |
| 1952 static const FUNCTION_INDEX = 0; | 1937 static const FUNCTION_INDEX = 0; |
| 1953 static const NAME_INDEX = 1; | 1938 static const NAME_INDEX = 1; |
| (...skipping 1516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3470 throw new MainError("No top-level function named 'main'."); | 3455 throw new MainError("No top-level function named 'main'."); |
| 3471 } | 3456 } |
| 3472 | 3457 |
| 3473 void badMain() { | 3458 void badMain() { |
| 3474 throw new MainError("'main' is not a function."); | 3459 throw new MainError("'main' is not a function."); |
| 3475 } | 3460 } |
| 3476 | 3461 |
| 3477 void mainHasTooManyParameters() { | 3462 void mainHasTooManyParameters() { |
| 3478 throw new MainError("'main' expects too many parameters."); | 3463 throw new MainError("'main' expects too many parameters."); |
| 3479 } | 3464 } |
| OLD | NEW |