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:_async_await_error_codes' as async_error_codes; | 7 import 'dart:_async_await_error_codes' as async_error_codes; |
8 | 8 |
9 import 'dart:_js_embedded_names' show | 9 import 'dart:_js_embedded_names' show |
10 DEFERRED_LIBRARY_URIS, | 10 DEFERRED_LIBRARY_URIS, |
11 DEFERRED_LIBRARY_HASHES, | 11 DEFERRED_LIBRARY_HASHES, |
12 GET_TYPE_FROM_NAME, | 12 GET_TYPE_FROM_NAME, |
13 GET_ISOLATE_TAG, | 13 GET_ISOLATE_TAG, |
14 INITIALIZE_LOADED_HUNK, | 14 INITIALIZE_LOADED_HUNK, |
15 INTERCEPTED_NAMES, | 15 INTERCEPTED_NAMES, |
16 INTERCEPTORS_BY_TAG, | 16 INTERCEPTORS_BY_TAG, |
17 IS_HUNK_LOADED, | 17 IS_HUNK_LOADED, |
18 IS_HUNK_INITIALIZED, | 18 IS_HUNK_INITIALIZED, |
| 19 JsBuiltin, |
19 JsGetName, | 20 JsGetName, |
20 LEAF_TAGS, | 21 LEAF_TAGS, |
21 METADATA, | 22 METADATA, |
22 NATIVE_SUPERCLASS_TAG_NAME, | 23 NATIVE_SUPERCLASS_TAG_NAME, |
23 TYPES; | 24 TYPES; |
24 | 25 |
25 import 'dart:collection'; | 26 import 'dart:collection'; |
26 | 27 |
27 import 'dart:_isolate_helper' show | 28 import 'dart:_isolate_helper' show |
28 IsolateNatives, | 29 IsolateNatives, |
29 enterJsAsync, | 30 enterJsAsync, |
30 isWorker, | 31 isWorker, |
31 leaveJsAsync; | 32 leaveJsAsync; |
32 | 33 |
33 import 'dart:async' show | 34 import 'dart:async' show |
34 Completer, | 35 Completer, |
35 DeferredLoadException, | 36 DeferredLoadException, |
36 Future, | 37 Future, |
37 StreamController, | 38 StreamController, |
38 Stream, | 39 Stream, |
39 StreamSubscription, | 40 StreamSubscription, |
40 scheduleMicrotask; | 41 scheduleMicrotask; |
41 | 42 |
42 import 'dart:_foreign_helper' show | 43 import 'dart:_foreign_helper' show |
43 DART_CLOSURE_TO_JS, | 44 DART_CLOSURE_TO_JS, |
44 JS, | 45 JS, |
| 46 JS_BUILTIN, |
45 JS_CALL_IN_ISOLATE, | 47 JS_CALL_IN_ISOLATE, |
46 JS_CONST, | 48 JS_CONST, |
47 JS_CURRENT_ISOLATE, | 49 JS_CURRENT_ISOLATE, |
48 JS_CURRENT_ISOLATE_CONTEXT, | 50 JS_CURRENT_ISOLATE_CONTEXT, |
49 JS_DART_OBJECT_CONSTRUCTOR, | |
50 JS_EFFECT, | 51 JS_EFFECT, |
51 JS_EMBEDDED_GLOBAL, | 52 JS_EMBEDDED_GLOBAL, |
52 JS_FUNCTION_CLASS_NAME, | |
53 JS_FUNCTION_TYPE_NAMED_PARAMETERS_TAG, | 53 JS_FUNCTION_TYPE_NAMED_PARAMETERS_TAG, |
54 JS_FUNCTION_TYPE_OPTIONAL_PARAMETERS_TAG, | 54 JS_FUNCTION_TYPE_OPTIONAL_PARAMETERS_TAG, |
55 JS_FUNCTION_TYPE_REQUIRED_PARAMETERS_TAG, | 55 JS_FUNCTION_TYPE_REQUIRED_PARAMETERS_TAG, |
56 JS_FUNCTION_TYPE_RETURN_TYPE_TAG, | 56 JS_FUNCTION_TYPE_RETURN_TYPE_TAG, |
57 JS_FUNCTION_TYPE_TAG, | |
58 JS_FUNCTION_TYPE_VOID_RETURN_TAG, | 57 JS_FUNCTION_TYPE_VOID_RETURN_TAG, |
| 58 JS_GET_FLAG, |
59 JS_GET_NAME, | 59 JS_GET_NAME, |
60 JS_GET_FLAG, | |
61 JS_HAS_EQUALS, | 60 JS_HAS_EQUALS, |
62 JS_IS_INDEXABLE_FIELD_NAME, | 61 JS_IS_INDEXABLE_FIELD_NAME, |
63 JS_NULL_CLASS_NAME, | 62 JS_NULL_CLASS_NAME, |
64 JS_OBJECT_CLASS_NAME, | 63 JS_OBJECT_CLASS_NAME, |
65 JS_OPERATOR_AS_PREFIX, | 64 JS_OPERATOR_AS_PREFIX, |
66 JS_OPERATOR_IS_PREFIX, | 65 JS_OPERATOR_IS_PREFIX, |
67 JS_SIGNATURE_NAME, | 66 JS_SIGNATURE_NAME, |
68 JS_STRING_CONCAT, | 67 JS_STRING_CONCAT, |
69 RAW_DART_FUNCTION_REF; | 68 RAW_DART_FUNCTION_REF; |
70 | 69 |
(...skipping 15 matching lines...) Expand all Loading... |
86 part 'regexp_helper.dart'; | 85 part 'regexp_helper.dart'; |
87 part 'string_helper.dart'; | 86 part 'string_helper.dart'; |
88 part 'js_rti.dart'; | 87 part 'js_rti.dart'; |
89 part 'linked_hash_map.dart'; | 88 part 'linked_hash_map.dart'; |
90 | 89 |
91 /// Marks the internal map in dart2js, so that internal libraries can is-check | 90 /// Marks the internal map in dart2js, so that internal libraries can is-check |
92 /// them. | 91 /// them. |
93 abstract class InternalMap { | 92 abstract class InternalMap { |
94 } | 93 } |
95 | 94 |
| 95 /// Returns true if the given [type] is a function type object. |
| 96 // TODO(floitsch): move this to foreign_helper.dart or similar. |
| 97 @ForceInline() |
| 98 bool isDartFunctionType(Object type) { |
| 99 return JS_BUILTIN('returns:bool;effects:none;depends:none', |
| 100 JsBuiltin.isFunctionType, type); |
| 101 } |
| 102 |
| 103 |
| 104 /// Creates a function type object. |
| 105 // TODO(floitsch): move this to foreign_helper.dart or similar. |
| 106 @ForceInline() |
| 107 bool createDartFunctionType() { |
| 108 return JS_BUILTIN('returns:=Object;effects:none;depends:none', |
| 109 JsBuiltin.createFunctionType); |
| 110 } |
| 111 |
| 112 /// Returns true if the given [type] is _the_ `Function` type. |
| 113 // TODO(floitsch): move this to foreign_helper.dart or similar. |
| 114 @ForceInline() |
| 115 bool isDartFunctionTypeLiteral(Object type) { |
| 116 return JS_BUILTIN('returns:bool;effects:none;depends:none', |
| 117 JsBuiltin.isFunctionTypeLiteral, type); |
| 118 } |
| 119 |
| 120 /// Retrieves the class name from type information stored on the constructor of |
| 121 /// [type]. |
| 122 // TODO(floitsch): move this to foreign_helper.dart or similar. |
| 123 @ForceInline() |
| 124 String getDartTypeName(Object type) { |
| 125 return JS_BUILTIN('String', JsBuiltin.typeName, type); |
| 126 } |
| 127 |
| 128 /// Returns the raw runtime type of the given object [o]. |
| 129 // TODO(floitsch): move this to foreign_helper.dart or similar. |
| 130 @ForceInline() |
| 131 Object getRawRuntimeType(Object o) { |
| 132 return JS_BUILTIN('', JsBuiltin.rawRuntimeType, getInterceptor(o)); |
| 133 } |
| 134 |
| 135 |
96 /// No-op method that is called to inform the compiler that preambles might | 136 /// No-op method that is called to inform the compiler that preambles might |
97 /// be needed when executing the resulting JS file in a command-line | 137 /// be needed when executing the resulting JS file in a command-line |
98 /// JS engine. | 138 /// JS engine. |
99 requiresPreamble() {} | 139 requiresPreamble() {} |
100 | 140 |
101 bool isJsIndexable(var object, var record) { | 141 bool isJsIndexable(var object, var record) { |
102 if (record != null) { | 142 if (record != null) { |
103 var result = dispatchRecordIndexability(record); | 143 var result = dispatchRecordIndexability(record); |
104 if (result != null) return result; | 144 if (result != null) return result; |
105 } | 145 } |
(...skipping 3002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3108 } | 3148 } |
3109 | 3149 |
3110 _extractFunctionTypeObjectFrom(o) { | 3150 _extractFunctionTypeObjectFrom(o) { |
3111 var interceptor = getInterceptor(o); | 3151 var interceptor = getInterceptor(o); |
3112 return JS('bool', '# in #', JS_SIGNATURE_NAME(), interceptor) | 3152 return JS('bool', '# in #', JS_SIGNATURE_NAME(), interceptor) |
3113 ? JS('', '#[#]()', interceptor, JS_SIGNATURE_NAME()) | 3153 ? JS('', '#[#]()', interceptor, JS_SIGNATURE_NAME()) |
3114 : null; | 3154 : null; |
3115 } | 3155 } |
3116 | 3156 |
3117 toRti() { | 3157 toRti() { |
3118 var result = JS('=Object', '{ #: "dynafunc" }', JS_FUNCTION_TYPE_TAG()); | 3158 var result = createDartFunctionType(); |
3119 if (isVoid) { | 3159 if (isVoid) { |
3120 JS('', '#[#] = true', result, JS_FUNCTION_TYPE_VOID_RETURN_TAG()); | 3160 JS('', '#[#] = true', result, JS_FUNCTION_TYPE_VOID_RETURN_TAG()); |
3121 } else { | 3161 } else { |
3122 if (returnType is! DynamicRuntimeType) { | 3162 if (returnType is! DynamicRuntimeType) { |
3123 JS('', '#[#] = #', result, JS_FUNCTION_TYPE_RETURN_TYPE_TAG(), | 3163 JS('', '#[#] = #', result, JS_FUNCTION_TYPE_RETURN_TYPE_TAG(), |
3124 returnType.toRti()); | 3164 returnType.toRti()); |
3125 } | 3165 } |
3126 } | 3166 } |
3127 if (parameterTypes != null && !parameterTypes.isEmpty) { | 3167 if (parameterTypes != null && !parameterTypes.isEmpty) { |
3128 JS('', '#[#] = #', result, JS_FUNCTION_TYPE_REQUIRED_PARAMETERS_TAG(), | 3168 JS('', '#[#] = #', result, JS_FUNCTION_TYPE_REQUIRED_PARAMETERS_TAG(), |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3976 // This is a function that will return a helper function that does the | 4016 // This is a function that will return a helper function that does the |
3977 // iteration of the sync*. | 4017 // iteration of the sync*. |
3978 // | 4018 // |
3979 // Each invocation should give a body with fresh state. | 4019 // Each invocation should give a body with fresh state. |
3980 final dynamic /* js function */ _outerHelper; | 4020 final dynamic /* js function */ _outerHelper; |
3981 | 4021 |
3982 SyncStarIterable(this._outerHelper); | 4022 SyncStarIterable(this._outerHelper); |
3983 | 4023 |
3984 Iterator get iterator => new SyncStarIterator(JS('', '#()', _outerHelper)); | 4024 Iterator get iterator => new SyncStarIterator(JS('', '#()', _outerHelper)); |
3985 } | 4025 } |
OLD | NEW |