OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 "test/inspector-protocol/channel-impl.h" | |
6 | |
7 #include "src/inspector/string-util.h" | |
8 #include "test/inspector-protocol/task-queue.h" | |
9 #include "test/inspector-protocol/task.h" | |
10 | |
11 namespace v8_inspector { | |
12 | |
13 namespace { | |
14 | |
15 class DispatchMessageOnFrontendTask : public Task { | |
16 public: | |
17 DispatchMessageOnFrontendTask(const StringView& message) | |
18 : message_(toString16(message)) {} | |
19 | |
20 bool is_protocol_task() final { return true; } | |
21 | |
22 void Run(v8::Isolate* isolate, | |
23 const v8::Global<v8::Context>& global_context) override { | |
24 v8_inspector::TaskScope task_scope(isolate, global_context); | |
25 v8::Local<v8::Context> context = task_scope.context(); | |
26 v8::Local<v8::Object> global = context->Global(); | |
27 v8::Local<v8::Value> dispatcher; | |
28 if (!global | |
29 ->Get(context, toV8StringInternalized(isolate, "dispatchMessage")) | |
30 .ToLocal(&dispatcher) || | |
31 !dispatcher->IsFunction()) { | |
32 fprintf(stderr, | |
dgozman
2016/09/22 17:44:49
Is this the correct way to return error from a tes
| |
33 "Warning: no dispatchMessage function in test context.\n"); | |
34 return; | |
35 } | |
36 v8::Local<v8::Value> message = toV8String(isolate, message_); | |
37 v8::MaybeLocal<v8::Value> result; | |
38 result = dispatcher.As<v8::Function>()->Call(context, global, 1, &message); | |
39 } | |
40 | |
41 private: | |
42 String16 message_; | |
43 }; | |
44 | |
45 } // namespace | |
46 | |
47 void ChannelImpl::SendMessageToFrontend(const StringView& message) { | |
48 frontend_queue_->Append(new DispatchMessageOnFrontendTask(message)); | |
49 } | |
50 | |
51 } // namespace v8 | |
OLD | NEW |