Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the V8 Inspector api #49

Closed
wants to merge 24 commits into from
Closed

Add the V8 Inspector api #49

wants to merge 24 commits into from

Conversation

iddm
Copy link
Collaborator

@iddm iddm commented Aug 29, 2023

Adds the Inspector API and the tools helpful to work with it.

iddm added 14 commits August 29, 2023 11:05
Adds a module called "inspector.rs" with corresponding relevant structures.

1. Changes ordinary comments to be doc-comments on the C bindings.
2. Corrects the naming of C binding functions to follow the convention.
3. Makes the tests work and pass.
4. Uses the logging facility.
5. Updates the dependencies.
6. Removes comments.
7. Refactors the code a little.
Split into more stages: building the server, accepting the first
connection and the main loop.
@iddm iddm self-assigned this Aug 29, 2023
@iddm iddm force-pushed the add-inspector-api-2-rebased branch from 8cac4a3 to 7612f7e Compare August 29, 2023 10:03
Comment on lines +148 to +176
/// Returns a raw pointer to the isolate.
pub fn get_raw_isolate(&self) -> *mut v8_isolate {
self.isolate.get_raw()
}

/// Creates a new [V8IsolateScope] (or "restores it") with an
/// already existing storage for the scopes.
/// The storage provided must have been created precisely for the
/// isolate passed.
pub fn restore(isolate: &'isolate V8Isolate, storage: V8IsolateScopeStorage) -> Option<Self> {
if !storage.is_same_isolate(isolate) {
None
} else {
Some(Self { isolate, storage })
}
}

/// Forgets about the isolate and handlers scopes, so that those
/// aren't deleted in destructor. Returns the storage object created
/// for this [V8IsolateScope], so that it is still possible to
/// restore later.
pub fn forget(&mut self) -> V8IsolateScopeStorage {
std::mem::take(&mut self.storage)
}

/// Returns `true` if the scopes are left uninitialised.
pub fn is_forgotten(&self) -> bool {
self.storage.is_uninitialised()
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were useful in some places, but now probably aren't. @MeirShpilraien what do you think?

Comment on lines +97 to +110
impl<'isolate_scope, 'isolate> From<&V8LocalString<'isolate_scope, 'isolate>> for String {
fn from(value: &V8LocalString<'isolate_scope, 'isolate>) -> Self {
let mut string = String::default();
let string_ptr = &mut string as *mut String as _;
unsafe {
crate::v8_c_raw::bindings::v8_GetStringValueWithCallback(
value.inner_string,
Some(convert_c_string_to_rust),
string_ptr,
)
};
string
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: there, IIRC, was another, easier way to do that. @MeirShpilraien Can you remind me, please?

@iddm iddm changed the title Draft: Add inspector api Add inspector api Aug 29, 2023
@iddm iddm changed the title Add inspector api Add the V8 Inspector api Aug 29, 2023
Cargo.toml Outdated
@@ -7,9 +7,14 @@ license = "Redis Source Available License 2.0 (RSALv2) or the Server Side Public
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tungstenite = { version = "0.20", optional = true }
log = "0.4"
serde = { version = "1", features = ["derive"] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets pin serde version?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, will do!

#[cfg(test)]
mod json_path_tests {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain all those tests changes? Are those just cosmetic or is there any fundamental change here?

Copy link
Collaborator Author

@iddm iddm Aug 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just purely cosmetic, we discussed these changes two months ago in slack :-)

/// The error subset of dispatch codes of the v8 inspector protocol. A
/// copy from the "dispatch.h" header file.
#[derive(Debug, Copy, Clone)]
pub enum ErrorCode {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be auto generated somehow? Otherwise we will need to maintain it each time it changes, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely we can use (probably, if it works well enough) bindgen for this. However, we would need the source code of V8, too, cuz this header isn't a part of the distributed headers of V8.

@iddm
Copy link
Collaborator Author

iddm commented Aug 30, 2023

We decided to split this into smaller PRs. The first one: #50

@iddm iddm closed this Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants