dad354688ace263a4458ab641d2183a18faebd4c
[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, 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, 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()
79 {
80     static v8::Persistent<v8::FunctionTemplate> cachedTemplate;
81     if (!cachedTemplate.IsEmpty())
82         return cachedTemplate;
83
84     v8::HandleScope scope;
85     v8::Local<v8::FunctionTemplate> result = v8::FunctionTemplate::New(V8TestNamedConstructorConstructorCallback);
86
87     v8::Local<v8::ObjectTemplate> instance = result->InstanceTemplate();
88     instance->SetInternalFieldCount(V8TestNamedConstructor::internalFieldCount);
89     result->SetClassName(v8::String::NewSymbol("TestNamedConstructor"));
90     result->Inherit(V8TestNamedConstructor::GetTemplate());
91
92     cachedTemplate = v8::Persistent<v8::FunctionTemplate>::New(result);
93     return cachedTemplate;
94 }
95
96 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestNamedConstructorTemplate(v8::Persistent<v8::FunctionTemplate> desc)
97 {
98     desc->ReadOnlyPrototype();
99
100     v8::Local<v8::Signature> defaultSignature;
101     defaultSignature = V8DOMConfiguration::configureTemplate(desc, "TestNamedConstructor", v8::Persistent<v8::FunctionTemplate>(), V8TestNamedConstructor::internalFieldCount,
102         0, 0,
103         0, 0);
104     UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
105     
106
107     // Custom toString template
108     desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
109     return desc;
110 }
111
112 v8::Persistent<v8::FunctionTemplate> V8TestNamedConstructor::GetRawTemplate()
113 {
114     V8PerIsolateData* data = V8PerIsolateData::current();
115     V8PerIsolateData::TemplateMap::iterator result = data->rawTemplateMap().find(&info);
116     if (result != data->rawTemplateMap().end())
117         return result->value;
118
119     v8::HandleScope handleScope;
120     v8::Persistent<v8::FunctionTemplate> templ = createRawTemplate();
121     data->rawTemplateMap().add(&info, templ);
122     return templ;
123 }
124
125 v8::Persistent<v8::FunctionTemplate> V8TestNamedConstructor::GetTemplate()
126 {
127     V8PerIsolateData* data = V8PerIsolateData::current();
128     V8PerIsolateData::TemplateMap::iterator result = data->templateMap().find(&info);
129     if (result != data->templateMap().end())
130         return result->value;
131
132     v8::HandleScope handleScope;
133     v8::Persistent<v8::FunctionTemplate> templ =
134         ConfigureV8TestNamedConstructorTemplate(GetRawTemplate());
135     data->templateMap().add(&info, templ);
136     return templ;
137 }
138
139 bool V8TestNamedConstructor::HasInstance(v8::Handle<v8::Value> value)
140 {
141     return GetRawTemplate()->HasInstance(value);
142 }
143
144 ActiveDOMObject* V8TestNamedConstructor::toActiveDOMObject(v8::Handle<v8::Object> object)
145 {
146     return toNative(object);
147 }      
148
149 v8::Handle<v8::Object> V8TestNamedConstructor::createWrapper(PassRefPtr<TestNamedConstructor> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
150 {
151     ASSERT(impl.get());
152     ASSERT(DOMDataStore::getWrapper(impl.get(), isolate).IsEmpty());
153
154     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &info, impl.get());
155     if (UNLIKELY(wrapper.IsEmpty()))
156         return wrapper;
157
158     installPerContextProperties(wrapper, impl.get());
159     v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate);
160     if (!hasDependentLifetime)
161         wrapperHandle.MarkIndependent();
162     return wrapper;
163 }
164
165 void V8TestNamedConstructor::derefObject(void* object)
166 {
167     static_cast<TestNamedConstructor*>(object)->deref();
168 }
169
170 } // namespace WebCore