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

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

Issue 1145283002: Use short array syntax in method signatures (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Address comments 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 | « no previous file | 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 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 var t; 564 var t;
565 if (arguments.length == 1) { 565 if (arguments.length == 1) {
566 // No type arguments, it's all dynamic 566 // No type arguments, it's all dynamic
567 let len = closure.length; 567 let len = closure.length;
568 let args = Array.apply(null, new Array(len)).map(() => dart.dynamic); 568 let args = Array.apply(null, new Array(len)).map(() => dart.dynamic);
569 t = functionType(dart.dynamic, args); 569 t = functionType(dart.dynamic, args);
570 } else { 570 } else {
571 // We're passed the piecewise components of the function type, 571 // We're passed the piecewise components of the function type,
572 // construct it. 572 // construct it.
573 let args = Array.prototype.slice.call(arguments, 1); 573 let args = Array.prototype.slice.call(arguments, 1);
574 t = functionType.apply(functionType, args); 574 t = functionType.apply(null, args);
575 } 575 }
576 setRuntimeType(closure, t); 576 setRuntimeType(closure, t);
577 return closure; 577 return closure;
578 } 578 }
579 dart.fn = fn; 579 dart.fn = fn;
580 580
581 function functionType(returnType, args, extra) { 581 function functionType(returnType, args, extra) {
582 // TODO(vsm): Cache / memomize? 582 // TODO(vsm): Cache / memomize?
583 var optionals; 583 var optionals;
584 var named; 584 var named;
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 function _getFunctionType(f) { 995 function _getFunctionType(f) {
996 return f[_runtimeType]; 996 return f[_runtimeType];
997 } 997 }
998 998
999 /// Get the type of a method using the stored signature 999 /// Get the type of a method using the stored signature
1000 function _getMethodType(obj, name) { 1000 function _getMethodType(obj, name) {
1001 if (obj === void 0) return void 0; 1001 if (obj === void 0) return void 0;
1002 if (obj == null) return void 0; 1002 if (obj == null) return void 0;
1003 let sigObj = obj.__proto__.constructor[_methodSig]; 1003 let sigObj = obj.__proto__.constructor[_methodSig];
1004 if (sigObj === void 0) return void 0; 1004 if (sigObj === void 0) return void 0;
1005 let sig = sigObj[name]; 1005 let parts = sigObj[name];
1006 if (parts === void 0) return void 0;
1007 let sig = functionType.apply(null, parts);
1006 return sig; 1008 return sig;
1007 } 1009 }
1008 1010
1009 /// Given an object and a method name, tear off the method. 1011 /// Given an object and a method name, tear off the method.
1010 /// Sets the runtime type of the torn off method appropriately, 1012 /// Sets the runtime type of the torn off method appropriately,
1011 /// and also binds the object. 1013 /// and also binds the object.
1012 /// TODO(leafp): Consider caching the tearoff on the object? 1014 /// TODO(leafp): Consider caching the tearoff on the object?
1013 function bind(obj, name) { 1015 function bind(obj, name) {
1014 let f = obj[name].bind(obj); 1016 let f = obj[name].bind(obj);
1015 let sig = _getMethodType(obj, name) 1017 let sig = _getMethodType(obj, name)
(...skipping 13 matching lines...) Expand all
1029 } 1031 }
1030 1032
1031 // Set up the static signature field on the constructor 1033 // Set up the static signature field on the constructor
1032 function _setStaticSignature(f, sigF) { 1034 function _setStaticSignature(f, sigF) {
1033 defineMemoizedGetter(f, _staticSig, sigF); 1035 defineMemoizedGetter(f, _staticSig, sigF);
1034 } 1036 }
1035 1037
1036 // Set the lazily computed runtime type field on static methods 1038 // Set the lazily computed runtime type field on static methods
1037 function _setStaticTypes(f, names) { 1039 function _setStaticTypes(f, names) {
1038 for (let name of names) { 1040 for (let name of names) {
1039 function getT() { return f[_staticSig][name];}; 1041 function getT() {
1042 let parts = f[_staticSig][name];
1043 return functionType.apply(null, parts);
1044 };
1040 defineProperty(f[name], _runtimeType, {get : getT}); 1045 defineProperty(f[name], _runtimeType, {get : getT});
1041 } 1046 }
1042 } 1047 }
1043 1048
1044 /// Set up the type signature of a class (constructor object) 1049 /// Set up the type signature of a class (constructor object)
1045 /// f is a constructor object 1050 /// f is a constructor object
1046 /// signature is an object containing optional properties as follows: 1051 /// signature is an object containing optional properties as follows:
1047 /// methods: A function returning an object mapping method names 1052 /// methods: A function returning an object mapping method names
1048 /// to method types. The function is evaluated lazily and cached. 1053 /// to method types. The function is evaluated lazily and cached.
1049 /// statics: A function returning an object mapping static method 1054 /// statics: A function returning an object mapping static method
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 Number.prototype['>'] = function(arg) { return this.valueOf() > arg; }; 1275 Number.prototype['>'] = function(arg) { return this.valueOf() > arg; };
1271 Number.prototype['+'] = function(arg) { return this.valueOf() + arg; }; 1276 Number.prototype['+'] = function(arg) { return this.valueOf() + arg; };
1272 1277
1273 // TODO(vsm): DOM facades? 1278 // TODO(vsm): DOM facades?
1274 // See: https://github.com/dart-lang/dev_compiler/issues/173 1279 // See: https://github.com/dart-lang/dev_compiler/issues/173
1275 NodeList.prototype.get = function(i) { return this[i]; }; 1280 NodeList.prototype.get = function(i) { return this[i]; };
1276 NamedNodeMap.prototype.get = function(i) { return this[i]; }; 1281 NamedNodeMap.prototype.get = function(i) { return this[i]; };
1277 DOMTokenList.prototype.get = function(i) { return this[i]; }; 1282 DOMTokenList.prototype.get = function(i) { return this[i]; };
1278 1283
1279 })(dart || (dart = {})); 1284 })(dart || (dart = {}));
OLDNEW
« no previous file with comments | « no previous file | lib/src/codegen/js_codegen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698