build: fix the build with enable_run_as_node disabled (#15711)

This commit is contained in:
Alexey Kuzmin 2019-01-11 17:02:06 +01:00 committed by Shelley Vohr
parent ca218b6395
commit 3cb9aadb80
5 changed files with 46 additions and 3 deletions

View file

@ -53,7 +53,7 @@ namespace {
const char kRunAsNode[] = "ELECTRON_RUN_AS_NODE"; const char kRunAsNode[] = "ELECTRON_RUN_AS_NODE";
#endif #endif
bool IsEnvSet(const char* name) { ALLOW_UNUSED_TYPE bool IsEnvSet(const char* name) {
#if defined(OS_WIN) #if defined(OS_WIN)
size_t required_size; size_t required_size;
getenv_s(&required_size, nullptr, 0, name); getenv_s(&required_size, nullptr, 0, name);

View file

@ -23,6 +23,10 @@ bool IsPDFViewerEnabled() {
return BUILDFLAG(ENABLE_PDF_VIEWER); return BUILDFLAG(ENABLE_PDF_VIEWER);
} }
bool IsRunAsNodeEnabled() {
return BUILDFLAG(ENABLE_RUN_AS_NODE);
}
bool IsFakeLocationProviderEnabled() { bool IsFakeLocationProviderEnabled() {
return BUILDFLAG(OVERRIDE_LOCATION_PROVIDER); return BUILDFLAG(OVERRIDE_LOCATION_PROVIDER);
} }
@ -47,6 +51,7 @@ void Initialize(v8::Local<v8::Object> exports,
dict.SetMethod("isDesktopCapturerEnabled", &IsDesktopCapturerEnabled); dict.SetMethod("isDesktopCapturerEnabled", &IsDesktopCapturerEnabled);
dict.SetMethod("isOffscreenRenderingEnabled", &IsOffscreenRenderingEnabled); dict.SetMethod("isOffscreenRenderingEnabled", &IsOffscreenRenderingEnabled);
dict.SetMethod("isPDFViewerEnabled", &IsPDFViewerEnabled); dict.SetMethod("isPDFViewerEnabled", &IsPDFViewerEnabled);
dict.SetMethod("isRunAsNodeEnabled", &IsRunAsNodeEnabled);
dict.SetMethod("isFakeLocationProviderEnabled", dict.SetMethod("isFakeLocationProviderEnabled",
&IsFakeLocationProviderEnabled); &IsFakeLocationProviderEnabled);
dict.SetMethod("isViewApiEnabled", &IsViewApiEnabled); dict.SetMethod("isViewApiEnabled", &IsViewApiEnabled);

View file

@ -12,6 +12,8 @@ const remote = require('electron').remote
const { ipcMain, BrowserWindow } = remote const { ipcMain, BrowserWindow } = remote
const features = process.atomBinding('features')
describe('asar package', function () { describe('asar package', function () {
const fixtures = path.join(__dirname, 'fixtures') const fixtures = path.join(__dirname, 'fixtures')
@ -844,6 +846,12 @@ describe('asar package', function () {
}) })
describe('child_process.fork', function () { describe('child_process.fork', function () {
before(function () {
if (!features.isRunAsNodeEnabled()) {
this.skip()
}
})
it('opens a normal js file', function (done) { it('opens a normal js file', function (done) {
const child = ChildProcess.fork(path.join(fixtures, 'asar', 'a.asar', 'ping.js')) const child = ChildProcess.fork(path.join(fixtures, 'asar', 'a.asar', 'ping.js'))
child.on('message', function (msg) { child.on('message', function (msg) {
@ -1040,6 +1048,12 @@ describe('asar package', function () {
}) })
describe('process.env.ELECTRON_NO_ASAR', function () { describe('process.env.ELECTRON_NO_ASAR', function () {
before(function () {
if (!features.isRunAsNodeEnabled()) {
this.skip()
}
})
it('disables asar support in forked processes', function (done) { it('disables asar support in forked processes', function (done) {
const forked = ChildProcess.fork(path.join(__dirname, 'fixtures', 'module', 'no-asar.js'), [], { const forked = ChildProcess.fork(path.join(__dirname, 'fixtures', 'module', 'no-asar.js'), [], {
env: { env: {
@ -1205,6 +1219,11 @@ describe('asar package', function () {
}) })
it('is available in forked scripts', function (done) { it('is available in forked scripts', function (done) {
if (!features.isRunAsNodeEnabled()) {
this.skip()
done()
}
const child = ChildProcess.fork(path.join(fixtures, 'module', 'original-fs.js')) const child = ChildProcess.fork(path.join(fixtures, 'module', 'original-fs.js'))
child.on('message', function (msg) { child.on('message', function (msg) {
assert.strictEqual(msg, 'object') assert.strictEqual(msg, 'object')

View file

@ -5,6 +5,7 @@ const fs = require('fs')
const { remote } = require('electron') const { remote } = require('electron')
const { BrowserWindow } = remote const { BrowserWindow } = remote
const { closeWindow } = require('./window-helpers') const { closeWindow } = require('./window-helpers')
const features = process.atomBinding('features')
const nativeModulesEnabled = remote.getGlobal('nativeModulesEnabled') const nativeModulesEnabled = remote.getGlobal('nativeModulesEnabled')
@ -17,7 +18,12 @@ describe('modules support', () => {
require('runas') require('runas')
}) })
it('can be required in node binary', (done) => { it('can be required in node binary', function (done) {
if (!features.isRunAsNodeEnabled()) {
this.skip()
done()
}
const runas = path.join(fixtures, 'module', 'runas.js') const runas = path.join(fixtures, 'module', 'runas.js')
const child = require('child_process').fork(runas) const child = require('child_process').fork(runas)
child.on('message', (msg) => { child.on('message', (msg) => {

View file

@ -6,6 +6,7 @@ const fs = require('fs')
const path = require('path') const path = require('path')
const os = require('os') const os = require('os')
const { ipcRenderer, remote } = require('electron') const { ipcRenderer, remote } = require('electron')
const features = process.atomBinding('features')
const isCI = remote.getGlobal('isCi') const isCI = remote.getGlobal('isCi')
chai.use(dirtyChai) chai.use(dirtyChai)
@ -14,6 +15,12 @@ describe('node feature', () => {
const fixtures = path.join(__dirname, 'fixtures') const fixtures = path.join(__dirname, 'fixtures')
describe('child_process', () => { describe('child_process', () => {
beforeEach(function () {
if (!features.isRunAsNodeEnabled()) {
this.skip()
}
})
describe('child_process.fork', () => { describe('child_process.fork', () => {
it('works in current process', (done) => { it('works in current process', (done) => {
const child = ChildProcess.fork(path.join(fixtures, 'module', 'ping.js')) const child = ChildProcess.fork(path.join(fixtures, 'module', 'ping.js'))
@ -208,6 +215,12 @@ describe('node feature', () => {
describe('inspector', () => { describe('inspector', () => {
let child = null let child = null
beforeEach(function () {
if (!features.isRunAsNodeEnabled()) {
this.skip()
}
})
afterEach(() => { afterEach(() => {
if (child !== null) child.kill() if (child !== null) child.kill()
}) })
@ -299,7 +312,7 @@ describe('node feature', () => {
describe('net.connect', () => { describe('net.connect', () => {
before(function () { before(function () {
if (process.platform !== 'darwin') { if (!features.isRunAsNodeEnabled() || process.platform !== 'darwin') {
this.skip() this.skip()
} }
}) })