@@ -31,8 +31,9 @@ class JSDOMNodeJSEnv(config: JSDOMNodeJSEnv.Config) extends JSEnv {
3131
3232 def start (input : Input , runConfig : RunConfig ): JSRun = {
3333 JSDOMNodeJSEnv .validator.validate(runConfig)
34+ val scripts = validateInput(input)
3435 try {
35- internalStart(initFiles ++ codeWithJSDOMContext(input ), runConfig)
36+ internalStart(codeWithJSDOMContext(scripts ), runConfig)
3637 } catch {
3738 case NonFatal (t) =>
3839 JSRun .failed(t)
@@ -42,9 +43,18 @@ class JSDOMNodeJSEnv(config: JSDOMNodeJSEnv.Config) extends JSEnv {
4243 def startWithCom (input : Input , runConfig : RunConfig ,
4344 onMessage : String => Unit ): JSComRun = {
4445 JSDOMNodeJSEnv .validator.validate(runConfig)
46+ val scripts = validateInput(input)
4547 ComRun .start(runConfig, onMessage) { comLoader =>
46- val files = initFiles ::: (comLoader :: codeWithJSDOMContext(input))
47- internalStart(files, runConfig)
48+ internalStart(comLoader :: codeWithJSDOMContext(scripts), runConfig)
49+ }
50+ }
51+
52+ private def validateInput (input : Input ): List [VirtualBinaryFile ] = {
53+ input match {
54+ case Input .ScriptsToLoad (scripts) =>
55+ scripts
56+ case _ =>
57+ throw new UnsupportedInputException (input)
4858 }
4959 }
5060
@@ -57,19 +67,13 @@ class JSDOMNodeJSEnv(config: JSDOMNodeJSEnv.Config) extends JSEnv {
5767 ExternalJSRun .start(command, externalConfig)(JSDOMNodeJSEnv .write(files))
5868 }
5969
60- private def initFiles : List [VirtualBinaryFile ] =
61- List (JSDOMNodeJSEnv .runtimeEnv, Support .fixPercentConsole)
62-
6370 private def env : Map [String , String ] =
6471 Map (" NODE_MODULE_CONTEXTS" -> " 0" ) ++ config.env
6572
66- private def scriptFiles (input : Input ): List [VirtualBinaryFile ] = input match {
67- case Input .ScriptsToLoad (scripts) => scripts
68- case _ => throw new UnsupportedInputException (input)
69- }
73+ private def codeWithJSDOMContext (
74+ scripts : List [VirtualBinaryFile ]): List [VirtualBinaryFile ] = {
7075
71- private def codeWithJSDOMContext (input : Input ): List [VirtualBinaryFile ] = {
72- val scriptsURIs = scriptFiles(input).map(JSDOMNodeJSEnv .materialize(_))
76+ val scriptsURIs = scripts.map(JSDOMNodeJSEnv .materialize(_))
7377 val scriptsURIsAsJSStrings =
7478 scriptsURIs.map(uri => '"' + escapeJS(uri.toASCIIString) + '"' )
7579 val jsDOMCode = {
@@ -102,7 +106,6 @@ class JSDOMNodeJSEnv(config: JSDOMNodeJSEnv.Config) extends JSEnv {
102106 | virtualConsole: virtualConsole,
103107 | created: function (error, window) {
104108 | if (error == null) {
105- | window["__ScalaJSEnv"] = __ScalaJSEnv;
106109 | window["scalajsCom"] = global.scalajsCom;
107110 | } else {
108111 | throw error;
@@ -120,16 +123,6 @@ class JSDOMNodeJSEnv(config: JSDOMNodeJSEnv.Config) extends JSEnv {
120123object JSDOMNodeJSEnv {
121124 private lazy val validator = ExternalJSRun .supports(RunConfig .Validator ())
122125
123- private lazy val runtimeEnv = {
124- MemVirtualBinaryFile .fromStringUTF8(" scalaJSEnvInfo.js" ,
125- """
126- |__ScalaJSEnv = {
127- | exitFunction: function(status) { process.exit(status); }
128- |};
129- """ .stripMargin
130- )
131- }
132-
133126 // Copied from NodeJSEnv.scala upstream
134127 private def write (files : List [VirtualBinaryFile ])(out : OutputStream ): Unit = {
135128 val p = new PrintStream (out, false , " UTF8" )
0 commit comments