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. 4 5 #include "gin/modules/console.h" 6 7 #include <iostream> 8 9 #include "base/strings/string_util.h" 10 #include "gin/arguments.h" 11 #include "gin/converter.h" 12 #include "gin/per_isolate_data.h" 13 #include "gin/public/wrapper_info.h" 14 15 using v8::ObjectTemplate; 16 17 namespace gin { 18 19 namespace { 20 21 void Log(const v8::FunctionCallbackInfo<v8::Value>& info) { 22 Arguments args(info); 23 24 std::vector<std::string> messages; 25 if (!args.GetRemaining(&messages)) 26 return args.ThrowTypeError("Expected strings."); 27 28 std::cout << JoinString(messages, ' ') << std::endl; 29 } 30 31 WrapperInfo g_wrapper_info = { kEmbedderNativeGin }; 32 33 } // namespace 34 35 const char Console::kModuleName[] = "console"; 36 37 v8::Local<ObjectTemplate> Console::GetTemplate(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 = ObjectTemplate::New(); 42 templ->Set(StringToSymbol(isolate, "log"), 43 v8::FunctionTemplate::New(isolate, Log)); 44 data->SetObjectTemplate(&g_wrapper_info, templ); 45 } 46 return templ; 47 } 48 49 } // namespace gin 50