()
| 242 | |
| 243 | let i = 0, boxes = Object.keys(sandboxes).map(k => sandboxes[k]) |
| 244 | function nextSandbox() { |
| 245 | if (i == boxes.length) return |
| 246 | let sandbox = boxes[i] |
| 247 | i++ |
| 248 | if (chapNum < 13 || chapNum >= 20 && chapNum < 22) { // Language-only |
| 249 | try { |
| 250 | ;(new Function("console, require, module", baseCode + sandbox.code))(_console, chapNum >= 20 && fakeRequire, {}) |
| 251 | nextSandbox() |
| 252 | } catch(e) { |
| 253 | report(e) |
| 254 | } |
| 255 | } else { |
| 256 | let {JSDOM} = require("jsdom") |
| 257 | new JSDOM({ |
| 258 | url: "https://eloquentjavascript.net/" + file + "#" + i, |
| 259 | html: sandbox.html || "<!doctype html><body></body>", |
| 260 | src: [baseCode], |
| 261 | done: function(err, window) { |
| 262 | if (err) report(err[0]) |
| 263 | window.console = _console |
| 264 | window.Element.prototype.innerText = "abc" |
| 265 | try { |
| 266 | window.run(sandbox.code, file + "#" + i) |
| 267 | } catch (e) { |
| 268 | report(e) |
| 269 | } |
| 270 | nextSandbox() |
| 271 | } |
| 272 | }) |
| 273 | } |
| 274 | } |
| 275 | if (doRun) nextSandbox() |
no test coverage detected