From 5cb14847aa6c0aae11f580e69e3630aa61f80422 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 13 Jan 2021 00:49:59 +0100 Subject: [PATCH] Expose v8::WriteOptions (#583) Without it, v8::String::write_utf8() is pretty much unusable. --- src/lib.rs | 1 + tests/test_api.rs | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 755894b2..cde42290 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -127,6 +127,7 @@ pub use snapshot::FunctionCodeHandling; pub use snapshot::SnapshotCreator; pub use snapshot::StartupData; pub use string::NewStringType; +pub use string::WriteOptions; pub use support::SharedPtr; pub use support::SharedRef; pub use support::UniquePtr; diff --git a/tests/test_api.rs b/tests/test_api.rs index eb6360f3..37b308e0 100644 --- a/tests/test_api.rs +++ b/tests/test_api.rs @@ -156,6 +156,15 @@ fn test_string() { assert_eq!(15, local.length()); assert_eq!(17, local.utf8_length(scope)); assert_eq!(reference, local.to_rust_string_lossy(scope)); + let mut vec = Vec::new(); + vec.resize(17, 0); + let options = v8::WriteOptions::NO_NULL_TERMINATION; + let mut nchars = 0; + assert_eq!( + 17, + local.write_utf8(scope, &mut vec, Some(&mut nchars), options) + ); + assert_eq!(15, nchars); } { let scope = &mut v8::HandleScope::new(isolate);