78c3fff5f556074d09ed227791b39d7cbeb7a108
[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 #if ENABLE(BINDING_INTEGRITY)
35 #if defined(OS_WIN)
36 #pragma warning(disable: 4483)
37 extern "C" { extern void (*const __identifier("??_7TestActiveDOMObject@WebCore@@6B@")[])(); }
38 #else
39 extern "C" { extern void* _ZTVN7WebCore19TestActiveDOMObjectE[]; }
40 #endif
41 #endif // ENABLE(BINDING_INTEGRITY)
42
43 namespace WebCore {
44
45 #if ENABLE(BINDING_INTEGRITY)
46 // This checks if a DOM object that is about to be wrapped is valid.
47 // Specifically, it checks that a vtable of the DOM object is equal to
48 // a vtable of an expected class.
49 // Due to a dangling pointer, the DOM object you are wrapping might be
50 // already freed or realloced. If freed, the check will fail because
51 // a free list pointer should be stored at the head of the DOM object.
52 // If realloced, the check will fail because the vtable of the DOM object
53 // differs from the expected vtable (unless the same class of DOM object
54 // is realloced on the slot).
55 inline void checkTypeOrDieTrying(TestActiveDOMObject* object)
56 {
57     void* actualVTablePointer = *(reinterpret_cast<void**>(object));
58 #if defined(OS_WIN)
59     void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7TestActiveDOMObject@WebCore@@6B@"));
60 #else
61     void* expectedVTablePointer = &_ZTVN7WebCore19TestActiveDOMObjectE[2];
62 #endif
63     if (actualVTablePointer != expectedVTablePointer)
64         CRASH();
65 }
66 #endif // ENABLE(BINDING_INTEGRITY)
67
68 WrapperTypeInfo V8TestActiveDOMObject::info = { V8TestActiveDOMObject::GetTemplate, V8TestActiveDOMObject::derefObject, 0, 0, 0, V8TestActiveDOMObject::installPerContextPrototypeProperties, 0, WrapperTypeObjectPrototype };
69
70 namespace TestActiveDOMObjectV8Internal {
71
72 template <typename T> void V8_USE(T) { }
73
74 static v8::Handle<v8::Value> excitingAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
75 {
76     TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(info.Holder());
77     return v8Integer(imp->excitingAttr(), info.GetIsolate());
78 }
79
80 static v8::Handle<v8::Value> excitingAttrAttrGetterCallback(v8::Local<v8::String> name, const v8::AccessorInfo& info)
81 {
82     return TestActiveDOMObjectV8Internal::excitingAttrAttrGetter(name, info);
83 }
84
85 bool indexedSecurityCheck(v8::Local<v8::Object> host, uint32_t index, v8::AccessType type, v8::Local<v8::Value>)
86 {
87     TestActiveDOMObject* imp =  V8TestActiveDOMObject::toNative(host);
88     return BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), imp->frame(), DoNotReportSecurityError);
89 }
90
91 bool namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value>)
92 {
93     TestActiveDOMObject* imp =  V8TestActiveDOMObject::toNative(host);
94     return BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), imp->frame(), DoNotReportSecurityError);
95 }
96
97 static v8::Handle<v8::Value> excitingFunctionMethod(const v8::Arguments& args)
98 {
99     if (args.Length() < 1)
100         return throwNotEnoughArgumentsError(args.GetIsolate());
101     TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(args.Holder());
102     if (!BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), imp->frame()))
103         return v8Undefined();
104     V8TRYCATCH(Node*, nextChild, V8Node::HasInstance(args[0], args.GetIsolate()) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0);
105     imp->excitingFunction(nextChild);
106     return v8Undefined();
107 }
108
109 static v8::Handle<v8::Value> excitingFunctionMethodCallback(const v8::Arguments& args)
110 {
111     return TestActiveDOMObjectV8Internal::excitingFunctionMethod(args);
112 }
113
114 static v8::Handle<v8::Value> postMessageMethod(const v8::Arguments& args)
115 {
116     if (args.Length() < 1)
117         return throwNotEnoughArgumentsError(args.GetIsolate());
118     TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(args.Holder());
119     V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, message, args[0]);
120     imp->postMessage(message);
121     return v8Undefined();
122 }
123
124 static v8::Handle<v8::Value> postMessageMethodCallback(const v8::Arguments& args)
125 {
126     return TestActiveDOMObjectV8Internal::postMessageMethod(args);
127 }
128
129 static v8::Handle<v8::Value> postMessageAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
130 {
131     static v8::Persistent<v8::FunctionTemplate> privateTemplate = v8::Persistent<v8::FunctionTemplate>::New(info.GetIsolate(), v8::FunctionTemplate::New(TestActiveDOMObjectV8Internal::postMessageMethodCallback, v8Undefined(), v8::Signature::New(V8TestActiveDOMObject::GetRawTemplate(info.GetIsolate()))));
132     v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8TestActiveDOMObject::GetTemplate(info.GetIsolate(), worldType(info.GetIsolate())));
133     if (holder.IsEmpty()) {
134         // can only reach here by 'object.__proto__.func', and it should passed
135         // domain security check already
136         return privateTemplate->GetFunction();
137     }
138     TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(holder);
139     if (!BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), imp->frame(), DoNotReportSecurityError)) {
140         static v8::Persistent<v8::FunctionTemplate> sharedTemplate = v8::Persistent<v8::FunctionTemplate>::New(info.GetIsolate(), v8::FunctionTemplate::New(TestActiveDOMObjectV8Internal::postMessageMethodCallback, v8Undefined(), v8::Signature::New(V8TestActiveDOMObject::GetRawTemplate(info.GetIsolate()))));
141         return sharedTemplate->GetFunction();
142     }
143
144     v8::Local<v8::Value> hiddenValue = info.This()->GetHiddenValue(name);
145     if (!hiddenValue.IsEmpty())
146         return hiddenValue;
147
148     return privateTemplate->GetFunction();
149 }
150
151 static v8::Handle<v8::Value> postMessageAttrGetterCallback(v8::Local<v8::String> name, const v8::AccessorInfo& info)
152 {
153     return TestActiveDOMObjectV8Internal::postMessageAttrGetter(name, info);
154 }
155
156 static void TestActiveDOMObjectDomainSafeFunctionSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
157 {
158     v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8TestActiveDOMObject::GetTemplate(info.GetIsolate(), worldType(info.GetIsolate())));
159     if (holder.IsEmpty())
160         return;
161     TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(holder);
162     if (!BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), imp->frame()))
163         return;
164
165     info.This()->SetHiddenValue(name, value);
166 }
167
168 } // namespace TestActiveDOMObjectV8Internal
169
170 static const V8DOMConfiguration::BatchedAttribute V8TestActiveDOMObjectAttrs[] = {
171     // Attribute 'excitingAttr' (Type: 'readonly attribute' ExtAttr: '')
172     {"excitingAttr", TestActiveDOMObjectV8Internal::excitingAttrAttrGetterCallback, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
173 };
174
175 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestActiveDOMObjectTemplate(v8::Persistent<v8::FunctionTemplate> desc, v8::Isolate* isolate, WrapperWorldType worldType)
176 {
177     desc->ReadOnlyPrototype();
178
179     v8::Local<v8::Signature> defaultSignature;
180     defaultSignature = V8DOMConfiguration::configureTemplate(desc, "TestActiveDOMObject", v8::Persistent<v8::FunctionTemplate>(), V8TestActiveDOMObject::internalFieldCount,
181         V8TestActiveDOMObjectAttrs, WTF_ARRAY_LENGTH(V8TestActiveDOMObjectAttrs),
182         0, 0, isolate);
183     UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
184     v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
185     v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate();
186     UNUSED_PARAM(instance); // In some cases, it will not be used.
187     UNUSED_PARAM(proto); // In some cases, it will not be used.
188     instance->SetAccessCheckCallbacks(TestActiveDOMObjectV8Internal::namedSecurityCheck, TestActiveDOMObjectV8Internal::indexedSecurityCheck, v8::External::New(&V8TestActiveDOMObject::info));
189
190     // Custom Signature 'excitingFunction'
191     const int excitingFunctionArgc = 1;
192     v8::Handle<v8::FunctionTemplate> excitingFunctionArgv[excitingFunctionArgc] = { V8Node::GetRawTemplate(isolate) };
193     v8::Handle<v8::Signature> excitingFunctionSignature = v8::Signature::New(desc, excitingFunctionArgc, excitingFunctionArgv);
194     proto->Set(v8::String::NewSymbol("excitingFunction"), v8::FunctionTemplate::New(TestActiveDOMObjectV8Internal::excitingFunctionMethodCallback, v8Undefined(), excitingFunctionSignature));
195
196     // Function 'postMessage' (ExtAttr: 'DoNotCheckSecurity')
197     proto->SetAccessor(v8::String::NewSymbol("postMessage"), TestActiveDOMObjectV8Internal::postMessageAttrGetterCallback, TestActiveDOMObjectV8Internal::TestActiveDOMObjectDomainSafeFunctionSetter, v8Undefined(), v8::ALL_CAN_READ, static_cast<v8::PropertyAttribute>(v8::DontDelete));
198
199     // Custom toString template
200     desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
201     return desc;
202 }
203
204 v8::Persistent<v8::FunctionTemplate> V8TestActiveDOMObject::GetRawTemplate(v8::Isolate* isolate)
205 {
206     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
207     V8PerIsolateData::TemplateMap::iterator result = data->rawTemplateMap().find(&info);
208     if (result != data->rawTemplateMap().end())
209         return result->value;
210
211     v8::HandleScope handleScope;
212     v8::Persistent<v8::FunctionTemplate> templ = createRawTemplate(isolate);
213     data->rawTemplateMap().add(&info, templ);
214     return templ;
215 }
216
217 v8::Persistent<v8::FunctionTemplate> V8TestActiveDOMObject::GetTemplate(v8::Isolate* isolate, WrapperWorldType worldType)
218 {
219     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
220     V8PerIsolateData::TemplateMap::iterator result = data->templateMap().find(&info);
221     if (result != data->templateMap().end())
222         return result->value;
223
224     v8::HandleScope handleScope;
225     v8::Persistent<v8::FunctionTemplate> templ =
226         ConfigureV8TestActiveDOMObjectTemplate(GetRawTemplate(isolate), isolate, worldType);
227     data->templateMap().add(&info, templ);
228     return templ;
229 }
230
231 bool V8TestActiveDOMObject::HasInstance(v8::Handle<v8::Value> value, v8::Isolate* isolate)
232 {
233     return GetRawTemplate(isolate)->HasInstance(value);
234 }
235
236
237 v8::Handle<v8::Object> V8TestActiveDOMObject::createWrapper(PassRefPtr<TestActiveDOMObject> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
238 {
239     ASSERT(impl.get());
240     ASSERT(DOMDataStore::getWrapper(impl.get(), isolate).IsEmpty());
241
242 #if ENABLE(BINDING_INTEGRITY)
243     checkTypeOrDieTrying(impl.get());
244 #endif
245
246     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &info, impl.get(), isolate);
247     if (UNLIKELY(wrapper.IsEmpty()))
248         return wrapper;
249
250     installPerContextProperties(wrapper, impl.get(), isolate);
251     V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate, hasDependentLifetime ? WrapperConfiguration::Dependent : WrapperConfiguration::Independent);
252     return wrapper;
253 }
254 void V8TestActiveDOMObject::derefObject(void* object)
255 {
256     static_cast<TestActiveDOMObject*>(object)->deref();
257 }
258
259 } // namespace WebCore