4ffd4a39bb75a03a63ab7ae6830d72e7d0f6e87d
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / V8 / V8TestEventConstructor.cpp
1 /*
2     This file is part of the WebKit open source project.
3     This file has been generated by generate-bindings.pl. DO NOT MODIFY!
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Library General Public
7     License as published by the Free Software Foundation; either
8     version 2 of the License, or (at your option) any later version.
9
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13     Library General Public License for more details.
14
15     You should have received a copy of the GNU Library General Public License
16     along with this library; see the file COPYING.LIB.  If not, write to
17     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18     Boston, MA 02111-1307, USA.
19 */
20
21 #include "config.h"
22 #include "V8TestEventConstructor.h"
23
24 #include "BindingState.h"
25 #include "ContextFeatures.h"
26 #include "Dictionary.h"
27 #include "Frame.h"
28 #include "RuntimeEnabledFeatures.h"
29 #include "V8Binding.h"
30 #include "V8DOMWrapper.h"
31 #include <wtf/UnusedParam.h>
32
33 namespace WebCore {
34
35 WrapperTypeInfo V8TestEventConstructor::info = { V8TestEventConstructor::GetTemplate, V8TestEventConstructor::derefObject, 0, 0, V8TestEventConstructor::installPerContextPrototypeProperties, 0, WrapperTypeObjectPrototype };
36
37 namespace TestEventConstructorV8Internal {
38
39 template <typename T> void V8_USE(T) { }
40
41 static v8::Handle<v8::Value> attr1AttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
42 {
43     TestEventConstructor* imp = V8TestEventConstructor::toNative(info.Holder());
44     return v8String(imp->attr1(), info.GetIsolate(), ReturnUnsafeHandle);
45 }
46
47 static v8::Handle<v8::Value> attr2AttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
48 {
49     TestEventConstructor* imp = V8TestEventConstructor::toNative(info.Holder());
50     return v8String(imp->attr2(), info.GetIsolate(), ReturnUnsafeHandle);
51 }
52
53 } // namespace TestEventConstructorV8Internal
54
55 static const V8DOMConfiguration::BatchedAttribute V8TestEventConstructorAttrs[] = {
56     // Attribute 'attr1' (Type: 'readonly attribute' ExtAttr: '')
57     {"attr1", TestEventConstructorV8Internal::attr1AttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
58     // Attribute 'attr2' (Type: 'readonly attribute' ExtAttr: 'InitializedByEventConstructor')
59     {"attr2", TestEventConstructorV8Internal::attr2AttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
60 };
61
62 v8::Handle<v8::Value> V8TestEventConstructor::constructorCallback(const v8::Arguments& args)
63 {
64     if (!args.IsConstructCall())
65         return throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate());
66
67     if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
68         return args.Holder();
69     if (args.Length() < 1)
70         return throwNotEnoughArgumentsError(args.GetIsolate());
71
72     V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, type, args[0]);
73     TestEventConstructorInit eventInit;
74     if (args.Length() >= 2) {
75         V8TRYCATCH(Dictionary, options, Dictionary(args[1], args.GetIsolate()));
76         if (!fillTestEventConstructorInit(eventInit, options))
77             return v8Undefined();
78     }
79
80     RefPtr<TestEventConstructor> event = TestEventConstructor::create(type, eventInit);
81
82     v8::Handle<v8::Object> wrapper = args.Holder();
83     V8DOMWrapper::associateObjectWithWrapper(event.release(), &info, wrapper, args.GetIsolate());
84     return wrapper;
85 }
86
87 bool fillTestEventConstructorInit(TestEventConstructorInit& eventInit, const Dictionary& options)
88 {
89     options.get("attr2", eventInit.attr2);
90     return true;
91 }
92
93 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestEventConstructorTemplate(v8::Persistent<v8::FunctionTemplate> desc)
94 {
95     desc->ReadOnlyPrototype();
96
97     v8::Local<v8::Signature> defaultSignature;
98     defaultSignature = V8DOMConfiguration::configureTemplate(desc, "TestEventConstructor", v8::Persistent<v8::FunctionTemplate>(), V8TestEventConstructor::internalFieldCount,
99         V8TestEventConstructorAttrs, WTF_ARRAY_LENGTH(V8TestEventConstructorAttrs),
100         0, 0);
101     UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
102     desc->SetCallHandler(V8TestEventConstructor::constructorCallback);
103     
104
105     // Custom toString template
106     desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
107     return desc;
108 }
109
110 v8::Persistent<v8::FunctionTemplate> V8TestEventConstructor::GetRawTemplate(v8::Isolate* isolate)
111 {
112     if (!isolate)
113         isolate = v8::Isolate::GetCurrent();
114     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
115     V8PerIsolateData::TemplateMap::iterator result = data->rawTemplateMap().find(&info);
116     if (result != data->rawTemplateMap().end())
117         return result->value;
118
119     v8::HandleScope handleScope;
120     v8::Persistent<v8::FunctionTemplate> templ = createRawTemplate();
121     data->rawTemplateMap().add(&info, templ);
122     return templ;
123 }
124
125 v8::Persistent<v8::FunctionTemplate> V8TestEventConstructor::GetTemplate(v8::Isolate* isolate)
126 {
127     if (!isolate)
128         isolate = v8::Isolate::GetCurrent();
129     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
130     V8PerIsolateData::TemplateMap::iterator result = data->templateMap().find(&info);
131     if (result != data->templateMap().end())
132         return result->value;
133
134     v8::HandleScope handleScope;
135     v8::Persistent<v8::FunctionTemplate> templ =
136         ConfigureV8TestEventConstructorTemplate(GetRawTemplate());
137     data->templateMap().add(&info, templ);
138     return templ;
139 }
140
141 bool V8TestEventConstructor::HasInstance(v8::Handle<v8::Value> value)
142 {
143     return GetRawTemplate()->HasInstance(value);
144 }
145
146
147 v8::Handle<v8::Object> V8TestEventConstructor::createWrapper(PassRefPtr<TestEventConstructor> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
148 {
149     ASSERT(impl.get());
150     ASSERT(DOMDataStore::getWrapper(impl.get(), isolate).IsEmpty());
151
152     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &info, impl.get());
153     if (UNLIKELY(wrapper.IsEmpty()))
154         return wrapper;
155
156     installPerContextProperties(wrapper, impl.get());
157     v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate);
158     if (!hasDependentLifetime)
159         wrapperHandle.MarkIndependent();
160     return wrapper;
161 }
162
163 void V8TestEventConstructor::derefObject(void* object)
164 {
165     static_cast<TestEventConstructor*>(object)->deref();
166 }
167
168 } // namespace WebCore