Chromium Code Reviews| Index: mojo/apps/js/mojo_runner_delegate.cc |
| diff --git a/mojo/apps/js/mojo_runner_delegate.cc b/mojo/apps/js/mojo_runner_delegate.cc |
| index 610ede4090006d18bdd123983bb888f201b87d59..3f5ed3fc732665f79b69d030a8913446f978f82d 100644 |
| --- a/mojo/apps/js/mojo_runner_delegate.cc |
| +++ b/mojo/apps/js/mojo_runner_delegate.cc |
| @@ -4,11 +4,13 @@ |
| #include "mojo/apps/js/mojo_runner_delegate.h" |
| +#include "base/bind.h" |
| #include "base/path_service.h" |
| +#include "gin/converter.h" |
| #include "gin/modules/console.h" |
| #include "gin/modules/module_registry.h" |
| #include "gin/try_catch.h" |
| -#include "mojo/apps/js/bootstrap.h" |
| +#include "mojo/apps/js/threading.h" |
| #include "mojo/public/bindings/js/core.h" |
| #include "mojo/public/bindings/js/support.h" |
| @@ -27,11 +29,28 @@ std::vector<base::FilePath> GetModuleSearchPaths() { |
| return search_paths; |
| } |
| +void StartCallback(base::WeakPtr<gin::Runner> runner, |
| + MojoHandle pipe, |
| + v8::Handle<v8::Value> module) { |
| + if (!runner) { |
|
Aaron Boodman
2013/11/27 19:02:41
Can we really get here with runner not populated?
abarth-chromium
2013/11/27 19:18:09
Removed.
|
| + CHECK(MojoClose(pipe) == MOJO_RESULT_OK); |
| + return; |
| + } |
| + v8::Isolate* isolate = runner->isolate(); |
| + v8::Handle<v8::Function> start; |
| + if (!gin::ConvertFromV8(module, &start)) { |
|
Aaron Boodman
2013/11/27 19:02:41
What would cause this to fail? I think it should j
abarth-chromium
2013/11/27 19:18:09
This can fail if the requested module returns an o
Aaron Boodman
2013/11/27 20:35:49
But we control main.js. It seems like if this ever
|
| + CHECK(MojoClose(pipe) == MOJO_RESULT_OK); |
| + return; |
| + } |
| + v8::Handle<v8::Value> args[] = { gin::ConvertToV8(isolate, pipe) }; |
| + runner->Call(start, runner->global(), 1, args); |
|
Aaron Boodman
2013/11/27 19:02:41
We should do a wrapper around calling JS functions
abarth-chromium
2013/11/27 19:18:09
I bet! :)
|
| +} |
| + |
| } // namespace |
| MojoRunnerDelegate::MojoRunnerDelegate() |
| : ModuleRunnerDelegate(GetModuleSearchPaths()) { |
| - AddBuiltinModule(Bootstrap::kModuleName, Bootstrap::GetTemplate); |
| + AddBuiltinModule(Threading::kModuleName, Threading::GetTemplate); |
| AddBuiltinModule(gin::Console::kModuleName, gin::Console::GetTemplate); |
| AddBuiltinModule(js::Core::kModuleName, js::Core::GetTemplate); |
| AddBuiltinModule(js::Support::kModuleName, js::Support::GetTemplate); |
| @@ -40,6 +59,16 @@ MojoRunnerDelegate::MojoRunnerDelegate() |
| MojoRunnerDelegate::~MojoRunnerDelegate() { |
| } |
| +void MojoRunnerDelegate::Start(gin::Runner* runner, |
| + MojoHandle pipe, |
| + const std::string& module) { |
| + gin::Runner::Scope scope(runner); |
| + gin::ModuleRegistry* registry = gin::ModuleRegistry::From(runner->context()); |
| + registry->LoadModule(runner->isolate(), module, |
| + base::Bind(StartCallback, runner->GetWeakPtr(), pipe)); |
| + AttemptToLoadMoreModules(runner); |
| +} |
| + |
| void MojoRunnerDelegate::UnhandledException(gin::Runner* runner, |
| gin::TryCatch& try_catch) { |
| gin::ModuleRunnerDelegate::UnhandledException(runner, try_catch); |