|
30 | 30 | * is that a JavaScript object is not normally an instance of any Java class, and it therefore
|
31 | 31 | * cannot be represented as a data-type in Java programs. When the JavaScript code (invoked by the
|
32 | 32 | * method annotated with the {@link JS} annotation) returns a JavaScript object, that object gets
|
33 |
| - * wrapped into <code>JSObject</code> instance. The <code>JSObject</code> allows the Java code to |
| 33 | + * wrapped into a <code>JSObject</code> instance. The <code>JSObject</code> allows the Java code to |
34 | 34 | * access the fields of the underlying JavaScript object using the <code>get</code> and
|
35 | 35 | * <code>set</code> methods.
|
36 | 36 | *
|
|
123 | 123 | *
|
124 | 124 | * Directly exposing a Java object to JavaScript code means that the JavaScript code is able to
|
125 | 125 | * manipulate the data within the object (e.g. mutate fields, add new fields, or redefine existing
|
126 |
| - * fields), which is not allowed by default for regular Java classes translated by Web Image. |
127 |
| - * Extending {@link JSObject} furthermore allows the JavaScript code to instantiate objects of the |
128 |
| - * {@link JSObject} subclass. One of the use-cases for these functionalities are JavaScript |
129 |
| - * frameworks that redefine properties of JavaScript objects with custom getters and setters, with |
130 |
| - * the goal of enabling data-binding or reactive updates. |
| 126 | + * fields), which is not allowed by default for regular Java classes. Extending {@link JSObject} |
| 127 | + * furthermore allows the JavaScript code to instantiate objects of the {@link JSObject} subclass. |
| 128 | + * One of the use-cases for these functionalities are JavaScript frameworks that redefine properties |
| 129 | + * of JavaScript objects with custom getters and setters, with the goal of enabling data-binding or |
| 130 | + * reactive updates. |
131 | 131 | *
|
132 | 132 | * In a subclass of {@link JSObject}, every JavaScript property directly corresponds to the Java
|
133 | 133 | * field of the same name. Consequently, all these properties point to native JavaScript values
|
134 |
| - * rather than Java values, so Web Image generates bridge methods that are called instead of |
135 |
| - * property accesses and that convert native JavaScript values to their Java counterparts. The |
136 |
| - * conversion rules are the same as in a {@link JS}-annotated method. Furthermore, note that |
137 |
| - * JavaScript code can violate the Java type-safety by storing into some property a value that is |
138 |
| - * not compatible with the corresponding Java field. For this reason, the bridge methods also |
139 |
| - * generate check-casts on every access: if the JavaScript property that corresponds to the Java |
140 |
| - * field does not contain a compatible value, a {@link ClassCastException} is thrown. |
141 |
| - * |
142 |
| - * There are several restrictions that Web Image imposes on {@link JSObject} subclasses: |
| 134 | + * rather than Java values, so bridge methods are generated that are called for each property access |
| 135 | + * and that convert native JavaScript values to their Java counterparts. The conversion rules are |
| 136 | + * the same as in a {@link JS}-annotated method. Furthermore, note that JavaScript code can violate |
| 137 | + * the Java type-safety by storing into some property a value that is not compatible with the |
| 138 | + * corresponding Java field. For this reason, the bridge methods also generate check-casts on every |
| 139 | + * access: if the JavaScript property that corresponds to the Java field does not contain a |
| 140 | + * compatible value, a {@link ClassCastException} is thrown. |
| 141 | + * |
| 142 | + * There are several restrictions imposed on {@link JSObject} subclasses: |
143 | 143 | * <ul>
|
144 |
| - * <li>Only public and protected fields are exposed to JavaScript. This restriction ensures |
145 |
| - * encapsulation, and also ensures that users cannot introduce two private fields of the same name |
146 |
| - * within the same inheritance lineage.</li> |
147 |
| - * <li>Subclasses of this class are only allowed to have non-final fields. This restriction ensures |
148 |
| - * that JavaScript code cannot inadvertently change the property that corresponds to a final |
149 |
| - * field.</li> |
| 144 | + * <li>Only public and protected fields are allowed to ensure encapsulation.</li> |
| 145 | + * <li>Instance fields must not be {@code final}. This restriction ensures that JavaScript code |
| 146 | + * cannot inadvertently change the property that corresponds to a final field.</li> |
150 | 147 | * </ul>
|
151 | 148 | *
|
152 | 149 | * <b>Example:</b> consider the following <code>JSObject</code> subclass:
|
|
172 | 169 | * <pre>
|
173 | 170 | * class Point {
|
174 | 171 | * constructor(x, y){
|
175 |
| - * this.x=x; |
176 |
| - * this.y=y; |
| 172 | + * this.x=x; |
| 173 | + * this.y=y; |
177 | 174 | * }
|
178 | 175 | *
|
179 | 176 | * absolute() {
|
|
225 | 222 | * </pre>
|
226 | 223 | *
|
227 | 224 | * A {@link Class} object that represents {@link JSObject} can also be passed to JavaScript code.
|
228 |
| - * The {@link Class} object is converted to its JavaScript representation, which is the JavaScript |
229 |
| - * class constructor. The JavaScript class constructor can be used inside a {@code new} expression |
| 225 | + * The {@link Class} object is wrapped in a proxy, which can be used inside a {@code new} expression |
230 | 226 | * to instantiate the object of the corresponding class from JavaScript.
|
231 | 227 | *
|
232 | 228 | * <b>Example:</b> the following code creates a {@code Point} object in JavaScript:
|
|
0 commit comments