Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / tests / results / V8TestInterfaceEventTarget.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 "V8TestInterfaceEventTarget.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(TestInterfaceEventTarget* object)
25 {
26     if (ScriptWrappable::wrapperCanBeStoredInObject(object))
27         ScriptWrappable::fromObject(object)->setTypeInfo(&V8TestInterfaceEventTarget::wrapperTypeInfo);
28     else
29         ASSERT_NOT_REACHED();
30 }
31
32 } // namespace WebCore
33
34 void webCoreInitializeScriptWrappableForInterface(WebCore::TestInterfaceEventTarget* object)
35 {
36     WebCore::initializeScriptWrappableForInterface(object);
37 }
38
39 namespace WebCore {
40 const WrapperTypeInfo V8TestInterfaceEventTarget::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceEventTarget::domTemplate, V8TestInterfaceEventTarget::derefObject, 0, V8TestInterfaceEventTarget::toEventTarget, 0, V8TestInterfaceEventTarget::installPerContextEnabledMethods, &V8EventTarget::wrapperTypeInfo, WrapperTypeObjectPrototype, RefCountedObject };
41
42 namespace TestInterfaceEventTargetV8Internal {
43
44 template <typename T> void V8_USE(T) { }
45
46 } // namespace TestInterfaceEventTargetV8Internal
47
48 const WrapperTypeInfo V8TestInterfaceEventTargetConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceEventTargetConstructor::domTemplate, V8TestInterfaceEventTarget::derefObject, 0, V8TestInterfaceEventTarget::toEventTarget, 0, V8TestInterfaceEventTarget::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype, RefCountedObject };
49
50 static void V8TestInterfaceEventTargetConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
51 {
52     v8::Isolate* isolate = info.GetIsolate();
53     if (!info.IsConstructCall()) {
54         throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("Name"), isolate);
55         return;
56     }
57
58     if (ConstructorMode::current(isolate) == ConstructorMode::WrapExistingObject) {
59         v8SetReturnValue(info, info.Holder());
60         return;
61     }
62
63     Document* document = currentDOMWindow(isolate)->document();
64     ASSERT(document);
65
66     // Make sure the document is added to the DOM Node map. Otherwise, the TestInterfaceEventTarget instance
67     // may end up being the only node in the map and get garbage-collected prematurely.
68     toV8(document, info.Holder(), isolate);
69
70     RefPtr<TestInterfaceEventTarget> impl = TestInterfaceEventTarget::createForJSConstructor(*document);
71
72     v8::Handle<v8::Object> wrapper = info.Holder();
73     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceEventTarget>(impl.release(), &V8TestInterfaceEventTargetConstructor::wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
74     v8SetReturnValue(info, wrapper);
75 }
76
77 v8::Handle<v8::FunctionTemplate> V8TestInterfaceEventTargetConstructor::domTemplate(v8::Isolate* isolate)
78 {
79     static int domTemplateKey; // This address is used for a key to look up the dom template.
80     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
81     v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(&domTemplateKey);
82     if (!result.IsEmpty())
83         return result;
84
85     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
86     result = v8::FunctionTemplate::New(isolate, V8TestInterfaceEventTargetConstructorCallback);
87     v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate();
88     instanceTemplate->SetInternalFieldCount(V8TestInterfaceEventTarget::internalFieldCount);
89     result->SetClassName(v8AtomicString(isolate, "TestInterfaceEventTarget"));
90     result->Inherit(V8TestInterfaceEventTarget::domTemplate(isolate));
91     data->setDOMTemplate(&domTemplateKey, result);
92     return result;
93 }
94
95 static void configureV8TestInterfaceEventTargetTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate)
96 {
97     functionTemplate->ReadOnlyPrototype();
98
99     v8::Local<v8::Signature> defaultSignature;
100     defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceEventTarget", V8EventTarget::domTemplate(isolate), V8TestInterfaceEventTarget::internalFieldCount,
101         0, 0,
102         0, 0,
103         0, 0,
104         isolate);
105     v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate();
106     v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate();
107
108     // Custom toString template
109     functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate());
110 }
111
112 v8::Handle<v8::FunctionTemplate> V8TestInterfaceEventTarget::domTemplate(v8::Isolate* isolate)
113 {
114     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
115     v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(const_cast<WrapperTypeInfo*>(&wrapperTypeInfo));
116     if (!result.IsEmpty())
117         return result;
118
119     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
120     result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidConstructorMode);
121     configureV8TestInterfaceEventTargetTemplate(result, isolate);
122     data->setDOMTemplate(const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), result);
123     return result;
124 }
125
126 bool V8TestInterfaceEventTarget::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
127 {
128     return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value);
129 }
130
131 v8::Handle<v8::Object> V8TestInterfaceEventTarget::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
132 {
133     return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value);
134 }
135
136 TestInterfaceEventTarget* V8TestInterfaceEventTarget::toNativeWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value)
137 {
138     return hasInstance(value, isolate) ? fromInternalPointer(v8::Handle<v8::Object>::Cast(value)->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex)) : 0;
139 }
140
141 EventTarget* V8TestInterfaceEventTarget::toEventTarget(v8::Handle<v8::Object> object)
142 {
143     return toNative(object);
144 }
145
146 v8::Handle<v8::Object> V8TestInterfaceEventTarget::createWrapper(PassRefPtr<TestInterfaceEventTarget> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
147 {
148     ASSERT(impl);
149     ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceEventTarget>(impl.get(), isolate));
150     if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
151         const WrapperTypeInfo* actualInfo = ScriptWrappable::fromObject(impl.get())->typeInfo();
152         // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
153         // the same object de-ref functions, though, so use that as the basis of the check.
154         RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
155     }
156
157     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
158     if (UNLIKELY(wrapper.IsEmpty()))
159         return wrapper;
160
161     installPerContextEnabledProperties(wrapper, impl.get(), isolate);
162     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceEventTarget>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
163     return wrapper;
164 }
165
166 void V8TestInterfaceEventTarget::derefObject(void* object)
167 {
168     fromInternalPointer(object)->deref();
169 }
170
171 template<>
172 v8::Handle<v8::Value> toV8NoInline(TestInterfaceEventTarget* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
173 {
174     return toV8(impl, creationContext, isolate);
175 }
176
177 } // namespace WebCore