acbded4ac30320702ce0a214c533c4f260d3d60b
[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 "ContextEnabledFeatures.h"
27 #include "ExceptionCode.h"
28 #include "RuntimeEnabledFeatures.h"
29 #include "TestSupplemental.h"
30 #include "V8Binding.h"
31 #include "V8BindingMacros.h"
32 #include "V8BindingState.h"
33 #include "V8DOMWrapper.h"
34 #include "V8IsolatedContext.h"
35 #include "V8Node.h"
36 #include "V8Proxy.h"
37 #include "V8TestObj.h"
38 #include <wtf/GetPtr.h>
39 #include <wtf/RefCounted.h>
40 #include <wtf/RefPtr.h>
41 #include <wtf/UnusedParam.h>
42
43 namespace WebCore {
44
45 WrapperTypeInfo V8TestInterface::info = { V8TestInterface::GetTemplate, V8TestInterface::derefObject, V8TestInterface::toActiveDOMObject, 0 };
46
47 namespace TestInterfaceV8Internal {
48
49 template <typename T> void V8_USE(T) { }
50
51 #if ENABLE(Condition11) || ENABLE(Condition12)
52
53 static v8::Handle<v8::Value> supplementalStr1AttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
54 {
55     INC_STATS("DOM.TestInterface.supplementalStr1._get");
56     TestInterface* imp = V8TestInterface::toNative(info.Holder());
57     return v8String(TestSupplemental::supplementalStr1(imp), info.GetIsolate());
58 }
59
60 #endif // ENABLE(Condition11) || ENABLE(Condition12)
61
62 #if ENABLE(Condition11) || ENABLE(Condition12)
63
64 static v8::Handle<v8::Value> supplementalStr2AttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
65 {
66     INC_STATS("DOM.TestInterface.supplementalStr2._get");
67     TestInterface* imp = V8TestInterface::toNative(info.Holder());
68     return v8String(TestSupplemental::supplementalStr2(imp), info.GetIsolate());
69 }
70
71 #endif // ENABLE(Condition11) || ENABLE(Condition12)
72
73 #if ENABLE(Condition11) || ENABLE(Condition12)
74
75 static void supplementalStr2AttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
76 {
77     INC_STATS("DOM.TestInterface.supplementalStr2._set");
78     TestInterface* imp = V8TestInterface::toNative(info.Holder());
79     STRING_TO_V8PARAMETER_EXCEPTION_BLOCK_VOID(V8Parameter<>, v, value);
80     TestSupplemental::setSupplementalStr2(imp, v);
81     return;
82 }
83
84 #endif // ENABLE(Condition11) || ENABLE(Condition12)
85
86 #if ENABLE(Condition11) || ENABLE(Condition12)
87
88 static v8::Handle<v8::Value> supplementalNodeAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
89 {
90     INC_STATS("DOM.TestInterface.supplementalNode._get");
91     TestInterface* imp = V8TestInterface::toNative(info.Holder());
92     return toV8(TestSupplemental::supplementalNode(imp), info.GetIsolate());
93 }
94
95 #endif // ENABLE(Condition11) || ENABLE(Condition12)
96
97 #if ENABLE(Condition11) || ENABLE(Condition12)
98
99 static void supplementalNodeAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
100 {
101     INC_STATS("DOM.TestInterface.supplementalNode._set");
102     TestInterface* imp = V8TestInterface::toNative(info.Holder());
103     Node* v = V8Node::HasInstance(value) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(value)) : 0;
104     TestSupplemental::setSupplementalNode(imp, WTF::getPtr(v));
105     return;
106 }
107
108 #endif // ENABLE(Condition11) || ENABLE(Condition12)
109
110 #if ENABLE(Condition11) || ENABLE(Condition12)
111
112 static v8::Handle<v8::Value> supplementalMethod1Callback(const v8::Arguments& args)
113 {
114     INC_STATS("DOM.TestInterface.supplementalMethod1");
115     TestInterface* imp = V8TestInterface::toNative(args.Holder());
116     TestSupplemental::supplementalMethod1(imp);
117     return v8::Handle<v8::Value>();
118 }
119
120 #endif // ENABLE(Condition11) || ENABLE(Condition12)
121
122 #if ENABLE(Condition11) || ENABLE(Condition12)
123
124 static v8::Handle<v8::Value> supplementalMethod2Callback(const v8::Arguments& args)
125 {
126     INC_STATS("DOM.TestInterface.supplementalMethod2");
127     if (args.Length() < 2)
128         return V8Proxy::throwNotEnoughArgumentsError(args.GetIsolate());
129     TestInterface* imp = V8TestInterface::toNative(args.Holder());
130     ExceptionCode ec = 0;
131     {
132     STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, strArg, MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined));
133     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);
134     ScriptExecutionContext* scriptContext = getScriptExecutionContext();
135     if (!scriptContext)
136         return v8::Undefined();
137     RefPtr<TestObj> result = TestSupplemental::supplementalMethod2(imp, scriptContext, strArg, objArg, ec);
138     if (UNLIKELY(ec))
139         goto fail;
140     return toV8(result.release(), args.GetIsolate());
141     }
142     fail:
143     V8Proxy::setDOMException(ec, args.GetIsolate());
144     return v8::Handle<v8::Value>();
145 }
146
147 #endif // ENABLE(Condition11) || ENABLE(Condition12)
148
149 #if ENABLE(Condition11) || ENABLE(Condition12)
150
151 static v8::Handle<v8::Value> supplementalMethod4Callback(const v8::Arguments& args)
152 {
153     INC_STATS("DOM.TestInterface.supplementalMethod4");
154     TestSupplemental::supplementalMethod4();
155     return v8::Handle<v8::Value>();
156 }
157
158 #endif // ENABLE(Condition11) || ENABLE(Condition12)
159
160 } // namespace TestInterfaceV8Internal
161
162 static const BatchedAttribute TestInterfaceAttrs[] = {
163 #if ENABLE(Condition11) || ENABLE(Condition12)
164     // Attribute 'supplementalStr1' (Type: 'readonly attribute' ExtAttr: 'Conditional ImplementedBy')
165     {"supplementalStr1", TestInterfaceV8Internal::supplementalStr1AttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
166 #endif // ENABLE(Condition11) || ENABLE(Condition12)
167 #if ENABLE(Condition11) || ENABLE(Condition12)
168     // Attribute 'supplementalStr2' (Type: 'attribute' ExtAttr: 'Conditional ImplementedBy')
169     {"supplementalStr2", TestInterfaceV8Internal::supplementalStr2AttrGetter, TestInterfaceV8Internal::supplementalStr2AttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
170 #endif // ENABLE(Condition11) || ENABLE(Condition12)
171 #if ENABLE(Condition11) || ENABLE(Condition12)
172     // Attribute 'supplementalStr3' (Type: 'attribute' ExtAttr: 'CustomSetter CustomGetter Conditional ImplementedBy')
173     {"supplementalStr3", V8TestInterface::supplementalStr3AccessorGetter, V8TestInterface::supplementalStr3AccessorSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
174 #endif // ENABLE(Condition11) || ENABLE(Condition12)
175 #if ENABLE(Condition11) || ENABLE(Condition12)
176     // Attribute 'supplementalNode' (Type: 'attribute' ExtAttr: 'Conditional ImplementedBy')
177     {"supplementalNode", TestInterfaceV8Internal::supplementalNodeAttrGetter, TestInterfaceV8Internal::supplementalNodeAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
178 #endif // ENABLE(Condition11) || ENABLE(Condition12)
179 };
180
181 static const BatchedCallback TestInterfaceCallbacks[] = {
182 #if ENABLE(Condition11) || ENABLE(Condition12)
183     {"supplementalMethod1", TestInterfaceV8Internal::supplementalMethod1Callback},
184 #endif
185 #if ENABLE(Condition11) || ENABLE(Condition12)
186     {"supplementalMethod3", V8TestInterface::supplementalMethod3Callback},
187 #endif
188 };
189
190 static const BatchedConstant TestInterfaceConsts[] = {
191 #if ENABLE(Condition11) || ENABLE(Condition12)
192     {"SUPPLEMENTALCONSTANT1", static_cast<signed int>(1)},
193 #endif
194 #if ENABLE(Condition11) || ENABLE(Condition12)
195     {"SUPPLEMENTALCONSTANT2", static_cast<signed int>(2)},
196 #endif
197 };
198
199
200 #if ENABLE(Condition11) || ENABLE(Condition12)
201 COMPILE_ASSERT(1 == TestSupplemental::SUPPLEMENTALCONSTANT1, TestInterfaceEnumSUPPLEMENTALCONSTANT1IsWrongUseDoNotCheckConstants);
202 #endif
203 #if ENABLE(Condition11) || ENABLE(Condition12)
204 COMPILE_ASSERT(2 == TestSupplemental::CONST_IMPL, TestInterfaceEnumCONST_IMPLIsWrongUseDoNotCheckConstants);
205 #endif
206
207 v8::Handle<v8::Value> V8TestInterface::constructorCallback(const v8::Arguments& args)
208 {
209     INC_STATS("DOM.TestInterface.Constructor");
210
211     if (!args.IsConstructCall())
212         return V8Proxy::throwTypeError("DOM object constructor cannot be called as a function.");
213
214     if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
215         return args.Holder();
216     if (args.Length() < 1)
217         return V8Proxy::throwNotEnoughArgumentsError(args.GetIsolate());
218
219     ExceptionCode ec = 0;
220     STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, str1, MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined));
221     STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, str2, MAYBE_MISSING_PARAMETER(args, 1, DefaultIsUndefined));
222
223     ScriptExecutionContext* context = getScriptExecutionContext();
224     if (!context)
225         return V8Proxy::throwError(V8Proxy::ReferenceError, "TestInterface constructor's associated context is not available", args.GetIsolate());
226
227     RefPtr<TestInterface> impl = TestInterface::create(context, str1, str2, ec);
228     v8::Handle<v8::Object> wrapper = args.Holder();
229     if (ec)
230         goto fail;
231
232     V8DOMWrapper::setDOMWrapper(wrapper, &info, impl.get());
233     V8DOMWrapper::setJSWrapperForActiveDOMObject(impl.release(), v8::Persistent<v8::Object>::New(wrapper), args.GetIsolate());
234     return args.Holder();
235   fail:
236     return throwError(ec, args.GetIsolate());
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(TestInterfaceV8Internal::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(TestInterfaceV8Internal::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(PassRefPtr<TestInterface> impl, v8::Isolate* isolate)
310 {
311     v8::Handle<v8::Object> wrapper;
312     V8Proxy* proxy = 0;
313     wrapper = V8DOMWrapper::instantiateV8Object(proxy, &info, impl.get());
314     if (UNLIKELY(wrapper.IsEmpty()))
315         return wrapper;
316
317     v8::Persistent<v8::Object> wrapperHandle = v8::Persistent<v8::Object>::New(wrapper);
318
319     if (!hasDependentLifetime)
320         wrapperHandle.MarkIndependent();
321     V8DOMWrapper::setJSWrapperForActiveDOMObject(impl, wrapperHandle, isolate);
322     return wrapper;
323 }
324
325 void V8TestInterface::derefObject(void* object)
326 {
327     static_cast<TestInterface*>(object)->deref();
328 }
329
330 } // namespace WebCore
331
332 #endif // ENABLE(Condition1) || ENABLE(Condition2)