[V8] setDOMException() should return v8::Handle<v8::Value>()
[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     return V8Proxy::setDOMException(ec, args.GetIsolate());
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 TestInterfaceV8Internal
160
161 static const BatchedAttribute TestInterfaceAttrs[] = {
162 #if ENABLE(Condition11) || ENABLE(Condition12)
163     // Attribute 'supplementalStr1' (Type: 'readonly attribute' ExtAttr: 'Conditional ImplementedBy')
164     {"supplementalStr1", TestInterfaceV8Internal::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", TestInterfaceV8Internal::supplementalStr2AttrGetter, TestInterfaceV8Internal::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", TestInterfaceV8Internal::supplementalNodeAttrGetter, TestInterfaceV8Internal::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", TestInterfaceV8Internal::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 V8Proxy::throwTypeError("DOM object constructor cannot be called as a function.");
212
213     if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
214         return args.Holder();
215     if (args.Length() < 1)
216         return V8Proxy::throwNotEnoughArgumentsError(args.GetIsolate());
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 V8Proxy::throwError(V8Proxy::ReferenceError, "TestInterface constructor's associated context is not available", args.GetIsolate());
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     V8DOMWrapper::setJSWrapperForActiveDOMObject(impl.release(), v8::Persistent<v8::Object>::New(wrapper), args.GetIsolate());
233     return args.Holder();
234   fail:
235     return throwError(ec, args.GetIsolate());
236 }
237
238 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestInterfaceTemplate(v8::Persistent<v8::FunctionTemplate> desc)
239 {
240     desc->ReadOnlyPrototype();
241
242     v8::Local<v8::Signature> defaultSignature;
243     defaultSignature = configureTemplate(desc, "TestInterface", v8::Persistent<v8::FunctionTemplate>(), V8TestInterface::internalFieldCount,
244         TestInterfaceAttrs, WTF_ARRAY_LENGTH(TestInterfaceAttrs),
245         TestInterfaceCallbacks, WTF_ARRAY_LENGTH(TestInterfaceCallbacks));
246     UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
247     desc->SetCallHandler(V8TestInterface::constructorCallback);
248     v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
249     v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate();
250     UNUSED_PARAM(instance); // In some cases, it will not be used.
251     UNUSED_PARAM(proto); // In some cases, it will not be used.
252     
253
254     // Custom Signature 'supplementalMethod2'
255     const int supplementalMethod2Argc = 2;
256     v8::Handle<v8::FunctionTemplate> supplementalMethod2Argv[supplementalMethod2Argc] = { v8::Handle<v8::FunctionTemplate>(), V8TestObj::GetRawTemplate() };
257     v8::Handle<v8::Signature> supplementalMethod2Signature = v8::Signature::New(desc, supplementalMethod2Argc, supplementalMethod2Argv);
258 #if ENABLE(Condition11) || ENABLE(Condition12)
259     proto->Set(v8::String::New("supplementalMethod2"), v8::FunctionTemplate::New(TestInterfaceV8Internal::supplementalMethod2Callback, v8::Handle<v8::Value>(), supplementalMethod2Signature));
260 #endif // ENABLE(Condition11) || ENABLE(Condition12)
261 #if ENABLE(Condition11) || ENABLE(Condition12)
262     desc->Set(v8::String::New("supplementalMethod4"), v8::FunctionTemplate::New(TestInterfaceV8Internal::supplementalMethod4Callback, v8::Handle<v8::Value>(), v8::Local<v8::Signature>()));
263 #endif // ENABLE(Condition11) || ENABLE(Condition12)
264     batchConfigureConstants(desc, proto, TestInterfaceConsts, WTF_ARRAY_LENGTH(TestInterfaceConsts));
265
266     // Custom toString template
267     desc->Set(getToStringName(), getToStringTemplate());
268     return desc;
269 }
270
271 v8::Persistent<v8::FunctionTemplate> V8TestInterface::GetRawTemplate()
272 {
273     V8BindingPerIsolateData* data = V8BindingPerIsolateData::current();
274     V8BindingPerIsolateData::TemplateMap::iterator result = data->rawTemplateMap().find(&info);
275     if (result != data->rawTemplateMap().end())
276         return result->second;
277
278     v8::HandleScope handleScope;
279     v8::Persistent<v8::FunctionTemplate> templ = createRawTemplate();
280     data->rawTemplateMap().add(&info, templ);
281     return templ;
282 }
283
284 v8::Persistent<v8::FunctionTemplate> V8TestInterface::GetTemplate()
285 {
286     V8BindingPerIsolateData* data = V8BindingPerIsolateData::current();
287     V8BindingPerIsolateData::TemplateMap::iterator result = data->templateMap().find(&info);
288     if (result != data->templateMap().end())
289         return result->second;
290
291     v8::HandleScope handleScope;
292     v8::Persistent<v8::FunctionTemplate> templ =
293         ConfigureV8TestInterfaceTemplate(GetRawTemplate());
294     data->templateMap().add(&info, templ);
295     return templ;
296 }
297
298 bool V8TestInterface::HasInstance(v8::Handle<v8::Value> value)
299 {
300     return GetRawTemplate()->HasInstance(value);
301 }
302
303 ActiveDOMObject* V8TestInterface::toActiveDOMObject(v8::Handle<v8::Object> object)
304 {
305     return toNative(object);
306 }      
307
308 v8::Handle<v8::Object> V8TestInterface::wrapSlow(PassRefPtr<TestInterface> impl, v8::Isolate* isolate)
309 {
310     v8::Handle<v8::Object> wrapper;
311     V8Proxy* proxy = 0;
312     wrapper = V8DOMWrapper::instantiateV8Object(proxy, &info, impl.get());
313     if (UNLIKELY(wrapper.IsEmpty()))
314         return wrapper;
315
316     v8::Persistent<v8::Object> wrapperHandle = v8::Persistent<v8::Object>::New(wrapper);
317
318     if (!hasDependentLifetime)
319         wrapperHandle.MarkIndependent();
320     V8DOMWrapper::setJSWrapperForActiveDOMObject(impl, wrapperHandle, isolate);
321     return wrapper;
322 }
323
324 void V8TestInterface::derefObject(void* object)
325 {
326     static_cast<TestInterface*>(object)->deref();
327 }
328
329 } // namespace WebCore
330
331 #endif // ENABLE(Condition1) || ENABLE(Condition2)