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

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

Issue 1152583002: Add constructors to signatures (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: 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
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 979 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 } 990 }
991 map.set(arg, value); 991 map.set(arg, value);
992 } 992 }
993 } 993 }
994 return value; 994 return value;
995 } 995 }
996 return makeGenericType; 996 return makeGenericType;
997 } 997 }
998 dart.generic = generic; 998 dart.generic = generic;
999 999
1000 let _constructorSig = Symbol('sigCtor');
1000 let _methodSig = Symbol("sig"); 1001 let _methodSig = Symbol("sig");
1001 let _staticSig = Symbol("sigStatic"); 1002 let _staticSig = Symbol("sigStatic");
1002 1003
1003 /// Get the type of a function using the store runtime type 1004 /// Get the type of a function using the store runtime type
1004 function _getFunctionType(f) { 1005 function _getFunctionType(f) {
1005 return f[_runtimeType]; 1006 return f[_runtimeType];
1006 } 1007 }
1007 1008
1008 /// Get the type of a method using the stored signature 1009 /// Get the type of a method using the stored signature
1009 function _getMethodType(obj, name) { 1010 function _getMethodType(obj, name) {
1010 if (obj === void 0) return void 0; 1011 if (obj === void 0) return void 0;
1011 if (obj == null) return void 0; 1012 if (obj == null) return void 0;
1012 let sigObj = obj.__proto__.constructor[_methodSig]; 1013 let sigObj = obj.__proto__.constructor[_methodSig];
1013 if (sigObj === void 0) return void 0; 1014 if (sigObj === void 0) return void 0;
1014 let parts = sigObj[name]; 1015 let parts = sigObj[name];
1015 if (parts === void 0) return void 0; 1016 if (parts === void 0) return void 0;
1016 let sig = functionType.apply(null, parts); 1017 let sig = functionType.apply(null, parts);
1017 return sig; 1018 return sig;
1018 } 1019 }
1019 1020
1021 /// Get the type of a constructor from a class using the stored signature
1022 /// If name is undefined, returns the type of the default constructor
1023 /// Returns undefined if the constructor is not found.
1024 function _getConstructorType(cls, name) {
1025 if(!name) name = cls.name;
1026 if (cls === void 0) return void 0;
1027 if (cls == null) return void 0;
1028 let sigCtor = cls[_constructorSig];
1029 if (sigCtor === void 0) return void 0;
1030 let parts = sigCtor[name];
1031 if (parts === void 0) return void 0;
1032 let sig = functionType.apply(null, parts);
1033 return sig;
1034 }
1035 dart.classGetConstructorType = _getConstructorType;
1036
1020 /// Given an object and a method name, tear off the method. 1037 /// Given an object and a method name, tear off the method.
1021 /// Sets the runtime type of the torn off method appropriately, 1038 /// Sets the runtime type of the torn off method appropriately,
1022 /// and also binds the object. 1039 /// and also binds the object.
1023 /// TODO(leafp): Consider caching the tearoff on the object? 1040 /// TODO(leafp): Consider caching the tearoff on the object?
1024 function bind(obj, name) { 1041 function bind(obj, name) {
1025 let f = obj[name].bind(obj); 1042 let f = obj[name].bind(obj);
1026 let sig = _getMethodType(obj, name) 1043 let sig = _getMethodType(obj, name)
1027 assert(sig); 1044 assert(sig);
1028 setRuntimeType(f, sig); 1045 setRuntimeType(f, sig);
1029 return f; 1046 return f;
1030 } 1047 }
1031 dart.bind = bind; 1048 dart.bind = bind;
1032 1049
1033 // Set up the method signature field on the constructor 1050 // Set up the method signature field on the constructor
1034 function _setMethodSignature(f, sigF) { 1051 function _setMethodSignature(f, sigF) {
1035 defineMemoizedGetter(f, _methodSig, () => { 1052 defineMemoizedGetter(f, _methodSig, () => {
1036 let sigObj = sigF(); 1053 let sigObj = sigF();
1037 sigObj.__proto__ = f.__proto__[_methodSig]; 1054 sigObj.__proto__ = f.__proto__[_methodSig];
1038 return sigObj; 1055 return sigObj;
1039 }); 1056 });
1040 } 1057 }
1041 1058
1059 // Set up the constructor signature field on the constructor
1060 function _setConstructorSignature(f, sigF) {
1061 defineMemoizedGetter(f, _constructorSig, sigF);
1062 }
1063
1042 // Set up the static signature field on the constructor 1064 // Set up the static signature field on the constructor
1043 function _setStaticSignature(f, sigF) { 1065 function _setStaticSignature(f, sigF) {
1044 defineMemoizedGetter(f, _staticSig, sigF); 1066 defineMemoizedGetter(f, _staticSig, sigF);
1045 } 1067 }
1046 1068
1047 // Set the lazily computed runtime type field on static methods 1069 // Set the lazily computed runtime type field on static methods
1048 function _setStaticTypes(f, names) { 1070 function _setStaticTypes(f, names) {
1049 for (let name of names) { 1071 for (let name of names) {
1050 function getT() { 1072 function getT() {
1051 let parts = f[_staticSig][name]; 1073 let parts = f[_staticSig][name];
1052 return functionType.apply(null, parts); 1074 return functionType.apply(null, parts);
1053 }; 1075 };
1054 defineProperty(f[name], _runtimeType, {get : getT}); 1076 defineProperty(f[name], _runtimeType, {get : getT});
1055 } 1077 }
1056 } 1078 }
1057 1079
1058 /// Set up the type signature of a class (constructor object) 1080 /// Set up the type signature of a class (constructor object)
1059 /// f is a constructor object 1081 /// f is a constructor object
1060 /// signature is an object containing optional properties as follows: 1082 /// signature is an object containing optional properties as follows:
1061 /// methods: A function returning an object mapping method names 1083 /// methods: A function returning an object mapping method names
1062 /// to method types. The function is evaluated lazily and cached. 1084 /// to method types. The function is evaluated lazily and cached.
1063 /// statics: A function returning an object mapping static method 1085 /// statics: A function returning an object mapping static method
1064 /// names to types. The function is evalutated lazily and cached. 1086 /// names to types. The function is evalutated lazily and cached.
1065 /// names: An array of the names of the static methods. Used to 1087 /// names: An array of the names of the static methods. Used to
1066 /// permit eagerly setting the runtimeType field on the methods 1088 /// permit eagerly setting the runtimeType field on the methods
1067 /// while still lazily computing the type descriptor object. 1089 /// while still lazily computing the type descriptor object.
1068 function setSignature(f, signature) { 1090 function setSignature(f, signature) {
1091 let constructors =
1092 ('constructors' in signature) ? signature.constructors : () => ({});
1069 let methods = 1093 let methods =
1070 ('methods' in signature) ? signature.methods : () => ({}); 1094 ('methods' in signature) ? signature.methods : () => ({});
1071 let statics = 1095 let statics =
1072 ('statics' in signature) ? signature.statics : () => ({}); 1096 ('statics' in signature) ? signature.statics : () => ({});
1073 let names = 1097 let names =
1074 ('names' in signature) ? signature.names : []; 1098 ('names' in signature) ? signature.names : [];
1099 _setConstructorSignature(f, constructors);
1075 _setMethodSignature(f, methods); 1100 _setMethodSignature(f, methods);
1076 _setStaticSignature(f, statics); 1101 _setStaticSignature(f, statics);
1077 _setStaticTypes(f, names); 1102 _setStaticTypes(f, names);
1078 }; 1103 };
1079 dart.setSignature = setSignature; 1104 dart.setSignature = setSignature;
1080 1105
1081 let _value = Symbol('_value'); 1106 let _value = Symbol('_value');
1082 /** 1107 /**
1083 * Looks up a sequence of [keys] in [map], recursively, and 1108 * Looks up a sequence of [keys] in [map], recursively, and
1084 * returns the result. If the value is not found, [valueFn] will be called to 1109 * returns the result. If the value is not found, [valueFn] will be called to
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 Number.prototype['>'] = function(arg) { return this.valueOf() > arg; }; 1309 Number.prototype['>'] = function(arg) { return this.valueOf() > arg; };
1285 Number.prototype['+'] = function(arg) { return this.valueOf() + arg; }; 1310 Number.prototype['+'] = function(arg) { return this.valueOf() + arg; };
1286 1311
1287 // TODO(vsm): DOM facades? 1312 // TODO(vsm): DOM facades?
1288 // See: https://github.com/dart-lang/dev_compiler/issues/173 1313 // See: https://github.com/dart-lang/dev_compiler/issues/173
1289 NodeList.prototype.get = function(i) { return this[i]; }; 1314 NodeList.prototype.get = function(i) { return this[i]; };
1290 NamedNodeMap.prototype.get = function(i) { return this[i]; }; 1315 NamedNodeMap.prototype.get = function(i) { return this[i]; };
1291 DOMTokenList.prototype.get = function(i) { return this[i]; }; 1316 DOMTokenList.prototype.get = function(i) { return this[i]; };
1292 1317
1293 })(dart || (dart = {})); 1318 })(dart || (dart = {}));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698