electron/shell/common/gin_converters/file_path_converter.h
Charles Kerr 054cbcd6eb
fix: don't use deprecate-soon class v8::String::Value (#43518)
* fix: remove use of deprecated v8::String::Value

Upstream marked v8::String::Value as `V8_DEPRECATE_SOON` last month,
so let's stop using it.

The replacement code mostly does the same as v8::String::Value();
but since our test only cares about the length and not the contents,
we get a small perf win of not needing to allocate a char array and
not needing to call Local::String::Write().

Upstream V8_DEPRECATE_SOON:
Xref: https://chromium-review.googlesource.com/c/v8/v8/+/5667299kkk

v8::String::Value() implementation:
20226b740b/src/api/api.cc (10883)

History on why we used it:
80c1a9739d
f49ed30f72

* Update shell/common/gin_converters/file_path_converter.h

Co-authored-by: Robo <hop2deep@gmail.com>

* fixup! Update shell/common/gin_converters/file_path_converter.h

do not return success for all non-Null non-Strings

---------

Co-authored-by: Robo <hop2deep@gmail.com>
2024-09-04 08:56:14 -05:00

43 lines
1.2 KiB
C++

// Copyright (c) 2019 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ELECTRON_SHELL_COMMON_GIN_CONVERTERS_FILE_PATH_CONVERTER_H_
#define ELECTRON_SHELL_COMMON_GIN_CONVERTERS_FILE_PATH_CONVERTER_H_
#include "base/files/file_path.h"
#include "gin/converter.h"
#include "shell/common/gin_converters/std_converter.h"
namespace gin {
template <>
struct Converter<base::FilePath> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const base::FilePath& val) {
return Converter<base::FilePath::StringType>::ToV8(isolate, val.value());
}
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
base::FilePath* out) {
if (val->IsNull())
return true;
if (val->IsString() && v8::Local<v8::String>::Cast(val)->Length() == 0) {
*out = {};
return true;
}
base::FilePath::StringType path;
if (Converter<base::FilePath::StringType>::FromV8(isolate, val, &path)) {
*out = base::FilePath(path);
return true;
} else {
return false;
}
}
};
} // namespace gin
#endif // ELECTRON_SHELL_COMMON_GIN_CONVERTERS_FILE_PATH_CONVERTER_H_