Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / tests / results / V8TestInterfacePython2.cpp
1 /*
2  * Copyright (C) 2013 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 // This file has been auto-generated by code_generator_v8.pm. DO NOT MODIFY!
32
33 #include "config.h"
34 #include "V8TestInterfacePython2.h"
35
36 #include "RuntimeEnabledFeatures.h"
37 #include "V8Interface1.h"
38 #include "V8Interface2.h"
39 #include "bindings/v8/ExceptionState.h"
40 #include "bindings/v8/V8DOMConfiguration.h"
41 #include "bindings/v8/V8GCController.h"
42 #include "bindings/v8/V8ObjectConstructor.h"
43 #include "core/dom/ContextFeatures.h"
44 #include "core/dom/Document.h"
45 #include "core/dom/Element.h"
46 #include "platform/TraceEvent.h"
47
48 namespace WebCore {
49
50 static void initializeScriptWrappableForInterface(TestInterfacePython2* object)
51 {
52     if (ScriptWrappable::wrapperCanBeStoredInObject(object))
53         ScriptWrappable::setTypeInfoInObject(object, &V8TestInterfacePython2::wrapperTypeInfo);
54     else
55         ASSERT_NOT_REACHED();
56 }
57
58 } // namespace WebCore
59
60 // In ScriptWrappable::init, the use of a local function declaration has an issue on Windows:
61 // the local declaration does not pick up the surrounding namespace. Therefore, we provide this function
62 // in the global namespace.
63 // (More info on the MSVC bug here: http://connect.microsoft.com/VisualStudio/feedback/details/664619/the-namespace-of-local-function-declarations-in-c)
64 void webCoreInitializeScriptWrappableForInterface(WebCore::TestInterfacePython2* object)
65 {
66     WebCore::initializeScriptWrappableForInterface(object);
67 }
68
69 namespace WebCore {
70 const WrapperTypeInfo V8TestInterfacePython2::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfacePython2::domTemplate, V8TestInterfacePython2::derefObject, 0, 0, V8TestInterfacePython2::visitDOMWrapper, V8TestInterfacePython2::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype };
71
72 namespace TestInterfacePython2V8Internal {
73
74 template <typename T> void V8_USE(T) { }
75
76 } // namespace TestInterfacePython2V8Internal
77
78 void V8TestInterfacePython2::visitDOMWrapper(void* object, const v8::Persistent<v8::Object>& wrapper, v8::Isolate* isolate)
79 {
80     TestInterfacePython2* impl = fromInternalPointer(object);
81     if (Node* owner = impl->ownerNode()) {
82         Node* root = V8GCController::opaqueRootForGC(owner, isolate);
83         isolate->SetReferenceFromGroup(v8::UniqueId(reinterpret_cast<intptr_t>(root)), wrapper);
84         return;
85     }
86     setObjectGroup(object, wrapper, isolate);
87 }
88
89 static void configureV8TestInterfacePython2Template(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate, WrapperWorldType currentWorldType)
90 {
91     functionTemplate->ReadOnlyPrototype();
92
93     v8::Local<v8::Signature> defaultSignature;
94     defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfacePython2", v8::Local<v8::FunctionTemplate>(), V8TestInterfacePython2::internalFieldCount,
95         0, 0,
96         0, 0,
97         0, 0,
98         isolate, currentWorldType);
99     v8::Local<v8::ObjectTemplate> ALLOW_UNUSED instanceTemplate = functionTemplate->InstanceTemplate();
100     v8::Local<v8::ObjectTemplate> ALLOW_UNUSED prototypeTemplate = functionTemplate->PrototypeTemplate();
101
102     // Custom toString template
103     functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::current()->toStringTemplate());
104 }
105
106 v8::Handle<v8::FunctionTemplate> V8TestInterfacePython2::domTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
107 {
108     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
109     V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWorldType).find(&wrapperTypeInfo);
110     if (result != data->templateMap(currentWorldType).end())
111         return result->value.newLocal(isolate);
112
113     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
114     v8::EscapableHandleScope handleScope(isolate);
115     v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidConstructorMode);
116     configureV8TestInterfacePython2Template(templ, isolate, currentWorldType);
117     data->templateMap(currentWorldType).add(&wrapperTypeInfo, UnsafePersistent<v8::FunctionTemplate>(isolate, templ));
118     return handleScope.Escape(templ);
119 }
120
121 bool V8TestInterfacePython2::hasInstance(v8::Handle<v8::Value> jsValue, v8::Isolate* isolate)
122 {
123     return V8PerIsolateData::from(isolate)->hasInstanceInMainWorld(&wrapperTypeInfo, jsValue)
124         || V8PerIsolateData::from(isolate)->hasInstanceInNonMainWorld(&wrapperTypeInfo, jsValue);
125 }
126
127 v8::Handle<v8::Object> wrap(TestInterfacePython2* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
128 {
129     ASSERT(impl);
130     if (impl->isInterface1())
131         return wrap(toInterface1(impl), creationContext, isolate);
132     if (impl->isInterface2())
133         return wrap(toInterface2(impl), creationContext, isolate);
134     v8::Handle<v8::Object> wrapper = V8TestInterfacePython2::createWrapper(impl, creationContext, isolate);
135     return wrapper;
136 }
137
138 v8::Handle<v8::Object> V8TestInterfacePython2::createWrapper(PassRefPtr<TestInterfacePython2> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
139 {
140     ASSERT(impl);
141     ASSERT(!DOMDataStore::containsWrapper<V8TestInterfacePython2>(impl.get(), isolate));
142     if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
143         const WrapperTypeInfo* actualInfo = ScriptWrappable::getTypeInfoFromObject(impl.get());
144         // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
145         // the same object de-ref functions, though, so use that as the basis of the check.
146         RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
147     }
148
149     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
150     if (UNLIKELY(wrapper.IsEmpty()))
151         return wrapper;
152
153     installPerContextEnabledProperties(wrapper, impl.get(), isolate);
154     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfacePython2>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Dependent);
155     return wrapper;
156 }
157
158 void V8TestInterfacePython2::derefObject(void* object)
159 {
160     fromInternalPointer(object)->deref();
161 }
162
163 template<>
164 v8::Handle<v8::Value> toV8NoInline(TestInterfacePython2* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
165 {
166     return toV8(impl, creationContext, isolate);
167 }
168
169 } // namespace WebCore