Aggregate damage rects in surface aggregator
[chromium-blink-merge.git] / gin / shell / gin_main.cc
blobd8c32adfc512ac4b59d98178c4b85d7d95c44102
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.
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/i18n/icu_util.h"
10 #include "base/message_loop/message_loop.h"
11 #include "gin/modules/console.h"
12 #include "gin/modules/module_runner_delegate.h"
13 #include "gin/public/isolate_holder.h"
14 #include "gin/test/file_runner.h"
15 #include "gin/try_catch.h"
17 namespace gin {
18 namespace {
20 std::string Load(const base::FilePath& path) {
21 std::string source;
22 if (!ReadFileToString(path, &source))
23 LOG(FATAL) << "Unable to read " << path.LossyDisplayName();
24 return source;
27 void Run(base::WeakPtr<Runner> runner, const base::FilePath& path) {
28 if (!runner)
29 return;
30 Runner::Scope scope(runner.get());
31 runner->Run(Load(path), path.AsUTF8Unsafe());
34 std::vector<base::FilePath> GetModuleSearchPaths() {
35 std::vector<base::FilePath> module_base(1);
36 CHECK(base::GetCurrentDirectory(&module_base[0]));
37 return module_base;
40 class GinShellRunnerDelegate : public ModuleRunnerDelegate {
41 public:
42 GinShellRunnerDelegate() : ModuleRunnerDelegate(GetModuleSearchPaths()) {
43 AddBuiltinModule(Console::kModuleName, Console::GetModule);
46 virtual void UnhandledException(ShellRunner* runner,
47 TryCatch& try_catch) OVERRIDE {
48 ModuleRunnerDelegate::UnhandledException(runner, try_catch);
49 LOG(ERROR) << try_catch.GetStackTrace();
52 private:
53 DISALLOW_COPY_AND_ASSIGN(GinShellRunnerDelegate);
56 } // namespace
57 } // namespace gin
59 int main(int argc, char** argv) {
60 base::AtExitManager at_exit;
61 CommandLine::Init(argc, argv);
62 base::i18n::InitializeICU();
64 gin::IsolateHolder instance(gin::IsolateHolder::kStrictMode);
66 base::MessageLoop message_loop;
68 gin::GinShellRunnerDelegate delegate;
69 gin::ShellRunner runner(&delegate, instance.isolate());
72 gin::Runner::Scope scope(&runner);
73 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
76 CommandLine::StringVector args = CommandLine::ForCurrentProcess()->GetArgs();
77 for (CommandLine::StringVector::const_iterator it = args.begin();
78 it != args.end(); ++it) {
79 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
80 gin::Run, runner.GetWeakPtr(), base::FilePath(*it)));
83 message_loop.RunUntilIdle();
84 return 0;