refactor: check ELECTRON_ENABLE_LOGGING via native implementation (#25623)

This commit is contained in:
Milan Burda 2020-10-06 02:58:31 +02:00 committed by GitHub
parent fec1c0b68b
commit b33f22601e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 1 deletions

View file

@ -0,0 +1,45 @@
// Copyright (c) 2020 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "base/environment.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/node_includes.h"
namespace {
v8::Local<v8::Value> GetVar(v8::Isolate* isolate, const std::string& name) {
std::string value;
if (base::Environment::Create()->GetVar(name, &value)) {
return gin::StringToV8(isolate, value);
} else {
return v8::Null(isolate);
}
}
bool HasVar(const std::string& name) {
return base::Environment::Create()->HasVar(name);
}
bool SetVar(const std::string& name, const std::string& value) {
return base::Environment::Create()->SetVar(name, value);
}
bool UnSetVar(const std::string& name) {
return base::Environment::Create()->UnSetVar(name);
}
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
gin_helper::Dictionary dict(context->GetIsolate(), exports);
dict.SetMethod("getVar", &GetVar);
dict.SetMethod("hasVar", &HasVar);
dict.SetMethod("setVar", &SetVar);
dict.SetMethod("unSetVar", &UnSetVar);
}
} // namespace
NODE_LINKED_MODULE_CONTEXT_AWARE(electron_common_environment, Initialize)