зеркало из https://github.com/electron/electron.git
Simplify how remote.require('electron') is optimized
This commit is contained in:
Родитель
9bf0a8647e
Коммит
099278855c
|
@ -1,9 +1,6 @@
|
||||||
# Import common modules.
|
# Import common modules.
|
||||||
module.exports = require '../../../../common/api/lib/exports/electron'
|
module.exports = require '../../../../common/api/lib/exports/electron'
|
||||||
|
|
||||||
v8Util = process.atomBinding 'v8_util'
|
|
||||||
v8Util.setHiddenValue module.exports, 'electronModule', true
|
|
||||||
|
|
||||||
Object.defineProperties module.exports,
|
Object.defineProperties module.exports,
|
||||||
# Browser side modules, please sort with alphabet order.
|
# Browser side modules, please sort with alphabet order.
|
||||||
app:
|
app:
|
||||||
|
|
|
@ -18,10 +18,6 @@ valueToMeta = (sender, value, optimizeSimpleObject=false) ->
|
||||||
meta.type = 'date' if value instanceof Date
|
meta.type = 'date' if value instanceof Date
|
||||||
meta.type = 'promise' if value?.constructor.name is 'Promise'
|
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.
|
# Treat simple objects as value.
|
||||||
if optimizeSimpleObject and meta.type is 'object' and v8Util.getHiddenValue value, 'simple'
|
if optimizeSimpleObject and meta.type is 'object' and v8Util.getHiddenValue value, 'simple'
|
||||||
meta.type = 'value'
|
meta.type = 'value'
|
||||||
|
@ -49,8 +45,6 @@ valueToMeta = (sender, value, optimizeSimpleObject=false) ->
|
||||||
meta.members = plainObjectToMeta value
|
meta.members = plainObjectToMeta value
|
||||||
else if meta.type is 'date'
|
else if meta.type is 'date'
|
||||||
meta.value = value.getTime()
|
meta.value = value.getTime()
|
||||||
else if meta.type is 'electronModule'
|
|
||||||
meta.members = (name for name of value)
|
|
||||||
else
|
else
|
||||||
meta.type = 'value'
|
meta.type = 'value'
|
||||||
meta.value = value
|
meta.value = value
|
||||||
|
|
|
@ -49,15 +49,6 @@ metaToValue = (meta) ->
|
||||||
when 'date' then new Date(meta.value)
|
when 'date' then new Date(meta.value)
|
||||||
when 'exception'
|
when 'exception'
|
||||||
throw new Error("#{meta.message}\n#{meta.stack}")
|
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
|
else
|
||||||
if meta.type is 'function'
|
if meta.type is 'function'
|
||||||
# A shadow class to represent the remote function object.
|
# A shadow class to represent the remote function object.
|
||||||
|
@ -157,6 +148,9 @@ exports.require = (module) ->
|
||||||
meta = ipcRenderer.sendSync 'ATOM_BROWSER_REQUIRE', module
|
meta = ipcRenderer.sendSync 'ATOM_BROWSER_REQUIRE', module
|
||||||
moduleCache[module] = metaToValue meta
|
moduleCache[module] = metaToValue meta
|
||||||
|
|
||||||
|
# Optimize require('electron').
|
||||||
|
moduleCache.electron = exports
|
||||||
|
|
||||||
# Alias to remote.require('electron').xxx.
|
# Alias to remote.require('electron').xxx.
|
||||||
builtinCache = {}
|
builtinCache = {}
|
||||||
exports.getBuiltin = (module) ->
|
exports.getBuiltin = (module) ->
|
||||||
|
|
Загрузка…
Ссылка в новой задаче