[V8] Pass Isolate to setDOMException() in CodeGeneratorV8.pm
[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 TestInterfaceV8Internal {
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), info.GetIsolate());
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), info.GetIsolate());
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(), args.GetIsolate());
140     }
141     fail:
142     V8Proxy::setDOMException(ec, args.GetIsolate());
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 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 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     V8DOMWrapper::setJSWrapperForActiveDOMObject(impl.release(), v8::Persistent<v8::Object>::New(wrapper));
233     return args.Holder();
234   fail:
235     return throwError(ec);
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)
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);
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)