0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-11-24 15:19:31 -05:00

Implicitly enter Isolate in v8::error (#191)

This commit is contained in:
Bartek Iwańczuk 2020-01-05 18:07:50 +01:00 committed by Bert Belder
parent a76339a59c
commit bddefbc2b2
2 changed files with 46 additions and 32 deletions

View file

@ -292,34 +292,53 @@ pub fn range_error<'sc>(
scope: &mut impl ToLocal<'sc>,
mut message: Local<String>,
) -> Local<'sc, Value> {
unsafe { scope.to_local(v8__Exception__RangeError(&mut *message)) }.unwrap()
let isolate = scope.isolate();
isolate.enter();
let e = unsafe { v8__Exception__RangeError(&mut *message) };
isolate.exit();
unsafe { scope.to_local(e) }.unwrap()
}
pub fn reference_error<'sc>(
scope: &mut impl ToLocal<'sc>,
mut message: Local<String>,
) -> Local<'sc, Value> {
unsafe { scope.to_local(v8__Exception__ReferenceError(&mut *message)) }
.unwrap()
let isolate = scope.isolate();
isolate.enter();
let e = unsafe { v8__Exception__ReferenceError(&mut *message) };
isolate.exit();
unsafe { scope.to_local(e) }.unwrap()
}
pub fn syntax_error<'sc>(
scope: &mut impl ToLocal<'sc>,
mut message: Local<String>,
) -> Local<'sc, Value> {
unsafe { scope.to_local(v8__Exception__SyntaxError(&mut *message)) }.unwrap()
let isolate = scope.isolate();
isolate.enter();
let e = unsafe { v8__Exception__SyntaxError(&mut *message) };
isolate.exit();
unsafe { scope.to_local(e) }.unwrap()
}
pub fn type_error<'sc>(
scope: &mut impl ToLocal<'sc>,
mut message: Local<String>,
) -> Local<'sc, Value> {
unsafe { scope.to_local(v8__Exception__TypeError(&mut *message)) }.unwrap()
let isolate = scope.isolate();
isolate.enter();
let e = unsafe { v8__Exception__TypeError(&mut *message) };
isolate.exit();
unsafe { scope.to_local(e) }.unwrap()
}
pub fn error<'sc>(
scope: &mut impl ToLocal<'sc>,
mut message: Local<String>,
) -> Local<'sc, Value> {
unsafe { scope.to_local(v8__Exception__Error(&mut *message)) }.unwrap()
let isolate = scope.isolate();
isolate.enter();
let e = unsafe { v8__Exception__Error(&mut *message) };
isolate.exit();
unsafe { scope.to_local(e) }.unwrap()
}

View file

@ -754,33 +754,28 @@ fn exception() {
setup();
let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator());
let mut isolate = v8::Isolate::new(params);
let isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
isolate.enter();
{
let mut hs = v8::HandleScope::new(&mut locker);
let scope = hs.enter();
let mut context = v8::Context::new(scope);
context.enter();
let reference = "This is a test error";
let local = v8::String::new(scope, reference).unwrap();
v8::range_error(scope, local);
v8::reference_error(scope, local);
v8::syntax_error(scope, local);
v8::type_error(scope, local);
let exception = v8::error(scope, local);
let msg = v8::create_message(scope, exception);
let msg_string = msg.get(scope);
let rust_msg_string = msg_string.to_rust_string_lossy(scope);
assert_eq!(
"Uncaught Error: This is a test error".to_string(),
rust_msg_string
);
assert!(v8::get_stack_trace(scope, exception).is_none());
context.exit();
}
drop(locker);
isolate.exit();
let mut hs = v8::HandleScope::new(&mut locker);
let scope = hs.enter();
let mut context = v8::Context::new(scope);
context.enter();
let reference = "This is a test error";
let local = v8::String::new(scope, reference).unwrap();
v8::range_error(scope, local);
v8::reference_error(scope, local);
v8::syntax_error(scope, local);
v8::type_error(scope, local);
let exception = v8::error(scope, local);
let msg = v8::create_message(scope, exception);
let msg_string = msg.get(scope);
let rust_msg_string = msg_string.to_rust_string_lossy(scope);
assert_eq!(
"Uncaught Error: This is a test error".to_string(),
rust_msg_string
);
assert!(v8::get_stack_trace(scope, exception).is_none());
context.exit();
}
#[test]