Simplify how remote.require('electron') is optimized
This commit is contained in:
parent
9bf0a8647e
commit
099278855c
3 changed files with 3 additions and 18 deletions
|
@ -1,9 +1,6 @@
|
|||
# Import common modules.
|
||||
module.exports = require '../../../../common/api/lib/exports/electron'
|
||||
|
||||
v8Util = process.atomBinding 'v8_util'
|
||||
v8Util.setHiddenValue module.exports, 'electronModule', true
|
||||
|
||||
Object.defineProperties module.exports,
|
||||
# Browser side modules, please sort with alphabet order.
|
||||
app:
|
||||
|
|
|
@ -18,10 +18,6 @@ valueToMeta = (sender, value, optimizeSimpleObject=false) ->
|
|||
meta.type = 'date' if value instanceof Date
|
||||
meta.type = 'promise' if value?.constructor.name is 'Promise'
|
||||
|
||||
# require('electron').
|
||||
if meta.type is 'object' and v8Util.getHiddenValue value, 'electronModule'
|
||||
meta.type = 'electronModule'
|
||||
|
||||
# Treat simple objects as value.
|
||||
if optimizeSimpleObject and meta.type is 'object' and v8Util.getHiddenValue value, 'simple'
|
||||
meta.type = 'value'
|
||||
|
@ -49,8 +45,6 @@ valueToMeta = (sender, value, optimizeSimpleObject=false) ->
|
|||
meta.members = plainObjectToMeta value
|
||||
else if meta.type is 'date'
|
||||
meta.value = value.getTime()
|
||||
else if meta.type is 'electronModule'
|
||||
meta.members = (name for name of value)
|
||||
else
|
||||
meta.type = 'value'
|
||||
meta.value = value
|
||||
|
|
|
@ -49,15 +49,6 @@ metaToValue = (meta) ->
|
|||
when 'date' then new Date(meta.value)
|
||||
when 'exception'
|
||||
throw new Error("#{meta.message}\n#{meta.stack}")
|
||||
when 'electronModule'
|
||||
# require('electron').
|
||||
ret = {}
|
||||
for member in meta.members
|
||||
do (member) ->
|
||||
Object.defineProperty ret, member,
|
||||
enumerable: true
|
||||
get: -> exports.getBuiltin member
|
||||
ret
|
||||
else
|
||||
if meta.type is 'function'
|
||||
# A shadow class to represent the remote function object.
|
||||
|
@ -157,6 +148,9 @@ exports.require = (module) ->
|
|||
meta = ipcRenderer.sendSync 'ATOM_BROWSER_REQUIRE', module
|
||||
moduleCache[module] = metaToValue meta
|
||||
|
||||
# Optimize require('electron').
|
||||
moduleCache.electron = exports
|
||||
|
||||
# Alias to remote.require('electron').xxx.
|
||||
builtinCache = {}
|
||||
exports.getBuiltin = (module) ->
|
||||
|
|
Loading…
Reference in a new issue