mirror of
https://github.com/denoland/rusty_v8.git
synced 2025-01-11 08:34:01 -05:00
idiomacy:
This commit is contained in:
parent
96e202505f
commit
5b9b9bcea1
6 changed files with 51 additions and 50 deletions
17
src/main.rs
17
src/main.rs
|
@ -1,6 +1,5 @@
|
|||
#![warn(clippy::all)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
mod support;
|
||||
mod v8;
|
||||
|
@ -15,18 +14,18 @@ mod example {
|
|||
#[repr(C)]
|
||||
pub struct TestChannel {
|
||||
field1: i32,
|
||||
channel_base: ChannelBase,
|
||||
base: ChannelBase,
|
||||
field2: f64,
|
||||
}
|
||||
|
||||
impl ChannelImpl for TestChannel {
|
||||
fn base(&self) -> &ChannelBase {
|
||||
&self.channel_base
|
||||
&self.base
|
||||
}
|
||||
fn base_mut(&mut self) -> &mut ChannelBase {
|
||||
&mut self.channel_base
|
||||
&mut self.base
|
||||
}
|
||||
fn sendResponse(
|
||||
fn send_response(
|
||||
&mut self,
|
||||
call_id: i32,
|
||||
mut message: UniquePtr<StringBuffer>,
|
||||
|
@ -37,14 +36,14 @@ mod example {
|
|||
message.as_mut().unwrap().string().characters16().unwrap()
|
||||
);
|
||||
}
|
||||
fn sendNotification(&mut self, _message: UniquePtr<StringBuffer>) {}
|
||||
fn flushProtocolNotifications(&mut self) {}
|
||||
fn send_notification(&mut self, _message: UniquePtr<StringBuffer>) {}
|
||||
fn flush_protocol_notifications(&mut self) {}
|
||||
}
|
||||
|
||||
impl TestChannel {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
channel_base: ChannelBase::new::<Self>(),
|
||||
base: ChannelBase::new::<Self>(),
|
||||
field1: -42,
|
||||
field2: 4.2,
|
||||
}
|
||||
|
@ -61,5 +60,5 @@ fn main() {
|
|||
let message: &[u8] = b"hello";
|
||||
let message = StringView::from(message);
|
||||
let message = StringBuffer::create(&message);
|
||||
chan.sendResponse(3, message);
|
||||
chan.send_response(3, message);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ extern "C" {
|
|||
|
||||
fn v8_inspector__V8Inspector__Channel__sendResponse(
|
||||
this: &mut Channel,
|
||||
callId: int,
|
||||
call_id: int,
|
||||
message: UniquePtr<StringBuffer>,
|
||||
) -> ();
|
||||
fn v8_inspector__V8Inspector__Channel__sendNotification(
|
||||
|
@ -37,10 +37,10 @@ extern "C" {
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn v8_inspector__V8Inspector__Channel__BASE__sendResponse(
|
||||
this: &mut Channel,
|
||||
callId: int,
|
||||
call_id: int,
|
||||
message: UniquePtr<StringBuffer>,
|
||||
) {
|
||||
ChannelBase::dispatch_mut(this).sendResponse(callId, message)
|
||||
ChannelBase::dispatch_mut(this).send_response(call_id, message)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -48,14 +48,14 @@ pub unsafe extern "C" fn v8_inspector__V8Inspector__Channel__BASE__sendNotificat
|
|||
this: &mut Channel,
|
||||
message: UniquePtr<StringBuffer>,
|
||||
) {
|
||||
ChannelBase::dispatch_mut(this).sendNotification(message)
|
||||
ChannelBase::dispatch_mut(this).send_notification(message)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn v8_inspector__V8Inspector__Channel__BASE__flushProtocolNotifications(
|
||||
this: &mut Channel,
|
||||
) {
|
||||
ChannelBase::dispatch_mut(this).flushProtocolNotifications()
|
||||
ChannelBase::dispatch_mut(this).flush_protocol_notifications()
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
|
@ -64,21 +64,21 @@ pub struct Channel {
|
|||
}
|
||||
|
||||
impl Channel {
|
||||
pub fn sendResponse(
|
||||
pub fn send_response(
|
||||
&mut self,
|
||||
callId: int,
|
||||
call_id: int,
|
||||
message: UniquePtr<StringBuffer>,
|
||||
) {
|
||||
unsafe {
|
||||
v8_inspector__V8Inspector__Channel__sendResponse(self, callId, message)
|
||||
v8_inspector__V8Inspector__Channel__sendResponse(self, call_id, message)
|
||||
}
|
||||
}
|
||||
pub fn sendNotification(&mut self, message: UniquePtr<StringBuffer>) {
|
||||
pub fn send_notification(&mut self, message: UniquePtr<StringBuffer>) {
|
||||
unsafe {
|
||||
v8_inspector__V8Inspector__Channel__sendNotification(self, message)
|
||||
}
|
||||
}
|
||||
pub fn flushProtocolNotifications(&mut self) {
|
||||
pub fn flush_protocol_notifications(&mut self) {
|
||||
unsafe {
|
||||
v8_inspector__V8Inspector__Channel__flushProtocolNotifications(self)
|
||||
}
|
||||
|
@ -115,13 +115,13 @@ pub trait ChannelImpl: AsChannel {
|
|||
fn base(&self) -> &ChannelBase;
|
||||
fn base_mut(&mut self) -> &mut ChannelBase;
|
||||
|
||||
fn sendResponse(
|
||||
fn send_response(
|
||||
&mut self,
|
||||
callId: int,
|
||||
call_id: int,
|
||||
message: UniquePtr<StringBuffer>,
|
||||
) -> ();
|
||||
fn sendNotification(&mut self, message: UniquePtr<StringBuffer>) -> ();
|
||||
fn flushProtocolNotifications(&mut self) -> ();
|
||||
fn send_notification(&mut self, message: UniquePtr<StringBuffer>) -> ();
|
||||
fn flush_protocol_notifications(&mut self) -> ();
|
||||
}
|
||||
|
||||
pub struct ChannelBase {
|
||||
|
|
|
@ -73,38 +73,38 @@ extern "C" {
|
|||
|
||||
fn v8_inspector__V8InspectorClient__runMessageLoopOnPause(
|
||||
this: &mut Client,
|
||||
contextGroupId: int,
|
||||
context_group_id: int,
|
||||
) -> ();
|
||||
fn v8_inspector__V8InspectorClient__quitMessageLoopOnPause(
|
||||
this: &mut Client,
|
||||
) -> ();
|
||||
fn v8_inspector__V8InspectorClient__runIfWaitingForDebugger(
|
||||
this: &mut Client,
|
||||
contextGroupId: int,
|
||||
context_group_id: int,
|
||||
) -> ();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn v8_inspector__V8InspectorClient__BASE__runMessageLoopOnPause(
|
||||
this: &mut Client,
|
||||
contextGroupId: int,
|
||||
context_group_id: int,
|
||||
) {
|
||||
ClientBase::dispatch_mut(this).runMessageLoopOnPause(contextGroupId)
|
||||
ClientBase::dispatch_mut(this).run_message_loop_on_pause(context_group_id)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn v8_inspector__V8InspectorClient__BASE__quitMessageLoopOnPause(
|
||||
this: &mut Client,
|
||||
) {
|
||||
ClientBase::dispatch_mut(this).quitMessageLoopOnPause()
|
||||
ClientBase::dispatch_mut(this).quit_message_loop_on_pause()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn v8_inspector__V8InspectorClient__BASE__runIfWaitingForDebugger(
|
||||
this: &mut Client,
|
||||
contextGroupId: int,
|
||||
context_group_id: int,
|
||||
) {
|
||||
ClientBase::dispatch_mut(this).runIfWaitingForDebugger(contextGroupId)
|
||||
ClientBase::dispatch_mut(this).run_if_waiting_for_debugger(context_group_id)
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
|
@ -113,22 +113,22 @@ pub struct Client {
|
|||
}
|
||||
|
||||
impl Client {
|
||||
pub fn runMessageLoopOnPause(&mut self, contextGroupId: int) {
|
||||
pub fn run_message_loop_on_pause(&mut self, context_group_id: int) {
|
||||
unsafe {
|
||||
v8_inspector__V8InspectorClient__runMessageLoopOnPause(
|
||||
self,
|
||||
contextGroupId,
|
||||
context_group_id,
|
||||
)
|
||||
}
|
||||
}
|
||||
pub fn quitMessageLoopOnPause(&mut self) {
|
||||
pub fn quit_message_loop_on_pause(&mut self) {
|
||||
unsafe { v8_inspector__V8InspectorClient__quitMessageLoopOnPause(self) }
|
||||
}
|
||||
pub fn runIfWaitingForDebugger(&mut self, contextGroupId: int) {
|
||||
pub fn run_if_waiting_for_debugger(&mut self, context_group_id: int) {
|
||||
unsafe {
|
||||
v8_inspector__V8InspectorClient__runIfWaitingForDebugger(
|
||||
self,
|
||||
contextGroupId,
|
||||
context_group_id,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -165,9 +165,9 @@ pub trait ClientImpl: AsClient {
|
|||
fn base(&self) -> &ClientBase;
|
||||
fn base_mut(&mut self) -> &mut ClientBase;
|
||||
|
||||
fn runMessageLoopOnPause(&mut self, contextGroupId: int) {}
|
||||
fn quitMessageLoopOnPause(&mut self) {}
|
||||
fn runIfWaitingForDebugger(&mut self, contextGroupId: int) {}
|
||||
fn run_message_loop_on_pause(&mut self, context_group_id: int) {}
|
||||
fn quit_message_loop_on_pause(&mut self) {}
|
||||
fn run_if_waiting_for_debugger(&mut self, context_group_id: int) {}
|
||||
}
|
||||
|
||||
pub struct ClientBase {
|
||||
|
|
|
@ -27,7 +27,7 @@ pub unsafe extern "C" fn v8__Task__BASE__DELETE(this: &mut Task) {
|
|||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn v8__Task__BASE__Run(this: &mut Task) {
|
||||
TaskBase::dispatch_mut(this).Run()
|
||||
TaskBase::dispatch_mut(this).run()
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
|
@ -36,7 +36,7 @@ pub struct Task {
|
|||
}
|
||||
|
||||
impl Task {
|
||||
pub fn Run(&mut self) {
|
||||
pub fn run(&mut self) {
|
||||
unsafe { v8__Task__Run(self) }
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ where
|
|||
pub trait TaskImpl: AsTask {
|
||||
fn base(&self) -> &TaskBase;
|
||||
fn base_mut(&mut self) -> &mut TaskBase;
|
||||
fn Run(&mut self) -> ();
|
||||
fn run(&mut self) -> ();
|
||||
}
|
||||
|
||||
pub struct TaskBase {
|
||||
|
@ -196,7 +196,7 @@ mod tests {
|
|||
fn base_mut(&mut self) -> &mut TaskBase {
|
||||
&mut self.base
|
||||
}
|
||||
fn Run(&mut self) {
|
||||
fn run(&mut self) {
|
||||
RUN_COUNT.fetch_add(1, SeqCst);
|
||||
}
|
||||
}
|
||||
|
@ -210,7 +210,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_task() {
|
||||
{
|
||||
TestTask::new().Run();
|
||||
TestTask::new().run();
|
||||
}
|
||||
assert_eq!(RUN_COUNT.swap(0, SeqCst), 1);
|
||||
assert_eq!(DROP_COUNT.swap(0, SeqCst), 1);
|
||||
|
|
|
@ -58,7 +58,7 @@ mod tests {
|
|||
let view = buf.as_mut().unwrap().string();
|
||||
|
||||
assert_eq!(chars.len(), view.into_iter().len());
|
||||
assert_eq!(chars.len(), view.length());
|
||||
assert_eq!(chars.len(), view.len());
|
||||
for (c1, c2) in chars.iter().copied().map(u16::from).zip(view) {
|
||||
assert_eq!(c1, c2);
|
||||
}
|
||||
|
|
|
@ -33,8 +33,9 @@ use std::slice;
|
|||
|
||||
// Notes:
|
||||
// * This class is ported, not wrapped using bindings.
|
||||
// * Since Rust `repr(bool)` is not allowed, assume `bool` and `u8` have the
|
||||
// same size. TODO: find/open upstream issue to allow #[repr(bool)] support.
|
||||
// * Since Rust `repr(bool)` is not allowed, we're assuming that `bool` and
|
||||
// `u8` have the same size. This is assumption is checked in 'support.h'.
|
||||
// TODO: find/open upstream issue to allow #[repr(bool)] support.
|
||||
|
||||
#[repr(u8)]
|
||||
#[derive(Debug)]
|
||||
|
@ -63,14 +64,14 @@ impl<'a> From<&'a [u16]> for StringView<'a> {
|
|||
}
|
||||
|
||||
impl<'a> StringView<'a> {
|
||||
pub fn is8Bit(&self) -> bool {
|
||||
pub fn is_8bit(&self) -> bool {
|
||||
match self {
|
||||
Self::U16(..) => false,
|
||||
Self::U8(..) => true,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn length(&self) -> usize {
|
||||
pub fn len(&self) -> usize {
|
||||
match self {
|
||||
Self::U16(v) => v.len(),
|
||||
Self::U8(v) => v.len(),
|
||||
|
@ -150,6 +151,7 @@ impl<'a, T> From<&'a [T]> for CharacterArray<'a, T> {
|
|||
|
||||
impl<'a, T> Deref for CharacterArray<'a, T> {
|
||||
type Target = [T];
|
||||
|
||||
fn deref(&self) -> &[T] {
|
||||
let Self {
|
||||
m_length,
|
||||
|
@ -185,7 +187,7 @@ impl<'a: 'b, 'b> Iterator for StringViewIterator<'a, 'b> {
|
|||
|
||||
impl<'a: 'b, 'b> ExactSizeIterator for StringViewIterator<'a, 'b> {
|
||||
fn len(&self) -> usize {
|
||||
self.view.length()
|
||||
self.view.len()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -199,7 +201,7 @@ mod tests {
|
|||
let view = StringView::from(&chars[..]);
|
||||
|
||||
assert_eq!(chars.len(), view.into_iter().len());
|
||||
assert_eq!(chars.len(), view.length());
|
||||
assert_eq!(chars.len(), view.len());
|
||||
for (c1, c2) in chars.iter().copied().map(u16::from).zip(&view) {
|
||||
assert_eq!(c1, c2);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue