summaryrefslogtreecommitdiffstats
path: root/mojo/apps/js/main.cc
blob: b5d4486736d60b2666b176880310c3922d8e8146 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/message_loop/message_loop.h"
#include "gin/public/isolate_holder.h"
#include "mojo/apps/js/mojo_runner_delegate.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/cpp/system/macros.h"

#if defined(WIN32)
#if !defined(CDECL)
#define CDECL __cdecl
#endif
#define MOJO_APPS_JS_EXPORT __declspec(dllexport)
#else
#define CDECL
#define MOJO_APPS_JS_EXPORT __attribute__((visibility("default")))
#endif

namespace mojo {
namespace apps {

void Start(MojoHandle pipe, const std::string& module) {
  base::MessageLoop loop;

  gin::IsolateHolder instance(gin::IsolateHolder::kStrictMode);
  MojoRunnerDelegate delegate;
  gin::ShellRunner runner(&delegate, instance.isolate());
  delegate.Start(&runner, pipe, module);

  base::MessageLoop::current()->Run();
}

}  // namespace apps
}  // namespace mojo

extern "C" MOJO_APPS_JS_EXPORT MojoResult CDECL MojoMain(MojoHandle pipe) {
  mojo::apps::Start(pipe, "mojo/apps/js/main");
  return MOJO_RESULT_OK;
}