Cleanup the CoffeeScript converted code

This commit is contained in:
Cheng Zhao 2016-06-01 15:08:51 +09:00
parent 5bb8da6073
commit eb882855bc

View file

@ -11,12 +11,11 @@ const binding = process.atomBinding('web_contents')
const debuggerBinding = process.atomBinding('debugger')
let nextId = 0
let getNextId = function () {
const getNextId = function () {
return ++nextId
}
let PDFPageSize = {
const PDFPageSize = {
A5: {
custom_display_name: 'A5',
height_microns: 210000,
@ -64,9 +63,9 @@ const webFrameMethods = [
'setZoomLevelLimits'
]
let wrapWebContents = function (webContents) {
// Add JavaScript wrappers for WebContents class.
const wrapWebContents = function (webContents) {
// webContents is an EventEmitter.
var controller, method, name, ref1
Object.setPrototypeOf(webContents, EventEmitter.prototype)
// Every remote callback from renderer process would add a listenter to the
@ -85,21 +84,18 @@ let wrapWebContents = function (webContents) {
webContents.sendToAll = sendWrapper.bind(null, true)
// The navigation controller.
controller = new NavigationController(webContents)
ref1 = NavigationController.prototype
for (name in ref1) {
method = ref1[name]
const controller = new NavigationController(webContents)
for (const name in NavigationController.prototype) {
const method = NavigationController.prototype[name]
if (method instanceof Function) {
(function (name, method) {
webContents[name] = function () {
return method.apply(controller, arguments)
}
})(name, method)
webContents[name] = function () {
return method.apply(controller, arguments)
}
}
}
// Mapping webFrame methods.
for (let method of webFrameMethods) {
for (const method of webFrameMethods) {
webContents[method] = function (...args) {
this.send('ELECTRON_INTERNAL_RENDERER_WEB_FRAME_METHOD', method, args)
}
@ -115,7 +111,7 @@ let wrapWebContents = function (webContents) {
// Make sure webContents.executeJavaScript would run the code only when the
// webContents has been loaded.
webContents.executeJavaScript = function (code, hasUserGesture, callback) {
let requestId = getNextId()
const requestId = getNextId()
if (typeof hasUserGesture === 'function') {
callback = hasUserGesture
hasUserGesture = false
@ -131,18 +127,16 @@ let wrapWebContents = function (webContents) {
// Dispatch IPC messages to the ipc module.
webContents.on('ipc-message', function (event, [channel, ...args]) {
ipcMain.emit.apply(ipcMain, [channel, event].concat(args))
ipcMain.emit(channel, event, ...args)
})
webContents.on('ipc-message-sync', function (event, [channel, ...args]) {
Object.defineProperty(event, 'returnValue', {
set: function (value) {
return event.sendReply(JSON.stringify(value))
},
get: function () {
return undefined
}
get: function () {}
})
return ipcMain.emit.apply(ipcMain, [channel, event].concat(args))
ipcMain.emit(channel, event, ...args)
})
// Handle context menu action request from pepper plugin.
@ -164,8 +158,7 @@ let wrapWebContents = function (webContents) {
})
webContents.printToPDF = function (options, callback) {
var printingSetting
printingSetting = {
const printingSetting = {
pageRage: [],
mediaSize: {},
landscape: false,
@ -229,13 +222,14 @@ let wrapWebContents = function (webContents) {
}
}
// Wrapper for native class.
let wrapDebugger = function (webContentsDebugger) {
binding._setWrapWebContents(wrapWebContents)
// Add JavaScript wrappers for Debugger class.
const wrapDebugger = function (webContentsDebugger) {
// debugger is an EventEmitter.
Object.setPrototypeOf(webContentsDebugger, EventEmitter.prototype)
}
binding._setWrapWebContents(wrapWebContents)
debuggerBinding._setWrapDebugger(wrapDebugger)
module.exports = {