Skip to content

Commit

Permalink
Fix ValueDeserializer::read_value() lifetime
Browse files Browse the repository at this point in the history
The return value should have the lifetime of the context, not the
deserializer.

Fixes denoland#607.
  • Loading branch information
bnoordhuis committed Feb 9, 2021
1 parent d60489c commit ae8dc8f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/value_deserializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,10 @@ pub trait ValueDeserializerHelper {
.into()
}

fn read_value(&mut self, context: Local<Context>) -> Option<Local<Value>> {
fn read_value<'s>(
&mut self,
context: Local<'s, Context>,
) -> Option<Local<'s, Value>> {
unsafe {
Local::from_raw(v8__ValueDeserializer__ReadValue(
self.get_cxx_value_deserializer(),
Expand Down Expand Up @@ -413,10 +416,10 @@ impl<'a, 's> ValueDeserializer<'a, 's> {
}
}

pub fn read_value(
pub fn read_value<'t>(
&mut self,
context: Local<Context>,
) -> Option<Local<Value>> {
context: Local<'t, Context>,
) -> Option<Local<'t, Value>> {
(*self.value_deserializer_heap).read_value(context)
}
}
2 changes: 2 additions & 0 deletions tests/test_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4240,6 +4240,7 @@ fn value_serializer_and_deserializer_js_objects() {
let name = v8::String::new(scope, "objects").unwrap();
let objects: v8::Local<v8::Value> =
value_deserializer.read_value(context).unwrap();
drop(value_deserializer);

context.global(scope).set(scope, name.into(), objects);

Expand Down Expand Up @@ -4343,6 +4344,7 @@ fn value_serializer_and_deserializer_array_buffers() {
let name = v8::String::new(scope, "objects").unwrap();
let objects: v8::Local<v8::Value> =
value_deserializer.read_value(context).unwrap();
drop(value_deserializer);

context.global(scope).set(scope, name.into(), objects);

Expand Down

0 comments on commit ae8dc8f

Please sign in to comment.