From d9c2cdae41f41d879351516eeadd1fb608210242 Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Thu, 15 Nov 2018 10:41:52 -0800 Subject: [PATCH] JS: Switch from `new Buffer` to `Buffer.from` Summary: Constructing `Buffer` using the constructor [[https://nodesource.com/blog/understanding-the-buffer-deprecation-in-node-js-10/ | has been deprecated in Node 10 due to security considerations]]. This is a simple and straightforward conversion. Reviewed By: mjesun Differential Revision: D13080655 fbshipit-source-id: 100d8f28c3b255422b26e820aaadcc4f32f41e0d --- RNTester/js/websocket_test_server.js | 2 +- local-cli/generator/promptSync.js | 4 ++-- local-cli/server/util/copyToClipBoard.js | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/RNTester/js/websocket_test_server.js b/RNTester/js/websocket_test_server.js index fee92917fd37eb..19e3a43167d6ef 100755 --- a/RNTester/js/websocket_test_server.js +++ b/RNTester/js/websocket_test_server.js @@ -35,7 +35,7 @@ server.on('connection', ws => { console.log('Received message:', message); console.log('Cookie:', ws.upgradeReq.headers.cookie); if (respondWithBinary) { - message = new Buffer(message); + message = Buffer.from(message); } if (message === 'getImage') { message = fs.readFileSync(path.resolve(__dirname, 'flux@3x.png')); diff --git a/local-cli/generator/promptSync.js b/local-cli/generator/promptSync.js index c8af74c487a3a7..f8ed5ddbb7aeb1 100644 --- a/local-cli/generator/promptSync.js +++ b/local-cli/generator/promptSync.js @@ -43,7 +43,7 @@ function create() { process.stdin.setRawMode(true); } - var buf = new Buffer(3); + var buf = Buffer.from(3); var str = '', character, read; @@ -62,7 +62,7 @@ function create() { insert = str.length; process.stdout.write('\u001b[2K\u001b[0G' + ask + str); process.stdout.write('\u001b[' + (insert + ask.length + 1) + 'G'); - buf = new Buffer(3); + buf = Buffer.from(3); } continue; // any other 3 character sequence is ignored } diff --git a/local-cli/server/util/copyToClipBoard.js b/local-cli/server/util/copyToClipBoard.js index 1f22477b9b16a3..e6b1bd7a18f4aa 100644 --- a/local-cli/server/util/copyToClipBoard.js +++ b/local-cli/server/util/copyToClipBoard.js @@ -23,15 +23,15 @@ function copyToClipBoard(content) { switch (process.platform) { case 'darwin': var child = spawn('pbcopy', []); - child.stdin.end(new Buffer(content, 'utf8')); + child.stdin.end(Buffer.from(content, 'utf8')); return true; case 'win32': var child = spawn('clip', []); - child.stdin.end(new Buffer(content, 'utf8')); + child.stdin.end(Buffer.from(content, 'utf8')); return true; case 'linux': var child = spawn(xsel, ['--clipboard', '--input']); - child.stdin.end(new Buffer(content, 'utf8')); + child.stdin.end(Buffer.from(content, 'utf8')); return true; default: return false;