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

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: 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
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
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();
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 }
OLDNEW
« gin/gin.gyp ('K') | « 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