Use rest parameters

This commit is contained in:
Kevin Sawicki 2016-03-18 11:51:02 -07:00
parent e05804848f
commit 8889c29866
14 changed files with 88 additions and 143 deletions

View file

@ -9,8 +9,6 @@ const bindings = process.atomBinding('app');
const downloadItemBindings = process.atomBinding('download_item');
const app = bindings.app;
var slice = [].slice;
app.__proto__ = EventEmitter.prototype;
app.setApplicationMenu = function(menu) {
@ -57,10 +55,8 @@ app.getAppPath = function() {
// Routes the events to webContents.
var ref1 = ['login', 'certificate-error', 'select-client-certificate'];
var fn = function(name) {
return app.on(name, function() {
var args, event, webContents;
event = arguments[0], webContents = arguments[1], args = 3 <= arguments.length ? slice.call(arguments, 2) : [];
return webContents.emit.apply(webContents, [name, event].concat(slice.call(args)));
return app.on(name, function(event, webContents, ...args) {
return webContents.emit.apply(webContents, [name, event].concat(args));
});
};
var i, len;

View file

@ -1,9 +1,10 @@
'use strict';
const app = require('electron').app;
const BrowserWindow = require('electron').BrowserWindow;
const binding = process.atomBinding('dialog');
const v8Util = process.atomBinding('v8_util');
var slice = [].slice;
var includes = [].includes;
var fileDialogProperties = {
@ -41,9 +42,8 @@ var checkAppInitialized = function() {
};
module.exports = {
showOpenDialog: function() {
var args, callback, options, prop, properties, ref1, value, window, wrappedCallback;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
showOpenDialog: function(...args) {
var callback, options, prop, properties, ref1, value, window, wrappedCallback;
checkAppInitialized();
ref1 = parseArgs.apply(null, args), window = ref1[0], options = ref1[1], callback = ref1[2];
if (options == null) {
@ -79,9 +79,9 @@ module.exports = {
} : null;
return binding.showOpenDialog(String(options.title), String(options.defaultPath), options.filters, properties, window, wrappedCallback);
},
showSaveDialog: function() {
var args, callback, options, ref1, window, wrappedCallback;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
showSaveDialog: function(...args) {
var callback, options, ref1, window, wrappedCallback;
checkAppInitialized();
ref1 = parseArgs.apply(null, args), window = ref1[0], options = ref1[1], callback = ref1[2];
if (options == null) {
@ -103,9 +103,9 @@ module.exports = {
} : null;
return binding.showSaveDialog(String(options.title), String(options.defaultPath), options.filters, window, wrappedCallback);
},
showMessageBox: function() {
var args, callback, flags, i, j, len, messageBoxType, options, ref1, ref2, ref3, text, window;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
showMessageBox: function(...args) {
var callback, flags, i, j, len, messageBoxType, options, ref1, ref2, ref3, text, window;
checkAppInitialized();
ref1 = parseArgs.apply(null, args), window = ref1[0], options = ref1[1], callback = ref1[2];
if (options == null) {
@ -154,9 +154,8 @@ module.exports = {
flags = options.noLink ? messageBoxOptions.noLink : 0;
return binding.showMessageBox(messageBoxType, options.buttons, options.defaultId, options.cancelId, flags, options.title, options.message, options.detail, options.icon, window, callback);
},
showErrorBox: function() {
var args;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
showErrorBox: function(...args) {
return binding.showErrorBox.apply(binding, args);
}
};

View file

@ -2,18 +2,14 @@
const ipcMain = require('electron').ipcMain;
var slice = [].slice;
// The history operation in renderer is redirected to browser.
ipcMain.on('ATOM_SHELL_NAVIGATION_CONTROLLER', function() {
var args, event, method, ref;
event = arguments[0], method = arguments[1], args = 3 <= arguments.length ? slice.call(arguments, 2) : [];
ipcMain.on('ATOM_SHELL_NAVIGATION_CONTROLLER', function(event, method, ...args) {
var ref;
return (ref = event.sender)[method].apply(ref, args);
});
ipcMain.on('ATOM_SHELL_SYNC_NAVIGATION_CONTROLLER', function() {
var args, event, method, ref;
event = arguments[0], method = arguments[1], args = 3 <= arguments.length ? slice.call(arguments, 2) : [];
ipcMain.on('ATOM_SHELL_SYNC_NAVIGATION_CONTROLLER', function(event, method, ...args) {
var ref;
return event.returnValue = (ref = event.sender)[method].apply(ref, args);
});

View file

@ -9,7 +9,7 @@ const Menu = require('electron').Menu;
const binding = process.atomBinding('web_contents');
const debuggerBinding = process.atomBinding('debugger');
let slice = [].slice;
let slice = [].slice;
let nextId = 0;
let getNextId = function() {
@ -74,13 +74,11 @@ let wrapWebContents = function(webContents) {
webContents.setMaxListeners(0);
// WebContents::send(channel, args..)
webContents.send = function() {
var args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
var channel = arguments[0];
webContents.send = function(channel, ...args) {
if (channel == null) {
throw new Error('Missing required channel argument');
}
return this._send(channel, slice.call(args));
return this._send(channel, args);
};
// The navigation controller.
@ -99,8 +97,7 @@ let wrapWebContents = function(webContents) {
// Mapping webFrame methods.
for (let method of webFrameMethods) {
webContents[method] = function() {
let args = Array.prototype.slice.call(arguments);
webContents[method] = function(...args) {
this.send('ELECTRON_INTERNAL_RENDERER_WEB_FRAME_METHOD', method, args);
};
}
@ -152,30 +149,26 @@ let wrapWebContents = function(webContents) {
});
// This error occurs when host could not be found.
webContents.on('did-fail-provisional-load', function() {
var args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
webContents.on('did-fail-provisional-load', function(...args) {
// Calling loadURL during this event might cause crash, so delay the event
// until next tick.
setImmediate(() => {
this.emit.apply(this, ['did-fail-load'].concat(slice.call(args)));
this.emit.apply(this, ['did-fail-load'].concat(args));
});
});
// Delays the page-title-updated event to next tick.
webContents.on('-page-title-updated', function() {
var args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
webContents.on('-page-title-updated', function(...args) {
setImmediate(() => {
this.emit.apply(this, ['page-title-updated'].concat(slice.call(args)));
this.emit.apply(this, ['page-title-updated'].concat(args));
});
});
// Deprecated.
deprecate.rename(webContents, 'loadUrl', 'loadURL');
deprecate.rename(webContents, 'getUrl', 'getURL');
deprecate.event(webContents, 'page-title-set', 'page-title-updated', function() {
var args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return this.emit.apply(this, ['page-title-set'].concat(slice.call(args)));
deprecate.event(webContents, 'page-title-set', 'page-title-updated', function(...args) {
return this.emit.apply(this, ['page-title-set'].concat(args));
});
return webContents.printToPDF = function(options, callback) {
var printingSetting;