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