2014-04-15 03:04:36 +00:00
|
|
|
// Copyright 2013 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE.chromium file.
|
|
|
|
|
|
|
|
#include "native_mate/object_template_builder.h"
|
|
|
|
|
|
|
|
namespace mate {
|
|
|
|
|
2014-04-15 03:34:07 +00:00
|
|
|
ObjectTemplateBuilder::ObjectTemplateBuilder(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::ObjectTemplate> templ)
|
|
|
|
: isolate_(isolate), template_(templ) {
|
2014-04-15 03:04:36 +00:00
|
|
|
template_->SetInternalFieldCount(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectTemplateBuilder::~ObjectTemplateBuilder() {
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectTemplateBuilder& ObjectTemplateBuilder::SetImpl(
|
2015-05-22 11:11:02 +00:00
|
|
|
const base::StringPiece& name, v8::Local<v8::Data> val) {
|
2014-04-15 03:04:36 +00:00
|
|
|
template_->Set(StringToSymbol(isolate_, name), val);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectTemplateBuilder& ObjectTemplateBuilder::SetPropertyImpl(
|
2015-05-22 11:11:02 +00:00
|
|
|
const base::StringPiece& name, v8::Local<v8::FunctionTemplate> getter,
|
|
|
|
v8::Local<v8::FunctionTemplate> setter) {
|
2014-04-15 03:04:36 +00:00
|
|
|
#if NODE_VERSION_AT_LEAST(0, 11, 0)
|
|
|
|
template_->SetAccessorProperty(StringToSymbol(isolate_, name), getter,
|
|
|
|
setter);
|
|
|
|
#endif
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::ObjectTemplate> ObjectTemplateBuilder::Build() {
|
|
|
|
v8::Local<v8::ObjectTemplate> result = template_;
|
|
|
|
template_.Clear();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mate
|