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