OLD | NEW |
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 lazyFn(closure, computeType) { | 68 lazyFn(closure, computeType) { |
69 tagLazy(closure, computeType); | 69 tagLazy(closure, computeType); |
70 return closure; | 70 return closure; |
71 } | 71 } |
72 | 72 |
73 // TODO(vsm): How should we encode the runtime type? | 73 // TODO(vsm): How should we encode the runtime type? |
74 final _runtimeType = JS('', 'Symbol("_runtimeType")'); | 74 final _runtimeType = JS('', 'Symbol("_runtimeType")'); |
75 final isNamedConstructor = JS('', 'Symbol("isNamedConstructor")'); | 75 final isNamedConstructor = JS('', 'Symbol("isNamedConstructor")'); |
76 | 76 |
| 77 final _moduleName = JS('', 'Symbol("_moduleName")'); |
| 78 |
77 _checkPrimitiveType(obj) { | 79 _checkPrimitiveType(obj) { |
78 // TODO(jmesserly): JS is used to prevent type literal wrapping. Is there a | 80 // TODO(jmesserly): JS is used to prevent type literal wrapping. Is there a |
79 // better way we can handle this? (sra: It is super dodgy that the values | 81 // better way we can handle this? (sra: It is super dodgy that the values |
80 // passed to JS are different to the values passed to a regular function - the | 82 // passed to JS are different to the values passed to a regular function - the |
81 // semantics are not longer that of calling an interpreter. dart2js has other | 83 // semantics are not longer that of calling an interpreter. dart2js has other |
82 // special functions, we could do the same.) | 84 // special functions, we could do the same.) |
83 | 85 |
84 // Check for null and undefined | 86 // Check for null and undefined |
85 if (obj == null) return JS('', '#', Null); | 87 if (obj == null) return JS('', '#', Null); |
86 | 88 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 var ret = JS('', 'new #(null, #)', LazyJSType, name); | 182 var ret = JS('', 'new #(null, #)', LazyJSType, name); |
181 JS('', '#.set(#, #)', _lazyJSTypes, name, ret); | 183 JS('', '#.set(#, #)', _lazyJSTypes, name, ret); |
182 return ret; | 184 return ret; |
183 } | 185 } |
184 | 186 |
185 /// Given a WrappedType, return the internal runtime type object. | 187 /// Given a WrappedType, return the internal runtime type object. |
186 unwrapType(WrappedType obj) => obj._wrappedType; | 188 unwrapType(WrappedType obj) => obj._wrappedType; |
187 | 189 |
188 _getRuntimeType(value) => JS('', '#[#]', value, _runtimeType); | 190 _getRuntimeType(value) => JS('', '#[#]', value, _runtimeType); |
189 getIsNamedConstructor(value) => JS('', '#[#]', value, isNamedConstructor); | 191 getIsNamedConstructor(value) => JS('', '#[#]', value, isNamedConstructor); |
190 // TODO(bmilligan): Define the symbol in rtti.dart instead of dart_library.js | 192 |
191 // and get rid of the call to dart_library in the JS here. | 193 /// Return the module name for a raw library object. |
192 getDartLibraryName(value) => JS('', '#[dart_library.dartLibraryName]', value); | 194 getModuleName(value) => JS('', '#[#]', value, _moduleName); |
193 | 195 |
194 /// Tag the runtime type of [value] to be type [t]. | 196 /// Tag the runtime type of [value] to be type [t]. |
195 void tag(value, t) { | 197 void tag(value, t) { |
196 JS('', '#[#] = #', value, _runtimeType, t); | 198 JS('', '#[#] = #', value, _runtimeType, t); |
197 } | 199 } |
198 | 200 |
199 void tagComputed(value, compute) { | 201 void tagComputed(value, compute) { |
200 JS('', '#(#, #, { get: # })', defineProperty, value, _runtimeType, compute); | 202 JS('', '#(#, #, { get: # })', defineProperty, value, _runtimeType, compute); |
201 } | 203 } |
202 | 204 |
203 void tagLazy(value, compute) { | 205 void tagLazy(value, compute) { |
204 JS('', '#(#, #, { get: # })', defineLazyProperty, value, _runtimeType, | 206 JS('', '#(#, #, { get: # })', defineLazyProperty, value, _runtimeType, |
205 compute); | 207 compute); |
206 } | 208 } |
| 209 |
| 210 var _loadedModules = JS('', 'new Map()'); |
| 211 |
| 212 List getModuleNames() { |
| 213 return JS('', 'Array.from(#.keys())', _loadedModules); |
| 214 } |
| 215 |
| 216 /// Return all library objects in the specified module. |
| 217 getModuleLibraries(String name) { |
| 218 var module = JS('', '#.get(#)', _loadedModules, name); |
| 219 if (module == null) return null; |
| 220 JS('', '#[#] = #', module, _moduleName, name); |
| 221 return module; |
| 222 } |
| 223 |
| 224 /// Track all libraries |
| 225 void trackLibraries(String moduleName, libraries) { |
| 226 JS('', '#.set(#, #)', _loadedModules, moduleName, libraries); |
| 227 } |
OLD | NEW |