Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: lib/runtime/dart_runtime.js

Issue 1142293002: Use dart.tearoff helper at tearoff sites (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Use dart.bind instead of dart.tearoff Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/runtime/dart/core.js ('k') | lib/src/codegen/js_codegen.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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, _js_primitives; 5 var dart, _js_helper, _js_primitives;
6 (function (dart) { 6 (function (dart) {
7 'use strict'; 7 'use strict';
8 8
9 // TODO(vsm): This is referenced (as init.globalState) from 9 // TODO(vsm): This is referenced (as init.globalState) from
10 // isolate_helper.dart. Where should it go? 10 // isolate_helper.dart. Where should it go?
(...skipping 26 matching lines...) Expand all
37 arg.replace(FN_ARG, function(all, underscore, name){ 37 arg.replace(FN_ARG, function(all, underscore, name){
38 args.push(name); 38 args.push(name);
39 }); 39 });
40 } 40 }
41 return args; 41 return args;
42 } 42 }
43 43
44 function dload(obj, field) { 44 function dload(obj, field) {
45 field = _canonicalFieldName(obj, field); 45 field = _canonicalFieldName(obj, field);
46 if (_getMethodType(obj, field) !== void 0) { 46 if (_getMethodType(obj, field) !== void 0) {
47 return dart.tearoff(obj, field); 47 return dart.bind(obj, field);
48 } 48 }
49 // TODO(vsm): Implement NSM robustly. An 'in' check breaks on certain 49 // TODO(vsm): Implement NSM robustly. An 'in' check breaks on certain
50 // types. hasOwnProperty doesn't chase the proto chain. 50 // types. hasOwnProperty doesn't chase the proto chain.
51 // Also, do we want an NSM on regular JS objects? 51 // Also, do we want an NSM on regular JS objects?
52 // See: https://github.com/dart-lang/dev_compiler/issues/169 52 // See: https://github.com/dart-lang/dev_compiler/issues/169
53 var result = obj[field]; 53 var result = obj[field];
54 54
55 // TODO(leafp): Decide whether to keep this for javascript 55 // TODO(leafp): Decide whether to keep this for javascript
56 // objects, or just use the javascript semantics. 56 // objects, or just use the javascript semantics.
57 if (typeof result == "function" && 57 if (typeof result == "function" &&
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } 147 }
148 return checkAndCall(obj.get, obj, [index], '[]'); 148 return checkAndCall(obj.get, obj, [index], '[]');
149 } 149 }
150 dart.dindex = dindex; 150 dart.dindex = dindex;
151 151
152 function dsetindex(obj, index, value) { 152 function dsetindex(obj, index, value) {
153 return checkAndCall(obj.set, obj, [index, value], '[]='); 153 return checkAndCall(obj.set, obj, [index, value], '[]=');
154 } 154 }
155 dart.dsetindex = dsetindex; 155 dart.dsetindex = dsetindex;
156 156
157 /**
158 * Returns bound `method`.
159 * This helper function avoids needing a temp for `obj`.
160 */
161 function bind(obj, method) {
162 // This is a static bind (dynamic would use `dload`) so no need to check
163 // if `method` is really there on `obj`.`
164 return obj[method].bind(obj);
165 }
166 dart.bind = bind;
167
168 function typeToString(type) { 157 function typeToString(type) {
169 if (typeof(type) == "function") { 158 if (typeof(type) == "function") {
170 var name = type.name; 159 var name = type.name;
171 var args = type[dart.typeArguments]; 160 var args = type[dart.typeArguments];
172 if (args) { 161 if (args) {
173 name += '<'; 162 name += '<';
174 for (var i = 0; i < args.length; ++i) { 163 for (var i = 0; i < args.length; ++i) {
175 if (i > 0) name += ', '; 164 if (i > 0) name += ', ';
176 name += typeToString(args[i]); 165 name += typeToString(args[i]);
177 } 166 }
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 let sigObj = obj.__proto__.constructor[_methodSig]; 1003 let sigObj = obj.__proto__.constructor[_methodSig];
1015 if (sigObj === void 0) return void 0; 1004 if (sigObj === void 0) return void 0;
1016 let sig = sigObj[name]; 1005 let sig = sigObj[name];
1017 return sig; 1006 return sig;
1018 } 1007 }
1019 1008
1020 /// Given an object and a method name, tear off the method. 1009 /// Given an object and a method name, tear off the method.
1021 /// Sets the runtime type of the torn off method appropriately, 1010 /// Sets the runtime type of the torn off method appropriately,
1022 /// and also binds the object. 1011 /// and also binds the object.
1023 /// TODO(leafp): Consider caching the tearoff on the object? 1012 /// TODO(leafp): Consider caching the tearoff on the object?
1024 function tearoff(obj, name) { 1013 function bind(obj, name) {
1025 let f = obj[name].bind(obj); 1014 let f = obj[name].bind(obj);
1026 let sig = _getMethodType(obj, name) 1015 let sig = _getMethodType(obj, name)
1027 assert(sig); 1016 assert(sig);
1028 setRuntimeType(f, sig); 1017 setRuntimeType(f, sig);
1029 return f; 1018 return f;
1030 } 1019 }
1031 dart.tearoff = tearoff; 1020 dart.bind = bind;
1032 1021
1033 // Set up the method signature field on the constructor 1022 // Set up the method signature field on the constructor
1034 function _setMethodSignature(f, sigF) { 1023 function _setMethodSignature(f, sigF) {
1035 defineMemoizedGetter(f, _methodSig, () => { 1024 defineMemoizedGetter(f, _methodSig, () => {
1036 let sigObj = sigF(); 1025 let sigObj = sigF();
1037 sigObj.__proto__ = f.__proto__[_methodSig]; 1026 sigObj.__proto__ = f.__proto__[_methodSig];
1038 return sigObj; 1027 return sigObj;
1039 }); 1028 });
1040 } 1029 }
1041 1030
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 Number.prototype['>'] = function(arg) { return this.valueOf() > arg; }; 1270 Number.prototype['>'] = function(arg) { return this.valueOf() > arg; };
1282 Number.prototype['+'] = function(arg) { return this.valueOf() + arg; }; 1271 Number.prototype['+'] = function(arg) { return this.valueOf() + arg; };
1283 1272
1284 // TODO(vsm): DOM facades? 1273 // TODO(vsm): DOM facades?
1285 // See: https://github.com/dart-lang/dev_compiler/issues/173 1274 // See: https://github.com/dart-lang/dev_compiler/issues/173
1286 NodeList.prototype.get = function(i) { return this[i]; }; 1275 NodeList.prototype.get = function(i) { return this[i]; };
1287 NamedNodeMap.prototype.get = function(i) { return this[i]; }; 1276 NamedNodeMap.prototype.get = function(i) { return this[i]; };
1288 DOMTokenList.prototype.get = function(i) { return this[i]; }; 1277 DOMTokenList.prototype.get = function(i) { return this[i]; };
1289 1278
1290 })(dart || (dart = {})); 1279 })(dart || (dart = {}));
OLDNEW
« no previous file with comments | « lib/runtime/dart/core.js ('k') | lib/src/codegen/js_codegen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698