electron/shell/common/gin_helper/object_template_builder.cc
Cheng Zhao eb0e55c514
chore: remove native_mate (Part 9) (#20645)
* refactor: remove a few uses of native_mate/gfx_converter.h

* refactor: deprecate mate::EventEmitter

* refactor: add gin_helper::EventEmitter

* refactor: convert a few classes to use gin_helper::EventEmitter

* refactor: get rid of native_mate_converters/gfx_converter.h

* fix: follow native_mate on reporting errors

* fix: gin is weak at guessing parameter types

* fix: incorrect full class name

* fix: gin::Handle does not accept null
2019-10-21 16:05:40 +09:00

38 lines
1.1 KiB
C++

// Copyright (c) 2019 GitHub, Inc. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/common/gin_helper/object_template_builder.h"
namespace gin_helper {
ObjectTemplateBuilder::ObjectTemplateBuilder(
v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> templ)
: isolate_(isolate), template_(templ) {}
ObjectTemplateBuilder::~ObjectTemplateBuilder() = default;
ObjectTemplateBuilder& ObjectTemplateBuilder::SetImpl(
const base::StringPiece& name,
v8::Local<v8::Data> val) {
template_->Set(gin::StringToSymbol(isolate_, name), val);
return *this;
}
ObjectTemplateBuilder& ObjectTemplateBuilder::SetPropertyImpl(
const base::StringPiece& name,
v8::Local<v8::FunctionTemplate> getter,
v8::Local<v8::FunctionTemplate> setter) {
template_->SetAccessorProperty(gin::StringToSymbol(isolate_, name), getter,
setter);
return *this;
}
v8::Local<v8::ObjectTemplate> ObjectTemplateBuilder::Build() {
v8::Local<v8::ObjectTemplate> result = template_;
template_.Clear();
return result;
}
} // namespace gin_helper