Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / tests / results / V8TestSpecialOperationsInt.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 "V8TestSpecialOperationsInt.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(TestSpecialOperationsInt* object)
49 {
50     if (ScriptWrappable::wrapperCanBeStoredInObject(object))
51         ScriptWrappable::setTypeInfoInObject(object, &V8TestSpecialOperationsInt::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::TestSpecialOperationsInt* object)
63 {
64     WebCore::initializeScriptWrappableForInterface(object);
65 }
66
67 namespace WebCore {
68 const WrapperTypeInfo V8TestSpecialOperationsInt::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestSpecialOperationsInt::domTemplate, V8TestSpecialOperationsInt::derefObject, 0, 0, 0, V8TestSpecialOperationsInt::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype, false };
69
70 namespace TestSpecialOperationsIntV8Internal {
71
72 template <typename T> void V8_USE(T) { }
73
74 static void indexedPropertyGetter(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info)
75 {
76     TestSpecialOperationsInt* imp = V8TestSpecialOperationsInt::toNative(info.Holder());
77     int result = imp->anonymousIndexedGetter(index);
78     if ()
79         return;
80     v8SetReturnValueInt(info, result);
81 }
82
83 static void indexedPropertyGetterCallback(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info)
84 {
85     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMIndexedProperty");
86     TestSpecialOperationsIntV8Internal::indexedPropertyGetter(index, info);
87     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
88 }
89
90 static void indexedPropertySetter(uint32_t index, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<v8::Value>& info)
91 {
92     TestSpecialOperationsInt* imp = V8TestSpecialOperationsInt::toNative(info.Holder());
93     V8TRYCATCH_EXCEPTION_VOID(unsigned, propertyValue, toUInt32(jsValue, exceptionState), exceptionState);
94     ExceptionState exceptionState(info.Holder(), info.GetIsolate());
95     bool result = imp->anonymousIndexedSetter(index, propertyValue);
96     if (!result)
97         return;
98     v8SetReturnValue(info, jsValue);
99 }
100
101 static void indexedPropertySetterCallback(uint32_t index, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<v8::Value>& info)
102 {
103     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMIndexedProperty");
104     TestSpecialOperationsIntV8Internal::indexedPropertySetter(index, jsValue, info);
105     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
106 }
107
108 static void namedPropertyGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
109 {
110     if (info.Holder()->HasRealNamedProperty(name))
111         return;
112     if (!info.Holder()->GetRealNamedPropertyInPrototypeChain(name).IsEmpty())
113         return;
114
115     TestSpecialOperationsInt* imp = V8TestSpecialOperationsInt::toNative(info.Holder());
116     AtomicString propertyName = toCoreAtomicString(name);
117     int result = imp->anonymousNamedGetter(propertyName);
118     if ()
119         return;
120     v8SetReturnValueInt(info, result);
121 }
122
123 static void namedPropertyGetterCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
124 {
125     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
126     TestSpecialOperationsIntV8Internal::namedPropertyGetter(name, info);
127     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
128 }
129
130 static void namedPropertySetter(v8::Local<v8::String> name, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<v8::Value>& info)
131 {
132     if (info.Holder()->HasRealNamedProperty(name))
133         return;
134     if (!info.Holder()->GetRealNamedPropertyInPrototypeChain(name).IsEmpty())
135         return;
136
137     TestSpecialOperationsInt* imp = V8TestSpecialOperationsInt::toNative(info.Holder());
138     V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, propertyName, name);
139     V8TRYCATCH_EXCEPTION_VOID(unsigned, propertyValue, toUInt32(jsValue, exceptionState), exceptionState);
140     ExceptionState exceptionState(info.Holder(), info.GetIsolate());
141     bool result = imp->anonymousNamedSetter(propertyName, propertyValue);
142     if (!result)
143         return;
144     v8SetReturnValue(info, jsValue);
145 }
146
147 static void namedPropertySetterCallback(v8::Local<v8::String> name, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<v8::Value>& info)
148 {
149     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
150     TestSpecialOperationsIntV8Internal::namedPropertySetter(name, jsValue, info);
151     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
152 }
153
154 static void namedPropertyQuery(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Integer>& info)
155 {
156     TestSpecialOperationsInt* imp = V8TestSpecialOperationsInt::toNative(info.Holder());
157     AtomicString propertyName = toCoreAtomicString(name);
158     ExceptionState exceptionState(info.Holder(), info.GetIsolate());
159     bool result = imp->namedPropertyQuery(propertyName, exceptionState);
160     if (exceptionState.throwIfNeeded())
161         return;
162     if (!result)
163         return;
164     v8SetReturnValueInt(info, v8::None);
165 }
166
167 static void namedPropertyQueryCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Integer>& info)
168 {
169     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
170     TestSpecialOperationsIntV8Internal::namedPropertyQuery(name, info);
171     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
172 }
173
174 static void namedPropertyEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info)
175 {
176     TestSpecialOperationsInt* imp = V8TestSpecialOperationsInt::toNative(info.Holder());
177     Vector<String> names;
178     ExceptionState exceptionState(info.Holder(), info.GetIsolate());
179     imp->namedPropertyEnumerator(names, exceptionState);
180     if (exceptionState.throwIfNeeded())
181         return;
182     v8::Handle<v8::Array> v8names = v8::Array::New(info.GetIsolate(), names.size());
183     for (size_t i = 0; i < names.size(); ++i)
184         v8names->Set(v8::Integer::New(info.GetIsolate(), i), v8String(info.GetIsolate(), names[i]));
185     v8SetReturnValue(info, v8names);
186 }
187
188 static void namedPropertyEnumeratorCallback(const v8::PropertyCallbackInfo<v8::Array>& info)
189 {
190     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
191     TestSpecialOperationsIntV8Internal::namedPropertyEnumerator(info);
192     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
193 }
194
195 } // namespace TestSpecialOperationsIntV8Internal
196
197 static void configureV8TestSpecialOperationsIntTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate, WrapperWorldType currentWorldType)
198 {
199     functionTemplate->ReadOnlyPrototype();
200
201     v8::Local<v8::Signature> defaultSignature;
202     defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestSpecialOperationsInt", v8::Local<v8::FunctionTemplate>(), V8TestSpecialOperationsInt::internalFieldCount,
203         0, 0,
204         0, 0,
205         0, 0,
206         isolate, currentWorldType);
207     v8::Local<v8::ObjectTemplate> ALLOW_UNUSED instanceTemplate = functionTemplate->InstanceTemplate();
208     v8::Local<v8::ObjectTemplate> ALLOW_UNUSED prototypeTemplate = functionTemplate->PrototypeTemplate();
209     functionTemplate->InstanceTemplate()->SetIndexedPropertyHandler(TestSpecialOperationsIntV8Internal::indexedPropertyGetterCallback, TestSpecialOperationsIntV8Internal::indexedPropertySetterCallback, 0, 0, indexedPropertyEnumerator<TestSpecialOperationsInt>);
210     functionTemplate->InstanceTemplate()->SetNamedPropertyHandler(TestSpecialOperationsIntV8Internal::namedPropertyGetterCallback, TestSpecialOperationsIntV8Internal::namedPropertySetterCallback, TestSpecialOperationsIntV8Internal::namedPropertyQueryCallback, 0, TestSpecialOperationsIntV8Internal::namedPropertyEnumeratorCallback);
211
212     // Custom toString template
213     functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::current()->toStringTemplate());
214 }
215
216 v8::Handle<v8::FunctionTemplate> V8TestSpecialOperationsInt::domTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
217 {
218     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
219     V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWorldType).find(&wrapperTypeInfo);
220     if (result != data->templateMap(currentWorldType).end())
221         return result->value.newLocal(isolate);
222
223     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
224     v8::EscapableHandleScope handleScope(isolate);
225     v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidConstructorMode);
226     configureV8TestSpecialOperationsIntTemplate(templ, isolate, currentWorldType);
227     data->templateMap(currentWorldType).add(&wrapperTypeInfo, UnsafePersistent<v8::FunctionTemplate>(isolate, templ));
228     return handleScope.Escape(templ);
229 }
230
231 bool V8TestSpecialOperationsInt::hasInstance(v8::Handle<v8::Value> jsValue, v8::Isolate* isolate)
232 {
233     return V8PerIsolateData::from(isolate)->hasInstanceInMainWorld(&wrapperTypeInfo, jsValue)
234         || V8PerIsolateData::from(isolate)->hasInstanceInNonMainWorld(&wrapperTypeInfo, jsValue);
235 }
236
237 v8::Handle<v8::Object> V8TestSpecialOperationsInt::createWrapper(PassRefPtr<TestSpecialOperationsInt> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
238 {
239     ASSERT(impl);
240     ASSERT(!DOMDataStore::containsWrapper<V8TestSpecialOperationsInt>(impl.get(), isolate));
241     if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
242         const WrapperTypeInfo* actualInfo = ScriptWrappable::getTypeInfoFromObject(impl.get());
243         // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
244         // the same object de-ref functions, though, so use that as the basis of the check.
245         RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
246     }
247
248     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
249     if (UNLIKELY(wrapper.IsEmpty()))
250         return wrapper;
251
252     installPerContextEnabledProperties(wrapper, impl.get(), isolate);
253     V8DOMWrapper::associateObjectWithWrapper<V8TestSpecialOperationsInt>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
254     return wrapper;
255 }
256
257 void V8TestSpecialOperationsInt::derefObject(void* object)
258 {
259     fromInternalPointer(object)->deref();
260 }
261
262 template<>
263 v8::Handle<v8::Value> toV8NoInline(TestSpecialOperationsInt* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
264 {
265     return toV8(impl, creationContext, isolate);
266 }
267
268 } // namespace WebCore