Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / tests / results / V8TestNode.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 "V8TestNode.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/V8ObjectConstructor.h"
14 #include "core/dom/ContextFeatures.h"
15 #include "core/dom/Document.h"
16 #include "core/frame/LocalDOMWindow.h"
17 #include "platform/RuntimeEnabledFeatures.h"
18 #include "platform/TraceEvent.h"
19 #include "wtf/GetPtr.h"
20 #include "wtf/RefPtr.h"
21
22 namespace blink {
23
24 static void initializeScriptWrappableForInterface(TestNode* object)
25 {
26     if (ScriptWrappable::wrapperCanBeStoredInObject(object))
27         ScriptWrappable::fromObject(object)->setTypeInfo(&V8TestNode::wrapperTypeInfo);
28     else
29         ASSERT_NOT_REACHED();
30 }
31
32 } // namespace blink
33
34 void webCoreInitializeScriptWrappableForInterface(blink::TestNode* object)
35 {
36     blink::initializeScriptWrappableForInterface(object);
37 }
38
39 namespace blink {
40 const WrapperTypeInfo V8TestNode::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestNode::domTemplate, V8TestNode::derefObject, 0, V8TestNode::toEventTarget, 0, V8TestNode::installConditionallyEnabledMethods, &V8Node::wrapperTypeInfo, WrapperTypeObjectPrototype, WillBeGarbageCollectedObject };
41
42 namespace TestNodeV8Internal {
43
44 template <typename T> void V8_USE(T) { }
45
46 static void hrefAttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
47 {
48     v8::Handle<v8::Object> holder = info.Holder();
49     TestNode* impl = V8TestNode::toNative(holder);
50     v8SetReturnValueString(info, impl->href(), info.GetIsolate());
51 }
52
53 static void hrefAttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
54 {
55     TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter");
56     TestNodeV8Internal::hrefAttributeGetter(info);
57     TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
58 }
59
60 static void hrefAttributeSetter(v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
61 {
62     v8::Handle<v8::Object> holder = info.Holder();
63     TestNode* impl = V8TestNode::toNative(holder);
64     TOSTRING_VOID(V8StringResource<>, cppValue, v8Value);
65     impl->setHref(cppValue);
66 }
67
68 static void hrefAttributeSetterCallback(v8::Local<v8::String>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
69 {
70     TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMSetter");
71     TestNodeV8Internal::hrefAttributeSetter(v8Value, info);
72     TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
73 }
74
75 static void hrefThrowsAttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
76 {
77     v8::Handle<v8::Object> holder = info.Holder();
78     TestNode* impl = V8TestNode::toNative(holder);
79     v8SetReturnValueString(info, impl->hrefThrows(), info.GetIsolate());
80 }
81
82 static void hrefThrowsAttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
83 {
84     TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter");
85     TestNodeV8Internal::hrefThrowsAttributeGetter(info);
86     TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
87 }
88
89 static void hrefThrowsAttributeSetter(v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
90 {
91     v8::Handle<v8::Object> holder = info.Holder();
92     ExceptionState exceptionState(ExceptionState::SetterContext, "hrefThrows", "TestNode", holder, info.GetIsolate());
93     TestNode* impl = V8TestNode::toNative(holder);
94     TOSTRING_VOID(V8StringResource<>, cppValue, v8Value);
95     impl->setHrefThrows(cppValue, exceptionState);
96     exceptionState.throwIfNeeded();
97 }
98
99 static void hrefThrowsAttributeSetterCallback(v8::Local<v8::String>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
100 {
101     TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMSetter");
102     TestNodeV8Internal::hrefThrowsAttributeSetter(v8Value, info);
103     TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
104 }
105
106 static void hrefCallWithAttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
107 {
108     v8::Handle<v8::Object> holder = info.Holder();
109     TestNode* impl = V8TestNode::toNative(holder);
110     v8SetReturnValueString(info, impl->hrefCallWith(), info.GetIsolate());
111 }
112
113 static void hrefCallWithAttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
114 {
115     TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter");
116     TestNodeV8Internal::hrefCallWithAttributeGetter(info);
117     TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
118 }
119
120 static void hrefCallWithAttributeSetter(v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
121 {
122     v8::Handle<v8::Object> holder = info.Holder();
123     TestNode* impl = V8TestNode::toNative(holder);
124     TOSTRING_VOID(V8StringResource<>, cppValue, v8Value);
125     ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
126     impl->setHrefCallWith(executionContext, callingDOMWindow(info.GetIsolate()), enteredDOMWindow(info.GetIsolate()), cppValue);
127 }
128
129 static void hrefCallWithAttributeSetterCallback(v8::Local<v8::String>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
130 {
131     TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMSetter");
132     TestNodeV8Internal::hrefCallWithAttributeSetter(v8Value, info);
133     TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
134 }
135
136 static void hrefByteStringAttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
137 {
138     v8::Handle<v8::Object> holder = info.Holder();
139     TestNode* impl = V8TestNode::toNative(holder);
140     v8SetReturnValueString(info, impl->hrefByteString(), info.GetIsolate());
141 }
142
143 static void hrefByteStringAttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
144 {
145     TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter");
146     TestNodeV8Internal::hrefByteStringAttributeGetter(info);
147     TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
148 }
149
150 static void hrefByteStringAttributeSetter(v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
151 {
152     v8::Handle<v8::Object> holder = info.Holder();
153     ExceptionState exceptionState(ExceptionState::SetterContext, "hrefByteString", "TestNode", holder, info.GetIsolate());
154     TestNode* impl = V8TestNode::toNative(holder);
155     TONATIVE_VOID_EXCEPTIONSTATE(V8StringResource<>, cppValue, toByteString(v8Value, exceptionState), exceptionState);
156     impl->setHrefByteString(cppValue);
157 }
158
159 static void hrefByteStringAttributeSetterCallback(v8::Local<v8::String>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
160 {
161     TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMSetter");
162     TestNodeV8Internal::hrefByteStringAttributeSetter(v8Value, info);
163     TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
164 }
165
166 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
167 {
168     RefPtrWillBeRawPtr<TestNode> impl = TestNode::create();
169     v8::Handle<v8::Object> wrapper = info.Holder();
170     V8DOMWrapper::associateObjectWithWrapper<V8TestNode>(impl.release(), &V8TestNode::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Dependent);
171     v8SetReturnValue(info, wrapper);
172 }
173
174 } // namespace TestNodeV8Internal
175
176 static const V8DOMConfiguration::AttributeConfiguration V8TestNodeAttributes[] = {
177     {"href", TestNodeV8Internal::hrefAttributeGetterCallback, TestNodeV8Internal::hrefAttributeSetterCallback, 0, 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInstance},
178     {"hrefThrows", TestNodeV8Internal::hrefThrowsAttributeGetterCallback, TestNodeV8Internal::hrefThrowsAttributeSetterCallback, 0, 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInstance},
179     {"hrefCallWith", TestNodeV8Internal::hrefCallWithAttributeGetterCallback, TestNodeV8Internal::hrefCallWithAttributeSetterCallback, 0, 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInstance},
180     {"hrefByteString", TestNodeV8Internal::hrefByteStringAttributeGetterCallback, TestNodeV8Internal::hrefByteStringAttributeSetterCallback, 0, 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInstance},
181 };
182
183 void V8TestNode::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
184 {
185     TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "DOMConstructor");
186     if (!info.IsConstructCall()) {
187         V8ThrowException::throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("TestNode"), info.GetIsolate());
188         return;
189     }
190
191     if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
192         v8SetReturnValue(info, info.Holder());
193         return;
194     }
195
196     TestNodeV8Internal::constructor(info);
197 }
198
199 static void installV8TestNodeTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate)
200 {
201     functionTemplate->ReadOnlyPrototype();
202
203     v8::Local<v8::Signature> defaultSignature;
204     defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestNode", V8Node::domTemplate(isolate), V8TestNode::internalFieldCount,
205         V8TestNodeAttributes, WTF_ARRAY_LENGTH(V8TestNodeAttributes),
206         0, 0,
207         0, 0,
208         isolate);
209     functionTemplate->SetCallHandler(V8TestNode::constructorCallback);
210     functionTemplate->SetLength(0);
211     v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate();
212     v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate();
213
214     // Custom toString template
215     functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate());
216 }
217
218 v8::Handle<v8::FunctionTemplate> V8TestNode::domTemplate(v8::Isolate* isolate)
219 {
220     return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), installV8TestNodeTemplate);
221 }
222
223 bool V8TestNode::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
224 {
225     return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value);
226 }
227
228 v8::Handle<v8::Object> V8TestNode::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
229 {
230     return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value);
231 }
232
233 TestNode* V8TestNode::toNativeWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value)
234 {
235     return hasInstance(value, isolate) ? fromInternalPointer(blink::toInternalPointer(v8::Handle<v8::Object>::Cast(value))) : 0;
236 }
237
238 EventTarget* V8TestNode::toEventTarget(v8::Handle<v8::Object> object)
239 {
240     return toNative(object);
241 }
242
243 v8::Handle<v8::Object> wrap(TestNode* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
244 {
245     ASSERT(impl);
246     ASSERT(!DOMDataStore::containsWrapper<V8TestNode>(impl, isolate));
247     return V8TestNode::createWrapper(impl, creationContext, isolate);
248 }
249
250 v8::Handle<v8::Object> V8TestNode::createWrapper(PassRefPtrWillBeRawPtr<TestNode> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
251 {
252     ASSERT(impl);
253     ASSERT(!DOMDataStore::containsWrapper<V8TestNode>(impl.get(), isolate));
254     if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
255         const WrapperTypeInfo* actualInfo = ScriptWrappable::fromObject(impl.get())->typeInfo();
256         // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
257         // the same object de-ref functions, though, so use that as the basis of the check.
258         RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
259     }
260
261     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
262     if (UNLIKELY(wrapper.IsEmpty()))
263         return wrapper;
264
265     installConditionallyEnabledProperties(wrapper, isolate);
266     V8DOMWrapper::associateObjectWithWrapper<V8TestNode>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Dependent);
267     return wrapper;
268 }
269
270 void V8TestNode::derefObject(ScriptWrappableBase* internalPointer)
271 {
272 #if !ENABLE(OILPAN)
273     fromInternalPointer(internalPointer)->deref();
274 #endif // !ENABLE(OILPAN)
275 }
276
277 template<>
278 v8::Handle<v8::Value> toV8NoInline(TestNode* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
279 {
280     return toV8(impl, creationContext, isolate);
281 }
282
283 } // namespace blink