d8bc6fb4304b6fa9673d9e365c6c561acc820c48
[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/core/v8/Dictionary.h"
11 #include "bindings/core/v8/ExceptionState.h"
12 #include "bindings/core/v8/V8DOMConfiguration.h"
13 #include "bindings/core/v8/V8HiddenValue.h"
14 #include "bindings/core/v8/V8ObjectConstructor.h"
15 #include "bindings/tests/v8/V8TestInterfaceEmpty.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 blink {
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 blink
36
37 void webCoreInitializeScriptWrappableForInterface(blink::TestInterfaceConstructor* object)
38 {
39     blink::initializeScriptWrappableForInterface(object);
40 }
41
42 namespace blink {
43 const WrapperTypeInfo V8TestInterfaceConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceConstructor::domTemplate, V8TestInterfaceConstructor::derefObject, 0, 0, 0, V8TestInterfaceConstructor::installConditionallyEnabledMethods, 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     ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
52     ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
53     Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
54     RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(executionContext, document, exceptionState);
55     if (exceptionState.hadException()) {
56         exceptionState.throwIfNeeded();
57         return;
58     }
59     v8::Handle<v8::Object> wrapper = info.Holder();
60     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.release(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Independent);
61     v8SetReturnValue(info, wrapper);
62 }
63
64 static void constructor2(const v8::FunctionCallbackInfo<v8::Value>& info)
65 {
66     ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
67     double doubleArg;
68     V8StringResource<> stringArg;
69     TestInterfaceEmpty* testInterfaceEmptyArg;
70     Dictionary dictionaryArg;
71     Vector<String> sequenceStringArg;
72     Vector<Dictionary> sequenceDictionaryArg;
73     Dictionary optionalDictionaryArg;
74     TestInterfaceEmpty* optionalTestInterfaceEmptyArg;
75     {
76         v8::TryCatch block;
77         V8RethrowTryCatchScope rethrow(block);
78         TONATIVE_VOID_INTERNAL(doubleArg, static_cast<double>(info[0]->NumberValue()));
79         TOSTRING_VOID_INTERNAL(stringArg, info[1]);
80         TONATIVE_VOID_INTERNAL(testInterfaceEmptyArg, V8TestInterfaceEmpty::toNativeWithTypeCheck(info.GetIsolate(), info[2]));
81         TONATIVE_VOID_INTERNAL(dictionaryArg, Dictionary(info[3], info.GetIsolate()));
82         if (!dictionaryArg.isUndefinedOrNull() && !dictionaryArg.isObject()) {
83             exceptionState.throwTypeError("parameter 4 ('dictionaryArg') is not an object.");
84             exceptionState.throwIfNeeded();
85             return;
86         }
87         TONATIVE_VOID_INTERNAL(sequenceStringArg, toNativeArray<String>(info[4], 5, info.GetIsolate()));
88         TONATIVE_VOID_INTERNAL(sequenceDictionaryArg, toNativeArray<Dictionary>(info[5], 6, info.GetIsolate()));
89         TONATIVE_VOID_INTERNAL(optionalDictionaryArg, Dictionary(info[6], info.GetIsolate()));
90         if (!optionalDictionaryArg.isUndefinedOrNull() && !optionalDictionaryArg.isObject()) {
91             exceptionState.throwTypeError("parameter 7 ('optionalDictionaryArg') is not an object.");
92             exceptionState.throwIfNeeded();
93             return;
94         }
95         TONATIVE_VOID_INTERNAL(optionalTestInterfaceEmptyArg, V8TestInterfaceEmpty::toNativeWithTypeCheck(info.GetIsolate(), info[7]));
96     }
97     ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
98     Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
99     RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(executionContext, document, doubleArg, stringArg, testInterfaceEmptyArg, dictionaryArg, sequenceStringArg, sequenceDictionaryArg, optionalDictionaryArg, optionalTestInterfaceEmptyArg, exceptionState);
100     if (exceptionState.hadException()) {
101         exceptionState.throwIfNeeded();
102         return;
103     }
104     v8::Handle<v8::Object> wrapper = info.Holder();
105     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.release(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Independent);
106     v8SetReturnValue(info, wrapper);
107 }
108
109 static void constructor3(const v8::FunctionCallbackInfo<v8::Value>& info)
110 {
111     ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
112     V8StringResource<> arg;
113     V8StringResource<> optArg;
114     {
115         TOSTRING_VOID_INTERNAL(arg, info[0]);
116         if (UNLIKELY(info.Length() <= 1)) {
117             ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
118             Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
119             RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(executionContext, document, arg, exceptionState);
120             if (exceptionState.hadException()) {
121                 exceptionState.throwIfNeeded();
122                 return;
123             }
124             v8::Handle<v8::Object> wrapper = info.Holder();
125             V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.release(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Independent);
126             v8SetReturnValue(info, wrapper);
127             return;
128         }
129         TOSTRING_VOID_INTERNAL(optArg, info[1]);
130     }
131     ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
132     Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
133     RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(executionContext, document, arg, optArg, exceptionState);
134     if (exceptionState.hadException()) {
135         exceptionState.throwIfNeeded();
136         return;
137     }
138     v8::Handle<v8::Object> wrapper = info.Holder();
139     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.release(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Independent);
140     v8SetReturnValue(info, wrapper);
141 }
142
143 static void constructor4(const v8::FunctionCallbackInfo<v8::Value>& info)
144 {
145     ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
146     V8StringResource<> arg;
147     V8StringResource<> arg2;
148     V8StringResource<> arg3;
149     {
150         TOSTRING_VOID_INTERNAL(arg, info[0]);
151         TOSTRING_VOID_INTERNAL(arg2, info[1]);
152         TOSTRING_VOID_INTERNAL(arg3, info[2]);
153     }
154     ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
155     Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
156     RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(executionContext, document, arg, arg2, arg3, exceptionState);
157     if (exceptionState.hadException()) {
158         exceptionState.throwIfNeeded();
159         return;
160     }
161     v8::Handle<v8::Object> wrapper = info.Holder();
162     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.release(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Independent);
163     v8SetReturnValue(info, wrapper);
164 }
165
166 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
167 {
168     ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
169     switch (std::min(8, info.Length())) {
170     case 0:
171         if (true) {
172             TestInterfaceConstructorV8Internal::constructor1(info);
173             return;
174         }
175         break;
176     case 1:
177         if (true) {
178             TestInterfaceConstructorV8Internal::constructor3(info);
179             return;
180         }
181         break;
182     case 2:
183         if (true) {
184             TestInterfaceConstructorV8Internal::constructor3(info);
185             return;
186         }
187         break;
188     case 3:
189         if (true) {
190             TestInterfaceConstructorV8Internal::constructor4(info);
191             return;
192         }
193         break;
194     case 6:
195         if (true) {
196             TestInterfaceConstructorV8Internal::constructor2(info);
197             return;
198         }
199         break;
200     case 7:
201         if (true) {
202             TestInterfaceConstructorV8Internal::constructor2(info);
203             return;
204         }
205         break;
206     case 8:
207         if (true) {
208             TestInterfaceConstructorV8Internal::constructor2(info);
209             return;
210         }
211         break;
212     default:
213         if (info.Length() >= 0) {
214             throwArityTypeError(exceptionState, "[0, 1, 2, 3, 6, 7, 8]", info.Length());
215             return;
216         }
217         exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(0, info.Length()));
218         exceptionState.throwIfNeeded();
219         return;
220     }
221     exceptionState.throwTypeError("No matching constructor signature.");
222     exceptionState.throwIfNeeded();
223 }
224
225 } // namespace TestInterfaceConstructorV8Internal
226
227 const WrapperTypeInfo V8TestInterfaceConstructorConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceConstructorConstructor::domTemplate, V8TestInterfaceConstructor::derefObject, 0, 0, 0, V8TestInterfaceConstructor::installConditionallyEnabledMethods, 0, WrapperTypeObjectPrototype, RefCountedObject };
228
229 static void V8TestInterfaceConstructorConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
230 {
231     if (!info.IsConstructCall()) {
232         V8ThrowException::throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("Audio"), info.GetIsolate());
233         return;
234     }
235
236     if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
237         v8SetReturnValue(info, info.Holder());
238         return;
239     }
240     ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
241     if (UNLIKELY(info.Length() < 1)) {
242         setMinimumArityTypeError(exceptionState, 1, info.Length());
243         exceptionState.throwIfNeeded();
244         return;
245     }
246     V8StringResource<> arg;
247     V8StringResource<> optArg;
248     {
249         TOSTRING_VOID_INTERNAL(arg, info[0]);
250         if (UNLIKELY(info.Length() <= 1)) {
251             ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
252             Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
253             RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::createForJSConstructor(executionContext, document, arg, exceptionState);
254             if (exceptionState.hadException()) {
255                 exceptionState.throwIfNeeded();
256                 return;
257             }
258             v8::Handle<v8::Object> wrapper = info.Holder();
259             V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.release(), &V8TestInterfaceConstructorConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Independent);
260             v8SetReturnValue(info, wrapper);
261             return;
262         }
263         TOSTRING_VOID_INTERNAL(optArg, info[1]);
264     }
265     ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
266     Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
267     RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::createForJSConstructor(executionContext, document, arg, optArg, exceptionState);
268     if (exceptionState.hadException()) {
269         exceptionState.throwIfNeeded();
270         return;
271     }
272     v8::Handle<v8::Object> wrapper = info.Holder();
273     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.release(), &V8TestInterfaceConstructorConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Independent);
274     v8SetReturnValue(info, wrapper);
275 }
276
277 v8::Handle<v8::FunctionTemplate> V8TestInterfaceConstructorConstructor::domTemplate(v8::Isolate* isolate)
278 {
279     static int domTemplateKey; // This address is used for a key to look up the dom template.
280     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
281     v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(&domTemplateKey);
282     if (!result.IsEmpty())
283         return result;
284
285     TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate");
286     result = v8::FunctionTemplate::New(isolate, V8TestInterfaceConstructorConstructorCallback);
287     v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate();
288     instanceTemplate->SetInternalFieldCount(V8TestInterfaceConstructor::internalFieldCount);
289     result->SetClassName(v8AtomicString(isolate, "TestInterfaceConstructor"));
290     result->Inherit(V8TestInterfaceConstructor::domTemplate(isolate));
291     data->setDOMTemplate(&domTemplateKey, result);
292     return result;
293 }
294
295 void V8TestInterfaceConstructor::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
296 {
297     TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "DOMConstructor");
298     UseCounter::count(callingExecutionContext(info.GetIsolate()), UseCounter::TestFeature);
299     if (!info.IsConstructCall()) {
300         V8ThrowException::throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("TestInterfaceConstructor"), info.GetIsolate());
301         return;
302     }
303
304     if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
305         v8SetReturnValue(info, info.Holder());
306         return;
307     }
308
309     TestInterfaceConstructorV8Internal::constructor(info);
310 }
311
312 static void installV8TestInterfaceConstructorTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate)
313 {
314     functionTemplate->ReadOnlyPrototype();
315
316     v8::Local<v8::Signature> defaultSignature;
317     defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceConstructor", v8::Local<v8::FunctionTemplate>(), V8TestInterfaceConstructor::internalFieldCount,
318         0, 0,
319         0, 0,
320         0, 0,
321         isolate);
322     functionTemplate->SetCallHandler(V8TestInterfaceConstructor::constructorCallback);
323     functionTemplate->SetLength(0);
324     v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate();
325     v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate();
326
327     // Custom toString template
328     functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate());
329 }
330
331 v8::Handle<v8::FunctionTemplate> V8TestInterfaceConstructor::domTemplate(v8::Isolate* isolate)
332 {
333     return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), installV8TestInterfaceConstructorTemplate);
334 }
335
336 bool V8TestInterfaceConstructor::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
337 {
338     return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value);
339 }
340
341 v8::Handle<v8::Object> V8TestInterfaceConstructor::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
342 {
343     return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value);
344 }
345
346 TestInterfaceConstructor* V8TestInterfaceConstructor::toNativeWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value)
347 {
348     return hasInstance(value, isolate) ? fromInternalPointer(blink::toInternalPointer(v8::Handle<v8::Object>::Cast(value))) : 0;
349 }
350
351 v8::Handle<v8::Object> wrap(TestInterfaceConstructor* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
352 {
353     ASSERT(impl);
354     ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceConstructor>(impl, isolate));
355     return V8TestInterfaceConstructor::createWrapper(impl, creationContext, isolate);
356 }
357
358 v8::Handle<v8::Object> V8TestInterfaceConstructor::createWrapper(PassRefPtr<TestInterfaceConstructor> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
359 {
360     ASSERT(impl);
361     ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceConstructor>(impl.get(), isolate));
362     if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
363         const WrapperTypeInfo* actualInfo = ScriptWrappable::fromObject(impl.get())->typeInfo();
364         // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
365         // the same object de-ref functions, though, so use that as the basis of the check.
366         RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
367     }
368
369     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
370     if (UNLIKELY(wrapper.IsEmpty()))
371         return wrapper;
372
373     installConditionallyEnabledProperties(wrapper, isolate);
374     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
375     return wrapper;
376 }
377
378 void V8TestInterfaceConstructor::derefObject(ScriptWrappableBase* internalPointer)
379 {
380     fromInternalPointer(internalPointer)->deref();
381 }
382
383 template<>
384 v8::Handle<v8::Value> toV8NoInline(TestInterfaceConstructor* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
385 {
386     return toV8(impl, creationContext, isolate);
387 }
388
389 } // namespace blink