From 9c4585a9ec41712439e06c731ad8fd028fe6fbea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 25 Jul 2024 16:29:56 +0200 Subject: [PATCH 1/2] Add tool to write multi-module tests in a single file --- tools/misc/explode-bundle.mjs | 85 +++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 tools/misc/explode-bundle.mjs diff --git a/tools/misc/explode-bundle.mjs b/tools/misc/explode-bundle.mjs new file mode 100644 index 00000000000..93e12aa0afa --- /dev/null +++ b/tools/misc/explode-bundle.mjs @@ -0,0 +1,85 @@ +import fs from "node:fs"; +import { resolve, basename, join as joinPaths } from "node:path"; +import { fileURLToPath } from "node:url"; + +async function* walk(dir) { + for await (const d of fs.opendirSync(dir)) { + const entry = joinPaths(dir, d.name); + if (d.isDirectory()) yield* walk(entry); + else if (d.isFile()) yield entry; + } +} + +const testsDir = resolve(fileURLToPath(import.meta.url), "../../../test"); + +for await (const bundleFilename of walk(testsDir)) { + if (/\.multi(?:\.md)$/.test(bundleFilename)) { + const folder = bundleFilename.replace(/\.multi(?:\.md)$/, "__generated"); + + const bundle = fs.readFileSync(bundleFilename, "utf8"); + const allFiles = parse(bundleFilename, bundle); + + const fixtureRE = /_FIXTURE\.\w+$/; + if (allFiles.filter((f) => !fixtureRE.test(f.filename)).length !== 1) { + throw new Error( + `Exactly one file must not end in _FIXTURE (in ${bundleFilename})` + ); + } + + fs.rmSync(folder, { force: true, recursive: true }); + fs.mkdirSync(folder); + for (const { filename, code } of allFiles) { + fs.writeFileSync(joinPaths(folder, filename), code); + } + } +} + +/** + * @param {string} bundleFilename + * @param {string} bundle + */ +function parse(bundleFilename, bundle) { + let index = 0; + + const files = []; + let prefix = null; + + while (true) { + let nextTitle = bundle.indexOf("##", index); + let nextCodeStart = bundle.indexOf("```", index); + let nextCodeEnd = bundle.indexOf("```", nextCodeStart + 3); + if (nextCodeStart === -1 && nextTitle === -1) break; + + if (nextTitle === -1 || nextTitle > nextCodeStart) { + throw new Error( + `Code blocks must be preceded by a filename, with ## (in ${bundleFilename})` + ); + } + if (nextCodeEnd === -1) { + throw new Error(`Unclosed code block (in ${bundleFilename})`); + } + + if (prefix === null) { + prefix = bundle.slice(index, nextTitle).trim(); + if (prefix !== "") prefix = prefix.replaceAll(/^/gm, "// ") + "\n\n"; + prefix = + "// THIS FILE IS AUTOGENERATED. DO NOT EDIT DIRECTLY.\n" + + `// TO MAKE CHANGES, EDIT ../${basename(bundleFilename)}\n\n` + + prefix; + } + const filename = bundle.slice(nextTitle + 2, nextCodeStart).trim(); + const code = + (filename.endsWith(".js") ? prefix : "") + + bundle + .slice(nextCodeStart + 3, nextCodeEnd) + .replace(/^\w+/, "") + .trim() + + "\n"; + + files.push({ filename, code }); + + index = nextCodeEnd + 3; + } + + return files; +} From e5cb468ba93ea7feb8c205a99712bcf2872ea00c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 25 Jul 2024 16:30:32 +0200 Subject: [PATCH 2/2] Example: rewrite import attributes tests --- .../json-extensibility-array.multi.md | 31 +++++++ .../json-value-array_FIXTURE.json | 1 + .../main.js} | 4 + .../json-extensibility-object.multi.md | 31 +++++++ .../json-value-object_FIXTURE.json} | 0 .../main.js} | 4 + .../json-idempotency.multi.md | 40 +++++++++ .../json-idempotency-indirect_FIXTURE.js | 3 + .../json-idempotency_FIXTURE.json | 1 + .../main.js} | 4 + .../import-attributes/json-invalid.multi.md | 36 ++++++++ .../json-invalid_FIXTURE.json | 0 .../main.js} | 4 + .../json-named-bindings.multi.md | 33 +++++++ .../json-named-bindings_FIXTURE.json | 3 - .../json-named-bindings_FIXTURE.json | 3 + .../main.js} | 4 + .../json-value-array.multi.md | 65 ++++++++++++++ .../json-value-array_FIXTURE.json | 6 +- .../main.js} | 4 + .../json-value-boolean.multi.md | 31 +++++++ .../json-value-boolean_FIXTURE.json | 0 .../main.js} | 4 + .../json-value-null.multi.md | 31 +++++++ .../json-value-null_FIXTURE.json | 0 .../main.js} | 4 + .../json-value-number.multi.md | 31 +++++++ .../json-value-number_FIXTURE.json | 0 .../main.js} | 4 + .../json-value-object.multi.md | 85 +++++++++++++++++++ .../json-value-object_FIXTURE.json | 6 +- .../main.js} | 4 + .../json-value-string.multi.md | 31 +++++++ .../json-value-string_FIXTURE.json | 0 .../main.js} | 4 + .../json-via-namespace.multi.md | 24 ++++++ .../json-via-namespace_FIXTURE.json | 0 .../main.js} | 4 + 38 files changed, 529 insertions(+), 11 deletions(-) create mode 100644 test/language/import/import-attributes/json-extensibility-array.multi.md create mode 100644 test/language/import/import-attributes/json-extensibility-array__generated/json-value-array_FIXTURE.json rename test/language/import/import-attributes/{json-extensibility-array.js => json-extensibility-array__generated/main.js} (82%) create mode 100644 test/language/import/import-attributes/json-extensibility-object.multi.md rename test/language/import/import-attributes/{json-idempotency_FIXTURE.json => json-extensibility-object__generated/json-value-object_FIXTURE.json} (100%) rename test/language/import/import-attributes/{json-extensibility-object.js => json-extensibility-object__generated/main.js} (82%) create mode 100644 test/language/import/import-attributes/json-idempotency.multi.md rename test/language/import/import-attributes/{ => json-idempotency__generated}/json-idempotency-indirect_FIXTURE.js (69%) create mode 100644 test/language/import/import-attributes/json-idempotency__generated/json-idempotency_FIXTURE.json rename test/language/import/import-attributes/{json-idempotency.js => json-idempotency__generated/main.js} (89%) create mode 100644 test/language/import/import-attributes/json-invalid.multi.md rename test/language/import/import-attributes/{ => json-invalid__generated}/json-invalid_FIXTURE.json (100%) rename test/language/import/import-attributes/{json-invalid.js => json-invalid__generated/main.js} (86%) create mode 100644 test/language/import/import-attributes/json-named-bindings.multi.md delete mode 100644 test/language/import/import-attributes/json-named-bindings_FIXTURE.json create mode 100644 test/language/import/import-attributes/json-named-bindings__generated/json-named-bindings_FIXTURE.json rename test/language/import/import-attributes/{json-named-bindings.js => json-named-bindings__generated/main.js} (86%) create mode 100644 test/language/import/import-attributes/json-value-array.multi.md rename test/language/import/import-attributes/{ => json-value-array__generated}/json-value-array_FIXTURE.json (84%) rename test/language/import/import-attributes/{json-value-array.js => json-value-array__generated/main.js} (94%) create mode 100644 test/language/import/import-attributes/json-value-boolean.multi.md rename test/language/import/import-attributes/{ => json-value-boolean__generated}/json-value-boolean_FIXTURE.json (100%) rename test/language/import/import-attributes/{json-value-boolean.js => json-value-boolean__generated/main.js} (86%) create mode 100644 test/language/import/import-attributes/json-value-null.multi.md rename test/language/import/import-attributes/{ => json-value-null__generated}/json-value-null_FIXTURE.json (100%) rename test/language/import/import-attributes/{json-value-null.js => json-value-null__generated/main.js} (86%) create mode 100644 test/language/import/import-attributes/json-value-number.multi.md rename test/language/import/import-attributes/{ => json-value-number__generated}/json-value-number_FIXTURE.json (100%) rename test/language/import/import-attributes/{json-value-number.js => json-value-number__generated/main.js} (86%) create mode 100644 test/language/import/import-attributes/json-value-object.multi.md rename test/language/import/import-attributes/{ => json-value-object__generated}/json-value-object_FIXTURE.json (91%) rename test/language/import/import-attributes/{json-value-object.js => json-value-object__generated/main.js} (94%) create mode 100644 test/language/import/import-attributes/json-value-string.multi.md rename test/language/import/import-attributes/{ => json-value-string__generated}/json-value-string_FIXTURE.json (100%) rename test/language/import/import-attributes/{json-value-string.js => json-value-string__generated/main.js} (86%) create mode 100644 test/language/import/import-attributes/json-via-namespace.multi.md rename test/language/import/import-attributes/{ => json-via-namespace__generated}/json-via-namespace_FIXTURE.json (100%) rename test/language/import/import-attributes/{json-via-namespace.js => json-via-namespace__generated/main.js} (80%) diff --git a/test/language/import/import-attributes/json-extensibility-array.multi.md b/test/language/import/import-attributes/json-extensibility-array.multi.md new file mode 100644 index 00000000000..cf6632e8dc5 --- /dev/null +++ b/test/language/import/import-attributes/json-extensibility-array.multi.md @@ -0,0 +1,31 @@ +Copyright (C) 2021 the V8 project authors. All rights reserved. +This code is governed by the BSD license found in the LICENSE file. + +## main.js + +```js +/*--- +esid: sec-parse-json-module +description: Creates extensible arrays +flags: [module] +includes: [propertyHelper.js] +features: [import-attributes, json-modules] +---*/ + +import value from './json-value-array_FIXTURE.json' with { type: 'json' }; + +value.test262property = 'test262 value'; + +verifyProperty(value, 'test262property', { + value: 'test262 value', + writable: true, + enumerable: true, + configurable: true +}); +``` + +## json-value-array_FIXTURE.json + +```json +[] +``` diff --git a/test/language/import/import-attributes/json-extensibility-array__generated/json-value-array_FIXTURE.json b/test/language/import/import-attributes/json-extensibility-array__generated/json-value-array_FIXTURE.json new file mode 100644 index 00000000000..fe51488c706 --- /dev/null +++ b/test/language/import/import-attributes/json-extensibility-array__generated/json-value-array_FIXTURE.json @@ -0,0 +1 @@ +[] diff --git a/test/language/import/import-attributes/json-extensibility-array.js b/test/language/import/import-attributes/json-extensibility-array__generated/main.js similarity index 82% rename from test/language/import/import-attributes/json-extensibility-array.js rename to test/language/import/import-attributes/json-extensibility-array__generated/main.js index 8fb21c6bd6e..bc37d16e017 100644 --- a/test/language/import/import-attributes/json-extensibility-array.js +++ b/test/language/import/import-attributes/json-extensibility-array__generated/main.js @@ -1,5 +1,9 @@ +// THIS FILE IS AUTOGENERATED. DO NOT EDIT DIRECTLY. +// TO MAKE CHANGES, EDIT ../json-extensibility-array.multi.md + // Copyright (C) 2021 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. + /*--- esid: sec-parse-json-module description: Creates extensible arrays diff --git a/test/language/import/import-attributes/json-extensibility-object.multi.md b/test/language/import/import-attributes/json-extensibility-object.multi.md new file mode 100644 index 00000000000..50a13f49c9f --- /dev/null +++ b/test/language/import/import-attributes/json-extensibility-object.multi.md @@ -0,0 +1,31 @@ +Copyright (C) 2021 the V8 project authors. All rights reserved. +This code is governed by the BSD license found in the LICENSE file. + +## main.js + +```js +/*--- +esid: sec-parse-json-module +description: Creates extensible objects +flags: [module] +includes: [propertyHelper.js] +features: [import-attributes, json-modules] +---*/ + +import value from './json-value-object_FIXTURE.json' with { type: 'json' }; + +value.test262property = 'test262 value'; + +verifyProperty(value, 'test262property', { + value: 'test262 value', + writable: true, + enumerable: true, + configurable: true +}); +``` + +## json-value-object_FIXTURE.json + +```json +{} +``` diff --git a/test/language/import/import-attributes/json-idempotency_FIXTURE.json b/test/language/import/import-attributes/json-extensibility-object__generated/json-value-object_FIXTURE.json similarity index 100% rename from test/language/import/import-attributes/json-idempotency_FIXTURE.json rename to test/language/import/import-attributes/json-extensibility-object__generated/json-value-object_FIXTURE.json diff --git a/test/language/import/import-attributes/json-extensibility-object.js b/test/language/import/import-attributes/json-extensibility-object__generated/main.js similarity index 82% rename from test/language/import/import-attributes/json-extensibility-object.js rename to test/language/import/import-attributes/json-extensibility-object__generated/main.js index 3cdeb79bf66..b74bcbfe702 100644 --- a/test/language/import/import-attributes/json-extensibility-object.js +++ b/test/language/import/import-attributes/json-extensibility-object__generated/main.js @@ -1,5 +1,9 @@ +// THIS FILE IS AUTOGENERATED. DO NOT EDIT DIRECTLY. +// TO MAKE CHANGES, EDIT ../json-extensibility-object.multi.md + // Copyright (C) 2021 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. + /*--- esid: sec-parse-json-module description: Creates extensible objects diff --git a/test/language/import/import-attributes/json-idempotency.multi.md b/test/language/import/import-attributes/json-idempotency.multi.md new file mode 100644 index 00000000000..f2ecece0f54 --- /dev/null +++ b/test/language/import/import-attributes/json-idempotency.multi.md @@ -0,0 +1,40 @@ +Copyright (C) 2021 the V8 project authors. All rights reserved. +This code is governed by the BSD license found in the LICENSE file. + +## main.js + +```js +/*--- +esid: sec-parse-json-module +description: The same object representation is returned to all import sites +flags: [module, async] +features: [import-attributes, json-modules, globalThis, dynamic-import] +---*/ + +import viaStaticImport1 from './json-idempotency_FIXTURE.json' with { type: 'json' }; +import {default as viaStaticImport2} from './json-idempotency_FIXTURE.json' with { type: 'json' }; +import './json-idempotency-indirect_FIXTURE.js'; + +assert.sameValue(viaStaticImport1, viaStaticImport2); +assert.sameValue(globalThis.viaSecondModule, viaStaticImport1); + +import('./json-idempotency_FIXTURE.json', { with: { type: 'json' } }) + .then(function(viaDynamicImport) { + assert.sameValue(viaDynamicImport.default, viaStaticImport1); + }) + .then($DONE, $DONE); +``` + +## json-idempotency_FIXTURE.json + +```json +{} +``` + +## json-idempotency-indirect_FIXTURE.js + +```js +import value from './json-idempotency_FIXTURE.json' with { type: 'json' }; + +globalThis.viaSecondModule = value; +``` diff --git a/test/language/import/import-attributes/json-idempotency-indirect_FIXTURE.js b/test/language/import/import-attributes/json-idempotency__generated/json-idempotency-indirect_FIXTURE.js similarity index 69% rename from test/language/import/import-attributes/json-idempotency-indirect_FIXTURE.js rename to test/language/import/import-attributes/json-idempotency__generated/json-idempotency-indirect_FIXTURE.js index 15f28b68b79..7c3e5485ac8 100644 --- a/test/language/import/import-attributes/json-idempotency-indirect_FIXTURE.js +++ b/test/language/import/import-attributes/json-idempotency__generated/json-idempotency-indirect_FIXTURE.js @@ -1,3 +1,6 @@ +// THIS FILE IS AUTOGENERATED. DO NOT EDIT DIRECTLY. +// TO MAKE CHANGES, EDIT ../json-idempotency.multi.md + // Copyright (C) 2021 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. diff --git a/test/language/import/import-attributes/json-idempotency__generated/json-idempotency_FIXTURE.json b/test/language/import/import-attributes/json-idempotency__generated/json-idempotency_FIXTURE.json new file mode 100644 index 00000000000..0967ef424bc --- /dev/null +++ b/test/language/import/import-attributes/json-idempotency__generated/json-idempotency_FIXTURE.json @@ -0,0 +1 @@ +{} diff --git a/test/language/import/import-attributes/json-idempotency.js b/test/language/import/import-attributes/json-idempotency__generated/main.js similarity index 89% rename from test/language/import/import-attributes/json-idempotency.js rename to test/language/import/import-attributes/json-idempotency__generated/main.js index e2c1b8e9d9a..cb327ff1cb8 100644 --- a/test/language/import/import-attributes/json-idempotency.js +++ b/test/language/import/import-attributes/json-idempotency__generated/main.js @@ -1,5 +1,9 @@ +// THIS FILE IS AUTOGENERATED. DO NOT EDIT DIRECTLY. +// TO MAKE CHANGES, EDIT ../json-idempotency.multi.md + // Copyright (C) 2021 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. + /*--- esid: sec-parse-json-module description: The same object representation is returned to all import sites diff --git a/test/language/import/import-attributes/json-invalid.multi.md b/test/language/import/import-attributes/json-invalid.multi.md new file mode 100644 index 00000000000..183c37247eb --- /dev/null +++ b/test/language/import/import-attributes/json-invalid.multi.md @@ -0,0 +1,36 @@ +Copyright (C) 2021 the V8 project authors. All rights reserved. +This code is governed by the BSD license found in the LICENSE file. + +## main.js + +```js +/*--- +esid: sec-parse-json-module +description: Does not define +info: | + # 1.4 ParseJSONModule ( source ) + + The abstract operation ParseJSONModule takes a single argument source which + is a String representing the contents of a module. + + 1. Let json be ? Call(%JSON.parse%, undefined, « source »). + 2. Return CreateDefaultExportSyntheticModule(json). +flags: [module] +features: [import-attributes, json-modules] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +import value from './json-invalid_FIXTURE.json' with { type: 'json' }; +``` + +## json-invalid_FIXTURE.json + +```json +{ + notJson: 0 +} +``` diff --git a/test/language/import/import-attributes/json-invalid_FIXTURE.json b/test/language/import/import-attributes/json-invalid__generated/json-invalid_FIXTURE.json similarity index 100% rename from test/language/import/import-attributes/json-invalid_FIXTURE.json rename to test/language/import/import-attributes/json-invalid__generated/json-invalid_FIXTURE.json diff --git a/test/language/import/import-attributes/json-invalid.js b/test/language/import/import-attributes/json-invalid__generated/main.js similarity index 86% rename from test/language/import/import-attributes/json-invalid.js rename to test/language/import/import-attributes/json-invalid__generated/main.js index 490083940f5..532d8825eb0 100644 --- a/test/language/import/import-attributes/json-invalid.js +++ b/test/language/import/import-attributes/json-invalid__generated/main.js @@ -1,5 +1,9 @@ +// THIS FILE IS AUTOGENERATED. DO NOT EDIT DIRECTLY. +// TO MAKE CHANGES, EDIT ../json-invalid.multi.md + // Copyright (C) 2021 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. + /*--- esid: sec-parse-json-module description: Does not define diff --git a/test/language/import/import-attributes/json-named-bindings.multi.md b/test/language/import/import-attributes/json-named-bindings.multi.md new file mode 100644 index 00000000000..5a6a1220327 --- /dev/null +++ b/test/language/import/import-attributes/json-named-bindings.multi.md @@ -0,0 +1,33 @@ +Copyright (C) 2021 the V8 project authors. All rights reserved. +This code is governed by the BSD license found in the LICENSE file. + +## main.js + +```js +/*--- +esid: sec-parse-json-module +description: Does not define named bindings +info: | + In the early design of JSON modules, contributors considered allowing the + properties of object values in JSON modules to be imported directly by name. + This was ultimately rejected, so attempting to import in this way should + produce a SyntaxError. +flags: [module] +features: [import-attributes, json-modules] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +import {name} from './json-named-bindings_FIXTURE.json' with { type: 'json' }; +``` + +## json-named-bindings_FIXTURE.json + +```json +{ + "name": 0 +} +``` diff --git a/test/language/import/import-attributes/json-named-bindings_FIXTURE.json b/test/language/import/import-attributes/json-named-bindings_FIXTURE.json deleted file mode 100644 index ead2bb7c668..00000000000 --- a/test/language/import/import-attributes/json-named-bindings_FIXTURE.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": 0 -} diff --git a/test/language/import/import-attributes/json-named-bindings__generated/json-named-bindings_FIXTURE.json b/test/language/import/import-attributes/json-named-bindings__generated/json-named-bindings_FIXTURE.json new file mode 100644 index 00000000000..787a303c1b6 --- /dev/null +++ b/test/language/import/import-attributes/json-named-bindings__generated/json-named-bindings_FIXTURE.json @@ -0,0 +1,3 @@ +{ + "name": 0 +} diff --git a/test/language/import/import-attributes/json-named-bindings.js b/test/language/import/import-attributes/json-named-bindings__generated/main.js similarity index 86% rename from test/language/import/import-attributes/json-named-bindings.js rename to test/language/import/import-attributes/json-named-bindings__generated/main.js index 01873fe99ef..0c0b36e0c28 100644 --- a/test/language/import/import-attributes/json-named-bindings.js +++ b/test/language/import/import-attributes/json-named-bindings__generated/main.js @@ -1,5 +1,9 @@ +// THIS FILE IS AUTOGENERATED. DO NOT EDIT DIRECTLY. +// TO MAKE CHANGES, EDIT ../json-named-bindings.multi.md + // Copyright (C) 2021 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. + /*--- esid: sec-parse-json-module description: Does not define named bindings diff --git a/test/language/import/import-attributes/json-value-array.multi.md b/test/language/import/import-attributes/json-value-array.multi.md new file mode 100644 index 00000000000..929df4997e4 --- /dev/null +++ b/test/language/import/import-attributes/json-value-array.multi.md @@ -0,0 +1,65 @@ +Copyright (C) 2021 the V8 project authors. All rights reserved. +This code is governed by the BSD license found in the LICENSE file. + +## main.js + +```js +/*--- +esid: sec-parse-json-module +description: Correctly parses the JSON representation of an array +info: | + # 1.4 ParseJSONModule ( source ) + + The abstract operation ParseJSONModule takes a single argument source which + is a String representing the contents of a module. + + 1. Let json be ? Call(%JSON.parse%, undefined, « source »). + 2. Return CreateDefaultExportSyntheticModule(json). + + To more fully verify parsing correctness, the source text of the imported + module record includes non-printable characters (specifically, all four forms + of JSON's so-called "whitespace" token) both before and after the "value." +flags: [module] +features: [import-attributes, json-modules] +---*/ + +import value from './json-value-array_FIXTURE.json' with { type: 'json' }; + +assert(Array.isArray(value), 'the exported value is an array'); +assert.sameValue( + Object.getPrototypeOf(value), + Array.prototype, + 'the exported value is not a subclass of Array' +); +assert.sameValue(Object.getOwnPropertyNames(value).length, 7); +assert.sameValue(value.length, 6); + +assert.sameValue(value[0], -1.2345); +assert.sameValue(value[1], true); +assert.sameValue(value[2], 'a string value'); +assert.sameValue(value[3], null); + +assert.sameValue(Object.getPrototypeOf(value[4]), Object.prototype); +assert.sameValue(Object.getOwnPropertyNames(value[4]).length, 0); + +assert(Array.isArray(value[5]), 'the fifth element is an array'); +assert.sameValue( + Object.getPrototypeOf(value[5]), + Array.prototype, + 'the fifth element is not a subclass of Array' +); +assert.sameValue(Object.getOwnPropertyNames(value[5]).length, 1); +``` + +## json-value-array_FIXTURE.json + +```json +[ + -1234.500e-003, + true, + "a string value", + null, + {}, + [] +] +``` diff --git a/test/language/import/import-attributes/json-value-array_FIXTURE.json b/test/language/import/import-attributes/json-value-array__generated/json-value-array_FIXTURE.json similarity index 84% rename from test/language/import/import-attributes/json-value-array_FIXTURE.json rename to test/language/import/import-attributes/json-value-array__generated/json-value-array_FIXTURE.json index 9520048793d..4d7b917bd7b 100644 --- a/test/language/import/import-attributes/json-value-array_FIXTURE.json +++ b/test/language/import/import-attributes/json-value-array__generated/json-value-array_FIXTURE.json @@ -1,10 +1,8 @@ - - [ +[ -1234.500e-003, true, "a string value", null, {}, [] -] - +] diff --git a/test/language/import/import-attributes/json-value-array.js b/test/language/import/import-attributes/json-value-array__generated/main.js similarity index 94% rename from test/language/import/import-attributes/json-value-array.js rename to test/language/import/import-attributes/json-value-array__generated/main.js index e819357e66d..1a87f303b9d 100644 --- a/test/language/import/import-attributes/json-value-array.js +++ b/test/language/import/import-attributes/json-value-array__generated/main.js @@ -1,5 +1,9 @@ +// THIS FILE IS AUTOGENERATED. DO NOT EDIT DIRECTLY. +// TO MAKE CHANGES, EDIT ../json-value-array.multi.md + // Copyright (C) 2021 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. + /*--- esid: sec-parse-json-module description: Correctly parses the JSON representation of an array diff --git a/test/language/import/import-attributes/json-value-boolean.multi.md b/test/language/import/import-attributes/json-value-boolean.multi.md new file mode 100644 index 00000000000..4020ee7cb20 --- /dev/null +++ b/test/language/import/import-attributes/json-value-boolean.multi.md @@ -0,0 +1,31 @@ +Copyright (C) 2021 the V8 project authors. All rights reserved. +This code is governed by the BSD license found in the LICENSE file. + +## main.js + +```js +/*--- +esid: sec-parse-json-module +description: Correctly parses the JSON representation of a boolean +info: | + # 1.4 ParseJSONModule ( source ) + + The abstract operation ParseJSONModule takes a single argument source which + is a String representing the contents of a module. + + 1. Let json be ? Call(%JSON.parse%, undefined, « source »). + 2. Return CreateDefaultExportSyntheticModule(json). +flags: [module] +features: [import-attributes, json-modules] +---*/ + +import value from './json-value-boolean_FIXTURE.json' with { type: 'json' }; + +assert.sameValue(value, true); +``` + +## json-value-boolean_FIXTURE.json + +```json +true +``` diff --git a/test/language/import/import-attributes/json-value-boolean_FIXTURE.json b/test/language/import/import-attributes/json-value-boolean__generated/json-value-boolean_FIXTURE.json similarity index 100% rename from test/language/import/import-attributes/json-value-boolean_FIXTURE.json rename to test/language/import/import-attributes/json-value-boolean__generated/json-value-boolean_FIXTURE.json diff --git a/test/language/import/import-attributes/json-value-boolean.js b/test/language/import/import-attributes/json-value-boolean__generated/main.js similarity index 86% rename from test/language/import/import-attributes/json-value-boolean.js rename to test/language/import/import-attributes/json-value-boolean__generated/main.js index 82433ef8dfd..0fc6a28ad5f 100644 --- a/test/language/import/import-attributes/json-value-boolean.js +++ b/test/language/import/import-attributes/json-value-boolean__generated/main.js @@ -1,5 +1,9 @@ +// THIS FILE IS AUTOGENERATED. DO NOT EDIT DIRECTLY. +// TO MAKE CHANGES, EDIT ../json-value-boolean.multi.md + // Copyright (C) 2021 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. + /*--- esid: sec-parse-json-module description: Correctly parses the JSON representation of a boolean diff --git a/test/language/import/import-attributes/json-value-null.multi.md b/test/language/import/import-attributes/json-value-null.multi.md new file mode 100644 index 00000000000..6bf14d78630 --- /dev/null +++ b/test/language/import/import-attributes/json-value-null.multi.md @@ -0,0 +1,31 @@ +Copyright (C) 2021 the V8 project authors. All rights reserved. +This code is governed by the BSD license found in the LICENSE file. + +## main.js + +```js +/*--- +esid: sec-parse-json-module +description: Correctly parses the JSON representation of null +info: | + # 1.4 ParseJSONModule ( source ) + + The abstract operation ParseJSONModule takes a single argument source which + is a String representing the contents of a module. + + 1. Let json be ? Call(%JSON.parse%, undefined, « source »). + 2. Return CreateDefaultExportSyntheticModule(json). +flags: [module] +features: [import-attributes, json-modules] +---*/ + +import value from './json-value-null_FIXTURE.json' with { type: 'json' }; + +assert.sameValue(value, null); +``` + +## json-value-null_FIXTURE.json + +```json +null +``` diff --git a/test/language/import/import-attributes/json-value-null_FIXTURE.json b/test/language/import/import-attributes/json-value-null__generated/json-value-null_FIXTURE.json similarity index 100% rename from test/language/import/import-attributes/json-value-null_FIXTURE.json rename to test/language/import/import-attributes/json-value-null__generated/json-value-null_FIXTURE.json diff --git a/test/language/import/import-attributes/json-value-null.js b/test/language/import/import-attributes/json-value-null__generated/main.js similarity index 86% rename from test/language/import/import-attributes/json-value-null.js rename to test/language/import/import-attributes/json-value-null__generated/main.js index cbc8e435e77..9ce96a25e90 100644 --- a/test/language/import/import-attributes/json-value-null.js +++ b/test/language/import/import-attributes/json-value-null__generated/main.js @@ -1,5 +1,9 @@ +// THIS FILE IS AUTOGENERATED. DO NOT EDIT DIRECTLY. +// TO MAKE CHANGES, EDIT ../json-value-null.multi.md + // Copyright (C) 2021 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. + /*--- esid: sec-parse-json-module description: Correctly parses the JSON representation of null diff --git a/test/language/import/import-attributes/json-value-number.multi.md b/test/language/import/import-attributes/json-value-number.multi.md new file mode 100644 index 00000000000..3780df56b5d --- /dev/null +++ b/test/language/import/import-attributes/json-value-number.multi.md @@ -0,0 +1,31 @@ +Copyright (C) 2021 the V8 project authors. All rights reserved. +This code is governed by the BSD license found in the LICENSE file. + +## main.js + +```js +/*--- +esid: sec-parse-json-module +description: Correctly parses the JSON representation of a number +info: | + # 1.4 ParseJSONModule ( source ) + + The abstract operation ParseJSONModule takes a single argument source which + is a String representing the contents of a module. + + 1. Let json be ? Call(%JSON.parse%, undefined, « source »). + 2. Return CreateDefaultExportSyntheticModule(json). +flags: [module] +features: [import-attributes, json-modules] +---*/ + +import value from './json-value-number_FIXTURE.json' with { type: 'json' }; + +assert.sameValue(value, -1.2345); +``` + +## json-value-number_FIXTURE.json + +```json +-1234.500e-003 +``` diff --git a/test/language/import/import-attributes/json-value-number_FIXTURE.json b/test/language/import/import-attributes/json-value-number__generated/json-value-number_FIXTURE.json similarity index 100% rename from test/language/import/import-attributes/json-value-number_FIXTURE.json rename to test/language/import/import-attributes/json-value-number__generated/json-value-number_FIXTURE.json diff --git a/test/language/import/import-attributes/json-value-number.js b/test/language/import/import-attributes/json-value-number__generated/main.js similarity index 86% rename from test/language/import/import-attributes/json-value-number.js rename to test/language/import/import-attributes/json-value-number__generated/main.js index 0c5a9f322f7..d67ae4f942b 100644 --- a/test/language/import/import-attributes/json-value-number.js +++ b/test/language/import/import-attributes/json-value-number__generated/main.js @@ -1,5 +1,9 @@ +// THIS FILE IS AUTOGENERATED. DO NOT EDIT DIRECTLY. +// TO MAKE CHANGES, EDIT ../json-value-number.multi.md + // Copyright (C) 2021 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. + /*--- esid: sec-parse-json-module description: Correctly parses the JSON representation of a number diff --git a/test/language/import/import-attributes/json-value-object.multi.md b/test/language/import/import-attributes/json-value-object.multi.md new file mode 100644 index 00000000000..02cd3eff831 --- /dev/null +++ b/test/language/import/import-attributes/json-value-object.multi.md @@ -0,0 +1,85 @@ +Copyright (C) 2021 the V8 project authors. All rights reserved. +This code is governed by the BSD license found in the LICENSE file. + +## main.js + +```js +/*--- +esid: sec-parse-json-module +description: Correctly parses the JSON representation of an ordinary object +info: | + # 1.4 ParseJSONModule ( source ) + + The abstract operation ParseJSONModule takes a single argument source which + is a String representing the contents of a module. + + 1. Let json be ? Call(%JSON.parse%, undefined, « source »). + 2. Return CreateDefaultExportSyntheticModule(json). + + To more fully verify parsing correctness, the source text of the imported + module record includes non-printable characters (specifically, all four forms + of JSON's so-called "whitespace" token) both before and after the "value." +flags: [module] +includes: [propertyHelper.js] +features: [import-attributes, json-modules] +---*/ + +import value from './json-value-object_FIXTURE.json' with { type: 'json' }; + +assert.sameValue(Object.getPrototypeOf(value), Object.prototype); +assert.sameValue(Object.getOwnPropertyNames(value).length, 6); + +verifyProperty(value, 'number', { + value: -1.2345, + writable: true, + enumerable: true, + configurable: true +}); + +verifyProperty(value, 'boolean', { + value: true, + writable: true, + enumerable: true, + configurable: true +}); + +verifyProperty(value, 'string', { + value: 'a string value', + writable: true, + enumerable: true, + configurable: true +}); + +verifyProperty(value, 'null', { + value: null, + writable: true, + enumerable: true, + configurable: true +}); + +assert.sameValue(Object.getPrototypeOf(value.object), Object.prototype); +assert.sameValue(Object.getOwnPropertyNames(value.object).length, 0); + +assert( + Array.isArray(value.array), 'the value of the "array" property is an array' +); +assert.sameValue( + Object.getPrototypeOf(value.array), + Array.prototype, + 'the value of the "array" property is not a subclass of Array' +); +assert.sameValue(Object.getOwnPropertyNames(value.array).length, 1); +``` + +## json-value-object_FIXTURE.json + +```json +{ + "number": -1234.500e-003, + "boolean": true, + "string": "a string value", + "null": null, + "object": {}, + "array": [] +} +``` \ No newline at end of file diff --git a/test/language/import/import-attributes/json-value-object_FIXTURE.json b/test/language/import/import-attributes/json-value-object__generated/json-value-object_FIXTURE.json similarity index 91% rename from test/language/import/import-attributes/json-value-object_FIXTURE.json rename to test/language/import/import-attributes/json-value-object__generated/json-value-object_FIXTURE.json index 814ec45e4dd..7d0f7b58b20 100644 --- a/test/language/import/import-attributes/json-value-object_FIXTURE.json +++ b/test/language/import/import-attributes/json-value-object__generated/json-value-object_FIXTURE.json @@ -1,10 +1,8 @@ - - { +{ "number": -1234.500e-003, "boolean": true, "string": "a string value", "null": null, "object": {}, "array": [] -} - +} diff --git a/test/language/import/import-attributes/json-value-object.js b/test/language/import/import-attributes/json-value-object__generated/main.js similarity index 94% rename from test/language/import/import-attributes/json-value-object.js rename to test/language/import/import-attributes/json-value-object__generated/main.js index b8d7a9f0aab..f92202b55bd 100644 --- a/test/language/import/import-attributes/json-value-object.js +++ b/test/language/import/import-attributes/json-value-object__generated/main.js @@ -1,5 +1,9 @@ +// THIS FILE IS AUTOGENERATED. DO NOT EDIT DIRECTLY. +// TO MAKE CHANGES, EDIT ../json-value-object.multi.md + // Copyright (C) 2021 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. + /*--- esid: sec-parse-json-module description: Correctly parses the JSON representation of an ordinary object diff --git a/test/language/import/import-attributes/json-value-string.multi.md b/test/language/import/import-attributes/json-value-string.multi.md new file mode 100644 index 00000000000..6892bd72069 --- /dev/null +++ b/test/language/import/import-attributes/json-value-string.multi.md @@ -0,0 +1,31 @@ +Copyright (C) 2021 the V8 project authors. All rights reserved. +This code is governed by the BSD license found in the LICENSE file. + +## main.js + +```js +/*--- +esid: sec-parse-json-module +description: Correctly parses the JSON representation of a string +info: | + # 1.4 ParseJSONModule ( source ) + + The abstract operation ParseJSONModule takes a single argument source which + is a String representing the contents of a module. + + 1. Let json be ? Call(%JSON.parse%, undefined, « source »). + 2. Return CreateDefaultExportSyntheticModule(json). +flags: [module] +features: [import-attributes, json-modules] +---*/ + +import value from './json-value-string_FIXTURE.json' with { type: 'json' }; + +assert.sameValue(value, 'a string value'); +``` + +## json-value-string_FIXTURE.json + +```json +"a string value" +``` diff --git a/test/language/import/import-attributes/json-value-string_FIXTURE.json b/test/language/import/import-attributes/json-value-string__generated/json-value-string_FIXTURE.json similarity index 100% rename from test/language/import/import-attributes/json-value-string_FIXTURE.json rename to test/language/import/import-attributes/json-value-string__generated/json-value-string_FIXTURE.json diff --git a/test/language/import/import-attributes/json-value-string.js b/test/language/import/import-attributes/json-value-string__generated/main.js similarity index 86% rename from test/language/import/import-attributes/json-value-string.js rename to test/language/import/import-attributes/json-value-string__generated/main.js index 5e5ce171a8d..f6209c4f388 100644 --- a/test/language/import/import-attributes/json-value-string.js +++ b/test/language/import/import-attributes/json-value-string__generated/main.js @@ -1,5 +1,9 @@ +// THIS FILE IS AUTOGENERATED. DO NOT EDIT DIRECTLY. +// TO MAKE CHANGES, EDIT ../json-value-string.multi.md + // Copyright (C) 2021 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. + /*--- esid: sec-parse-json-module description: Correctly parses the JSON representation of a string diff --git a/test/language/import/import-attributes/json-via-namespace.multi.md b/test/language/import/import-attributes/json-via-namespace.multi.md new file mode 100644 index 00000000000..c60e819c062 --- /dev/null +++ b/test/language/import/import-attributes/json-via-namespace.multi.md @@ -0,0 +1,24 @@ +Copyright (C) 2021 the V8 project authors. All rights reserved. +This code is governed by the BSD license found in the LICENSE file. + +## main.js + +```js +/*--- +esid: sec-parse-json-module +description: May be imported via a module namespace object +flags: [module] +features: [import-attributes, json-modules] +---*/ + +import * as ns from './json-via-namespace_FIXTURE.json' with { type: 'json' }; + +assert.sameValue(Object.getOwnPropertyNames(ns).length, 1); +assert.sameValue(ns.default, 262); +``` + +## json-via-namespace_FIXTURE.json + +```json +262 +``` diff --git a/test/language/import/import-attributes/json-via-namespace_FIXTURE.json b/test/language/import/import-attributes/json-via-namespace__generated/json-via-namespace_FIXTURE.json similarity index 100% rename from test/language/import/import-attributes/json-via-namespace_FIXTURE.json rename to test/language/import/import-attributes/json-via-namespace__generated/json-via-namespace_FIXTURE.json diff --git a/test/language/import/import-attributes/json-via-namespace.js b/test/language/import/import-attributes/json-via-namespace__generated/main.js similarity index 80% rename from test/language/import/import-attributes/json-via-namespace.js rename to test/language/import/import-attributes/json-via-namespace__generated/main.js index 0ce54422d2f..08ebd13f8eb 100644 --- a/test/language/import/import-attributes/json-via-namespace.js +++ b/test/language/import/import-attributes/json-via-namespace__generated/main.js @@ -1,5 +1,9 @@ +// THIS FILE IS AUTOGENERATED. DO NOT EDIT DIRECTLY. +// TO MAKE CHANGES, EDIT ../json-via-namespace.multi.md + // Copyright (C) 2021 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. + /*--- esid: sec-parse-json-module description: May be imported via a module namespace object