Revert "Merge #18603 from atom/electron-3-0"

This reverts commit b92ae2ad04, reversing
changes made to d4fe5ccfeb.
This commit is contained in:
Jason Rudolph
2019-02-25 13:37:35 -05:00
parent 46fa62ac59
commit c9e6d04e8c
19 changed files with 168 additions and 223 deletions

View File

@@ -1,7 +1,7 @@
const Module = require('module')
const path = require('path')
const cachedVm = require('cached-run-in-this-context')
const crypto = require('crypto')
const vm = require('vm')
function computeHash (contents) {
return crypto.createHash('sha1').update(contents, 'utf8').digest('hex')
@@ -34,24 +34,6 @@ class NativeCompileCache {
this.previousModuleCompile = Module.prototype._compile
}
runInThisContext (code, filename) {
// produceCachedData is deprecated after Node 10.6, will need to update
// this for Electron 4.0 to use script.createCachedData()
const script = new vm.Script(code, {filename, produceCachedData: true})
return {
result: script.runInThisContext(),
cacheBuffer: script.cachedData
}
}
runInThisContextCached (code, filename, cachedData) {
const script = new vm.Script(code, {filename, cachedData})
return {
result: script.runInThisContext(),
wasRejected: script.cachedDataRejected
}
}
overrideModuleCompile () {
let self = this
// Here we override Node's module.js
@@ -82,7 +64,7 @@ class NativeCompileCache {
let compiledWrapper = null
if (self.cacheStore.has(cacheKey)) {
let buffer = self.cacheStore.get(cacheKey)
let compilationResult = self.runInThisContextCached(wrapper, filename, buffer)
let compilationResult = cachedVm.runInThisContextCached(wrapper, filename, buffer)
compiledWrapper = compilationResult.result
if (compilationResult.wasRejected) {
self.cacheStore.delete(cacheKey)
@@ -90,12 +72,12 @@ class NativeCompileCache {
} else {
let compilationResult
try {
compilationResult = self.runInThisContext(wrapper, filename)
compilationResult = cachedVm.runInThisContext(wrapper, filename)
} catch (err) {
console.error(`Error running script ${filename}`)
throw err
}
if (compilationResult.cacheBuffer !== null) {
if (compilationResult.cacheBuffer) {
self.cacheStore.set(cacheKey, compilationResult.cacheBuffer)
}
compiledWrapper = compilationResult.result