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

Unified Diff: pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart

Issue 2691433004: Support virtual fields in DDC without requiring the @virtual annotation.
Patch Set: Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart
diff --git a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart
index cdc14c1c37a9279066a7ac4831f04da8572ddd81..5d9b9034b9b7122f621a16218d2de372d15da0c3 100644
--- a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart
+++ b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart
@@ -82,6 +82,35 @@ mixin(base, @rest mixins) => JS(
return Mixin;
})()''');
+///
+/// Support for virtualizing fields on-demand.
+///
+final _virtualNames = JS('', '{}');
+
+virtualName(key) => JS(
+ '',
+ '''(() => {
+ return #[key] || (#[key] = Symbol(key));
+})()''',
+ _virtualNames,
+ _virtualNames);
+
+virtualize(object, keys) => JS(
+ '',
+ '''(() => {
+ for (var i = 0; i < keys.length; i += 2) {
+ let name = keys[i];
+ let symbol = keys[i + 1];
+ Object.defineProperty(object, name, {
+ configurable: true,
+ set: function(value) {
+ object[symbol] = value;
+ delete object[name];
+ }
+ });
+ }
+})()''');
+
/// The Symbol for storing type arguments on a specialized generic type.
final _mixins = JS('', 'Symbol("mixins")');
« no previous file with comments | « pkg/dev_compiler/lib/src/compiler/code_generator.dart ('k') | tests/language_strong/field_override5_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698