@@ -78,79 +78,46 @@ class JSDOMNodeJSEnv(config: JSDOMNodeJSEnv.Config) extends JSEnv {
78
78
val scriptsURIsJSArray = scriptsURIsAsJSStrings.mkString(" [" , " , " , " ]" )
79
79
val jsDOMCode = {
80
80
s """
81
- |
82
81
|(function () {
83
82
| var jsdom = require("jsdom");
84
83
|
85
- | if (typeof jsdom.JSDOM === "function") {
86
- | // jsdom >= 10.0.0
87
- | var virtualConsole = new jsdom.VirtualConsole()
88
- | .sendTo(console, { omitJSDOMErrors: true });
89
- | virtualConsole.on("jsdomError", function (error) {
90
- | try {
91
- | // Display as much info about the error as possible
92
- | if (error.detail && error.detail.stack) {
93
- | console.error("" + error.detail);
94
- | console.error(error.detail.stack);
95
- | } else {
96
- | console.error(error);
97
- | }
98
- | } finally {
99
- | // Whatever happens, kill the process so that the run fails
100
- | process.exit(1);
84
+ | var virtualConsole = new jsdom.VirtualConsole()
85
+ | .sendTo(console, { omitJSDOMErrors: true });
86
+ | virtualConsole.on("jsdomError", function (error) {
87
+ | try {
88
+ | // Display as much info about the error as possible
89
+ | if (error.detail && error.detail.stack) {
90
+ | console.error("" + error.detail);
91
+ | console.error(error.detail.stack);
92
+ | } else {
93
+ | console.error(error);
101
94
| }
102
- | });
103
- |
104
- | var dom = new jsdom.JSDOM("", {
105
- | virtualConsole: virtualConsole,
106
- | url: "http://localhost/",
107
- |
108
- | /* Allow unrestricted <script> tags. This is exactly as
109
- | * "dangerous" as the arbitrary execution of script files we
110
- | * do in the non-jsdom Node.js env.
111
- | */
112
- | resources: "usable",
113
- | runScripts: "dangerously"
114
- | });
95
+ | } finally {
96
+ | // Whatever happens, kill the process so that the run fails
97
+ | process.exit(1);
98
+ | }
99
+ | });
115
100
|
116
- | var window = dom.window;
117
- | window["scalajsCom"] = global.scalajsCom;
101
+ | var dom = new jsdom.JSDOM("", {
102
+ | virtualConsole: virtualConsole,
103
+ | url: "http://localhost/",
118
104
|
119
- | var scriptsSrcs = $scriptsURIsJSArray;
120
- | for (var i = 0; i < scriptsSrcs.length; i++) {
121
- | var script = window.document.createElement("script");
122
- | script.src = scriptsSrcs[i];
123
- | window.document.body.appendChild(script);
124
- | }
125
- | } else {
126
- | // jsdom v9.x
127
- | var virtualConsole = jsdom.createVirtualConsole()
128
- | .sendTo(console, { omitJsdomErrors: true });
129
- | virtualConsole.on("jsdomError", function (error) {
130
- | /* This inelegant if + console.error is the only way I found
131
- | * to make sure the stack trace of the original error is
132
- | * printed out.
133
- | */
134
- | if (error.detail && error.detail.stack)
135
- | console.error(error.detail.stack);
105
+ | /* Allow unrestricted <script> tags. This is exactly as
106
+ | * "dangerous" as the arbitrary execution of script files we
107
+ | * do in the non-jsdom Node.js env.
108
+ | */
109
+ | resources: "usable",
110
+ | runScripts: "dangerously"
111
+ | });
136
112
|
137
- | // Throw the error anew to make sure the whole execution fails
138
- | throw error;
139
- | });
113
+ | var window = dom.window;
114
+ | window["scalajsCom"] = global.scalajsCom;
140
115
|
141
- | jsdom.env({
142
- | html: "",
143
- | virtualConsole: virtualConsole,
144
- | url: "http://localhost/",
145
- | created: function (error, window) {
146
- | if (error == null) {
147
- | window["scalajsCom"] = global.scalajsCom;
148
- | } else {
149
- | throw error;
150
- | }
151
- | },
152
- | scripts: $scriptsURIsJSArray
153
- | });
116
+ | var scriptsSrcs = $scriptsURIsJSArray;
117
+ | for (var i = 0; i < scriptsSrcs.length; i++) {
118
+ | var script = window.document.createElement("script");
119
+ | script.src = scriptsSrcs[i];
120
+ | window.document.body.appendChild(script);
154
121
| }
155
122
|})();
156
123
| """ .stripMargin
0 commit comments