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

Side by Side Diff: pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/rtti.dart

Issue 2515353003: Support lazy JS types. (Closed)
Patch Set: Support lazy JS types. Created 4 years, 1 month 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 /// This library defines the association between runtime objects and 5 /// This library defines the association between runtime objects and
6 /// runtime types. 6 /// runtime types.
7 part of dart._runtime; 7 part of dart._runtime;
8 8
9 /// Runtime type information. This module defines the mapping from 9 /// Runtime type information. This module defines the mapping from
10 /// runtime objects to their runtime type information. See the types 10 /// runtime objects to their runtime type information. See the types
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 /// 51 ///
52 /// `dart.fn(cls, rType, argsT, extras)` marks cls as having the 52 /// `dart.fn(cls, rType, argsT, extras)` marks cls as having the
53 /// runtime type dart.functionType(rType, argsT, extras). 53 /// runtime type dart.functionType(rType, argsT, extras).
54 /// 54 ///
55 /// Note that since we are producing a type for a concrete function, 55 /// Note that since we are producing a type for a concrete function,
56 /// it is sound to use the definite arrow type. 56 /// it is sound to use the definite arrow type.
57 /// 57 ///
58 fn(closure, t) { 58 fn(closure, t) {
59 if (t == null) { 59 if (t == null) {
60 // No type arguments, it's all dynamic 60 // No type arguments, it's all dynamic
61 t = definiteFunctionType( 61 t = definiteFunctionType(JS('', '#', dynamic),
62 JS('', '#', dynamic), 62 JS('', 'Array(#.length).fill(#)', closure, dynamic), JS('', 'void 0'));
63 JS('', 'Array(#.length).fill(#)', closure, dynamic),
64 JS('', 'void 0'));
65 } 63 }
66 tag(closure, t); 64 tag(closure, t);
67 return closure; 65 return closure;
68 } 66 }
69 67
70 lazyFn(closure, computeType) { 68 lazyFn(closure, computeType) {
71 tagLazy(closure, computeType); 69 tagLazy(closure, computeType);
72 return closure; 70 return closure;
73 } 71 }
74 72
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 /// that implements the dart:core Type interface. 152 /// that implements the dart:core Type interface.
155 wrapType(type) { 153 wrapType(type) {
156 // If we've already wrapped this type once, use the previous wrapper. This 154 // If we've already wrapped this type once, use the previous wrapper. This
157 // way, multiple references to the same type return an identical Type. 155 // way, multiple references to the same type return an identical Type.
158 if (JS('bool', '#.hasOwnProperty(#)', type, _typeObject)) { 156 if (JS('bool', '#.hasOwnProperty(#)', type, _typeObject)) {
159 return JS('', '#[#]', type, _typeObject); 157 return JS('', '#[#]', type, _typeObject);
160 } 158 }
161 return JS('', '#[#] = new #(#)', type, _typeObject, WrappedType, type); 159 return JS('', '#[#] = new #(#)', type, _typeObject, WrappedType, type);
162 } 160 }
163 161
162 var _lazyJSTypes = JS('', 'new Map()');
163
164 lazyJSType(getJSTypeCallback, name) {
165 var key = JS('String', '#.toString()', getJSTypeCallback);
166 if (JS('bool', '#.has(#)', _lazyJSTypes, key)) {
167 return JS('', '#.get(#)', _lazyJSTypes, key);
168 }
169 var ret = JS('', 'new #(#, #)', LazyJSType, getJSTypeCallback, name);
170 JS('', '#.set(#, #)', _lazyJSTypes, key, ret);
171 return ret;
172 }
173
174 // TODO(jacobr): do not use the same LazyJSType object for anonymous JS types
175 // from different libraries.
176 lazyAnonymousJSType(name) {
177 if (JS('bool', '#.has(#)', _lazyJSTypes, name)) {
178 return JS('', '#.get(#)', _lazyJSTypes, name);
179 }
180 var ret = JS('', 'new #(null, #)', LazyJSType, name);
181 JS('', '#.set(#, #)', _lazyJSTypes, name, ret);
182 return ret;
183 }
184
164 /// Given a WrappedType, return the internal runtime type object. 185 /// Given a WrappedType, return the internal runtime type object.
165 unwrapType(obj) => obj._wrappedType; 186 unwrapType(obj) => obj._wrappedType;
166 187
167 _getRuntimeType(value) => JS('', '#[#]', value, _runtimeType); 188 _getRuntimeType(value) => JS('', '#[#]', value, _runtimeType);
168 getIsNamedConstructor(value) => JS('', '#[#]', value, isNamedConstructor); 189 getIsNamedConstructor(value) => JS('', '#[#]', value, isNamedConstructor);
169 // TODO(bmilligan): Define the symbol in rtti.dart instead of dart_library.js 190 // TODO(bmilligan): Define the symbol in rtti.dart instead of dart_library.js
170 // and get rid of the call to dart_library in the JS here. 191 // and get rid of the call to dart_library in the JS here.
171 getDartLibraryName(value) => JS('', '#[dart_library.dartLibraryName]', value); 192 getDartLibraryName(value) => JS('', '#[dart_library.dartLibraryName]', value);
172 193
173 /// Tag the runtime type of [value] to be type [t]. 194 /// Tag the runtime type of [value] to be type [t].
174 void tag(value, t) { 195 void tag(value, t) {
175 JS('', '#[#] = #', value, _runtimeType, t); 196 JS('', '#[#] = #', value, _runtimeType, t);
176 } 197 }
177 198
178 void tagComputed(value, compute) { 199 void tagComputed(value, compute) {
179 JS('', '#(#, #, { get: # })', defineProperty, value, _runtimeType, compute); 200 JS('', '#(#, #, { get: # })', defineProperty, value, _runtimeType, compute);
180 } 201 }
181 202
182 void tagLazy(value, compute) { 203 void tagLazy(value, compute) {
183 JS('', '#(#, #, { get: # })', 204 JS('', '#(#, #, { get: # })', defineLazyProperty, value, _runtimeType,
184 defineLazyProperty, value, _runtimeType, compute); 205 compute);
185 } 206 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698