OLD | NEW |
---|---|
(Empty) | |
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 "base/at_exit.h" | |
6 #include "base/bind.h" | |
7 #include "base/command_line.h" | |
8 #include "base/file_util.h" | |
9 #include "base/message_loop/message_loop.h" | |
10 #include "gin/initialize.h" | |
11 #include "gin/modules/module_runner_delegate.h" | |
12 #include "gin/test/file_runner.h" | |
13 #include "gin/try_catch.h" | |
14 | |
15 namespace gin { | |
16 namespace { | |
17 | |
18 std::string Load(const base::FilePath& path) { | |
19 std::string source; | |
20 if (!ReadFileToString(path, &source)) | |
21 LOG(FATAL) << "Unable to read " << path.LossyDisplayName(); | |
22 return source; | |
23 } | |
24 | |
25 void Run(base::WeakPtr<Runner> runner, const std::string& source) { | |
26 if (!runner) | |
27 return; | |
28 Runner::Scope scope(runner.get()); | |
29 runner->Run(source); | |
30 } | |
31 | |
32 base::FilePath GetModuleBase() { | |
33 base::FilePath module_base; | |
34 CHECK(file_util::GetCurrentDirectory(&module_base)); | |
35 return module_base; | |
36 } | |
37 | |
38 class ShellRunnerDelegate : public ModuleRunnerDelegate { | |
39 public: | |
40 ShellRunnerDelegate() : ModuleRunnerDelegate(GetModuleBase()) {} | |
41 | |
42 virtual void UnhandledException(Runner* runner, | |
43 TryCatch& try_catch) OVERRIDE { | |
44 ModuleRunnerDelegate::UnhandledException(runner, try_catch); | |
45 LOG(ERROR) << try_catch.GetPrettyMessage(); | |
46 } | |
47 }; | |
jochen (gone - plz use gerrit)
2013/11/18 12:46:05
nit. private: DISALLOW_COPY_AND_ASSIGN(ShellRunner
abarth-chromium
2013/11/18 15:33:06
Done.
| |
48 | |
49 } // namespace | |
50 } // namespace gin | |
51 | |
52 int main(int argc, char** argv) { | |
53 base::AtExitManager at_exit; | |
54 CommandLine::Init(argc, argv); | |
55 gin::Initialize(); | |
jochen (gone - plz use gerrit)
2013/11/18 12:46:05
in gin::Initialize, you should invoke base::i18n::
abarth-chromium
2013/11/18 15:33:06
Done.
abarth-chromium
2013/11/18 15:34:37
If I do that, gin_shell doesn't link. Maybe I nee
| |
56 | |
57 base::MessageLoop message_loop; | |
58 | |
59 gin::ShellRunnerDelegate delegate; | |
60 gin::Runner runner(&delegate, v8::Isolate::GetCurrent()); | |
61 | |
62 CommandLine::StringVector args = CommandLine::ForCurrentProcess()->GetArgs(); | |
63 for (CommandLine::StringVector::const_iterator it = args.begin(); | |
64 it != args.end(); ++it) { | |
65 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | |
66 gin::Run, runner.GetWeakPtr(), gin::Load(base::FilePath(*it)))); | |
67 } | |
68 | |
69 message_loop.RunUntilIdle(); | |
70 return 0; | |
71 } | |
OLD | NEW |