Merge pull request #4872 from atom/destructured-assignment

Destructuring assignment
This commit is contained in:
Kevin Sawicki 2016-03-22 13:57:42 -07:00
commit 6041c7edf9
8 changed files with 55 additions and 66 deletions

View file

@ -43,9 +43,9 @@ var checkAppInitialized = function() {
module.exports = { module.exports = {
showOpenDialog: function(...args) { showOpenDialog: function(...args) {
var callback, options, prop, properties, ref1, value, window, wrappedCallback; var prop, properties, value, wrappedCallback;
checkAppInitialized(); checkAppInitialized();
ref1 = parseArgs.apply(null, args), window = ref1[0], options = ref1[1], callback = ref1[2]; let [window, options, callback] = parseArgs.apply(null, args);
if (options == null) { if (options == null) {
options = { options = {
title: 'Open', title: 'Open',
@ -81,9 +81,9 @@ module.exports = {
}, },
showSaveDialog: function(...args) { showSaveDialog: function(...args) {
var callback, options, ref1, window, wrappedCallback; var wrappedCallback;
checkAppInitialized(); checkAppInitialized();
ref1 = parseArgs.apply(null, args), window = ref1[0], options = ref1[1], callback = ref1[2]; let [window, options, callback] = parseArgs.apply(null, args);
if (options == null) { if (options == null) {
options = { options = {
title: 'Save' title: 'Save'
@ -105,9 +105,9 @@ module.exports = {
}, },
showMessageBox: function(...args) { showMessageBox: function(...args) {
var callback, flags, i, j, len, messageBoxType, options, ref1, ref2, ref3, text, window; var flags, i, j, len, messageBoxType, ref2, ref3, text;
checkAppInitialized(); checkAppInitialized();
ref1 = parseArgs.apply(null, args), window = ref1[0], options = ref1[1], callback = ref1[2]; let [window, options, callback] = parseArgs.apply(null, args);
if (options == null) { if (options == null) {
options = { options = {
type: 'none' type: 'none'

View file

@ -51,11 +51,11 @@ var indexOfItemById = function(items, id) {
// Returns the index of where to insert the item according to |position|. // Returns the index of where to insert the item according to |position|.
var indexToInsertByPosition = function(items, position) { var indexToInsertByPosition = function(items, position) {
var id, insertIndex, query, ref1; var insertIndex;
if (!position) { if (!position) {
return items.length; return items.length;
} }
ref1 = position.split('='), query = ref1[0], id = ref1[1]; const [query, id] = position.split('=');
insertIndex = indexOfItemById(items, id); insertIndex = indexOfItemById(items, id);
if (insertIndex === -1 && query !== 'endof') { if (insertIndex === -1 && query !== 'endof') {
console.warn("Item with id '" + id + "' is not found"); console.warn("Item with id '" + id + "' is not found");

View file

@ -9,7 +9,6 @@ const Menu = require('electron').Menu;
const binding = process.atomBinding('web_contents'); const binding = process.atomBinding('web_contents');
const debuggerBinding = process.atomBinding('debugger'); const debuggerBinding = process.atomBinding('debugger');
let slice = [].slice;
let nextId = 0; let nextId = 0;
let getNextId = function() { let getNextId = function() {
@ -125,20 +124,16 @@ let wrapWebContents = function(webContents) {
}; };
// Dispatch IPC messages to the ipc module. // Dispatch IPC messages to the ipc module.
webContents.on('ipc-message', function(event, packed) { webContents.on('ipc-message', function(event, [channel, ...args]) {
var args, channel; return ipcMain.emit.apply(ipcMain, [channel, event].concat(args));
channel = packed[0], args = 2 <= packed.length ? slice.call(packed, 1) : [];
return ipcMain.emit.apply(ipcMain, [channel, event].concat(slice.call(args)));
}); });
webContents.on('ipc-message-sync', function(event, packed) { webContents.on('ipc-message-sync', function(event, [channel, ...args]) {
var args, channel;
channel = packed[0], args = 2 <= packed.length ? slice.call(packed, 1) : [];
Object.defineProperty(event, 'returnValue', { Object.defineProperty(event, 'returnValue', {
set: function(value) { set: function(value) {
return event.sendReply(JSON.stringify(value)); return event.sendReply(JSON.stringify(value));
} }
}); });
return ipcMain.emit.apply(ipcMain, [channel, event].concat(slice.call(args))); return ipcMain.emit.apply(ipcMain, [channel, event].concat(args));
}); });
// Handle context menu action request from pepper plugin. // Handle context menu action request from pepper plugin.

View file

@ -1,3 +1,5 @@
'use strict';
const ipcMain = require('electron').ipcMain; const ipcMain = require('electron').ipcMain;
const desktopCapturer = process.atomBinding('desktop_capturer').desktopCapturer; const desktopCapturer = process.atomBinding('desktop_capturer').desktopCapturer;
@ -33,7 +35,7 @@ ipcMain.on('ATOM_BROWSER_DESKTOP_CAPTURER_GET_SOURCES', function(event, captureW
desktopCapturer.emit = function(event, name, sources) { desktopCapturer.emit = function(event, name, sources) {
// Receiving sources result from main process, now send them back to renderer. // Receiving sources result from main process, now send them back to renderer.
var captureScreen, captureWindow, handledRequest, i, len, ref, ref1, ref2, request, result, source, thumbnailSize, unhandledRequestsQueue; var handledRequest, i, len, ref, ref1, request, result, source, unhandledRequestsQueue;
handledRequest = requestsQueue.shift(0); handledRequest = requestsQueue.shift(0);
result = (function() { result = (function() {
var i, len, results; var i, len, results;
@ -69,7 +71,7 @@ desktopCapturer.emit = function(event, name, sources) {
// If the requestsQueue is not empty, start a new request handling. // If the requestsQueue is not empty, start a new request handling.
if (requestsQueue.length > 0) { if (requestsQueue.length > 0) {
ref2 = requestsQueue[0].options, captureWindow = ref2.captureWindow, captureScreen = ref2.captureScreen, thumbnailSize = ref2.thumbnailSize; const {captureWindow, captureScreen, thumbnailSize} = requestsQueue[0].options;
return desktopCapturer.startHandling(captureWindow, captureScreen, thumbnailSize); return desktopCapturer.startHandling(captureWindow, captureScreen, thumbnailSize);
} }
}; };

View file

@ -3,8 +3,6 @@
const ipcMain = require('electron').ipcMain; const ipcMain = require('electron').ipcMain;
const webContents = require('electron').webContents; const webContents = require('electron').webContents;
var slice = [].slice;
// Doesn't exist in early initialization. // Doesn't exist in early initialization.
var webViewManager = null; var webViewManager = null;
@ -148,10 +146,8 @@ var createGuest = function(embedder, params) {
} }
// Dispatch guest's IPC messages to embedder. // Dispatch guest's IPC messages to embedder.
guest.on('ipc-message-host', function(_, packed) { guest.on('ipc-message-host', function(_, [channel, ...args]) {
var args, channel; return embedder.send.apply(embedder, ["ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-" + guest.viewInstanceId, channel].concat(args));
channel = packed[0], args = 2 <= packed.length ? slice.call(packed, 1) : [];
return embedder.send.apply(embedder, ["ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-" + guest.viewInstanceId, channel].concat(slice.call(args)));
}); });
// Autosize. // Autosize.

View file

@ -82,9 +82,7 @@ var createGuest = function(embedder, url, frameName, options) {
}; };
// Routed window.open messages. // Routed window.open messages.
ipcMain.on('ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', function(event, ...args) { ipcMain.on('ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', function(event, url, frameName, options) {
var frameName, options, url;
url = args[0], frameName = args[1], options = args[2];
options = mergeBrowserWindowOptions(event.sender, options); options = mergeBrowserWindowOptions(event.sender, options);
event.sender.emit('new-window', event, url, frameName, 'new-window', options); event.sender.emit('new-window', event, url, frameName, 'new-window', options);
if ((event.sender.isGuest() && !event.sender.allowPopups) || event.defaultPrevented) { if ((event.sender.isGuest() && !event.sender.allowPopups) || event.defaultPrevented) {

View file

@ -150,9 +150,9 @@
} }
old = module[name]; old = module[name];
return module[name] = function() { return module[name] = function() {
var archive, asarPath, filePath, isAsar, newPath, p, ref; var archive, newPath, p;
p = arguments[arg]; p = arguments[arg];
ref = splitPath(p), isAsar = ref[0], asarPath = ref[1], filePath = ref[2]; const [isAsar, asarPath, filePath] = splitPath(p);
if (!isAsar) { if (!isAsar) {
return old.apply(this, arguments); return old.apply(this, arguments);
} }
@ -176,9 +176,9 @@
} }
old = module[name]; old = module[name];
return module[name] = function() { return module[name] = function() {
var archive, asarPath, callback, filePath, isAsar, newPath, p, ref; var archive, callback, newPath, p;
p = arguments[arg]; p = arguments[arg];
ref = splitPath(p), isAsar = ref[0], asarPath = ref[1], filePath = ref[2]; const [isAsar, asarPath, filePath] = splitPath(p);
if (!isAsar) { if (!isAsar) {
return old.apply(this, arguments); return old.apply(this, arguments);
} }
@ -221,8 +221,8 @@
lstatSync = fs.lstatSync; lstatSync = fs.lstatSync;
fs.lstatSync = function(p) { fs.lstatSync = function(p) {
var archive, asarPath, filePath, isAsar, ref, stats; var archive, stats;
ref = splitPath(p), isAsar = ref[0], asarPath = ref[1], filePath = ref[2]; const [isAsar, asarPath, filePath] = splitPath(p);
if (!isAsar) { if (!isAsar) {
return lstatSync(p); return lstatSync(p);
} }
@ -238,8 +238,8 @@
}; };
lstat = fs.lstat; lstat = fs.lstat;
fs.lstat = function(p, callback) { fs.lstat = function(p, callback) {
var archive, asarPath, filePath, isAsar, ref, stats; var archive, stats;
ref = splitPath(p), isAsar = ref[0], asarPath = ref[1], filePath = ref[2]; const [isAsar, asarPath, filePath] = splitPath(p);
if (!isAsar) { if (!isAsar) {
return lstat(p, callback); return lstat(p, callback);
} }
@ -257,7 +257,7 @@
}; };
statSync = fs.statSync; statSync = fs.statSync;
fs.statSync = function(p) { fs.statSync = function(p) {
var isAsar = splitPath(p)[0]; const [isAsar] = splitPath(p);
if (!isAsar) { if (!isAsar) {
return statSync(p); return statSync(p);
} }
@ -267,7 +267,7 @@
}; };
stat = fs.stat; stat = fs.stat;
fs.stat = function(p, callback) { fs.stat = function(p, callback) {
var isAsar = splitPath(p)[0]; const [isAsar] = splitPath(p);
if (!isAsar) { if (!isAsar) {
return stat(p, callback); return stat(p, callback);
} }
@ -279,8 +279,8 @@
}; };
statSyncNoException = fs.statSyncNoException; statSyncNoException = fs.statSyncNoException;
fs.statSyncNoException = function(p) { fs.statSyncNoException = function(p) {
var archive, asarPath, filePath, isAsar, ref, stats; var archive, stats;
ref = splitPath(p), isAsar = ref[0], asarPath = ref[1], filePath = ref[2]; const [isAsar, asarPath, filePath] = splitPath(p);
if (!isAsar) { if (!isAsar) {
return statSyncNoException(p); return statSyncNoException(p);
} }
@ -296,8 +296,8 @@
}; };
realpathSync = fs.realpathSync; realpathSync = fs.realpathSync;
fs.realpathSync = function(p) { fs.realpathSync = function(p) {
var archive, asarPath, filePath, isAsar, real, ref; var archive, real;
ref = splitPath(p), isAsar = ref[0], asarPath = ref[1], filePath = ref[2]; const [isAsar, asarPath, filePath] = splitPath(p);
if (!isAsar) { if (!isAsar) {
return realpathSync.apply(this, arguments); return realpathSync.apply(this, arguments);
} }
@ -313,8 +313,8 @@
}; };
realpath = fs.realpath; realpath = fs.realpath;
fs.realpath = function(p, cache, callback) { fs.realpath = function(p, cache, callback) {
var archive, asarPath, filePath, isAsar, real, ref; var archive, real;
ref = splitPath(p), isAsar = ref[0], asarPath = ref[1], filePath = ref[2]; const [isAsar, asarPath, filePath] = splitPath(p);
if (!isAsar) { if (!isAsar) {
return realpath.apply(this, arguments); return realpath.apply(this, arguments);
} }
@ -339,8 +339,8 @@
}; };
exists = fs.exists; exists = fs.exists;
fs.exists = function(p, callback) { fs.exists = function(p, callback) {
var archive, asarPath, filePath, isAsar, ref; var archive;
ref = splitPath(p), isAsar = ref[0], asarPath = ref[1], filePath = ref[2]; const [isAsar, asarPath, filePath] = splitPath(p);
if (!isAsar) { if (!isAsar) {
return exists(p, callback); return exists(p, callback);
} }
@ -354,8 +354,8 @@
}; };
existsSync = fs.existsSync; existsSync = fs.existsSync;
fs.existsSync = function(p) { fs.existsSync = function(p) {
var archive, asarPath, filePath, isAsar, ref; var archive;
ref = splitPath(p), isAsar = ref[0], asarPath = ref[1], filePath = ref[2]; const [isAsar, asarPath, filePath] = splitPath(p);
if (!isAsar) { if (!isAsar) {
return existsSync(p); return existsSync(p);
} }
@ -367,8 +367,8 @@
}; };
readFile = fs.readFile; readFile = fs.readFile;
fs.readFile = function(p, options, callback) { fs.readFile = function(p, options, callback) {
var archive, asarPath, buffer, encoding, fd, filePath, info, isAsar, realPath, ref; var archive, buffer, encoding, fd, info, realPath;
ref = splitPath(p), isAsar = ref[0], asarPath = ref[1], filePath = ref[2]; const [isAsar, asarPath, filePath] = splitPath(p);
if (!isAsar) { if (!isAsar) {
return readFile.apply(this, arguments); return readFile.apply(this, arguments);
} }
@ -418,9 +418,9 @@
readFileSync = fs.readFileSync; readFileSync = fs.readFileSync;
fs.readFileSync = function(p, opts) { fs.readFileSync = function(p, opts) {
// this allows v8 to optimize this function // this allows v8 to optimize this function
var archive, asarPath, buffer, encoding, fd, filePath, info, isAsar, options, realPath, ref; var archive, buffer, encoding, fd, info, options, realPath;
options = opts; options = opts;
ref = splitPath(p), isAsar = ref[0], asarPath = ref[1], filePath = ref[2]; const [isAsar, asarPath, filePath] = splitPath(p);
if (!isAsar) { if (!isAsar) {
return readFileSync.apply(this, arguments); return readFileSync.apply(this, arguments);
} }
@ -470,8 +470,8 @@
}; };
readdir = fs.readdir; readdir = fs.readdir;
fs.readdir = function(p, callback) { fs.readdir = function(p, callback) {
var archive, asarPath, filePath, files, isAsar, ref; var archive, files;
ref = splitPath(p), isAsar = ref[0], asarPath = ref[1], filePath = ref[2]; const [isAsar, asarPath, filePath] = splitPath(p);
if (!isAsar) { if (!isAsar) {
return readdir.apply(this, arguments); return readdir.apply(this, arguments);
} }
@ -489,8 +489,8 @@
}; };
readdirSync = fs.readdirSync; readdirSync = fs.readdirSync;
fs.readdirSync = function(p) { fs.readdirSync = function(p) {
var archive, asarPath, filePath, files, isAsar, ref; var archive, files;
ref = splitPath(p), isAsar = ref[0], asarPath = ref[1], filePath = ref[2]; const [isAsar, asarPath, filePath] = splitPath(p);
if (!isAsar) { if (!isAsar) {
return readdirSync.apply(this, arguments); return readdirSync.apply(this, arguments);
} }
@ -506,8 +506,8 @@
}; };
internalModuleReadFile = process.binding('fs').internalModuleReadFile; internalModuleReadFile = process.binding('fs').internalModuleReadFile;
process.binding('fs').internalModuleReadFile = function(p) { process.binding('fs').internalModuleReadFile = function(p) {
var archive, asarPath, buffer, fd, filePath, info, isAsar, realPath, ref; var archive, buffer, fd, info, realPath;
ref = splitPath(p), isAsar = ref[0], asarPath = ref[1], filePath = ref[2]; const [isAsar, asarPath, filePath] = splitPath(p);
if (!isAsar) { if (!isAsar) {
return internalModuleReadFile(p); return internalModuleReadFile(p);
} }
@ -539,8 +539,8 @@
}; };
internalModuleStat = process.binding('fs').internalModuleStat; internalModuleStat = process.binding('fs').internalModuleStat;
process.binding('fs').internalModuleStat = function(p) { process.binding('fs').internalModuleStat = function(p) {
var archive, asarPath, filePath, isAsar, ref, stats; var archive, stats;
ref = splitPath(p), isAsar = ref[0], asarPath = ref[1], filePath = ref[2]; const [isAsar, asarPath, filePath] = splitPath(p);
if (!isAsar) { if (!isAsar) {
return internalModuleStat(p); return internalModuleStat(p);
} }
@ -570,11 +570,10 @@
if (process.platform === 'win32') { if (process.platform === 'win32') {
mkdir = fs.mkdir; mkdir = fs.mkdir;
fs.mkdir = function(p, mode, callback) { fs.mkdir = function(p, mode, callback) {
var filePath, isAsar, ref;
if (typeof mode === 'function') { if (typeof mode === 'function') {
callback = mode; callback = mode;
} }
ref = splitPath(p), isAsar = ref[0], filePath = ref[2]; const [isAsar, , filePath] = splitPath(p);
if (isAsar && filePath.length) { if (isAsar && filePath.length) {
return notDirError(callback); return notDirError(callback);
} }
@ -582,8 +581,7 @@
}; };
mkdirSync = fs.mkdirSync; mkdirSync = fs.mkdirSync;
fs.mkdirSync = function(p, mode) { fs.mkdirSync = function(p, mode) {
var filePath, isAsar, ref; const [isAsar, , filePath] = splitPath(p);
ref = splitPath(p), isAsar = ref[0], filePath = ref[2];
if (isAsar && filePath.length) { if (isAsar && filePath.length) {
notDirError(); notDirError();
} }

View file

@ -216,7 +216,7 @@ let metaToValue = function(meta) {
// Construct a plain object from the meta. // Construct a plain object from the meta.
var metaToPlainObject = function(meta) { var metaToPlainObject = function(meta) {
var i, len, name, obj, ref1, ref2, value; var i, len, obj, ref1;
obj = (function() { obj = (function() {
switch (meta.type) { switch (meta.type) {
case 'error': case 'error':
@ -227,7 +227,7 @@ var metaToPlainObject = function(meta) {
})(); })();
ref1 = meta.members; ref1 = meta.members;
for (i = 0, len = ref1.length; i < len; i++) { for (i = 0, len = ref1.length; i < len; i++) {
ref2 = ref1[i], name = ref2.name, value = ref2.value; let {name, value} = ref1[i];
obj[name] = value; obj[name] = value;
} }
return obj; return obj;