Implement MouseEvent constructor
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / V8 / V8TestNamedConstructor.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 "V8TestNamedConstructor.h"
23
24 #include "BindingState.h"
25 #include "ContextFeatures.h"
26 #include "ExceptionCode.h"
27 #include "Frame.h"
28 #include "RuntimeEnabledFeatures.h"
29 #include "V8Binding.h"
30 #include "V8DOMWrapper.h"
31 #include <wtf/UnusedParam.h>
32
33 namespace WebCore {
34
35 WrapperTypeInfo V8TestNamedConstructor::info = { V8TestNamedConstructor::GetTemplate, V8TestNamedConstructor::derefObject, V8TestNamedConstructor::toActiveDOMObject, 0, 0, V8TestNamedConstructor::installPerContextPrototypeProperties, 0, WrapperTypeObjectPrototype };
36
37 namespace TestNamedConstructorV8Internal {
38
39 template <typename T> void V8_USE(T) { }
40
41 } // namespace TestNamedConstructorV8Internal
42
43 WrapperTypeInfo V8TestNamedConstructorConstructor::info = { V8TestNamedConstructorConstructor::GetTemplate, V8TestNamedConstructor::derefObject, V8TestNamedConstructor::toActiveDOMObject, 0, 0, V8TestNamedConstructor::installPerContextPrototypeProperties, 0, WrapperTypeObjectPrototype };
44
45 static v8::Handle<v8::Value> V8TestNamedConstructorConstructorCallback(const v8::Arguments& args)
46 {
47     
48     if (!args.IsConstructCall())
49         return throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate());
50
51     if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
52         return args.Holder();
53     Document* document = currentDocument(BindingState::instance());
54
55     // Make sure the document is added to the DOM Node map. Otherwise, the TestNamedConstructor instance
56     // may end up being the only node in the map and get garbage-collected prematurely.
57     toV8(document, args.Holder(), args.GetIsolate());
58
59     if (args.Length() < 1)
60         return throwNotEnoughArgumentsError(args.GetIsolate());
61
62     ExceptionCode ec = 0;
63     V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, str1, MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined));
64     V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, str2, MAYBE_MISSING_PARAMETER(args, 1, DefaultIsUndefined));
65     V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, str3, MAYBE_MISSING_PARAMETER(args, 2, DefaultIsNullString));
66
67     RefPtr<TestNamedConstructor> impl = TestNamedConstructor::createForJSConstructor(document, str1, str2, str3, ec);
68     v8::Handle<v8::Object> wrapper = args.Holder();
69     if (ec)
70         goto fail;
71
72     V8DOMWrapper::associateObjectWithWrapper(impl.release(), &V8TestNamedConstructorConstructor::info, wrapper, args.GetIsolate());
73     return wrapper;
74   fail:
75     return setDOMException(ec, args.GetIsolate());
76 }
77
78 v8::Persistent<v8::FunctionTemplate> V8TestNamedConstructorConstructor::GetTemplate(v8::Isolate* isolate)
79 {
80     if (!isolate)
81         isolate = v8::Isolate::GetCurrent();
82     static v8::Persistent<v8::FunctionTemplate> cachedTemplate;
83     if (!cachedTemplate.IsEmpty())
84         return cachedTemplate;
85
86     v8::HandleScope scope;
87     v8::Local<v8::FunctionTemplate> result = v8::FunctionTemplate::New(V8TestNamedConstructorConstructorCallback);
88
89     v8::Local<v8::ObjectTemplate> instance = result->InstanceTemplate();
90     instance->SetInternalFieldCount(V8TestNamedConstructor::internalFieldCount);
91     result->SetClassName(v8::String::NewSymbol("TestNamedConstructor"));
92     result->Inherit(V8TestNamedConstructor::GetTemplate());
93
94     cachedTemplate = v8::Persistent<v8::FunctionTemplate>::New(result);
95     return cachedTemplate;
96 }
97
98 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestNamedConstructorTemplate(v8::Persistent<v8::FunctionTemplate> desc)
99 {
100     desc->ReadOnlyPrototype();
101
102     v8::Local<v8::Signature> defaultSignature;
103     defaultSignature = V8DOMConfiguration::configureTemplate(desc, "TestNamedConstructor", v8::Persistent<v8::FunctionTemplate>(), V8TestNamedConstructor::internalFieldCount,
104         0, 0,
105         0, 0);
106     UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
107     
108
109     // Custom toString template
110     desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
111     return desc;
112 }
113
114 v8::Persistent<v8::FunctionTemplate> V8TestNamedConstructor::GetRawTemplate(v8::Isolate* isolate)
115 {
116     if (!isolate)
117         isolate = v8::Isolate::GetCurrent();
118     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
119     V8PerIsolateData::TemplateMap::iterator result = data->rawTemplateMap().find(&info);
120     if (result != data->rawTemplateMap().end())
121         return result->value;
122
123     v8::HandleScope handleScope;
124     v8::Persistent<v8::FunctionTemplate> templ = createRawTemplate();
125     data->rawTemplateMap().add(&info, templ);
126     return templ;
127 }
128
129 v8::Persistent<v8::FunctionTemplate> V8TestNamedConstructor::GetTemplate(v8::Isolate* isolate)
130 {
131     if (!isolate)
132         isolate = v8::Isolate::GetCurrent();
133     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
134     V8PerIsolateData::TemplateMap::iterator result = data->templateMap().find(&info);
135     if (result != data->templateMap().end())
136         return result->value;
137
138     v8::HandleScope handleScope;
139     v8::Persistent<v8::FunctionTemplate> templ =
140         ConfigureV8TestNamedConstructorTemplate(GetRawTemplate());
141     data->templateMap().add(&info, templ);
142     return templ;
143 }
144
145 bool V8TestNamedConstructor::HasInstance(v8::Handle<v8::Value> value)
146 {
147     return GetRawTemplate()->HasInstance(value);
148 }
149
150 ActiveDOMObject* V8TestNamedConstructor::toActiveDOMObject(v8::Handle<v8::Object> object)
151 {
152     return toNative(object);
153 }
154
155
156 v8::Handle<v8::Object> V8TestNamedConstructor::createWrapper(PassRefPtr<TestNamedConstructor> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
157 {
158     ASSERT(impl.get());
159     ASSERT(DOMDataStore::getWrapper(impl.get(), isolate).IsEmpty());
160
161     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &info, impl.get());
162     if (UNLIKELY(wrapper.IsEmpty()))
163         return wrapper;
164
165     installPerContextProperties(wrapper, impl.get());
166     v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate);
167     if (!hasDependentLifetime)
168         wrapperHandle.MarkIndependent();
169     return wrapper;
170 }
171 void V8TestNamedConstructor::derefObject(void* object)
172 {
173     static_cast<TestNamedConstructor*>(object)->deref();
174 }
175
176 } // namespace WebCore