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