Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / tests / results / V8TestSpecialOperations.cpp
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // This file has been auto-generated by code_generator_v8.py. DO NOT MODIFY!
6
7 #include "config.h"
8 #include "V8TestSpecialOperations.h"
9
10 #include "RuntimeEnabledFeatures.h"
11 #include "V8Node.h"
12 #include "V8NodeList.h"
13 #include "bindings/v8/ExceptionState.h"
14 #include "bindings/v8/V8DOMConfiguration.h"
15 #include "bindings/v8/V8HiddenValue.h"
16 #include "bindings/v8/V8ObjectConstructor.h"
17 #include "core/dom/ContextFeatures.h"
18 #include "core/dom/Document.h"
19 #include "platform/TraceEvent.h"
20 #include "wtf/GetPtr.h"
21 #include "wtf/RefPtr.h"
22
23 namespace WebCore {
24
25 static void initializeScriptWrappableForInterface(TestSpecialOperations* object)
26 {
27     if (ScriptWrappable::wrapperCanBeStoredInObject(object))
28         ScriptWrappable::fromObject(object)->setTypeInfo(&V8TestSpecialOperations::wrapperTypeInfo);
29     else
30         ASSERT_NOT_REACHED();
31 }
32
33 } // namespace WebCore
34
35 void webCoreInitializeScriptWrappableForInterface(WebCore::TestSpecialOperations* object)
36 {
37     WebCore::initializeScriptWrappableForInterface(object);
38 }
39
40 namespace WebCore {
41 const WrapperTypeInfo V8TestSpecialOperations::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestSpecialOperations::domTemplate, V8TestSpecialOperations::derefObject, 0, 0, 0, V8TestSpecialOperations::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype, RefCountedObject };
42
43 namespace TestSpecialOperationsV8Internal {
44
45 template <typename T> void V8_USE(T) { }
46
47 static void namedItemMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
48 {
49     if (UNLIKELY(info.Length() < 1)) {
50         throwArityTypeErrorForMethod("namedItem", "TestSpecialOperations", 1, info.Length(), info.GetIsolate());
51         return;
52     }
53     TestSpecialOperations* impl = V8TestSpecialOperations::toNative(info.Holder());
54     TOSTRING_VOID(V8StringResource<>, name, info[0]);
55     bool result0Enabled = false;
56     RefPtr<Node> result0;
57     bool result1Enabled = false;
58     RefPtr<NodeList> result1;
59     impl->getItem(name, result0Enabled, result0, result1Enabled, result1);
60     if (result0Enabled) {
61         v8SetReturnValue(info, result0.release());
62         return;
63     }
64     if (result1Enabled) {
65         v8SetReturnValue(info, result1.release());
66         return;
67     }
68     v8SetReturnValueNull(info);
69 }
70
71 static void namedItemMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
72 {
73     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
74     TestSpecialOperationsV8Internal::namedItemMethod(info);
75     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
76 }
77
78 static void namedPropertyGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
79 {
80     TestSpecialOperations* impl = V8TestSpecialOperations::toNative(info.Holder());
81     AtomicString propertyName = toCoreAtomicString(name);
82     bool result0Enabled = false;
83     RefPtr<Node> result0;
84     bool result1Enabled = false;
85     RefPtr<NodeList> result1;
86     impl->getItem(propertyName, result0Enabled, result0, result1Enabled, result1);
87     if (!result0Enabled && !result1Enabled)
88         return;
89     if (result0Enabled) {
90         v8SetReturnValueFast(info, WTF::getPtr(result0.release()), impl);
91         return;
92     }
93     if (result1Enabled) {
94         v8SetReturnValueFast(info, WTF::getPtr(result1.release()), impl);
95         return;
96     }
97     v8SetReturnValueNull(info);
98 }
99
100 static void namedPropertyGetterCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
101 {
102     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
103     TestSpecialOperationsV8Internal::namedPropertyGetter(name, info);
104     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
105 }
106
107 static void namedPropertySetter(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<v8::Value>& info)
108 {
109     TestSpecialOperations* impl = V8TestSpecialOperations::toNative(info.Holder());
110     TOSTRING_VOID(V8StringResource<>, propertyName, name);
111     TONATIVE_VOID(Node*, propertyValue, V8Node::toNativeWithTypeCheck(info.GetIsolate(), v8Value));
112     bool result = impl->anonymousNamedSetter(propertyName, propertyValue);
113     if (!result)
114         return;
115     v8SetReturnValue(info, v8Value);
116 }
117
118 static void namedPropertySetterCallback(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<v8::Value>& info)
119 {
120     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
121     TestSpecialOperationsV8Internal::namedPropertySetter(name, v8Value, info);
122     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
123 }
124
125 static void namedPropertyQuery(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Integer>& info)
126 {
127     TestSpecialOperations* impl = V8TestSpecialOperations::toNative(info.Holder());
128     AtomicString propertyName = toCoreAtomicString(name);
129     v8::String::Utf8Value namedProperty(name);
130     ExceptionState exceptionState(ExceptionState::GetterContext, *namedProperty, "TestSpecialOperations", info.Holder(), info.GetIsolate());
131     bool result = impl->namedPropertyQuery(propertyName, exceptionState);
132     if (exceptionState.throwIfNeeded())
133         return;
134     if (!result)
135         return;
136     v8SetReturnValueInt(info, v8::None);
137 }
138
139 static void namedPropertyQueryCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Integer>& info)
140 {
141     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
142     TestSpecialOperationsV8Internal::namedPropertyQuery(name, info);
143     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
144 }
145
146 static void namedPropertyEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info)
147 {
148     TestSpecialOperations* impl = V8TestSpecialOperations::toNative(info.Holder());
149     v8::Isolate* isolate = info.GetIsolate();
150     Vector<String> names;
151     ExceptionState exceptionState(ExceptionState::EnumerationContext, "TestSpecialOperations", info.Holder(), isolate);
152     impl->namedPropertyEnumerator(names, exceptionState);
153     if (exceptionState.throwIfNeeded())
154         return;
155     v8::Handle<v8::Array> v8names = v8::Array::New(isolate, names.size());
156     for (size_t i = 0; i < names.size(); ++i)
157         v8names->Set(v8::Integer::New(isolate, i), v8String(isolate, names[i]));
158     v8SetReturnValue(info, v8names);
159 }
160
161 static void namedPropertyEnumeratorCallback(const v8::PropertyCallbackInfo<v8::Array>& info)
162 {
163     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
164     TestSpecialOperationsV8Internal::namedPropertyEnumerator(info);
165     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
166 }
167
168 } // namespace TestSpecialOperationsV8Internal
169
170 static const V8DOMConfiguration::MethodConfiguration V8TestSpecialOperationsMethods[] = {
171     {"namedItem", TestSpecialOperationsV8Internal::namedItemMethodCallback, 0, 1},
172 };
173
174 static void configureV8TestSpecialOperationsTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate)
175 {
176     functionTemplate->ReadOnlyPrototype();
177
178     v8::Local<v8::Signature> defaultSignature;
179     defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestSpecialOperations", v8::Local<v8::FunctionTemplate>(), V8TestSpecialOperations::internalFieldCount,
180         0, 0,
181         0, 0,
182         V8TestSpecialOperationsMethods, WTF_ARRAY_LENGTH(V8TestSpecialOperationsMethods),
183         isolate);
184     v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate();
185     v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate();
186     functionTemplate->InstanceTemplate()->SetNamedPropertyHandler(TestSpecialOperationsV8Internal::namedPropertyGetterCallback, TestSpecialOperationsV8Internal::namedPropertySetterCallback, TestSpecialOperationsV8Internal::namedPropertyQueryCallback, 0, TestSpecialOperationsV8Internal::namedPropertyEnumeratorCallback);
187
188     // Custom toString template
189     functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate());
190 }
191
192 v8::Handle<v8::FunctionTemplate> V8TestSpecialOperations::domTemplate(v8::Isolate* isolate)
193 {
194     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
195     v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(const_cast<WrapperTypeInfo*>(&wrapperTypeInfo));
196     if (!result.IsEmpty())
197         return result;
198
199     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
200     result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidConstructorMode);
201     configureV8TestSpecialOperationsTemplate(result, isolate);
202     data->setDOMTemplate(const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), result);
203     return result;
204 }
205
206 bool V8TestSpecialOperations::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
207 {
208     return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value);
209 }
210
211 v8::Handle<v8::Object> V8TestSpecialOperations::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
212 {
213     return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value);
214 }
215
216 TestSpecialOperations* V8TestSpecialOperations::toNativeWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value)
217 {
218     return hasInstance(value, isolate) ? fromInternalPointer(v8::Handle<v8::Object>::Cast(value)->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex)) : 0;
219 }
220
221 v8::Handle<v8::Object> V8TestSpecialOperations::createWrapper(PassRefPtr<TestSpecialOperations> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
222 {
223     ASSERT(impl);
224     ASSERT(!DOMDataStore::containsWrapper<V8TestSpecialOperations>(impl.get(), isolate));
225     if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
226         const WrapperTypeInfo* actualInfo = ScriptWrappable::fromObject(impl.get())->typeInfo();
227         // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
228         // the same object de-ref functions, though, so use that as the basis of the check.
229         RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
230     }
231
232     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
233     if (UNLIKELY(wrapper.IsEmpty()))
234         return wrapper;
235
236     installPerContextEnabledProperties(wrapper, impl.get(), isolate);
237     V8DOMWrapper::associateObjectWithWrapper<V8TestSpecialOperations>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
238     return wrapper;
239 }
240
241 void V8TestSpecialOperations::derefObject(void* object)
242 {
243     fromInternalPointer(object)->deref();
244 }
245
246 template<>
247 v8::Handle<v8::Value> toV8NoInline(TestSpecialOperations* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
248 {
249     return toV8(impl, creationContext, isolate);
250 }
251
252 } // namespace WebCore