fbfe1aa302f1622766f56d73b7c81b6c7a6c9a2e
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / V8 / V8TestOverloadedConstructors.cpp
1 /*
2     This file is part of the WebKit open source project.
3     This file has been generated by generate-bindings.pl. DO NOT MODIFY!
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Library General Public
7     License as published by the Free Software Foundation; either
8     version 2 of the License, or (at your option) any later version.
9
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13     Library General Public License for more details.
14
15     You should have received a copy of the GNU Library General Public License
16     along with this library; see the file COPYING.LIB.  If not, write to
17     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18     Boston, MA 02111-1307, USA.
19 */
20
21 #include "config.h"
22 #include "V8TestOverloadedConstructors.h"
23
24 #include "BindingState.h"
25 #include "ContextFeatures.h"
26 #include "ExceptionCode.h"
27 #include "Frame.h"
28 #include "RuntimeEnabledFeatures.h"
29 #include "V8ArrayBuffer.h"
30 #include "V8ArrayBufferView.h"
31 #include "V8Binding.h"
32 #include "V8Blob.h"
33 #include "V8DOMWrapper.h"
34 #include <wtf/ArrayBuffer.h>
35 #include <wtf/ArrayBufferView.h>
36 #include <wtf/UnusedParam.h>
37
38 #if ENABLE(BINDING_INTEGRITY)
39 #if defined(OS_WIN)
40 #pragma warning(disable: 4483)
41 extern "C" { extern void (*const __identifier("??_7TestOverloadedConstructors@WebCore@@6B@")[])(); }
42 #else
43 extern "C" { extern void* _ZTVN7WebCore26TestOverloadedConstructorsE[]; }
44 #endif
45 #endif // ENABLE(BINDING_INTEGRITY)
46
47 namespace WebCore {
48
49 #if ENABLE(BINDING_INTEGRITY)
50 inline void checkTypeOrDieTrying(TestOverloadedConstructors* object)
51 {
52     void* actualVTablePointer = *(reinterpret_cast<void**>(object));
53 #if defined(OS_WIN)
54     void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7TestOverloadedConstructors@WebCore@@6B@"));
55 #else
56     void* expectedVTablePointer = &_ZTVN7WebCore26TestOverloadedConstructorsE[2];
57 #endif
58     if (actualVTablePointer != expectedVTablePointer)
59         CRASH();
60 }
61 #endif // ENABLE(BINDING_INTEGRITY)
62
63 WrapperTypeInfo V8TestOverloadedConstructors::info = { V8TestOverloadedConstructors::GetTemplate, V8TestOverloadedConstructors::derefObject, 0, 0, 0, V8TestOverloadedConstructors::installPerContextPrototypeProperties, 0, WrapperTypeObjectPrototype };
64
65 namespace TestOverloadedConstructorsV8Internal {
66
67 template <typename T> void V8_USE(T) { }
68
69 } // namespace TestOverloadedConstructorsV8Internal
70
71 v8::Handle<v8::Value> V8TestOverloadedConstructors::constructor1Callback(const v8::Arguments& args)
72 {
73     
74     V8TRYCATCH(ArrayBuffer*, arrayBuffer, V8ArrayBuffer::HasInstance(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined), args.GetIsolate()) ? V8ArrayBuffer::toNative(v8::Handle<v8::Object>::Cast(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined))) : 0);
75
76     RefPtr<TestOverloadedConstructors> impl = TestOverloadedConstructors::create(arrayBuffer);
77     v8::Handle<v8::Object> wrapper = args.Holder();
78
79     V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate());
80     return wrapper;
81 }
82
83 v8::Handle<v8::Value> V8TestOverloadedConstructors::constructor2Callback(const v8::Arguments& args)
84 {
85     
86     V8TRYCATCH(ArrayBufferView*, arrayBufferView, V8ArrayBufferView::HasInstance(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined), args.GetIsolate()) ? V8ArrayBufferView::toNative(v8::Handle<v8::Object>::Cast(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined))) : 0);
87
88     RefPtr<TestOverloadedConstructors> impl = TestOverloadedConstructors::create(arrayBufferView);
89     v8::Handle<v8::Object> wrapper = args.Holder();
90
91     V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate());
92     return wrapper;
93 }
94
95 v8::Handle<v8::Value> V8TestOverloadedConstructors::constructor3Callback(const v8::Arguments& args)
96 {
97     
98     V8TRYCATCH(Blob*, blob, V8Blob::HasInstance(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined), args.GetIsolate()) ? V8Blob::toNative(v8::Handle<v8::Object>::Cast(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined))) : 0);
99
100     RefPtr<TestOverloadedConstructors> impl = TestOverloadedConstructors::create(blob);
101     v8::Handle<v8::Object> wrapper = args.Holder();
102
103     V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate());
104     return wrapper;
105 }
106
107 v8::Handle<v8::Value> V8TestOverloadedConstructors::constructor4Callback(const v8::Arguments& args)
108 {
109     
110     V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, string, MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined));
111
112     RefPtr<TestOverloadedConstructors> impl = TestOverloadedConstructors::create(string);
113     v8::Handle<v8::Object> wrapper = args.Holder();
114
115     V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate());
116     return wrapper;
117 }
118
119 v8::Handle<v8::Value> V8TestOverloadedConstructors::constructorCallback(const v8::Arguments& args)
120 {
121     if (!args.IsConstructCall())
122         return throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate());
123
124     if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
125         return args.Holder();
126     if ((args.Length() == 1 && (V8ArrayBuffer::HasInstance(args[0], args.GetIsolate()))))
127         return constructor1Callback(args);
128     if ((args.Length() == 1 && (V8ArrayBufferView::HasInstance(args[0], args.GetIsolate()))))
129         return constructor2Callback(args);
130     if ((args.Length() == 1 && (V8Blob::HasInstance(args[0], args.GetIsolate()))))
131         return constructor3Callback(args);
132     if (args.Length() == 1)
133         return constructor4Callback(args);
134     if (args.Length() < 1)
135         return throwNotEnoughArgumentsError(args.GetIsolate());
136     return throwTypeError(0, args.GetIsolate());
137 }
138
139 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestOverloadedConstructorsTemplate(v8::Persistent<v8::FunctionTemplate> desc, v8::Isolate* isolate)
140 {
141     desc->ReadOnlyPrototype();
142
143     v8::Local<v8::Signature> defaultSignature;
144     defaultSignature = V8DOMConfiguration::configureTemplate(desc, "TestOverloadedConstructors", v8::Persistent<v8::FunctionTemplate>(), V8TestOverloadedConstructors::internalFieldCount,
145         0, 0,
146         0, 0, isolate);
147     UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
148     desc->SetCallHandler(V8TestOverloadedConstructors::constructorCallback);
149     
150
151     // Custom toString template
152     desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
153     return desc;
154 }
155
156 v8::Persistent<v8::FunctionTemplate> V8TestOverloadedConstructors::GetRawTemplate(v8::Isolate* isolate)
157 {
158     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
159     V8PerIsolateData::TemplateMap::iterator result = data->rawTemplateMap().find(&info);
160     if (result != data->rawTemplateMap().end())
161         return result->value;
162
163     v8::HandleScope handleScope;
164     v8::Persistent<v8::FunctionTemplate> templ = createRawTemplate();
165     data->rawTemplateMap().add(&info, templ);
166     return templ;
167 }
168
169 v8::Persistent<v8::FunctionTemplate> V8TestOverloadedConstructors::GetTemplate(v8::Isolate* isolate)
170 {
171     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
172     V8PerIsolateData::TemplateMap::iterator result = data->templateMap().find(&info);
173     if (result != data->templateMap().end())
174         return result->value;
175
176     v8::HandleScope handleScope;
177     v8::Persistent<v8::FunctionTemplate> templ =
178         ConfigureV8TestOverloadedConstructorsTemplate(GetRawTemplate(isolate), isolate);
179     data->templateMap().add(&info, templ);
180     return templ;
181 }
182
183 bool V8TestOverloadedConstructors::HasInstance(v8::Handle<v8::Value> value, v8::Isolate* isolate)
184 {
185     return GetRawTemplate(isolate)->HasInstance(value);
186 }
187
188
189 v8::Handle<v8::Object> V8TestOverloadedConstructors::createWrapper(PassRefPtr<TestOverloadedConstructors> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
190 {
191     ASSERT(impl.get());
192     ASSERT(DOMDataStore::getWrapper(impl.get(), isolate).IsEmpty());
193
194 #if ENABLE(BINDING_INTEGRITY)
195     checkTypeOrDieTrying(impl.get());
196 #endif
197
198     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &info, impl.get(), isolate);
199     if (UNLIKELY(wrapper.IsEmpty()))
200         return wrapper;
201
202     installPerContextProperties(wrapper, impl.get(), isolate);
203     v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate);
204     if (!hasDependentLifetime)
205         wrapperHandle.MarkIndependent();
206     return wrapper;
207 }
208 void V8TestOverloadedConstructors::derefObject(void* object)
209 {
210     static_cast<TestOverloadedConstructors*>(object)->deref();
211 }
212
213 } // namespace WebCore