[inspector] fixed CommandLineAPIData leak

We can use v8::ArrayBuffer to store struct.

R=dgozman@chromium.org

Bug: none
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I6c4e994e3a8b0a19ad06f89dfadf808f8c6a68e6
Reviewed-on: https://chromium-review.googlesource.com/772036
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49390}
This commit is contained in:
Alexey Kozyatinskiy 2017-11-15 08:33:13 -08:00 committed by Commit Bot
parent 4ab559cb89
commit f51192bc4d
2 changed files with 6 additions and 5 deletions

View File

@ -663,9 +663,10 @@ v8::Local<v8::Object> V8Console::createCommandLineAPI(
DCHECK(success);
USE(success);
// TODO(dgozman): this CommandLineAPIData instance leaks. Use PodArray maybe?
v8::Local<v8::External> data =
v8::External::New(isolate, new CommandLineAPIData(this, sessionId));
v8::Local<v8::ArrayBuffer> data =
v8::ArrayBuffer::New(isolate, sizeof(CommandLineAPIData));
*static_cast<CommandLineAPIData*>(data->GetContents().Data()) =
CommandLineAPIData(this, sessionId);
createBoundFunctionProperty(context, commandLineAPI, data, "dir",
&V8Console::call<&V8Console::Dir>,
"function dir(value) { [Command Line API] }");

View File

@ -108,14 +108,14 @@ class V8Console : public v8::debug::ConsoleDelegate {
int)>
static void call(const v8::FunctionCallbackInfo<v8::Value>& info) {
CommandLineAPIData* data = static_cast<CommandLineAPIData*>(
info.Data().As<v8::External>()->Value());
info.Data().As<v8::ArrayBuffer>()->GetContents().Data());
(data->first->*func)(info, data->second);
}
template <void (V8Console::*func)(const v8::debug::ConsoleCallArguments&,
const v8::debug::ConsoleContext&)>
static void call(const v8::FunctionCallbackInfo<v8::Value>& info) {
CommandLineAPIData* data = static_cast<CommandLineAPIData*>(
info.Data().As<v8::External>()->Value());
info.Data().As<v8::ArrayBuffer>()->GetContents().Data());
v8::debug::ConsoleCallArguments args(info);
(data->first->*func)(args, v8::debug::ConsoleContext());
}