1a60205b8908e496f40d1cc44226da29e0061be6
[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 "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 "V8Node.h"
32 #include <wtf/UnusedParam.h>
33
34 namespace WebCore {
35
36 WrapperTypeInfo V8TestActiveDOMObject::info = { V8TestActiveDOMObject::GetTemplate, V8TestActiveDOMObject::derefObject, 0, 0, V8TestActiveDOMObject::installPerContextPrototypeProperties, 0, WrapperTypeObjectPrototype };
37
38 namespace TestActiveDOMObjectV8Internal {
39
40 template <typename T> void V8_USE(T) { }
41
42 static v8::Handle<v8::Value> excitingAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
43 {
44     TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(info.Holder());
45     return v8Integer(imp->excitingAttr(), info.GetIsolate());
46 }
47
48 static v8::Handle<v8::Value> excitingFunctionCallback(const v8::Arguments& args)
49 {
50     if (args.Length() < 1)
51         return throwNotEnoughArgumentsError(args.GetIsolate());
52     TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(args.Holder());
53     if (!BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), imp->frame()))
54         return v8Undefined();
55     V8TRYCATCH(Node*, nextChild, V8Node::HasInstance(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined)) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined))) : 0);
56     imp->excitingFunction(nextChild);
57     return v8Undefined();
58 }
59
60 static v8::Handle<v8::Value> postMessageCallback(const v8::Arguments& args)
61 {
62     if (args.Length() < 1)
63         return throwNotEnoughArgumentsError(args.GetIsolate());
64     TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(args.Holder());
65     V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, message, MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined));
66     imp->postMessage(message);
67     return v8Undefined();
68 }
69
70 static v8::Handle<v8::Value> postMessageAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
71 {
72     static v8::Persistent<v8::FunctionTemplate> privateTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(TestActiveDOMObjectV8Internal::postMessageCallback, v8Undefined(), v8::Signature::New(V8TestActiveDOMObject::GetRawTemplate())));
73     v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8TestActiveDOMObject::GetTemplate());
74     if (holder.IsEmpty()) {
75         // can only reach here by 'object.__proto__.func', and it should passed
76         // domain security check already
77         return privateTemplate->GetFunction();
78     }
79     TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(holder);
80     if (!BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), imp->frame(), DoNotReportSecurityError)) {
81         static v8::Persistent<v8::FunctionTemplate> sharedTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(TestActiveDOMObjectV8Internal::postMessageCallback, v8Undefined(), v8::Signature::New(V8TestActiveDOMObject::GetRawTemplate())));
82         return sharedTemplate->GetFunction();
83     }
84
85     v8::Local<v8::Value> hiddenValue = info.This()->GetHiddenValue(name);
86     if (!hiddenValue.IsEmpty())
87         return hiddenValue;
88
89     return privateTemplate->GetFunction();
90 }
91
92 static void TestActiveDOMObjectDomainSafeFunctionSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
93 {
94     v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8TestActiveDOMObject::GetTemplate());
95     if (holder.IsEmpty())
96         return;
97     TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(holder);
98     if (!BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), imp->frame()))
99         return;
100
101     info.This()->SetHiddenValue(name, value);
102 }
103
104 } // namespace TestActiveDOMObjectV8Internal
105
106 static const V8DOMConfiguration::BatchedAttribute V8TestActiveDOMObjectAttrs[] = {
107     // Attribute 'excitingAttr' (Type: 'readonly attribute' ExtAttr: '')
108     {"excitingAttr", TestActiveDOMObjectV8Internal::excitingAttrAttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
109 };
110
111 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestActiveDOMObjectTemplate(v8::Persistent<v8::FunctionTemplate> desc)
112 {
113     desc->ReadOnlyPrototype();
114
115     v8::Local<v8::Signature> defaultSignature;
116     defaultSignature = V8DOMConfiguration::configureTemplate(desc, "TestActiveDOMObject", v8::Persistent<v8::FunctionTemplate>(), V8TestActiveDOMObject::internalFieldCount,
117         V8TestActiveDOMObjectAttrs, WTF_ARRAY_LENGTH(V8TestActiveDOMObjectAttrs),
118         0, 0);
119     UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
120     v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
121     v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate();
122     UNUSED_PARAM(instance); // In some cases, it will not be used.
123     UNUSED_PARAM(proto); // In some cases, it will not be used.
124     instance->SetAccessCheckCallbacks(V8TestActiveDOMObject::namedSecurityCheck, V8TestActiveDOMObject::indexedSecurityCheck, v8::External::New(&V8TestActiveDOMObject::info));
125
126     // Custom Signature 'excitingFunction'
127     const int excitingFunctionArgc = 1;
128     v8::Handle<v8::FunctionTemplate> excitingFunctionArgv[excitingFunctionArgc] = { V8Node::GetRawTemplate() };
129     v8::Handle<v8::Signature> excitingFunctionSignature = v8::Signature::New(desc, excitingFunctionArgc, excitingFunctionArgv);
130     proto->Set(v8::String::NewSymbol("excitingFunction"), v8::FunctionTemplate::New(TestActiveDOMObjectV8Internal::excitingFunctionCallback, v8Undefined(), excitingFunctionSignature));
131
132     // Function 'postMessage' (ExtAttr: 'DoNotCheckSecurity')
133     proto->SetAccessor(v8::String::NewSymbol("postMessage"), TestActiveDOMObjectV8Internal::postMessageAttrGetter, TestActiveDOMObjectV8Internal::TestActiveDOMObjectDomainSafeFunctionSetter, v8Undefined(), v8::ALL_CAN_READ, static_cast<v8::PropertyAttribute>(v8::DontDelete));
134
135     // Custom toString template
136     desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
137     return desc;
138 }
139
140 v8::Persistent<v8::FunctionTemplate> V8TestActiveDOMObject::GetRawTemplate()
141 {
142     V8PerIsolateData* data = V8PerIsolateData::current();
143     V8PerIsolateData::TemplateMap::iterator result = data->rawTemplateMap().find(&info);
144     if (result != data->rawTemplateMap().end())
145         return result->value;
146
147     v8::HandleScope handleScope;
148     v8::Persistent<v8::FunctionTemplate> templ = createRawTemplate();
149     data->rawTemplateMap().add(&info, templ);
150     return templ;
151 }
152
153 v8::Persistent<v8::FunctionTemplate> V8TestActiveDOMObject::GetTemplate()
154 {
155     V8PerIsolateData* data = V8PerIsolateData::current();
156     V8PerIsolateData::TemplateMap::iterator result = data->templateMap().find(&info);
157     if (result != data->templateMap().end())
158         return result->value;
159
160     v8::HandleScope handleScope;
161     v8::Persistent<v8::FunctionTemplate> templ =
162         ConfigureV8TestActiveDOMObjectTemplate(GetRawTemplate());
163     data->templateMap().add(&info, templ);
164     return templ;
165 }
166
167 bool V8TestActiveDOMObject::HasInstance(v8::Handle<v8::Value> value)
168 {
169     return GetRawTemplate()->HasInstance(value);
170 }
171
172
173 v8::Handle<v8::Object> V8TestActiveDOMObject::createWrapper(PassRefPtr<TestActiveDOMObject> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
174 {
175     ASSERT(impl.get());
176     ASSERT(DOMDataStore::getWrapper(impl.get(), isolate).IsEmpty());
177
178     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &info, impl.get());
179     if (UNLIKELY(wrapper.IsEmpty()))
180         return wrapper;
181
182     installPerContextProperties(wrapper, impl.get());
183     v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate);
184     if (!hasDependentLifetime)
185         wrapperHandle.MarkIndependent();
186     return wrapper;
187 }
188
189 void V8TestActiveDOMObject::derefObject(void* object)
190 {
191     static_cast<TestActiveDOMObject*>(object)->deref();
192 }
193
194 } // namespace WebCore