Merge pull request #6963 from electron/remote-buffers
Serialize ArrayBuffers as Buffers instead of Arrays over remote
This commit is contained in:
commit
97a004a357
3 changed files with 27 additions and 5 deletions
|
@ -91,7 +91,7 @@ let valueToMeta = function (sender, value, optimizeSimpleObject = false) {
|
|||
meta.members = getObjectMembers(value)
|
||||
meta.proto = getObjectPrototype(value)
|
||||
} else if (meta.type === 'buffer') {
|
||||
meta.value = Array.prototype.slice.call(value, 0)
|
||||
meta.value = Buffer.from(value)
|
||||
} else if (meta.type === 'promise') {
|
||||
// Add default handler to prevent unhandled rejections in main process
|
||||
// Instead they should appear in the renderer process
|
||||
|
|
|
@ -33,7 +33,7 @@ const wrapArgs = function (args, visited) {
|
|||
} else if (ArrayBuffer.isView(value)) {
|
||||
return {
|
||||
type: 'buffer',
|
||||
value: Array.prototype.slice.call(value, 0)
|
||||
value: Buffer.from(value)
|
||||
}
|
||||
} else if (value instanceof Date) {
|
||||
return {
|
||||
|
|
|
@ -163,10 +163,23 @@ describe('ipc module', function () {
|
|||
assert.deepEqual(printName.echo(now), now)
|
||||
})
|
||||
|
||||
it('supports instanceof Buffer', function () {
|
||||
const buffer = Buffer.from('test')
|
||||
assert.ok(buffer.equals(printName.echo(buffer)))
|
||||
|
||||
const objectWithBuffer = {a: 'foo', b: Buffer.from('bar')}
|
||||
assert.ok(objectWithBuffer.b.equals(printName.echo(objectWithBuffer).b))
|
||||
|
||||
const arrayWithBuffer = [1, 2, Buffer.from('baz')]
|
||||
assert.ok(arrayWithBuffer[2].equals(printName.echo(arrayWithBuffer)[2]))
|
||||
})
|
||||
|
||||
it('supports TypedArray', function () {
|
||||
const values = [1, 2, 3, 4]
|
||||
const typedArray = printName.typedArray(values)
|
||||
assert.deepEqual(values, typedArray)
|
||||
assert.deepEqual(printName.typedArray(values), values)
|
||||
|
||||
const int16values = new Int16Array([1, 2, 3, 4])
|
||||
assert.deepEqual(printName.typedArray(int16values), int16values)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -286,7 +299,7 @@ describe('ipc module', function () {
|
|||
ipcRenderer.send('message', obj)
|
||||
})
|
||||
|
||||
it('can send instance of Date', function (done) {
|
||||
it('can send instances of Date', function (done) {
|
||||
const currentDate = new Date()
|
||||
ipcRenderer.once('message', function (event, value) {
|
||||
assert.equal(value, currentDate.toISOString())
|
||||
|
@ -295,6 +308,15 @@ describe('ipc module', function () {
|
|||
ipcRenderer.send('message', currentDate)
|
||||
})
|
||||
|
||||
it('can send instances of Buffer', function (done) {
|
||||
const buffer = Buffer.from('hello')
|
||||
ipcRenderer.once('message', function (event, message) {
|
||||
assert.ok(buffer.equals(message))
|
||||
done()
|
||||
})
|
||||
ipcRenderer.send('message', buffer)
|
||||
})
|
||||
|
||||
it('can send objects with DOM class prototypes', function (done) {
|
||||
ipcRenderer.once('message', function (event, value) {
|
||||
assert.equal(value.protocol, 'file:')
|
||||
|
|
Loading…
Reference in a new issue