f5a1cc64f1bd9234fa4be937612afead95e475d3
[WebKit-https.git] / WebCore / bindings / scripts / test / V8 / V8TestObj.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 "V8TestObj.h"
23
24 #include "ExceptionCode.h"
25 #include "RuntimeEnabledFeatures.h"
26 #include "ScriptCallStack.h"
27 #include "SerializedScriptValue.h"
28 #include "V8Binding.h"
29 #include "V8BindingState.h"
30 #include "V8DOMWrapper.h"
31 #include "V8IsolatedContext.h"
32 #include "V8Proxy.h"
33 #include "V8log.h"
34 #include <wtf/GetPtr.h>
35 #include <wtf/RefCounted.h>
36 #include <wtf/RefPtr.h>
37
38 namespace WebCore {
39
40 WrapperTypeInfo V8TestObj::info = { V8TestObj::GetTemplate, V8TestObj::derefObject, 0 };
41
42 namespace TestObjInternal {
43
44 template <typename T> void V8_USE(T) { }
45
46 static v8::Handle<v8::Value> readOnlyIntAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
47 {
48     INC_STATS("DOM.TestObj.readOnlyIntAttr._get");
49     TestObj* imp = V8TestObj::toNative(info.Holder());
50     return v8::Integer::New(imp->readOnlyIntAttr());
51 }
52
53 static v8::Handle<v8::Value> readOnlyStringAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
54 {
55     INC_STATS("DOM.TestObj.readOnlyStringAttr._get");
56     TestObj* imp = V8TestObj::toNative(info.Holder());
57     return v8String(imp->readOnlyStringAttr());
58 }
59
60 static v8::Handle<v8::Value> readOnlyTestObjAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
61 {
62     INC_STATS("DOM.TestObj.readOnlyTestObjAttr._get");
63     TestObj* imp = V8TestObj::toNative(info.Holder());
64     RefPtr<TestObj> result = imp->readOnlyTestObjAttr();
65     v8::Handle<v8::Value> wrapper = result.get() ? getDOMObjectMap().get(result.get()) : v8::Handle<v8::Value>();
66     if (wrapper.IsEmpty()) {
67         wrapper = toV8(result.get());
68         if (!wrapper.IsEmpty())
69             V8DOMWrapper::setHiddenReference(info.Holder(), wrapper);
70     }
71     return wrapper;
72 }
73
74 static v8::Handle<v8::Value> intAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
75 {
76     INC_STATS("DOM.TestObj.intAttr._get");
77     TestObj* imp = V8TestObj::toNative(info.Holder());
78     return v8::Integer::New(imp->intAttr());
79 }
80
81 static void intAttrAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
82 {
83     INC_STATS("DOM.TestObj.intAttr._set");
84     TestObj* imp = V8TestObj::toNative(info.Holder());
85     int v = toInt32(value);
86     imp->setIntAttr(v);
87     return;
88 }
89
90 static v8::Handle<v8::Value> longLongAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
91 {
92     INC_STATS("DOM.TestObj.longLongAttr._get");
93     TestObj* imp = V8TestObj::toNative(info.Holder());
94     return v8::Number::New(static_cast<double>(imp->longLongAttr()));
95 }
96
97 static void longLongAttrAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
98 {
99     INC_STATS("DOM.TestObj.longLongAttr._set");
100     TestObj* imp = V8TestObj::toNative(info.Holder());
101     long long v = toInt64(value);
102     imp->setLongLongAttr(WTF::getPtr(v));
103     return;
104 }
105
106 static v8::Handle<v8::Value> unsignedLongLongAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
107 {
108     INC_STATS("DOM.TestObj.unsignedLongLongAttr._get");
109     TestObj* imp = V8TestObj::toNative(info.Holder());
110     return v8::Number::New(static_cast<double>(imp->unsignedLongLongAttr()));
111 }
112
113 static void unsignedLongLongAttrAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
114 {
115     INC_STATS("DOM.TestObj.unsignedLongLongAttr._set");
116     TestObj* imp = V8TestObj::toNative(info.Holder());
117     unsigned long long v = toInt64(value);
118     imp->setUnsignedLongLongAttr(WTF::getPtr(v));
119     return;
120 }
121
122 static v8::Handle<v8::Value> stringAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
123 {
124     INC_STATS("DOM.TestObj.stringAttr._get");
125     TestObj* imp = V8TestObj::toNative(info.Holder());
126     return v8String(imp->stringAttr());
127 }
128
129 static void stringAttrAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
130 {
131     INC_STATS("DOM.TestObj.stringAttr._set");
132     TestObj* imp = V8TestObj::toNative(info.Holder());
133     V8Parameter<> v = value;
134     imp->setStringAttr(v);
135     return;
136 }
137
138 static v8::Handle<v8::Value> testObjAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
139 {
140     INC_STATS("DOM.TestObj.testObjAttr._get");
141     TestObj* imp = V8TestObj::toNative(info.Holder());
142     return toV8(imp->testObjAttr());
143 }
144
145 static void testObjAttrAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
146 {
147     INC_STATS("DOM.TestObj.testObjAttr._set");
148     TestObj* imp = V8TestObj::toNative(info.Holder());
149     TestObj* v = V8TestObj::HasInstance(value) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(value)) : 0;
150     imp->setTestObjAttr(WTF::getPtr(v));
151     return;
152 }
153
154 static v8::Handle<v8::Value> attrWithExceptionAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
155 {
156     INC_STATS("DOM.TestObj.attrWithException._get");
157     TestObj* imp = V8TestObj::toNative(info.Holder());
158     return v8::Integer::New(imp->attrWithException());
159 }
160
161 static void attrWithExceptionAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
162 {
163     INC_STATS("DOM.TestObj.attrWithException._set");
164     TestObj* imp = V8TestObj::toNative(info.Holder());
165     int v = toInt32(value);
166     imp->setAttrWithException(v);
167     return;
168 }
169
170 static v8::Handle<v8::Value> attrWithSetterExceptionAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
171 {
172     INC_STATS("DOM.TestObj.attrWithSetterException._get");
173     TestObj* imp = V8TestObj::toNative(info.Holder());
174     return v8::Integer::New(imp->attrWithSetterException());
175 }
176
177 static void attrWithSetterExceptionAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
178 {
179     INC_STATS("DOM.TestObj.attrWithSetterException._set");
180     TestObj* imp = V8TestObj::toNative(info.Holder());
181     int v = toInt32(value);
182     imp->setAttrWithSetterException(v);
183     return;
184 }
185
186 static v8::Handle<v8::Value> attrWithGetterExceptionAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
187 {
188     INC_STATS("DOM.TestObj.attrWithGetterException._get");
189     TestObj* imp = V8TestObj::toNative(info.Holder());
190     return v8::Integer::New(imp->attrWithGetterException());
191 }
192
193 static void attrWithGetterExceptionAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
194 {
195     INC_STATS("DOM.TestObj.attrWithGetterException._set");
196     TestObj* imp = V8TestObj::toNative(info.Holder());
197     int v = toInt32(value);
198     imp->setAttrWithGetterException(v);
199     return;
200 }
201
202 static v8::Handle<v8::Value> voidMethodCallback(const v8::Arguments& args)
203 {
204     INC_STATS("DOM.TestObj.voidMethod");
205     TestObj* imp = V8TestObj::toNative(args.Holder());
206     imp->voidMethod();
207     return v8::Handle<v8::Value>();
208 }
209
210 static v8::Handle<v8::Value> voidMethodWithArgsCallback(const v8::Arguments& args)
211 {
212     INC_STATS("DOM.TestObj.voidMethodWithArgs");
213     TestObj* imp = V8TestObj::toNative(args.Holder());
214     int intArg = toInt32(args[0]);
215     V8Parameter<> strArg = args[1];
216     TestObj* objArg = V8TestObj::HasInstance(args[2]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[2])) : 0;
217     imp->voidMethodWithArgs(intArg, strArg, objArg);
218     return v8::Handle<v8::Value>();
219 }
220
221 static v8::Handle<v8::Value> intMethodCallback(const v8::Arguments& args)
222 {
223     INC_STATS("DOM.TestObj.intMethod");
224     TestObj* imp = V8TestObj::toNative(args.Holder());
225     return v8::Integer::New(imp->intMethod());
226 }
227
228 static v8::Handle<v8::Value> intMethodWithArgsCallback(const v8::Arguments& args)
229 {
230     INC_STATS("DOM.TestObj.intMethodWithArgs");
231     TestObj* imp = V8TestObj::toNative(args.Holder());
232     int intArg = toInt32(args[0]);
233     V8Parameter<> strArg = args[1];
234     TestObj* objArg = V8TestObj::HasInstance(args[2]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[2])) : 0;
235     return v8::Integer::New(imp->intMethodWithArgs(intArg, strArg, objArg));
236 }
237
238 static v8::Handle<v8::Value> objMethodCallback(const v8::Arguments& args)
239 {
240     INC_STATS("DOM.TestObj.objMethod");
241     TestObj* imp = V8TestObj::toNative(args.Holder());
242     return toV8(imp->objMethod());
243 }
244
245 static v8::Handle<v8::Value> objMethodWithArgsCallback(const v8::Arguments& args)
246 {
247     INC_STATS("DOM.TestObj.objMethodWithArgs");
248     TestObj* imp = V8TestObj::toNative(args.Holder());
249     int intArg = toInt32(args[0]);
250     V8Parameter<> strArg = args[1];
251     TestObj* objArg = V8TestObj::HasInstance(args[2]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[2])) : 0;
252     return toV8(imp->objMethodWithArgs(intArg, strArg, objArg));
253 }
254
255 static v8::Handle<v8::Value> serializedValueCallback(const v8::Arguments& args)
256 {
257     INC_STATS("DOM.TestObj.serializedValue");
258     TestObj* imp = V8TestObj::toNative(args.Holder());
259     bool serializedArgDidThrow = false;
260     RefPtr<SerializedScriptValue> serializedArg = SerializedScriptValue::create(args[0], serializedArgDidThrow);
261     if (serializedArgDidThrow)
262         return v8::Undefined();
263     imp->serializedValue(serializedArg);
264     return v8::Handle<v8::Value>();
265 }
266
267 static v8::Handle<v8::Value> methodWithExceptionCallback(const v8::Arguments& args)
268 {
269     INC_STATS("DOM.TestObj.methodWithException");
270     TestObj* imp = V8TestObj::toNative(args.Holder());
271     ExceptionCode ec = 0;
272     {
273     imp->methodWithException(ec);
274     if (UNLIKELY(ec))
275         goto fail;
276     return v8::Handle<v8::Value>();
277     }
278     fail:
279     V8Proxy::setDOMException(ec);
280     return v8::Handle<v8::Value>();
281 }
282
283 static v8::Handle<v8::Value> customArgsAndExceptionCallback(const v8::Arguments& args)
284 {
285     INC_STATS("DOM.TestObj.customArgsAndException");
286     TestObj* imp = V8TestObj::toNative(args.Holder());
287     ExceptionCode ec = 0;
288     {
289     OwnPtr<ScriptCallStack> callStack(ScriptCallStack::create(args, 1));
290     if (!callStack)
291         return v8::Undefined();
292     log* intArg = V8log::HasInstance(args[0]) ? V8log::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0;
293     imp->customArgsAndException(intArg, callStack.get(), ec);
294     if (UNLIKELY(ec))
295         goto fail;
296     return v8::Handle<v8::Value>();
297     }
298     fail:
299     V8Proxy::setDOMException(ec);
300     return v8::Handle<v8::Value>();
301 }
302
303 static v8::Handle<v8::Value> addEventListenerCallback(const v8::Arguments& args)
304 {
305     INC_STATS("DOM.TestObj.addEventListener()");
306     RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(args[1], false, ListenerFindOrCreate);
307     if (listener) {
308         V8TestObj::toNative(args.Holder())->addEventListener(v8ValueToAtomicWebCoreString(args[0]), listener, args[2]->BooleanValue());
309         createHiddenDependency(args.Holder(), args[1], V8TestObj::eventListenerCacheIndex);
310     }
311     return v8::Undefined();
312 }
313
314 static v8::Handle<v8::Value> removeEventListenerCallback(const v8::Arguments& args)
315 {
316     INC_STATS("DOM.TestObj.removeEventListener()");
317     RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(args[1], false, ListenerFindOnly);
318     if (listener) {
319         V8TestObj::toNative(args.Holder())->removeEventListener(v8ValueToAtomicWebCoreString(args[0]), listener.get(), args[2]->BooleanValue());
320         removeHiddenDependency(args.Holder(), args[1], V8TestObj::eventListenerCacheIndex);
321     }
322     return v8::Undefined();
323 }
324
325 static v8::Handle<v8::Value> withDynamicFrameCallback(const v8::Arguments& args)
326 {
327     INC_STATS("DOM.TestObj.withDynamicFrame");
328     TestObj* imp = V8TestObj::toNative(args.Holder());
329     Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext();
330     if (!enteredFrame)
331         return v8::Undefined();
332     imp->withDynamicFrame(enteredFrame);
333     return v8::Handle<v8::Value>();
334 }
335
336 static v8::Handle<v8::Value> withDynamicFrameAndArgCallback(const v8::Arguments& args)
337 {
338     INC_STATS("DOM.TestObj.withDynamicFrameAndArg");
339     TestObj* imp = V8TestObj::toNative(args.Holder());
340     int intArg = toInt32(args[0]);
341     Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext();
342     if (!enteredFrame)
343         return v8::Undefined();
344     imp->withDynamicFrameAndArg(enteredFrame, intArg);
345     return v8::Handle<v8::Value>();
346 }
347
348 static v8::Handle<v8::Value> withDynamicFrameAndOptionalArgCallback(const v8::Arguments& args)
349 {
350     INC_STATS("DOM.TestObj.withDynamicFrameAndOptionalArg");
351     TestObj* imp = V8TestObj::toNative(args.Holder());
352     int intArg = toInt32(args[0]);
353     if (args.Length() <= 1) {
354         Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext();
355         if (!enteredFrame)
356             return v8::Undefined();
357         imp->withDynamicFrameAndOptionalArg(enteredFrame, intArg);
358         return v8::Handle<v8::Value>();
359     }
360     int optionalArg = toInt32(args[1]);
361     Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext();
362     if (!enteredFrame)
363         return v8::Undefined();
364     imp->withDynamicFrameAndOptionalArg(enteredFrame, intArg, optionalArg);
365     return v8::Handle<v8::Value>();
366 }
367
368 static v8::Handle<v8::Value> withDynamicFrameAndUserGestureCallback(const v8::Arguments& args)
369 {
370     INC_STATS("DOM.TestObj.withDynamicFrameAndUserGesture");
371     TestObj* imp = V8TestObj::toNative(args.Holder());
372     int intArg = toInt32(args[0]);
373     Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext();
374     if (!enteredFrame)
375         return v8::Undefined();
376     imp->withDynamicFrameAndUserGesture(enteredFrame, intArg, processingUserGesture());
377     return v8::Handle<v8::Value>();
378 }
379
380 static v8::Handle<v8::Value> withDynamicFrameAndUserGestureASADCallback(const v8::Arguments& args)
381 {
382     INC_STATS("DOM.TestObj.withDynamicFrameAndUserGestureASAD");
383     TestObj* imp = V8TestObj::toNative(args.Holder());
384     int intArg = toInt32(args[0]);
385     if (args.Length() <= 1) {
386         Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext();
387         if (!enteredFrame)
388             return v8::Undefined();
389         imp->withDynamicFrameAndUserGestureASAD(enteredFrame, intArg, processingUserGesture());
390         return v8::Handle<v8::Value>();
391     }
392     int optionalArg = toInt32(args[1]);
393     Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext();
394     if (!enteredFrame)
395         return v8::Undefined();
396     imp->withDynamicFrameAndUserGestureASAD(enteredFrame, intArg, optionalArg, processingUserGesture());
397     return v8::Handle<v8::Value>();
398 }
399
400 static v8::Handle<v8::Value> withScriptStateVoidCallback(const v8::Arguments& args)
401 {
402     INC_STATS("DOM.TestObj.withScriptStateVoid");
403     TestObj* imp = V8TestObj::toNative(args.Holder());
404     EmptyScriptState state;
405     imp->withScriptStateVoid(&state);
406     if (state.hadException())
407         return throwError(state.exception());
408     return v8::Handle<v8::Value>();
409 }
410
411 static v8::Handle<v8::Value> withScriptStateObjCallback(const v8::Arguments& args)
412 {
413     INC_STATS("DOM.TestObj.withScriptStateObj");
414     TestObj* imp = V8TestObj::toNative(args.Holder());
415     EmptyScriptState state;
416     RefPtr<TestObj> result = imp->withScriptStateObj(&state);
417     if (state.hadException())
418         return throwError(state.exception());
419     return toV8(result.release());
420 }
421
422 static v8::Handle<v8::Value> withScriptStateVoidExceptionCallback(const v8::Arguments& args)
423 {
424     INC_STATS("DOM.TestObj.withScriptStateVoidException");
425     TestObj* imp = V8TestObj::toNative(args.Holder());
426     ExceptionCode ec = 0;
427     {
428     EmptyScriptState state;
429     imp->withScriptStateVoidException(&state, ec);
430     if (UNLIKELY(ec))
431         goto fail;
432     if (state.hadException())
433         return throwError(state.exception());
434     return v8::Handle<v8::Value>();
435     }
436     fail:
437     V8Proxy::setDOMException(ec);
438     return v8::Handle<v8::Value>();
439 }
440
441 static v8::Handle<v8::Value> withScriptStateObjExceptionCallback(const v8::Arguments& args)
442 {
443     INC_STATS("DOM.TestObj.withScriptStateObjException");
444     TestObj* imp = V8TestObj::toNative(args.Holder());
445     ExceptionCode ec = 0;
446     {
447     EmptyScriptState state;
448     RefPtr<TestObj> result = imp->withScriptStateObjException(&state, ec);
449     if (UNLIKELY(ec))
450         goto fail;
451     if (state.hadException())
452         return throwError(state.exception());
453     return toV8(result.release());
454     }
455     fail:
456     V8Proxy::setDOMException(ec);
457     return v8::Handle<v8::Value>();
458 }
459
460 static v8::Handle<v8::Value> methodWithOptionalArgCallback(const v8::Arguments& args)
461 {
462     INC_STATS("DOM.TestObj.methodWithOptionalArg");
463     TestObj* imp = V8TestObj::toNative(args.Holder());
464     if (args.Length() <= 0) {
465         imp->methodWithOptionalArg();
466         return v8::Handle<v8::Value>();
467     }
468     int opt = toInt32(args[0]);
469     imp->methodWithOptionalArg(opt);
470     return v8::Handle<v8::Value>();
471 }
472
473 static v8::Handle<v8::Value> methodWithNonOptionalArgAndOptionalArgCallback(const v8::Arguments& args)
474 {
475     INC_STATS("DOM.TestObj.methodWithNonOptionalArgAndOptionalArg");
476     TestObj* imp = V8TestObj::toNative(args.Holder());
477     int nonOpt = toInt32(args[0]);
478     if (args.Length() <= 1) {
479         imp->methodWithNonOptionalArgAndOptionalArg(nonOpt);
480         return v8::Handle<v8::Value>();
481     }
482     int opt = toInt32(args[1]);
483     imp->methodWithNonOptionalArgAndOptionalArg(nonOpt, opt);
484     return v8::Handle<v8::Value>();
485 }
486
487 static v8::Handle<v8::Value> methodWithNonOptionalArgAndTwoOptionalArgsCallback(const v8::Arguments& args)
488 {
489     INC_STATS("DOM.TestObj.methodWithNonOptionalArgAndTwoOptionalArgs");
490     TestObj* imp = V8TestObj::toNative(args.Holder());
491     int nonOpt = toInt32(args[0]);
492     if (args.Length() <= 1) {
493         imp->methodWithNonOptionalArgAndTwoOptionalArgs(nonOpt);
494         return v8::Handle<v8::Value>();
495     }
496     int opt1 = toInt32(args[1]);
497     int opt2 = toInt32(args[2]);
498     imp->methodWithNonOptionalArgAndTwoOptionalArgs(nonOpt, opt1, opt2);
499     return v8::Handle<v8::Value>();
500 }
501
502 static v8::Handle<v8::Value> overloadedMethod1Callback(const v8::Arguments& args)
503 {
504     INC_STATS("DOM.TestObj.overloadedMethod1");
505     TestObj* imp = V8TestObj::toNative(args.Holder());
506     TestObj* objArg = V8TestObj::HasInstance(args[0]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0;
507     V8Parameter<> strArg = args[1];
508     imp->overloadedMethod(objArg, strArg);
509     return v8::Handle<v8::Value>();
510 }
511
512 static v8::Handle<v8::Value> overloadedMethod2Callback(const v8::Arguments& args)
513 {
514     INC_STATS("DOM.TestObj.overloadedMethod2");
515     TestObj* imp = V8TestObj::toNative(args.Holder());
516     TestObj* objArg = V8TestObj::HasInstance(args[0]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0;
517     if (args.Length() <= 1) {
518         imp->overloadedMethod(objArg);
519         return v8::Handle<v8::Value>();
520     }
521     int intArg = toInt32(args[1]);
522     imp->overloadedMethod(objArg, intArg);
523     return v8::Handle<v8::Value>();
524 }
525
526 static v8::Handle<v8::Value> overloadedMethod3Callback(const v8::Arguments& args)
527 {
528     INC_STATS("DOM.TestObj.overloadedMethod3");
529     TestObj* imp = V8TestObj::toNative(args.Holder());
530     V8Parameter<> strArg = args[0];
531     imp->overloadedMethod(strArg);
532     return v8::Handle<v8::Value>();
533 }
534
535 static v8::Handle<v8::Value> overloadedMethod4Callback(const v8::Arguments& args)
536 {
537     INC_STATS("DOM.TestObj.overloadedMethod4");
538     TestObj* imp = V8TestObj::toNative(args.Holder());
539     int intArg = toInt32(args[0]);
540     imp->overloadedMethod(intArg);
541     return v8::Handle<v8::Value>();
542 }
543
544 static v8::Handle<v8::Value> overloadedMethodCallback(const v8::Arguments& args)
545 {
546     INC_STATS("DOM.TestObj.overloadedMethod");
547     if ((args.Length() == 2 && (args[0]->IsNull() || V8TestObj::HasInstance(args[0])) && (args[1]->IsNull() || args[1]->IsUndefined() || args[1]->IsString() || args[1]->IsObject())))
548         return overloadedMethod1Callback(args);
549     if ((args.Length() == 1 && (args[0]->IsNull() || V8TestObj::HasInstance(args[0]))) || (args.Length() == 2 && (args[0]->IsNull() || V8TestObj::HasInstance(args[0]))))
550         return overloadedMethod2Callback(args);
551     if ((args.Length() == 1 && (args[0]->IsNull() || args[0]->IsUndefined() || args[0]->IsString() || args[0]->IsObject())))
552         return overloadedMethod3Callback(args);
553     if (args.Length() == 1)
554         return overloadedMethod4Callback(args);
555     V8Proxy::setDOMException(SYNTAX_ERR);
556     return notHandledByInterceptor();
557 }
558
559 } // namespace TestObjInternal
560
561 static const BatchedAttribute TestObjAttrs[] = {
562     // Attribute 'readOnlyIntAttr' (Type: 'readonly attribute' ExtAttr: '')
563     {"readOnlyIntAttr", TestObjInternal::readOnlyIntAttrAttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
564     // Attribute 'readOnlyStringAttr' (Type: 'readonly attribute' ExtAttr: '')
565     {"readOnlyStringAttr", TestObjInternal::readOnlyStringAttrAttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
566     // Attribute 'readOnlyTestObjAttr' (Type: 'readonly attribute' ExtAttr: '')
567     {"readOnlyTestObjAttr", TestObjInternal::readOnlyTestObjAttrAttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
568     // Attribute 'intAttr' (Type: 'attribute' ExtAttr: '')
569     {"intAttr", TestObjInternal::intAttrAttrGetter, TestObjInternal::intAttrAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
570     // Attribute 'longLongAttr' (Type: 'attribute' ExtAttr: '')
571     {"longLongAttr", TestObjInternal::longLongAttrAttrGetter, TestObjInternal::longLongAttrAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
572     // Attribute 'unsignedLongLongAttr' (Type: 'attribute' ExtAttr: '')
573     {"unsignedLongLongAttr", TestObjInternal::unsignedLongLongAttrAttrGetter, TestObjInternal::unsignedLongLongAttrAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
574     // Attribute 'stringAttr' (Type: 'attribute' ExtAttr: '')
575     {"stringAttr", TestObjInternal::stringAttrAttrGetter, TestObjInternal::stringAttrAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
576     // Attribute 'testObjAttr' (Type: 'attribute' ExtAttr: '')
577     {"testObjAttr", TestObjInternal::testObjAttrAttrGetter, TestObjInternal::testObjAttrAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
578     // Attribute 'attrWithException' (Type: 'attribute' ExtAttr: '')
579     {"attrWithException", TestObjInternal::attrWithExceptionAttrGetter, TestObjInternal::attrWithExceptionAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
580     // Attribute 'attrWithSetterException' (Type: 'attribute' ExtAttr: '')
581     {"attrWithSetterException", TestObjInternal::attrWithSetterExceptionAttrGetter, TestObjInternal::attrWithSetterExceptionAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
582     // Attribute 'attrWithGetterException' (Type: 'attribute' ExtAttr: '')
583     {"attrWithGetterException", TestObjInternal::attrWithGetterExceptionAttrGetter, TestObjInternal::attrWithGetterExceptionAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
584     // Attribute 'customAttr' (Type: 'attribute' ExtAttr: 'Custom')
585     {"customAttr", V8TestObj::customAttrAccessorGetter, V8TestObj::customAttrAccessorSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
586 };
587 static const BatchedCallback TestObjCallbacks[] = {
588     {"voidMethod", TestObjInternal::voidMethodCallback},
589     {"intMethod", TestObjInternal::intMethodCallback},
590     {"objMethod", TestObjInternal::objMethodCallback},
591     {"serializedValue", TestObjInternal::serializedValueCallback},
592     {"methodWithException", TestObjInternal::methodWithExceptionCallback},
593     {"customMethod", V8TestObj::customMethodCallback},
594     {"customMethodWithArgs", V8TestObj::customMethodWithArgsCallback},
595     {"addEventListener", TestObjInternal::addEventListenerCallback},
596     {"removeEventListener", TestObjInternal::removeEventListenerCallback},
597     {"withDynamicFrame", TestObjInternal::withDynamicFrameCallback},
598     {"withDynamicFrameAndArg", TestObjInternal::withDynamicFrameAndArgCallback},
599     {"withDynamicFrameAndOptionalArg", TestObjInternal::withDynamicFrameAndOptionalArgCallback},
600     {"withDynamicFrameAndUserGesture", TestObjInternal::withDynamicFrameAndUserGestureCallback},
601     {"withDynamicFrameAndUserGestureASAD", TestObjInternal::withDynamicFrameAndUserGestureASADCallback},
602     {"withScriptStateVoid", TestObjInternal::withScriptStateVoidCallback},
603     {"withScriptStateObj", TestObjInternal::withScriptStateObjCallback},
604     {"withScriptStateVoidException", TestObjInternal::withScriptStateVoidExceptionCallback},
605     {"withScriptStateObjException", TestObjInternal::withScriptStateObjExceptionCallback},
606     {"methodWithOptionalArg", TestObjInternal::methodWithOptionalArgCallback},
607     {"methodWithNonOptionalArgAndOptionalArg", TestObjInternal::methodWithNonOptionalArgAndOptionalArgCallback},
608     {"methodWithNonOptionalArgAndTwoOptionalArgs", TestObjInternal::methodWithNonOptionalArgAndTwoOptionalArgsCallback},
609     {"overloadedMethod", TestObjInternal::overloadedMethodCallback},
610 };
611 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestObjTemplate(v8::Persistent<v8::FunctionTemplate> desc)
612 {
613     v8::Local<v8::Signature> defaultSignature = configureTemplate(desc, "TestObj", v8::Persistent<v8::FunctionTemplate>(), V8TestObj::internalFieldCount,
614         TestObjAttrs, sizeof(TestObjAttrs) / sizeof(*TestObjAttrs),
615         TestObjCallbacks, sizeof(TestObjCallbacks) / sizeof(*TestObjCallbacks));
616     v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
617     v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate();
618     
619
620     // Custom Signature 'voidMethodWithArgs'
621     const int voidMethodWithArgsArgc = 3;
622     v8::Handle<v8::FunctionTemplate> voidMethodWithArgsArgv[voidMethodWithArgsArgc] = { v8::Handle<v8::FunctionTemplate>(), v8::Handle<v8::FunctionTemplate>(), V8TestObj::GetRawTemplate() };
623     v8::Handle<v8::Signature> voidMethodWithArgsSignature = v8::Signature::New(desc, voidMethodWithArgsArgc, voidMethodWithArgsArgv);
624     proto->Set(v8::String::New("voidMethodWithArgs"), v8::FunctionTemplate::New(TestObjInternal::voidMethodWithArgsCallback, v8::Handle<v8::Value>(), voidMethodWithArgsSignature));
625
626     // Custom Signature 'intMethodWithArgs'
627     const int intMethodWithArgsArgc = 3;
628     v8::Handle<v8::FunctionTemplate> intMethodWithArgsArgv[intMethodWithArgsArgc] = { v8::Handle<v8::FunctionTemplate>(), v8::Handle<v8::FunctionTemplate>(), V8TestObj::GetRawTemplate() };
629     v8::Handle<v8::Signature> intMethodWithArgsSignature = v8::Signature::New(desc, intMethodWithArgsArgc, intMethodWithArgsArgv);
630     proto->Set(v8::String::New("intMethodWithArgs"), v8::FunctionTemplate::New(TestObjInternal::intMethodWithArgsCallback, v8::Handle<v8::Value>(), intMethodWithArgsSignature));
631
632     // Custom Signature 'objMethodWithArgs'
633     const int objMethodWithArgsArgc = 3;
634     v8::Handle<v8::FunctionTemplate> objMethodWithArgsArgv[objMethodWithArgsArgc] = { v8::Handle<v8::FunctionTemplate>(), v8::Handle<v8::FunctionTemplate>(), V8TestObj::GetRawTemplate() };
635     v8::Handle<v8::Signature> objMethodWithArgsSignature = v8::Signature::New(desc, objMethodWithArgsArgc, objMethodWithArgsArgv);
636     proto->Set(v8::String::New("objMethodWithArgs"), v8::FunctionTemplate::New(TestObjInternal::objMethodWithArgsCallback, v8::Handle<v8::Value>(), objMethodWithArgsSignature));
637
638     // Custom Signature 'customArgsAndException'
639     const int customArgsAndExceptionArgc = 1;
640     v8::Handle<v8::FunctionTemplate> customArgsAndExceptionArgv[customArgsAndExceptionArgc] = { V8log::GetRawTemplate() };
641     v8::Handle<v8::Signature> customArgsAndExceptionSignature = v8::Signature::New(desc, customArgsAndExceptionArgc, customArgsAndExceptionArgv);
642     proto->Set(v8::String::New("customArgsAndException"), v8::FunctionTemplate::New(TestObjInternal::customArgsAndExceptionCallback, v8::Handle<v8::Value>(), customArgsAndExceptionSignature));
643
644     // Custom toString template
645     desc->Set(getToStringName(), getToStringTemplate());
646     return desc;
647 }
648
649 v8::Persistent<v8::FunctionTemplate> V8TestObj::GetRawTemplate()
650 {
651     static v8::Persistent<v8::FunctionTemplate> V8TestObjRawCache = createRawTemplate();
652     return V8TestObjRawCache;
653 }
654
655 v8::Persistent<v8::FunctionTemplate> V8TestObj::GetTemplate()
656 {
657     static v8::Persistent<v8::FunctionTemplate> V8TestObjCache = ConfigureV8TestObjTemplate(GetRawTemplate());
658     return V8TestObjCache;
659 }
660
661 TestObj* V8TestObj::toNative(v8::Handle<v8::Object> object)
662 {
663     return reinterpret_cast<TestObj*>(object->GetPointerFromInternalField(v8DOMWrapperObjectIndex));
664 }
665
666 bool V8TestObj::HasInstance(v8::Handle<v8::Value> value)
667 {
668     return GetRawTemplate()->HasInstance(value);
669 }
670
671
672 v8::Handle<v8::Object> V8TestObj::wrap(TestObj* impl)
673 {
674     v8::Handle<v8::Object> wrapper;
675     V8Proxy* proxy = 0;
676         wrapper = getDOMObjectMap().get(impl);
677         if (!wrapper.IsEmpty())
678             return wrapper;
679     wrapper = V8DOMWrapper::instantiateV8Object(proxy, &info, impl);
680     if (wrapper.IsEmpty())
681         return wrapper;
682
683     impl->ref();
684     getDOMObjectMap().set(impl, v8::Persistent<v8::Object>::New(wrapper));
685     return wrapper;
686 }
687
688 v8::Handle<v8::Value> toV8(PassRefPtr<TestObj > impl)
689 {
690     return toV8(impl.get());
691 }
692
693 v8::Handle<v8::Value> toV8(TestObj* impl)
694 {
695     if (!impl)
696         return v8::Null();
697     return V8TestObj::wrap(impl);
698 }
699
700 void V8TestObj::derefObject(void* object)
701 {
702     static_cast<TestObj*>(object)->deref();
703 }
704
705 } // namespace WebCore