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

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

Issue 2873073002: fix #29585, implement equality for tearoffs (Closed)
Patch Set: merged Created 3 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 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 11 matching lines...) Expand all
22 : memberName = _dartSymbol(memberName), 22 : memberName = _dartSymbol(memberName),
23 namedArguments = _namedArgsToSymbols(namedArguments); 23 namedArguments = _namedArgsToSymbols(namedArguments);
24 24
25 static Map<Symbol, dynamic> _namedArgsToSymbols(namedArgs) { 25 static Map<Symbol, dynamic> _namedArgsToSymbols(namedArgs) {
26 if (namedArgs == null) return {}; 26 if (namedArgs == null) return {};
27 return new Map.fromIterable(getOwnPropertyNames(namedArgs), 27 return new Map.fromIterable(getOwnPropertyNames(namedArgs),
28 key: _dartSymbol, value: (k) => JS('', '#[#]', namedArgs, k)); 28 key: _dartSymbol, value: (k) => JS('', '#[#]', namedArgs, k));
29 } 29 }
30 } 30 }
31 31
32 /// Given an object and a method name, tear off the method.
33 /// Sets the runtime type of the torn off method appropriately,
34 /// and also binds the object.
35 ///
36 /// If the optional `f` argument is passed in, it will be used as the method.
37 /// This supports cases like `super.foo` where we need to tear off the method
38 /// from the superclass, not from the `obj` directly.
39 /// TODO(leafp): Consider caching the tearoff on the object?
40 bind(obj, name, f) {
41 if (f == null) f = JS('', '#[#]', obj, name);
42
43 // TODO(jmesserly): it would be nice to do this lazily, but JS interop seems
44 // to require us to be eager (the test below).
45 var sig = getMethodType(getType(obj), name);
46
47 // JS interop case: do not bind this for compatibility with the dart2js
48 // implementation where we cannot bind this reliably here until we trust
49 // types more.
50 if (sig == null) return f;
51
52 f = JS('', '#.bind(#)', f, obj);
53 JS(
54 '',
55 r'''#[dartx["=="]] = function boundMethodEquals(other) {
56 return other[#] === this[#] && other[#] === this[#];
57 }''',
58 f,
59 _boundMethodTarget,
60 _boundMethodTarget,
61 _boundMethodName,
62 _boundMethodName);
63 JS('', '#[#] = #', f, _boundMethodTarget, obj);
64 JS('', '#[#] = #', f, _boundMethodName, name);
65 tag(f, sig);
66 return f;
67 }
68
69 final _boundMethodTarget = JS('', 'Symbol("_boundMethodTarget")');
70 final _boundMethodName = JS('', 'Symbol("_boundMethodName")');
71
72 /// Instantiate a generic method.
73 ///
74 /// We need to apply the type arguments both to the function, as well as its
75 /// associated function type.
76 gbind(f, @rest typeArgs) {
77 var result = JS('', '#.apply(null, #)', f, typeArgs);
78 var sig = JS('', '#.instantiate(#)', _getRuntimeType(f), typeArgs);
79 tag(result, sig);
80 return result;
81 }
82
32 // Warning: dload, dput, and dsend assume they are never called on methods 83 // Warning: dload, dput, and dsend assume they are never called on methods
33 // implemented by the Object base class as those methods can always be 84 // implemented by the Object base class as those methods can always be
34 // statically resolved. 85 // statically resolved.
35 dload(obj, field) { 86 dload(obj, field) {
36 var f = _canonicalMember(obj, field); 87 var f = _canonicalMember(obj, field);
37 88
38 _trackCall(obj); 89 _trackCall(obj);
39 if (f != null) { 90 if (f != null) {
40 var type = getType(obj); 91 var type = getType(obj);
41 92
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 name = '+' + name; 992 name = '+' + name;
942 } 993 }
943 return name; 994 return name;
944 } 995 }
945 996
946 /// Emulates the implicit "loadLibrary" function provided by a deferred library. 997 /// Emulates the implicit "loadLibrary" function provided by a deferred library.
947 /// 998 ///
948 /// Libraries are not actually deferred in DDC, so this just returns a future 999 /// Libraries are not actually deferred in DDC, so this just returns a future
949 /// that completes immediately. 1000 /// that completes immediately.
950 Future loadLibrary() => new Future.value(); 1001 Future loadLibrary() => new Future.value();
OLDNEW
« no previous file with comments | « pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart ('k') | tests/language_strong/tearoff_dynamic_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698