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 var dart, _js_helper; | 5 var dart, _js_helper; |
6 (function (dart) { | 6 (function (dart) { |
7 'use strict'; | 7 'use strict'; |
8 | 8 |
9 let defineProperty = Object.defineProperty; | 9 let defineProperty = Object.defineProperty; |
10 let getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; | 10 let getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; |
(...skipping 18 matching lines...) Expand all Loading... |
29 args.push(name); | 29 args.push(name); |
30 }); | 30 }); |
31 } | 31 } |
32 return args; | 32 return args; |
33 } | 33 } |
34 | 34 |
35 function dload(obj, field) { | 35 function dload(obj, field) { |
36 if (!(field in obj)) { | 36 if (!(field in obj)) { |
37 throw new core.NoSuchMethodError(obj, field); | 37 throw new core.NoSuchMethodError(obj, field); |
38 } | 38 } |
39 return obj[field]; | 39 var result = obj[field]; |
| 40 if (typeof result == "function") { |
| 41 // We can't tell if the result needs binding. Fortunately binding the |
| 42 // same function twice has no effect, so we can simply attempt to bind. |
| 43 return result.bind(obj); |
| 44 } |
| 45 return result; |
40 } | 46 } |
41 dart.dload = dload; | 47 dart.dload = dload; |
42 | 48 |
43 // TODO(jmesserly): this should call noSuchMethod, not throw. | 49 // TODO(jmesserly): this should call noSuchMethod, not throw. |
44 function throwNoSuchMethod(obj, name, args, opt_func) { | 50 function throwNoSuchMethod(obj, name, args, opt_func) { |
45 if (obj === void 0) obj = opt_func; | 51 if (obj === void 0) obj = opt_func; |
46 throw new core.NoSuchMethodError(obj, name, args); | 52 throw new core.NoSuchMethodError(obj, name, args); |
47 } | 53 } |
48 | 54 |
49 function checkAndCall(f, obj, args, name) { | 55 function checkAndCall(f, obj, args, name) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } | 97 } |
92 return checkAndCall(obj.get, obj, [index], '[]'); | 98 return checkAndCall(obj.get, obj, [index], '[]'); |
93 } | 99 } |
94 dart.dindex = dindex; | 100 dart.dindex = dindex; |
95 | 101 |
96 function dsetindex(obj, index, value) { | 102 function dsetindex(obj, index, value) { |
97 return checkAndCall(obj.set, obj, [index, value], '[]='); | 103 return checkAndCall(obj.set, obj, [index, value], '[]='); |
98 } | 104 } |
99 dart.dsetindex = dsetindex; | 105 dart.dsetindex = dsetindex; |
100 | 106 |
| 107 /** |
| 108 * Returns bound `method`. |
| 109 * This helper function avoids needing a temp for `obj`. |
| 110 */ |
| 111 function bind(obj, method) { |
| 112 // This is a static bind (dynamic would use `dload`) so no need to check |
| 113 // if `method` is really there on `obj`.` |
| 114 return obj[method].bind(obj); |
| 115 } |
| 116 dart.bind = bind; |
| 117 |
101 function cast(obj, type) { | 118 function cast(obj, type) { |
102 // TODO(vsm): handle non-nullable types | 119 // TODO(vsm): handle non-nullable types |
103 if (obj == null) return obj; | 120 if (obj == null) return obj; |
104 let actual = getRuntimeType(obj); | 121 let actual = getRuntimeType(obj); |
105 if (isSubtype(actual, type)) return obj; | 122 if (isSubtype(actual, type)) return obj; |
106 throw new _js_helper.CastErrorImplementation(actual, type); | 123 throw new _js_helper.CastErrorImplementation(actual, type); |
107 } | 124 } |
108 dart.as = cast; | 125 dart.as = cast; |
109 | 126 |
110 | 127 |
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 dart.void = { toString() { return 'void'; } }; | 804 dart.void = { toString() { return 'void'; } }; |
788 dart.bottom = { toString() { return 'bottom'; } }; | 805 dart.bottom = { toString() { return 'bottom'; } }; |
789 | 806 |
790 dart.JsSymbol = Symbol; | 807 dart.JsSymbol = Symbol; |
791 | 808 |
792 // TODO(jmesserly): hack to bootstrap the SDK | 809 // TODO(jmesserly): hack to bootstrap the SDK |
793 _js_helper = _js_helper || {}; | 810 _js_helper = _js_helper || {}; |
794 _js_helper.checkNum = notNull; | 811 _js_helper.checkNum = notNull; |
795 | 812 |
796 })(dart || (dart = {})); | 813 })(dart || (dart = {})); |
OLD | NEW |