94dcd5ee0aef042d3c034d4cb4c41756b00fe017
[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> scriptStringAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
203 {
204     INC_STATS("DOM.TestObj.scriptStringAttr._get");
205     TestObj* imp = V8TestObj::toNative(info.Holder());
206     v8StringOrNull(exec, imp->scriptStringAttr());
207 }
208
209 static v8::Handle<v8::Value> voidMethodCallback(const v8::Arguments& args)
210 {
211     INC_STATS("DOM.TestObj.voidMethod");
212     TestObj* imp = V8TestObj::toNative(args.Holder());
213     imp->voidMethod();
214     return v8::Handle<v8::Value>();
215 }
216
217 static v8::Handle<v8::Value> voidMethodWithArgsCallback(const v8::Arguments& args)
218 {
219     INC_STATS("DOM.TestObj.voidMethodWithArgs");
220     TestObj* imp = V8TestObj::toNative(args.Holder());
221     int intArg = toInt32(args[0]);
222     V8Parameter<> strArg = args[1];
223     TestObj* objArg = V8TestObj::HasInstance(args[2]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[2])) : 0;
224     imp->voidMethodWithArgs(intArg, strArg, objArg);
225     return v8::Handle<v8::Value>();
226 }
227
228 static v8::Handle<v8::Value> intMethodCallback(const v8::Arguments& args)
229 {
230     INC_STATS("DOM.TestObj.intMethod");
231     TestObj* imp = V8TestObj::toNative(args.Holder());
232     return v8::Integer::New(imp->intMethod());
233 }
234
235 static v8::Handle<v8::Value> intMethodWithArgsCallback(const v8::Arguments& args)
236 {
237     INC_STATS("DOM.TestObj.intMethodWithArgs");
238     TestObj* imp = V8TestObj::toNative(args.Holder());
239     int intArg = toInt32(args[0]);
240     V8Parameter<> strArg = args[1];
241     TestObj* objArg = V8TestObj::HasInstance(args[2]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[2])) : 0;
242     return v8::Integer::New(imp->intMethodWithArgs(intArg, strArg, objArg));
243 }
244
245 static v8::Handle<v8::Value> objMethodCallback(const v8::Arguments& args)
246 {
247     INC_STATS("DOM.TestObj.objMethod");
248     TestObj* imp = V8TestObj::toNative(args.Holder());
249     return toV8(imp->objMethod());
250 }
251
252 static v8::Handle<v8::Value> objMethodWithArgsCallback(const v8::Arguments& args)
253 {
254     INC_STATS("DOM.TestObj.objMethodWithArgs");
255     TestObj* imp = V8TestObj::toNative(args.Holder());
256     int intArg = toInt32(args[0]);
257     V8Parameter<> strArg = args[1];
258     TestObj* objArg = V8TestObj::HasInstance(args[2]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[2])) : 0;
259     return toV8(imp->objMethodWithArgs(intArg, strArg, objArg));
260 }
261
262 static v8::Handle<v8::Value> serializedValueCallback(const v8::Arguments& args)
263 {
264     INC_STATS("DOM.TestObj.serializedValue");
265     TestObj* imp = V8TestObj::toNative(args.Holder());
266     bool serializedArgDidThrow = false;
267     RefPtr<SerializedScriptValue> serializedArg = SerializedScriptValue::create(args[0], serializedArgDidThrow);
268     if (serializedArgDidThrow)
269         return v8::Undefined();
270     imp->serializedValue(serializedArg);
271     return v8::Handle<v8::Value>();
272 }
273
274 static v8::Handle<v8::Value> methodWithExceptionCallback(const v8::Arguments& args)
275 {
276     INC_STATS("DOM.TestObj.methodWithException");
277     TestObj* imp = V8TestObj::toNative(args.Holder());
278     ExceptionCode ec = 0;
279     {
280     imp->methodWithException(ec);
281     if (UNLIKELY(ec))
282         goto fail;
283     return v8::Handle<v8::Value>();
284     }
285     fail:
286     V8Proxy::setDOMException(ec);
287     return v8::Handle<v8::Value>();
288 }
289
290 static v8::Handle<v8::Value> customArgsAndExceptionCallback(const v8::Arguments& args)
291 {
292     INC_STATS("DOM.TestObj.customArgsAndException");
293     TestObj* imp = V8TestObj::toNative(args.Holder());
294     ExceptionCode ec = 0;
295     {
296     OwnPtr<ScriptCallStack> callStack(ScriptCallStack::create(args, 1));
297     if (!callStack)
298         return v8::Undefined();
299     log* intArg = V8log::HasInstance(args[0]) ? V8log::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0;
300     imp->customArgsAndException(intArg, callStack.get(), ec);
301     if (UNLIKELY(ec))
302         goto fail;
303     return v8::Handle<v8::Value>();
304     }
305     fail:
306     V8Proxy::setDOMException(ec);
307     return v8::Handle<v8::Value>();
308 }
309
310 static v8::Handle<v8::Value> addEventListenerCallback(const v8::Arguments& args)
311 {
312     INC_STATS("DOM.TestObj.addEventListener()");
313     RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(args[1], false, ListenerFindOrCreate);
314     if (listener) {
315         V8TestObj::toNative(args.Holder())->addEventListener(v8ValueToAtomicWebCoreString(args[0]), listener, args[2]->BooleanValue());
316         createHiddenDependency(args.Holder(), args[1], V8TestObj::eventListenerCacheIndex);
317     }
318     return v8::Undefined();
319 }
320
321 static v8::Handle<v8::Value> removeEventListenerCallback(const v8::Arguments& args)
322 {
323     INC_STATS("DOM.TestObj.removeEventListener()");
324     RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(args[1], false, ListenerFindOnly);
325     if (listener) {
326         V8TestObj::toNative(args.Holder())->removeEventListener(v8ValueToAtomicWebCoreString(args[0]), listener.get(), args[2]->BooleanValue());
327         removeHiddenDependency(args.Holder(), args[1], V8TestObj::eventListenerCacheIndex);
328     }
329     return v8::Undefined();
330 }
331
332 static v8::Handle<v8::Value> withDynamicFrameCallback(const v8::Arguments& args)
333 {
334     INC_STATS("DOM.TestObj.withDynamicFrame");
335     TestObj* imp = V8TestObj::toNative(args.Holder());
336     Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext();
337     if (!enteredFrame)
338         return v8::Undefined();
339     imp->withDynamicFrame(enteredFrame);
340     return v8::Handle<v8::Value>();
341 }
342
343 static v8::Handle<v8::Value> withDynamicFrameAndArgCallback(const v8::Arguments& args)
344 {
345     INC_STATS("DOM.TestObj.withDynamicFrameAndArg");
346     TestObj* imp = V8TestObj::toNative(args.Holder());
347     int intArg = toInt32(args[0]);
348     Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext();
349     if (!enteredFrame)
350         return v8::Undefined();
351     imp->withDynamicFrameAndArg(enteredFrame, intArg);
352     return v8::Handle<v8::Value>();
353 }
354
355 static v8::Handle<v8::Value> withDynamicFrameAndOptionalArgCallback(const v8::Arguments& args)
356 {
357     INC_STATS("DOM.TestObj.withDynamicFrameAndOptionalArg");
358     TestObj* imp = V8TestObj::toNative(args.Holder());
359     int intArg = toInt32(args[0]);
360     if (args.Length() <= 1) {
361         Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext();
362         if (!enteredFrame)
363             return v8::Undefined();
364         imp->withDynamicFrameAndOptionalArg(enteredFrame, intArg);
365         return v8::Handle<v8::Value>();
366     }
367     int optionalArg = toInt32(args[1]);
368     Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext();
369     if (!enteredFrame)
370         return v8::Undefined();
371     imp->withDynamicFrameAndOptionalArg(enteredFrame, intArg, optionalArg);
372     return v8::Handle<v8::Value>();
373 }
374
375 static v8::Handle<v8::Value> withDynamicFrameAndUserGestureCallback(const v8::Arguments& args)
376 {
377     INC_STATS("DOM.TestObj.withDynamicFrameAndUserGesture");
378     TestObj* imp = V8TestObj::toNative(args.Holder());
379     int intArg = toInt32(args[0]);
380     Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext();
381     if (!enteredFrame)
382         return v8::Undefined();
383     imp->withDynamicFrameAndUserGesture(enteredFrame, intArg, processingUserGesture());
384     return v8::Handle<v8::Value>();
385 }
386
387 static v8::Handle<v8::Value> withDynamicFrameAndUserGestureASADCallback(const v8::Arguments& args)
388 {
389     INC_STATS("DOM.TestObj.withDynamicFrameAndUserGestureASAD");
390     TestObj* imp = V8TestObj::toNative(args.Holder());
391     int intArg = toInt32(args[0]);
392     if (args.Length() <= 1) {
393         Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext();
394         if (!enteredFrame)
395             return v8::Undefined();
396         imp->withDynamicFrameAndUserGestureASAD(enteredFrame, intArg, processingUserGesture());
397         return v8::Handle<v8::Value>();
398     }
399     int optionalArg = toInt32(args[1]);
400     Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext();
401     if (!enteredFrame)
402         return v8::Undefined();
403     imp->withDynamicFrameAndUserGestureASAD(enteredFrame, intArg, optionalArg, processingUserGesture());
404     return v8::Handle<v8::Value>();
405 }
406
407 static v8::Handle<v8::Value> withScriptStateVoidCallback(const v8::Arguments& args)
408 {
409     INC_STATS("DOM.TestObj.withScriptStateVoid");
410     TestObj* imp = V8TestObj::toNative(args.Holder());
411     EmptyScriptState state;
412     imp->withScriptStateVoid(&state);
413     if (state.hadException())
414         return throwError(state.exception());
415     return v8::Handle<v8::Value>();
416 }
417
418 static v8::Handle<v8::Value> withScriptStateObjCallback(const v8::Arguments& args)
419 {
420     INC_STATS("DOM.TestObj.withScriptStateObj");
421     TestObj* imp = V8TestObj::toNative(args.Holder());
422     EmptyScriptState state;
423     RefPtr<TestObj> result = imp->withScriptStateObj(&state);
424     if (state.hadException())
425         return throwError(state.exception());
426     return toV8(result.release());
427 }
428
429 static v8::Handle<v8::Value> withScriptStateVoidExceptionCallback(const v8::Arguments& args)
430 {
431     INC_STATS("DOM.TestObj.withScriptStateVoidException");
432     TestObj* imp = V8TestObj::toNative(args.Holder());
433     ExceptionCode ec = 0;
434     {
435     EmptyScriptState state;
436     imp->withScriptStateVoidException(&state, ec);
437     if (UNLIKELY(ec))
438         goto fail;
439     if (state.hadException())
440         return throwError(state.exception());
441     return v8::Handle<v8::Value>();
442     }
443     fail:
444     V8Proxy::setDOMException(ec);
445     return v8::Handle<v8::Value>();
446 }
447
448 static v8::Handle<v8::Value> withScriptStateObjExceptionCallback(const v8::Arguments& args)
449 {
450     INC_STATS("DOM.TestObj.withScriptStateObjException");
451     TestObj* imp = V8TestObj::toNative(args.Holder());
452     ExceptionCode ec = 0;
453     {
454     EmptyScriptState state;
455     RefPtr<TestObj> result = imp->withScriptStateObjException(&state, ec);
456     if (UNLIKELY(ec))
457         goto fail;
458     if (state.hadException())
459         return throwError(state.exception());
460     return toV8(result.release());
461     }
462     fail:
463     V8Proxy::setDOMException(ec);
464     return v8::Handle<v8::Value>();
465 }
466
467 static v8::Handle<v8::Value> methodWithOptionalArgCallback(const v8::Arguments& args)
468 {
469     INC_STATS("DOM.TestObj.methodWithOptionalArg");
470     TestObj* imp = V8TestObj::toNative(args.Holder());
471     if (args.Length() <= 0) {
472         imp->methodWithOptionalArg();
473         return v8::Handle<v8::Value>();
474     }
475     int opt = toInt32(args[0]);
476     imp->methodWithOptionalArg(opt);
477     return v8::Handle<v8::Value>();
478 }
479
480 static v8::Handle<v8::Value> methodWithNonOptionalArgAndOptionalArgCallback(const v8::Arguments& args)
481 {
482     INC_STATS("DOM.TestObj.methodWithNonOptionalArgAndOptionalArg");
483     TestObj* imp = V8TestObj::toNative(args.Holder());
484     int nonOpt = toInt32(args[0]);
485     if (args.Length() <= 1) {
486         imp->methodWithNonOptionalArgAndOptionalArg(nonOpt);
487         return v8::Handle<v8::Value>();
488     }
489     int opt = toInt32(args[1]);
490     imp->methodWithNonOptionalArgAndOptionalArg(nonOpt, opt);
491     return v8::Handle<v8::Value>();
492 }
493
494 static v8::Handle<v8::Value> methodWithNonOptionalArgAndTwoOptionalArgsCallback(const v8::Arguments& args)
495 {
496     INC_STATS("DOM.TestObj.methodWithNonOptionalArgAndTwoOptionalArgs");
497     TestObj* imp = V8TestObj::toNative(args.Holder());
498     int nonOpt = toInt32(args[0]);
499     if (args.Length() <= 1) {
500         imp->methodWithNonOptionalArgAndTwoOptionalArgs(nonOpt);
501         return v8::Handle<v8::Value>();
502     }
503     int opt1 = toInt32(args[1]);
504     int opt2 = toInt32(args[2]);
505     imp->methodWithNonOptionalArgAndTwoOptionalArgs(nonOpt, opt1, opt2);
506     return v8::Handle<v8::Value>();
507 }
508
509 static v8::Handle<v8::Value> overloadedMethod1Callback(const v8::Arguments& args)
510 {
511     INC_STATS("DOM.TestObj.overloadedMethod1");
512     TestObj* imp = V8TestObj::toNative(args.Holder());
513     TestObj* objArg = V8TestObj::HasInstance(args[0]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0;
514     V8Parameter<> strArg = args[1];
515     imp->overloadedMethod(objArg, strArg);
516     return v8::Handle<v8::Value>();
517 }
518
519 static v8::Handle<v8::Value> overloadedMethod2Callback(const v8::Arguments& args)
520 {
521     INC_STATS("DOM.TestObj.overloadedMethod2");
522     TestObj* imp = V8TestObj::toNative(args.Holder());
523     TestObj* objArg = V8TestObj::HasInstance(args[0]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0;
524     if (args.Length() <= 1) {
525         imp->overloadedMethod(objArg);
526         return v8::Handle<v8::Value>();
527     }
528     int intArg = toInt32(args[1]);
529     imp->overloadedMethod(objArg, intArg);
530     return v8::Handle<v8::Value>();
531 }
532
533 static v8::Handle<v8::Value> overloadedMethod3Callback(const v8::Arguments& args)
534 {
535     INC_STATS("DOM.TestObj.overloadedMethod3");
536     TestObj* imp = V8TestObj::toNative(args.Holder());
537     V8Parameter<> strArg = args[0];
538     imp->overloadedMethod(strArg);
539     return v8::Handle<v8::Value>();
540 }
541
542 static v8::Handle<v8::Value> overloadedMethod4Callback(const v8::Arguments& args)
543 {
544     INC_STATS("DOM.TestObj.overloadedMethod4");
545     TestObj* imp = V8TestObj::toNative(args.Holder());
546     int intArg = toInt32(args[0]);
547     imp->overloadedMethod(intArg);
548     return v8::Handle<v8::Value>();
549 }
550
551 static v8::Handle<v8::Value> overloadedMethodCallback(const v8::Arguments& args)
552 {
553     INC_STATS("DOM.TestObj.overloadedMethod");
554     if ((args.Length() == 2 && (args[0]->IsNull() || V8TestObj::HasInstance(args[0])) && (args[1]->IsNull() || args[1]->IsUndefined() || args[1]->IsString() || args[1]->IsObject())))
555         return overloadedMethod1Callback(args);
556     if ((args.Length() == 1 && (args[0]->IsNull() || V8TestObj::HasInstance(args[0]))) || (args.Length() == 2 && (args[0]->IsNull() || V8TestObj::HasInstance(args[0]))))
557         return overloadedMethod2Callback(args);
558     if ((args.Length() == 1 && (args[0]->IsNull() || args[0]->IsUndefined() || args[0]->IsString() || args[0]->IsObject())))
559         return overloadedMethod3Callback(args);
560     if (args.Length() == 1)
561         return overloadedMethod4Callback(args);
562     V8Proxy::setDOMException(SYNTAX_ERR);
563     return notHandledByInterceptor();
564 }
565
566 } // namespace TestObjInternal
567
568 static const BatchedAttribute TestObjAttrs[] = {
569     // Attribute 'readOnlyIntAttr' (Type: 'readonly attribute' ExtAttr: '')
570     {"readOnlyIntAttr", TestObjInternal::readOnlyIntAttrAttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
571     // Attribute 'readOnlyStringAttr' (Type: 'readonly attribute' ExtAttr: '')
572     {"readOnlyStringAttr", TestObjInternal::readOnlyStringAttrAttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
573     // Attribute 'readOnlyTestObjAttr' (Type: 'readonly attribute' ExtAttr: '')
574     {"readOnlyTestObjAttr", TestObjInternal::readOnlyTestObjAttrAttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
575     // Attribute 'intAttr' (Type: 'attribute' ExtAttr: '')
576     {"intAttr", TestObjInternal::intAttrAttrGetter, TestObjInternal::intAttrAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
577     // Attribute 'longLongAttr' (Type: 'attribute' ExtAttr: '')
578     {"longLongAttr", TestObjInternal::longLongAttrAttrGetter, TestObjInternal::longLongAttrAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
579     // Attribute 'unsignedLongLongAttr' (Type: 'attribute' ExtAttr: '')
580     {"unsignedLongLongAttr", TestObjInternal::unsignedLongLongAttrAttrGetter, TestObjInternal::unsignedLongLongAttrAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
581     // Attribute 'stringAttr' (Type: 'attribute' ExtAttr: '')
582     {"stringAttr", TestObjInternal::stringAttrAttrGetter, TestObjInternal::stringAttrAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
583     // Attribute 'testObjAttr' (Type: 'attribute' ExtAttr: '')
584     {"testObjAttr", TestObjInternal::testObjAttrAttrGetter, TestObjInternal::testObjAttrAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
585     // Attribute 'attrWithException' (Type: 'attribute' ExtAttr: '')
586     {"attrWithException", TestObjInternal::attrWithExceptionAttrGetter, TestObjInternal::attrWithExceptionAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
587     // Attribute 'attrWithSetterException' (Type: 'attribute' ExtAttr: '')
588     {"attrWithSetterException", TestObjInternal::attrWithSetterExceptionAttrGetter, TestObjInternal::attrWithSetterExceptionAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
589     // Attribute 'attrWithGetterException' (Type: 'attribute' ExtAttr: '')
590     {"attrWithGetterException", TestObjInternal::attrWithGetterExceptionAttrGetter, TestObjInternal::attrWithGetterExceptionAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
591     // Attribute 'customAttr' (Type: 'attribute' ExtAttr: 'Custom')
592     {"customAttr", V8TestObj::customAttrAccessorGetter, V8TestObj::customAttrAccessorSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
593     // Attribute 'scriptStringAttr' (Type: 'readonly attribute' ExtAttr: 'ConvertScriptString')
594     {"scriptStringAttr", TestObjInternal::scriptStringAttrAttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
595 };
596 static const BatchedCallback TestObjCallbacks[] = {
597     {"voidMethod", TestObjInternal::voidMethodCallback},
598     {"intMethod", TestObjInternal::intMethodCallback},
599     {"objMethod", TestObjInternal::objMethodCallback},
600     {"serializedValue", TestObjInternal::serializedValueCallback},
601     {"methodWithException", TestObjInternal::methodWithExceptionCallback},
602     {"customMethod", V8TestObj::customMethodCallback},
603     {"customMethodWithArgs", V8TestObj::customMethodWithArgsCallback},
604     {"addEventListener", TestObjInternal::addEventListenerCallback},
605     {"removeEventListener", TestObjInternal::removeEventListenerCallback},
606     {"withDynamicFrame", TestObjInternal::withDynamicFrameCallback},
607     {"withDynamicFrameAndArg", TestObjInternal::withDynamicFrameAndArgCallback},
608     {"withDynamicFrameAndOptionalArg", TestObjInternal::withDynamicFrameAndOptionalArgCallback},
609     {"withDynamicFrameAndUserGesture", TestObjInternal::withDynamicFrameAndUserGestureCallback},
610     {"withDynamicFrameAndUserGestureASAD", TestObjInternal::withDynamicFrameAndUserGestureASADCallback},
611     {"withScriptStateVoid", TestObjInternal::withScriptStateVoidCallback},
612     {"withScriptStateObj", TestObjInternal::withScriptStateObjCallback},
613     {"withScriptStateVoidException", TestObjInternal::withScriptStateVoidExceptionCallback},
614     {"withScriptStateObjException", TestObjInternal::withScriptStateObjExceptionCallback},
615     {"methodWithOptionalArg", TestObjInternal::methodWithOptionalArgCallback},
616     {"methodWithNonOptionalArgAndOptionalArg", TestObjInternal::methodWithNonOptionalArgAndOptionalArgCallback},
617     {"methodWithNonOptionalArgAndTwoOptionalArgs", TestObjInternal::methodWithNonOptionalArgAndTwoOptionalArgsCallback},
618     {"overloadedMethod", TestObjInternal::overloadedMethodCallback},
619 };
620 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestObjTemplate(v8::Persistent<v8::FunctionTemplate> desc)
621 {
622     v8::Local<v8::Signature> defaultSignature = configureTemplate(desc, "TestObj", v8::Persistent<v8::FunctionTemplate>(), V8TestObj::internalFieldCount,
623         TestObjAttrs, sizeof(TestObjAttrs) / sizeof(*TestObjAttrs),
624         TestObjCallbacks, sizeof(TestObjCallbacks) / sizeof(*TestObjCallbacks));
625     v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
626     v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate();
627     
628
629     // Custom Signature 'voidMethodWithArgs'
630     const int voidMethodWithArgsArgc = 3;
631     v8::Handle<v8::FunctionTemplate> voidMethodWithArgsArgv[voidMethodWithArgsArgc] = { v8::Handle<v8::FunctionTemplate>(), v8::Handle<v8::FunctionTemplate>(), V8TestObj::GetRawTemplate() };
632     v8::Handle<v8::Signature> voidMethodWithArgsSignature = v8::Signature::New(desc, voidMethodWithArgsArgc, voidMethodWithArgsArgv);
633     proto->Set(v8::String::New("voidMethodWithArgs"), v8::FunctionTemplate::New(TestObjInternal::voidMethodWithArgsCallback, v8::Handle<v8::Value>(), voidMethodWithArgsSignature));
634
635     // Custom Signature 'intMethodWithArgs'
636     const int intMethodWithArgsArgc = 3;
637     v8::Handle<v8::FunctionTemplate> intMethodWithArgsArgv[intMethodWithArgsArgc] = { v8::Handle<v8::FunctionTemplate>(), v8::Handle<v8::FunctionTemplate>(), V8TestObj::GetRawTemplate() };
638     v8::Handle<v8::Signature> intMethodWithArgsSignature = v8::Signature::New(desc, intMethodWithArgsArgc, intMethodWithArgsArgv);
639     proto->Set(v8::String::New("intMethodWithArgs"), v8::FunctionTemplate::New(TestObjInternal::intMethodWithArgsCallback, v8::Handle<v8::Value>(), intMethodWithArgsSignature));
640
641     // Custom Signature 'objMethodWithArgs'
642     const int objMethodWithArgsArgc = 3;
643     v8::Handle<v8::FunctionTemplate> objMethodWithArgsArgv[objMethodWithArgsArgc] = { v8::Handle<v8::FunctionTemplate>(), v8::Handle<v8::FunctionTemplate>(), V8TestObj::GetRawTemplate() };
644     v8::Handle<v8::Signature> objMethodWithArgsSignature = v8::Signature::New(desc, objMethodWithArgsArgc, objMethodWithArgsArgv);
645     proto->Set(v8::String::New("objMethodWithArgs"), v8::FunctionTemplate::New(TestObjInternal::objMethodWithArgsCallback, v8::Handle<v8::Value>(), objMethodWithArgsSignature));
646
647     // Custom Signature 'customArgsAndException'
648     const int customArgsAndExceptionArgc = 1;
649     v8::Handle<v8::FunctionTemplate> customArgsAndExceptionArgv[customArgsAndExceptionArgc] = { V8log::GetRawTemplate() };
650     v8::Handle<v8::Signature> customArgsAndExceptionSignature = v8::Signature::New(desc, customArgsAndExceptionArgc, customArgsAndExceptionArgv);
651     proto->Set(v8::String::New("customArgsAndException"), v8::FunctionTemplate::New(TestObjInternal::customArgsAndExceptionCallback, v8::Handle<v8::Value>(), customArgsAndExceptionSignature));
652
653     // Custom toString template
654     desc->Set(getToStringName(), getToStringTemplate());
655     return desc;
656 }
657
658 v8::Persistent<v8::FunctionTemplate> V8TestObj::GetRawTemplate()
659 {
660     static v8::Persistent<v8::FunctionTemplate> V8TestObjRawCache = createRawTemplate();
661     return V8TestObjRawCache;
662 }
663
664 v8::Persistent<v8::FunctionTemplate> V8TestObj::GetTemplate()
665 {
666     static v8::Persistent<v8::FunctionTemplate> V8TestObjCache = ConfigureV8TestObjTemplate(GetRawTemplate());
667     return V8TestObjCache;
668 }
669
670 TestObj* V8TestObj::toNative(v8::Handle<v8::Object> object)
671 {
672     return reinterpret_cast<TestObj*>(object->GetPointerFromInternalField(v8DOMWrapperObjectIndex));
673 }
674
675 bool V8TestObj::HasInstance(v8::Handle<v8::Value> value)
676 {
677     return GetRawTemplate()->HasInstance(value);
678 }
679
680
681 v8::Handle<v8::Object> V8TestObj::wrap(TestObj* impl)
682 {
683     v8::Handle<v8::Object> wrapper;
684     V8Proxy* proxy = 0;
685         wrapper = getDOMObjectMap().get(impl);
686         if (!wrapper.IsEmpty())
687             return wrapper;
688     wrapper = V8DOMWrapper::instantiateV8Object(proxy, &info, impl);
689     if (wrapper.IsEmpty())
690         return wrapper;
691
692     impl->ref();
693     getDOMObjectMap().set(impl, v8::Persistent<v8::Object>::New(wrapper));
694     return wrapper;
695 }
696
697 v8::Handle<v8::Value> toV8(PassRefPtr<TestObj > impl)
698 {
699     return toV8(impl.get());
700 }
701
702 v8::Handle<v8::Value> toV8(TestObj* impl)
703 {
704     if (!impl)
705         return v8::Null();
706     return V8TestObj::wrap(impl);
707 }
708
709 void V8TestObj::derefObject(void* object)
710 {
711     static_cast<TestObj*>(object)->deref();
712 }
713
714 } // namespace WebCore