MCPcopy Create free account
hub / github.com/marijnh/Eloquent-JavaScript / nextSandbox

Function nextSandbox

src/run_tests.mjs:244–274  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

242
243let i = 0, boxes = Object.keys(sandboxes).map(k => sandboxes[k])
244function 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}
275if (doRun) nextSandbox()

Callers 1

run_tests.mjsFile · 0.85

Calls 2

reportFunction · 0.85
runMethod · 0.80

Tested by

no test coverage detected