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 dartLibraryName = JS('', 'Symbol("dartLibraryName")'); |
| 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 getDartLibraryName(value) => JS('', '#[#]', value, dartLibraryName); |
191 // and get rid of the call to dart_library in the JS here. | |
192 getDartLibraryName(value) => JS('', '#[dart_library.dartLibraryName]', value); | |
193 | 193 |
194 /// Tag the runtime type of [value] to be type [t]. | 194 /// Tag the runtime type of [value] to be type [t]. |
195 void tag(value, t) { | 195 void tag(value, t) { |
196 JS('', '#[#] = #', value, _runtimeType, t); | 196 JS('', '#[#] = #', value, _runtimeType, t); |
197 } | 197 } |
198 | 198 |
199 void tagComputed(value, compute) { | 199 void tagComputed(value, compute) { |
200 JS('', '#(#, #, { get: # })', defineProperty, value, _runtimeType, compute); | 200 JS('', '#(#, #, { get: # })', defineProperty, value, _runtimeType, compute); |
201 } | 201 } |
202 | 202 |
203 void tagLazy(value, compute) { | 203 void tagLazy(value, compute) { |
204 JS('', '#(#, #, { get: # })', defineLazyProperty, value, _runtimeType, | 204 JS('', '#(#, #, { get: # })', defineLazyProperty, value, _runtimeType, |
205 compute); | 205 compute); |
206 } | 206 } |
OLD | NEW |