Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial support for external v8 strings #641

Merged
merged 9 commits into from
Mar 7, 2021
Prev Previous commit
Next Next commit
tests: add basic external_strings test
AaronO committed Mar 7, 2021
commit f755651ea428f9ed019746ef3c726d2a2cb25fe7
26 changes: 26 additions & 0 deletions tests/test_api.rs
Original file line number Diff line number Diff line change
@@ -4894,3 +4894,29 @@ fn code_cache() {
.unwrap();
assert_eq!(&value.to_rust_string_lossy(&mut scope), "world");
}

#[test]
fn external_strings() {
let _setup_guard = setup();
let isolate = &mut v8::Isolate::new(Default::default());
{
let scope = &mut v8::HandleScope::new(isolate);
let context = v8::Context::new(scope);
let scope = &mut v8::ContextScope::new(scope, context);

// Parse JSON from an external string
let json_static = "{\"a\": 1, \"b\": 2}";
let json_external =
v8::String::new_external_onebyte_static(scope, json_static).unwrap();
let maybe_value = v8::json::parse(scope, json_external);
assert!(maybe_value.is_some());
// Check length
assert!(json_external.length() == 16);

// In & out
let hello =
v8::String::new_external_onebyte_static(scope, "hello world").unwrap();
let rust_str = hello.to_rust_string_lossy(scope);
assert_eq!(rust_str, "hello world");
}
}