Upstream version 10.38.222.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 "bindings/core/v8/ExceptionState.h"
11 #include "bindings/core/v8/V8DOMConfiguration.h"
12 #include "bindings/core/v8/V8HiddenValue.h"
13 #include "bindings/core/v8/V8NodeList.h"
14 #include "bindings/core/v8/V8ObjectConstructor.h"
15 #include "bindings/tests/v8/V8Node.h"
16 #include "core/dom/ContextFeatures.h"
17 #include "core/dom/Document.h"
18 #include "core/dom/NameNodeList.h"
19 #include "core/dom/NodeList.h"
20 #include "core/dom/StaticNodeList.h"
21 #include "core/html/LabelsNodeList.h"
22 #include "platform/RuntimeEnabledFeatures.h"
23 #include "platform/TraceEvent.h"
24 #include "wtf/GetPtr.h"
25 #include "wtf/RefPtr.h"
26
27 namespace blink {
28
29 static void initializeScriptWrappableForInterface(TestSpecialOperations* object)
30 {
31     if (ScriptWrappable::wrapperCanBeStoredInObject(object))
32         ScriptWrappable::fromObject(object)->setTypeInfo(&V8TestSpecialOperations::wrapperTypeInfo);
33     else
34         ASSERT_NOT_REACHED();
35 }
36
37 } // namespace blink
38
39 void webCoreInitializeScriptWrappableForInterface(blink::TestSpecialOperations* object)
40 {
41     blink::initializeScriptWrappableForInterface(object);
42 }
43
44 namespace blink {
45 const WrapperTypeInfo V8TestSpecialOperations::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestSpecialOperations::domTemplate, V8TestSpecialOperations::derefObject, 0, 0, 0, V8TestSpecialOperations::installConditionallyEnabledMethods, 0, WrapperTypeObjectPrototype, RefCountedObject };
46
47 namespace TestSpecialOperationsV8Internal {
48
49 template <typename T> void V8_USE(T) { }
50
51 static void namedItemMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
52 {
53     if (UNLIKELY(info.Length() < 1)) {
54         V8ThrowException::throwException(createMinimumArityTypeErrorForMethod("namedItem", "TestSpecialOperations", 1, info.Length(), info.GetIsolate()), info.GetIsolate());
55         return;
56     }
57     TestSpecialOperations* impl = V8TestSpecialOperations::toNative(info.Holder());
58     V8StringResource<> name;
59     {
60         TOSTRING_VOID_INTERNAL(name, info[0]);
61     }
62     RefPtrWillBeRawPtr<Node> result0;
63     RefPtrWillBeRawPtr<NodeList> result1;
64     impl->getItem(name, result0, result1);
65     if (result0) {
66         v8SetReturnValue(info, result0.release());
67         return;
68     }
69     if (result1) {
70         v8SetReturnValue(info, result1.release());
71         return;
72     }
73     v8SetReturnValueNull(info);
74 }
75
76 static void namedItemMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
77 {
78     TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod");
79     TestSpecialOperationsV8Internal::namedItemMethod(info);
80     TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
81 }
82
83 static void namedPropertyGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
84 {
85     TestSpecialOperations* impl = V8TestSpecialOperations::toNative(info.Holder());
86     AtomicString propertyName = toCoreAtomicString(name);
87     RefPtrWillBeRawPtr<Node> result0;
88     RefPtrWillBeRawPtr<NodeList> result1;
89     impl->getItem(propertyName, result0, result1);
90     if (!(result0 || result1))
91         return;
92     if (result0) {
93         v8SetReturnValue(info, result0.release());
94         return;
95     }
96     if (result1) {
97         v8SetReturnValue(info, result1.release());
98         return;
99     }
100     ASSERT_NOT_REACHED();
101 }
102
103 static void namedPropertyGetterCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
104 {
105     TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMNamedProperty");
106     TestSpecialOperationsV8Internal::namedPropertyGetter(name, info);
107     TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
108 }
109
110 static void namedPropertySetter(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<v8::Value>& info)
111 {
112     TestSpecialOperations* impl = V8TestSpecialOperations::toNative(info.Holder());
113     TOSTRING_VOID(V8StringResource<>, propertyName, name);
114     TONATIVE_VOID(Node*, propertyValue, V8Node::toNativeWithTypeCheck(info.GetIsolate(), v8Value));
115     bool result = impl->anonymousNamedSetter(propertyName, propertyValue);
116     if (!result)
117         return;
118     v8SetReturnValue(info, v8Value);
119 }
120
121 static void namedPropertySetterCallback(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<v8::Value>& info)
122 {
123     TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMNamedProperty");
124     TestSpecialOperationsV8Internal::namedPropertySetter(name, v8Value, info);
125     TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
126 }
127
128 static void namedPropertyQuery(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Integer>& info)
129 {
130     TestSpecialOperations* impl = V8TestSpecialOperations::toNative(info.Holder());
131     AtomicString propertyName = toCoreAtomicString(name);
132     v8::String::Utf8Value namedProperty(name);
133     ExceptionState exceptionState(ExceptionState::GetterContext, *namedProperty, "TestSpecialOperations", info.Holder(), info.GetIsolate());
134     bool result = impl->namedPropertyQuery(propertyName, exceptionState);
135     if (exceptionState.throwIfNeeded())
136         return;
137     if (!result)
138         return;
139     v8SetReturnValueInt(info, v8::None);
140 }
141
142 static void namedPropertyQueryCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Integer>& info)
143 {
144     TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMNamedProperty");
145     TestSpecialOperationsV8Internal::namedPropertyQuery(name, info);
146     TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
147 }
148
149 static void namedPropertyEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info)
150 {
151     TestSpecialOperations* impl = V8TestSpecialOperations::toNative(info.Holder());
152     Vector<String> names;
153     ExceptionState exceptionState(ExceptionState::EnumerationContext, "TestSpecialOperations", info.Holder(), info.GetIsolate());
154     impl->namedPropertyEnumerator(names, exceptionState);
155     if (exceptionState.throwIfNeeded())
156         return;
157     v8::Handle<v8::Array> v8names = v8::Array::New(info.GetIsolate(), names.size());
158     for (size_t i = 0; i < names.size(); ++i)
159         v8names->Set(v8::Integer::New(info.GetIsolate(), i), v8String(info.GetIsolate(), names[i]));
160     v8SetReturnValue(info, v8names);
161 }
162
163 static void namedPropertyEnumeratorCallback(const v8::PropertyCallbackInfo<v8::Array>& info)
164 {
165     TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMNamedProperty");
166     TestSpecialOperationsV8Internal::namedPropertyEnumerator(info);
167     TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
168 }
169
170 } // namespace TestSpecialOperationsV8Internal
171
172 static const V8DOMConfiguration::MethodConfiguration V8TestSpecialOperationsMethods[] = {
173     {"namedItem", TestSpecialOperationsV8Internal::namedItemMethodCallback, 0, 1, V8DOMConfiguration::ExposedToAllScripts},
174 };
175
176 static void installV8TestSpecialOperationsTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate)
177 {
178     functionTemplate->ReadOnlyPrototype();
179
180     v8::Local<v8::Signature> defaultSignature;
181     defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestSpecialOperations", v8::Local<v8::FunctionTemplate>(), V8TestSpecialOperations::internalFieldCount,
182         0, 0,
183         0, 0,
184         V8TestSpecialOperationsMethods, WTF_ARRAY_LENGTH(V8TestSpecialOperationsMethods),
185         isolate);
186     v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate();
187     v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate();
188     functionTemplate->InstanceTemplate()->SetNamedPropertyHandler(TestSpecialOperationsV8Internal::namedPropertyGetterCallback, TestSpecialOperationsV8Internal::namedPropertySetterCallback, TestSpecialOperationsV8Internal::namedPropertyQueryCallback, 0, TestSpecialOperationsV8Internal::namedPropertyEnumeratorCallback);
189
190     // Custom toString template
191     functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate());
192 }
193
194 v8::Handle<v8::FunctionTemplate> V8TestSpecialOperations::domTemplate(v8::Isolate* isolate)
195 {
196     return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), installV8TestSpecialOperationsTemplate);
197 }
198
199 bool V8TestSpecialOperations::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
200 {
201     return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value);
202 }
203
204 v8::Handle<v8::Object> V8TestSpecialOperations::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
205 {
206     return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value);
207 }
208
209 TestSpecialOperations* V8TestSpecialOperations::toNativeWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value)
210 {
211     return hasInstance(value, isolate) ? fromInternalPointer(blink::toInternalPointer(v8::Handle<v8::Object>::Cast(value))) : 0;
212 }
213
214 v8::Handle<v8::Object> wrap(TestSpecialOperations* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
215 {
216     ASSERT(impl);
217     ASSERT(!DOMDataStore::containsWrapper<V8TestSpecialOperations>(impl, isolate));
218     return V8TestSpecialOperations::createWrapper(impl, creationContext, isolate);
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     installConditionallyEnabledProperties(wrapper, isolate);
237     V8DOMWrapper::associateObjectWithWrapper<V8TestSpecialOperations>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
238     return wrapper;
239 }
240
241 void V8TestSpecialOperations::derefObject(ScriptWrappableBase* internalPointer)
242 {
243     fromInternalPointer(internalPointer)->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 blink