Skip to content

Commit 0c15c1e

Browse files
committed
implement test262 json module loading
1 parent 55e2738 commit 0c15c1e

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

scripts/test262.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,14 @@ async function runCodeInHarness(yaml, code, importDir) {
552552
let module = moduleCache.get(modulePath)
553553
if (!module) {
554554
const code = fs.readFileSync(modulePath, 'utf8')
555-
module = new vm.SourceTextModule(code + unique(), { context, importModuleDynamically })
555+
if (modulePath.endsWith('json')) {
556+
const evaluate = function () {
557+
this.setExport('default', vm.runInContext('JSON.parse', context)(code))
558+
}
559+
module = new vm.SyntheticModule(['default'], evaluate, { context })
560+
} else {
561+
module = new vm.SourceTextModule(code + unique(), { context, importModuleDynamically })
562+
}
556563
moduleCache.set(modulePath, module)
557564
}
558565
return module
@@ -567,9 +574,13 @@ async function runCodeInHarness(yaml, code, importDir) {
567574
let promise = dynamicImportCache.get(where)
568575
if (!promise) {
569576
const module = findModule(where, context)
570-
promise = module.link(linker)
571-
.then(() => module.evaluate())
572-
.then(() => module)
577+
if (module.status === 'unlinked') {
578+
promise = module.link(linker)
579+
.then(() => module.evaluate())
580+
.then(() => module)
581+
} else {
582+
promise = Promise.resolve(module)
583+
}
573584
dynamicImportCache.set(where, promise)
574585
}
575586
return promise

0 commit comments

Comments
 (0)