 Chromium Code Reviews
 Chromium Code Reviews Issue 11453032:
  Reapply class/method/field minification  (Closed) 
  Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
    
  
    Issue 11453032:
  Reapply class/method/field minification  (Closed) 
  Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart| Index: sdk/lib/_internal/compiler/implementation/lib/native_helper.dart | 
| diff --git a/sdk/lib/_internal/compiler/implementation/lib/native_helper.dart b/sdk/lib/_internal/compiler/implementation/lib/native_helper.dart | 
| index 46d81be95f1a8aa1b16726b6975e4b54f19daff0..98eea0219a45b27e85f188a3ba1c83a761dffd12 100644 | 
| --- a/sdk/lib/_internal/compiler/implementation/lib/native_helper.dart | 
| +++ b/sdk/lib/_internal/compiler/implementation/lib/native_helper.dart | 
| @@ -118,10 +118,6 @@ void arraySet(List array, int index, var value) { | 
| JS('var', '#[#] = #', array, index, value); | 
| } | 
| -propertyGet(var object, String property) { | 
| 
kasperl
2012/12/07 10:37:45
Why did this disappear? No remaining uses? I'd pro
 
erikcorry
2012/12/10 08:36:01
It's not getting inlined, but I'll put it back and
 | 
| - return JS('var', '#[#]', object, property); | 
| -} | 
| - | 
| void propertySet(var object, String property, var value) { | 
| JS('var', '#[#] = #', object, property, value); | 
| } | 
| @@ -205,21 +201,31 @@ dynamicBind(var obj, | 
| String name, | 
| var methods, | 
| List arguments) { | 
| + // The tag is related to the class name. E.g. the dart:html class | 
| + // '_ButtonElement' has the tag 'HTMLButtonElement'. TODO(erikcorry): rename | 
| + // getTypeNameOf to getTypeTag. | 
| String tag = getTypeNameOf(obj); | 
| - var method = JS('var', '#[#]', methods, tag); | 
| + var hasOwnProperty = JS('var', 'Object.prototype.hasOwnProperty'); | 
| + var method = lookupDynamicClass(hasOwnProperty, methods, tag); | 
| if (method == null && _dynamicMetadata != null) { | 
| + // Look at the inheritance data, getting the class tags and using them | 
| + // 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, tag)) { | 
| 
kasperl
2012/12/07 10:37:45
Consider adding a named helper for the hasOwnPrope
 
erikcorry
2012/12/10 08:36:01
Done.
 | 
| + 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); | 
| @@ -239,13 +245,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) we must always use hasOwnProperty. | 
| +var lookupDynamicClass(var hasOwnProperty, var methods, String className) { | 
| + return JS('bool', '#.call(#, #)', hasOwnProperty, methods, className) ? | 
| + JS('var', '#[#]', methods, className) : | 
| 
kasperl
2012/12/07 10:37:45
Use propertyGet here?
 
erikcorry
2012/12/10 08:36:01
Done.
 | 
| + null; | 
| +} | 
| + | 
| /** | 
| * Code for doing the dynamic dispatch on JavaScript prototypes that are not | 
| * available at compile-time. Each property of a native Dart class | 
| @@ -273,7 +290,10 @@ 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); | 
| + var dartMethod = | 
| + JS('var', 'Object.getPrototypeOf(#)[#]', const Object(), name); | 
| 
kasperl
2012/12/07 10:37:45
Add helper for getPrototypeOf stuff?
 
erikcorry
2012/12/10 08:36:01
Done.
 | 
| + // Take the method from the Dart Object class if we didn't find it yet and it | 
| + // is there. | 
| if (dartMethod != null) propertySet(methods, 'Object', dartMethod); | 
| var bind = JS('var', |