diff --git a/INTERPRETING.md b/INTERPRETING.md index 5a76859655f..b5cb6de4462 100644 --- a/INTERPRETING.md +++ b/INTERPRETING.md @@ -10,6 +10,8 @@ property of the JSON-formatted `package.json` file will be incremented. In this way, consumers who are transitioning between revisions of Test262 can more easily determine the cause of new test failures. +**Note** Some tests are sensitive to line endings. On Windows, a Git configuration of `core.autocrlf = true` may cause unexpected test failures. It is advised to set `core.autocrlf = false` before cloning this repository. + ## Test Execution Test262 tests are only valid under the runtime environment conditions described diff --git a/features.txt b/features.txt index 065eb259c80..d49512cc0b6 100644 --- a/features.txt +++ b/features.txt @@ -84,6 +84,10 @@ upsert # https://github.com/tc39/proposal-immutable-arraybuffer immutable-arraybuffer +# Import Bytes +# https://github.com/tc39/proposal-import-bytes +import-bytes + # Non-extensible Applies to Private # https://github.com/tc39/proposal-nonextensible-applies-to-private nonextensible-applies-to-private diff --git a/test/language/import/import-bytes/bytes-from-empty.js b/test/language/import/import-bytes/bytes-from-empty.js new file mode 100644 index 00000000000..48705f5f60e --- /dev/null +++ b/test/language/import/import-bytes/bytes-from-empty.js @@ -0,0 +1,28 @@ +// Copyright (C) 2025 @styfle. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-create-bytes-module +description: Creates bytes module from txt file +flags: [module] +features: [import-attributes, immutable-arraybuffer, import-bytes] +includes: [compareArray.js] +---*/ + +import value from './bytes-from-empty_FIXTURE.bin' with { type: 'bytes' }; + +assert(value instanceof Uint8Array); +assert(value.buffer instanceof ArrayBuffer); + +assert.sameValue(value.length, 0); +assert.sameValue(value.buffer.byteLength, 0); +assert.sameValue(value.buffer.immutable, true); + +assert.compareArray(Array.from(value), []); + +assert.throws(TypeError, function() { + value.buffer.resize(0); +}); + +assert.throws(TypeError, function() { + value.buffer.transfer(); +}); diff --git a/test/language/import/import-bytes/bytes-from-empty_FIXTURE.bin b/test/language/import/import-bytes/bytes-from-empty_FIXTURE.bin new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/language/import/import-bytes/bytes-from-js.js b/test/language/import/import-bytes/bytes-from-js.js new file mode 100644 index 00000000000..b3ffe294be9 --- /dev/null +++ b/test/language/import/import-bytes/bytes-from-js.js @@ -0,0 +1,171 @@ +// Copyright (C) 2025 @styfle. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-create-bytes-module +description: Creates bytes module from js file +flags: [module] +features: [import-attributes, immutable-arraybuffer, import-bytes] +includes: [compareArray.js] +---*/ + +import value from './bytes-from-js_FIXTURE.js' with { type: 'bytes' }; + +assert(value instanceof Uint8Array); +assert(value.buffer instanceof ArrayBuffer); + +assert.sameValue(value.length, 16); +assert.sameValue(value.buffer.byteLength, 16); +assert.sameValue(value.buffer.immutable, true); + +assert.compareArray( + Array.from(value), + [ + 47, + 47, + 32, + 67, + 111, + 112, + 121, + 114, + 105, + 103, + 104, + 116, + 32, + 40, + 67, + 41, + 32, + 50, + 48, + 50, + 53, + 32, + 64, + 115, + 116, + 121, + 102, + 108, + 101, + 46, + 32, + 65, + 108, + 108, + 32, + 114, + 105, + 103, + 104, + 116, + 115, + 32, + 114, + 101, + 115, + 101, + 114, + 118, + 101, + 100, + 46, + 10, + 47, + 47, + 32, + 84, + 104, + 105, + 115, + 32, + 99, + 111, + 100, + 101, + 32, + 105, + 115, + 32, + 103, + 111, + 118, + 101, + 114, + 110, + 101, + 100, + 32, + 98, + 121, + 32, + 116, + 104, + 101, + 32, + 66, + 83, + 68, + 32, + 108, + 105, + 99, + 101, + 110, + 115, + 101, + 32, + 102, + 111, + 117, + 110, + 100, + 32, + 105, + 110, + 32, + 116, + 104, + 101, + 32, + 76, + 73, + 67, + 69, + 78, + 83, + 69, + 32, + 102, + 105, + 108, + 101, + 46, + 10, + 118, + 97, + 114, + 32, + 102, + 111, + 111, + 32, + 61, + 32, + 39, + 98, + 97, + 114, + 39, + 10 + ] +); + +assert.throws(TypeError, function() { + value.buffer.resize(0); +}); + +assert.throws(TypeError, function() { + value.buffer.transfer(); +}); diff --git a/test/language/import/import-bytes/bytes-from-js_FIXTURE.js b/test/language/import/import-bytes/bytes-from-js_FIXTURE.js new file mode 100644 index 00000000000..09665a839be --- /dev/null +++ b/test/language/import/import-bytes/bytes-from-js_FIXTURE.js @@ -0,0 +1,3 @@ +// Copyright (C) 2025 @styfle. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +var foo = 'bar' diff --git a/test/language/import/import-bytes/bytes-from-json.js b/test/language/import/import-bytes/bytes-from-json.js new file mode 100644 index 00000000000..cde5595e6e3 --- /dev/null +++ b/test/language/import/import-bytes/bytes-from-json.js @@ -0,0 +1,44 @@ +// Copyright (C) 2025 @styfle. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-create-bytes-module +description: Creates bytes module from json file +flags: [module] +features: [import-attributes, immutable-arraybuffer, import-bytes] +includes: [compareArray.js] +---*/ + +import value from './bytes-from-json_FIXTURE.json' with { type: 'bytes' }; + +assert(value instanceof Uint8Array); +assert(value.buffer instanceof ArrayBuffer); + +assert.sameValue(value.length, 12); +assert.sameValue(value.buffer.byteLength, 12); +assert.sameValue(value.buffer.immutable, true); + +assert.compareArray( + Array.from(value), + [ + 0x7b, // { + 0x20, // (space) + 0x22, // " + 0x61, // a + 0x22, // " + 0x3a, // : + 0x20, // (space) + 0x34, // 4 + 0x32, // 2 + 0x20, // (space) + 0x7d, // } + 0x0a, // (newline) + ] +); + +assert.throws(TypeError, function() { + value.buffer.resize(0); +}); + +assert.throws(TypeError, function() { + value.buffer.transfer(); +}); diff --git a/test/language/import/import-bytes/bytes-from-json_FIXTURE.json b/test/language/import/import-bytes/bytes-from-json_FIXTURE.json new file mode 100644 index 00000000000..5886c6f613f --- /dev/null +++ b/test/language/import/import-bytes/bytes-from-json_FIXTURE.json @@ -0,0 +1 @@ +{ "a": 42 } diff --git a/test/language/import/import-bytes/bytes-from-png.js b/test/language/import/import-bytes/bytes-from-png.js new file mode 100644 index 00000000000..c37764978a9 --- /dev/null +++ b/test/language/import/import-bytes/bytes-from-png.js @@ -0,0 +1,99 @@ +// Copyright (C) 2025 @styfle. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-create-bytes-module +description: Creates bytes module from png file +flags: [module] +features: [import-attributes, immutable-arraybuffer, import-bytes] +includes: [compareArray.js] +---*/ + +import value from './bytes-from-png_FIXTURE.png' with { type: 'bytes' }; + +assert(value instanceof Uint8Array); +assert(value.buffer instanceof ArrayBuffer); + +assert.sameValue(value.length, 67); +assert.sameValue(value.buffer.byteLength, 67); +assert.sameValue(value.buffer.immutable, true); + +assert.compareArray( + Array.from(value), + [ + 0x89, + 0x50, + 0x4e, + 0x47, + 0xd, + 0xa, + 0x1a, + 0xa, + 0x0, + 0x0, + 0x0, + 0xd, + 0x49, + 0x48, + 0x44, + 0x52, + 0x0, + 0x0, + 0x0, + 0x1, + 0x0, + 0x0, + 0x0, + 0x1, + 0x1, + 0x0, + 0x0, + 0x0, + 0x0, + 0x37, + 0x6e, + 0xf9, + 0x24, + 0x0, + 0x0, + 0x0, + 0xa, + 0x49, + 0x44, + 0x41, + 0x54, + 0x78, + 0x1, + 0x63, + 0x60, + 0x0, + 0x0, + 0x0, + 0x2, + 0x0, + 0x1, + 0x73, + 0x75, + 0x1, + 0x18, + 0x0, + 0x0, + 0x0, + 0x0, + 0x49, + 0x45, + 0x4e, + 0x44, + 0xae, + 0x42, + 0x60, + 0x82, + ] +); + +assert.throws(TypeError, function() { + value.buffer.resize(0); +}); + +assert.throws(TypeError, function() { + value.buffer.transfer(); +}); diff --git a/test/language/import/import-bytes/bytes-from-png_FIXTURE.png b/test/language/import/import-bytes/bytes-from-png_FIXTURE.png new file mode 100644 index 00000000000..252d9502d85 Binary files /dev/null and b/test/language/import/import-bytes/bytes-from-png_FIXTURE.png differ diff --git a/test/language/import/import-bytes/bytes-from-txt.js b/test/language/import/import-bytes/bytes-from-txt.js new file mode 100644 index 00000000000..d332e10b065 --- /dev/null +++ b/test/language/import/import-bytes/bytes-from-txt.js @@ -0,0 +1,45 @@ +// Copyright (C) 2025 @styfle. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-create-bytes-module +description: Creates bytes module from txt file +flags: [module] +features: [import-attributes, immutable-arraybuffer, import-bytes] +includes: [compareArray.js] +---*/ + +import value from './bytes-from-txt_FIXTURE.txt' with { type: 'bytes' }; + +assert(value instanceof Uint8Array); +assert(value.buffer instanceof ArrayBuffer); + +assert.sameValue(value.length, 13); +assert.sameValue(value.buffer.byteLength, 13); +assert.sameValue(value.buffer.immutable, true); + +assert.compareArray( + Array.from(value), + [ + 0x48, // H + 0x65, // e + 0x6c, // l + 0x6c, // l + 0x6f, // o + 0x20, // (space) + 0x57, // W + 0x6f, // o + 0x72, // r + 0x6c, // l + 0x64, // d + 0x21, // ! + 0x0a, // (newline) + ] +); + +assert.throws(TypeError, function() { + value.buffer.resize(0); +}); + +assert.throws(TypeError, function() { + value.buffer.transfer(); +}); diff --git a/test/language/import/import-bytes/bytes-from-txt_FIXTURE.txt b/test/language/import/import-bytes/bytes-from-txt_FIXTURE.txt new file mode 100644 index 00000000000..980a0d5f19a --- /dev/null +++ b/test/language/import/import-bytes/bytes-from-txt_FIXTURE.txt @@ -0,0 +1 @@ +Hello World! diff --git a/tools/generation/generator.py b/tools/generation/generator.py index 030a9491ff2..ed6116f886f 100755 --- a/tools/generation/generator.py +++ b/tools/generation/generator.py @@ -40,7 +40,8 @@ def find_cases(location): def clean(args): for (subdir, _, fileNames) in os.walk(args.directory): for fileName in map(lambda x: os.path.join(subdir, x), fileNames): - if os.path.basename(fileName) in ignored_files: + basename = os.path.basename(fileName) + if basename in ignored_files or '_FIXTURE' in basename: continue test = Test(fileName) test.load() diff --git a/tools/generation/test/run.py b/tools/generation/test/run.py index 98af0aba99d..d7259fa4728 100755 --- a/tools/generation/test/run.py +++ b/tools/generation/test/run.py @@ -49,6 +49,39 @@ def compareTrees(self, targetName): def tearDown(self): shutil.rmtree(OUT_DIR, ignore_errors=True) + def test_clean_ignores_binary_fixtures(self): + os.makedirs(OUT_DIR, exist_ok=True) + + png_path = os.path.join(OUT_DIR, 'example_FIXTURE.png') + with open(png_path, 'wb') as handle: + handle.write(b'\x89PNG\r\nSomeMoreBytesHere') + + generated_path = os.path.join(OUT_DIR, 'generated-test.js') + with open(generated_path, 'w', encoding='utf-8') as handle: + handle.write( + '/*---\n' + 'description: generated test\n' + 'flags: [generated]\n' + '---*/\n' + '\n' + '"hello";\n' + ) + + sp = subprocess.Popen( + [ex, 'clean', OUT_DIR], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + stdout, stderr = sp.communicate() + + self.assertEqual( + sp.returncode, + 0, + msg='clean failed\nstdout:\n' + stdout.decode('utf-8', errors='replace') + + '\nstderr:\n' + stderr.decode('utf-8', errors='replace')) + + self.assertTrue(os.path.exists(png_path)) + self.assertFalse(os.path.exists(generated_path)) + def test_glob(self): result = self.fixture('glob.case') self.assertEqual(result['returncode'], 0)