}
public final native <T> T get(Object id) /*-{
- var r = this && this[id], t = typeof r;
- // box booleans and numbers in a gwt object
- if (t == 'boolean') return @java.lang.Boolean::valueOf(Z)(r);
- if (t == 'number') return @java.lang.Double::valueOf(D)(r);
- return r;
+ return @com.google.gwt.query.client.js.JsCache::gwtBox(*)([ this && this[id] ]);
}-*/;
public final JsCache getCache(int id) {
}
return js;
}
+
+ /**
+ * Gets an object wrapped in a js array and boxes it with the appropriate
+ * Object in the GWT world.
+ *
+ * It is thought to be called from other jsni code without dealing with casting issues.
+ *
+ * It will box the unique element in the array with a Boolean or a Double in the case
+ * of primitive variables, otherwise it returns the object itself, or null if undefined.
+ *
+ * Example
+ * <pre>
+ * native Object myMethod() /*-{
+ * var myJsVar = ... ;
+ * return @com.google.gwt.query.client.js.JsCache::gwtBox(*)([ myJsVar ]);
+ * }-* /
+ * </pre>
+ *
+ */
+ public static native Object gwtBox(JavaScriptObject oneElementArray) /*-{
+ var r = oneElementArray;
+ if (typeof r == 'object' && r.length == 1) {
+ var r = r[0]; t = typeof r;
+ if (t == 'boolean') return @java.lang.Boolean::valueOf(Z)(r);
+ if (t == 'number') return @java.lang.Double::valueOf(D)(r);
+ }
+ return r || null;
+ }-*/;
}
return jso.equals(obj);
}
- private native void exec(JavaScriptObject f, Object data) /*-{
- f(data);
+ private native Object exec(JavaScriptObject f, Object data) /*-{
+ return @com.google.gwt.query.client.js.JsCache::gwtBox(*)([ f(data) ]);
}-*/;
public void f() {
if (jso != null) {
- exec(jso, getDataObject());
+ setArguments(exec(jso, arguments(0)));
}
}
}
private static native <T> T runJavascriptFunctionImpl(JavaScriptObject o, String meth, JsArrayMixed args) /*-{
- return (f = o && o[meth]) && @com.google.gwt.query.client.js.JsUtils::isFunction(*)(f) && f.apply(o, args) || null;
+ return (f = o && o[meth])
+ && @com.google.gwt.query.client.js.JsUtils::isFunction(*)(f)
+ && @com.google.gwt.query.client.js.JsCache::gwtBox(*)([f.apply(o, args)]);
}-*/;
/**
}
return ret;
}
+
}