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

Unified Diff: sdk/lib/_internal/lib/js_helper.dart

Issue 23567019: Change how we generate bound closures to handler boud closures due to super getters: we need to pas… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 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: sdk/lib/_internal/lib/js_helper.dart
===================================================================
--- sdk/lib/_internal/lib/js_helper.dart (revision 27466)
+++ sdk/lib/_internal/lib/js_helper.dart (working copy)
@@ -86,9 +86,9 @@
argumentNames);
}
-void throwInvalidReflectionError(Symbol memberName) {
- throw new UnsupportedError('invalid reflective use of ${memberName}, '
- 'which is not included by a @MirrorsUsed annotation');
+void throwInvalidReflectionError(String memberName) {
+ throw new UnsupportedError("Can't use '$memberName' in reflection "
+ "because it is not included in a @MirrorsUsed annotation.");
}
bool hasReflectableProperty(var jsFunction) {
@@ -180,7 +180,7 @@
var method = JS('var', '#[#]', receiver, name);
if (JS('String', 'typeof #', method) == 'function') {
if (!hasReflectableProperty(method)) {
- throwInvalidReflectionError(memberName);
+ throwInvalidReflectionError(_symbol_dev.Symbol.getName(memberName));
}
return new CachedInvocation(method, isIntercepted, interceptor);
} else {
@@ -1496,12 +1496,15 @@
// we need the interceptor when generating the call method.
final _self;
- /// The method name.
- final String _target;
+ /// The method.
+ final _target;
- /// The receiver.
+ /// The receiver. Null if [_self] is not an interceptor.
final _receiver;
+ /// The name of the function. Only used by the mirror system.
+ final String _name;
+
bool operator==(other) {
if (identical(this, other)) return true;
if (other is! BoundClosure) return false;
@@ -1512,17 +1515,30 @@
}
int get hashCode {
- return JS('int', '(# + # + #) & 0x3ffffff',
- _self.hashCode,
- _target.hashCode,
- _receiver.hashCode);
+ int receiverHashCode;
+ if (_receiver == null) {
+ // A bound closure on a regular Dart object, just use the
+ // identity hash code.
+ receiverHashCode = Primitives.objectHashCode(_self);
+ } else if (JS('String', 'typeof #', _receiver) != 'object') {
+ // A bound closure on a primitive JavaScript type. We
+ // use the hashCode method we define for those primitive types.
+ receiverHashCode = _receiver.hashCode;
+ } else {
+ // A bound closure on an intercepted native class, just use the
+ // identity hash code.
+ receiverHashCode = Primitives.objectHashCode(_receiver);
+ }
+ return receiverHashCode ^ Primitives.objectHashCode(_target);
}
static selfOf(BoundClosure closure) => closure._self;
- static String targetOf(BoundClosure closure) => closure._target;
+ static targetOf(BoundClosure closure) => closure._target;
- static revceiverOf(BoundClosure closure) => closure._receiver;
+ static receiverOf(BoundClosure closure) => closure._receiver;
+
+ static nameOf(BoundClosure closure) => closure._name;
}
bool jsHasOwnProperty(var jsObject, String property) {

Powered by Google App Engine
This is Rietveld 408576698