File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -205,6 +205,35 @@ impl Context {
205205 }
206206
207207 /// Execute the pending job in the event loop.
208+ /// Update the QuickJS runtime's stack top reference to the current native
209+ /// stack pointer.
210+ ///
211+ /// This should be called before any JS execution when entering from Rust,
212+ /// so that QuickJS measures the JS stack depth from the current position
213+ /// rather than from wherever the runtime was first created.
214+ ///
215+ /// This is especially important in debug builds where Rust/C frames are
216+ /// significantly larger than in release builds.
217+ pub fn update_stack_top ( & self ) {
218+ unsafe {
219+ q:: JS_UpdateStackTop ( self . runtime ) ;
220+ }
221+ }
222+
223+ /// Set the maximum JS stack size (in bytes).
224+ ///
225+ /// The default is 1MB. In debug builds the QuickJS C interpreter frames
226+ /// are unoptimized and consume more native stack per JS call, so a larger
227+ /// limit (e.g. 4MB) may be required to run the same code that works fine
228+ /// in release builds.
229+ ///
230+ /// Use `0` to disable the stack size limit entirely.
231+ pub fn set_max_stack_size ( & self , size : usize ) {
232+ unsafe {
233+ q:: JS_SetMaxStackSize ( self . runtime , size) ;
234+ }
235+ }
236+
208237 pub fn execute_pending_job ( & self ) -> Result < ( ) , ExecutionError > {
209238 let mut pctx = Box :: new ( std:: ptr:: null_mut :: < JSContext > ( ) ) ;
210239 unsafe {
You can’t perform that action at this time.
0 commit comments