mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-21 15:04:33 -05:00
Add Isolate::add_message_listener_with_error_level
(#1424)
This commit is contained in:
parent
2825ced8be
commit
bc5ac4d486
4 changed files with 59 additions and 0 deletions
|
@ -276,6 +276,11 @@ bool v8__Isolate__AddMessageListener(v8::Isolate* isolate,
|
|||
return isolate->AddMessageListener(callback);
|
||||
}
|
||||
|
||||
bool v8__Isolate__AddMessageListenerWithErrorLevel(
|
||||
v8::Isolate* isolate, v8::MessageCallback callback, int error_level) {
|
||||
return isolate->AddMessageListenerWithErrorLevel(callback, error_level);
|
||||
}
|
||||
|
||||
void v8__Isolate__AddGCPrologueCallback(
|
||||
v8::Isolate* isolate, v8::Isolate::GCCallbackWithData callback, void* data,
|
||||
v8::GCType gc_type_filter) {
|
||||
|
|
|
@ -119,6 +119,19 @@ pub enum GarbageCollectionType {
|
|||
|
||||
pub type MessageCallback = extern "C" fn(Local<Message>, Local<Value>);
|
||||
|
||||
bitflags! {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(transparent)]
|
||||
pub struct MessageErrorLevel: int {
|
||||
const LOG = 1 << 0;
|
||||
const DEBUG = 1 << 1;
|
||||
const INFO = 1 << 2;
|
||||
const ERROR = 1 << 3;
|
||||
const WARNING = 1 << 4;
|
||||
const ALL = (1 << 5) - 1;
|
||||
}
|
||||
}
|
||||
|
||||
pub type PromiseHook =
|
||||
extern "C" fn(PromiseHookType, Local<Promise>, Local<Value>);
|
||||
|
||||
|
@ -393,6 +406,11 @@ extern "C" {
|
|||
isolate: *mut Isolate,
|
||||
callback: MessageCallback,
|
||||
) -> bool;
|
||||
fn v8__Isolate__AddMessageListenerWithErrorLevel(
|
||||
isolate: *mut Isolate,
|
||||
callback: MessageCallback,
|
||||
message_levels: MessageErrorLevel,
|
||||
) -> bool;
|
||||
fn v8__Isolate__AddGCPrologueCallback(
|
||||
isolate: *mut Isolate,
|
||||
callback: GcCallbackWithData,
|
||||
|
@ -889,6 +907,22 @@ impl Isolate {
|
|||
unsafe { v8__Isolate__AddMessageListener(self, callback) }
|
||||
}
|
||||
|
||||
/// Adds a message listener for the specified message levels.
|
||||
#[inline(always)]
|
||||
pub fn add_message_listener_with_error_level(
|
||||
&mut self,
|
||||
callback: MessageCallback,
|
||||
message_levels: MessageErrorLevel,
|
||||
) -> bool {
|
||||
unsafe {
|
||||
v8__Isolate__AddMessageListenerWithErrorLevel(
|
||||
self,
|
||||
callback,
|
||||
message_levels,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// This specifies the callback called when the stack property of Error
|
||||
/// is accessed.
|
||||
///
|
||||
|
|
|
@ -106,6 +106,7 @@ pub use isolate::Isolate;
|
|||
pub use isolate::IsolateHandle;
|
||||
pub use isolate::MemoryPressureLevel;
|
||||
pub use isolate::MessageCallback;
|
||||
pub use isolate::MessageErrorLevel;
|
||||
pub use isolate::MicrotasksPolicy;
|
||||
pub use isolate::NearHeapLimitCallback;
|
||||
pub use isolate::OomDetails;
|
||||
|
|
|
@ -4902,6 +4902,9 @@ fn module_stalled_top_level_await() {
|
|||
|
||||
#[test]
|
||||
fn import_assertions() {
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
let _setup_guard = setup::parallel_test();
|
||||
let isolate = &mut v8::Isolate::new(Default::default());
|
||||
|
||||
|
@ -4954,6 +4957,20 @@ fn import_assertions() {
|
|||
}
|
||||
isolate.set_host_import_module_dynamically_callback(dynamic_import_cb);
|
||||
|
||||
// TODO(@littledivy): this won't work when V8 removes `assert`.
|
||||
static COUNTER: AtomicUsize = AtomicUsize::new(0);
|
||||
extern "C" fn callback(
|
||||
_msg: v8::Local<v8::Message>,
|
||||
_: v8::Local<v8::Value>,
|
||||
) {
|
||||
COUNTER.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
isolate.add_message_listener_with_error_level(
|
||||
callback,
|
||||
v8::MessageErrorLevel::ALL,
|
||||
);
|
||||
|
||||
{
|
||||
let scope = &mut v8::HandleScope::new(isolate);
|
||||
let context = v8::Context::new(scope);
|
||||
|
@ -4979,6 +4996,8 @@ fn import_assertions() {
|
|||
assert!(result.unwrap());
|
||||
assert_eq!(v8::ModuleStatus::Instantiated, module.get_status());
|
||||
}
|
||||
|
||||
assert_eq!(COUNTER.load(Ordering::SeqCst), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue