denoland / rusty_v8

Rust bindings for the V8 JavaScript engine
https://crates.io/crates/v8
MIT License
3.08k stars 299 forks source link

Add non-static external onebyte string #1511

Closed nathanwhit closed 1 week ago

nathanwhit commented 1 week ago

We currently have static and const external onebyte strings, but these effectively leak memory (and so we can't use them extensively. This PR adds an ExternalOneByteString class which frees the underlying memory when V8 destroys the string (it's just a matter of overriding the destructor really). This allows passing latin1 rust strings created at runtime to v8 without copying (or leaking memory).

Additionally, this adds an API to get an external one byte string and call virtual methods on it.

Also fixes some issues with the existing get_external_string_resource_base function, which was using an Encoding type with incorrect enum values (which caused a segfault whenever you tried to actually read the encoding from rust).

CLAassistant commented 1 week ago

CLA assistant check
All committers have signed the CLA.