From 96b2f088ae2fc35e9fa3a7232092182e4ea50fa5 Mon Sep 17 00:00:00 2001 From: bridiver Date: Sat, 3 Dec 2016 19:11:33 -0700 Subject: [PATCH] use safe version of apply auditors: @brendaneich @diracdeltas --- atom/common/api/resources/event_emitter.js | 4 ++-- atom/common/api/resources/ipc_utils.js | 17 ++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/atom/common/api/resources/event_emitter.js b/atom/common/api/resources/event_emitter.js index 763d402db..8015b52ad 100644 --- a/atom/common/api/resources/event_emitter.js +++ b/atom/common/api/resources/event_emitter.js @@ -10,7 +10,7 @@ EventEmitter2.prototype.on = function (event, fn) { EventEmitter2.prototype.once = function (event, fn) { function on() { this.off(event, on); - fn.apply(this, arguments); + $Function.apply(fn, this, arguments) } on.fn = fn; @@ -40,7 +40,7 @@ EventEmitter2.prototype.emit = function(event) { if (callbacks) { callbacks = callbacks.slice(0); for (var i = 0, len = callbacks.length; i < len; ++i) { - callbacks[i].apply(this, args); + $Function.apply(callbacks[i], this, args); } } diff --git a/atom/common/api/resources/ipc_utils.js b/atom/common/api/resources/ipc_utils.js index da67ef7ce..4ce073f47 100644 --- a/atom/common/api/resources/ipc_utils.js +++ b/atom/common/api/resources/ipc_utils.js @@ -4,30 +4,29 @@ var ipc = atom.ipc var ipcRenderer = atom.v8.getHiddenValue('ipc') if (!ipcRenderer) { - var slice = [].slice ipcRenderer = new EventEmitter ipcRenderer.send = function () { var args - args = 1 <= arguments.length ? slice.call(arguments, 0) : [] - return ipc.send('ipc-message', slice.call(args)) + args = 1 <= arguments.length ? $Array.slice(arguments, 0) : [] + return ipc.send('ipc-message', $Array.slice(args)) } ipcRenderer.sendSync = function () { var args - args = 1 <= arguments.length ? slice.call(arguments, 0) : [] - return JSON.parse(ipc.sendSync('ipc-message-sync', slice.call(args))) + args = 1 <= arguments.length ? $Array.slice(arguments, 0) : [] + return $JSON.parse(ipc.sendSync('ipc-message-sync', $Array.slice(args))) } ipcRenderer.sendToHost = function () { var args - args = 1 <= arguments.length ? slice.call(arguments, 0) : [] - return ipc.send('ipc-message-host', slice.call(args)) + args = 1 <= arguments.length ? $Array.slice(arguments, 0) : [] + return ipc.send('ipc-message-host', $Array.slice(args)) } ipcRenderer.emit = function () { - arguments[1] && (arguments[1].sender = ipcRenderer) - return EventEmitter.prototype.emit.apply(ipcRenderer, arguments) + arguments[1].sender = ipcRenderer + return $Function.apply(EventEmitter.prototype.emit, ipcRenderer, arguments) } atom.v8.setHiddenValue('ipc', ipcRenderer) }