| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "gin/modules/console.h" | 5 #include "gin/test/gc.h" |
| 6 | 6 |
| 7 #include <iostream> | 7 #include "base/bind.h" |
| 8 | 8 #include "base/logging.h" |
| 9 #include "base/strings/string_util.h" | |
| 10 #include "gin/arguments.h" | 9 #include "gin/arguments.h" |
| 11 #include "gin/converter.h" | 10 #include "gin/converter.h" |
| 11 #include "gin/function_template.h" |
| 12 #include "gin/object_template_builder.h" | 12 #include "gin/object_template_builder.h" |
| 13 #include "gin/per_isolate_data.h" | 13 #include "gin/per_isolate_data.h" |
| 14 #include "gin/public/wrapper_info.h" | 14 #include "gin/public/wrapper_info.h" |
| 15 | 15 #include "gin/wrappable.h" |
| 16 using v8::ObjectTemplate; | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 namespace gin { | 18 namespace gin { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | |
| 22 void Log(Arguments* args) { | |
| 23 std::vector<std::string> messages; | |
| 24 if (!args->GetRemaining(&messages)) { | |
| 25 args->ThrowError(); | |
| 26 return; | |
| 27 } | |
| 28 std::cout << JoinString(messages, ' ') << std::endl; | |
| 29 } | |
| 30 | |
| 31 WrapperInfo g_wrapper_info = { kEmbedderNativeGin }; | 21 WrapperInfo g_wrapper_info = { kEmbedderNativeGin }; |
| 32 | |
| 33 } // namespace | 22 } // namespace |
| 34 | 23 |
| 35 const char Console::kModuleName[] = "console"; | 24 const char GC::kModuleName[] = "gc"; |
| 36 | 25 |
| 37 v8::Local<v8::Value> Console::GetModule(v8::Isolate* isolate) { | 26 v8::Local<v8::Value> GC::GetModule(v8::Isolate* isolate) { |
| 38 PerIsolateData* data = PerIsolateData::From(isolate); | 27 PerIsolateData* data = PerIsolateData::From(isolate); |
| 39 v8::Local<ObjectTemplate> templ = data->GetObjectTemplate(&g_wrapper_info); | 28 v8::Local<v8::ObjectTemplate> templ = |
| 29 data->GetObjectTemplate(&g_wrapper_info); |
| 40 if (templ.IsEmpty()) { | 30 if (templ.IsEmpty()) { |
| 41 templ = ObjectTemplateBuilder(isolate) | 31 templ = ObjectTemplateBuilder(isolate) |
| 42 .SetMethod("log", Log) | 32 .SetMethod("collectGarbage", v8::V8::LowMemoryNotification) |
| 43 .Build(); | 33 .Build(); |
| 44 data->SetObjectTemplate(&g_wrapper_info, templ); | 34 data->SetObjectTemplate(&g_wrapper_info, templ); |
| 45 } | 35 } |
| 46 return templ->NewInstance(); | 36 return templ->NewInstance(); |
| 47 } | 37 } |
| 48 | 38 |
| 49 } // namespace gin | 39 } // namespace gin |
| OLD | NEW |