1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "gin/object_template_builder.h"
6
7 namespace gin {
8
ObjectTemplateBuilder(v8::Isolate * isolate)9 ObjectTemplateBuilder::ObjectTemplateBuilder(v8::Isolate* isolate)
10 : isolate_(isolate), template_(v8::ObjectTemplate::New(isolate)) {
11 }
12
~ObjectTemplateBuilder()13 ObjectTemplateBuilder::~ObjectTemplateBuilder() {
14 }
15
SetImpl(const base::StringPiece & name,v8::Handle<v8::Data> val)16 ObjectTemplateBuilder& ObjectTemplateBuilder::SetImpl(
17 const base::StringPiece& name, v8::Handle<v8::Data> val) {
18 template_->Set(StringToSymbol(isolate_, name), val);
19 return *this;
20 }
21
SetPropertyImpl(const base::StringPiece & name,v8::Handle<v8::FunctionTemplate> getter,v8::Handle<v8::FunctionTemplate> setter)22 ObjectTemplateBuilder& ObjectTemplateBuilder::SetPropertyImpl(
23 const base::StringPiece& name, v8::Handle<v8::FunctionTemplate> getter,
24 v8::Handle<v8::FunctionTemplate> setter) {
25 template_->SetAccessorProperty(StringToSymbol(isolate_, name), getter,
26 setter);
27 return *this;
28 }
29
Build()30 v8::Local<v8::ObjectTemplate> ObjectTemplateBuilder::Build() {
31 v8::Local<v8::ObjectTemplate> result = template_;
32 template_.Clear();
33 return result;
34 }
35
36 } // namespace gin
37