23dd353eea34405d4010dd7e159b42f2a88eaad8
[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 namespace WebCore {
39
40 WrapperTypeInfo V8TestOverloadedConstructors::info = { V8TestOverloadedConstructors::GetTemplate, V8TestOverloadedConstructors::derefObject, 0, 0, V8TestOverloadedConstructors::installPerContextPrototypeProperties, 0, WrapperTypeObjectPrototype };
41
42 namespace TestOverloadedConstructorsV8Internal {
43
44 template <typename T> void V8_USE(T) { }
45
46 } // namespace TestOverloadedConstructorsV8Internal
47
48 v8::Handle<v8::Value> V8TestOverloadedConstructors::constructor1Callback(const v8::Arguments& args)
49 {
50     
51     V8TRYCATCH(ArrayBuffer*, arrayBuffer, V8ArrayBuffer::HasInstance(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined)) ? V8ArrayBuffer::toNative(v8::Handle<v8::Object>::Cast(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined))) : 0);
52
53     RefPtr<TestOverloadedConstructors> impl = TestOverloadedConstructors::create(arrayBuffer);
54     v8::Handle<v8::Object> wrapper = args.Holder();
55
56     V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate());
57     return wrapper;
58 }
59
60 v8::Handle<v8::Value> V8TestOverloadedConstructors::constructor2Callback(const v8::Arguments& args)
61 {
62     
63     V8TRYCATCH(ArrayBufferView*, arrayBufferView, V8ArrayBufferView::HasInstance(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined)) ? V8ArrayBufferView::toNative(v8::Handle<v8::Object>::Cast(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined))) : 0);
64
65     RefPtr<TestOverloadedConstructors> impl = TestOverloadedConstructors::create(arrayBufferView);
66     v8::Handle<v8::Object> wrapper = args.Holder();
67
68     V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate());
69     return wrapper;
70 }
71
72 v8::Handle<v8::Value> V8TestOverloadedConstructors::constructor3Callback(const v8::Arguments& args)
73 {
74     
75     V8TRYCATCH(Blob*, blob, V8Blob::HasInstance(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined)) ? V8Blob::toNative(v8::Handle<v8::Object>::Cast(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined))) : 0);
76
77     RefPtr<TestOverloadedConstructors> impl = TestOverloadedConstructors::create(blob);
78     v8::Handle<v8::Object> wrapper = args.Holder();
79
80     V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate());
81     return wrapper;
82 }
83
84 v8::Handle<v8::Value> V8TestOverloadedConstructors::constructor4Callback(const v8::Arguments& args)
85 {
86     
87     V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, string, MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined));
88
89     RefPtr<TestOverloadedConstructors> impl = TestOverloadedConstructors::create(string);
90     v8::Handle<v8::Object> wrapper = args.Holder();
91
92     V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate());
93     return wrapper;
94 }
95
96 v8::Handle<v8::Value> V8TestOverloadedConstructors::constructorCallback(const v8::Arguments& args)
97 {
98     if (!args.IsConstructCall())
99         return throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate());
100
101     if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
102         return args.Holder();
103     if ((args.Length() == 1 && (V8ArrayBuffer::HasInstance(args[0]))))
104         return constructor1Callback(args);
105     if ((args.Length() == 1 && (V8ArrayBufferView::HasInstance(args[0]))))
106         return constructor2Callback(args);
107     if ((args.Length() == 1 && (V8Blob::HasInstance(args[0]))))
108         return constructor3Callback(args);
109     if (args.Length() == 1)
110         return constructor4Callback(args);
111     if (args.Length() < 1)
112         return throwNotEnoughArgumentsError(args.GetIsolate());
113     return throwTypeError(0, args.GetIsolate());
114 }
115
116 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestOverloadedConstructorsTemplate(v8::Persistent<v8::FunctionTemplate> desc)
117 {
118     desc->ReadOnlyPrototype();
119
120     v8::Local<v8::Signature> defaultSignature;
121     defaultSignature = V8DOMConfiguration::configureTemplate(desc, "TestOverloadedConstructors", v8::Persistent<v8::FunctionTemplate>(), V8TestOverloadedConstructors::internalFieldCount,
122         0, 0,
123         0, 0);
124     UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
125     desc->SetCallHandler(V8TestOverloadedConstructors::constructorCallback);
126     
127
128     // Custom toString template
129     desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
130     return desc;
131 }
132
133 v8::Persistent<v8::FunctionTemplate> V8TestOverloadedConstructors::GetRawTemplate()
134 {
135     V8PerIsolateData* data = V8PerIsolateData::current();
136     V8PerIsolateData::TemplateMap::iterator result = data->rawTemplateMap().find(&info);
137     if (result != data->rawTemplateMap().end())
138         return result->value;
139
140     v8::HandleScope handleScope;
141     v8::Persistent<v8::FunctionTemplate> templ = createRawTemplate();
142     data->rawTemplateMap().add(&info, templ);
143     return templ;
144 }
145
146 v8::Persistent<v8::FunctionTemplate> V8TestOverloadedConstructors::GetTemplate()
147 {
148     V8PerIsolateData* data = V8PerIsolateData::current();
149     V8PerIsolateData::TemplateMap::iterator result = data->templateMap().find(&info);
150     if (result != data->templateMap().end())
151         return result->value;
152
153     v8::HandleScope handleScope;
154     v8::Persistent<v8::FunctionTemplate> templ =
155         ConfigureV8TestOverloadedConstructorsTemplate(GetRawTemplate());
156     data->templateMap().add(&info, templ);
157     return templ;
158 }
159
160 bool V8TestOverloadedConstructors::HasInstance(v8::Handle<v8::Value> value)
161 {
162     return GetRawTemplate()->HasInstance(value);
163 }
164
165
166 v8::Handle<v8::Object> V8TestOverloadedConstructors::createWrapper(PassRefPtr<TestOverloadedConstructors> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
167 {
168     ASSERT(impl.get());
169     ASSERT(DOMDataStore::getWrapper(impl.get(), isolate).IsEmpty());
170
171     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &info, impl.get());
172     if (UNLIKELY(wrapper.IsEmpty()))
173         return wrapper;
174
175     installPerContextProperties(wrapper, impl.get());
176     v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate);
177     if (!hasDependentLifetime)
178         wrapperHandle.MarkIndependent();
179     return wrapper;
180 }
181
182 void V8TestOverloadedConstructors::derefObject(void* object)
183 {
184     static_cast<TestOverloadedConstructors*>(object)->deref();
185 }
186
187 } // namespace WebCore