feat: add process.uptime() to sandboxed renderers (#26684)
This commit is contained in:
parent
c8c41fb727
commit
14c8e000cb
4 changed files with 9 additions and 0 deletions
|
@ -22,6 +22,7 @@ In sandboxed renderers the `process` object contains only a subset of the APIs:
|
||||||
* `getSystemVersion()`
|
* `getSystemVersion()`
|
||||||
* `getCPUUsage()`
|
* `getCPUUsage()`
|
||||||
* `getIOCounters()`
|
* `getIOCounters()`
|
||||||
|
* `uptime()`
|
||||||
* `argv`
|
* `argv`
|
||||||
* `execPath`
|
* `execPath`
|
||||||
* `env`
|
* `env`
|
||||||
|
|
|
@ -90,6 +90,11 @@ v8::Local<v8::Value> CreatePreloadScript(v8::Isolate* isolate,
|
||||||
preloadSrc);
|
preloadSrc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double Uptime() {
|
||||||
|
return (base::Time::Now() - base::Process::Current().CreationTime())
|
||||||
|
.InSecondsF();
|
||||||
|
}
|
||||||
|
|
||||||
void InvokeHiddenCallback(v8::Handle<v8::Context> context,
|
void InvokeHiddenCallback(v8::Handle<v8::Context> context,
|
||||||
const std::string& hidden_key,
|
const std::string& hidden_key,
|
||||||
const std::string& callback_name) {
|
const std::string& callback_name) {
|
||||||
|
@ -137,6 +142,7 @@ void ElectronSandboxedRendererClient::InitializeBindings(
|
||||||
|
|
||||||
ElectronBindings::BindProcess(isolate, &process, metrics_.get());
|
ElectronBindings::BindProcess(isolate, &process, metrics_.get());
|
||||||
|
|
||||||
|
process.SetMethod("uptime", Uptime);
|
||||||
process.Set("argv", base::CommandLine::ForCurrentProcess()->argv());
|
process.Set("argv", base::CommandLine::ForCurrentProcess()->argv());
|
||||||
process.SetReadOnly("pid", base::GetCurrentProcId());
|
process.SetReadOnly("pid", base::GetCurrentProcId());
|
||||||
process.SetReadOnly("sandboxed", true);
|
process.SetReadOnly("sandboxed", true);
|
||||||
|
|
|
@ -2533,6 +2533,7 @@ describe('BrowserWindow module', () => {
|
||||||
expect(test.systemVersion).to.be.a('string');
|
expect(test.systemVersion).to.be.a('string');
|
||||||
expect(test.cpuUsage).to.be.an('object');
|
expect(test.cpuUsage).to.be.an('object');
|
||||||
expect(test.ioCounters).to.be.an('object');
|
expect(test.ioCounters).to.be.an('object');
|
||||||
|
expect(test.uptime).to.be.a('number');
|
||||||
expect(test.arch).to.equal(process.arch);
|
expect(test.arch).to.equal(process.arch);
|
||||||
expect(test.platform).to.equal(process.platform);
|
expect(test.platform).to.equal(process.platform);
|
||||||
expect(test.env).to.deep.equal(process.env);
|
expect(test.env).to.deep.equal(process.env);
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
systemVersion: invoke(() => process.getSystemVersion()),
|
systemVersion: invoke(() => process.getSystemVersion()),
|
||||||
cpuUsage: invoke(() => process.getCPUUsage()),
|
cpuUsage: invoke(() => process.getCPUUsage()),
|
||||||
ioCounters: invoke(() => process.getIOCounters()),
|
ioCounters: invoke(() => process.getIOCounters()),
|
||||||
|
uptime: invoke(() => process.uptime()),
|
||||||
env: process.env,
|
env: process.env,
|
||||||
execPath: process.execPath,
|
execPath: process.execPath,
|
||||||
pid: process.pid,
|
pid: process.pid,
|
||||||
|
|
Loading…
Add table
Reference in a new issue