From c525555e4291de8b3a2357576d11dcb2c049c69d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 9 Aug 2021 15:53:30 +0200 Subject: [PATCH] feat: add V8InspectorSession::can_dispatch_method (#746) --- src/binding.cc | 5 +++++ src/inspector.rs | 7 +++++++ tests/test_api.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/src/binding.cc b/src/binding.cc index 1f643a69..1c1ffd7a 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -2122,6 +2122,11 @@ void v8_inspector__V8Inspector__contextCreated( ptr_to_local(&context), contextGroupId, humanReadableName)); } +bool v8_inspector__V8InspectorSession__canDispatchMethod( + v8_inspector::StringView method) { + return v8_inspector::V8InspectorSession::canDispatchMethod(method); +} + void v8_inspector__V8InspectorSession__DELETE( v8_inspector::V8InspectorSession* self) { delete self; diff --git a/src/inspector.rs b/src/inspector.rs index b6cccd34..1ab4ec70 100644 --- a/src/inspector.rs +++ b/src/inspector.rs @@ -82,6 +82,9 @@ extern "C" { break_reason: StringView, break_details: StringView, ); + fn v8_inspector__V8InspectorSession__canDispatchMethod( + method: StringView, + ) -> bool; fn v8_inspector__StringBuffer__DELETE(this: &mut StringBuffer); fn v8_inspector__StringBuffer__string(this: &StringBuffer) -> StringView; @@ -598,6 +601,10 @@ impl Debug for V8InspectorClientBase { pub struct V8InspectorSession(Opaque); impl V8InspectorSession { + pub fn can_dispatch_method(method: StringView) -> bool { + unsafe { v8_inspector__V8InspectorSession__canDispatchMethod(method) } + } + pub fn dispatch_protocol_message(&mut self, message: StringView) { unsafe { v8_inspector__V8InspectorSession__dispatchProtocolMessage(self, message) diff --git a/tests/test_api.rs b/tests/test_api.rs index 9b0ee6ad..424189c7 100644 --- a/tests/test_api.rs +++ b/tests/test_api.rs @@ -3584,6 +3584,51 @@ impl v8::inspector::ChannelImpl for ChannelCounter { } } +#[test] +fn inspector_can_dispatch_method() { + use v8::inspector::*; + + let message = String::from("Runtime.enable"); + let message = &message.into_bytes()[..]; + let string_view = StringView::from(message); + assert!(V8InspectorSession::can_dispatch_method(string_view)); + + let message = String::from("Debugger.enable"); + let message = &message.into_bytes()[..]; + let string_view = StringView::from(message); + assert!(V8InspectorSession::can_dispatch_method(string_view)); + + let message = String::from("Profiler.enable"); + let message = &message.into_bytes()[..]; + let string_view = StringView::from(message); + assert!(V8InspectorSession::can_dispatch_method(string_view)); + + let message = String::from("HeapProfiler.enable"); + let message = &message.into_bytes()[..]; + let string_view = StringView::from(message); + assert!(V8InspectorSession::can_dispatch_method(string_view)); + + let message = String::from("Console.enable"); + let message = &message.into_bytes()[..]; + let string_view = StringView::from(message); + assert!(V8InspectorSession::can_dispatch_method(string_view)); + + let message = String::from("Schema.getDomains"); + let message = &message.into_bytes()[..]; + let string_view = StringView::from(message); + assert!(V8InspectorSession::can_dispatch_method(string_view)); + + let message = String::from("Foo.enable"); + let message = &message.into_bytes()[..]; + let string_view = StringView::from(message); + assert!(!V8InspectorSession::can_dispatch_method(string_view)); + + let message = String::from("Bar.enable"); + let message = &message.into_bytes()[..]; + let string_view = StringView::from(message); + assert!(!V8InspectorSession::can_dispatch_method(string_view)); +} + #[test] fn inspector_dispatch_protocol_message() { let _setup_guard = setup();