[v8] wrapSlow methods should ref underlying object before creating wrapper
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / V8 / V8TestCustomNamedGetter.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 "V8TestCustomNamedGetter.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 V8TestCustomNamedGetter::info = { V8TestCustomNamedGetter::GetTemplate, V8TestCustomNamedGetter::derefObject, 0, 0 };
37
38 namespace TestCustomNamedGetterInternal {
39
40 template <typename T> void V8_USE(T) { }
41
42 static v8::Handle<v8::Value> anotherFunctionCallback(const v8::Arguments& args)
43 {
44     INC_STATS("DOM.TestCustomNamedGetter.anotherFunction");
45     if (args.Length() < 1)
46         return throwError("Not enough arguments", V8Proxy::TypeError);
47     TestCustomNamedGetter* imp = V8TestCustomNamedGetter::toNative(args.Holder());
48     STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, str, MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined));
49     imp->anotherFunction(str);
50     return v8::Handle<v8::Value>();
51 }
52
53 } // namespace TestCustomNamedGetterInternal
54
55 static const BatchedCallback TestCustomNamedGetterCallbacks[] = {
56     {"anotherFunction", TestCustomNamedGetterInternal::anotherFunctionCallback},
57 };
58
59 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestCustomNamedGetterTemplate(v8::Persistent<v8::FunctionTemplate> desc)
60 {
61     desc->ReadOnlyPrototype();
62
63     v8::Local<v8::Signature> defaultSignature;
64     defaultSignature = configureTemplate(desc, "TestCustomNamedGetter", v8::Persistent<v8::FunctionTemplate>(), V8TestCustomNamedGetter::internalFieldCount,
65         0, 0,
66         TestCustomNamedGetterCallbacks, WTF_ARRAY_LENGTH(TestCustomNamedGetterCallbacks));
67     UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
68     v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
69     v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate();
70     UNUSED_PARAM(instance); // In some cases, it will not be used.
71     UNUSED_PARAM(proto); // In some cases, it will not be used.
72     
73     desc->InstanceTemplate()->SetNamedPropertyHandler(V8TestCustomNamedGetter::namedPropertyGetter, 0, 0, 0, 0);
74
75     // Custom toString template
76     desc->Set(getToStringName(), getToStringTemplate());
77     return desc;
78 }
79
80 v8::Persistent<v8::FunctionTemplate> V8TestCustomNamedGetter::GetRawTemplate()
81 {
82     V8BindingPerIsolateData* data = V8BindingPerIsolateData::current();
83     V8BindingPerIsolateData::TemplateMap::iterator result = data->rawTemplateMap().find(&info);
84     if (result != data->rawTemplateMap().end())
85         return result->second;
86
87     v8::HandleScope handleScope;
88     v8::Persistent<v8::FunctionTemplate> templ = createRawTemplate();
89     data->rawTemplateMap().add(&info, templ);
90     return templ;
91 }
92
93 v8::Persistent<v8::FunctionTemplate> V8TestCustomNamedGetter::GetTemplate()
94 {
95     V8BindingPerIsolateData* data = V8BindingPerIsolateData::current();
96     V8BindingPerIsolateData::TemplateMap::iterator result = data->templateMap().find(&info);
97     if (result != data->templateMap().end())
98         return result->second;
99
100     v8::HandleScope handleScope;
101     v8::Persistent<v8::FunctionTemplate> templ =
102         ConfigureV8TestCustomNamedGetterTemplate(GetRawTemplate());
103     data->templateMap().add(&info, templ);
104     return templ;
105 }
106
107 bool V8TestCustomNamedGetter::HasInstance(v8::Handle<v8::Value> value)
108 {
109     return GetRawTemplate()->HasInstance(value);
110 }
111
112
113 v8::Handle<v8::Object> V8TestCustomNamedGetter::wrapSlow(PassRefPtr<TestCustomNamedGetter> impl)
114 {
115     v8::Handle<v8::Object> wrapper;
116     V8Proxy* proxy = 0;
117     wrapper = V8DOMWrapper::instantiateV8Object(proxy, &info, impl.get());
118     if (UNLIKELY(wrapper.IsEmpty()))
119         return wrapper;
120
121     v8::Persistent<v8::Object> wrapperHandle = v8::Persistent<v8::Object>::New(wrapper);
122
123     if (!hasDependentLifetime)
124         wrapperHandle.MarkIndependent();
125     getDOMObjectMap().set(impl.leakRef(), wrapperHandle);
126     return wrapper;
127 }
128
129 void V8TestCustomNamedGetter::derefObject(void* object)
130 {
131     static_cast<TestCustomNamedGetter*>(object)->deref();
132 }
133
134 } // namespace WebCore