Revision: 6909 Author: j...@google.com Date: Mon Nov 16 08:32:42 2009 Log: Work around JSNI uses of JSOs as maps on Chrome in DevMode (where the plugin adds __gwt_ObjectId to any JS object passed to Java to preserve object identity). We fix it by overriding Object.prototype.hasOwnProperty and fixing Dictionary to use it.
User-written JSNI may need to make similar changes. Patch by: jat Review by: jlabanca http://code.google.com/p/google-web-toolkit/source/detail?r=6909 Modified: /trunk/dev/core/src/com/google/gwt/core/ext/linker/impl/hosted.html /trunk/user/src/com/google/gwt/i18n/client/Dictionary.java ======================================= --- /trunk/dev/core/src/com/google/gwt/core/ext/linker/impl/hosted.html Fri Nov 13 09:04:35 2009 +++ /trunk/dev/core/src/com/google/gwt/core/ext/linker/impl/hosted.html Mon Nov 16 08:32:42 2009 @@ -72,13 +72,22 @@ external.gwtOnLoad(window, null, $hostedHtmlVersion); }; } else { - // install eval wrapper on FF to avoid EvalError problem - if (navigator.userAgent.toLowerCase().indexOf("gecko") != -1) { + var ua = navigator.userAgent.toLowerCase(); + if (ua.indexOf("gecko") != -1) { + // install eval wrapper on FF to avoid EvalError problem + // TODO(jat): should this UA check be more specific (this hits chrome too)? var __eval = window.eval; window.eval = function(s) { return __eval(s); } } + if (ua.indexOf("chrome") != -1) { + // work around __gwt_ObjectId appearing in JS objects + var hop = Object.prototype.hasOwnProperty; + Object.prototype.hasOwnProperty = function(prop) { + return prop != "__gwt_ObjectId" && hop.call(this, prop); + }; + } // wrapper to call JS methods, which we need both to be able to supply a // different this for method lookup and to get the exception back ======================================= --- /trunk/user/src/com/google/gwt/i18n/client/Dictionary.java Mon Jun 1 16:12:37 2009 +++ /trunk/user/src/com/google/gwt/i18n/client/Dictionary.java Mon Nov 16 08:32:42 2009 @@ -143,20 +143,19 @@ * @throws MissingResourceException if the value is not found */ public native String get(String key) /*-{ - var value = th...@com.google.gwt.i18n.client.dictionary::dict[key]; - var keys = th...@com.google.gwt.i18n.client.dictionary::accessedKeys; - keys.unshift(key); - // only keep the last 30 elements. Shrink it when array exceeds 60 - if (keys.length > 60) { - keys.splice(30); - } - if (value == null || !Object.prototype.hasOwnProperty.call( - th...@com.google.gwt.i18n.client.dictionary::dict, key)) - { - th...@com.google.gwt.i18n.client.dictionary::resourceError(Ljava/lang/String;)(key); - } - return String(value); - }-*/; + var map = th...@com.google.gwt.i18n.client.dictionary::dict; + var value = map[key]; + var keys = th...@com.google.gwt.i18n.client.dictionary::accessedKeys; + keys.unshift(key); + // only keep the last 30 elements. Shrink it when array exceeds 60 + if (keys.length > 60) { + keys.splice(30); + } + if (value == null || !map.hasOwnProperty(key)) { + th...@com.google.gwt.i18n.client.dictionary::resourceError(Ljava/lang/String;)(key); + } + return String(value); + }-*/; /** * The set of keys associated with this dictionary. @@ -196,15 +195,21 @@ } private native void addKeys(HashSet<String> s) /*-{ - for (x in th...@com.google.gwt.i18n.client.dictionary::dict) { - s...@java.util.hashset::add(Ljava/lang/Object;)(x); + var map = th...@com.google.gwt.i18n.client.dictionary::dict + for (var key in map) { + if (map.hasOwnProperty(key)) { + s...@java.util.hashset::add(Ljava/lang/Object;)(key); + } } }-*/; private native void addValues(ArrayList<String> s) /*-{ - for (x in th...@com.google.gwt.i18n.client.dictionary::dict) { - var value = th...@com.google.gwt.i18n.client.dictionary::get(Ljava/lang/String;)(x); - s...@java.util.arraylist::add(Ljava/lang/Object;)(value); + var map = th...@com.google.gwt.i18n.client.dictionary::dict + for (var key in map) { + if (map.hasOwnProperty(key)) { + var value = th...@com.google.gwt.i18n.client.dictionary::get(Ljava/lang/String;)(key); + s...@java.util.arraylist::add(Ljava/lang/Object;)(value); + } } }-*/; -- http://groups.google.com/group/Google-Web-Toolkit-Contributors