Skip to content

Commit 9dde29e

Browse files
authored
Merge pull request #43 from sjrd/drop-jsdom-9
Drop support for jsdom 9.x.
2 parents e2adf2b + 4efe39a commit 9dde29e

File tree

3 files changed

+33
-67
lines changed

3 files changed

+33
-67
lines changed

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ scala:
77
jdk:
88
- openjdk8
99
env:
10-
- JSDOM_VERSION=9.12.0
1110
- JSDOM_VERSION=10.0.0
1211
- JSDOM_VERSION=16.0.0
1312
install:

build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
inThisBuild(Seq(
2-
version := "1.0.1-SNAPSHOT",
2+
version := "1.1.0-SNAPSHOT",
33
organization := "org.scala-js",
44

55
crossScalaVersions := Seq("2.12.10", "2.11.12", "2.13.1"),

jsdom-nodejs-env/src/main/scala/org/scalajs/jsenv/jsdomnodejs/JSDOMNodeJSEnv.scala

+32-65
Original file line numberDiff line numberDiff line change
@@ -78,79 +78,46 @@ class JSDOMNodeJSEnv(config: JSDOMNodeJSEnv.Config) extends JSEnv {
7878
val scriptsURIsJSArray = scriptsURIsAsJSStrings.mkString("[", ", ", "]")
7979
val jsDOMCode = {
8080
s"""
81-
|
8281
|(function () {
8382
| var jsdom = require("jsdom");
8483
|
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);
10194
| }
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+
| });
115100
|
116-
| var window = dom.window;
117-
| window["scalajsCom"] = global.scalajsCom;
101+
| var dom = new jsdom.JSDOM("", {
102+
| virtualConsole: virtualConsole,
103+
| url: "http://localhost/",
118104
|
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+
| });
136112
|
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;
140115
|
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);
154121
| }
155122
|})();
156123
|""".stripMargin

0 commit comments

Comments
 (0)