| 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 return closure; | 67 return closure; |
| 68 } | 68 } |
| 69 | 69 |
| 70 lazyFn(closure, computeType) { | 70 lazyFn(closure, computeType) { |
| 71 tagLazy(closure, computeType); | 71 tagLazy(closure, computeType); |
| 72 return closure; | 72 return closure; |
| 73 } | 73 } |
| 74 | 74 |
| 75 // TODO(vsm): How should we encode the runtime type? | 75 // TODO(vsm): How should we encode the runtime type? |
| 76 final _runtimeType = JS('', 'Symbol("_runtimeType")'); | 76 final _runtimeType = JS('', 'Symbol("_runtimeType")'); |
| 77 final isNamedConstructor = JS('', 'Symbol("isNamedConstructor")'); |
| 77 | 78 |
| 78 _checkPrimitiveType(obj) { | 79 _checkPrimitiveType(obj) { |
| 79 // 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 |
| 80 // 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 |
| 81 // 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 |
| 82 // 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 |
| 83 // special functions, we could do the same.) | 84 // special functions, we could do the same.) |
| 84 | 85 |
| 85 // Check for null and undefined | 86 // Check for null and undefined |
| 86 if (obj == null) return JS('', '#', Null); | 87 if (obj == null) return JS('', '#', Null); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 107 | 108 |
| 108 return null; | 109 return null; |
| 109 } | 110 } |
| 110 | 111 |
| 111 getFunctionType(obj) { | 112 getFunctionType(obj) { |
| 112 // TODO(vsm): Encode this properly on the function for Dart-generated code. | 113 // TODO(vsm): Encode this properly on the function for Dart-generated code. |
| 113 var args = JS('', 'Array(#.length).fill(#)', obj, dynamic); | 114 var args = JS('', 'Array(#.length).fill(#)', obj, dynamic); |
| 114 return definiteFunctionType(bottom, args, JS('', 'void 0')); | 115 return definiteFunctionType(bottom, args, JS('', 'void 0')); |
| 115 } | 116 } |
| 116 | 117 |
| 117 /// Returns an the runtime representation of the type of obj. | 118 /// Returns the runtime representation of the type of obj. |
| 118 /// | 119 /// |
| 119 /// The resulting object is used internally for runtime type checking. This is | 120 /// The resulting object is used internally for runtime type checking. This is |
| 120 /// different from the user-visible Type object returned by calling | 121 /// different from the user-visible Type object returned by calling |
| 121 /// `runtimeType` on some Dart object. | 122 /// `runtimeType` on some Dart object. |
| 122 getReifiedType(obj) { | 123 getReifiedType(obj) { |
| 123 var result = _checkPrimitiveType(obj); | 124 var result = _checkPrimitiveType(obj); |
| 124 if (result != null) return result; | 125 if (result != null) return result; |
| 125 return _nonPrimitiveRuntimeType(obj); | 126 return _nonPrimitiveRuntimeType(obj); |
| 126 } | 127 } |
| 127 | 128 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 157 if (JS('bool', '#.hasOwnProperty(#)', type, _typeObject)) { | 158 if (JS('bool', '#.hasOwnProperty(#)', type, _typeObject)) { |
| 158 return JS('', '#[#]', type, _typeObject); | 159 return JS('', '#[#]', type, _typeObject); |
| 159 } | 160 } |
| 160 return JS('', '#[#] = new #(#)', type, _typeObject, WrappedType, type); | 161 return JS('', '#[#] = new #(#)', type, _typeObject, WrappedType, type); |
| 161 } | 162 } |
| 162 | 163 |
| 163 /// Given a WrappedType, return the internal runtime type object. | 164 /// Given a WrappedType, return the internal runtime type object. |
| 164 unwrapType(obj) => obj._wrappedType; | 165 unwrapType(obj) => obj._wrappedType; |
| 165 | 166 |
| 166 _getRuntimeType(value) => JS('', '#[#]', value, _runtimeType); | 167 _getRuntimeType(value) => JS('', '#[#]', value, _runtimeType); |
| 168 getIsNamedConstructor(value) => JS('', '#[#]', value, isNamedConstructor); |
| 169 // 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. |
| 171 getDartLibraryName(value) => JS('', '#[dart_library.dartLibraryName]', value); |
| 167 | 172 |
| 168 /// Tag the runtime type of [value] to be type [t]. | 173 /// Tag the runtime type of [value] to be type [t]. |
| 169 void tag(value, t) { | 174 void tag(value, t) { |
| 170 JS('', '#[#] = #', value, _runtimeType, t); | 175 JS('', '#[#] = #', value, _runtimeType, t); |
| 171 } | 176 } |
| 172 | 177 |
| 173 void tagComputed(value, compute) { | 178 void tagComputed(value, compute) { |
| 174 JS('', '#(#, #, { get: # })', defineProperty, value, _runtimeType, compute); | 179 JS('', '#(#, #, { get: # })', defineProperty, value, _runtimeType, compute); |
| 175 } | 180 } |
| 176 | 181 |
| 177 void tagLazy(value, compute) { | 182 void tagLazy(value, compute) { |
| 178 JS('', '#(#, #, { get: # })', | 183 JS('', '#(#, #, { get: # })', |
| 179 defineLazyProperty, value, _runtimeType, compute); | 184 defineLazyProperty, value, _runtimeType, compute); |
| 180 } | 185 } |
| OLD | NEW |