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

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

Issue 2668543002: Fix dynamic calls on JS interop classes. (Closed)
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 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 runtime operations on objects used by the code 5 /// This library defines runtime operations on objects used by the code
6 /// generator. 6 /// generator.
7 part of dart._runtime; 7 part of dart._runtime;
8 8
9 class InvocationImpl extends Invocation { 9 class InvocationImpl extends Invocation {
10 final Symbol memberName; 10 final Symbol memberName;
(...skipping 23 matching lines...) Expand all
34 // statically resolved. 34 // statically resolved.
35 dload(obj, field) { 35 dload(obj, field) {
36 var f = _canonicalMember(obj, field); 36 var f = _canonicalMember(obj, field);
37 37
38 _trackCall(obj); 38 _trackCall(obj);
39 if (f != null) { 39 if (f != null) {
40 var type = getType(obj); 40 var type = getType(obj);
41 41
42 if (hasField(type, f) || hasGetter(type, f)) return JS('', '#[#]', obj, f); 42 if (hasField(type, f) || hasGetter(type, f)) return JS('', '#[#]', obj, f);
43 if (hasMethod(type, f)) return bind(obj, f, JS('', 'void 0')); 43 if (hasMethod(type, f)) return bind(obj, f, JS('', 'void 0'));
44
45 // Always allow for JS interop objects.
46 if (isJsInterop(obj)) return JS('', '#[#]', obj, f);
44 } 47 }
45 return noSuchMethod( 48 return noSuchMethod(
46 obj, new InvocationImpl(field, JS('', '[]'), isGetter: true)); 49 obj, new InvocationImpl(field, JS('', '[]'), isGetter: true));
50 }
51
52 // Version of dload that matches legacy mirrors behavior for JS types.
53 dloadMirror(obj, field) {
54 var f = _canonicalMember(obj, field);
55
56 _trackCall(obj);
57 if (f != null) {
58 var type = getType(obj);
59
60 if (hasField(type, f) || hasGetter(type, f)) return JS('', '#[#]', obj, f);
61 if (hasMethod(type, f)) return bind(obj, f, JS('', 'void 0'));
62
63 // Do not support calls on JS interop objects to match Dart2JS behavior.
64 }
65 return noSuchMethod(
66 obj, new InvocationImpl(field, JS('', '[]'), isGetter: true));
47 } 67 }
48 68
49 _stripGenericArguments(type) { 69 _stripGenericArguments(type) {
50 var genericClass = getGenericClass(type); 70 var genericClass = getGenericClass(type);
51 if (genericClass != null) return JS('', '#()', genericClass); 71 if (genericClass != null) return JS('', '#()', genericClass);
52 return type; 72 return type;
53 } 73 }
54 74
55 // Version of dput that matches legacy Dart 1 type check rules. 75 // Version of dput that matches legacy Dart 1 type check rules and mirrors
56 // TODO(jacobr): remove this temporary workaround when mirrors based 76 // behavior for JS types.
77 // TODO(jacobr): remove the type checking rules workaround when mirrors based
57 // PageLoader code can generate the correct reified generic types. 78 // PageLoader code can generate the correct reified generic types.
58 dputLegacy(obj, field, value) { 79 dputMirror(obj, field, value) {
59 var f = _canonicalMember(obj, field); 80 var f = _canonicalMember(obj, field);
60 _trackCall(obj); 81 _trackCall(obj);
61 if (f != null) { 82 if (f != null) {
62 var objType = getType(obj); 83 var objType = getType(obj);
63 var setterType = getSetterType(objType, f); 84 var setterType = getSetterType(objType, f);
64 if (JS('bool', '# != void 0', setterType)) { 85 if (JS('bool', '# != void 0', setterType)) {
65 return JS('', '#[#] = #', obj, f, check(value, _stripGenericArguments(JS( '', '#.args[0]', setterType)))); 86 return JS(
87 '',
88 '#[#] = #',
89 obj,
90 f,
91 check(
92 value, _stripGenericArguments(JS('', '#.args[0]', setterType))));
66 } else { 93 } else {
67 var fieldType = getFieldType(objType, f); 94 var fieldType = getFieldType(objType, f);
68 // TODO(jacobr): add metadata tracking which fields are final and throw 95 // TODO(jacobr): add metadata tracking which fields are final and throw
69 // if a setter is called on a final field. 96 // if a setter is called on a final field.
70 if (JS('bool', '# != void 0', fieldType)) { 97 if (JS('bool', '# != void 0', fieldType)) {
71 return JS('', '#[#] = #', obj, f, check(value, _stripGenericArguments(fi eldType))); 98 return JS('', '#[#] = #', obj, f,
99 check(value, _stripGenericArguments(fieldType)));
72 } 100 }
101
102 // Do not support calls on JS interop objects to match Dart2JS behavior.
73 } 103 }
74 } 104 }
75 return noSuchMethod( 105 return noSuchMethod(
76 obj, new InvocationImpl(field, JS('', '[#]', value), isSetter: true)); 106 obj, new InvocationImpl(field, JS('', '[#]', value), isSetter: true));
77 } 107 }
78 108
79 dput(obj, field, value) { 109 dput(obj, field, value) {
80 var f = _canonicalMember(obj, field); 110 var f = _canonicalMember(obj, field);
81 _trackCall(obj); 111 _trackCall(obj);
82 if (f != null) { 112 if (f != null) {
83 var objType = getType(obj); 113 var objType = getType(obj);
84 var setterType = getSetterType(objType, f); 114 var setterType = getSetterType(objType, f);
85 if (JS('bool', '# != void 0', setterType)) { 115 if (JS('bool', '# != void 0', setterType)) {
86 return JS('', '#[#] = #', obj, f, check(value, JS('', '#.args[0]', setter Type))); 116 return JS('', '#[#] = #', obj, f,
117 check(value, JS('', '#.args[0]', setterType)));
87 } else { 118 } else {
88 var fieldType = getFieldType(objType, f); 119 var fieldType = getFieldType(objType, f);
89 // TODO(jacobr): add metadata tracking which fields are final and throw 120 // TODO(jacobr): add metadata tracking which fields are final and throw
90 // if a setter is called on a final field. 121 // if a setter is called on a final field.
91 if (JS('bool', '# != void 0', fieldType)) { 122 if (JS('bool', '# != void 0', fieldType)) {
92 return JS('', '#[#] = #', obj, f, check(value, fieldType)); 123 return JS('', '#[#] = #', obj, f, check(value, fieldType));
93 } 124 }
125 // Always allow for JS interop objects.
126 if (isJsInterop(obj)) {
127 return JS('', '#[#] = #', obj, f, value);
128 }
94 } 129 }
95 } 130 }
96 return noSuchMethod( 131 return noSuchMethod(
97 obj, new InvocationImpl(field, JS('', '[#]', value), isSetter: true)); 132 obj, new InvocationImpl(field, JS('', '[#]', value), isSetter: true));
98 } 133 }
99 134
100 /// Check that a function of a given type can be applied to 135 /// Check that a function of a given type can be applied to
101 /// actuals. 136 /// actuals.
102 _checkApply(type, actuals) => JS( 137 _checkApply(type, actuals) => JS(
103 '', 138 '',
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 name = '+' + name; 959 name = '+' + name;
925 } 960 }
926 return name; 961 return name;
927 } 962 }
928 963
929 /// Emulates the implicit "loadLibrary" function provided by a deferred library. 964 /// Emulates the implicit "loadLibrary" function provided by a deferred library.
930 /// 965 ///
931 /// Libraries are not actually deferred in DDC, so this just returns a future 966 /// Libraries are not actually deferred in DDC, so this just returns a future
932 /// that completes immediately. 967 /// that completes immediately.
933 Future loadLibrary() => new Future.value(); 968 Future loadLibrary() => new Future.value();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698