| 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 } | 150 } |
| 151 | 151 |
| 152 /// Given an internal runtime type object, wraps it in a `WrappedType` object | 152 /// Given an internal runtime type object, wraps it in a `WrappedType` object |
| 153 /// that implements the dart:core Type interface. | 153 /// that implements the dart:core Type interface. |
| 154 wrapType(type) { | 154 wrapType(type) { |
| 155 // If we've already wrapped this type once, use the previous wrapper. This | 155 // If we've already wrapped this type once, use the previous wrapper. This |
| 156 // way, multiple references to the same type return an identical Type. | 156 // way, multiple references to the same type return an identical Type. |
| 157 if (JS('bool', '#.hasOwnProperty(#)', type, _typeObject)) { | 157 if (JS('bool', '#.hasOwnProperty(#)', type, _typeObject)) { |
| 158 return JS('', '#[#]', type, _typeObject); | 158 return JS('', '#[#]', type, _typeObject); |
| 159 } | 159 } |
| 160 return JS('', '#[#] = new #(#)', type, _typeObject, WrappedType, type); | 160 return JS('', '#[#] = #', type, _typeObject, new WrappedType(type)); |
| 161 } | 161 } |
| 162 | 162 |
| 163 var _lazyJSTypes = JS('', 'new Map()'); | 163 var _lazyJSTypes = JS('', 'new Map()'); |
| 164 | 164 |
| 165 lazyJSType(getJSTypeCallback, name) { | 165 lazyJSType(getJSTypeCallback, name) { |
| 166 var key = JS('String', '#.toString()', getJSTypeCallback); | 166 var key = JS('String', '#.toString()', getJSTypeCallback); |
| 167 if (JS('bool', '#.has(#)', _lazyJSTypes, key)) { | 167 if (JS('bool', '#.has(#)', _lazyJSTypes, key)) { |
| 168 return JS('', '#.get(#)', _lazyJSTypes, key); | 168 return JS('', '#.get(#)', _lazyJSTypes, key); |
| 169 } | 169 } |
| 170 var ret = JS('', 'new #(#, #)', LazyJSType, getJSTypeCallback, name); | 170 var ret = new LazyJSType(getJSTypeCallback, name); |
| 171 JS('', '#.set(#, #)', _lazyJSTypes, key, ret); | 171 JS('', '#.set(#, #)', _lazyJSTypes, key, ret); |
| 172 return ret; | 172 return ret; |
| 173 } | 173 } |
| 174 | 174 |
| 175 // TODO(jacobr): do not use the same LazyJSType object for anonymous JS types | 175 // TODO(jacobr): do not use the same LazyJSType object for anonymous JS types |
| 176 // from different libraries. | 176 // from different libraries. |
| 177 lazyAnonymousJSType(name) { | 177 lazyAnonymousJSType(name) { |
| 178 if (JS('bool', '#.has(#)', _lazyJSTypes, name)) { | 178 if (JS('bool', '#.has(#)', _lazyJSTypes, name)) { |
| 179 return JS('', '#.get(#)', _lazyJSTypes, name); | 179 return JS('', '#.get(#)', _lazyJSTypes, name); |
| 180 } | 180 } |
| 181 var ret = JS('', 'new #(null, #)', LazyJSType, name); | 181 var ret = new LazyJSType(null, name); |
| 182 JS('', '#.set(#, #)', _lazyJSTypes, name, ret); | 182 JS('', '#.set(#, #)', _lazyJSTypes, name, ret); |
| 183 return ret; | 183 return ret; |
| 184 } | 184 } |
| 185 | 185 |
| 186 /// Given a WrappedType, return the internal runtime type object. | 186 /// Given a WrappedType, return the internal runtime type object. |
| 187 unwrapType(WrappedType obj) => obj._wrappedType; | 187 unwrapType(WrappedType obj) => obj._wrappedType; |
| 188 | 188 |
| 189 _getRuntimeType(value) => JS('', '#[#]', value, _runtimeType); | 189 _getRuntimeType(value) => JS('', '#[#]', value, _runtimeType); |
| 190 | 190 |
| 191 /// Return the module name for a raw library object. | 191 /// Return the module name for a raw library object. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 222 if (module == null) return null; | 222 if (module == null) return null; |
| 223 JS('', '#[#] = #', module, _moduleName, name); | 223 JS('', '#[#] = #', module, _moduleName, name); |
| 224 return module; | 224 return module; |
| 225 } | 225 } |
| 226 | 226 |
| 227 /// Track all libraries | 227 /// Track all libraries |
| 228 void trackLibraries(String moduleName, libraries, sourceMap) { | 228 void trackLibraries(String moduleName, libraries, sourceMap) { |
| 229 JS('', '#.set(#, #)', _loadedSourceMaps, moduleName, sourceMap); | 229 JS('', '#.set(#, #)', _loadedSourceMaps, moduleName, sourceMap); |
| 230 JS('', '#.set(#, #)', _loadedModules, moduleName, libraries); | 230 JS('', '#.set(#, #)', _loadedModules, moduleName, libraries); |
| 231 } | 231 } |
| OLD | NEW |