Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / tests / results / V8TestInterfaceWillBeGarbageCollected.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 "V8TestInterfaceWillBeGarbageCollected.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 "bindings/tests/v8/V8TestInterfaceWillBeGarbageCollected.h"
15 #include "core/dom/ContextFeatures.h"
16 #include "core/dom/Document.h"
17 #include "core/frame/LocalDOMWindow.h"
18 #include "platform/RuntimeEnabledFeatures.h"
19 #include "platform/TraceEvent.h"
20 #include "wtf/GetPtr.h"
21 #include "wtf/RefPtr.h"
22
23 namespace blink {
24
25 static void initializeScriptWrappableForInterface(TestInterfaceWillBeGarbageCollected* object)
26 {
27     if (ScriptWrappable::wrapperCanBeStoredInObject(object))
28         ScriptWrappable::fromObject(object)->setTypeInfo(&V8TestInterfaceWillBeGarbageCollected::wrapperTypeInfo);
29     else
30         ASSERT_NOT_REACHED();
31 }
32
33 } // namespace blink
34
35 void webCoreInitializeScriptWrappableForInterface(blink::TestInterfaceWillBeGarbageCollected* object)
36 {
37     blink::initializeScriptWrappableForInterface(object);
38 }
39
40 namespace blink {
41 const WrapperTypeInfo V8TestInterfaceWillBeGarbageCollected::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceWillBeGarbageCollected::domTemplate, V8TestInterfaceWillBeGarbageCollected::derefObject, 0, V8TestInterfaceWillBeGarbageCollected::toEventTarget, 0, V8TestInterfaceWillBeGarbageCollected::installConditionallyEnabledMethods, &V8EventTarget::wrapperTypeInfo, WrapperTypeObjectPrototype, WillBeGarbageCollectedObject };
42
43 namespace TestInterfaceWillBeGarbageCollectedV8Internal {
44
45 template <typename T> void V8_USE(T) { }
46
47 static void attr1AttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
48 {
49     v8::Handle<v8::Object> holder = info.Holder();
50     TestInterfaceWillBeGarbageCollected* impl = V8TestInterfaceWillBeGarbageCollected::toNative(holder);
51     v8SetReturnValueFast(info, WTF::getPtr(impl->attr1()), impl);
52 }
53
54 static void attr1AttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
55 {
56     TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter");
57     TestInterfaceWillBeGarbageCollectedV8Internal::attr1AttributeGetter(info);
58     TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
59 }
60
61 static void attr1AttributeSetter(v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
62 {
63     v8::Handle<v8::Object> holder = info.Holder();
64     TestInterfaceWillBeGarbageCollected* impl = V8TestInterfaceWillBeGarbageCollected::toNative(holder);
65     TONATIVE_VOID(TestInterfaceWillBeGarbageCollected*, cppValue, V8TestInterfaceWillBeGarbageCollected::toNativeWithTypeCheck(info.GetIsolate(), v8Value));
66     impl->setAttr1(WTF::getPtr(cppValue));
67 }
68
69 static void attr1AttributeSetterCallback(v8::Local<v8::String>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
70 {
71     TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMSetter");
72     TestInterfaceWillBeGarbageCollectedV8Internal::attr1AttributeSetter(v8Value, info);
73     TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
74 }
75
76 static void funcMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
77 {
78     if (UNLIKELY(info.Length() < 1)) {
79         V8ThrowException::throwException(createMinimumArityTypeErrorForMethod("func", "TestInterfaceWillBeGarbageCollected", 1, info.Length(), info.GetIsolate()), info.GetIsolate());
80         return;
81     }
82     TestInterfaceWillBeGarbageCollected* impl = V8TestInterfaceWillBeGarbageCollected::toNative(info.Holder());
83     TestInterfaceWillBeGarbageCollected* arg;
84     {
85         v8::TryCatch block;
86         V8RethrowTryCatchScope rethrow(block);
87         TONATIVE_VOID_INTERNAL(arg, V8TestInterfaceWillBeGarbageCollected::toNativeWithTypeCheck(info.GetIsolate(), info[0]));
88     }
89     impl->func(arg);
90 }
91
92 static void funcMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
93 {
94     TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod");
95     TestInterfaceWillBeGarbageCollectedV8Internal::funcMethod(info);
96     TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
97 }
98
99 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
100 {
101     if (UNLIKELY(info.Length() < 1)) {
102         V8ThrowException::throwException(createMinimumArityTypeErrorForConstructor("TestInterfaceWillBeGarbageCollected", 1, info.Length(), info.GetIsolate()), info.GetIsolate());
103         return;
104     }
105     V8StringResource<> str;
106     {
107         TOSTRING_VOID_INTERNAL(str, info[0]);
108     }
109     RefPtrWillBeRawPtr<TestInterfaceWillBeGarbageCollected> impl = TestInterfaceWillBeGarbageCollected::create(str);
110     v8::Handle<v8::Object> wrapper = info.Holder();
111     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceWillBeGarbageCollected>(impl.release(), &V8TestInterfaceWillBeGarbageCollected::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Independent);
112     v8SetReturnValue(info, wrapper);
113 }
114
115 } // namespace TestInterfaceWillBeGarbageCollectedV8Internal
116
117 static const V8DOMConfiguration::AttributeConfiguration V8TestInterfaceWillBeGarbageCollectedAttributes[] = {
118     {"attr1", TestInterfaceWillBeGarbageCollectedV8Internal::attr1AttributeGetterCallback, TestInterfaceWillBeGarbageCollectedV8Internal::attr1AttributeSetterCallback, 0, 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInstance},
119 };
120
121 static const V8DOMConfiguration::MethodConfiguration V8TestInterfaceWillBeGarbageCollectedMethods[] = {
122     {"func", TestInterfaceWillBeGarbageCollectedV8Internal::funcMethodCallback, 0, 1, V8DOMConfiguration::ExposedToAllScripts},
123 };
124
125 const WrapperTypeInfo V8TestInterfaceWillBeGarbageCollectedConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceWillBeGarbageCollectedConstructor::domTemplate, V8TestInterfaceWillBeGarbageCollected::derefObject, 0, V8TestInterfaceWillBeGarbageCollected::toEventTarget, 0, V8TestInterfaceWillBeGarbageCollected::installConditionallyEnabledMethods, 0, WrapperTypeObjectPrototype, WillBeGarbageCollectedObject };
126
127 static void V8TestInterfaceWillBeGarbageCollectedConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
128 {
129     if (!info.IsConstructCall()) {
130         V8ThrowException::throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("TestInterface"), info.GetIsolate());
131         return;
132     }
133
134     if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
135         v8SetReturnValue(info, info.Holder());
136         return;
137     }
138     if (UNLIKELY(info.Length() < 1)) {
139         V8ThrowException::throwException(createMinimumArityTypeErrorForConstructor("TestInterfaceWillBeGarbageCollected", 1, info.Length(), info.GetIsolate()), info.GetIsolate());
140         return;
141     }
142     V8StringResource<> str;
143     {
144         TOSTRING_VOID_INTERNAL(str, info[0]);
145     }
146     RefPtrWillBeRawPtr<TestInterfaceWillBeGarbageCollected> impl = TestInterfaceWillBeGarbageCollected::createForJSConstructor(str);
147     v8::Handle<v8::Object> wrapper = info.Holder();
148     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceWillBeGarbageCollected>(impl.release(), &V8TestInterfaceWillBeGarbageCollectedConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Independent);
149     v8SetReturnValue(info, wrapper);
150 }
151
152 v8::Handle<v8::FunctionTemplate> V8TestInterfaceWillBeGarbageCollectedConstructor::domTemplate(v8::Isolate* isolate)
153 {
154     static int domTemplateKey; // This address is used for a key to look up the dom template.
155     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
156     v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(&domTemplateKey);
157     if (!result.IsEmpty())
158         return result;
159
160     TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate");
161     result = v8::FunctionTemplate::New(isolate, V8TestInterfaceWillBeGarbageCollectedConstructorCallback);
162     v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate();
163     instanceTemplate->SetInternalFieldCount(V8TestInterfaceWillBeGarbageCollected::internalFieldCount);
164     result->SetClassName(v8AtomicString(isolate, "TestInterfaceWillBeGarbageCollected"));
165     result->Inherit(V8TestInterfaceWillBeGarbageCollected::domTemplate(isolate));
166     data->setDOMTemplate(&domTemplateKey, result);
167     return result;
168 }
169
170 void V8TestInterfaceWillBeGarbageCollected::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
171 {
172     TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "DOMConstructor");
173     if (!info.IsConstructCall()) {
174         V8ThrowException::throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("TestInterfaceWillBeGarbageCollected"), info.GetIsolate());
175         return;
176     }
177
178     if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
179         v8SetReturnValue(info, info.Holder());
180         return;
181     }
182
183     TestInterfaceWillBeGarbageCollectedV8Internal::constructor(info);
184 }
185
186 static void installV8TestInterfaceWillBeGarbageCollectedTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate)
187 {
188     functionTemplate->ReadOnlyPrototype();
189
190     v8::Local<v8::Signature> defaultSignature;
191     defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceWillBeGarbageCollected", V8EventTarget::domTemplate(isolate), V8TestInterfaceWillBeGarbageCollected::internalFieldCount,
192         V8TestInterfaceWillBeGarbageCollectedAttributes, WTF_ARRAY_LENGTH(V8TestInterfaceWillBeGarbageCollectedAttributes),
193         0, 0,
194         V8TestInterfaceWillBeGarbageCollectedMethods, WTF_ARRAY_LENGTH(V8TestInterfaceWillBeGarbageCollectedMethods),
195         isolate);
196     functionTemplate->SetCallHandler(V8TestInterfaceWillBeGarbageCollected::constructorCallback);
197     functionTemplate->SetLength(1);
198     v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate();
199     v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate();
200
201     // Custom toString template
202     functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate());
203 }
204
205 v8::Handle<v8::FunctionTemplate> V8TestInterfaceWillBeGarbageCollected::domTemplate(v8::Isolate* isolate)
206 {
207     return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), installV8TestInterfaceWillBeGarbageCollectedTemplate);
208 }
209
210 bool V8TestInterfaceWillBeGarbageCollected::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
211 {
212     return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value);
213 }
214
215 v8::Handle<v8::Object> V8TestInterfaceWillBeGarbageCollected::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
216 {
217     return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value);
218 }
219
220 TestInterfaceWillBeGarbageCollected* V8TestInterfaceWillBeGarbageCollected::toNativeWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value)
221 {
222     return hasInstance(value, isolate) ? fromInternalPointer(blink::toInternalPointer(v8::Handle<v8::Object>::Cast(value))) : 0;
223 }
224
225 EventTarget* V8TestInterfaceWillBeGarbageCollected::toEventTarget(v8::Handle<v8::Object> object)
226 {
227     return toNative(object);
228 }
229
230 v8::Handle<v8::Object> wrap(TestInterfaceWillBeGarbageCollected* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
231 {
232     ASSERT(impl);
233     ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceWillBeGarbageCollected>(impl, isolate));
234     return V8TestInterfaceWillBeGarbageCollected::createWrapper(impl, creationContext, isolate);
235 }
236
237 v8::Handle<v8::Object> V8TestInterfaceWillBeGarbageCollected::createWrapper(PassRefPtrWillBeRawPtr<TestInterfaceWillBeGarbageCollected> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
238 {
239     ASSERT(impl);
240     ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceWillBeGarbageCollected>(impl.get(), isolate));
241     if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
242         const WrapperTypeInfo* actualInfo = ScriptWrappable::fromObject(impl.get())->typeInfo();
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     installConditionallyEnabledProperties(wrapper, isolate);
253     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceWillBeGarbageCollected>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
254     return wrapper;
255 }
256
257 void V8TestInterfaceWillBeGarbageCollected::derefObject(ScriptWrappableBase* internalPointer)
258 {
259 #if !ENABLE(OILPAN)
260     fromInternalPointer(internalPointer)->deref();
261 #endif // !ENABLE(OILPAN)
262 }
263
264 template<>
265 v8::Handle<v8::Value> toV8NoInline(TestInterfaceWillBeGarbageCollected* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
266 {
267     return toV8(impl, creationContext, isolate);
268 }
269
270 } // namespace blink