[email protected] | b520e13 | 2013-11-29 03:21:48 | [diff] [blame] | 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" |
[email protected] | cb6c2bb | 2013-12-17 21:47:04 | [diff] [blame^] | 6 | #include "gin/public/wrapper_info.h" |
[email protected] | b520e13 | 2013-11-29 03:21:48 | [diff] [blame] | 7 | |
| 8 | namespace gin { |
| 9 | |
| 10 | ObjectTemplateBuilder::ObjectTemplateBuilder(v8::Isolate* isolate) |
| 11 | : isolate_(isolate), template_(v8::ObjectTemplate::New(isolate)) { |
[email protected] | cb6c2bb | 2013-12-17 21:47:04 | [diff] [blame^] | 12 | template_->SetInternalFieldCount(kNumberOfInternalFields); |
[email protected] | b520e13 | 2013-11-29 03:21:48 | [diff] [blame] | 13 | } |
| 14 | |
| 15 | ObjectTemplateBuilder::~ObjectTemplateBuilder() { |
| 16 | } |
| 17 | |
| 18 | ObjectTemplateBuilder& ObjectTemplateBuilder::SetImpl( |
| 19 | const base::StringPiece& name, v8::Handle<v8::Data> val) { |
| 20 | template_->Set(StringToSymbol(isolate_, name), val); |
| 21 | return *this; |
| 22 | } |
| 23 | |
[email protected] | bf3dd3c | 2013-12-06 06:55:25 | [diff] [blame] | 24 | ObjectTemplateBuilder& ObjectTemplateBuilder::SetPropertyImpl( |
| 25 | const base::StringPiece& name, v8::Handle<v8::FunctionTemplate> getter, |
| 26 | v8::Handle<v8::FunctionTemplate> setter) { |
| 27 | template_->SetAccessorProperty(StringToSymbol(isolate_, name), getter, |
| 28 | setter); |
| 29 | return *this; |
| 30 | } |
| 31 | |
[email protected] | b520e13 | 2013-11-29 03:21:48 | [diff] [blame] | 32 | v8::Local<v8::ObjectTemplate> ObjectTemplateBuilder::Build() { |
| 33 | v8::Local<v8::ObjectTemplate> result = template_; |
| 34 | template_.Clear(); |
| 35 | return result; |
| 36 | } |
| 37 | |
| 38 | } // namespace gin |