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

Unified Diff: lib/compiler/implementation/lib/native_helper.dart

Issue 11265020: Minifying renamer for classes, methods and instance variables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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: lib/compiler/implementation/lib/native_helper.dart
diff --git a/lib/compiler/implementation/lib/native_helper.dart b/lib/compiler/implementation/lib/native_helper.dart
index 1ff2e1c098d8dba355251d3427425d78844c55b7..c98e39d330943395f6f5a76edfc783c5f1424ee8 100644
--- a/lib/compiler/implementation/lib/native_helper.dart
+++ b/lib/compiler/implementation/lib/native_helper.dart
@@ -189,21 +189,28 @@ dynamicBind(var obj,
String name,
var methods,
List arguments) {
- String tag = getTypeNameOf(obj);
- var method = JS('var', '#[#]', methods, tag);
+ String className = getTypeNameOf(obj);
sra1 2012/10/26 06:41:45 Don't call this 'className', it will lead to confu
erikcorry 2012/12/06 09:38:07 Done.
+ var hasOwnProperty = JS('var', 'Object.prototype.hasOwnProperty');
+ var method = lookupDynamicClass(hasOwnProperty, methods, className);
if (method == null && _dynamicMetadata != null) {
+ // Look up the inheritance chain, getting the class names and using them
floitsch 2012/10/25 12:58:38 thanks for the comments. makes it much easier to u
sra1 2012/10/26 06:41:45 It is not really a chain, since it is inverted (pa
erikcorry 2012/12/06 09:38:07 Done.
erikcorry 2012/12/06 09:38:07 Done.
+ // to check the methods table for this method name.
for (int i = 0; i < arrayLength(_dynamicMetadata); i++) {
MetaInfo entry = arrayGet(_dynamicMetadata, i);
- if (JS('bool', '#', propertyGet(entry._set, tag))) {
- method = propertyGet(methods, entry._tag);
+ if (JS('bool', '#.call(#, #)', hasOwnProperty, entry._set, className)) {
+ method = lookupDynamicClass(hasOwnProperty, methods, entry._tag);
+ // Stop if we found it in the methods array.
if (method != null) break;
}
}
}
+ // If we didn't find the method then look up in the Dart Object class, using
+ // getTypeNameOf in case the minifier has renamed Object.
if (method == null) {
- method = propertyGet(methods, 'Object');
+ String nameOfObjectClass = getTypeNameOf(const Object());
+ method = lookupDynamicClass(hasOwnProperty, methods, nameOfObjectClass);
}
var proto = JS('var', 'Object.getPrototypeOf(#)', obj);
@@ -223,13 +230,24 @@ dynamicBind(var obj,
proto, name, name);
}
- if (JS('bool', '!#.hasOwnProperty(#)', proto, name)) {
+ if (JS('bool', '!#.call(#, #)', hasOwnProperty, proto, name)) {
defineProperty(proto, name, method);
}
return JS('var', '#.apply(#, #)', method, obj, arguments);
}
+// For each method name and class inheritance subtree, we use an ordinary JS
+// object as a hash map to store the method for each class. Entries are added
+// in native_emitter.dart (see dynamicName). In order to avoid the class names
+// clashing with the method names on Object.prototype (needed for native objects
floitsch 2012/10/25 08:42:40 missing closing ")".
erikcorry 2012/10/25 09:09:28 Done.
+// we must always use hasOwnProperty.
+var lookupDynamicClass(var hasOwnProperty, var methods, String className) {
+ return JS('bool', '#.call(#, #)', hasOwnProperty, methods, className) ?
+ JS('var', '#[#]', methods, className) :
+ JS('var', 'void 0');
floitsch 2012/10/25 12:58:38 null
erikcorry 2012/12/06 09:38:07 Done. I just used dart null rather than JS null.
+}
+
/**
* Code for doing the dynamic dispatch on JavaScript prototypes that are not
* available at compile-time. Each property of a native Dart class
@@ -248,7 +266,7 @@ dynamicBind(var obj,
*/
dynamicFunction(name) {
var f = JS('var', 'Object.prototype[#]', name);
- if (f != null && JS('bool', '!!#.methods', f)) {
floitsch 2012/10/25 12:58:38 While I agree that it probably works, this is "che
erikcorry 2012/12/06 09:38:07 Done.
+ if (f != null && JS('bool', '#.methods', f)) {
sra1 2012/10/26 06:41:45 I agree the !! is safer. In the conditional conte
erikcorry 2012/12/06 09:38:07 Done.
return JS('var', '#.methods', f);
}
@@ -257,8 +275,13 @@ dynamicFunction(name) {
var methods = JS('var', '{}');
// If there is a method attached to the Dart Object class, use it as
// the method to call in case no method is registered for that type.
- var dartMethod = JS('var', 'Object.getPrototypeOf(#)[#]', const Object(), name);
- if (dartMethod != null) propertySet(methods, 'Object', dartMethod);
+ var dartMethod =
+ JS('var', 'Object.getPrototypeOf(#)[#]', const Object(), name);
+ // Take the method from the Dart Object class if we didn't find it yet and it
+ // is there.
+ if (dartMethod != null) {
+ JS('void', '#[#] = #', methods, getTypeNameOf(const Object()), dartMethod);
sra1 2012/10/26 06:41:45 Do we have any reason to believe getTypeNameOf(con
erikcorry 2012/12/06 09:38:07 No.
+ }
var bind = JS('var',
'function() {'

Powered by Google App Engine
This is Rietveld 408576698