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

APIs required to implement inspector #205

Closed
bartlomieju opened this issue Jan 13, 2020 · 5 comments
Closed

APIs required to implement inspector #205

bartlomieju opened this issue Jan 13, 2020 · 5 comments

Comments

@bartlomieju
Copy link
Member

  • v8_inspector::V8Inspector
    • create
    • connect
    • StringView
  • v8_inspector::ContextInfo
    • new
  • v8_inspector::InspectorSession
    • dispatchProtocolMessage
    • schedulePauseOnNextStatement
  • API to get Rust String out of StringView if it is two-byte string (!string_view.is_8_bit())

CC @piscisaureus

@piscisaureus
Copy link
Member

  • API to get Rust String out of StringView if it is two-byte string (!string_view.is_8_bit())
  1. Not sure you need it at all. I think all you need to do is forward the message between the client and server.
  2. If you do need it, this would do the trick: https://doc.rust-lang.org/std/string/struct.String.html#method.from_utf16.
  3. Also, an 8bit string_view is not encoded as UTF8 but as Latin-1. Converting an 8bit StringView is probably more involved than converting a 16bit string.

@bartlomieju
Copy link
Member Author

Not sure you need it at all. I think all you need to do is forward the message between the client and server.

I'm prototyping now on types, you might be right, I'll get back on that

If you do need it, this would do the trick: https://doc.rust-lang.org/std/string/struct.String.html#method.from_utf16.

👍

Also, an 8bit string_view is not encoded as UTF8 but as Latin-1. Converting an 8bit StringView is probably more involved than converting a 16bit string.

You are right, looks like previous implementation did convert to Utf8Value before actually encoding into string.

void InspectorFrontend::Send(const v8_inspector::StringView& string) {
  v8::HandleScope handle_scope(isolate_);
  int length = static_cast<int>(string.length());
  DCHECK_LT(length, v8::String::kMaxLength);
  Local<String> message =
      (string.is8Bit()
           ? v8::String::NewFromOneByte(
                 isolate_,
                 reinterpret_cast<const uint8_t*>(string.characters8()),
                 v8::NewStringType::kNormal, length)
           : v8::String::NewFromTwoByte(
                 isolate_,
                 reinterpret_cast<const uint16_t*>(string.characters16()),
                 v8::NewStringType::kNormal, length))
          .ToLocalChecked();

  String::Utf8Value utf8(isolate_, message);
  std::string str(*utf8);

  char* cstr = &str[0u];

  deno_->inspector_message_cb_(deno_->hack_, cstr);
}

@bartlomieju
Copy link
Member Author

  • API to get Rust String out of StringView if it is two-byte string (!string_view.is_8_bit())
  1. Not sure you need it at all. I think all you need to do is forward the message between the client and server.
  2. If you do need it, this would do the trick: https://doc.rust-lang.org/std/string/struct.String.html#method.from_utf16.
  3. Also, an 8bit string_view is not encoded as UTF8 but as Latin-1. Converting an 8bit StringView is probably more involved than converting a 16bit string.

Okay, checked, we need that conversion because those messages are pushed/pulled via WS socket which requires String type for messages.

@kitsonk
Copy link

kitsonk commented Mar 1, 2020

In order to solve denoland/deno#106 we would also need the following APIs exposed:

A V8 blog post describes the process in detail.

@piscisaureus
Copy link
Member

Closing this as the currently bound APIs were sufficient to implement the inspector in Deno.

If other APIs mentioned in this thread (e.g. Profiler.*) are still missing and still needed, feel free to open a separate issue (or PR).

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

No branches or pull requests

3 participants