LCOV - code coverage report
Current view: top level - src/backend - V8Engine.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 16 0.0 %
Date: 2025-03-25 01:19:55 Functions: 0 9 0.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : #pragma once
       2                 :            : 
       3                 :            : #include "backend/WebAssembly.hpp"
       4                 :            : #include "util/WebSocketServer.hpp"
       5                 :            : #include <v8-inspector.h>
       6                 :            : #include <v8.h>
       7                 :            : 
       8                 :            : 
       9                 :            : namespace m {
      10                 :            : 
      11                 :            : namespace wasm {
      12                 :            : 
      13                 :            : namespace detail {
      14                 :            : 
      15                 :            : struct WebSocketChannel : v8_inspector::V8Inspector::Channel
      16                 :            : {
      17                 :            :     private:
      18                 :            :     v8::Isolate *isolate_;
      19                 :            :     WebSocketServer::Connection &conn_;
      20                 :            : 
      21                 :            :     public:
      22                 :          0 :     WebSocketChannel(v8::Isolate *isolate, WebSocketServer::Connection &conn)
      23                 :          0 :         : isolate_(isolate)
      24                 :          0 :         , conn_(conn) {}
      25                 :            : 
      26                 :            :     WebSocketServer::Connection &connection() const { return conn_; }
      27                 :            : 
      28                 :            :     private:
      29                 :            :     void sendResponse(int, std::unique_ptr<v8_inspector::StringBuffer> message) override;
      30                 :            :     void sendNotification(std::unique_ptr<v8_inspector::StringBuffer> message) override;
      31                 :            : 
      32                 :          0 :     void flushProtocolNotifications() override {}
      33                 :            : };
      34                 :            : 
      35                 :            : struct V8InspectorClientImpl : v8_inspector::V8InspectorClient
      36                 :            : {
      37                 :            :     private:
      38                 :            :     v8::Isolate *isolate_ = nullptr;
      39                 :            :     WebSocketServer server_;
      40                 :            :     std::unique_ptr<WebSocketServer::Connection> conn_;
      41                 :            :     std::unique_ptr<WebSocketChannel> channel_;
      42                 :            :     std::unique_ptr<v8_inspector::V8Inspector> inspector_;
      43                 :            :     std::unique_ptr<v8_inspector::V8InspectorSession> session_;
      44                 :            :     std::function<void(void)> code_; ///< the code to execute in the debugger
      45                 :            :     bool is_terminated_ = true;
      46                 :            : 
      47                 :            :     public:
      48                 :            :     V8InspectorClientImpl(int16_t port, v8::Isolate *isolate);
      49                 :            :     V8InspectorClientImpl(const V8InspectorClientImpl &) = delete;
      50                 :            : 
      51                 :          0 :     ~V8InspectorClientImpl() {
      52                 :          0 :         session_.reset();
      53                 :          0 :         channel_.reset();
      54                 :          0 :         conn_.reset();
      55                 :          0 :         inspector_.reset();
      56                 :          0 :     }
      57                 :            : 
      58                 :          0 :     void start(std::function<void(void)> code) {
      59                 :          0 :         code_ = std::move(code);
      60                 :          0 :         conn_->listen();
      61                 :          0 :     }
      62                 :            : 
      63                 :            :     /** Register the context object in the V8Inspector instance. */
      64                 :            :     void register_context(v8::Local<v8::Context> context);
      65                 :            : 
      66                 :            :     /** Deregister the context object in the V8Inspector instance. */
      67                 :            :     void deregister_context(v8::Local<v8::Context> context);
      68                 :            : 
      69                 :            :     void on_message(std::string_view sv);
      70                 :            : 
      71                 :            :     /** Synchronously consume all front end (CDT) debugging messages. */
      72                 :            :     void runMessageLoopOnPause(int) override;
      73                 :            : 
      74                 :            :     /** Called by V8 when no more inspector messages are pending. */
      75                 :          0 :     void quitMessageLoopOnPause() override { is_terminated_ = true; }
      76                 :            : 
      77                 :          0 :     void waitFrontendMessageOnPause() { is_terminated_ = false; }
      78                 :            : };
      79                 :            : 
      80                 :            : void insist(const v8::FunctionCallbackInfo<v8::Value> &info);
      81                 :            : void _throw(const v8::FunctionCallbackInfo<v8::Value> &info);
      82                 :            : void print(const v8::FunctionCallbackInfo<v8::Value> &info);
      83                 :            : void print_memory_consumption(const v8::FunctionCallbackInfo<v8::Value> &info);
      84                 :            : void set_wasm_instance_raw_memory(const v8::FunctionCallbackInfo<v8::Value> &info);
      85                 :            : void read_result_set(const v8::FunctionCallbackInfo<v8::Value> &info);
      86                 :            : template<typename Index, typename V8ValueT, bool IsLower>
      87                 :            : void index_seek(const v8::FunctionCallbackInfo<v8::Value> &info);
      88                 :            : template<typename Index>
      89                 :            : void index_sequential_scan(const v8::FunctionCallbackInfo<v8::Value> &info);
      90                 :            : 
      91                 :            : v8::Local<v8::String> mkstr(v8::Isolate &isolate, const std::string &str);
      92                 :            : v8::Local<v8::WasmModuleObject> instantiate(v8::Isolate &isolate, v8::Local<v8::Object> imports);
      93                 :            : v8::Local<v8::Object> create_env(v8::Isolate &isolate, const m::MatchBase &plan);
      94                 :            : v8::Local<v8::String> to_json(v8::Isolate &isolate, v8::Local<v8::Value> val);
      95                 :            : std::string create_js_debug_script(v8::Isolate &isolate, v8::Local<v8::Object> env,
      96                 :            :                                    const WasmEngine::WasmContext &wasm_context);
      97                 :            : void run_inspector(V8InspectorClientImpl &inspector, v8::Isolate &isolate, v8::Local<v8::Object> env);
      98                 :            : 
      99                 :            : }
     100                 :            : 
     101                 :            : }
     102                 :            : 
     103                 :            : }

Generated by: LCOV version 1.16