From 1350dc46edf2e6ec5444b1b9827e48264f132710 Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Mon, 3 Aug 2020 14:26:27 -0700 Subject: [PATCH] refactor: ginify Archive (#24799) --- shell/common/api/electron_api_asar.cc | 34 +++++++++++++++------------ 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/shell/common/api/electron_api_asar.cc b/shell/common/api/electron_api_asar.cc index 7423dcddc7f4..d449e29db791 100644 --- a/shell/common/api/electron_api_asar.cc +++ b/shell/common/api/electron_api_asar.cc @@ -2,35 +2,36 @@ // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. -#include - #include +#include "gin/handle.h" +#include "gin/object_template_builder.h" +#include "gin/wrappable.h" #include "shell/common/asar/archive.h" #include "shell/common/asar/asar_util.h" #include "shell/common/gin_converters/callback_converter.h" #include "shell/common/gin_converters/file_path_converter.h" #include "shell/common/gin_helper/dictionary.h" -#include "shell/common/gin_helper/object_template_builder.h" -#include "shell/common/gin_helper/wrappable.h" #include "shell/common/node_includes.h" #include "shell/common/node_util.h" + namespace { -class Archive : public gin_helper::Wrappable { +class Archive : public gin::Wrappable { public: - static v8::Local Create(v8::Isolate* isolate, + static gin::Handle Create(v8::Isolate* isolate, const base::FilePath& path) { auto archive = std::make_unique(path); if (!archive->Init()) - return v8::False(isolate); - return (new Archive(isolate, std::move(archive)))->GetWrapper(); + return gin::Handle(); + return gin::CreateHandle(isolate, new Archive(isolate, std::move(archive))); } - static void BuildPrototype(v8::Isolate* isolate, - v8::Local prototype) { - prototype->SetClassName(gin::StringToV8(isolate, "Archive")); - gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) + // gin::Wrappable + static gin::WrapperInfo kWrapperInfo; + gin::ObjectTemplateBuilder GetObjectTemplateBuilder( + v8::Isolate* isolate) override { + return gin::ObjectTemplateBuilder(isolate) .SetProperty("path", &Archive::GetPath) .SetMethod("getFileInfo", &Archive::GetFileInfo) .SetMethod("stat", &Archive::Stat) @@ -40,11 +41,11 @@ class Archive : public gin_helper::Wrappable { .SetMethod("getFd", &Archive::GetFD); } + const char* GetTypeName() override { return "Archive"; } + protected: Archive(v8::Isolate* isolate, std::unique_ptr archive) - : archive_(std::move(archive)) { - Init(isolate); - } + : archive_(std::move(archive)) {} // Returns the path of the file. base::FilePath GetPath() { return archive_->path(); } @@ -116,6 +117,9 @@ class Archive : public gin_helper::Wrappable { DISALLOW_COPY_AND_ASSIGN(Archive); }; +// static +gin::WrapperInfo Archive::kWrapperInfo = {gin::kEmbedderNativeGin}; + void InitAsarSupport(v8::Isolate* isolate, v8::Local require) { // Evaluate asar_bundle.js. std::vector> asar_bundle_params = {