electron/shell/common/api/electron_api_environment.cc
trop[bot] a5ab67c12c
chore: remove unused internal env.unSetVar() (#43176)
chore: remove unused unSetVar JS binding

Added in Oct 2020 (b33f2260, #25623) but never used

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
2024-08-01 21:31:58 -05:00

40 lines
1.1 KiB
C++

// 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);
}
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);
}
} // namespace
NODE_LINKED_BINDING_CONTEXT_AWARE(electron_common_environment, Initialize)