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

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

Issue 2664493005: Fix getFieldType to handle metadata and workaround bad types for setters called via mirrors. (Closed)
Patch Set: Created 3 years, 11 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/operations.dart
diff --git a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/operations.dart b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/operations.dart
index 5975ddce2d84f7e72f32c6d565941988f328cc8f..399b4ffb276ee0c03c30b43eec6994c65849d639 100644
--- a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/operations.dart
+++ b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/operations.dart
@@ -46,28 +46,50 @@ dload(obj, field) {
obj, new InvocationImpl(field, JS('', '[]'), isGetter: true));
}
-dput(obj, field, value) {
+_stripGenericArguments(type) {
+ var genericClass = getGenericClass(type);
+ if (genericClass != null) return JS('', '#()', genericClass);
+ return type;
+}
+
+// Version of dput that matches legacy Dart 1 type check rules.
+// TODO(jacobr): remove this temporary workaround when mirrors based
+// PageLoader code can generate the correct reified generic types.
+dputLegacy(obj, field, value) {
var f = _canonicalMember(obj, field);
_trackCall(obj);
if (f != null) {
var objType = getType(obj);
var setterType = getSetterType(objType, f);
if (JS('bool', '# != void 0', setterType)) {
- // TODO(jacobr): throw a type error instead of a NoSuchMethodError if
- // the type of the setter doesn't match.
- if (instanceOfOrNull(value, JS('', '#.args[0]', setterType))) {
- return JS('', '#[#] = #', obj, f, value);
+ return JS('', '#[#] = #', obj, f, check(value, _stripGenericArguments(JS('', '#.args[0]', setterType))));
+ } else {
+ var fieldType = getFieldType(objType, f);
+ // TODO(jacobr): add metadata tracking which fields are final and throw
+ // if a setter is called on a final field.
+ if (JS('bool', '# != void 0', fieldType)) {
+ return JS('', '#[#] = #', obj, f, check(value, _stripGenericArguments(fieldType)));
}
+ }
+ }
+ return noSuchMethod(
+ obj, new InvocationImpl(field, JS('', '[#]', value), isSetter: true));
+}
+
+dput(obj, field, value) {
+ var f = _canonicalMember(obj, field);
+ _trackCall(obj);
+ if (f != null) {
+ var objType = getType(obj);
+ var setterType = getSetterType(objType, f);
+ if (JS('bool', '# != void 0', setterType)) {
+ return JS('', '#[#] = #', obj, f, check(value, JS('', '#.args[0]', setterType)));
} else {
var fieldType = getFieldType(objType, f);
// TODO(jacobr): add metadata tracking which fields are final and throw
// if a setter is called on a final field.
if (JS('bool', '# != void 0', fieldType)) {
- // TODO(jacobr): throw a type error instead of a NoSuchMethodError if
- // the type of the field doesn't match.
- if (instanceOfOrNull(value, fieldType)) {
- return JS('', '#[#] = #', obj, f, value);
- }
+ return JS('', '#[#] = #', obj, f, check(value, fieldType));
}
}
}

Powered by Google App Engine
This is Rietveld 408576698