OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "mojo/edk/js/mojo_runner_delegate.h" | 5 #include "mojo/edk/js/mojo_runner_delegate.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "gin/converter.h" | 9 #include "gin/converter.h" |
10 #include "gin/modules/console.h" | 10 #include "gin/modules/console.h" |
11 #include "gin/modules/module_registry.h" | 11 #include "gin/modules/module_registry.h" |
12 #include "gin/modules/timer.h" | 12 #include "gin/modules/timer.h" |
13 #include "gin/try_catch.h" | 13 #include "gin/try_catch.h" |
14 #include "mojo/edk/js/core.h" | 14 #include "mojo/edk/js/core.h" |
15 #include "mojo/edk/js/handle.h" | 15 #include "mojo/edk/js/handle.h" |
16 #include "mojo/edk/js/support.h" | 16 #include "mojo/edk/js/support.h" |
17 #include "mojo/edk/js/threading.h" | 17 #include "mojo/edk/js/threading.h" |
18 | 18 |
19 namespace mojo { | 19 namespace mojo { |
20 namespace js { | 20 namespace edk { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // TODO(abarth): Rather than loading these modules from the file system, we | 24 // TODO(abarth): Rather than loading these modules from the file system, we |
25 // should load them from the network via Mojo IPC. | 25 // should load them from the network via Mojo IPC. |
26 std::vector<base::FilePath> GetModuleSearchPaths() { | 26 std::vector<base::FilePath> GetModuleSearchPaths() { |
27 std::vector<base::FilePath> search_paths(2); | 27 std::vector<base::FilePath> search_paths(2); |
28 PathService::Get(base::DIR_SOURCE_ROOT, &search_paths[0]); | 28 PathService::Get(base::DIR_SOURCE_ROOT, &search_paths[0]); |
29 PathService::Get(base::DIR_EXE, &search_paths[1]); | 29 PathService::Get(base::DIR_EXE, &search_paths[1]); |
30 search_paths[1] = search_paths[1].AppendASCII("gen"); | 30 search_paths[1] = search_paths[1].AppendASCII("gen"); |
(...skipping 11 matching lines...) Expand all Loading... |
42 gin::ConvertToV8(isolate, Handle(pipe)) }; | 42 gin::ConvertToV8(isolate, Handle(pipe)) }; |
43 runner->Call(start, runner->global(), 1, args); | 43 runner->Call(start, runner->global(), 1, args); |
44 } | 44 } |
45 | 45 |
46 } // namespace | 46 } // namespace |
47 | 47 |
48 MojoRunnerDelegate::MojoRunnerDelegate() | 48 MojoRunnerDelegate::MojoRunnerDelegate() |
49 : ModuleRunnerDelegate(GetModuleSearchPaths()) { | 49 : ModuleRunnerDelegate(GetModuleSearchPaths()) { |
50 AddBuiltinModule(gin::Console::kModuleName, gin::Console::GetModule); | 50 AddBuiltinModule(gin::Console::kModuleName, gin::Console::GetModule); |
51 AddBuiltinModule(gin::TimerModule::kName, gin::TimerModule::GetModule); | 51 AddBuiltinModule(gin::TimerModule::kName, gin::TimerModule::GetModule); |
52 AddBuiltinModule(js::Core::kModuleName, js::Core::GetModule); | 52 AddBuiltinModule(Core::kModuleName, Core::GetModule); |
53 AddBuiltinModule(js::Support::kModuleName, js::Support::GetModule); | 53 AddBuiltinModule(Support::kModuleName, Support::GetModule); |
54 AddBuiltinModule(js::Threading::kModuleName, js::Threading::GetModule); | 54 AddBuiltinModule(Threading::kModuleName, Threading::GetModule); |
55 } | 55 } |
56 | 56 |
57 MojoRunnerDelegate::~MojoRunnerDelegate() { | 57 MojoRunnerDelegate::~MojoRunnerDelegate() { |
58 } | 58 } |
59 | 59 |
60 void MojoRunnerDelegate::Start(gin::Runner* runner, | 60 void MojoRunnerDelegate::Start(gin::Runner* runner, |
61 MojoHandle pipe, | 61 MojoHandle pipe, |
62 const std::string& module) { | 62 const std::string& module) { |
63 gin::Runner::Scope scope(runner); | 63 gin::Runner::Scope scope(runner); |
64 gin::ModuleRegistry* registry = | 64 gin::ModuleRegistry* registry = |
65 gin::ModuleRegistry::From(runner->GetContextHolder()->context()); | 65 gin::ModuleRegistry::From(runner->GetContextHolder()->context()); |
66 registry->LoadModule(runner->GetContextHolder()->isolate(), module, | 66 registry->LoadModule(runner->GetContextHolder()->isolate(), module, |
67 base::Bind(StartCallback, runner->GetWeakPtr(), pipe)); | 67 base::Bind(StartCallback, runner->GetWeakPtr(), pipe)); |
68 AttemptToLoadMoreModules(runner); | 68 AttemptToLoadMoreModules(runner); |
69 } | 69 } |
70 | 70 |
71 void MojoRunnerDelegate::UnhandledException(gin::ShellRunner* runner, | 71 void MojoRunnerDelegate::UnhandledException(gin::ShellRunner* runner, |
72 gin::TryCatch& try_catch) { | 72 gin::TryCatch& try_catch) { |
73 gin::ModuleRunnerDelegate::UnhandledException(runner, try_catch); | 73 gin::ModuleRunnerDelegate::UnhandledException(runner, try_catch); |
74 LOG(ERROR) << try_catch.GetStackTrace(); | 74 LOG(ERROR) << try_catch.GetStackTrace(); |
75 } | 75 } |
76 | 76 |
77 } // namespace js | 77 } // namespace edk |
78 } // namespace mojo | 78 } // namespace mojo |
OLD | NEW |