diff --git a/lib/browser/rpc-server.js b/lib/browser/rpc-server.js index 083c5e4d03e..2ee14a6659b 100644 --- a/lib/browser/rpc-server.js +++ b/lib/browser/rpc-server.js @@ -2,7 +2,7 @@ const electron = require('electron') const v8Util = process.atomBinding('v8_util') -const {ipcMain, isPromise, webContents} = electron +const {ipcMain, isPromise, isTypedArray, webContents} = electron const objectsRegistry = require('./objects-registry') @@ -63,6 +63,8 @@ let valueToMeta = function (sender, value, optimizeSimpleObject = false) { meta.type = 'buffer' } else if (Array.isArray(value)) { meta.type = 'array' + } else if (isTypedArray(value.buffer)) { + meta.type = 'typed-array' } else if (value instanceof Error) { meta.type = 'error' } else if (value instanceof Date) { @@ -149,6 +151,8 @@ const unwrapArgs = function (sender, args) { return unwrapArgs(sender, meta.value) case 'buffer': return new Buffer(meta.value) + case 'typed-array': + return Buffer.from(meta.value) case 'date': return new Date(meta.value) case 'promise': diff --git a/lib/common/api/is-typed-array.js b/lib/common/api/is-typed-array.js new file mode 100644 index 00000000000..85432debb98 --- /dev/null +++ b/lib/common/api/is-typed-array.js @@ -0,0 +1,16 @@ +'use strict' + +module.exports = function isTypedArray(val) { + return ( + val && + (val instanceof Int8Array + || val instanceof Int16Array + || val instanceof Int32Array + || val instanceof Uint8Array + || val instanceof Uint8ClampedArray + || val instanceof Uint16Array + || val instanceof Uint32Array + || val instanceof Float32Array + || val instanceof Float64Array) + ) +} \ No newline at end of file diff --git a/lib/renderer/api/remote.js b/lib/renderer/api/remote.js index 40f067f3401..30b94e98841 100644 --- a/lib/renderer/api/remote.js +++ b/lib/renderer/api/remote.js @@ -1,7 +1,7 @@ 'use strict' const v8Util = process.atomBinding('v8_util') -const {ipcRenderer, isPromise, CallbacksRegistry} = require('electron') +const {ipcRenderer, isPromise, isTypedArray, CallbacksRegistry} = require('electron') const callbacksRegistry = new CallbacksRegistry() @@ -35,6 +35,11 @@ const wrapArgs = function (args, visited) { type: 'buffer', value: Array.prototype.slice.call(value, 0) } + } else if (isTypedArray(value.buffer)) { + return { + type: 'typed-array', + value: Array.prototype.slice.call(value) + } } else if (value instanceof Date) { return { type: 'date', @@ -164,6 +169,8 @@ const metaToValue = function (meta) { return results case 'buffer': return new Buffer(meta.value) + case 'typed-array': + return Buffer.from(meta.value) case 'promise': return Promise.resolve({ then: metaToValue(meta.then)