Source code
Revision control
Copy as Markdown
Other Tools
// |reftest| shell-option(--enable-arraybuffer-immutable) shell-option(--enable-import-bytes) skip-if(release_or_beta||!ArrayBuffer.prototype.sliceToImmutable||!xulRuntime.shell) module -- import-bytes is not released yet, immutable-arraybuffer is not enabled unconditionally, requires shell-options
// 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, 139);
assert.sameValue(value.buffer.byteLength, 139);
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();
});
reportCompare(0, 0);