Unreviewed, rolling out r112199.
[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 "Dictionary.h"
25 #include "RuntimeEnabledFeatures.h"
26 #include "V8Binding.h"
27 #include "V8BindingMacros.h"
28 #include "V8BindingState.h"
29 #include "V8DOMWrapper.h"
30 #include "V8IsolatedContext.h"
31 #include "V8Proxy.h"
32 #include <wtf/UnusedParam.h>
33
34 namespace WebCore {
35
36 WrapperTypeInfo V8TestEventConstructor::info = { V8TestEventConstructor::GetTemplate, V8TestEventConstructor::derefObject, 0, 0 };
37
38 namespace TestEventConstructorInternal {
39
40 template <typename T> void V8_USE(T) { }
41
42 static v8::Handle<v8::Value> attr1AttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
43 {
44     INC_STATS("DOM.TestEventConstructor.attr1._get");
45     TestEventConstructor* imp = V8TestEventConstructor::toNative(info.Holder());
46     return v8String(imp->attr1());
47 }
48
49 static v8::Handle<v8::Value> attr2AttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
50 {
51     INC_STATS("DOM.TestEventConstructor.attr2._get");
52     TestEventConstructor* imp = V8TestEventConstructor::toNative(info.Holder());
53     return v8String(imp->attr2());
54 }
55
56 } // namespace TestEventConstructorInternal
57
58 static const BatchedAttribute TestEventConstructorAttrs[] = {
59     // Attribute 'attr1' (Type: 'readonly attribute' ExtAttr: '')
60     {"attr1", TestEventConstructorInternal::attr1AttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
61     // Attribute 'attr2' (Type: 'readonly attribute' ExtAttr: 'InitializedByEventConstructor')
62     {"attr2", TestEventConstructorInternal::attr2AttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
63 };
64
65 v8::Handle<v8::Value> V8TestEventConstructor::constructorCallback(const v8::Arguments& args)
66 {
67     INC_STATS("DOM.TestEventConstructor.Constructor");
68
69     if (!args.IsConstructCall())
70         return throwError("DOM object constructor cannot be called as a function.", V8Proxy::TypeError);
71
72     if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
73         return args.Holder();
74
75     if (args.Length() < 1)
76         return throwError("Not enough arguments", V8Proxy::TypeError);
77
78     STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, type, args[0]);
79     TestEventConstructorInit eventInit;
80     if (args.Length() >= 2) {
81         EXCEPTION_BLOCK(Dictionary, options, args[1]);
82         if (!fillTestEventConstructorInit(eventInit, options))
83             return v8::Undefined();
84     }
85
86     RefPtr<TestEventConstructor> event = TestEventConstructor::create(type, eventInit);
87
88     V8DOMWrapper::setDOMWrapper(args.Holder(), &info, event.get());
89     return toV8(event.release(), args.Holder());
90 }
91
92 bool fillTestEventConstructorInit(TestEventConstructorInit& eventInit, const Dictionary& options)
93 {
94     options.get("attr2", eventInit.attr2);
95     return true;
96 }
97
98 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestEventConstructorTemplate(v8::Persistent<v8::FunctionTemplate> desc)
99 {
100     desc->ReadOnlyPrototype();
101
102     v8::Local<v8::Signature> defaultSignature;
103     defaultSignature = configureTemplate(desc, "TestEventConstructor", v8::Persistent<v8::FunctionTemplate>(), V8TestEventConstructor::internalFieldCount,
104         TestEventConstructorAttrs, WTF_ARRAY_LENGTH(TestEventConstructorAttrs),
105         0, 0);
106     UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
107     desc->SetCallHandler(V8TestEventConstructor::constructorCallback);
108     
109
110     // Custom toString template
111     desc->Set(getToStringName(), getToStringTemplate());
112     return desc;
113 }
114
115 v8::Persistent<v8::FunctionTemplate> V8TestEventConstructor::GetRawTemplate()
116 {
117     V8BindingPerIsolateData* data = V8BindingPerIsolateData::current();
118     V8BindingPerIsolateData::TemplateMap::iterator result = data->rawTemplateMap().find(&info);
119     if (result != data->rawTemplateMap().end())
120         return result->second;
121
122     v8::HandleScope handleScope;
123     v8::Persistent<v8::FunctionTemplate> templ = createRawTemplate();
124     data->rawTemplateMap().add(&info, templ);
125     return templ;
126 }
127
128 v8::Persistent<v8::FunctionTemplate> V8TestEventConstructor::GetTemplate()
129 {
130     V8BindingPerIsolateData* data = V8BindingPerIsolateData::current();
131     V8BindingPerIsolateData::TemplateMap::iterator result = data->templateMap().find(&info);
132     if (result != data->templateMap().end())
133         return result->second;
134
135     v8::HandleScope handleScope;
136     v8::Persistent<v8::FunctionTemplate> templ =
137         ConfigureV8TestEventConstructorTemplate(GetRawTemplate());
138     data->templateMap().add(&info, templ);
139     return templ;
140 }
141
142 bool V8TestEventConstructor::HasInstance(v8::Handle<v8::Value> value)
143 {
144     return GetRawTemplate()->HasInstance(value);
145 }
146
147
148 v8::Handle<v8::Object> V8TestEventConstructor::wrapSlow(PassRefPtr<TestEventConstructor> impl)
149 {
150     v8::Handle<v8::Object> wrapper;
151     V8Proxy* proxy = 0;
152     wrapper = V8DOMWrapper::instantiateV8Object(proxy, &info, impl.get());
153     if (UNLIKELY(wrapper.IsEmpty()))
154         return wrapper;
155
156     v8::Persistent<v8::Object> wrapperHandle = v8::Persistent<v8::Object>::New(wrapper);
157
158     if (!hasDependentLifetime)
159         wrapperHandle.MarkIndependent();
160     getDOMObjectMap().set(impl.leakRef(), wrapperHandle);
161     return wrapper;
162 }
163
164 void V8TestEventConstructor::derefObject(void* object)
165 {
166     static_cast<TestEventConstructor*>(object)->deref();
167 }
168
169 } // namespace WebCore