Π·Π΅ΡΠΊΠ°Π»ΠΎ ΠΈΠ· https://github.com/Unity-Technologies/electron.git
π§ Spec: Donβt use deprecated `new Buffer()`
This commit is contained in:
Π ΠΎΠ΄ΠΈΡΠ΅Π»Ρ
f7d6e3fa7b
ΠΠΎΠΌΠΌΠΈΡ
0278e380de
|
@ -27,7 +27,7 @@ describe('BrowserWindow module', () => {
|
|||
postData = [
|
||||
{
|
||||
type: 'rawData',
|
||||
bytes: new Buffer('username=test&file=')
|
||||
bytes: Buffer.from('username=test&file=')
|
||||
},
|
||||
{
|
||||
type: 'file',
|
||||
|
@ -270,7 +270,7 @@ describe('BrowserWindow module', () => {
|
|||
assert.equal(isMainFrame, true)
|
||||
done()
|
||||
})
|
||||
const data = new Buffer(2 * 1024 * 1024).toString('base64')
|
||||
const data = Buffer.alloc(2 * 1024 * 1024).toString('base64')
|
||||
w.loadURL(`data:image/png;base64,${data}`)
|
||||
})
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ describe('ipc module', () => {
|
|||
|
||||
describe('remote.createFunctionWithReturnValue', () => {
|
||||
it('should be called in browser synchronously', () => {
|
||||
const buf = new Buffer('test')
|
||||
const buf = Buffer.from('test')
|
||||
const call = remote.require(path.join(fixtures, 'module', 'call.js'))
|
||||
const result = call.call(remote.createFunctionWithReturnValue(buf))
|
||||
assert.equal(result.constructor.name, 'Buffer')
|
||||
|
@ -239,7 +239,7 @@ describe('ipc module', () => {
|
|||
const printName = remote.require(print)
|
||||
|
||||
it('keeps its constructor name for objects', () => {
|
||||
const buf = new Buffer('test')
|
||||
const buf = Buffer.from('test')
|
||||
assert.equal(printName.print(buf), 'Buffer')
|
||||
})
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ describe('protocol module', () => {
|
|||
const body = stream.PassThrough()
|
||||
|
||||
async function sendChunks () {
|
||||
let buf = new Buffer(data)
|
||||
let buf = Buffer.from(data)
|
||||
for (;;) {
|
||||
body.push(buf.slice(0, chunkSize))
|
||||
buf = buf.slice(chunkSize)
|
||||
|
@ -204,7 +204,7 @@ describe('protocol module', () => {
|
|||
})
|
||||
|
||||
describe('protocol.registerBufferProtocol', () => {
|
||||
const buffer = new Buffer(text)
|
||||
const buffer = Buffer.from(text)
|
||||
it('sends Buffer as response', (done) => {
|
||||
const handler = (request, callback) => callback(buffer)
|
||||
protocol.registerBufferProtocol(protocolName, handler, (error) => {
|
||||
|
@ -767,7 +767,7 @@ describe('protocol module', () => {
|
|||
|
||||
describe('protocol.interceptBufferProtocol', () => {
|
||||
it('can intercept http protocol', (done) => {
|
||||
const handler = (request, callback) => callback(new Buffer(text))
|
||||
const handler = (request, callback) => callback(Buffer.from(text))
|
||||
protocol.interceptBufferProtocol('http', handler, (error) => {
|
||||
if (error) return done(error)
|
||||
$.ajax({
|
||||
|
|
|
@ -242,7 +242,7 @@ describe('session module', () => {
|
|||
})
|
||||
|
||||
it('can cancel default download behavior', (done) => {
|
||||
const mockFile = new Buffer(1024)
|
||||
const mockFile = Buffer.alloc(1024)
|
||||
const contentDisposition = 'inline; filename="mockFile.txt"'
|
||||
const downloadServer = http.createServer((req, res) => {
|
||||
res.writeHead(200, {
|
||||
|
@ -271,7 +271,7 @@ describe('session module', () => {
|
|||
})
|
||||
|
||||
describe('DownloadItem', () => {
|
||||
const mockPDF = new Buffer(1024 * 1024 * 5)
|
||||
const mockPDF = Buffer.alloc(1024 * 1024 * 5)
|
||||
let contentDisposition = 'inline; filename="mock.pdf"'
|
||||
const downloadFilePath = path.join(fixtures, 'mock.pdf')
|
||||
const downloadServer = http.createServer((req, res) => {
|
||||
|
|
|
@ -15,7 +15,7 @@ describe('asar package', function () {
|
|||
|
||||
describe('node api', function () {
|
||||
it('supports paths specified as a Buffer', function () {
|
||||
var file = new Buffer(path.join(fixtures, 'asar', 'a.asar', 'file1'))
|
||||
var file = Buffer.from(path.join(fixtures, 'asar', 'a.asar', 'file1'))
|
||||
assert.equal(fs.existsSync(file), true)
|
||||
})
|
||||
|
||||
|
@ -491,7 +491,7 @@ describe('asar package', function () {
|
|||
file = ref2[j]
|
||||
p = path.join(fixtures, 'asar', 'a.asar', file)
|
||||
fd = fs.openSync(p, 'r')
|
||||
buffer = new Buffer(6)
|
||||
buffer = Buffer.alloc(6)
|
||||
fs.readSync(fd, buffer, 0, 6, 0)
|
||||
assert.equal(String(buffer).trim(), 'file1')
|
||||
fs.closeSync(fd)
|
||||
|
@ -512,7 +512,7 @@ describe('asar package', function () {
|
|||
var p = path.join(fixtures, 'asar', 'a.asar', 'file1')
|
||||
fs.open(p, 'r', function (err, fd) {
|
||||
assert.equal(err, null)
|
||||
var buffer = new Buffer(6)
|
||||
var buffer = Buffer.alloc(6)
|
||||
fs.read(fd, buffer, 0, 6, 0, function (err) {
|
||||
assert.equal(err, null)
|
||||
assert.equal(String(buffer).trim(), 'file1')
|
||||
|
|
|
@ -274,7 +274,7 @@ describe('node feature', () => {
|
|||
it('can be created from WebKit external string', () => {
|
||||
const p = document.createElement('p')
|
||||
p.innerText = 'ι²δΊζ½ε½±ζ₯ζ ζ οΌη©ζ’ζ移ε εΊ¦η§'
|
||||
const b = new Buffer(p.innerText)
|
||||
const b = Buffer.from(p.innerText)
|
||||
assert.equal(b.toString(), 'ι²δΊζ½ε½±ζ₯ζ ζ οΌη©ζ’ζ移ε εΊ¦η§')
|
||||
assert.equal(Buffer.byteLength(p.innerText), 45)
|
||||
})
|
||||
|
@ -282,15 +282,15 @@ describe('node feature', () => {
|
|||
it('correctly parses external one-byte UTF8 string', () => {
|
||||
const p = document.createElement('p')
|
||||
p.innerText = 'JΓΈhΓ€nΓ±Γ©Γ'
|
||||
const b = new Buffer(p.innerText)
|
||||
const b = Buffer.from(p.innerText)
|
||||
assert.equal(b.toString(), 'JΓΈhΓ€nΓ±Γ©Γ')
|
||||
assert.equal(Buffer.byteLength(p.innerText), 13)
|
||||
})
|
||||
|
||||
it('does not crash when creating large Buffers', () => {
|
||||
let buffer = new Buffer(new Array(4096).join(' '))
|
||||
let buffer = Buffer.from(new Array(4096).join(' '))
|
||||
assert.equal(buffer.length, 4095)
|
||||
buffer = new Buffer(new Array(4097).join(' '))
|
||||
buffer = Buffer.from(new Array(4097).join(' '))
|
||||
assert.equal(buffer.length, 4096)
|
||||
})
|
||||
})
|
||||
|
|
ΠΠ°Π³ΡΡΠ·ΠΊΠ°β¦
Π‘ΡΡΠ»ΠΊΠ° Π² Π½ΠΎΠ²ΠΎΠΉ Π·Π°Π΄Π°ΡΠ΅