| 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 operations that define and manipulate Dart | 5 /// This library defines the operations that define and manipulate Dart |
| 6 /// classes. Included in this are: | 6 /// classes. Included in this are: |
| 7 /// - Generics | 7 /// - Generics |
| 8 /// - Class metadata | 8 /// - Class metadata |
| 9 /// - Extension methods | 9 /// - Extension methods |
| 10 /// | 10 /// |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 196 |
| 197 getGenericTypeCtor(value) => JS('', '#[#]', value, _genericTypeCtor); | 197 getGenericTypeCtor(value) => JS('', '#[#]', value, _genericTypeCtor); |
| 198 | 198 |
| 199 /// Get the type of a method from an object using the stored signature | 199 /// Get the type of a method from an object using the stored signature |
| 200 getType(obj) => JS( | 200 getType(obj) => JS( |
| 201 '', | 201 '', |
| 202 '''(() => { | 202 '''(() => { |
| 203 return $obj == null ? $Object : $obj.__proto__.constructor; | 203 return $obj == null ? $Object : $obj.__proto__.constructor; |
| 204 })()'''); | 204 })()'''); |
| 205 | 205 |
| 206 bool isJsInterop(obj) { |
| 207 if (JS('bool', 'typeof # === "function"', obj)) { |
| 208 // A function is a Dart function if it has runtime type information. |
| 209 return _getRuntimeType(obj) == null; |
| 210 } |
| 211 // Primitive types are not JS interop types. |
| 212 if (JS('bool', 'typeof # !== "object"', obj)) return false; |
| 213 |
| 214 // Extension types are not considered JS interop types. |
| 215 // Note that it is still possible to call typed JS interop methods on |
| 216 // extension types but the calls must be statically typed. |
| 217 if (getExtensionType(obj) != null) return false; |
| 218 return JS('bool', '!($obj instanceof $Object)'); |
| 219 } |
| 220 |
| 206 /// Get the type of a method from a type using the stored signature | 221 /// Get the type of a method from a type using the stored signature |
| 207 getMethodType(type, name) => JS( | 222 getMethodType(type, name) => JS( |
| 208 '', | 223 '', |
| 209 '''(() => { | 224 '''(() => { |
| 210 let sigObj = $type[$_methodSig]; | 225 let sigObj = $type[$_methodSig]; |
| 211 if (sigObj === void 0) return void 0; | 226 if (sigObj === void 0) return void 0; |
| 212 return sigObj[$name]; | 227 return sigObj[$name]; |
| 213 })()'''); | 228 })()'''); |
| 214 | 229 |
| 215 getFieldType(type, name) => JS( | 230 getFieldType(type, name) => JS( |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 '''(() => { | 634 '''(() => { |
| 620 let values = []; | 635 let values = []; |
| 621 for (var i = 0; i < $names.length; i++) { | 636 for (var i = 0; i < $names.length; i++) { |
| 622 let value = $const_(new $enumClass(i)); | 637 let value = $const_(new $enumClass(i)); |
| 623 values.push(value); | 638 values.push(value); |
| 624 Object.defineProperty($enumClass, $names[i], | 639 Object.defineProperty($enumClass, $names[i], |
| 625 { value: value, configurable: true }); | 640 { value: value, configurable: true }); |
| 626 } | 641 } |
| 627 $enumClass.values = $constList(values, $enumClass); | 642 $enumClass.values = $constList(values, $enumClass); |
| 628 })()'''); | 643 })()'''); |
| OLD | NEW |