Skip to content

Commit

Permalink
implement test262 json module loading
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Dec 18, 2022
1 parent 55e2738 commit 0c15c1e
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions scripts/test262.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,14 @@ async function runCodeInHarness(yaml, code, importDir) {
let module = moduleCache.get(modulePath)
if (!module) {
const code = fs.readFileSync(modulePath, 'utf8')
module = new vm.SourceTextModule(code + unique(), { context, importModuleDynamically })
if (modulePath.endsWith('json')) {
const evaluate = function () {
this.setExport('default', vm.runInContext('JSON.parse', context)(code))
}
module = new vm.SyntheticModule(['default'], evaluate, { context })
} else {
module = new vm.SourceTextModule(code + unique(), { context, importModuleDynamically })
}
moduleCache.set(modulePath, module)
}
return module
Expand All @@ -567,9 +574,13 @@ async function runCodeInHarness(yaml, code, importDir) {
let promise = dynamicImportCache.get(where)
if (!promise) {
const module = findModule(where, context)
promise = module.link(linker)
.then(() => module.evaluate())
.then(() => module)
if (module.status === 'unlinked') {
promise = module.link(linker)
.then(() => module.evaluate())
.then(() => module)
} else {
promise = Promise.resolve(module)
}
dynamicImportCache.set(where, promise)
}
return promise
Expand Down

0 comments on commit 0c15c1e

Please sign in to comment.