| 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 runtime operations on objects used by the code | 5 /// This library defines runtime operations on objects used by the code |
| 6 /// generator. | 6 /// generator. |
| 7 part of dart._runtime; | 7 part of dart._runtime; |
| 8 | 8 |
| 9 class InvocationImpl extends Invocation { | 9 class InvocationImpl extends Invocation { |
| 10 final Symbol memberName; | 10 final Symbol memberName; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 if (f != null) { | 39 if (f != null) { |
| 40 var type = getType(obj); | 40 var type = getType(obj); |
| 41 | 41 |
| 42 if (hasField(type, f) || hasGetter(type, f)) return JS('', '#[#]', obj, f); | 42 if (hasField(type, f) || hasGetter(type, f)) return JS('', '#[#]', obj, f); |
| 43 if (hasMethod(type, f)) return bind(obj, f, JS('', 'void 0')); | 43 if (hasMethod(type, f)) return bind(obj, f, JS('', 'void 0')); |
| 44 } | 44 } |
| 45 return noSuchMethod( | 45 return noSuchMethod( |
| 46 obj, new InvocationImpl(field, JS('', '[]'), isGetter: true)); | 46 obj, new InvocationImpl(field, JS('', '[]'), isGetter: true)); |
| 47 } | 47 } |
| 48 | 48 |
| 49 _stripGenericArguments(type) { |
| 50 var genericClass = getGenericClass(type); |
| 51 if (genericClass != null) return JS('', '#()', genericClass); |
| 52 return type; |
| 53 } |
| 54 |
| 55 // Version of dput that matches legacy Dart 1 type check rules. |
| 56 // TODO(jacobr): remove this temporary workaround when mirrors based |
| 57 // PageLoader code can generate the correct reified generic types. |
| 58 dputLegacy(obj, field, value) { |
| 59 var f = _canonicalMember(obj, field); |
| 60 _trackCall(obj); |
| 61 if (f != null) { |
| 62 var objType = getType(obj); |
| 63 var setterType = getSetterType(objType, f); |
| 64 if (JS('bool', '# != void 0', setterType)) { |
| 65 return JS('', '#[#] = #', obj, f, check(value, _stripGenericArguments(JS(
'', '#.args[0]', setterType)))); |
| 66 } else { |
| 67 var fieldType = getFieldType(objType, f); |
| 68 // TODO(jacobr): add metadata tracking which fields are final and throw |
| 69 // if a setter is called on a final field. |
| 70 if (JS('bool', '# != void 0', fieldType)) { |
| 71 return JS('', '#[#] = #', obj, f, check(value, _stripGenericArguments(fi
eldType))); |
| 72 } |
| 73 } |
| 74 } |
| 75 return noSuchMethod( |
| 76 obj, new InvocationImpl(field, JS('', '[#]', value), isSetter: true)); |
| 77 } |
| 78 |
| 49 dput(obj, field, value) { | 79 dput(obj, field, value) { |
| 50 var f = _canonicalMember(obj, field); | 80 var f = _canonicalMember(obj, field); |
| 51 _trackCall(obj); | 81 _trackCall(obj); |
| 52 if (f != null) { | 82 if (f != null) { |
| 53 var objType = getType(obj); | 83 var objType = getType(obj); |
| 54 var setterType = getSetterType(objType, f); | 84 var setterType = getSetterType(objType, f); |
| 55 if (JS('bool', '# != void 0', setterType)) { | 85 if (JS('bool', '# != void 0', setterType)) { |
| 56 // TODO(jacobr): throw a type error instead of a NoSuchMethodError if | 86 return JS('', '#[#] = #', obj, f, check(value, JS('', '#.args[0]', setter
Type))); |
| 57 // the type of the setter doesn't match. | |
| 58 if (instanceOfOrNull(value, JS('', '#.args[0]', setterType))) { | |
| 59 return JS('', '#[#] = #', obj, f, value); | |
| 60 } | |
| 61 } else { | 87 } else { |
| 62 var fieldType = getFieldType(objType, f); | 88 var fieldType = getFieldType(objType, f); |
| 63 // TODO(jacobr): add metadata tracking which fields are final and throw | 89 // TODO(jacobr): add metadata tracking which fields are final and throw |
| 64 // if a setter is called on a final field. | 90 // if a setter is called on a final field. |
| 65 if (JS('bool', '# != void 0', fieldType)) { | 91 if (JS('bool', '# != void 0', fieldType)) { |
| 66 // TODO(jacobr): throw a type error instead of a NoSuchMethodError if | 92 return JS('', '#[#] = #', obj, f, check(value, fieldType)); |
| 67 // the type of the field doesn't match. | |
| 68 if (instanceOfOrNull(value, fieldType)) { | |
| 69 return JS('', '#[#] = #', obj, f, value); | |
| 70 } | |
| 71 } | 93 } |
| 72 } | 94 } |
| 73 } | 95 } |
| 74 return noSuchMethod( | 96 return noSuchMethod( |
| 75 obj, new InvocationImpl(field, JS('', '[#]', value), isSetter: true)); | 97 obj, new InvocationImpl(field, JS('', '[#]', value), isSetter: true)); |
| 76 } | 98 } |
| 77 | 99 |
| 78 /// Check that a function of a given type can be applied to | 100 /// Check that a function of a given type can be applied to |
| 79 /// actuals. | 101 /// actuals. |
| 80 _checkApply(type, actuals) => JS( | 102 _checkApply(type, actuals) => JS( |
| (...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 name = '+' + name; | 924 name = '+' + name; |
| 903 } | 925 } |
| 904 return name; | 926 return name; |
| 905 } | 927 } |
| 906 | 928 |
| 907 /// Emulates the implicit "loadLibrary" function provided by a deferred library. | 929 /// Emulates the implicit "loadLibrary" function provided by a deferred library. |
| 908 /// | 930 /// |
| 909 /// Libraries are not actually deferred in DDC, so this just returns a future | 931 /// Libraries are not actually deferred in DDC, so this just returns a future |
| 910 /// that completes immediately. | 932 /// that completes immediately. |
| 911 Future loadLibrary() => new Future.value(); | 933 Future loadLibrary() => new Future.value(); |
| OLD | NEW |