Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | package org.mozilla.gecko.util; |
michael@0 | 7 | |
michael@0 | 8 | import org.mozilla.gecko.mozglue.JNITarget; |
michael@0 | 9 | |
michael@0 | 10 | /** |
michael@0 | 11 | * NativeJSObject is a wrapper around the SpiderMonkey JSAPI to make it possible to |
michael@0 | 12 | * access Javascript objects in Java. |
michael@0 | 13 | */ |
michael@0 | 14 | @JNITarget |
michael@0 | 15 | public class NativeJSObject |
michael@0 | 16 | { |
michael@0 | 17 | private final NativeJSContainer mContainer; |
michael@0 | 18 | private final int mObjectIndex; |
michael@0 | 19 | |
michael@0 | 20 | protected NativeJSObject() { |
michael@0 | 21 | mContainer = (NativeJSContainer)this; |
michael@0 | 22 | mObjectIndex = -1; |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | private NativeJSObject(NativeJSContainer container, int index) { |
michael@0 | 26 | mContainer = container; |
michael@0 | 27 | mObjectIndex = index; |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | /** |
michael@0 | 31 | * Returns the value of a boolean property. |
michael@0 | 32 | * |
michael@0 | 33 | * @param name |
michael@0 | 34 | * Property name |
michael@0 | 35 | * @throws IllegalArgumentException |
michael@0 | 36 | * If the property does not exist or if its type does not match the return type |
michael@0 | 37 | * @throws NullPointerException |
michael@0 | 38 | * If name is null or if this JS object has been disposed |
michael@0 | 39 | * @throws IllegalThreadStateException |
michael@0 | 40 | * If not called on the thread this object is attached to |
michael@0 | 41 | * @throws UnsupportedOperationException |
michael@0 | 42 | * If an internal JSAPI call failed |
michael@0 | 43 | */ |
michael@0 | 44 | public native boolean getBoolean(String name); |
michael@0 | 45 | |
michael@0 | 46 | /** |
michael@0 | 47 | * Returns the value of a boolean property. |
michael@0 | 48 | * |
michael@0 | 49 | * @param name |
michael@0 | 50 | * Property name |
michael@0 | 51 | * @param fallback |
michael@0 | 52 | * Value to return if property does not exist |
michael@0 | 53 | * @throws IllegalArgumentException |
michael@0 | 54 | * If the property exists and its type does not match the return type |
michael@0 | 55 | * @throws NullPointerException |
michael@0 | 56 | * If name is null or if this JS object has been disposed |
michael@0 | 57 | * @throws IllegalThreadStateException |
michael@0 | 58 | * If not called on the thread this object is attached to |
michael@0 | 59 | * @throws UnsupportedOperationException |
michael@0 | 60 | * If an internal JSAPI call failed |
michael@0 | 61 | */ |
michael@0 | 62 | public native boolean optBoolean(String name, boolean fallback); |
michael@0 | 63 | |
michael@0 | 64 | /** |
michael@0 | 65 | * Returns the value of a double property. |
michael@0 | 66 | * |
michael@0 | 67 | * @param name |
michael@0 | 68 | * Property name |
michael@0 | 69 | * @throws IllegalArgumentException |
michael@0 | 70 | * If the property does not exist or if its type does not match the return type |
michael@0 | 71 | * @throws NullPointerException |
michael@0 | 72 | * If name is null or if this JS object has been disposed |
michael@0 | 73 | * @throws IllegalThreadStateException |
michael@0 | 74 | * If not called on the thread this object is attached to |
michael@0 | 75 | * @throws UnsupportedOperationException |
michael@0 | 76 | * If an internal JSAPI call failed |
michael@0 | 77 | */ |
michael@0 | 78 | public native double getDouble(String name); |
michael@0 | 79 | |
michael@0 | 80 | /** |
michael@0 | 81 | * Returns the value of a double property. |
michael@0 | 82 | * |
michael@0 | 83 | * @param name |
michael@0 | 84 | * Property name |
michael@0 | 85 | * @param fallback |
michael@0 | 86 | * Value to return if property does not exist |
michael@0 | 87 | * @throws IllegalArgumentException |
michael@0 | 88 | * If the property exists and its type does not match the return type |
michael@0 | 89 | * @throws NullPointerException |
michael@0 | 90 | * If name is null or if this JS object has been disposed |
michael@0 | 91 | * @throws IllegalThreadStateException |
michael@0 | 92 | * If not called on the thread this object is attached to |
michael@0 | 93 | * @throws UnsupportedOperationException |
michael@0 | 94 | * If an internal JSAPI call failed |
michael@0 | 95 | */ |
michael@0 | 96 | public native double optDouble(String name, double fallback); |
michael@0 | 97 | |
michael@0 | 98 | /** |
michael@0 | 99 | * Returns the value of an int property. |
michael@0 | 100 | * |
michael@0 | 101 | * @param name |
michael@0 | 102 | * Property name |
michael@0 | 103 | * @throws IllegalArgumentException |
michael@0 | 104 | * If the property does not exist or if its type does not match the return type |
michael@0 | 105 | * @throws NullPointerException |
michael@0 | 106 | * If name is null or if this JS object has been disposed |
michael@0 | 107 | * @throws IllegalThreadStateException |
michael@0 | 108 | * If not called on the thread this object is attached to |
michael@0 | 109 | * @throws UnsupportedOperationException |
michael@0 | 110 | * If an internal JSAPI call failed |
michael@0 | 111 | */ |
michael@0 | 112 | public native int getInt(String name); |
michael@0 | 113 | |
michael@0 | 114 | /** |
michael@0 | 115 | * Returns the value of an int property. |
michael@0 | 116 | * |
michael@0 | 117 | * @param name |
michael@0 | 118 | * Property name |
michael@0 | 119 | * @param fallback |
michael@0 | 120 | * Value to return if property does not exist |
michael@0 | 121 | * @throws IllegalArgumentException |
michael@0 | 122 | * If the property exists and its type does not match the return type |
michael@0 | 123 | * @throws NullPointerException |
michael@0 | 124 | * If name is null or if this JS object has been disposed |
michael@0 | 125 | * @throws IllegalThreadStateException |
michael@0 | 126 | * If not called on the thread this object is attached to |
michael@0 | 127 | * @throws UnsupportedOperationException |
michael@0 | 128 | * If an internal JSAPI call failed |
michael@0 | 129 | */ |
michael@0 | 130 | public native int optInt(String name, int fallback); |
michael@0 | 131 | |
michael@0 | 132 | /** |
michael@0 | 133 | * Returns the value of an object property. |
michael@0 | 134 | * |
michael@0 | 135 | * @param name |
michael@0 | 136 | * Property name |
michael@0 | 137 | * @throws IllegalArgumentException |
michael@0 | 138 | * If the property does not exist or if its type does not match the return type |
michael@0 | 139 | * @throws NullPointerException |
michael@0 | 140 | * If name is null or if this JS object has been disposed |
michael@0 | 141 | * @throws IllegalThreadStateException |
michael@0 | 142 | * If not called on the thread this object is attached to |
michael@0 | 143 | * @throws UnsupportedOperationException |
michael@0 | 144 | * If an internal JSAPI call failed |
michael@0 | 145 | */ |
michael@0 | 146 | public native NativeJSObject getObject(String name); |
michael@0 | 147 | |
michael@0 | 148 | /** |
michael@0 | 149 | * Returns the value of an object property. |
michael@0 | 150 | * |
michael@0 | 151 | * @param name |
michael@0 | 152 | * Property name |
michael@0 | 153 | * @param fallback |
michael@0 | 154 | * Value to return if property does not exist |
michael@0 | 155 | * @throws IllegalArgumentException |
michael@0 | 156 | * If the property exists and its type does not match the return type |
michael@0 | 157 | * @throws NullPointerException |
michael@0 | 158 | * If name is null or if this JS object has been disposed |
michael@0 | 159 | * @throws IllegalThreadStateException |
michael@0 | 160 | * If not called on the thread this object is attached to |
michael@0 | 161 | * @throws UnsupportedOperationException |
michael@0 | 162 | * If an internal JSAPI call failed |
michael@0 | 163 | */ |
michael@0 | 164 | public native NativeJSObject optObject(String name, NativeJSObject fallback); |
michael@0 | 165 | |
michael@0 | 166 | /** |
michael@0 | 167 | * Returns the value of a string property. |
michael@0 | 168 | * |
michael@0 | 169 | * @param name |
michael@0 | 170 | * Property name |
michael@0 | 171 | * @throws IllegalArgumentException |
michael@0 | 172 | * If the property does not exist or if its type does not match the return type |
michael@0 | 173 | * @throws NullPointerException |
michael@0 | 174 | * If name is null or if this JS object has been disposed |
michael@0 | 175 | * @throws IllegalThreadStateException |
michael@0 | 176 | * If not called on the thread this object is attached to |
michael@0 | 177 | * @throws UnsupportedOperationException |
michael@0 | 178 | * If an internal JSAPI call failed |
michael@0 | 179 | */ |
michael@0 | 180 | public native String getString(String name); |
michael@0 | 181 | |
michael@0 | 182 | /** |
michael@0 | 183 | * Returns the value of a string property. |
michael@0 | 184 | * |
michael@0 | 185 | * @param name |
michael@0 | 186 | * Property name |
michael@0 | 187 | * @param fallback |
michael@0 | 188 | * Value to return if property does not exist |
michael@0 | 189 | * @throws IllegalArgumentException |
michael@0 | 190 | * If the property exists and its type does not match the return type |
michael@0 | 191 | * @throws NullPointerException |
michael@0 | 192 | * If name is null or if this JS object has been disposed |
michael@0 | 193 | * @throws IllegalThreadStateException |
michael@0 | 194 | * If not called on the thread this object is attached to |
michael@0 | 195 | * @throws UnsupportedOperationException |
michael@0 | 196 | * If an internal JSAPI call failed |
michael@0 | 197 | */ |
michael@0 | 198 | public native String optString(String name, String fallback); |
michael@0 | 199 | |
michael@0 | 200 | /** |
michael@0 | 201 | * Returns whether a property exists in this object |
michael@0 | 202 | * |
michael@0 | 203 | * @param name |
michael@0 | 204 | * Property name |
michael@0 | 205 | * @throws NullPointerException |
michael@0 | 206 | * If name is null or if this JS object has been disposed |
michael@0 | 207 | * @throws IllegalThreadStateException |
michael@0 | 208 | * If not called on the thread this object is attached to |
michael@0 | 209 | * @throws UnsupportedOperationException |
michael@0 | 210 | * If an internal JSAPI call failed |
michael@0 | 211 | */ |
michael@0 | 212 | public native boolean has(String name); |
michael@0 | 213 | |
michael@0 | 214 | /** |
michael@0 | 215 | * Returns the JSON representation of this object. |
michael@0 | 216 | * |
michael@0 | 217 | * @throws NullPointerException |
michael@0 | 218 | * If this JS object has been disposed |
michael@0 | 219 | * @throws IllegalThreadStateException |
michael@0 | 220 | * If not called on the thread this object is attached to |
michael@0 | 221 | * @throws UnsupportedOperationException |
michael@0 | 222 | * If an internal JSAPI call failed |
michael@0 | 223 | */ |
michael@0 | 224 | @Override |
michael@0 | 225 | public native String toString(); |
michael@0 | 226 | } |