[v8] wrapSlow methods should ref underlying object before creating wrapper
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / V8 / V8TestActiveDOMObject.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 "V8TestActiveDOMObject.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 "V8Node.h"
32 #include "V8Proxy.h"
33 #include <wtf/UnusedParam.h>
34
35 namespace WebCore {
36
37 WrapperTypeInfo V8TestActiveDOMObject::info = { V8TestActiveDOMObject::GetTemplate, V8TestActiveDOMObject::derefObject, 0, 0 };
38
39 namespace TestActiveDOMObjectInternal {
40
41 template <typename T> void V8_USE(T) { }
42
43 static v8::Handle<v8::Value> excitingAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
44 {
45     INC_STATS("DOM.TestActiveDOMObject.excitingAttr._get");
46     TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(info.Holder());
47     return v8::Integer::New(imp->excitingAttr());
48 }
49
50 static v8::Handle<v8::Value> excitingFunctionCallback(const v8::Arguments& args)
51 {
52     INC_STATS("DOM.TestActiveDOMObject.excitingFunction");
53     if (args.Length() < 1)
54         return throwError("Not enough arguments", V8Proxy::TypeError);
55     TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(args.Holder());
56     if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), true))
57         return v8::Handle<v8::Value>();
58     EXCEPTION_BLOCK(Node*, nextChild, V8Node::HasInstance(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined)) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined))) : 0);
59     imp->excitingFunction(nextChild);
60     return v8::Handle<v8::Value>();
61 }
62
63 static v8::Handle<v8::Value> postMessageCallback(const v8::Arguments& args)
64 {
65     INC_STATS("DOM.TestActiveDOMObject.postMessage");
66     if (args.Length() < 1)
67         return throwError("Not enough arguments", V8Proxy::TypeError);
68     TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(args.Holder());
69     STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, message, MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined));
70     imp->postMessage(message);
71     return v8::Handle<v8::Value>();
72 }
73
74 static v8::Handle<v8::Value> postMessageAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
75 {
76     INC_STATS("DOM.TestActiveDOMObject.postMessage._get");
77     static v8::Persistent<v8::FunctionTemplate> privateTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(TestActiveDOMObjectInternal::postMessageCallback, v8::Handle<v8::Value>(), v8::Signature::New(V8TestActiveDOMObject::GetRawTemplate())));
78     v8::Handle<v8::Object> holder = V8DOMWrapper::lookupDOMWrapper(V8TestActiveDOMObject::GetTemplate(), info.This());
79     if (holder.IsEmpty()) {
80         // can only reach here by 'object.__proto__.func', and it should passed
81         // domain security check already
82         return privateTemplate->GetFunction();
83     }
84     TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(holder);
85     if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), false)) {
86         static v8::Persistent<v8::FunctionTemplate> sharedTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(TestActiveDOMObjectInternal::postMessageCallback, v8::Handle<v8::Value>(), v8::Signature::New(V8TestActiveDOMObject::GetRawTemplate())));
87         return sharedTemplate->GetFunction();
88     }
89     return privateTemplate->GetFunction();
90 }
91
92 } // namespace TestActiveDOMObjectInternal
93
94 static const BatchedAttribute TestActiveDOMObjectAttrs[] = {
95     // Attribute 'excitingAttr' (Type: 'readonly attribute' ExtAttr: '')
96     {"excitingAttr", TestActiveDOMObjectInternal::excitingAttrAttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
97 };
98
99 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestActiveDOMObjectTemplate(v8::Persistent<v8::FunctionTemplate> desc)
100 {
101     desc->ReadOnlyPrototype();
102
103     v8::Local<v8::Signature> defaultSignature;
104     defaultSignature = configureTemplate(desc, "TestActiveDOMObject", v8::Persistent<v8::FunctionTemplate>(), V8TestActiveDOMObject::internalFieldCount,
105         TestActiveDOMObjectAttrs, WTF_ARRAY_LENGTH(TestActiveDOMObjectAttrs),
106         0, 0);
107     UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
108     v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
109     v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate();
110     UNUSED_PARAM(instance); // In some cases, it will not be used.
111     UNUSED_PARAM(proto); // In some cases, it will not be used.
112     instance->SetAccessCheckCallbacks(V8TestActiveDOMObject::namedSecurityCheck, V8TestActiveDOMObject::indexedSecurityCheck, v8::External::Wrap(&V8TestActiveDOMObject::info));
113
114     // Custom Signature 'excitingFunction'
115     const int excitingFunctionArgc = 1;
116     v8::Handle<v8::FunctionTemplate> excitingFunctionArgv[excitingFunctionArgc] = { V8Node::GetRawTemplate() };
117     v8::Handle<v8::Signature> excitingFunctionSignature = v8::Signature::New(desc, excitingFunctionArgc, excitingFunctionArgv);
118     proto->Set(v8::String::New("excitingFunction"), v8::FunctionTemplate::New(TestActiveDOMObjectInternal::excitingFunctionCallback, v8::Handle<v8::Value>(), excitingFunctionSignature));
119
120     // Function 'postMessage' (ExtAttr: 'DoNotCheckSecurity')
121     proto->SetAccessor(v8::String::New("postMessage"), TestActiveDOMObjectInternal::postMessageAttrGetter, 0, v8::Handle<v8::Value>(), v8::ALL_CAN_READ, static_cast<v8::PropertyAttribute>(v8::DontDelete | v8::ReadOnly));
122
123     // Custom toString template
124     desc->Set(getToStringName(), getToStringTemplate());
125     return desc;
126 }
127
128 v8::Persistent<v8::FunctionTemplate> V8TestActiveDOMObject::GetRawTemplate()
129 {
130     V8BindingPerIsolateData* data = V8BindingPerIsolateData::current();
131     V8BindingPerIsolateData::TemplateMap::iterator result = data->rawTemplateMap().find(&info);
132     if (result != data->rawTemplateMap().end())
133         return result->second;
134
135     v8::HandleScope handleScope;
136     v8::Persistent<v8::FunctionTemplate> templ = createRawTemplate();
137     data->rawTemplateMap().add(&info, templ);
138     return templ;
139 }
140
141 v8::Persistent<v8::FunctionTemplate> V8TestActiveDOMObject::GetTemplate()
142 {
143     V8BindingPerIsolateData* data = V8BindingPerIsolateData::current();
144     V8BindingPerIsolateData::TemplateMap::iterator result = data->templateMap().find(&info);
145     if (result != data->templateMap().end())
146         return result->second;
147
148     v8::HandleScope handleScope;
149     v8::Persistent<v8::FunctionTemplate> templ =
150         ConfigureV8TestActiveDOMObjectTemplate(GetRawTemplate());
151     data->templateMap().add(&info, templ);
152     return templ;
153 }
154
155 bool V8TestActiveDOMObject::HasInstance(v8::Handle<v8::Value> value)
156 {
157     return GetRawTemplate()->HasInstance(value);
158 }
159
160
161 v8::Handle<v8::Object> V8TestActiveDOMObject::wrapSlow(PassRefPtr<TestActiveDOMObject> impl)
162 {
163     v8::Handle<v8::Object> wrapper;
164     V8Proxy* proxy = 0;
165     if (impl->frame()) {
166         proxy = V8Proxy::retrieve(impl->frame());
167         if (proxy)
168             proxy->windowShell()->initContextIfNeeded();
169     }
170
171     v8::Handle<v8::Context> context;
172     if (proxy)
173         context = proxy->context();
174
175     // Enter the node's context and create the wrapper in that context.
176     if (!context.IsEmpty())
177         context->Enter();
178     wrapper = V8DOMWrapper::instantiateV8Object(proxy, &info, impl.get());
179     // Exit the node's context if it was entered.
180     if (!context.IsEmpty())
181         context->Exit();
182     if (UNLIKELY(wrapper.IsEmpty()))
183         return wrapper;
184
185     v8::Persistent<v8::Object> wrapperHandle = v8::Persistent<v8::Object>::New(wrapper);
186
187     if (!hasDependentLifetime)
188         wrapperHandle.MarkIndependent();
189     getDOMObjectMap().set(impl.leakRef(), wrapperHandle);
190     return wrapper;
191 }
192
193 void V8TestActiveDOMObject::derefObject(void* object)
194 {
195     static_cast<TestActiveDOMObject*>(object)->deref();
196 }
197
198 } // namespace WebCore