@mikrojs/quickjs 0.17.0 → 0.17.1-next.20260731001908

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1598,6 +1598,15 @@ static void js_trigger_gc(JSRuntime *rt, size_t size)
1598
1598
  JS_RunGC(rt);
1599
1599
  rt->malloc_gc_threshold = rt->malloc_state.malloc_size +
1600
1600
  (rt->malloc_state.malloc_size >> 1);
1601
+ /* mikrojs patch: never re-arm the threshold above the memory limit,
1602
+ else a single long job whose live size exceeds ~2/3 of the limit
1603
+ accumulates collectible garbage straight into OOM. */
1604
+ if (rt->malloc_state.malloc_limit &&
1605
+ rt->malloc_gc_threshold >
1606
+ rt->malloc_state.malloc_limit - (rt->malloc_state.malloc_limit >> 3)) {
1607
+ rt->malloc_gc_threshold =
1608
+ rt->malloc_state.malloc_limit - (rt->malloc_state.malloc_limit >> 3);
1609
+ }
1601
1610
  }
1602
1611
  }
1603
1612
 
@@ -31238,9 +31247,19 @@ done:
31238
31247
  goto done;
31239
31248
  }
31240
31249
 
31250
+ /* mikrojs patch: once a module reaches EVALUATED its init function can
31251
+ never run again; drop the bytecode so top-level-only code is reclaimed.
31252
+ Live closures and export binding var_refs hold their own references. */
31253
+ static void js_module_release_func(JSContext *ctx, JSModuleDef *m)
31254
+ {
31255
+ JS_FreeValue(ctx, m->func_obj);
31256
+ m->func_obj = JS_UNDEFINED;
31257
+ }
31258
+
31241
31259
  static void js_set_module_evaluated(JSContext *ctx, JSModuleDef *m)
31242
31260
  {
31243
31261
  m->status = JS_MODULE_STATUS_EVALUATED;
31262
+ js_module_release_func(ctx, m);
31244
31263
  if (!JS_IsUndefined(m->promise)) {
31245
31264
  JSValue ret_val;
31246
31265
  assert(m->cycle_root == m);
@@ -31335,6 +31354,7 @@ static JSValue js_async_module_execution_rejected(JSContext *ctx, JSValueConst t
31335
31354
  module->eval_has_exception = true;
31336
31355
  module->eval_exception = js_dup(error);
31337
31356
  module->status = JS_MODULE_STATUS_EVALUATED;
31357
+ js_module_release_func(ctx, module);
31338
31358
 
31339
31359
  for(i = 0; i < module->async_parent_modules_count; i++) {
31340
31360
  JSModuleDef *m = module->async_parent_modules[i];
@@ -31564,6 +31584,7 @@ static int js_inner_module_evaluation(JSContext *ctx, JSModuleDef *m,
31564
31584
  *pstack_top = m1->stack_prev;
31565
31585
  if (!m1->async_evaluation) {
31566
31586
  m1->status = JS_MODULE_STATUS_EVALUATED;
31587
+ js_module_release_func(ctx, m1);
31567
31588
  } else {
31568
31589
  m1->status = JS_MODULE_STATUS_EVALUATING_ASYNC;
31569
31590
  }
@@ -31604,6 +31625,7 @@ static JSValue js_evaluate_module(JSContext *ctx, JSModuleDef *m)
31604
31625
  m1 = stack_top;
31605
31626
  assert(m1->status == JS_MODULE_STATUS_EVALUATING);
31606
31627
  m1->status = JS_MODULE_STATUS_EVALUATED;
31628
+ js_module_release_func(ctx, m1);
31607
31629
  m1->eval_has_exception = true;
31608
31630
  m1->eval_exception = js_dup(result);
31609
31631
  m1->cycle_root = m; /* spec bug: should be present */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikrojs/quickjs",
3
- "version": "0.17.0",
3
+ "version": "0.17.1-next.20260731001908",
4
4
  "description": "QuickJS-NG engine source, shared CMake module, and qjsc bytecode compiler",
5
5
  "keywords": [
6
6
  "bytecode",
package/quickjs.cmake CHANGED
@@ -28,6 +28,31 @@ endif()
28
28
  get_filename_component(_QUICKJS_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY)
29
29
  set(QUICKJS_INCLUDE_DIR "${_QUICKJS_CMAKE_DIR}/deps/quickjs")
30
30
 
31
+ # Apply the mikrojs patch series before anything compiles QuickJS sources.
32
+ # postinstall covers `pnpm install`, but a patch file added or edited after
33
+ # install was previously a silent no-op: the tree built unpatched and the
34
+ # full test suite ran against code the patch never touched. apply-patches.js
35
+ # is stamp-guarded so this is cheap when nothing changed; the GLOB's
36
+ # CONFIGURE_DEPENDS reruns configure when the patch set changes, and
37
+ # CMAKE_CONFIGURE_DEPENDS reruns it when patch contents change.
38
+ #
39
+ # Guarded for CMake script mode: ESP-IDF's early component-requirements
40
+ # pass includes component CMakeLists (and through them this file) via
41
+ # script-mode CMake, where CONFIGURE_DEPENDS globs and directory
42
+ # properties are hard errors. The real project-mode configure that
43
+ # follows runs the sync; the requirements pass only needs the variables.
44
+ if(NOT CMAKE_SCRIPT_MODE_FILE)
45
+ file(GLOB _QUICKJS_PATCHES CONFIGURE_DEPENDS "${_QUICKJS_CMAKE_DIR}/patches/*.patch")
46
+ set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${_QUICKJS_PATCHES})
47
+ execute_process(
48
+ COMMAND node "${_QUICKJS_CMAKE_DIR}/apply-patches.js"
49
+ RESULT_VARIABLE _QUICKJS_PATCH_RC
50
+ )
51
+ if(NOT _QUICKJS_PATCH_RC EQUAL 0)
52
+ message(FATAL_ERROR "quickjs.cmake: applying QuickJS patches failed (see output above)")
53
+ endif()
54
+ endif()
55
+
31
56
  # Source files
32
57
  set(QUICKJS_SOURCES
33
58
  "${QUICKJS_INCLUDE_DIR}/quickjs.c"