93d096052b98c2b34f5f43caa364fbcc2b5a16bc
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / V8 / V8TestEventTarget.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 "V8TestEventTarget.h"
23
24 #include "BindingState.h"
25 #include "ContextFeatures.h"
26 #include "ExceptionCode.h"
27 #include "Frame.h"
28 #include "RuntimeEnabledFeatures.h"
29 #include "V8Binding.h"
30 #include "V8Collection.h"
31 #include "V8DOMWrapper.h"
32 #include "V8Event.h"
33 #include "V8EventListenerList.h"
34 #include "V8Node.h"
35 #include <wtf/UnusedParam.h>
36
37 namespace WebCore {
38
39 WrapperTypeInfo V8TestEventTarget::info = { V8TestEventTarget::GetTemplate, V8TestEventTarget::derefObject, 0, 0, V8TestEventTarget::installPerContextPrototypeProperties, 0, WrapperTypeObjectPrototype };
40
41 namespace TestEventTargetV8Internal {
42
43 template <typename T> void V8_USE(T) { }
44
45 static v8::Handle<v8::Value> itemCallback(const v8::Arguments& args)
46 {
47     if (args.Length() < 1)
48         return throwNotEnoughArgumentsError(args.GetIsolate());
49     TestEventTarget* imp = V8TestEventTarget::toNative(args.Holder());
50     ExceptionCode ec = 0;
51     {
52     V8TRYCATCH(int, index, toUInt32(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined)));
53     if (UNLIKELY(index < 0)) {
54         ec = INDEX_SIZE_ERR;
55         goto fail;
56     }
57     return toV8(imp->item(index), args.Holder(), args.GetIsolate());
58     }
59     fail:
60     return setDOMException(ec, args.GetIsolate());
61 }
62
63 static v8::Handle<v8::Value> addEventListenerCallback(const v8::Arguments& args)
64 {
65     RefPtr<EventListener> listener = V8EventListenerList::getEventListener(args[1], false, ListenerFindOrCreate);
66     if (listener) {
67         V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<WithNullCheck>, stringResource, args[0]);
68         V8TestEventTarget::toNative(args.Holder())->addEventListener(stringResource, listener, args[2]->BooleanValue());
69         createHiddenDependency(args.Holder(), args[1], V8TestEventTarget::eventListenerCacheIndex);
70     }
71     return v8Undefined();
72 }
73
74 static v8::Handle<v8::Value> removeEventListenerCallback(const v8::Arguments& args)
75 {
76     RefPtr<EventListener> listener = V8EventListenerList::getEventListener(args[1], false, ListenerFindOnly);
77     if (listener) {
78         V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<WithNullCheck>, stringResource, args[0]);
79         V8TestEventTarget::toNative(args.Holder())->removeEventListener(stringResource, listener.get(), args[2]->BooleanValue());
80         removeHiddenDependency(args.Holder(), args[1], V8TestEventTarget::eventListenerCacheIndex);
81     }
82     return v8Undefined();
83 }
84
85 static v8::Handle<v8::Value> dispatchEventCallback(const v8::Arguments& args)
86 {
87     if (args.Length() < 1)
88         return throwNotEnoughArgumentsError(args.GetIsolate());
89     TestEventTarget* imp = V8TestEventTarget::toNative(args.Holder());
90     ExceptionCode ec = 0;
91     {
92     V8TRYCATCH(Event*, evt, V8Event::HasInstance(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined)) ? V8Event::toNative(v8::Handle<v8::Object>::Cast(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined))) : 0);
93     bool result = imp->dispatchEvent(evt, ec);
94     if (UNLIKELY(ec))
95         goto fail;
96     return v8Boolean(result, args.GetIsolate());
97     }
98     fail:
99     return setDOMException(ec, args.GetIsolate());
100 }
101
102 } // namespace TestEventTargetV8Internal
103
104 static const V8DOMConfiguration::BatchedCallback V8TestEventTargetCallbacks[] = {
105     {"item", TestEventTargetV8Internal::itemCallback},
106     {"addEventListener", TestEventTargetV8Internal::addEventListenerCallback},
107     {"removeEventListener", TestEventTargetV8Internal::removeEventListenerCallback},
108 };
109
110 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestEventTargetTemplate(v8::Persistent<v8::FunctionTemplate> desc)
111 {
112     desc->ReadOnlyPrototype();
113
114     v8::Local<v8::Signature> defaultSignature;
115     defaultSignature = V8DOMConfiguration::configureTemplate(desc, "TestEventTarget", v8::Persistent<v8::FunctionTemplate>(), V8TestEventTarget::internalFieldCount,
116         0, 0,
117         V8TestEventTargetCallbacks, WTF_ARRAY_LENGTH(V8TestEventTargetCallbacks));
118     UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
119     v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
120     v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate();
121     UNUSED_PARAM(instance); // In some cases, it will not be used.
122     UNUSED_PARAM(proto); // In some cases, it will not be used.
123     
124     setCollectionIndexedGetter<TestEventTarget, Node>(desc);
125     desc->InstanceTemplate()->SetNamedPropertyHandler(V8TestEventTarget::namedPropertyGetter, 0, 0, 0, 0);
126     desc->InstanceTemplate()->MarkAsUndetectable();
127
128     // Custom Signature 'dispatchEvent'
129     const int dispatchEventArgc = 1;
130     v8::Handle<v8::FunctionTemplate> dispatchEventArgv[dispatchEventArgc] = { V8Event::GetRawTemplate() };
131     v8::Handle<v8::Signature> dispatchEventSignature = v8::Signature::New(desc, dispatchEventArgc, dispatchEventArgv);
132     proto->Set(v8::String::NewSymbol("dispatchEvent"), v8::FunctionTemplate::New(TestEventTargetV8Internal::dispatchEventCallback, v8Undefined(), dispatchEventSignature));
133
134     // Custom toString template
135     desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
136     return desc;
137 }
138
139 v8::Persistent<v8::FunctionTemplate> V8TestEventTarget::GetRawTemplate(v8::Isolate* isolate)
140 {
141     if (!isolate)
142         isolate = v8::Isolate::GetCurrent();
143     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
144     V8PerIsolateData::TemplateMap::iterator result = data->rawTemplateMap().find(&info);
145     if (result != data->rawTemplateMap().end())
146         return result->value;
147
148     v8::HandleScope handleScope;
149     v8::Persistent<v8::FunctionTemplate> templ = createRawTemplate();
150     data->rawTemplateMap().add(&info, templ);
151     return templ;
152 }
153
154 v8::Persistent<v8::FunctionTemplate> V8TestEventTarget::GetTemplate(v8::Isolate* isolate)
155 {
156     if (!isolate)
157         isolate = v8::Isolate::GetCurrent();
158     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
159     V8PerIsolateData::TemplateMap::iterator result = data->templateMap().find(&info);
160     if (result != data->templateMap().end())
161         return result->value;
162
163     v8::HandleScope handleScope;
164     v8::Persistent<v8::FunctionTemplate> templ =
165         ConfigureV8TestEventTargetTemplate(GetRawTemplate());
166     data->templateMap().add(&info, templ);
167     return templ;
168 }
169
170 bool V8TestEventTarget::HasInstance(v8::Handle<v8::Value> value)
171 {
172     return GetRawTemplate()->HasInstance(value);
173 }
174
175
176 v8::Handle<v8::Object> V8TestEventTarget::createWrapper(PassRefPtr<TestEventTarget> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
177 {
178     ASSERT(impl.get());
179     ASSERT(DOMDataStore::getWrapper(impl.get(), isolate).IsEmpty());
180
181     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &info, impl.get());
182     if (UNLIKELY(wrapper.IsEmpty()))
183         return wrapper;
184
185     installPerContextProperties(wrapper, impl.get());
186     v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate);
187     if (!hasDependentLifetime)
188         wrapperHandle.MarkIndependent();
189     return wrapper;
190 }
191
192 void V8TestEventTarget::derefObject(void* object)
193 {
194     static_cast<TestEventTarget*>(object)->deref();
195 }
196
197 } // namespace WebCore