Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / tests / results / V8TestInterfaceGarbageCollected.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 "V8TestInterfaceGarbageCollected.h"
9
10 #include "RuntimeEnabledFeatures.h"
11 #include "bindings/v8/ExceptionState.h"
12 #include "bindings/v8/V8DOMConfiguration.h"
13 #include "bindings/v8/V8HiddenValue.h"
14 #include "bindings/v8/V8ObjectConstructor.h"
15 #include "core/dom/ContextFeatures.h"
16 #include "core/dom/Document.h"
17 #include "core/frame/DOMWindow.h"
18 #include "platform/TraceEvent.h"
19 #include "wtf/GetPtr.h"
20 #include "wtf/RefPtr.h"
21
22 namespace WebCore {
23
24 static void initializeScriptWrappableForInterface(TestInterfaceGarbageCollected* object)
25 {
26     if (ScriptWrappable::wrapperCanBeStoredInObject(object))
27         ScriptWrappable::fromObject(object)->setTypeInfo(&V8TestInterfaceGarbageCollected::wrapperTypeInfo);
28     else
29         ASSERT_NOT_REACHED();
30 }
31
32 } // namespace WebCore
33
34 void webCoreInitializeScriptWrappableForInterface(WebCore::TestInterfaceGarbageCollected* object)
35 {
36     WebCore::initializeScriptWrappableForInterface(object);
37 }
38
39 namespace WebCore {
40 const WrapperTypeInfo V8TestInterfaceGarbageCollected::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceGarbageCollected::domTemplate, V8TestInterfaceGarbageCollected::derefObject, 0, V8TestInterfaceGarbageCollected::toEventTarget, 0, V8TestInterfaceGarbageCollected::installPerContextEnabledMethods, &V8EventTarget::wrapperTypeInfo, WrapperTypeObjectPrototype, GarbageCollectedObject };
41
42 namespace TestInterfaceGarbageCollectedV8Internal {
43
44 template <typename T> void V8_USE(T) { }
45
46 static void attr1AttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
47 {
48     v8::Handle<v8::Object> holder = info.Holder();
49     TestInterfaceGarbageCollected* impl = V8TestInterfaceGarbageCollected::toNative(holder);
50     v8SetReturnValueFast(info, WTF::getPtr(impl->attr1()), impl);
51 }
52
53 static void attr1AttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
54 {
55     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
56     TestInterfaceGarbageCollectedV8Internal::attr1AttributeGetter(info);
57     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
58 }
59
60 static void attr1AttributeSetter(v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
61 {
62     v8::Handle<v8::Object> holder = info.Holder();
63     TestInterfaceGarbageCollected* impl = V8TestInterfaceGarbageCollected::toNative(holder);
64     TONATIVE_VOID(TestInterfaceGarbageCollected*, cppValue, V8TestInterfaceGarbageCollected::toNativeWithTypeCheck(info.GetIsolate(), v8Value));
65     impl->setAttr1(WTF::getPtr(cppValue));
66 }
67
68 static void attr1AttributeSetterCallback(v8::Local<v8::String>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
69 {
70     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMSetter");
71     TestInterfaceGarbageCollectedV8Internal::attr1AttributeSetter(v8Value, info);
72     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
73 }
74
75 static void funcMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
76 {
77     if (UNLIKELY(info.Length() < 1)) {
78         throwArityTypeErrorForMethod("func", "TestInterfaceGarbageCollected", 1, info.Length(), info.GetIsolate());
79         return;
80     }
81     TestInterfaceGarbageCollected* impl = V8TestInterfaceGarbageCollected::toNative(info.Holder());
82     TONATIVE_VOID(TestInterfaceGarbageCollected*, arg, V8TestInterfaceGarbageCollected::toNativeWithTypeCheck(info.GetIsolate(), info[0]));
83     impl->func(arg);
84 }
85
86 static void funcMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
87 {
88     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
89     TestInterfaceGarbageCollectedV8Internal::funcMethod(info);
90     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
91 }
92
93 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
94 {
95     v8::Isolate* isolate = info.GetIsolate();
96     if (UNLIKELY(info.Length() < 1)) {
97         throwArityTypeErrorForConstructor("TestInterfaceGarbageCollected", 1, info.Length(), info.GetIsolate());
98         return;
99     }
100     TOSTRING_VOID(V8StringResource<>, str, info[0]);
101     RawPtr<TestInterfaceGarbageCollected> impl = TestInterfaceGarbageCollected::create(str);
102
103     v8::Handle<v8::Object> wrapper = info.Holder();
104     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceGarbageCollected>(impl.release(), &V8TestInterfaceGarbageCollected::wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
105     v8SetReturnValue(info, wrapper);
106 }
107
108 } // namespace TestInterfaceGarbageCollectedV8Internal
109
110 static const V8DOMConfiguration::AttributeConfiguration V8TestInterfaceGarbageCollectedAttributes[] = {
111     {"attr1", TestInterfaceGarbageCollectedV8Internal::attr1AttributeGetterCallback, TestInterfaceGarbageCollectedV8Internal::attr1AttributeSetterCallback, 0, 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
112 };
113
114 static const V8DOMConfiguration::MethodConfiguration V8TestInterfaceGarbageCollectedMethods[] = {
115     {"func", TestInterfaceGarbageCollectedV8Internal::funcMethodCallback, 0, 1},
116 };
117
118 void V8TestInterfaceGarbageCollected::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
119 {
120     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "DOMConstructor");
121     if (!info.IsConstructCall()) {
122         throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("TestInterfaceGarbageCollected"), info.GetIsolate());
123         return;
124     }
125
126     if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
127         v8SetReturnValue(info, info.Holder());
128         return;
129     }
130
131     TestInterfaceGarbageCollectedV8Internal::constructor(info);
132 }
133
134 static void configureV8TestInterfaceGarbageCollectedTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate)
135 {
136     functionTemplate->ReadOnlyPrototype();
137
138     v8::Local<v8::Signature> defaultSignature;
139     defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceGarbageCollected", V8EventTarget::domTemplate(isolate), V8TestInterfaceGarbageCollected::internalFieldCount,
140         V8TestInterfaceGarbageCollectedAttributes, WTF_ARRAY_LENGTH(V8TestInterfaceGarbageCollectedAttributes),
141         0, 0,
142         V8TestInterfaceGarbageCollectedMethods, WTF_ARRAY_LENGTH(V8TestInterfaceGarbageCollectedMethods),
143         isolate);
144     functionTemplate->SetCallHandler(V8TestInterfaceGarbageCollected::constructorCallback);
145     functionTemplate->SetLength(1);
146     v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate();
147     v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate();
148
149     // Custom toString template
150     functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate());
151 }
152
153 v8::Handle<v8::FunctionTemplate> V8TestInterfaceGarbageCollected::domTemplate(v8::Isolate* isolate)
154 {
155     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
156     v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(const_cast<WrapperTypeInfo*>(&wrapperTypeInfo));
157     if (!result.IsEmpty())
158         return result;
159
160     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
161     result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidConstructorMode);
162     configureV8TestInterfaceGarbageCollectedTemplate(result, isolate);
163     data->setDOMTemplate(const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), result);
164     return result;
165 }
166
167 bool V8TestInterfaceGarbageCollected::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
168 {
169     return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value);
170 }
171
172 v8::Handle<v8::Object> V8TestInterfaceGarbageCollected::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
173 {
174     return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value);
175 }
176
177 TestInterfaceGarbageCollected* V8TestInterfaceGarbageCollected::toNativeWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value)
178 {
179     return hasInstance(value, isolate) ? fromInternalPointer(v8::Handle<v8::Object>::Cast(value)->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex)) : 0;
180 }
181
182 EventTarget* V8TestInterfaceGarbageCollected::toEventTarget(v8::Handle<v8::Object> object)
183 {
184     return toNative(object);
185 }
186
187 v8::Handle<v8::Object> V8TestInterfaceGarbageCollected::createWrapper(RawPtr<TestInterfaceGarbageCollected> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
188 {
189     ASSERT(impl);
190     ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceGarbageCollected>(impl.get(), isolate));
191     if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
192         const WrapperTypeInfo* actualInfo = ScriptWrappable::fromObject(impl.get())->typeInfo();
193         // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
194         // the same object de-ref functions, though, so use that as the basis of the check.
195         RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
196     }
197
198     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
199     if (UNLIKELY(wrapper.IsEmpty()))
200         return wrapper;
201
202     installPerContextEnabledProperties(wrapper, impl.get(), isolate);
203     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceGarbageCollected>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
204     return wrapper;
205 }
206
207 void V8TestInterfaceGarbageCollected::derefObject(void* object)
208 {
209 }
210
211 template<>
212 v8::Handle<v8::Value> toV8NoInline(TestInterfaceGarbageCollected* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
213 {
214     return toV8(impl, creationContext, isolate);
215 }
216
217 } // namespace WebCore