Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: gin/shell/gin_main.cc

Issue 74753002: Introduce gin_shell (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix more header nits Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gin/runner_unittest.cc ('k') | gin/test/file_runner.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
48 private:
49 DISALLOW_COPY_AND_ASSIGN(ShellRunnerDelegate);
50 };
51
52 } // namespace
53 } // namespace gin
54
55 int main(int argc, char** argv) {
56 base::AtExitManager at_exit;
57 CommandLine::Init(argc, argv);
58 gin::Initialize();
59
60 base::MessageLoop message_loop;
61
62 gin::ShellRunnerDelegate delegate;
63 gin::Runner runner(&delegate, v8::Isolate::GetCurrent());
64
65 CommandLine::StringVector args = CommandLine::ForCurrentProcess()->GetArgs();
66 for (CommandLine::StringVector::const_iterator it = args.begin();
67 it != args.end(); ++it) {
68 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
69 gin::Run, runner.GetWeakPtr(), gin::Load(base::FilePath(*it))));
70 }
71
72 message_loop.RunUntilIdle();
73 return 0;
74 }
OLDNEW
« no previous file with comments | « gin/runner_unittest.cc ('k') | gin/test/file_runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698