c1cec44443b06a08d94922a369cbf95147ad0bb5
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / tests / results / V8TestEventTarget.cpp
1 /*
2  * Copyright (C) 2013 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 // This file has been auto-generated by code_generator_v8.pm. DO NOT MODIFY!
32
33 #include "config.h"
34 #include "V8TestEventTarget.h"
35
36 #include "RuntimeEnabledFeatures.h"
37 #include "V8Node.h"
38 #include "bindings/v8/ExceptionState.h"
39 #include "bindings/v8/V8DOMConfiguration.h"
40 #include "bindings/v8/V8ObjectConstructor.h"
41 #include "core/dom/ContextFeatures.h"
42 #include "core/dom/Document.h"
43 #include "platform/TraceEvent.h"
44 #include "wtf/GetPtr.h"
45 #include "wtf/RefPtr.h"
46
47 namespace WebCore {
48
49 static void initializeScriptWrappableForInterface(TestEventTarget* object)
50 {
51     if (ScriptWrappable::wrapperCanBeStoredInObject(object))
52         ScriptWrappable::setTypeInfoInObject(object, &V8TestEventTarget::wrapperTypeInfo);
53     else
54         ASSERT_NOT_REACHED();
55 }
56
57 } // namespace WebCore
58
59 // In ScriptWrappable::init, the use of a local function declaration has an issue on Windows:
60 // the local declaration does not pick up the surrounding namespace. Therefore, we provide this function
61 // in the global namespace.
62 // (More info on the MSVC bug here: http://connect.microsoft.com/VisualStudio/feedback/details/664619/the-namespace-of-local-function-declarations-in-c)
63 void webCoreInitializeScriptWrappableForInterface(WebCore::TestEventTarget* object)
64 {
65     WebCore::initializeScriptWrappableForInterface(object);
66 }
67
68 namespace WebCore {
69 const WrapperTypeInfo V8TestEventTarget::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestEventTarget::domTemplate, V8TestEventTarget::derefObject, 0, V8TestEventTarget::toEventTarget, 0, V8TestEventTarget::installPerContextEnabledMethods, &V8EventTarget::wrapperTypeInfo, WrapperTypeObjectPrototype };
70
71 namespace TestEventTargetV8Internal {
72
73 template <typename T> void V8_USE(T) { }
74
75 static void itemMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
76 {
77     ExceptionState exceptionState(ExceptionState::ExecutionContext, "item", "TestEventTarget", info.Holder(), info.GetIsolate());
78     if (UNLIKELY(info.Length() < 1)) {
79         exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, info.Length()));
80         exceptionState.throwIfNeeded();
81         return;
82     }
83     TestEventTarget* imp = V8TestEventTarget::toNative(info.Holder());
84     V8TRYCATCH_EXCEPTION_VOID(unsigned, index, toUInt32(info[0], exceptionState), exceptionState);
85     v8SetReturnValue(info, imp->item(index));
86 }
87
88 static void itemMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
89 {
90     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
91     TestEventTargetV8Internal::itemMethod(info);
92     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
93 }
94
95 static void namedItemMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
96 {
97     if (UNLIKELY(info.Length() < 1)) {
98         throwTypeError(ExceptionMessages::failedToExecute("namedItem", "TestEventTarget", ExceptionMessages::notEnoughArguments(1, info.Length())), info.GetIsolate());
99         return;
100     }
101     TestEventTarget* imp = V8TestEventTarget::toNative(info.Holder());
102     V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, name, info[0]);
103     v8SetReturnValue(info, imp->namedItem(name));
104 }
105
106 static void namedItemMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
107 {
108     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
109     TestEventTargetV8Internal::namedItemMethod(info);
110     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
111 }
112
113 static void indexedPropertyGetter(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info)
114 {
115     TestEventTarget* collection = V8TestEventTarget::toNative(info.Holder());
116     RefPtr<Node> element = collection->item(index);
117     if (!element)
118         return;
119     v8SetReturnValueFast(info, element.release(), collection);
120 }
121
122 static void indexedPropertyGetterCallback(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info)
123 {
124     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMIndexedProperty");
125     TestEventTargetV8Internal::indexedPropertyGetter(index, info);
126     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
127 }
128
129 static void indexedPropertySetter(uint32_t index, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<v8::Value>& info)
130 {
131     TestEventTarget* collection = V8TestEventTarget::toNative(info.Holder());
132     V8TRYCATCH_VOID(Node*, propertyValue, V8Node::hasInstance(jsValue, info.GetIsolate()) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(jsValue)) : 0);
133     bool result = collection->anonymousIndexedSetter(index, propertyValue);
134     if (!result)
135         return;
136     v8SetReturnValue(info, jsValue);
137 }
138
139 static void indexedPropertySetterCallback(uint32_t index, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<v8::Value>& info)
140 {
141     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMIndexedProperty");
142     TestEventTargetV8Internal::indexedPropertySetter(index, jsValue, info);
143     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
144 }
145
146 static void indexedPropertyDeleter(unsigned index, const v8::PropertyCallbackInfo<v8::Boolean>& info)
147 {
148     TestEventTarget* collection = V8TestEventTarget::toNative(info.Holder());
149     ExceptionState exceptionState(info.Holder(), info.GetIsolate());
150     DeleteResult result = collection->anonymousIndexedDeleter(index, exceptionState);
151     if (exceptionState.throwIfNeeded())
152         return;
153     if (result != DeleteUnknownProperty)
154         return v8SetReturnValueBool(info, result == DeleteSuccess);
155 }
156
157 static void indexedPropertyDeleterCallback(uint32_t index, const v8::PropertyCallbackInfo<v8::Boolean>& info)
158 {
159     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMIndexedProperty");
160     TestEventTargetV8Internal::indexedPropertyDeleter(index, info);
161     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
162 }
163
164 static void namedPropertyGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
165 {
166     if (!info.Holder()->GetRealNamedPropertyInPrototypeChain(name).IsEmpty())
167         return;
168     if (info.Holder()->HasRealNamedCallbackProperty(name))
169         return;
170     if (info.Holder()->HasRealNamedProperty(name))
171         return;
172
173     TestEventTarget* collection = V8TestEventTarget::toNative(info.Holder());
174     AtomicString propertyName = toCoreAtomicString(name);
175     RefPtr<Node> element = collection->namedItem(propertyName);
176     if (!element)
177         return;
178     v8SetReturnValueFast(info, element.release(), collection);
179 }
180
181 static void namedPropertyGetterCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
182 {
183     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
184     TestEventTargetV8Internal::namedPropertyGetter(name, info);
185     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
186 }
187
188 static void namedPropertySetter(v8::Local<v8::String> name, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<v8::Value>& info)
189 {
190     if (!info.Holder()->GetRealNamedPropertyInPrototypeChain(name).IsEmpty())
191         return;
192     if (info.Holder()->HasRealNamedCallbackProperty(name))
193         return;
194     if (info.Holder()->HasRealNamedProperty(name))
195         return;
196     TestEventTarget* collection = V8TestEventTarget::toNative(info.Holder());
197     V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, propertyName, name);
198     V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, propertyValue, jsValue);
199     bool result;
200     if (jsValue->IsUndefined())
201         result = collection->anonymousNamedSetterUndefined(propertyName);
202     else
203         result = collection->anonymousNamedSetter(propertyName, propertyValue);
204     if (!result)
205         return;
206     v8SetReturnValue(info, jsValue);
207 }
208
209 static void namedPropertySetterCallback(v8::Local<v8::String> name, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<v8::Value>& info)
210 {
211     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
212     TestEventTargetV8Internal::namedPropertySetter(name, jsValue, info);
213     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
214 }
215
216 static void namedPropertyDeleter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Boolean>& info)
217 {
218     TestEventTarget* collection = V8TestEventTarget::toNative(info.Holder());
219     AtomicString propertyName = toCoreAtomicString(name);
220     DeleteResult result = collection->anonymousNamedDeleter(propertyName);
221     if (result != DeleteUnknownProperty)
222         return v8SetReturnValueBool(info, result == DeleteSuccess);
223 }
224
225 static void namedPropertyDeleterCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Boolean>& info)
226 {
227     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
228     TestEventTargetV8Internal::namedPropertyDeleter(name, info);
229     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
230 }
231
232 static void namedPropertyEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info)
233 {
234     ExceptionState exceptionState(info.Holder(), info.GetIsolate());
235     TestEventTarget* collection = V8TestEventTarget::toNative(info.Holder());
236     Vector<String> names;
237     collection->namedPropertyEnumerator(names, exceptionState);
238     if (exceptionState.throwIfNeeded())
239         return;
240     v8::Handle<v8::Array> v8names = v8::Array::New(info.GetIsolate(), names.size());
241     for (size_t i = 0; i < names.size(); ++i)
242         v8names->Set(v8::Integer::New(info.GetIsolate(), i), v8String(info.GetIsolate(), names[i]));
243     v8SetReturnValue(info, v8names);
244 }
245
246 static void namedPropertyQuery(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Integer>& info)
247 {
248     TestEventTarget* collection = V8TestEventTarget::toNative(info.Holder());
249     AtomicString propertyName = toCoreAtomicString(name);
250     ExceptionState exceptionState(info.Holder(), info.GetIsolate());
251     bool result = collection->namedPropertyQuery(propertyName, exceptionState);
252     if (exceptionState.throwIfNeeded())
253         return;
254     if (!result)
255         return;
256     v8SetReturnValueInt(info, v8::None);
257 }
258
259 static void namedPropertyEnumeratorCallback(const v8::PropertyCallbackInfo<v8::Array>& info)
260 {
261     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
262     TestEventTargetV8Internal::namedPropertyEnumerator(info);
263     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
264 }
265
266 static void namedPropertyQueryCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Integer>& info)
267 {
268     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
269     TestEventTargetV8Internal::namedPropertyQuery(name, info);
270     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
271 }
272
273 } // namespace TestEventTargetV8Internal
274
275 static const V8DOMConfiguration::MethodConfiguration V8TestEventTargetMethods[] = {
276     {"item", TestEventTargetV8Internal::itemMethodCallback, 0, 1},
277     {"namedItem", TestEventTargetV8Internal::namedItemMethodCallback, 0, 1},
278 };
279
280 static void configureV8TestEventTargetTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate, WrapperWorldType currentWorldType)
281 {
282     functionTemplate->ReadOnlyPrototype();
283
284     v8::Local<v8::Signature> defaultSignature;
285     defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestEventTarget", V8EventTarget::domTemplate(isolate, currentWorldType), V8TestEventTarget::internalFieldCount,
286         0, 0,
287         0, 0,
288         V8TestEventTargetMethods, WTF_ARRAY_LENGTH(V8TestEventTargetMethods),
289         isolate, currentWorldType);
290     v8::Local<v8::ObjectTemplate> ALLOW_UNUSED instanceTemplate = functionTemplate->InstanceTemplate();
291     v8::Local<v8::ObjectTemplate> ALLOW_UNUSED prototypeTemplate = functionTemplate->PrototypeTemplate();
292     functionTemplate->InstanceTemplate()->SetIndexedPropertyHandler(TestEventTargetV8Internal::indexedPropertyGetterCallback, TestEventTargetV8Internal::indexedPropertySetterCallback, 0, TestEventTargetV8Internal::indexedPropertyDeleterCallback, indexedPropertyEnumerator<TestEventTarget>);
293     functionTemplate->InstanceTemplate()->SetNamedPropertyHandler(TestEventTargetV8Internal::namedPropertyGetterCallback, TestEventTargetV8Internal::namedPropertySetterCallback, TestEventTargetV8Internal::namedPropertyQueryCallback, TestEventTargetV8Internal::namedPropertyDeleterCallback, TestEventTargetV8Internal::namedPropertyEnumeratorCallback);
294
295     // Custom toString template
296     functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::current()->toStringTemplate());
297 }
298
299 v8::Handle<v8::FunctionTemplate> V8TestEventTarget::domTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
300 {
301     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
302     V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWorldType).find(&wrapperTypeInfo);
303     if (result != data->templateMap(currentWorldType).end())
304         return result->value.newLocal(isolate);
305
306     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
307     v8::EscapableHandleScope handleScope(isolate);
308     v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidConstructorMode);
309     configureV8TestEventTargetTemplate(templ, isolate, currentWorldType);
310     data->templateMap(currentWorldType).add(&wrapperTypeInfo, UnsafePersistent<v8::FunctionTemplate>(isolate, templ));
311     return handleScope.Escape(templ);
312 }
313
314 bool V8TestEventTarget::hasInstance(v8::Handle<v8::Value> jsValue, v8::Isolate* isolate)
315 {
316     return V8PerIsolateData::from(isolate)->hasInstanceInMainWorld(&wrapperTypeInfo, jsValue)
317         || V8PerIsolateData::from(isolate)->hasInstanceInNonMainWorld(&wrapperTypeInfo, jsValue);
318 }
319
320 EventTarget* V8TestEventTarget::toEventTarget(v8::Handle<v8::Object> object)
321 {
322     return toNative(object);
323 }
324
325 v8::Handle<v8::Object> V8TestEventTarget::createWrapper(PassRefPtr<TestEventTarget> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
326 {
327     ASSERT(impl);
328     ASSERT(!DOMDataStore::containsWrapper<V8TestEventTarget>(impl.get(), isolate));
329     if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
330         const WrapperTypeInfo* actualInfo = ScriptWrappable::getTypeInfoFromObject(impl.get());
331         // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
332         // the same object de-ref functions, though, so use that as the basis of the check.
333         RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
334     }
335
336     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
337     if (UNLIKELY(wrapper.IsEmpty()))
338         return wrapper;
339
340     installPerContextEnabledProperties(wrapper, impl.get(), isolate);
341     V8DOMWrapper::associateObjectWithWrapper<V8TestEventTarget>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
342     return wrapper;
343 }
344
345 void V8TestEventTarget::derefObject(void* object)
346 {
347     fromInternalPointer(object)->deref();
348 }
349
350 template<>
351 v8::Handle<v8::Value> toV8NoInline(TestEventTarget* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
352 {
353     return toV8(impl, creationContext, isolate);
354 }
355
356 } // namespace WebCore