[google-web-toolkit] r6909 committed - Work around JSNI uses of JSOs as maps on Chrome in DevMode (where the ...

16 views
Skip to first unread message

codesite...@google.com

unread,
Nov 16, 2009, 11:33:04 AM11/16/09
to gwt...@gmail.com
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 = this.@com.google.gwt.i18n.client.Dictionary::dict[key];
- var keys = this.@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(
- this.@com.google.gwt.i18n.client.Dictionary::dict, key))
- {
-
this.@com.google.gwt.i18n.client.Dictionary::resourceError(Ljava/lang/String;)(key);
- }
- return String(value);
- }-*/;
+ var map = this.@com.google.gwt.i18n.client.Dictionary::dict;
+ var value = map[key];
+ var keys = this.@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)) {
+
this.@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 this.@com.google.gwt.i18n.client.Dictionary::dict) {
- s.@java.util.HashSet::add(Ljava/lang/Object;)(x);
+ var map = this.@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 this.@com.google.gwt.i18n.client.Dictionary::dict) {
- var value =
this.@com.google.gwt.i18n.client.Dictionary::get(Ljava/lang/String;)(x);
- s.@java.util.ArrayList::add(Ljava/lang/Object;)(value);
+ var map = this.@com.google.gwt.i18n.client.Dictionary::dict
+ for (var key in map) {
+ if (map.hasOwnProperty(key)) {
+ var value =
this.@com.google.gwt.i18n.client.Dictionary::get(Ljava/lang/String;)(key);
+ s.@java.util.ArrayList::add(Ljava/lang/Object;)(value);
+ }
}
}-*/;

Reply all
Reply to author
Forward
0 new messages