quickjs 0.22.0 → 0.22.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 506c4bf5a42bbbcd0609160663a6ce2fcf2e577f2838c82ec8e33f29932d80c2
4
- data.tar.gz: 2a80c962744fb3626a82bb5eb6714223298ca209b5a9a657903530a1eb50bedd
3
+ metadata.gz: 7a8e20ce6a80fc1a0a8bb7ef208721cd0ee17526ceb0efc91f92ccb04e24906a
4
+ data.tar.gz: 2eb884bd5df4447be1fba2fa918d4c8d92e3ce245d7c79157060d4ed0c53be36
5
5
  SHA512:
6
- metadata.gz: d6036f838b27d9b5da95117fb45af91c18eb09510ec6d16de6f5c798c42cfb93954359a8a70a3a5417a53c3f29df4bac0e86528e24e9423379bf0109a746a546
7
- data.tar.gz: 13c6520708931be4c9c3bb4f3772955e456a194134cb2e1cff3c608765a755f32ee0fc0496ab353ae70f60e974b8cc5f18817f0086fc998de639391ce6e496d7
6
+ metadata.gz: 4f2fbf1912c1137b2e2a1476ccd386ec8c75ffb084d5942c04ff808e38be41aeecd42b392f93e17a6e9f221d36d1625087a1646491afa86b9ebc4c0a0442bf36
7
+ data.tar.gz: 727ca2377e95c75f64208d340fb8919adbf43ea64ec87a5a82cd88aa03ee7f2bac8ae3ef547bab56117368208f5adb3aa20e2d6e98fc36673674864ae4935e0f
data/README.md CHANGED
@@ -516,7 +516,8 @@ vm.memory_usage
516
516
  # atom_count: Integer, str_count: Integer, obj_count: Integer,
517
517
  # prop_count: Integer, shape_count: Integer,
518
518
  # js_func_count: Integer, js_func_code_size: Integer,
519
- # c_func_count: Integer, array_count: Integer }
519
+ # c_func_count: Integer, array_count: Integer,
520
+ # alloc_refusals: Integer }
520
521
 
521
522
  vm.gc! # trigger a QuickJS GC cycle; returns nil
522
523
 
@@ -526,6 +527,14 @@ vm.poisoned? #=> false (true when the VM has stopped accepting work, for
526
527
 
527
528
  When the JS heap exhausts its memory limit, QuickJS enters a fragile state where further evaluation can segfault the process. `memory_poisoned?` flips to `true` after such an event, and subsequent `eval_code` / `call` calls raise `Quickjs::RuntimeError` immediately instead of risking a crash. Rescue it and recreate the VM.
528
529
 
530
+ The flag takes two things together, and neither on its own. The allocator must have actually refused an allocation during the call, which no JavaScript can bring about by saying so, and QuickJS must be the one reporting it: its own out-of-memory error, an error whose message it could not afford to build, or no error object at all. So JavaScript that merely throws an error reading `out of memory` leaves the VM alone, and a real exhaustion is still caught at either end where there is nothing left to read, whether it arrives as a throw or as a promise rejection.
531
+
532
+ `alloc_refusals` in `memory_usage` counts the allocations this VM asked for and did not get. QuickJS carries on correctly through some of them, so a nonzero count is not by itself a VM in trouble; it is the one number that says the ceiling was reached at all, which `malloc_size` cannot once the failed allocation has been rolled back.
533
+
534
+ Whatever the guest says for itself is reported as itself. JavaScript that catches its own out-of-memory and then throws a `TypeError`, or hands you a rejection carrying its own error, or runs past its `timeout_msec`, gets that error and keeps its VM, exactly as it would have without the earlier exhaustion. The heap is condemned when QuickJS says the heap is the problem, and not when the guest happens to fail next.
535
+
536
+ One asymmetry to know about: an exhaustion that arrives as a promise rejection is judged when the rejection is seen with no handler attached, so `f().catch(() => {})` around a real exhaustion condemns the VM where the synchronous `try { … } catch {}` around the same allocation does not. Nothing revisits that verdict once a handler attaches. A handler attached before the rejection happens, as in `async function f() { await null; BIG }`, is never seen by it at all and leaves the VM alone.
537
+
529
538
  A VM can also stop accepting work for a reason recreating it will not fix. `poisoned?` answers for any of them, `memory_poisoned?` only for out-of-memory, so the recycle path below tests the narrower one on purpose: if `poisoned?` is true while `memory_poisoned?` is false, a new VM will refuse in the same way and the failure belongs to the host. The one case today is `SecureRandom.random_number` no longer returning distinct integers, which leaves objects crossing into JS with no handle a guest cannot guess; the raised message says so.
530
539
 
531
540
  ```rb
@@ -11,7 +11,7 @@ $srcs = [
11
11
  'libregexp.c',
12
12
  'cutils.c',
13
13
  'quickjs.c',
14
- 'quickjs-libc.c',
14
+ 'quickjsrb_libc.c',
15
15
  'polyfill-file.min.c',
16
16
  'polyfill-encoding.min.c',
17
17
  'polyfill-url.min.c',