MCPcopy Create free account
hub / github.com/nodejs/node / bytes

Function bytes

deps/v8/test/mjsunit/wasm/wasm-module-builder.js:15–35  ·  view source on GitHub ↗
(...input)

Source from the content-addressed store, hash-verified

13// - a single string; the returned buffer will contain the char codes of all
14// contained characters.
15function bytes(...input) {
16 if (input.length == 1 && typeof input[0] == 'array') input = input[0];
17 if (input.length == 1 && typeof input[0] == 'string') {
18 let len = input[0].length;
19 let view = new Uint8Array(len);
20 for (let i = 0; i < len; i++) view[i] = input[0].charCodeAt(i);
21 return view.buffer;
22 }
23 let view = new Uint8Array(input.length);
24 for (let i = 0; i < input.length; i++) {
25 let val = input[i];
26 if (typeof val == 'string') {
27 if (val.length != 1) {
28 throw new Error('string inputs must have length 1');
29 }
30 val = val.charCodeAt(0);
31 }
32 view[i] = val | 0;
33 }
34 return view.buffer;
35}
36
37// Header declaration constants
38var kWasmH0 = 0;

Callers 2

errors.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected