Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
use safe version of apply
Browse files Browse the repository at this point in the history
  • Loading branch information
bridiver committed Dec 9, 2016
1 parent f6f98de commit 96b2f08
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions atom/common/api/resources/event_emitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
17 changes: 8 additions & 9 deletions atom/common/api/resources/ipc_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 96b2f08

Please sign in to comment.