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