Line data Source code
1 : // Copyright 2018 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #include <memory>
6 :
7 : #include "test/cctest/cctest.h"
8 :
9 : #include "include/v8-inspector.h"
10 : #include "include/v8.h"
11 : #include "src/inspector/protocol/Runtime.h"
12 :
13 : using v8_inspector::StringBuffer;
14 : using v8_inspector::StringView;
15 : using v8_inspector::V8ContextInfo;
16 : using v8_inspector::V8Inspector;
17 : using v8_inspector::V8InspectorSession;
18 :
19 : namespace {
20 :
21 : class NoopChannel : public V8Inspector::Channel {
22 : public:
23 5 : ~NoopChannel() override = default;
24 0 : void sendResponse(int callId,
25 0 : std::unique_ptr<StringBuffer> message) override {}
26 0 : void sendNotification(std::unique_ptr<StringBuffer> message) override {}
27 0 : void flushProtocolNotifications() override {}
28 : };
29 :
30 0 : void WrapOnInterrupt(v8::Isolate* isolate, void* data) {
31 : const char* object_group = "";
32 : StringView object_group_view(reinterpret_cast<const uint8_t*>(object_group),
33 : strlen(object_group));
34 : reinterpret_cast<V8InspectorSession*>(data)->wrapObject(
35 : isolate->GetCurrentContext(), v8::Null(isolate), object_group_view,
36 0 : false);
37 0 : }
38 :
39 : } // namespace
40 :
41 25880 : TEST(WrapInsideWrapOnInterrupt) {
42 5 : LocalContext env;
43 5 : v8::Isolate* isolate = env->GetIsolate();
44 10 : v8::HandleScope handle_scope(isolate);
45 :
46 5 : v8_inspector::V8InspectorClient default_client;
47 : std::unique_ptr<V8Inspector> inspector =
48 5 : V8Inspector::create(isolate, &default_client);
49 : const char* name = "";
50 : StringView name_view(reinterpret_cast<const uint8_t*>(name), strlen(name));
51 5 : V8ContextInfo context_info(env.local(), 1, name_view);
52 5 : inspector->contextCreated(context_info);
53 :
54 5 : NoopChannel channel;
55 : const char* state = "{}";
56 : StringView state_view(reinterpret_cast<const uint8_t*>(state), strlen(state));
57 : std::unique_ptr<V8InspectorSession> session =
58 5 : inspector->connect(1, &channel, state_view);
59 :
60 : const char* object_group = "";
61 : StringView object_group_view(reinterpret_cast<const uint8_t*>(object_group),
62 : strlen(object_group));
63 5 : isolate->RequestInterrupt(&WrapOnInterrupt, session.get());
64 20 : session->wrapObject(env.local(), v8::Null(isolate), object_group_view, false);
65 77630 : }
|