| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 } | 51 } |
| 52 | 52 |
| 53 /// Check that a function of a given type can be applied to | 53 /// Check that a function of a given type can be applied to |
| 54 /// actuals. | 54 /// actuals. |
| 55 _checkApply(type, actuals) => JS( | 55 _checkApply(type, actuals) => JS( |
| 56 '', | 56 '', |
| 57 '''(() => { | 57 '''(() => { |
| 58 if ($actuals.length < $type.args.length) return false; | 58 if ($actuals.length < $type.args.length) return false; |
| 59 let index = 0; | 59 let index = 0; |
| 60 for(let i = 0; i < $type.args.length; ++i) { | 60 for(let i = 0; i < $type.args.length; ++i) { |
| 61 if (!$instanceOfOrNull($actuals[i], $type.args[i])) return false; | 61 $check($actuals[i], $type.args[i]); |
| 62 ++index; | 62 ++index; |
| 63 } | 63 } |
| 64 if ($actuals.length == $type.args.length) return true; | 64 if ($actuals.length == $type.args.length) return true; |
| 65 let extras = $actuals.length - $type.args.length; | 65 let extras = $actuals.length - $type.args.length; |
| 66 if ($type.optionals.length > 0) { | 66 if ($type.optionals.length > 0) { |
| 67 if (extras > $type.optionals.length) return false; | 67 if (extras > $type.optionals.length) return false; |
| 68 for(let i = 0, j=index; i < extras; ++i, ++j) { | 68 for(let i = 0, j=index; i < extras; ++i, ++j) { |
| 69 if (!$instanceOfOrNull($actuals[j], $type.optionals[i])) return false; | 69 $check($actuals[j], $type.optionals[i]); |
| 70 } | 70 } |
| 71 return true; | 71 return true; |
| 72 } | 72 } |
| 73 // TODO(leafp): We can't tell when someone might be calling | 73 // TODO(leafp): We can't tell when someone might be calling |
| 74 // something expecting an optional argument with named arguments | 74 // something expecting an optional argument with named arguments |
| 75 | 75 |
| 76 if (extras != 1) return false; | 76 if (extras != 1) return false; |
| 77 // An empty named list means no named arguments | 77 // An empty named list means no named arguments |
| 78 if ($getOwnPropertyNames($type.named).length == 0) return false; | 78 if ($getOwnPropertyNames($type.named).length == 0) return false; |
| 79 let opts = $actuals[index]; | 79 let opts = $actuals[index]; |
| 80 let names = $getOwnPropertyNames(opts); | 80 let names = $getOwnPropertyNames(opts); |
| 81 // Type is something other than a map | 81 // Type is something other than a map |
| 82 if (names.length == 0) return false; | 82 if (names.length == 0) return false; |
| 83 for (var name of names) { | 83 for (var name of names) { |
| 84 if (!($hasOwnProperty.call($type.named, name))) { | 84 if (!($hasOwnProperty.call($type.named, name))) { |
| 85 return false; | 85 return false; |
| 86 } | 86 } |
| 87 if (!$instanceOfOrNull(opts[name], $type.named[name])) return false; | 87 $check(opts[name], $type.named[name]); |
| 88 } | 88 } |
| 89 return true; | 89 return true; |
| 90 })()'''); | 90 })()'''); |
| 91 | 91 |
| 92 Symbol _dartSymbol(name) => | 92 Symbol _dartSymbol(name) => |
| 93 JS('', '#(#.new(#.toString()))', const_, Symbol, name); | 93 JS('', '#(#.new(#.toString()))', const_, Symbol, name); |
| 94 | 94 |
| 95 /// Extracts the named argument array from a list of arguments, and returns it. | 95 /// Extracts the named argument array from a list of arguments, and returns it. |
| 96 // TODO(jmesserly): we need to handle named arguments better. | 96 // TODO(jmesserly): we need to handle named arguments better. |
| 97 extractNamedArgs(args) { | 97 extractNamedArgs(args) { |
| (...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 name = '+' + name; | 841 name = '+' + name; |
| 842 } | 842 } |
| 843 return name; | 843 return name; |
| 844 } | 844 } |
| 845 | 845 |
| 846 /// Emulates the implicit "loadLibrary" function provided by a deferred library. | 846 /// Emulates the implicit "loadLibrary" function provided by a deferred library. |
| 847 /// | 847 /// |
| 848 /// Libraries are not actually deferred in DDC, so this just returns a future | 848 /// Libraries are not actually deferred in DDC, so this just returns a future |
| 849 /// that completes immediately. | 849 /// that completes immediately. |
| 850 Future loadLibrary() => new Future.value(); | 850 Future loadLibrary() => new Future.value(); |
| OLD | NEW |