You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Non-static methods and static methods are supported. Wrap a Java method as a JSFunction, then add the JSFunction to the JSContext. Call it like a normal Javascript function.
int result = context.evaluate("plus(1, 2)", "test.js", Integer.class);
79
-
assertThat(result).isEqualTo(3);
80
-
}
81
-
}
82
-
```
83
-
84
-
### Call Javascript Methods in Java codes
85
-
86
-
Just **evaluate** it. Or call `JSFunction.invoke()`.
87
-
88
-
### Promise
89
-
90
-
Use `JSContext.executePendingJob()` to execute pending job of promises. You may call `JSContext.executePendingJob()` several times until it returns `false`.
### Conversion between Java Values and Javascript Values
108
-
109
-
Java values are converted to Javascript values when calling Java methods in Javascript scripts. Javascript values are converted to a Java values when receiving return values from evaluated Javascript scripts. QuickJS Android supports primitive types, string, array.
1. Even when operating in bytecode mode, QuickJS's evaluation time is notably higher than V8's, and this disparity intensifies as the JavaScript file size increases.
185
55
2. QuickJS's initialization time is slightly lower than V8's, and this advantage is constant despite of file sizes.
186
56
187
-
## Concept
188
-
189
-
QuickJS Android uses the similar APIs to QuickJS.
190
-
191
-
### JSRuntime
192
-
193
-
> JSRuntime represents a Javascript runtime corresponding to an object heap. Several runtimes can exist at the same time but they cannot exchange objects. Inside a given runtime, no multi-threading is supported.
194
-
>
195
-
> -- QuickJS Document
196
-
197
-
### JSContext
198
-
199
-
> JSContext represents a Javascript context (or Realm). Each JSContext has its own global objects and system objects. There can be several JSContexts per JSRuntime and they can share objects, similar to frames of the same origin sharing Javascript objects in a web browser.
200
-
>
201
-
> -- QuickJS Document
202
-
203
-
### JSValue
204
-
205
-
> JSValue represents a Javascript value which can be a primitive type or an object.
206
-
>
207
-
> -- QuickJS Document
208
-
209
-
Available subclasses of `JSValue` are `JSNull`, `JSUndefined`, `JSBoolean`, `JSNumber`, `JSString`, `JSObject`, `JSArray`, `JSFunction`, `JSSymbol`.
210
-
211
-
## Test
212
-
213
-
The original tests and benchmarks of QuickJS are in [android-test](android-test). It's a console-like app running all tests and benchmarks at startup, like `make test`.
214
-
215
57
## Acknowledgement
216
58
217
59
1.[bellard/quickjs](https://github.com/bellard/quickjs) QuickJS official repository.
> JSRuntime represents a Javascript runtime corresponding to an object heap. Several runtimes can exist at the same time but they cannot exchange objects. Inside a given runtime, no multi-threading is supported.
10
+
>
11
+
> -- QuickJS Document
12
+
13
+
### JSContext
14
+
15
+
> JSContext represents a Javascript context (or Realm). Each JSContext has its own global objects and system objects. There can be several JSContexts per JSRuntime and they can share objects, similar to frames of the same origin sharing Javascript objects in a web browser.
16
+
>
17
+
> -- QuickJS Document
18
+
19
+
### JSValue
20
+
21
+
> JSValue represents a Javascript value which can be a primitive type or an object.
22
+
>
23
+
> -- QuickJS Document
24
+
25
+
Available subclasses of `JSValue` are `JSNull`, `JSUndefined`, `JSBoolean`, `JSNumber`, `JSString`, `JSObject`, `JSArray`, `JSFunction`, `JSSymbol`.
int result = context.evaluate(script2, "fibonacci.js", int.class);
46
+
assertEquals(55, result);
47
+
}
48
+
}
49
+
```
50
+
51
+
### Call Java Methods in Javascript Scripts
52
+
53
+
Non-static methods and static methods are supported. Wrap a Java method as a JSFunction, then add the JSFunction to the JSContext. Call it like a normal Javascript function.
int result = context.evaluate("plus(1, 2)", "test.js", Integer.class);
93
+
assertThat(result).isEqualTo(3);
94
+
}
95
+
}
96
+
```
97
+
98
+
### Call Javascript Methods in Java codes
99
+
100
+
Just **evaluate** it. Or call `JSFunction.invoke()`.
101
+
102
+
### Promise
103
+
104
+
Use `JSContext.executePendingJob()` to execute pending job of promises. You may call `JSContext.executePendingJob()` several times until it returns `false`.
### Conversion between Java Values and Javascript Values
122
+
123
+
Java values are converted to Javascript values when calling Java methods in Javascript scripts. Javascript values are converted to a Java values when receiving return values from evaluated Javascript scripts. QuickJS Android supports primitive types, string, array.
0 commit comments