-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issues between reference counting and the custom
JSON.parse
imp…
…lementation (#673) * Introduce a minimal failing test This commit introduces a minimal failing test case where SIMD JSON parsing and reference couting causes a panic. Analysis: Even though our fork of rquickjs disallows GC, it doesn't prevent reference counting. This, combined with the usage of `JS_DefinePropertyValue` which decrements the reference count of each String value inside a map, introduced the bug showcased in this commit. * Fix issues with reference counting and SIMD JSON (parsing) This commit is follow-up to the previous commit, in which the relationship between reference counting and String Object value creation is fixed by: - Avoiding the usage of `unsafe` APIs - Ensuring that everytime a string value gets created it gets correctly taken into acount. Using rquickjs' safe APIs ensures that new values get cloned, which means that `JS_DupValue` is called, which correctly increases the reference count. * Gate the misc test with #[cfg(feature = 'json')] * Clippy fixes
- Loading branch information
1 parent
78e5e9d
commit 21e7c97
Showing
3 changed files
with
38 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use anyhow::Result; | ||
use javy::{quickjs::context::EvalOptions, Config, Runtime}; | ||
|
||
#[cfg(feature = "json")] | ||
#[test] | ||
fn string_keys_and_ref_counting() -> Result<()> { | ||
let mut config = Config::default(); | ||
config.override_json_parse_and_stringify(true); | ||
|
||
let source = include_bytes!("string_keys_and_ref_counting.js"); | ||
let rt = Runtime::new(config)?; | ||
|
||
rt.context().with(|this| { | ||
let _: () = this | ||
.eval_with_options(*source, EvalOptions::default()) | ||
.inspect_err(|e| println!("{e}")) | ||
.expect("source evaluation to succeed"); | ||
}); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const input = JSON.parse('{"elements":[{"id":"zza"},{"id":"zzb"},{"id":"zzc"},{"id":"zzd"},{"id":"zze"}]}'); | ||
|
||
const acc = {}; | ||
input.elements.forEach(e => { | ||
if (!acc[e.id]) { | ||
acc[e.id] = 1; | ||
} | ||
}); |