0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-11-25 15:29:43 -05:00

Fix bug in v8::create_message() argument lifetimes (#212)

This commit is contained in:
Bert Belder 2020-01-17 02:19:06 +01:00
parent f650abe44e
commit b09df9b552
No known key found for this signature in database
GPG key ID: 7A77887B2E2ED461
2 changed files with 42 additions and 3 deletions

View file

@ -58,7 +58,7 @@ extern "C" {
fn v8__Exception__CreateMessage(
isolate: &Isolate,
exception: *mut Value,
exception: Local<Value>,
) -> *mut Message;
fn v8__Exception__GetStackTrace(exception: *mut Value) -> *mut StackTrace;
@ -267,10 +267,10 @@ impl Message {
/// or capture the current stack trace if not available.
pub fn create_message<'sc>(
scope: &mut impl ToLocal<'sc>,
mut exception: Local<'sc, Value>,
exception: Local<Value>,
) -> Local<'sc, Message> {
let isolate = scope.isolate();
let ptr = unsafe { v8__Exception__CreateMessage(isolate, &mut *exception) };
let ptr = unsafe { v8__Exception__CreateMessage(isolate, exception) };
unsafe { scope.to_local(ptr) }.unwrap()
}

View file

@ -817,6 +817,45 @@ fn exception() {
context.exit();
}
#[test]
fn create_message_argument_lifetimes() {
setup();
let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let mut hs = v8::HandleScope::new(&mut locker);
let scope = hs.enter();
let mut context = v8::Context::new(scope);
context.enter();
{
let mut create_message = v8::Function::new(
scope,
context,
|scope: v8::FunctionCallbackScope,
args: v8::FunctionCallbackArguments,
mut rv: v8::ReturnValue| {
let message = v8::create_message(scope, args.get(0));
let message_str = message.get(scope);
rv.set(message_str.into())
},
)
.unwrap();
let receiver = context.global(scope);
let message_str = v8::String::new(scope, "mishap").unwrap();
let exception = v8::type_error(scope, message_str);
let actual = create_message
.call(scope, context, receiver.into(), 1, vec![exception])
.unwrap();
let expected =
v8::String::new(scope, "Uncaught TypeError: mishap").unwrap();
assert!(actual.strict_equals(expected.into()));
}
context.exit();
}
#[test]
fn json() {
setup();