Upstream version 8.37.180.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / tests / results / V8TestInterfaceConstructor.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 "V8TestInterfaceConstructor.h"
9
10 #include "bindings/tests/v8/V8TestInterfaceEmpty.h"
11 #include "bindings/v8/Dictionary.h"
12 #include "bindings/v8/ExceptionState.h"
13 #include "bindings/v8/V8DOMConfiguration.h"
14 #include "bindings/v8/V8HiddenValue.h"
15 #include "bindings/v8/V8ObjectConstructor.h"
16 #include "core/dom/ContextFeatures.h"
17 #include "core/dom/Document.h"
18 #include "core/frame/LocalDOMWindow.h"
19 #include "core/frame/UseCounter.h"
20 #include "platform/RuntimeEnabledFeatures.h"
21 #include "platform/TraceEvent.h"
22 #include "wtf/GetPtr.h"
23 #include "wtf/RefPtr.h"
24
25 namespace WebCore {
26
27 static void initializeScriptWrappableForInterface(TestInterfaceConstructor* object)
28 {
29     if (ScriptWrappable::wrapperCanBeStoredInObject(object))
30         ScriptWrappable::fromObject(object)->setTypeInfo(&V8TestInterfaceConstructor::wrapperTypeInfo);
31     else
32         ASSERT_NOT_REACHED();
33 }
34
35 } // namespace WebCore
36
37 void webCoreInitializeScriptWrappableForInterface(WebCore::TestInterfaceConstructor* object)
38 {
39     WebCore::initializeScriptWrappableForInterface(object);
40 }
41
42 namespace WebCore {
43 const WrapperTypeInfo V8TestInterfaceConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceConstructor::domTemplate, V8TestInterfaceConstructor::derefObject, 0, 0, 0, V8TestInterfaceConstructor::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype, RefCountedObject };
44
45 namespace TestInterfaceConstructorV8Internal {
46
47 template <typename T> void V8_USE(T) { }
48
49 static void constructor1(const v8::FunctionCallbackInfo<v8::Value>& info)
50 {
51     v8::Isolate* isolate = info.GetIsolate();
52     ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), isolate);
53     ExecutionContext* executionContext = currentExecutionContext(isolate);
54     Document& document = *toDocument(currentExecutionContext(isolate));
55     RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(executionContext, document, exceptionState);
56     if (exceptionState.throwIfNeeded())
57         return;
58
59     v8::Handle<v8::Object> wrapper = info.Holder();
60     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.release(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
61     v8SetReturnValue(info, wrapper);
62 }
63
64 static void constructor2(const v8::FunctionCallbackInfo<v8::Value>& info)
65 {
66     v8::Isolate* isolate = info.GetIsolate();
67     ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), isolate);
68     double doubleArg;
69     V8StringResource<> stringArg;
70     TestInterfaceEmpty* testInterfaceEmptyArg;
71     Dictionary dictionaryArg;
72     Vector<String> sequenceStringArg;
73     Vector<Dictionary> sequenceDictionaryArg;
74     Dictionary optionalDictionaryArg;
75     TestInterfaceEmpty* optionalTestInterfaceEmptyArg;
76     {
77         v8::TryCatch block;
78         V8RethrowTryCatchScope rethrow(block);
79         TONATIVE_VOID_INTERNAL(doubleArg, static_cast<double>(info[0]->NumberValue()));
80         TOSTRING_VOID_INTERNAL(stringArg, info[1]);
81         TONATIVE_VOID_INTERNAL(testInterfaceEmptyArg, V8TestInterfaceEmpty::toNativeWithTypeCheck(info.GetIsolate(), info[2]));
82         TONATIVE_VOID_INTERNAL(dictionaryArg, Dictionary(info[3], info.GetIsolate()));
83         if (!dictionaryArg.isUndefinedOrNull() && !dictionaryArg.isObject()) {
84             exceptionState.throwTypeError("parameter 4 ('dictionaryArg') is not an object.");
85             exceptionState.throwIfNeeded();
86             return;
87         }
88         TONATIVE_VOID_INTERNAL(sequenceStringArg, toNativeArray<String>(info[4], 5, info.GetIsolate()));
89         TONATIVE_VOID_INTERNAL(sequenceDictionaryArg, toNativeArray<Dictionary>(info[5], 6, info.GetIsolate()));
90         TONATIVE_VOID_INTERNAL(optionalDictionaryArg, Dictionary(info[6], info.GetIsolate()));
91         if (!optionalDictionaryArg.isUndefinedOrNull() && !optionalDictionaryArg.isObject()) {
92             exceptionState.throwTypeError("parameter 7 ('optionalDictionaryArg') is not an object.");
93             exceptionState.throwIfNeeded();
94             return;
95         }
96         TONATIVE_VOID_INTERNAL(optionalTestInterfaceEmptyArg, V8TestInterfaceEmpty::toNativeWithTypeCheck(info.GetIsolate(), info[7]));
97     }
98     ExecutionContext* executionContext = currentExecutionContext(isolate);
99     Document& document = *toDocument(currentExecutionContext(isolate));
100     RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(executionContext, document, doubleArg, stringArg, testInterfaceEmptyArg, dictionaryArg, sequenceStringArg, sequenceDictionaryArg, optionalDictionaryArg, optionalTestInterfaceEmptyArg, exceptionState);
101     if (exceptionState.throwIfNeeded())
102         return;
103
104     v8::Handle<v8::Object> wrapper = info.Holder();
105     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.release(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
106     v8SetReturnValue(info, wrapper);
107 }
108
109 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
110 {
111     v8::Isolate* isolate = info.GetIsolate();
112     ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), isolate);
113     switch (std::min(8, info.Length())) {
114     case 0:
115         if (true) {
116             TestInterfaceConstructorV8Internal::constructor1(info);
117             return;
118         }
119         break;
120     case 6:
121         if (true) {
122             TestInterfaceConstructorV8Internal::constructor2(info);
123             return;
124         }
125         break;
126     case 7:
127         if (true) {
128             TestInterfaceConstructorV8Internal::constructor2(info);
129             return;
130         }
131         break;
132     case 8:
133         if (true) {
134             TestInterfaceConstructorV8Internal::constructor2(info);
135             return;
136         }
137         break;
138     default:
139         if (info.Length() >= 0) {
140             throwArityTypeError(exceptionState, "[0, 6, 7, 8]", info.Length());
141             return;
142         }
143         exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(0, info.Length()));
144         exceptionState.throwIfNeeded();
145         return;
146     }
147     exceptionState.throwTypeError("No matching constructor signature.");
148     exceptionState.throwIfNeeded();
149 }
150
151 } // namespace TestInterfaceConstructorV8Internal
152
153 void V8TestInterfaceConstructor::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
154 {
155     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "DOMConstructor");
156     UseCounter::count(callingExecutionContext(info.GetIsolate()), UseCounter::TestFeature);
157     if (!info.IsConstructCall()) {
158         throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("TestInterfaceConstructor"), info.GetIsolate());
159         return;
160     }
161
162     if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
163         v8SetReturnValue(info, info.Holder());
164         return;
165     }
166
167     TestInterfaceConstructorV8Internal::constructor(info);
168 }
169
170 static void configureV8TestInterfaceConstructorTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate)
171 {
172     functionTemplate->ReadOnlyPrototype();
173
174     v8::Local<v8::Signature> defaultSignature;
175     defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceConstructor", v8::Local<v8::FunctionTemplate>(), V8TestInterfaceConstructor::internalFieldCount,
176         0, 0,
177         0, 0,
178         0, 0,
179         isolate);
180     functionTemplate->SetCallHandler(V8TestInterfaceConstructor::constructorCallback);
181     functionTemplate->SetLength(0);
182     v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate();
183     v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate();
184
185     // Custom toString template
186     functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate());
187 }
188
189 v8::Handle<v8::FunctionTemplate> V8TestInterfaceConstructor::domTemplate(v8::Isolate* isolate)
190 {
191     return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), configureV8TestInterfaceConstructorTemplate);
192 }
193
194 bool V8TestInterfaceConstructor::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
195 {
196     return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value);
197 }
198
199 v8::Handle<v8::Object> V8TestInterfaceConstructor::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
200 {
201     return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value);
202 }
203
204 TestInterfaceConstructor* V8TestInterfaceConstructor::toNativeWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value)
205 {
206     return hasInstance(value, isolate) ? fromInternalPointer(v8::Handle<v8::Object>::Cast(value)->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex)) : 0;
207 }
208
209 v8::Handle<v8::Object> wrap(TestInterfaceConstructor* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
210 {
211     ASSERT(impl);
212     ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceConstructor>(impl, isolate));
213     return V8TestInterfaceConstructor::createWrapper(impl, creationContext, isolate);
214 }
215
216 v8::Handle<v8::Object> V8TestInterfaceConstructor::createWrapper(PassRefPtr<TestInterfaceConstructor> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
217 {
218     ASSERT(impl);
219     ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceConstructor>(impl.get(), isolate));
220     if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
221         const WrapperTypeInfo* actualInfo = ScriptWrappable::fromObject(impl.get())->typeInfo();
222         // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
223         // the same object de-ref functions, though, so use that as the basis of the check.
224         RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
225     }
226
227     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
228     if (UNLIKELY(wrapper.IsEmpty()))
229         return wrapper;
230
231     installPerContextEnabledProperties(wrapper, impl.get(), isolate);
232     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
233     return wrapper;
234 }
235
236 void V8TestInterfaceConstructor::derefObject(void* object)
237 {
238     fromInternalPointer(object)->deref();
239 }
240
241 template<>
242 v8::Handle<v8::Value> toV8NoInline(TestInterfaceConstructor* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
243 {
244     return toV8(impl, creationContext, isolate);
245 }
246
247 } // namespace WebCore