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

Side by Side Diff: tool/input_sdk/private/ddc_runtime/classes.dart

Issue 1918033002: Remove virtualField helper, just emit getters/setters in codegen. (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 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 /// 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 $_setConstructorSignature($f, constructors); 223 $_setConstructorSignature($f, constructors);
224 $_setMethodSignature($f, methods); 224 $_setMethodSignature($f, methods);
225 $_setStaticSignature($f, statics); 225 $_setStaticSignature($f, statics);
226 $_setStaticTypes($f, names); 226 $_setStaticTypes($f, names);
227 $tagMemoized($f, () => $Type); 227 $tagMemoized($f, () => $Type);
228 })()'''); 228 })()''');
229 229
230 hasMethod(obj, name) => JS('', '$getMethodType($obj, $name) !== void 0'); 230 hasMethod(obj, name) => JS('', '$getMethodType($obj, $name) !== void 0');
231 231
232 /// 232 ///
233 /// This is called whenever a derived class needs to introduce a new field,
234 /// shadowing a field or getter/setter pair on its parent.
235 ///
236 /// This is important because otherwise, trying to read or write the field
237 /// would end up calling the getter or setter, and one of those might not even
238 /// exist, resulting in a runtime error. Even if they did exist, that's the
239 /// wrong behavior if a new field was declared.
240 ///
241 virtualField(subclass, fieldName) => JS('', '''(() => {
242 // If the field is already overridden, do nothing.
243 let prop = $getOwnPropertyDescriptor($subclass.prototype, $fieldName);
244 if (prop) return;
245
246 let symbol = Symbol($subclass.name + '.' + $fieldName.toString());
247 $defineProperty($subclass.prototype, $fieldName, {
248 get: function() { return this[symbol]; },
249 set: function(x) { this[symbol] = x; }
250 });
251 })()''');
252
253 ///
254 /// Given a class and an initializer method name, creates a constructor 233 /// Given a class and an initializer method name, creates a constructor
255 /// function with the same name. For example `new SomeClass.name(args)`. 234 /// function with the same name. For example `new SomeClass.name(args)`.
256 /// 235 ///
257 defineNamedConstructor(clazz, name) => JS('', '''(() => { 236 defineNamedConstructor(clazz, name) => JS('', '''(() => {
258 let proto = $clazz.prototype; 237 let proto = $clazz.prototype;
259 let initMethod = proto[$name]; 238 let initMethod = proto[$name];
260 let ctor = function() { return initMethod.apply(this, arguments); }; 239 let ctor = function() { return initMethod.apply(this, arguments); };
261 ctor.prototype = proto; 240 ctor.prototype = proto;
262 // Use defineProperty so we don't hit a property defined on Function, 241 // Use defineProperty so we don't hit a property defined on Function,
263 // like `caller` and `arguments`. 242 // like `caller` and `arguments`.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 })()'''); 351 })()''');
373 352
374 /// Sets the element type of a list literal. 353 /// Sets the element type of a list literal.
375 list(obj, elementType) => 354 list(obj, elementType) =>
376 JS('', '$setType($obj, ${getGenericClass(JSArray)}($elementType))'); 355 JS('', '$setType($obj, ${getGenericClass(JSArray)}($elementType))');
377 356
378 setBaseClass(derived, base) => JS('', '''(() => { 357 setBaseClass(derived, base) => JS('', '''(() => {
379 // Link the extension to the type it's extending as a base class. 358 // Link the extension to the type it's extending as a base class.
380 $derived.prototype.__proto__ = $base.prototype; 359 $derived.prototype.__proto__ = $base.prototype;
381 })()'''); 360 })()''');
OLDNEW
« lib/src/compiler/code_generator.dart ('K') | « test/codegen/language/final_field_override_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698