*/\r
package com.google.gwt.query.client;\r
\r
+import com.google.gwt.core.client.GWT;\r
import com.google.gwt.core.client.JavaScriptObject;\r
import com.google.gwt.core.client.JsArrayMixed;\r
import com.google.gwt.query.client.js.JsCache;\r
}\r
\r
public final String toJsonString() {\r
- // In dev-mode a null object casted to JavascriptObject does not throw a NPE\r
- // e.g: System.out.println(((Properties)null).toJsonString());\r
- if (this == null) return "null";\r
- \r
String ret = "";\r
for (String k : keys()){\r
String ky = k.matches("\\d+") ? k : "\"" + k + "\"";\r
}\r
\r
public final String toQueryString() {\r
- // In dev-mode a null object casted to JavascriptObject does not throw a NPE\r
- if (this == null) return "null";\r
- \r
String ret = "";\r
for (String k : keys()) {\r
ret += ret.isEmpty() ? "" : "&";\r
public final boolean isEmpty(){\r
return c().length() == 0;\r
}\r
+\r
}\r
*/
package com.google.gwt.query.client.js;
+import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArrayMixed;
import com.google.gwt.core.client.JsArrayString;
}-*/;
public final void pushAll(JavaScriptObject prevElem) {
+ checkNull();
JsCache c = prevElem.cast();
for (int i = 0, ilen = c.length(); i < ilen; i++) {
put(length(), c.get(i));
public final <T extends JavaScriptObject> T getJavaScriptObject(Object name) {
Object o = get(name);
- return (o instanceof JavaScriptObject) ? ((JavaScriptObject)o).<T>cast() : null;
+ return (o != null && o instanceof JavaScriptObject) ? ((JavaScriptObject)o).<T>cast() : null;
}
public final native boolean isEmpty() /*-{
}-*/;
public final int[] indexes() {
+ checkNull();
JsArrayString a = keysImpl();
int[] ret = new int[a.length()];
for (int i = 0; i < a.length(); i++) {
}
public final String[] keys() {
+ checkNull();
JsArrayString a = keysImpl();
String[] ret = new String[a.length()];
for (int i = 0; i < a.length(); i++) {
return ret + "}";
}
+ private void checkNull() {
+ // In dev-mode a null object casted to JavascriptObject does not throw a NPE
+ if (!GWT.isProdMode() && this == null) {
+ throw new NullPointerException();
+ }
+ }
+
private final native JsArrayString keysImpl() /*-{
var key, keys=[];
// Chrome in DevMode injects a property to JS objects
p = $$("({border:'1px solid black'})");
assertEquals(1, p.keys().length);
assertNotNull(p.getStr("border"));
+
+ try {
+ // DevMode null casting return an object
+ ((Properties)null).toJsonString();
+ fail("Executing methods of a null object should throw a NullPointerException");
+ } catch (NullPointerException e) {
+ }
}
public void testRelativeMethods() {