Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / tests / results / V8TestInterfaceConstructor.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 "V8TestInterfaceConstructor.h"
35
36 #include "RuntimeEnabledFeatures.h"
37 #include "V8TestInterfaceEmpty.h"
38 #include "bindings/v8/Dictionary.h"
39 #include "bindings/v8/ExceptionState.h"
40 #include "bindings/v8/V8DOMConfiguration.h"
41 #include "bindings/v8/V8ObjectConstructor.h"
42 #include "core/dom/ContextFeatures.h"
43 #include "core/dom/Document.h"
44 #include "core/frame/UseCounter.h"
45 #include "platform/TraceEvent.h"
46 #include "wtf/GetPtr.h"
47 #include "wtf/RefPtr.h"
48
49 namespace WebCore {
50
51 static void initializeScriptWrappableForInterface(TestInterfaceConstructor* object)
52 {
53     if (ScriptWrappable::wrapperCanBeStoredInObject(object))
54         ScriptWrappable::setTypeInfoInObject(object, &V8TestInterfaceConstructor::wrapperTypeInfo);
55     else
56         ASSERT_NOT_REACHED();
57 }
58
59 } // namespace WebCore
60
61 // In ScriptWrappable::init, the use of a local function declaration has an issue on Windows:
62 // the local declaration does not pick up the surrounding namespace. Therefore, we provide this function
63 // in the global namespace.
64 // (More info on the MSVC bug here: http://connect.microsoft.com/VisualStudio/feedback/details/664619/the-namespace-of-local-function-declarations-in-c)
65 void webCoreInitializeScriptWrappableForInterface(WebCore::TestInterfaceConstructor* object)
66 {
67     WebCore::initializeScriptWrappableForInterface(object);
68 }
69
70 namespace WebCore {
71 const WrapperTypeInfo V8TestInterfaceConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceConstructor::domTemplate, V8TestInterfaceConstructor::derefObject, 0, 0, 0, V8TestInterfaceConstructor::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype, false };
72
73 namespace TestInterfaceConstructorV8Internal {
74
75 template <typename T> void V8_USE(T) { }
76
77 static void constructor1(const v8::FunctionCallbackInfo<v8::Value>& info)
78 {
79     ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
80     ExecutionContext* context = currentExecutionContext(info.GetIsolate());
81     Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
82     RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(context, document, exceptionState);
83     v8::Handle<v8::Object> wrapper = info.Holder();
84     if (exceptionState.throwIfNeeded())
85         return;
86
87     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.release(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Dependent);
88     v8SetReturnValue(info, wrapper);
89 }
90
91 static void constructor2(const v8::FunctionCallbackInfo<v8::Value>& info)
92 {
93     ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
94     V8TRYCATCH_VOID(double, doubleArg, static_cast<double>(info[0]->NumberValue()));
95     V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, stringArg, info[1]);
96     V8TRYCATCH_VOID(TestInterfaceEmpty*, testInterfaceEmptyArg, V8TestInterfaceEmpty::hasInstance(info[2], info.GetIsolate()) ? V8TestInterfaceEmpty::toNative(v8::Handle<v8::Object>::Cast(info[2])) : 0);
97     V8TRYCATCH_VOID(Dictionary, dictionaryArg, Dictionary(info[3], info.GetIsolate()));
98     if (!dictionaryArg.isUndefinedOrNull() && !dictionaryArg.isObject()) {
99         exceptionState.throwTypeError("parameter 4 ('dictionaryArg') is not an object.");
100         exceptionState.throwIfNeeded();
101         return;
102     }
103     V8TRYCATCH_VOID(Vector<String>, sequenceStringArg, toNativeArray<String>(info[4], 5, info.GetIsolate()));
104     V8TRYCATCH_VOID(Dictionary, optionalDictionaryArg, Dictionary(info[5], info.GetIsolate()));
105     if (!optionalDictionaryArg.isUndefinedOrNull() && !optionalDictionaryArg.isObject()) {
106         exceptionState.throwTypeError("parameter 6 ('optionalDictionaryArg') is not an object.");
107         exceptionState.throwIfNeeded();
108         return;
109     }
110     V8TRYCATCH_VOID(TestInterfaceEmpty*, optionalTestInterfaceEmptyArg, V8TestInterfaceEmpty::hasInstance(info[6], info.GetIsolate()) ? V8TestInterfaceEmpty::toNative(v8::Handle<v8::Object>::Cast(info[6])) : 0);
111     ExecutionContext* context = currentExecutionContext(info.GetIsolate());
112     Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
113     RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(context, document, doubleArg, stringArg, testInterfaceEmptyArg, dictionaryArg, sequenceStringArg, optionalDictionaryArg, optionalTestInterfaceEmptyArg, exceptionState);
114     v8::Handle<v8::Object> wrapper = info.Holder();
115     if (exceptionState.throwIfNeeded())
116         return;
117
118     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.release(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Dependent);
119     v8SetReturnValue(info, wrapper);
120 }
121
122 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
123 {
124     if (((info.Length() == 0))) {
125         TestInterfaceConstructorV8Internal::constructor1(info);
126         return;
127     }
128     if (((info.Length() == 5) && (V8TestInterfaceEmpty::hasInstance(info[2], info.GetIsolate())) && (info[3]->IsObject()) && (info[4]->IsArray())) || ((info.Length() == 6) && (V8TestInterfaceEmpty::hasInstance(info[2], info.GetIsolate())) && (info[3]->IsObject()) && (info[4]->IsArray()) && (info[5]->IsUndefined() || info[5]->IsObject())) || ((info.Length() == 7) && (V8TestInterfaceEmpty::hasInstance(info[2], info.GetIsolate())) && (info[3]->IsObject()) && (info[4]->IsArray()) && (info[5]->IsUndefined() || info[5]->IsObject()) && (V8TestInterfaceEmpty::hasInstance(info[6], info.GetIsolate())))) {
129         TestInterfaceConstructorV8Internal::constructor2(info);
130         return;
131     }
132     throwTypeError(ExceptionMessages::failedToConstruct("TestInterfaceConstructor", "No matching constructor signature."), info.GetIsolate());
133 }
134
135 } // namespace TestInterfaceConstructorV8Internal
136
137 void V8TestInterfaceConstructor::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
138 {
139     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "DOMConstructor");
140     UseCounter::count(activeExecutionContext(info.GetIsolate()), UseCounter::TestFeature);
141     if (!info.IsConstructCall()) {
142         throwTypeError(ExceptionMessages::failedToConstruct("TestInterfaceConstructor", "Please use the 'new' operator, this DOM object constructor cannot be called as a function."), info.GetIsolate());
143         return;
144     }
145
146     if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) {
147         v8SetReturnValue(info, info.Holder());
148         return;
149     }
150
151     TestInterfaceConstructorV8Internal::constructor(info);
152 }
153
154 static void configureV8TestInterfaceConstructorTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate, WrapperWorldType currentWorldType)
155 {
156     functionTemplate->ReadOnlyPrototype();
157
158     v8::Local<v8::Signature> defaultSignature;
159     defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceConstructor", v8::Local<v8::FunctionTemplate>(), V8TestInterfaceConstructor::internalFieldCount,
160         0, 0,
161         0, 0,
162         0, 0,
163         isolate, currentWorldType);
164     functionTemplate->SetCallHandler(V8TestInterfaceConstructor::constructorCallback);
165     functionTemplate->SetLength(0);
166     v8::Local<v8::ObjectTemplate> ALLOW_UNUSED instanceTemplate = functionTemplate->InstanceTemplate();
167     v8::Local<v8::ObjectTemplate> ALLOW_UNUSED prototypeTemplate = functionTemplate->PrototypeTemplate();
168
169     // Custom toString template
170     functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::current()->toStringTemplate());
171 }
172
173 v8::Handle<v8::FunctionTemplate> V8TestInterfaceConstructor::domTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
174 {
175     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
176     V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWorldType).find(&wrapperTypeInfo);
177     if (result != data->templateMap(currentWorldType).end())
178         return result->value.newLocal(isolate);
179
180     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
181     v8::EscapableHandleScope handleScope(isolate);
182     v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidConstructorMode);
183     configureV8TestInterfaceConstructorTemplate(templ, isolate, currentWorldType);
184     data->templateMap(currentWorldType).add(&wrapperTypeInfo, UnsafePersistent<v8::FunctionTemplate>(isolate, templ));
185     return handleScope.Escape(templ);
186 }
187
188 bool V8TestInterfaceConstructor::hasInstance(v8::Handle<v8::Value> jsValue, v8::Isolate* isolate)
189 {
190     return V8PerIsolateData::from(isolate)->hasInstanceInMainWorld(&wrapperTypeInfo, jsValue)
191         || V8PerIsolateData::from(isolate)->hasInstanceInNonMainWorld(&wrapperTypeInfo, jsValue);
192 }
193
194 v8::Handle<v8::Object> V8TestInterfaceConstructor::createWrapper(PassRefPtr<TestInterfaceConstructor> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
195 {
196     ASSERT(impl);
197     ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceConstructor>(impl.get(), isolate));
198     if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
199         const WrapperTypeInfo* actualInfo = ScriptWrappable::getTypeInfoFromObject(impl.get());
200         // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
201         // the same object de-ref functions, though, so use that as the basis of the check.
202         RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
203     }
204
205     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
206     if (UNLIKELY(wrapper.IsEmpty()))
207         return wrapper;
208
209     installPerContextEnabledProperties(wrapper, impl.get(), isolate);
210     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
211     return wrapper;
212 }
213
214 void V8TestInterfaceConstructor::derefObject(void* object)
215 {
216     fromInternalPointer(object)->deref();
217 }
218
219 template<>
220 v8::Handle<v8::Value> toV8NoInline(TestInterfaceConstructor* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
221 {
222     return toV8(impl, creationContext, isolate);
223 }
224
225 } // namespace WebCore