| 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 */ | 7 */ |
| 8 dart_library.library('dart_runtime/_operations', null, /* Imports */[ | 8 dart_library.library('dart_runtime/_operations', null, /* Imports */[ |
| 9 ], /* Lazy Imports */[ | 9 ], /* Lazy Imports */[ |
| 10 'dart/async', | 10 'dart/async', |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 function dcall(f/*, ...args*/) { | 145 function dcall(f/*, ...args*/) { |
| 146 let args = slice.call(arguments, 1); | 146 let args = slice.call(arguments, 1); |
| 147 let ftype = rtti.read(f); | 147 let ftype = rtti.read(f); |
| 148 return checkAndCall(f, ftype, void 0, args, 'call'); | 148 return checkAndCall(f, ftype, void 0, args, 'call'); |
| 149 } | 149 } |
| 150 exports.dcall = dcall; | 150 exports.dcall = dcall; |
| 151 | 151 |
| 152 /** Shared code for dsend, dindex, and dsetindex. */ | 152 /** Shared code for dsend, dindex, and dsetindex. */ |
| 153 function callMethod(obj, name, args, displayName) { | 153 function callMethod(obj, name, args, displayName) { |
| 154 let symbol = _canonicalFieldName(obj, name, args, displayName); | 154 let symbol = _canonicalFieldName(obj, name, args, displayName); |
| 155 let f = obj[symbol]; | 155 let f = obj != null ? obj[symbol] : null; |
| 156 let ftype = classes.getMethodType(obj, name); | 156 let ftype = classes.getMethodType(obj, name); |
| 157 return checkAndCall(f, ftype, obj, args, displayName); | 157 return checkAndCall(f, ftype, obj, args, displayName); |
| 158 } | 158 } |
| 159 | 159 |
| 160 function dsend(obj, method/*, ...args*/) { | 160 function dsend(obj, method/*, ...args*/) { |
| 161 return callMethod(obj, method, slice.call(arguments, 2)); | 161 return callMethod(obj, method, slice.call(arguments, 2), method); |
| 162 } | 162 } |
| 163 exports.dsend = dsend; | 163 exports.dsend = dsend; |
| 164 | 164 |
| 165 function dindex(obj, index) { | 165 function dindex(obj, index) { |
| 166 return callMethod(obj, 'get', [index], '[]'); | 166 return callMethod(obj, 'get', [index], '[]'); |
| 167 } | 167 } |
| 168 exports.dindex = dindex; | 168 exports.dindex = dindex; |
| 169 | 169 |
| 170 function dsetindex(obj, index, value) { | 170 function dsetindex(obj, index, value) { |
| 171 return callMethod(obj, 'set', [index, value], '[]='); | 171 return callMethod(obj, 'set', [index, value], '[]='); |
| 172 } | 172 } |
| 173 exports.dsetindex = dsetindex; | 173 exports.dsetindex = dsetindex; |
| 174 | 174 |
| 175 function _ignoreTypeFailure(actual, type) { | 175 function _ignoreTypeFailure(actual, type) { |
| 176 // TODO(vsm): Remove this hack ... | 176 // TODO(vsm): Remove this hack ... |
| 177 // This is primarily due to the lack of generic methods, | 177 // This is primarily due to the lack of generic methods, |
| 178 // but we need to triage all the errors. | 178 // but we need to triage all the errors. |
| 179 let isSubtype = types.isSubtype; | 179 let isSubtype = types.isSubtype; |
| 180 if (isSubtype(type, core.Iterable) && isSubtype(actual, core.Iterable) || | 180 if (isSubtype(type, core.Iterable) && isSubtype(actual, core.Iterable) || |
| 181 isSubtype(type, async.Future) && isSubtype(actual, async.Future) || | 181 isSubtype(type, async.Future) && isSubtype(actual, async.Future) || |
| 182 isSubtype(type, core.Map) && isSubtype(actual, core.Map) || | 182 isSubtype(type, core.Map) && isSubtype(actual, core.Map) || |
| 183 isSubtype(type, core.Function) && isSubtype(actual, core.Function)) { | 183 isSubtype(type, core.Function) && isSubtype(actual, core.Function) || |
| 184 console.error('Ignoring cast fail from ' + types.typeName(actual) + | 184 isSubtype(type, async.Stream) && isSubtype(actual, async.Stream) || |
| 185 isSubtype(type, async.StreamSubscription) && |
| 186 isSubtype(actual, async.StreamSubscription)) { |
| 187 console.warn('Ignoring cast fail from ' + types.typeName(actual) + |
| 185 ' to ' + types.typeName(type)); | 188 ' to ' + types.typeName(type)); |
| 186 return true; | 189 return true; |
| 187 } | 190 } |
| 188 return false; | 191 return false; |
| 189 } | 192 } |
| 190 | 193 |
| 191 function instanceOf(obj, type) { | 194 function instanceOf(obj, type) { |
| 192 return types.isSubtype(rtti.realRuntimeType(obj), type); | 195 return types.isSubtype(rtti.realRuntimeType(obj), type); |
| 193 } | 196 } |
| 194 exports.instanceOf = instanceOf; | 197 exports.instanceOf = instanceOf; |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 next() { | 414 next() { |
| 412 let i = this.dartIterator; | 415 let i = this.dartIterator; |
| 413 let done = !i.moveNext(); | 416 let done = !i.moveNext(); |
| 414 return { done: done, value: done ? void 0 : i.current }; | 417 return { done: done, value: done ? void 0 : i.current }; |
| 415 } | 418 } |
| 416 } | 419 } |
| 417 exports.JsIterator = JsIterator; | 420 exports.JsIterator = JsIterator; |
| 418 | 421 |
| 419 | 422 |
| 420 }); | 423 }); |
| OLD | NEW |