From 0e86101ed9036c2e5fb63ad5fa19310d1a55b41d Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Sun, 20 Oct 2019 16:10:40 -0700 Subject: [PATCH] wip --- .vscode/settings.json | 3 ++- src/lib.cpp | 7 +++--- src/main.rs | 22 +++++++++---------- src/{cxx_util.rs => support.rs} | 1 + src/{v8_inspector => v8/inspector}/channel.h | 0 src/{v8_inspector => v8/inspector}/channel.rs | 15 ++++++------- src/{v8_inspector => v8/inspector}/client.h | 0 src/{v8_inspector => v8/inspector}/client.rs | 10 ++++----- src/v8/inspector/mod.rs | 5 +++++ src/{v8_inspector => v8}/mod.rs | 5 +---- src/{v8_inspector => v8}/string_buffer.h | 0 src/{v8_inspector => v8}/string_buffer.rs | 11 +++++----- src/{v8_inspector => v8}/string_view.rs | 12 +++++----- 13 files changed, 46 insertions(+), 45 deletions(-) rename src/{cxx_util.rs => support.rs} (99%) rename src/{v8_inspector => v8/inspector}/channel.h (100%) rename src/{v8_inspector => v8/inspector}/channel.rs (96%) rename src/{v8_inspector => v8/inspector}/client.h (100%) rename src/{v8_inspector => v8/inspector}/client.rs (97%) create mode 100644 src/v8/inspector/mod.rs rename src/{v8_inspector => v8}/mod.rs (58%) rename src/{v8_inspector => v8}/string_buffer.h (100%) rename src/{v8_inspector => v8}/string_buffer.rs (87%) rename src/{v8_inspector => v8}/string_view.rs (99%) diff --git a/.vscode/settings.json b/.vscode/settings.json index d01fed2a..cd651608 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,7 @@ "C_Cpp.clang_format_style": "Chromium", "files.associations": { "memory": "cpp", - "vector": "cpp" + "vector": "cpp", + "cctype": "cpp" } } \ No newline at end of file diff --git a/src/lib.cpp b/src/lib.cpp index 03079983..cf031e5d 100644 --- a/src/lib.cpp +++ b/src/lib.cpp @@ -7,6 +7,7 @@ #include #include "../goog/v8/include/v8-inspector.h" +#include "../goog/v8/include/v8.h" template using uninit_t = typename std::aligned_storage::type; @@ -17,6 +18,6 @@ auto launder(T ptr) { return ptr; } -#include "v8_inspector/channel.h" -#include "v8_inspector/client.h" -#include "v8_inspector/string_buffer.h" +#include "v8/inspector/channel.h" +#include "v8/inspector/client.h" +#include "v8/string_buffer.h" diff --git a/src/main.rs b/src/main.rs index 23eb1a78..5db7dd2d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,26 +1,26 @@ #![allow(dead_code)] #![allow(non_snake_case)] -mod cxx_util; -mod v8_inspector; +mod support; +mod v8; mod example { - use crate::cxx_util::UniquePtr; - use crate::v8_inspector::channel::*; - use crate::v8_inspector::*; + use crate::support::UniquePtr; + use crate::v8::inspector::channel::*; + use crate::v8::*; pub struct Example { a: i32, - channel_extender: ChannelBase, + channel_base: ChannelBase, b: i32, } impl ChannelImpl for Example { fn base(&self) -> &ChannelBase { - &self.channel_extender + &self.channel_base } fn base_mut(&mut self) -> &mut ChannelBase { - &mut self.channel_extender + &mut self.channel_base } fn sendResponse( &mut self, @@ -40,7 +40,7 @@ mod example { impl Example { pub fn new() -> Self { Self { - channel_extender: ChannelBase::new::(), + channel_base: ChannelBase::new::(), a: 2, b: 3, } @@ -49,8 +49,8 @@ mod example { } fn main() { - use crate::v8_inspector::channel::*; - use crate::v8_inspector::*; + use crate::v8::inspector::channel::*; + use crate::v8::*; use example::*; let mut ex = Example::new(); let chan = ex.as_channel_mut(); diff --git a/src/cxx_util.rs b/src/support.rs similarity index 99% rename from src/cxx_util.rs rename to src/support.rs index 9f6ea22a..4bae789a 100644 --- a/src/cxx_util.rs +++ b/src/support.rs @@ -96,6 +96,7 @@ pub struct FieldOffset(usize, PhantomData); unsafe impl Send for FieldOffset where F: Send {} unsafe impl Sync for FieldOffset where F: Sync {} + impl Copy for FieldOffset {} impl Clone for FieldOffset { diff --git a/src/v8_inspector/channel.h b/src/v8/inspector/channel.h similarity index 100% rename from src/v8_inspector/channel.h rename to src/v8/inspector/channel.h diff --git a/src/v8_inspector/channel.rs b/src/v8/inspector/channel.rs similarity index 96% rename from src/v8_inspector/channel.rs rename to src/v8/inspector/channel.rs index a12392a3..2df051b0 100644 --- a/src/v8_inspector/channel.rs +++ b/src/v8/inspector/channel.rs @@ -1,11 +1,10 @@ -use crate::cxx_util::int; -use crate::cxx_util::CxxVTable; -use crate::cxx_util::FieldOffset; -use crate::cxx_util::Opaque; -use crate::cxx_util::RustVTable; -use crate::cxx_util::UniquePtr; - -use super::StringBuffer; +use crate::support::int; +use crate::support::CxxVTable; +use crate::support::FieldOffset; +use crate::support::Opaque; +use crate::support::RustVTable; +use crate::support::UniquePtr; +use crate::v8::StringBuffer; // class Channel { // public: diff --git a/src/v8_inspector/client.h b/src/v8/inspector/client.h similarity index 100% rename from src/v8_inspector/client.h rename to src/v8/inspector/client.h diff --git a/src/v8_inspector/client.rs b/src/v8/inspector/client.rs similarity index 97% rename from src/v8_inspector/client.rs rename to src/v8/inspector/client.rs index d8982035..d5168761 100644 --- a/src/v8_inspector/client.rs +++ b/src/v8/inspector/client.rs @@ -1,8 +1,8 @@ -use crate::cxx_util::int; -use crate::cxx_util::CxxVTable; -use crate::cxx_util::FieldOffset; -use crate::cxx_util::Opaque; -use crate::cxx_util::RustVTable; +use crate::support::int; +use crate::support::CxxVTable; +use crate::support::FieldOffset; +use crate::support::Opaque; +use crate::support::RustVTable; // class V8InspectorClient { // public: diff --git a/src/v8/inspector/mod.rs b/src/v8/inspector/mod.rs new file mode 100644 index 00000000..2e093f7c --- /dev/null +++ b/src/v8/inspector/mod.rs @@ -0,0 +1,5 @@ +pub mod channel; +pub mod client; + +pub use channel::Channel; +pub use client::Client; diff --git a/src/v8_inspector/mod.rs b/src/v8/mod.rs similarity index 58% rename from src/v8_inspector/mod.rs rename to src/v8/mod.rs index 67acf894..d04e4373 100644 --- a/src/v8_inspector/mod.rs +++ b/src/v8/mod.rs @@ -1,9 +1,6 @@ -pub mod channel; -pub mod client; +pub mod inspector; pub mod string_buffer; pub mod string_view; -pub use channel::Channel; -pub use client::Client; pub use string_buffer::StringBuffer; pub use string_view::StringView; diff --git a/src/v8_inspector/string_buffer.h b/src/v8/string_buffer.h similarity index 100% rename from src/v8_inspector/string_buffer.h rename to src/v8/string_buffer.h diff --git a/src/v8_inspector/string_buffer.rs b/src/v8/string_buffer.rs similarity index 87% rename from src/v8_inspector/string_buffer.rs rename to src/v8/string_buffer.rs index c1948124..4b25efe9 100644 --- a/src/v8_inspector/string_buffer.rs +++ b/src/v8/string_buffer.rs @@ -1,10 +1,9 @@ -use crate::cxx_util::CxxVTable; -use crate::cxx_util::Delete; -use crate::cxx_util::UniquePtr; +use crate::support::CxxVTable; +use crate::support::Delete; +use crate::support::UniquePtr; +use crate::v8::StringView; -use super::StringView; - -// class V8_EXPORT StringBuffer { +// class StringBuffer { // public: // virtual ~StringBuffer() = default; // virtual const StringView& string() = 0; diff --git a/src/v8_inspector/string_view.rs b/src/v8/string_view.rs similarity index 99% rename from src/v8_inspector/string_view.rs rename to src/v8/string_view.rs index 4c16bd40..927348d0 100644 --- a/src/v8_inspector/string_view.rs +++ b/src/v8/string_view.rs @@ -4,12 +4,6 @@ use std::ptr::null; use std::ptr::NonNull; 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. - -// ```cpp // class StringView { // public: // StringView() : m_is8Bit(true), m_length(0), m_characters8(nullptr) {} @@ -34,7 +28,11 @@ use std::slice; // const uint16_t* m_characters16; // }; // }; -// ``` + +// 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. #[repr(u8)] #[derive(Copy, Clone, Debug)]