Fix overriding async node API
This commit is contained in:
parent
e3ae062c5c
commit
e24976c59f
1 changed files with 24 additions and 5 deletions
|
@ -221,7 +221,7 @@ fs.readdirSync = (p) ->
|
||||||
files
|
files
|
||||||
|
|
||||||
# Override APIs that rely on passing file path instead of content to C++.
|
# Override APIs that rely on passing file path instead of content to C++.
|
||||||
overrideAPI = (module, name, arg = 0) ->
|
overrideAPISync = (module, name, arg = 0) ->
|
||||||
old = module[name]
|
old = module[name]
|
||||||
module[name] = ->
|
module[name] = ->
|
||||||
p = arguments[arg]
|
p = arguments[arg]
|
||||||
|
@ -237,9 +237,28 @@ overrideAPI = (module, name, arg = 0) ->
|
||||||
arguments[arg] = newPath
|
arguments[arg] = newPath
|
||||||
old.apply this, arguments
|
old.apply this, arguments
|
||||||
|
|
||||||
overrideAPI process, 'dlopen', 1
|
overrideAPI = (module, name, arg = 0) ->
|
||||||
overrideAPI require('module')._extensions, '.node', 1
|
old = module[name]
|
||||||
|
module[name] = ->
|
||||||
|
p = arguments[arg]
|
||||||
|
[isAsar, asarPath, filePath] = splitPath p
|
||||||
|
return old.apply this, arguments unless isAsar
|
||||||
|
|
||||||
|
callback = arguments[arguments.length - 1]
|
||||||
|
return overrideAPISync module, name, arg unless typeof callback is 'function'
|
||||||
|
|
||||||
|
archive = getOrCreateArchive asarPath
|
||||||
|
return callback new Error("Invalid package #{asarPath}") unless archive
|
||||||
|
|
||||||
|
newPath = archive.copyFileOut filePath
|
||||||
|
return callback createNotFoundError(asarPath, filePath) unless newPath
|
||||||
|
|
||||||
|
arguments[arg] = newPath
|
||||||
|
old.apply this, arguments
|
||||||
|
|
||||||
overrideAPI fs, 'open'
|
overrideAPI fs, 'open'
|
||||||
overrideAPI fs, 'openSync'
|
|
||||||
overrideAPI child_process, 'fork'
|
|
||||||
overrideAPI child_process, 'execFile'
|
overrideAPI child_process, 'execFile'
|
||||||
|
overrideAPISync process, 'dlopen', 1
|
||||||
|
overrideAPISync require('module')._extensions, '.node', 1
|
||||||
|
overrideAPISync fs, 'openSync'
|
||||||
|
overrideAPISync child_process, 'fork'
|
||||||
|
|
Loading…
Reference in a new issue