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

Unified Diff: lib/runtime/dart_runtime.js

Issue 1099743002: fix fields that override getters/setters (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: merged Created 5 years, 8 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
« no previous file with comments | « lib/runtime/dart/core.js ('k') | lib/src/codegen/js_codegen.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/runtime/dart_runtime.js
diff --git a/lib/runtime/dart_runtime.js b/lib/runtime/dart_runtime.js
index e80d4131cb47fdc4875ba813d3ce4138913a2326..e6995067318b24b0a06bc9a1934ec3491a579d9f 100644
--- a/lib/runtime/dart_runtime.js
+++ b/lib/runtime/dart_runtime.js
@@ -597,6 +597,27 @@ var dart, _js_helper;
}
dart.copyProperties = copyProperties;
+ /**
+ * This is called whenever a derived class needs to introduce a new field,
+ * shadowing a field or getter/setter pair on its parent.
+ *
+ * This is important because otherwise, trying to read or write the field
+ * would end up calling the getter or setter, and one of those might not even
+ * exist, resulting in a runtime error. Even if they did exist, that's the
+ * wrong behavior if a new field was declared.
+ */
+ function virtualField(subclass, fieldName) {
+ // If the field is already overridden, do nothing.
+ let prop = getOwnPropertyDescriptor(subclass.prototype, fieldName);
+ if (prop) return;
+
+ let symbol = Symbol(subclass.name + '.' + fieldName);
+ defineProperty(subclass.prototype, fieldName, {
+ get: function() { return this[symbol]; },
+ set: function(x) { this[symbol] = x; }
+ });
+ }
+ dart.virtualField = virtualField;
/** The Symbol for storing type arguments on a specialized generic type. */
dart.mixins = Symbol('mixins');
« no previous file with comments | « lib/runtime/dart/core.js ('k') | lib/src/codegen/js_codegen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698