File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed
java/com/hippo/quickjs/android Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,18 @@ Java_com_hippo_quickjs_android_QuickJS_setRuntimeMallocLimit(
4747 JS_SetMemoryLimit (qj_rt -> rt , (size_t ) malloc_limit );
4848}
4949
50+ JNIEXPORT void JNICALL
51+ Java_com_hippo_quickjs_android_QuickJS_setRuntimeMaxStackSize (
52+ JNIEnv * env ,
53+ jclass __unused clazz ,
54+ jlong runtime ,
55+ jint stack_size
56+ ) {
57+ QJRuntime * qj_rt = (QJRuntime * ) runtime ;
58+ CHECK_NULL (env , qj_rt , MSG_NULL_JS_RUNTIME );
59+ JS_SetMaxStackSize (qj_rt -> rt , (size_t ) stack_size );
60+ }
61+
5062static int on_interrupt (JSRuntime __unused * rt , void * opaque ) {
5163 int result = 0 ;
5264
Original file line number Diff line number Diff line change @@ -59,6 +59,21 @@ public synchronized void setMallocLimit(int mallocLimit) {
5959 QuickJS .setRuntimeMallocLimit (pointer , mallocLimit );
6060 }
6161
62+ /**
63+ * Set max stack size for this JSRuntime.
64+ * Only positive number and {@code 0} are accepted.
65+ * {@code 0} for no stack size check.
66+ */
67+ public synchronized void setMaxStackSize (int stackSize ) {
68+ checkClosed ();
69+
70+ if (stackSize < 0 ) {
71+ throw new IllegalArgumentException ("Only positive number and 0 are accepted as max stack size" );
72+ }
73+
74+ QuickJS .setRuntimeMaxStackSize (pointer , stackSize );
75+ }
76+
6277 /**
6378 * Set the InterruptHandler for this JSRuntime.
6479 * {@link InterruptHandler#onInterrupt()} is called every 10000 js instructions.
Original file line number Diff line number Diff line change @@ -109,6 +109,7 @@ public QuickJS build() {
109109
110110 static native long createRuntime ();
111111 static native void setRuntimeMallocLimit (long runtime , int mallocLimit );
112+ static native void setRuntimeMaxStackSize (long runtime , int stackSize );
112113 static native void setRuntimeInterruptHandler (long runtime , JSRuntime .InterruptHandler interruptHandler );
113114 static native void destroyRuntime (long runtime );
114115
You can’t perform that action at this time.
0 commit comments