a2c551860bf0900cd61fa61231564745028596fd
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / V8 / V8TestInterface.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 "V8TestInterface.h"
23
24 #if ENABLE(Condition1) || ENABLE(Condition2)
25
26 #include "ExceptionCode.h"
27 #include "RuntimeEnabledFeatures.h"
28 #include "TestSupplemental.h"
29 #include "V8Binding.h"
30 #include "V8BindingMacros.h"
31 #include "V8BindingState.h"
32 #include "V8DOMWrapper.h"
33 #include "V8IsolatedContext.h"
34 #include "V8Node.h"
35 #include "V8Proxy.h"
36 #include "V8TestObj.h"
37 #include <wtf/GetPtr.h>
38 #include <wtf/RefCounted.h>
39 #include <wtf/RefPtr.h>
40 #include <wtf/UnusedParam.h>
41
42 namespace WebCore {
43
44 WrapperTypeInfo V8TestInterface::info = { V8TestInterface::GetTemplate, V8TestInterface::derefObject, V8TestInterface::toActiveDOMObject, 0 };
45
46 namespace TestInterfaceInternal {
47
48 template <typename T> void V8_USE(T) { }
49
50 #if ENABLE(Condition11) || ENABLE(Condition12)
51
52 static v8::Handle<v8::Value> supplementalStr1AttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
53 {
54     INC_STATS("DOM.TestInterface.supplementalStr1._get");
55     TestInterface* imp = V8TestInterface::toNative(info.Holder());
56     return v8String(TestSupplemental::supplementalStr1(imp));
57 }
58
59 #endif // ENABLE(Condition11) || ENABLE(Condition12)
60
61 #if ENABLE(Condition11) || ENABLE(Condition12)
62
63 static v8::Handle<v8::Value> supplementalStr2AttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
64 {
65     INC_STATS("DOM.TestInterface.supplementalStr2._get");
66     TestInterface* imp = V8TestInterface::toNative(info.Holder());
67     return v8String(TestSupplemental::supplementalStr2(imp));
68 }
69
70 #endif // ENABLE(Condition11) || ENABLE(Condition12)
71
72 #if ENABLE(Condition11) || ENABLE(Condition12)
73
74 static void supplementalStr2AttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
75 {
76     INC_STATS("DOM.TestInterface.supplementalStr2._set");
77     TestInterface* imp = V8TestInterface::toNative(info.Holder());
78     STRING_TO_V8PARAMETER_EXCEPTION_BLOCK_VOID(V8Parameter<>, v, value);
79     TestSupplemental::setSupplementalStr2(imp, v);
80     return;
81 }
82
83 #endif // ENABLE(Condition11) || ENABLE(Condition12)
84
85 #if ENABLE(Condition11) || ENABLE(Condition12)
86
87 static v8::Handle<v8::Value> supplementalNodeAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
88 {
89     INC_STATS("DOM.TestInterface.supplementalNode._get");
90     TestInterface* imp = V8TestInterface::toNative(info.Holder());
91     return toV8(TestSupplemental::supplementalNode(imp));
92 }
93
94 #endif // ENABLE(Condition11) || ENABLE(Condition12)
95
96 #if ENABLE(Condition11) || ENABLE(Condition12)
97
98 static void supplementalNodeAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
99 {
100     INC_STATS("DOM.TestInterface.supplementalNode._set");
101     TestInterface* imp = V8TestInterface::toNative(info.Holder());
102     Node* v = V8Node::HasInstance(value) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(value)) : 0;
103     TestSupplemental::setSupplementalNode(imp, WTF::getPtr(v));
104     return;
105 }
106
107 #endif // ENABLE(Condition11) || ENABLE(Condition12)
108
109 #if ENABLE(Condition11) || ENABLE(Condition12)
110
111 static v8::Handle<v8::Value> supplementalMethod1Callback(const v8::Arguments& args)
112 {
113     INC_STATS("DOM.TestInterface.supplementalMethod1");
114     TestInterface* imp = V8TestInterface::toNative(args.Holder());
115     TestSupplemental::supplementalMethod1(imp);
116     return v8::Handle<v8::Value>();
117 }
118
119 #endif // ENABLE(Condition11) || ENABLE(Condition12)
120
121 #if ENABLE(Condition11) || ENABLE(Condition12)
122
123 static v8::Handle<v8::Value> supplementalMethod2Callback(const v8::Arguments& args)
124 {
125     INC_STATS("DOM.TestInterface.supplementalMethod2");
126     if (args.Length() < 2)
127         return throwError("Not enough arguments", V8Proxy::TypeError);
128     TestInterface* imp = V8TestInterface::toNative(args.Holder());
129     ExceptionCode ec = 0;
130     {
131     STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, strArg, MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined));
132     EXCEPTION_BLOCK(TestObj*, objArg, V8TestObj::HasInstance(MAYBE_MISSING_PARAMETER(args, 1, DefaultIsUndefined)) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(MAYBE_MISSING_PARAMETER(args, 1, DefaultIsUndefined))) : 0);
133     ScriptExecutionContext* scriptContext = getScriptExecutionContext();
134     if (!scriptContext)
135         return v8::Undefined();
136     RefPtr<TestObj> result = TestSupplemental::supplementalMethod2(imp, scriptContext, strArg, objArg, ec);
137     if (UNLIKELY(ec))
138         goto fail;
139     return toV8(result.release());
140     }
141     fail:
142     V8Proxy::setDOMException(ec);
143     return v8::Handle<v8::Value>();
144 }
145
146 #endif // ENABLE(Condition11) || ENABLE(Condition12)
147
148 #if ENABLE(Condition11) || ENABLE(Condition12)
149
150 static v8::Handle<v8::Value> supplementalMethod4Callback(const v8::Arguments& args)
151 {
152     INC_STATS("DOM.TestInterface.supplementalMethod4");
153     TestSupplemental::supplementalMethod4();
154     return v8::Handle<v8::Value>();
155 }
156
157 #endif // ENABLE(Condition11) || ENABLE(Condition12)
158
159 } // namespace TestInterfaceInternal
160
161 static const BatchedAttribute TestInterfaceAttrs[] = {
162 #if ENABLE(Condition11) || ENABLE(Condition12)
163     // Attribute 'supplementalStr1' (Type: 'readonly attribute' ExtAttr: 'Conditional ImplementedBy')
164     {"supplementalStr1", TestInterfaceInternal::supplementalStr1AttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
165 #endif // ENABLE(Condition11) || ENABLE(Condition12)
166 #if ENABLE(Condition11) || ENABLE(Condition12)
167     // Attribute 'supplementalStr2' (Type: 'attribute' ExtAttr: 'Conditional ImplementedBy')
168     {"supplementalStr2", TestInterfaceInternal::supplementalStr2AttrGetter, TestInterfaceInternal::supplementalStr2AttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
169 #endif // ENABLE(Condition11) || ENABLE(Condition12)
170 #if ENABLE(Condition11) || ENABLE(Condition12)
171     // Attribute 'supplementalStr3' (Type: 'attribute' ExtAttr: 'CustomSetter CustomGetter Conditional ImplementedBy')
172     {"supplementalStr3", V8TestInterface::supplementalStr3AccessorGetter, V8TestInterface::supplementalStr3AccessorSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
173 #endif // ENABLE(Condition11) || ENABLE(Condition12)
174 #if ENABLE(Condition11) || ENABLE(Condition12)
175     // Attribute 'supplementalNode' (Type: 'attribute' ExtAttr: 'Conditional ImplementedBy')
176     {"supplementalNode", TestInterfaceInternal::supplementalNodeAttrGetter, TestInterfaceInternal::supplementalNodeAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
177 #endif // ENABLE(Condition11) || ENABLE(Condition12)
178 };
179
180 static const BatchedCallback TestInterfaceCallbacks[] = {
181 #if ENABLE(Condition11) || ENABLE(Condition12)
182     {"supplementalMethod1", TestInterfaceInternal::supplementalMethod1Callback},
183 #endif
184 #if ENABLE(Condition11) || ENABLE(Condition12)
185     {"supplementalMethod3", V8TestInterface::supplementalMethod3Callback},
186 #endif
187 };
188
189 static const BatchedConstant TestInterfaceConsts[] = {
190 #if ENABLE(Condition11) || ENABLE(Condition12)
191     {"SUPPLEMENTALCONSTANT1", static_cast<signed int>(1)},
192 #endif
193 #if ENABLE(Condition11) || ENABLE(Condition12)
194     {"SUPPLEMENTALCONSTANT2", static_cast<signed int>(2)},
195 #endif
196 };
197
198
199 #if ENABLE(Condition11) || ENABLE(Condition12)
200 COMPILE_ASSERT(1 == TestSupplemental::SUPPLEMENTALCONSTANT1, TestInterfaceEnumSUPPLEMENTALCONSTANT1IsWrongUseDoNotCheckConstants);
201 #endif
202 #if ENABLE(Condition11) || ENABLE(Condition12)
203 COMPILE_ASSERT(2 == TestSupplemental::CONST_IMPL, TestInterfaceEnumCONST_IMPLIsWrongUseDoNotCheckConstants);
204 #endif
205
206 v8::Handle<v8::Value> V8TestInterface::constructorCallback(const v8::Arguments& args)
207 {
208     INC_STATS("DOM.TestInterface.Constructor");
209
210     if (!args.IsConstructCall())
211         return throwError("DOM object constructor cannot be called as a function.", V8Proxy::TypeError);
212
213     if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
214         return args.Holder();
215     if (args.Length() < 1)
216         return throwError("Not enough arguments", V8Proxy::TypeError);
217
218     ExceptionCode ec = 0;
219     STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, str1, MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined));
220     STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, str2, MAYBE_MISSING_PARAMETER(args, 1, DefaultIsUndefined));
221
222     ScriptExecutionContext* context = getScriptExecutionContext();
223     if (!context)
224         return throwError("TestInterface constructor's associated context is not available", V8Proxy::ReferenceError);
225
226     RefPtr<TestInterface> impl = TestInterface::create(context, str1, str2, ec);
227     v8::Handle<v8::Object> wrapper = args.Holder();
228     if (ec)
229         goto fail;
230
231     V8DOMWrapper::setDOMWrapper(wrapper, &info, impl.get());
232     impl->ref();
233     V8DOMWrapper::setJSWrapperForActiveDOMObject(impl.get(), v8::Persistent<v8::Object>::New(wrapper));
234     return args.Holder();
235   fail:
236     return throwError(ec);
237 }
238
239 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestInterfaceTemplate(v8::Persistent<v8::FunctionTemplate> desc)
240 {
241     desc->ReadOnlyPrototype();
242
243     v8::Local<v8::Signature> defaultSignature;
244     defaultSignature = configureTemplate(desc, "TestInterface", v8::Persistent<v8::FunctionTemplate>(), V8TestInterface::internalFieldCount,
245         TestInterfaceAttrs, WTF_ARRAY_LENGTH(TestInterfaceAttrs),
246         TestInterfaceCallbacks, WTF_ARRAY_LENGTH(TestInterfaceCallbacks));
247     UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
248     desc->SetCallHandler(V8TestInterface::constructorCallback);
249     v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
250     v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate();
251     UNUSED_PARAM(instance); // In some cases, it will not be used.
252     UNUSED_PARAM(proto); // In some cases, it will not be used.
253     
254
255     // Custom Signature 'supplementalMethod2'
256     const int supplementalMethod2Argc = 2;
257     v8::Handle<v8::FunctionTemplate> supplementalMethod2Argv[supplementalMethod2Argc] = { v8::Handle<v8::FunctionTemplate>(), V8TestObj::GetRawTemplate() };
258     v8::Handle<v8::Signature> supplementalMethod2Signature = v8::Signature::New(desc, supplementalMethod2Argc, supplementalMethod2Argv);
259 #if ENABLE(Condition11) || ENABLE(Condition12)
260     proto->Set(v8::String::New("supplementalMethod2"), v8::FunctionTemplate::New(TestInterfaceInternal::supplementalMethod2Callback, v8::Handle<v8::Value>(), supplementalMethod2Signature));
261 #endif // ENABLE(Condition11) || ENABLE(Condition12)
262 #if ENABLE(Condition11) || ENABLE(Condition12)
263     desc->Set(v8::String::New("supplementalMethod4"), v8::FunctionTemplate::New(TestInterfaceInternal::supplementalMethod4Callback, v8::Handle<v8::Value>(), v8::Local<v8::Signature>()));
264 #endif // ENABLE(Condition11) || ENABLE(Condition12)
265     batchConfigureConstants(desc, proto, TestInterfaceConsts, WTF_ARRAY_LENGTH(TestInterfaceConsts));
266
267     // Custom toString template
268     desc->Set(getToStringName(), getToStringTemplate());
269     return desc;
270 }
271
272 v8::Persistent<v8::FunctionTemplate> V8TestInterface::GetRawTemplate()
273 {
274     V8BindingPerIsolateData* data = V8BindingPerIsolateData::current();
275     V8BindingPerIsolateData::TemplateMap::iterator result = data->rawTemplateMap().find(&info);
276     if (result != data->rawTemplateMap().end())
277         return result->second;
278
279     v8::HandleScope handleScope;
280     v8::Persistent<v8::FunctionTemplate> templ = createRawTemplate();
281     data->rawTemplateMap().add(&info, templ);
282     return templ;
283 }
284
285 v8::Persistent<v8::FunctionTemplate> V8TestInterface::GetTemplate()
286 {
287     V8BindingPerIsolateData* data = V8BindingPerIsolateData::current();
288     V8BindingPerIsolateData::TemplateMap::iterator result = data->templateMap().find(&info);
289     if (result != data->templateMap().end())
290         return result->second;
291
292     v8::HandleScope handleScope;
293     v8::Persistent<v8::FunctionTemplate> templ =
294         ConfigureV8TestInterfaceTemplate(GetRawTemplate());
295     data->templateMap().add(&info, templ);
296     return templ;
297 }
298
299 bool V8TestInterface::HasInstance(v8::Handle<v8::Value> value)
300 {
301     return GetRawTemplate()->HasInstance(value);
302 }
303
304 ActiveDOMObject* V8TestInterface::toActiveDOMObject(v8::Handle<v8::Object> object)
305 {
306     return toNative(object);
307 }      
308
309 v8::Handle<v8::Object> V8TestInterface::wrapSlow(TestInterface* impl)
310 {
311     v8::Handle<v8::Object> wrapper;
312     V8Proxy* proxy = 0;
313     wrapper = V8DOMWrapper::instantiateV8Object(proxy, &info, impl);
314     if (UNLIKELY(wrapper.IsEmpty()))
315         return wrapper;
316
317     impl->ref();
318     v8::Persistent<v8::Object> wrapperHandle = v8::Persistent<v8::Object>::New(wrapper);
319
320     if (!hasDependentLifetime)
321         wrapperHandle.MarkIndependent();
322     getActiveDOMObjectMap().set(impl, wrapperHandle);
323     return wrapper;
324 }
325
326 void V8TestInterface::derefObject(void* object)
327 {
328     static_cast<TestInterface*>(object)->deref();
329 }
330
331 } // namespace WebCore
332
333 #endif // ENABLE(Condition1) || ENABLE(Condition2)