Roll src/third_party/WebKit a562e22:1c61ac4 (svn 198174:198176)
[chromium-blink-merge.git] / gin / modules / console.cc
blob75241df081a7acd1f95fc8e2a87165890f4966e3
1 // Copyright 2013 The Chromium 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.
5 #include "gin/modules/console.h"
7 #include <iostream>
9 #include "base/strings/string_util.h"
10 #include "gin/arguments.h"
11 #include "gin/converter.h"
12 #include "gin/object_template_builder.h"
13 #include "gin/per_isolate_data.h"
14 #include "gin/public/wrapper_info.h"
16 using v8::ObjectTemplate;
18 namespace gin {
20 namespace {
22 void Log(Arguments* args) {
23 std::vector<std::string> messages;
24 if (!args->GetRemaining(&messages)) {
25 args->ThrowError();
26 return;
28 std::cout << JoinString(messages, ' ') << std::endl;
31 WrapperInfo g_wrapper_info = { kEmbedderNativeGin };
33 } // namespace
35 const char Console::kModuleName[] = "console";
37 v8::Local<v8::Value> Console::GetModule(v8::Isolate* isolate) {
38 PerIsolateData* data = PerIsolateData::From(isolate);
39 v8::Local<ObjectTemplate> templ = data->GetObjectTemplate(&g_wrapper_info);
40 if (templ.IsEmpty()) {
41 templ = ObjectTemplateBuilder(isolate)
42 .SetMethod("log", Log)
43 .Build();
44 data->SetObjectTemplate(&g_wrapper_info, templ);
46 return templ->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();
49 } // namespace gin