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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 JS_SIGNATURE_NAME, | 55 JS_SIGNATURE_NAME, |
56 JS_STRING_CONCAT, | 56 JS_STRING_CONCAT, |
57 RAW_DART_FUNCTION_REF; | 57 RAW_DART_FUNCTION_REF; |
58 | 58 |
59 import 'dart:_interceptors'; | 59 import 'dart:_interceptors'; |
60 import 'dart:_internal' as _symbol_dev; | 60 import 'dart:_internal' as _symbol_dev; |
61 import 'dart:_internal' show MappedIterable; | 61 import 'dart:_internal' show MappedIterable; |
62 | 62 |
63 import 'dart:_js_names' show | 63 import 'dart:_js_names' show |
64 extractKeys, | 64 extractKeys, |
65 mangledNames, | 65 mangledNames; |
66 unmangleGlobalNameIfPreservedAnyways, | |
67 unmangleAllIdentifiersIfPreservedAnyways; | |
68 | 66 |
69 part 'annotations.dart'; | 67 part 'annotations.dart'; |
70 part 'constant_map.dart'; | 68 part 'constant_map.dart'; |
71 part 'native_helper.dart'; | 69 part 'native_helper.dart'; |
72 part 'regexp_helper.dart'; | 70 part 'regexp_helper.dart'; |
73 part 'string_helper.dart'; | 71 part 'string_helper.dart'; |
74 part 'js_rti.dart'; | 72 part 'js_rti.dart'; |
75 | 73 |
74 // TODO(jacobr): remove. | |
75 String unmangleGlobalNameIfPreservedAnyways(String str) => str; | |
76 // TODO(jacobr): remove. | |
77 String unmangleAllIdentifiersIfPreservedAnyways(String str) => str; | |
78 | |
76 class _Patch { | 79 class _Patch { |
77 const _Patch(); | 80 const _Patch(); |
78 } | 81 } |
79 | 82 |
80 const _Patch patch = const _Patch(); | 83 const _Patch patch = const _Patch(); |
81 | 84 |
82 | 85 |
83 /// Marks the internal map in dart2js, so that internal libraries can is-check | 86 /// Marks the internal map in dart2js, so that internal libraries can is-check |
84 // them. | 87 // them. |
85 abstract class InternalMap { | 88 abstract class InternalMap { |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
674 return result; | 677 return result; |
675 } | 678 } |
676 return handleError(source); | 679 return handleError(source); |
677 } | 680 } |
678 return result; | 681 return result; |
679 } | 682 } |
680 | 683 |
681 /** [: r"$".codeUnitAt(0) :] */ | 684 /** [: r"$".codeUnitAt(0) :] */ |
682 static const int DOLLAR_CHAR_VALUE = 36; | 685 static const int DOLLAR_CHAR_VALUE = 36; |
683 | 686 |
687 static constructorNameFallback = JS('Function', r''' | |
Jennifer Messerly
2015/04/22 21:14:19
TODO:remove?
Jacob
2015/04/22 22:58:32
agreed. done
| |
688 function getTagFallback(o) { | |
689 var constructor = o.constructor; | |
690 if (typeof constructor == "function") { | |
691 var name = constructor.name; | |
692 // If the name is a non-empty string, we use that as the type name of this | |
693 // object. There are various cases where that does not work, so we have t o | |
694 // detect them and fall through to the toString() based implementation. | |
695 | |
696 if (typeof name == "string" && | |
697 | |
698 // Sometimes the string is empty. This test also catches minified | |
699 // shadow dom polyfil wrapper for Window on Firefox where the faked | |
700 // constructor name does not 'stick'. The shortest real DOM object | |
701 // names have three characters (e.g. URL, CSS). | |
702 name.length > 2 && | |
703 | |
704 // On Firefox we often get "Object" as the constructor name, even for | |
705 // more specialized DOM objects. | |
706 name !== "Object" && | |
707 | |
708 // This can happen in Opera. | |
709 name !== "Function.prototype") { | |
710 return name; | |
711 } | |
712 } | |
713 var s = Object.prototype.toString.call(o); | |
714 return s.substring(8, s.length - 1); | |
715 }'''); | |
716 | |
684 /// Creates a string containing the complete type for the class [className] | 717 /// Creates a string containing the complete type for the class [className] |
685 /// with the given type arguments. | 718 /// with the given type arguments. |
686 /// | 719 /// |
687 /// In minified mode, uses the unminified names if available. | 720 /// In minified mode, uses the unminified names if available. |
688 static String formatType(String className, List typeArguments) { | 721 static String formatType(String className, List typeArguments) { |
689 return unmangleAllIdentifiersIfPreservedAnyways | 722 return unmangleAllIdentifiersIfPreservedAnyways |
690 ('$className${joinArguments(typeArguments, 0)}'); | 723 ('$className${joinArguments(typeArguments, 0)}'); |
691 } | 724 } |
692 | 725 |
693 /// Returns the type of [object] as a string (including type arguments). | 726 /// Returns the type of [object] as a string (including type arguments). |
694 /// | 727 /// |
695 /// In minified mode, uses the unminified names if available. | 728 /// In minified mode, uses the unminified names if available. |
696 static String objectTypeName(Object object) { | 729 static String objectTypeName(Object object) { |
697 String name = constructorNameFallback(getInterceptor(object)); | 730 String name = JS('String', '#(#)', constructorNameFallback, object); |
698 if (name == 'Object') { | 731 if (name == 'Object') { |
699 // Try to decompile the constructor by turning it into a string and get | 732 // Try to decompile the constructor by turning it into a string and get |
700 // the name out of that. If the decompiled name is a string containing an | 733 // the name out of that. If the decompiled name is a string containing an |
701 // identifier, we use that instead of the very generic 'Object'. | 734 // identifier, we use that instead of the very generic 'Object'. |
702 var decompiled = | 735 var decompiled = |
703 JS('var', r'#.match(/^\s*function\s*(\S*)\s*\(/)[1]', | 736 JS('var', r'#.match(/^\s*function\s*(\S*)\s*\(/)[1]', |
704 JS('var', r'String(#.constructor)', object)); | 737 JS('var', r'String(#.constructor)', object)); |
705 if (decompiled is String) | 738 if (decompiled is String) |
706 if (JS('bool', r'/^\w+$/.test(#)', decompiled)) | 739 if (JS('bool', r'/^\w+$/.test(#)', decompiled)) |
707 name = decompiled; | 740 name = decompiled; |
708 } | 741 } |
709 // TODO(kasperl): If the namer gave us a fresh global name, we may | 742 // TODO(kasperl): If the namer gave us a fresh global name, we may |
710 // want to remove the numeric suffix that makes it unique too. | 743 // want to remove the numeric suffix that makes it unique too. |
744 // TODO(jacobr): commented this out as it seems bogus and it breaks as | |
745 // codeUnitAt is not yet supported. | |
Jennifer Messerly
2015/04/22 21:14:19
ideally we kill the entire method :)
Jacob
2015/04/22 22:58:32
yeah. this method is pretty crazy but copying it
| |
746 /* | |
711 if (name.length > 1 && identical(name.codeUnitAt(0), DOLLAR_CHAR_VALUE)) { | 747 if (name.length > 1 && identical(name.codeUnitAt(0), DOLLAR_CHAR_VALUE)) { |
712 name = name.substring(1); | 748 name = name.substring(1); |
713 } | 749 } |
750 */ | |
714 return formatType(name, getRuntimeTypeInfo(object)); | 751 return formatType(name, getRuntimeTypeInfo(object)); |
715 } | 752 } |
716 | 753 |
717 /// In minified mode, uses the unminified names if available. | 754 /// In minified mode, uses the unminified names if available. |
718 static String objectToString(Object object) { | 755 static String objectToString(Object object) { |
719 String name = objectTypeName(object); | 756 String name = objectTypeName(object); |
720 return "Instance of '$name'"; | 757 return "Instance of '$name'"; |
721 } | 758 } |
722 | 759 |
723 static num dateNow() => JS('int', r'Date.now()'); | 760 static num dateNow() => JS('int', r'Date.now()'); |
(...skipping 2708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3432 throw new MainError("No top-level function named 'main'."); | 3469 throw new MainError("No top-level function named 'main'."); |
3433 } | 3470 } |
3434 | 3471 |
3435 void badMain() { | 3472 void badMain() { |
3436 throw new MainError("'main' is not a function."); | 3473 throw new MainError("'main' is not a function."); |
3437 } | 3474 } |
3438 | 3475 |
3439 void mainHasTooManyParameters() { | 3476 void mainHasTooManyParameters() { |
3440 throw new MainError("'main' expects too many parameters."); | 3477 throw new MainError("'main' expects too many parameters."); |
3441 } | 3478 } |
OLD | NEW |