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/_operations', null, /* Imports */[ | 8 dart_library.library('dart/_operations', null, /* Imports */[ |
9 ], /* Lazy Imports */[ | 9 ], /* Lazy Imports */[ |
10 'dart/_utils', | 10 'dart/_utils', |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 96 } |
97 return true; | 97 return true; |
98 } | 98 } |
99 | 99 |
100 function throwNoSuchMethod(obj, name, args, opt_func) { | 100 function throwNoSuchMethod(obj, name, args, opt_func) { |
101 if (obj === void 0) obj = opt_func; | 101 if (obj === void 0) obj = opt_func; |
102 errors.throwNoSuchMethod(obj, name, args); | 102 errors.throwNoSuchMethod(obj, name, args); |
103 } | 103 } |
104 | 104 |
105 function checkAndCall(f, ftype, obj, args, name) { | 105 function checkAndCall(f, ftype, obj, args, name) { |
| 106 let originalFunction = f; |
106 if (!(f instanceof Function)) { | 107 if (!(f instanceof Function)) { |
107 // We're not a function (and hence not a method either) | 108 // We're not a function (and hence not a method either) |
108 // Grab the `call` method if it's not a function. | 109 // Grab the `call` method if it's not a function. |
109 if (f != null) { | 110 if (f != null) { |
110 ftype = classes.getMethodType(f, 'call'); | 111 ftype = classes.getMethodType(f, 'call'); |
111 f = f.call; | 112 f = f.call; |
112 } | 113 } |
113 if (!(f instanceof Function)) { | 114 if (!(f instanceof Function)) { |
114 throwNoSuchMethod(obj, name, args); | 115 throwNoSuchMethod(obj, name, args, originalFunction); |
115 } | 116 } |
116 } | 117 } |
117 // If f is a function, but not a method (no method type) | 118 // If f is a function, but not a method (no method type) |
118 // then it should have been a function valued field, so | 119 // then it should have been a function valued field, so |
119 // get the type from the function. | 120 // get the type from the function. |
120 if (ftype === void 0) { | 121 if (ftype === void 0) { |
121 ftype = rtti.read(f); | 122 ftype = rtti.read(f); |
122 } | 123 } |
123 | 124 |
124 if (!ftype) { | 125 if (!ftype) { |
125 // TODO(leafp): Allow JS objects to go through? | 126 // TODO(leafp): Allow JS objects to go through? |
126 // This includes the DOM. | 127 // This includes the DOM. |
127 return f.apply(obj, args); | 128 return f.apply(obj, args); |
128 } | 129 } |
129 | 130 |
130 if (checkApply(ftype, args)) { | 131 if (checkApply(ftype, args)) { |
131 return f.apply(obj, args); | 132 return f.apply(obj, args); |
132 } | 133 } |
133 | 134 |
134 // TODO(leafp): throw a type error (rather than NSM) | 135 // TODO(leafp): throw a type error (rather than NSM) |
135 // if the arity matches but the types are wrong. | 136 // if the arity matches but the types are wrong. |
136 throwNoSuchMethod(obj, name, args, f); | 137 throwNoSuchMethod(obj, name, args, originalFunction); |
137 } | 138 } |
138 | 139 |
139 function dcall(f, ...args) { | 140 function dcall(f, ...args) { |
140 let ftype = rtti.read(f); | 141 let ftype = rtti.read(f); |
141 return checkAndCall(f, ftype, void 0, args, 'call'); | 142 return checkAndCall(f, ftype, void 0, args, 'call'); |
142 } | 143 } |
143 exports.dcall = dcall; | 144 exports.dcall = dcall; |
144 | 145 |
145 /** Shared code for dsend, dindex, and dsetindex. */ | 146 /** Shared code for dsend, dindex, and dsetindex. */ |
146 function callMethod(obj, name, args, displayName) { | 147 function callMethod(obj, name, args, displayName) { |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 next() { | 458 next() { |
458 let i = this.dartIterator; | 459 let i = this.dartIterator; |
459 let done = !i.moveNext(); | 460 let done = !i.moveNext(); |
460 return { done: done, value: done ? void 0 : i.current }; | 461 return { done: done, value: done ? void 0 : i.current }; |
461 } | 462 } |
462 } | 463 } |
463 exports.JsIterator = JsIterator; | 464 exports.JsIterator = JsIterator; |
464 | 465 |
465 | 466 |
466 }); | 467 }); |
OLD | NEW |