Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / tests / results / V8TestNode.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 "V8TestNode.h"
35
36 #include "RuntimeEnabledFeatures.h"
37 #include "bindings/v8/ExceptionState.h"
38 #include "bindings/v8/V8DOMConfiguration.h"
39 #include "bindings/v8/V8ObjectConstructor.h"
40 #include "core/dom/ContextFeatures.h"
41 #include "core/dom/Document.h"
42 #include "platform/TraceEvent.h"
43 #include "wtf/GetPtr.h"
44 #include "wtf/RefPtr.h"
45
46 namespace WebCore {
47
48 static void initializeScriptWrappableForInterface(TestNode* object)
49 {
50     if (ScriptWrappable::wrapperCanBeStoredInObject(object))
51         ScriptWrappable::setTypeInfoInObject(object, &V8TestNode::wrapperTypeInfo);
52     else
53         ASSERT_NOT_REACHED();
54 }
55
56 } // namespace WebCore
57
58 // In ScriptWrappable::init, the use of a local function declaration has an issue on Windows:
59 // the local declaration does not pick up the surrounding namespace. Therefore, we provide this function
60 // in the global namespace.
61 // (More info on the MSVC bug here: http://connect.microsoft.com/VisualStudio/feedback/details/664619/the-namespace-of-local-function-declarations-in-c)
62 void webCoreInitializeScriptWrappableForInterface(WebCore::TestNode* object)
63 {
64     WebCore::initializeScriptWrappableForInterface(object);
65 }
66
67 namespace WebCore {
68 const WrapperTypeInfo V8TestNode::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestNode::domTemplate, V8TestNode::derefObject, 0, V8TestNode::toEventTarget, 0, V8TestNode::installPerContextEnabledMethods, &V8Node::wrapperTypeInfo, WrapperTypeObjectPrototype, false };
69
70 namespace TestNodeV8Internal {
71
72 template <typename T> void V8_USE(T) { }
73
74 static void hrefAttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
75 {
76     TestNode* imp = V8TestNode::toNative(info.Holder());
77     v8SetReturnValueString(info, imp->href(), info.GetIsolate());
78 }
79
80 static void hrefAttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
81 {
82     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
83     TestNodeV8Internal::hrefAttributeGetter(info);
84     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
85 }
86
87 static void hrefAttributeSetter(v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info)
88 {
89     TestNode* imp = V8TestNode::toNative(info.Holder());
90     V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, cppValue, jsValue);
91     imp->setHref(cppValue);
92 }
93
94 static void hrefAttributeSetterCallback(v8::Local<v8::String>, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info)
95 {
96     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMSetter");
97     TestNodeV8Internal::hrefAttributeSetter(jsValue, info);
98     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
99 }
100
101 static void hrefThrowsAttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
102 {
103     TestNode* imp = V8TestNode::toNative(info.Holder());
104     v8SetReturnValueString(info, imp->hrefThrows(), info.GetIsolate());
105 }
106
107 static void hrefThrowsAttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
108 {
109     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
110     TestNodeV8Internal::hrefThrowsAttributeGetter(info);
111     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
112 }
113
114 static void hrefThrowsAttributeSetter(v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info)
115 {
116     ExceptionState exceptionState(ExceptionState::SetterContext, "hrefThrows", "TestNode", info.Holder(), info.GetIsolate());
117     TestNode* imp = V8TestNode::toNative(info.Holder());
118     V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, cppValue, jsValue);
119     imp->setHrefThrows(cppValue, exceptionState);
120     exceptionState.throwIfNeeded();
121 }
122
123 static void hrefThrowsAttributeSetterCallback(v8::Local<v8::String>, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info)
124 {
125     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMSetter");
126     TestNodeV8Internal::hrefThrowsAttributeSetter(jsValue, info);
127     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
128 }
129
130 static void hrefCallWithAttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
131 {
132     TestNode* imp = V8TestNode::toNative(info.Holder());
133     v8SetReturnValueString(info, imp->hrefCallWith(), info.GetIsolate());
134 }
135
136 static void hrefCallWithAttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
137 {
138     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
139     TestNodeV8Internal::hrefCallWithAttributeGetter(info);
140     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
141 }
142
143 static void hrefCallWithAttributeSetter(v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info)
144 {
145     TestNode* imp = V8TestNode::toNative(info.Holder());
146     V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, cppValue, jsValue);
147     imp->setHrefCallWith(activeDOMWindow(info.GetIsolate()), firstDOMWindow(info.GetIsolate()), cppValue);
148 }
149
150 static void hrefCallWithAttributeSetterCallback(v8::Local<v8::String>, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info)
151 {
152     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMSetter");
153     TestNodeV8Internal::hrefCallWithAttributeSetter(jsValue, info);
154     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
155 }
156
157 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
158 {
159     RefPtr<TestNode> impl = TestNode::create();
160     v8::Handle<v8::Object> wrapper = info.Holder();
161
162     V8DOMWrapper::associateObjectWithWrapper<V8TestNode>(impl.release(), &V8TestNode::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Dependent);
163     v8SetReturnValue(info, wrapper);
164 }
165
166 } // namespace TestNodeV8Internal
167
168 static const V8DOMConfiguration::AttributeConfiguration V8TestNodeAttributes[] = {
169     {"href", TestNodeV8Internal::hrefAttributeGetterCallback, TestNodeV8Internal::hrefAttributeSetterCallback, 0, 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
170     {"hrefThrows", TestNodeV8Internal::hrefThrowsAttributeGetterCallback, TestNodeV8Internal::hrefThrowsAttributeSetterCallback, 0, 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
171     {"hrefCallWith", TestNodeV8Internal::hrefCallWithAttributeGetterCallback, TestNodeV8Internal::hrefCallWithAttributeSetterCallback, 0, 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
172 };
173
174 void V8TestNode::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
175 {
176     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "DOMConstructor");
177     if (!info.IsConstructCall()) {
178         throwTypeError(ExceptionMessages::failedToConstruct("TestNode", "Please use the 'new' operator, this DOM object constructor cannot be called as a function."), info.GetIsolate());
179         return;
180     }
181
182     if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) {
183         v8SetReturnValue(info, info.Holder());
184         return;
185     }
186
187     TestNodeV8Internal::constructor(info);
188 }
189
190 static void configureV8TestNodeTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate, WrapperWorldType currentWorldType)
191 {
192     functionTemplate->ReadOnlyPrototype();
193
194     v8::Local<v8::Signature> defaultSignature;
195     defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestNode", V8Node::domTemplate(isolate, currentWorldType), V8TestNode::internalFieldCount,
196         V8TestNodeAttributes, WTF_ARRAY_LENGTH(V8TestNodeAttributes),
197         0, 0,
198         0, 0,
199         isolate, currentWorldType);
200     functionTemplate->SetCallHandler(V8TestNode::constructorCallback);
201     functionTemplate->SetLength(0);
202     v8::Local<v8::ObjectTemplate> ALLOW_UNUSED instanceTemplate = functionTemplate->InstanceTemplate();
203     v8::Local<v8::ObjectTemplate> ALLOW_UNUSED prototypeTemplate = functionTemplate->PrototypeTemplate();
204
205     // Custom toString template
206     functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::current()->toStringTemplate());
207 }
208
209 v8::Handle<v8::FunctionTemplate> V8TestNode::domTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
210 {
211     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
212     V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWorldType).find(&wrapperTypeInfo);
213     if (result != data->templateMap(currentWorldType).end())
214         return result->value.newLocal(isolate);
215
216     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
217     v8::EscapableHandleScope handleScope(isolate);
218     v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidConstructorMode);
219     configureV8TestNodeTemplate(templ, isolate, currentWorldType);
220     data->templateMap(currentWorldType).add(&wrapperTypeInfo, UnsafePersistent<v8::FunctionTemplate>(isolate, templ));
221     return handleScope.Escape(templ);
222 }
223
224 bool V8TestNode::hasInstance(v8::Handle<v8::Value> jsValue, v8::Isolate* isolate)
225 {
226     return V8PerIsolateData::from(isolate)->hasInstanceInMainWorld(&wrapperTypeInfo, jsValue)
227         || V8PerIsolateData::from(isolate)->hasInstanceInNonMainWorld(&wrapperTypeInfo, jsValue);
228 }
229
230 EventTarget* V8TestNode::toEventTarget(v8::Handle<v8::Object> object)
231 {
232     return toNative(object);
233 }
234
235 v8::Handle<v8::Object> V8TestNode::createWrapper(PassRefPtr<TestNode> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
236 {
237     ASSERT(impl);
238     ASSERT(!DOMDataStore::containsWrapper<V8TestNode>(impl.get(), isolate));
239     if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
240         const WrapperTypeInfo* actualInfo = ScriptWrappable::getTypeInfoFromObject(impl.get());
241         // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
242         // the same object de-ref functions, though, so use that as the basis of the check.
243         RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
244     }
245
246     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
247     if (UNLIKELY(wrapper.IsEmpty()))
248         return wrapper;
249
250     installPerContextEnabledProperties(wrapper, impl.get(), isolate);
251     V8DOMWrapper::associateObjectWithWrapper<V8TestNode>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Dependent);
252     return wrapper;
253 }
254
255 void V8TestNode::derefObject(void* object)
256 {
257     fromInternalPointer(object)->deref();
258 }
259
260 template<>
261 v8::Handle<v8::Value> toV8NoInline(TestNode* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
262 {
263     return toV8(impl, creationContext, isolate);
264 }
265
266 } // namespace WebCore