Skip to content

Buffer.from not support SharedArrayBuffer #8440

@wlunlimited

Description

@wlunlimited

create a buffer from SharedArrayBuffer just like the buff.from sample in doc:

let sab =new SharedArrayBuffer(24);
const arr = new Uint16Array(sab);

arr[0] = 5000;
arr[1] = 4000;

// Shares memory with arr
const buf = Buffer.from(arr.buffer);

// Prints: <Buffer 88 13 a0 0f>
console.log(buf);

// Changing the original Uint16Array changes the Buffer also
arr[1] = 6000;

// Prints: <Buffer 88 13 70 17>
console.log(buf);

  • Version:
  • Platform:
  • Subsystem:

run above code :
node --harmony-sharedarraybuffer ./test.js
and then we would got a error below:

buffer.js:259
throw new TypeError(kFromErrorMsg);
^

TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.
at fromObject (buffer.js:259:9)
at Function.Buffer.from (buffer.js:96:10)
at Object. (/home/Myprojects/node_git/test_buff_sab.js:8:20)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.runMain (module.js:590:10)
at run (bootstrap_node.js:394:7)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions