summaryrefslogtreecommitdiff
path: root/examples/scala-js/tools/shared/src/main/scala/scala/scalajs/tools/env/ComJSEnv.scala
blob: 882e46ac19216a1b8396830315d2d34126668f40 (plain) (blame)
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
/*                     __                                               *\
**     ________ ___   / /  ___      __ ____  Scala.js sbt plugin        **
**    / __/ __// _ | / /  / _ | __ / // __/  (c) 2013, LAMP/EPFL        **
**  __\ \/ /__/ __ |/ /__/ __ |/_// /_\ \    http://scala-js.org/       **
** /____/\___/_/ |_/____/_/ | |__/ /____/                               **
**                          |/____/                                     **
\*                                                                      */


package scala.scalajs.tools.env

import scala.scalajs.tools.io._
import scala.scalajs.tools.classpath._
import scala.scalajs.tools.logging._

/** An [[AsyncJSEnv]] that provides communication to and from the JS VM.
 *
 *  Inside the VM there is a global JavaScript object named `scalajsCom` that
 *  can be used to control the message channel. It's operations are:
 *  {{{
 *  // initialize com (with callback)
 *  scalajsCom.init(function(msg) { console.log("Received: " + msg); });
 *
 *  // send a message to host system
 *  scalajsCom.send("my message");
 *
 *  // close com (releases callback, allowing VM to terminate)
 *  scalajsCom.close();
 *  }}}
 */
trait ComJSEnv extends AsyncJSEnv {
  def comRunner(classpath: CompleteClasspath, code: VirtualJSFile,
      logger: Logger, console: JSConsole): ComJSRunner
}

object ComJSEnv {
  class ComClosedException extends Exception("JSCom has been closed")
}