Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: sdk/lib/_internal/compiler/js_lib/js_helper.dart

Issue 981143003: dart2js: split out types from metadata. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 JsGetName, 10 DEFERRED_LIBRARY_URIS,
11 DEFERRED_LIBRARY_HASHES,
11 GET_TYPE_FROM_NAME, 12 GET_TYPE_FROM_NAME,
12 GET_ISOLATE_TAG, 13 GET_ISOLATE_TAG,
14 INITIALIZE_LOADED_HUNK,
13 INTERCEPTED_NAMES, 15 INTERCEPTED_NAMES,
14 INTERCEPTORS_BY_TAG, 16 INTERCEPTORS_BY_TAG,
17 IS_HUNK_LOADED,
18 IS_HUNK_INITIALIZED,
19 JsGetName,
15 LEAF_TAGS, 20 LEAF_TAGS,
16 METADATA, 21 METADATA,
17 DEFERRED_LIBRARY_URIS, 22 NATIVE_SUPERCLASS_TAG_NAME,
18 DEFERRED_LIBRARY_HASHES, 23 TYPES;
19 INITIALIZE_LOADED_HUNK,
20 IS_HUNK_LOADED,
21 IS_HUNK_INITIALIZED,
22 NATIVE_SUPERCLASS_TAG_NAME;
23 24
24 import 'dart:collection'; 25 import 'dart:collection';
25 26
26 import 'dart:_isolate_helper' show 27 import 'dart:_isolate_helper' show
27 IsolateNatives, 28 IsolateNatives,
28 enterJsAsync, 29 enterJsAsync,
29 isWorker, 30 isWorker,
30 leaveJsAsync; 31 leaveJsAsync;
31 32
32 import 'dart:async' show 33 import 'dart:async' show
34 Completer,
35 DeferredLoadException,
33 Future, 36 Future,
34 DeferredLoadException,
35 Completer,
36 StreamController, 37 StreamController,
37 Stream, 38 Stream,
38 StreamSubscription, 39 StreamSubscription,
39 scheduleMicrotask; 40 scheduleMicrotask;
40 41
41 import 'dart:_foreign_helper' show 42 import 'dart:_foreign_helper' show
42 DART_CLOSURE_TO_JS, 43 DART_CLOSURE_TO_JS,
43 JS, 44 JS,
44 JS_CALL_IN_ISOLATE, 45 JS_CALL_IN_ISOLATE,
45 JS_CONST, 46 JS_CONST,
(...skipping 16 matching lines...) Expand all
62 JS_NULL_CLASS_NAME, 63 JS_NULL_CLASS_NAME,
63 JS_OBJECT_CLASS_NAME, 64 JS_OBJECT_CLASS_NAME,
64 JS_OPERATOR_AS_PREFIX, 65 JS_OPERATOR_AS_PREFIX,
65 JS_OPERATOR_IS_PREFIX, 66 JS_OPERATOR_IS_PREFIX,
66 JS_SIGNATURE_NAME, 67 JS_SIGNATURE_NAME,
67 JS_STRING_CONCAT, 68 JS_STRING_CONCAT,
68 RAW_DART_FUNCTION_REF; 69 RAW_DART_FUNCTION_REF;
69 70
70 import 'dart:_interceptors'; 71 import 'dart:_interceptors';
71 import 'dart:_internal' as _symbol_dev; 72 import 'dart:_internal' as _symbol_dev;
72 import 'dart:_internal' show MappedIterable, EfficientLength; 73 import 'dart:_internal' show EfficientLength, MappedIterable;
73 74
74 import 'dart:_native_typed_data'; 75 import 'dart:_native_typed_data';
75 76
76 import 'dart:_js_names' show 77 import 'dart:_js_names' show
77 extractKeys, 78 extractKeys,
78 mangledNames, 79 mangledNames,
79 unmangleGlobalNameIfPreservedAnyways, 80 unmangleGlobalNameIfPreservedAnyways,
80 unmangleAllIdentifiersIfPreservedAnyways; 81 unmangleAllIdentifiersIfPreservedAnyways;
81 82
82 part 'annotations.dart'; 83 part 'annotations.dart';
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 (positions.keys.toList()..sort()).forEach((String name) { 530 (positions.keys.toList()..sort()).forEach((String name) {
530 cachedSortedIndices[index++] = positions[name]; 531 cachedSortedIndices[index++] = positions[name];
531 }); 532 });
532 } 533 }
533 return cachedSortedIndices[unsortedIndex]; 534 return cachedSortedIndices[unsortedIndex];
534 } 535 }
535 536
536 @NoInline() 537 @NoInline()
537 computeFunctionRti(jsConstructor) { 538 computeFunctionRti(jsConstructor) {
538 if (JS('bool', 'typeof # == "number"', functionType)) { 539 if (JS('bool', 'typeof # == "number"', functionType)) {
539 return getMetadata(functionType); 540 return getType(functionType);
540 } else if (JS('bool', 'typeof # == "function"', functionType)) { 541 } else if (JS('bool', 'typeof # == "function"', functionType)) {
541 var fakeInstance = JS('', 'new #()', jsConstructor); 542 var fakeInstance = JS('', 'new #()', jsConstructor);
542 setRuntimeTypeInfo( 543 setRuntimeTypeInfo(
543 fakeInstance, JS('JSExtendableArray', '#["<>"]', fakeInstance)); 544 fakeInstance, JS('JSExtendableArray', '#["<>"]', fakeInstance));
544 return JS('=Object|Null', r'#.apply({$receiver:#})', 545 return JS('=Object|Null', r'#.apply({$receiver:#})',
545 functionType, fakeInstance); 546 functionType, fakeInstance);
546 } else { 547 } else {
547 throw new RuntimeError('Unexpected function type'); 548 throw new RuntimeError('Unexpected function type');
548 } 549 }
549 } 550 }
550 551
551 String get reflectionName => JS('String', r'#.$reflectionName', jsFunction); 552 String get reflectionName => JS('String', r'#.$reflectionName', jsFunction);
552 } 553 }
553 554
554 getMetadata(int index) { 555 getMetadata(int index) {
555 var metadata = JS_EMBEDDED_GLOBAL('', METADATA); 556 var metadata = JS_EMBEDDED_GLOBAL('', METADATA);
556 return JS('', '#[#]', metadata, index); 557 return JS('', '#[#]', metadata, index);
557 } 558 }
558 559
560 getType(int index) {
561 var types = JS_EMBEDDED_GLOBAL('', TYPES);
562 return JS('', '#[#]', types, index);
563 }
564
559 class Primitives { 565 class Primitives {
560 /// Isolate-unique ID for caching [JsClosureMirror.function]. 566 /// Isolate-unique ID for caching [JsClosureMirror.function].
561 /// Note the initial value is used by the first isolate (or if there are no 567 /// Note the initial value is used by the first isolate (or if there are no
562 /// isolates), new isolates will update this value to avoid conflicts by 568 /// isolates), new isolates will update this value to avoid conflicts by
563 /// calling [initializeStatics]. 569 /// calling [initializeStatics].
564 static String mirrorFunctionCacheName = '\$cachedFunction'; 570 static String mirrorFunctionCacheName = '\$cachedFunction';
565 571
566 /// Isolate-unique ID for caching [JsInstanceMirror._invoke]. 572 /// Isolate-unique ID for caching [JsInstanceMirror._invoke].
567 static String mirrorInvokeCacheName = '\$cachedInvocation'; 573 static String mirrorInvokeCacheName = '\$cachedInvocation';
568 574
(...skipping 1571 matching lines...) Expand 10 before | Expand all | Expand 10 after
2140 isIntercepted = true; 2146 isIntercepted = true;
2141 } 2147 }
2142 trampoline = forwardCallTo(receiver, function, isIntercepted); 2148 trampoline = forwardCallTo(receiver, function, isIntercepted);
2143 JS('', '#.\$reflectionInfo = #', trampoline, reflectionInfo); 2149 JS('', '#.\$reflectionInfo = #', trampoline, reflectionInfo);
2144 } else { 2150 } else {
2145 JS('', '#.\$name = #', prototype, propertyName); 2151 JS('', '#.\$name = #', prototype, propertyName);
2146 } 2152 }
2147 2153
2148 var signatureFunction; 2154 var signatureFunction;
2149 if (JS('bool', 'typeof # == "number"', functionType)) { 2155 if (JS('bool', 'typeof # == "number"', functionType)) {
2150 var metadata = JS_EMBEDDED_GLOBAL('', METADATA); 2156 var types = JS_EMBEDDED_GLOBAL('', TYPES);
2151 // It is ok, if the access is inlined into the JS. The access is safe in 2157 // It is ok, if the access is inlined into the JS. The access is safe in
2152 // and outside the function. In fact we prefer if there is a textual 2158 // and outside the function. In fact we prefer if there is a textual
2153 // inlining. 2159 // inlining.
2154 signatureFunction = 2160 signatureFunction =
2155 JS('', '(function(s){return function(){return #[s]}})(#)', 2161 JS('', '(function(s){return function(){return #[s]}})(#)',
2156 metadata, 2162 types,
2157 functionType); 2163 functionType);
2158 } else if (!isStatic 2164 } else if (!isStatic
2159 && JS('bool', 'typeof # == "function"', functionType)) { 2165 && JS('bool', 'typeof # == "function"', functionType)) {
2160 var getReceiver = isIntercepted 2166 var getReceiver = isIntercepted
2161 ? RAW_DART_FUNCTION_REF(BoundClosure.receiverOf) 2167 ? RAW_DART_FUNCTION_REF(BoundClosure.receiverOf)
2162 : RAW_DART_FUNCTION_REF(BoundClosure.selfOf); 2168 : RAW_DART_FUNCTION_REF(BoundClosure.selfOf);
2163 signatureFunction = JS( 2169 signatureFunction = JS(
2164 '', 2170 '',
2165 'function(f,r){' 2171 'function(f,r){'
2166 'return function(){' 2172 'return function(){'
(...skipping 1696 matching lines...) Expand 10 before | Expand all | Expand 10 after
3863 // This is a function that will return a helper function that does the 3869 // This is a function that will return a helper function that does the
3864 // iteration of the sync*. 3870 // iteration of the sync*.
3865 // 3871 //
3866 // Each invocation should give a body with fresh state. 3872 // Each invocation should give a body with fresh state.
3867 final dynamic /* js function */ _outerHelper; 3873 final dynamic /* js function */ _outerHelper;
3868 3874
3869 SyncStarIterable(this._outerHelper); 3875 SyncStarIterable(this._outerHelper);
3870 3876
3871 Iterator get iterator => new SyncStarIterator(JS('', '#()', _outerHelper)); 3877 Iterator get iterator => new SyncStarIterator(JS('', '#()', _outerHelper));
3872 } 3878 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698