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 the operations that define and manipulate Dart | 5 /// This library defines the operations that define and manipulate Dart |
6 /// classes. Included in this are: | 6 /// classes. Included in this are: |
7 /// - Generics | 7 /// - Generics |
8 /// - Class metadata | 8 /// - Class metadata |
9 /// - Extension methods | 9 /// - Extension methods |
10 /// | 10 /// |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 | 185 |
186 // Set up the static signature field on the constructor | 186 // Set up the static signature field on the constructor |
187 _setStaticSignature(f, sigF) => | 187 _setStaticSignature(f, sigF) => |
188 JS('', '$defineMemoizedGetter($f, $_staticSig, $sigF)'); | 188 JS('', '$defineMemoizedGetter($f, $_staticSig, $sigF)'); |
189 | 189 |
190 // Set the lazily computed runtime type field on static methods | 190 // Set the lazily computed runtime type field on static methods |
191 _setStaticTypes(f, names) => JS('', '''(() => { | 191 _setStaticTypes(f, names) => JS('', '''(() => { |
192 for (let name of $names) { | 192 for (let name of $names) { |
193 // TODO(vsm): Need to generate static methods. | 193 // TODO(vsm): Need to generate static methods. |
194 if (!$f[name]) continue; | 194 if (!$f[name]) continue; |
195 $tagMemoized($f[name], function() { | 195 $tagLazy($f[name], function() { |
196 let parts = $f[$_staticSig][name]; | 196 let parts = $f[$_staticSig][name]; |
197 return $definiteFunctionType.apply(null, parts); | 197 return $definiteFunctionType.apply(null, parts); |
198 }) | 198 }) |
199 } | 199 } |
200 })()'''); | 200 })()'''); |
201 | 201 |
202 /// Set up the type signature of a class (constructor object) | 202 /// Set up the type signature of a class (constructor object) |
203 /// f is a constructor object | 203 /// f is a constructor object |
204 /// signature is an object containing optional properties as follows: | 204 /// signature is an object containing optional properties as follows: |
205 /// methods: A function returning an object mapping method names | 205 /// methods: A function returning an object mapping method names |
(...skipping 10 matching lines...) Expand all Loading... |
216 let methods = | 216 let methods = |
217 ('methods' in signature) ? signature.methods : () => ({}); | 217 ('methods' in signature) ? signature.methods : () => ({}); |
218 let statics = | 218 let statics = |
219 ('statics' in signature) ? signature.statics : () => ({}); | 219 ('statics' in signature) ? signature.statics : () => ({}); |
220 let names = | 220 let names = |
221 ('names' in signature) ? signature.names : []; | 221 ('names' in signature) ? signature.names : []; |
222 $_setConstructorSignature($f, constructors); | 222 $_setConstructorSignature($f, constructors); |
223 $_setMethodSignature($f, methods); | 223 $_setMethodSignature($f, methods); |
224 $_setStaticSignature($f, statics); | 224 $_setStaticSignature($f, statics); |
225 $_setStaticTypes($f, names); | 225 $_setStaticTypes($f, names); |
226 $tagMemoized($f, () => $Type); | 226 $tagLazy($f, () => $Type); |
227 })()'''); | 227 })()'''); |
228 | 228 |
229 hasMethod(obj, name) => JS('', '$getMethodType($obj, $name) !== void 0'); | 229 hasMethod(obj, name) => JS('', '$getMethodType($obj, $name) !== void 0'); |
230 | 230 |
231 /// | 231 /// |
232 /// Given a class and an initializer method name, creates a constructor | 232 /// Given a class and an initializer method name, creates a constructor |
233 /// function with the same name. For example `new SomeClass.name(args)`. | 233 /// function with the same name. For example `new SomeClass.name(args)`. |
234 /// | 234 /// |
235 defineNamedConstructor(clazz, name) => JS('', '''(() => { | 235 defineNamedConstructor(clazz, name) => JS('', '''(() => { |
236 let proto = $clazz.prototype; | 236 let proto = $clazz.prototype; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 })()'''); | 350 })()'''); |
351 | 351 |
352 /// Sets the element type of a list literal. | 352 /// Sets the element type of a list literal. |
353 list(obj, elementType) => | 353 list(obj, elementType) => |
354 JS('', '$setType($obj, ${getGenericClass(JSArray)}($elementType))'); | 354 JS('', '$setType($obj, ${getGenericClass(JSArray)}($elementType))'); |
355 | 355 |
356 setBaseClass(derived, base) => JS('', '''(() => { | 356 setBaseClass(derived, base) => JS('', '''(() => { |
357 // Link the extension to the type it's extending as a base class. | 357 // Link the extension to the type it's extending as a base class. |
358 $derived.prototype.__proto__ = $base.prototype; | 358 $derived.prototype.__proto__ = $base.prototype; |
359 })()'''); | 359 })()'''); |
OLD | NEW |