Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Side by Side Diff: Source/WebCore/bindings/scripts/test/V8/V8TestSerializedScriptValueInterface.cpp

Issue 13937004: Move bindings-tests to bindings/tests (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 #if ENABLE(Condition1) || ENABLE(Condition2)
23 #include "V8TestSerializedScriptValueInterface.h"
24
25 #include "BindingState.h"
26 #include "ContextFeatures.h"
27 #include "ExceptionCode.h"
28 #include "Frame.h"
29 #include "MessagePort.h"
30 #include "RuntimeEnabledFeatures.h"
31 #include "SerializedScriptValue.h"
32 #include "V8Binding.h"
33 #include "V8DOMWrapper.h"
34 #include "V8MessagePort.h"
35 #include <wtf/ArrayBuffer.h>
36 #include <wtf/UnusedParam.h>
37
38 #if ENABLE(BINDING_INTEGRITY)
39 #if defined(OS_WIN)
40 #pragma warning(disable: 4483)
41 extern "C" { extern void (*const __identifier("??_7TestSerializedScriptValueInte rface@WebCore@@6B@")[])(); }
42 #else
43 extern "C" { extern void* _ZTVN7WebCore34TestSerializedScriptValueInterfaceE[]; }
44 #endif
45 #endif // ENABLE(BINDING_INTEGRITY)
46
47 namespace WebCore {
48
49 #if ENABLE(BINDING_INTEGRITY)
50 // This checks if a DOM object that is about to be wrapped is valid.
51 // Specifically, it checks that a vtable of the DOM object is equal to
52 // a vtable of an expected class.
53 // Due to a dangling pointer, the DOM object you are wrapping might be
54 // already freed or realloced. If freed, the check will fail because
55 // a free list pointer should be stored at the head of the DOM object.
56 // If realloced, the check will fail because the vtable of the DOM object
57 // differs from the expected vtable (unless the same class of DOM object
58 // is realloced on the slot).
59 inline void checkTypeOrDieTrying(TestSerializedScriptValueInterface* object)
60 {
61 void* actualVTablePointer = *(reinterpret_cast<void**>(object));
62 #if defined(OS_WIN)
63 void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7Test SerializedScriptValueInterface@WebCore@@6B@"));
64 #else
65 void* expectedVTablePointer = &_ZTVN7WebCore34TestSerializedScriptValueInter faceE[2];
66 #endif
67 if (actualVTablePointer != expectedVTablePointer)
68 CRASH();
69 }
70 #endif // ENABLE(BINDING_INTEGRITY)
71
72 WrapperTypeInfo V8TestSerializedScriptValueInterface::info = { V8TestSerializedS criptValueInterface::GetTemplate, V8TestSerializedScriptValueInterface::derefObj ect, 0, 0, 0, V8TestSerializedScriptValueInterface::installPerContextPrototypePr operties, 0, WrapperTypeObjectPrototype };
73
74 namespace TestSerializedScriptValueInterfaceV8Internal {
75
76 template <typename T> void V8_USE(T) { }
77
78 static v8::Handle<v8::Value> valueAttrGetter(v8::Local<v8::String> name, const v 8::AccessorInfo& info)
79 {
80 TestSerializedScriptValueInterface* imp = V8TestSerializedScriptValueInterfa ce::toNative(info.Holder());
81 return imp->value() ? imp->value()->deserialize() : v8::Handle<v8::Value>(v8 Null(info.GetIsolate()));
82 }
83
84 static v8::Handle<v8::Value> valueAttrGetterCallback(v8::Local<v8::String> name, const v8::AccessorInfo& info)
85 {
86 return TestSerializedScriptValueInterfaceV8Internal::valueAttrGetter(name, i nfo);
87 }
88
89 static void valueAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> val ue, const v8::AccessorInfo& info)
90 {
91 TestSerializedScriptValueInterface* imp = V8TestSerializedScriptValueInterfa ce::toNative(info.Holder());
92 V8TRYCATCH_VOID(RefPtr<SerializedScriptValue>, v, SerializedScriptValue::cre ate(value, info.GetIsolate()));
93 imp->setValue(WTF::getPtr(v));
94 return;
95 }
96
97 static void valueAttrSetterCallback(v8::Local<v8::String> name, v8::Local<v8::Va lue> value, const v8::AccessorInfo& info)
98 {
99 TestSerializedScriptValueInterfaceV8Internal::valueAttrSetter(name, value, i nfo);
100 }
101
102 static v8::Handle<v8::Value> readonlyValueAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
103 {
104 TestSerializedScriptValueInterface* imp = V8TestSerializedScriptValueInterfa ce::toNative(info.Holder());
105 return imp->readonlyValue() ? imp->readonlyValue()->deserialize() : v8::Hand le<v8::Value>(v8Null(info.GetIsolate()));
106 }
107
108 static v8::Handle<v8::Value> readonlyValueAttrGetterCallback(v8::Local<v8::Strin g> name, const v8::AccessorInfo& info)
109 {
110 return TestSerializedScriptValueInterfaceV8Internal::readonlyValueAttrGetter (name, info);
111 }
112
113 static v8::Handle<v8::Value> cachedValueAttrGetter(v8::Local<v8::String> name, c onst v8::AccessorInfo& info)
114 {
115 v8::Handle<v8::String> propertyName = v8::String::NewSymbol("cachedValue");
116 v8::Handle<v8::Value> value = info.Holder()->GetHiddenValue(propertyName);
117 if (!value.IsEmpty())
118 return value;
119 TestSerializedScriptValueInterface* imp = V8TestSerializedScriptValueInterfa ce::toNative(info.Holder());
120 RefPtr<SerializedScriptValue> serialized = imp->cachedValue();
121 value = serialized ? serialized->deserialize() : v8::Handle<v8::Value>(v8Nul l(info.GetIsolate()));
122 info.Holder()->SetHiddenValue(propertyName, value);
123 return value;
124 }
125
126 static v8::Handle<v8::Value> cachedValueAttrGetterCallback(v8::Local<v8::String> name, const v8::AccessorInfo& info)
127 {
128 return TestSerializedScriptValueInterfaceV8Internal::cachedValueAttrGetter(n ame, info);
129 }
130
131 static void cachedValueAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Valu e> value, const v8::AccessorInfo& info)
132 {
133 TestSerializedScriptValueInterface* imp = V8TestSerializedScriptValueInterfa ce::toNative(info.Holder());
134 V8TRYCATCH_VOID(RefPtr<SerializedScriptValue>, v, SerializedScriptValue::cre ate(value, info.GetIsolate()));
135 imp->setCachedValue(WTF::getPtr(v));
136 info.Holder()->DeleteHiddenValue(v8::String::NewSymbol("cachedValue")); // I nvalidate the cached value.
137 return;
138 }
139
140 static void cachedValueAttrSetterCallback(v8::Local<v8::String> name, v8::Local< v8::Value> value, const v8::AccessorInfo& info)
141 {
142 TestSerializedScriptValueInterfaceV8Internal::cachedValueAttrSetter(name, va lue, info);
143 }
144
145 static v8::Handle<v8::Value> portsAttrGetter(v8::Local<v8::String> name, const v 8::AccessorInfo& info)
146 {
147 TestSerializedScriptValueInterface* imp = V8TestSerializedScriptValueInterfa ce::toNative(info.Holder());
148 MessagePortArray* ports = imp->ports();
149 if (!ports)
150 return v8::Array::New(0);
151 MessagePortArray portsCopy(*ports);
152 v8::Local<v8::Array> portArray = v8::Array::New(portsCopy.size());
153 for (size_t i = 0; i < portsCopy.size(); ++i)
154 portArray->Set(v8Integer(i, info.GetIsolate()), toV8Fast(portsCopy[i].ge t(), info, imp));
155 return portArray;
156 }
157
158 static v8::Handle<v8::Value> portsAttrGetterCallback(v8::Local<v8::String> name, const v8::AccessorInfo& info)
159 {
160 return TestSerializedScriptValueInterfaceV8Internal::portsAttrGetter(name, i nfo);
161 }
162
163 static v8::Handle<v8::Value> cachedReadonlyValueAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
164 {
165 v8::Handle<v8::String> propertyName = v8::String::NewSymbol("cachedReadonlyV alue");
166 v8::Handle<v8::Value> value = info.Holder()->GetHiddenValue(propertyName);
167 if (!value.IsEmpty())
168 return value;
169 TestSerializedScriptValueInterface* imp = V8TestSerializedScriptValueInterfa ce::toNative(info.Holder());
170 RefPtr<SerializedScriptValue> serialized = imp->cachedReadonlyValue();
171 value = serialized ? serialized->deserialize() : v8::Handle<v8::Value>(v8Nul l(info.GetIsolate()));
172 info.Holder()->SetHiddenValue(propertyName, value);
173 return value;
174 }
175
176 static v8::Handle<v8::Value> cachedReadonlyValueAttrGetterCallback(v8::Local<v8: :String> name, const v8::AccessorInfo& info)
177 {
178 return TestSerializedScriptValueInterfaceV8Internal::cachedReadonlyValueAttr Getter(name, info);
179 }
180
181 static v8::Handle<v8::Value> acceptTransferListMethod(const v8::Arguments& args)
182 {
183 if (args.Length() < 1)
184 return throwNotEnoughArgumentsError(args.GetIsolate());
185 TestSerializedScriptValueInterface* imp = V8TestSerializedScriptValueInterfa ce::toNative(args.Holder());
186 MessagePortArray messagePortArrayTransferList;
187 ArrayBufferArray arrayBufferArrayTransferList;
188 if (args.Length() > 1) {
189 if (!extractTransferables(args[1], messagePortArrayTransferList, arrayBu fferArrayTransferList, args.GetIsolate()))
190 return throwTypeError("Could not extract transferables", args.GetIso late());
191 }
192 bool dataDidThrow = false;
193 RefPtr<SerializedScriptValue> data = SerializedScriptValue::create(args[0], &messagePortArrayTransferList, &arrayBufferArrayTransferList, dataDidThrow, args .GetIsolate());
194 if (dataDidThrow)
195 return v8Undefined();
196 if (args.Length() <= 1) {
197 imp->acceptTransferList(data);
198 return v8Undefined();
199 }
200 imp->acceptTransferList(data, messagePortArrayTransferList);
201 return v8Undefined();
202 }
203
204 static v8::Handle<v8::Value> acceptTransferListMethodCallback(const v8::Argument s& args)
205 {
206 return TestSerializedScriptValueInterfaceV8Internal::acceptTransferListMetho d(args);
207 }
208
209 static v8::Handle<v8::Value> multiTransferListMethod(const v8::Arguments& args)
210 {
211 TestSerializedScriptValueInterface* imp = V8TestSerializedScriptValueInterfa ce::toNative(args.Holder());
212 if (args.Length() <= 0) {
213 imp->multiTransferList();
214 return v8Undefined();
215 }
216 MessagePortArray messagePortArrayTx;
217 ArrayBufferArray arrayBufferArrayTx;
218 if (args.Length() > 1) {
219 if (!extractTransferables(args[1], messagePortArrayTx, arrayBufferArrayT x, args.GetIsolate()))
220 return throwTypeError("Could not extract transferables", args.GetIso late());
221 }
222 bool firstDidThrow = false;
223 RefPtr<SerializedScriptValue> first = SerializedScriptValue::create(args[0], &messagePortArrayTx, &arrayBufferArrayTx, firstDidThrow, args.GetIsolate());
224 if (firstDidThrow)
225 return v8Undefined();
226 if (args.Length() <= 1) {
227 imp->multiTransferList(first);
228 return v8Undefined();
229 }
230 if (args.Length() <= 2) {
231 imp->multiTransferList(first, messagePortArrayTx);
232 return v8Undefined();
233 }
234 MessagePortArray messagePortArrayTxx;
235 ArrayBufferArray arrayBufferArrayTxx;
236 if (args.Length() > 3) {
237 if (!extractTransferables(args[3], messagePortArrayTxx, arrayBufferArray Txx, args.GetIsolate()))
238 return throwTypeError("Could not extract transferables", args.GetIso late());
239 }
240 bool secondDidThrow = false;
241 RefPtr<SerializedScriptValue> second = SerializedScriptValue::create(args[2] , &messagePortArrayTxx, &arrayBufferArrayTxx, secondDidThrow, args.GetIsolate()) ;
242 if (secondDidThrow)
243 return v8Undefined();
244 if (args.Length() <= 3) {
245 imp->multiTransferList(first, messagePortArrayTx, second);
246 return v8Undefined();
247 }
248 imp->multiTransferList(first, messagePortArrayTx, second, messagePortArrayTx x);
249 return v8Undefined();
250 }
251
252 static v8::Handle<v8::Value> multiTransferListMethodCallback(const v8::Arguments & args)
253 {
254 return TestSerializedScriptValueInterfaceV8Internal::multiTransferListMethod (args);
255 }
256
257 static v8::Handle<v8::Value> constructor(const v8::Arguments& args)
258 {
259 if (args.Length() < 2)
260 return throwNotEnoughArgumentsError(args.GetIsolate());
261 V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, hello, args[0]);
262 MessagePortArray messagePortArrayTransferList;
263 ArrayBufferArray arrayBufferArrayTransferList;
264 if (args.Length() > 2) {
265 if (!extractTransferables(args[2], messagePortArrayTransferList, arrayBu fferArrayTransferList, args.GetIsolate()))
266 return throwTypeError("Could not extract transferables", args.GetIso late());
267 }
268 bool dataDidThrow = false;
269 RefPtr<SerializedScriptValue> data = SerializedScriptValue::create(args[1], &messagePortArrayTransferList, &arrayBufferArrayTransferList, dataDidThrow, args .GetIsolate());
270 if (dataDidThrow)
271 return v8Undefined();
272
273 RefPtr<TestSerializedScriptValueInterface> impl = TestSerializedScriptValueI nterface::create(hello, data, messagePortArrayTransferList);
274 v8::Handle<v8::Object> wrapper = args.Holder();
275
276 V8DOMWrapper::associateObjectWithWrapper(impl.release(), &V8TestSerializedSc riptValueInterface::info, wrapper, args.GetIsolate(), WrapperConfiguration::Depe ndent);
277 return wrapper;
278 }
279
280 } // namespace TestSerializedScriptValueInterfaceV8Internal
281
282 static const V8DOMConfiguration::BatchedAttribute V8TestSerializedScriptValueInt erfaceAttrs[] = {
283 // Attribute 'value' (Type: 'attribute' ExtAttr: '')
284 {"value", TestSerializedScriptValueInterfaceV8Internal::valueAttrGetterCallb ack, TestSerializedScriptValueInterfaceV8Internal::valueAttrSetterCallback, 0, 0 , 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8:: PropertyAttribute>(v8::None), 0 /* on instance */},
285 // Attribute 'readonlyValue' (Type: 'readonly attribute' ExtAttr: '')
286 {"readonlyValue", TestSerializedScriptValueInterfaceV8Internal::readonlyValu eAttrGetterCallback, 0, 0, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8 ::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
287 // Attribute 'cachedValue' (Type: 'attribute' ExtAttr: 'CachedAttribute')
288 {"cachedValue", TestSerializedScriptValueInterfaceV8Internal::cachedValueAtt rGetterCallback, TestSerializedScriptValueInterfaceV8Internal::cachedValueAttrSe tterCallback, 0, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT) , static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
289 // Attribute 'ports' (Type: 'readonly attribute' ExtAttr: '')
290 {"ports", TestSerializedScriptValueInterfaceV8Internal::portsAttrGetterCallb ack, 0, 0, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), stat ic_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
291 // Attribute 'cachedReadonlyValue' (Type: 'readonly attribute' ExtAttr: 'Cac hedAttribute')
292 {"cachedReadonlyValue", TestSerializedScriptValueInterfaceV8Internal::cached ReadonlyValueAttrGetterCallback, 0, 0, 0, 0 /* no data */, static_cast<v8::Acces sControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on in stance */},
293 };
294
295 static const V8DOMConfiguration::BatchedMethod V8TestSerializedScriptValueInterf aceMethods[] = {
296 {"acceptTransferList", TestSerializedScriptValueInterfaceV8Internal::acceptT ransferListMethodCallback, 0},
297 {"multiTransferList", TestSerializedScriptValueInterfaceV8Internal::multiTra nsferListMethodCallback, 0},
298 };
299
300 v8::Handle<v8::Value> V8TestSerializedScriptValueInterface::constructorCallback( const v8::Arguments& args)
301 {
302 if (!args.IsConstructCall())
303 return throwTypeError("DOM object constructor cannot be called as a func tion.", args.GetIsolate());
304
305 if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
306 return args.Holder();
307
308 return TestSerializedScriptValueInterfaceV8Internal::constructor(args);
309 }
310
311 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestSerializedScriptValue InterfaceTemplate(v8::Persistent<v8::FunctionTemplate> desc, v8::Isolate* isolat e, WrapperWorldType currentWorldType)
312 {
313 desc->ReadOnlyPrototype();
314
315 v8::Local<v8::Signature> defaultSignature;
316 defaultSignature = V8DOMConfiguration::configureTemplate(desc, "TestSerializ edScriptValueInterface", v8::Persistent<v8::FunctionTemplate>(), V8TestSerialize dScriptValueInterface::internalFieldCount,
317 V8TestSerializedScriptValueInterfaceAttrs, WTF_ARRAY_LENGTH(V8TestSerial izedScriptValueInterfaceAttrs),
318 V8TestSerializedScriptValueInterfaceMethods, WTF_ARRAY_LENGTH(V8TestSeri alizedScriptValueInterfaceMethods), isolate, currentWorldType);
319 UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
320 desc->SetCallHandler(V8TestSerializedScriptValueInterface::constructorCallba ck);
321 v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
322 v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate();
323 UNUSED_PARAM(instance); // In some cases, it will not be used.
324 UNUSED_PARAM(proto); // In some cases, it will not be used.
325
326
327 // Custom toString template
328 desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->to StringTemplate());
329 return desc;
330 }
331
332 v8::Persistent<v8::FunctionTemplate> V8TestSerializedScriptValueInterface::GetTe mplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
333 {
334 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
335 V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWo rldType).find(&info);
336 if (result != data->templateMap(currentWorldType).end())
337 return result->value;
338
339 v8::HandleScope handleScope;
340 v8::Persistent<v8::FunctionTemplate> templ =
341 ConfigureV8TestSerializedScriptValueInterfaceTemplate(data->rawTemplate( &info, currentWorldType), isolate, currentWorldType);
342 data->templateMap(currentWorldType).add(&info, templ);
343 return templ;
344 }
345
346 bool V8TestSerializedScriptValueInterface::HasInstance(v8::Handle<v8::Value> val ue, v8::Isolate* isolate, WrapperWorldType currentWorldType)
347 {
348 return V8PerIsolateData::from(isolate)->hasInstance(&info, value, currentWor ldType);
349 }
350
351 bool V8TestSerializedScriptValueInterface::HasInstanceInAnyWorld(v8::Handle<v8:: Value> value, v8::Isolate* isolate)
352 {
353 return V8PerIsolateData::from(isolate)->hasInstance(&info, value, MainWorld)
354 || V8PerIsolateData::from(isolate)->hasInstance(&info, value, IsolatedWo rld)
355 || V8PerIsolateData::from(isolate)->hasInstance(&info, value, WorkerWorl d);
356 }
357
358
359 v8::Handle<v8::Object> V8TestSerializedScriptValueInterface::createWrapper(PassR efPtr<TestSerializedScriptValueInterface> impl, v8::Handle<v8::Object> creationC ontext, v8::Isolate* isolate)
360 {
361 ASSERT(impl.get());
362 ASSERT(DOMDataStore::getWrapper(impl.get(), isolate).IsEmpty());
363
364 #if ENABLE(BINDING_INTEGRITY)
365 checkTypeOrDieTrying(impl.get());
366 #endif
367
368 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext , &info, impl.get(), isolate);
369 if (UNLIKELY(wrapper.IsEmpty()))
370 return wrapper;
371
372 installPerContextProperties(wrapper, impl.get(), isolate);
373 V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate, hasD ependentLifetime ? WrapperConfiguration::Dependent : WrapperConfiguration::Indep endent);
374 return wrapper;
375 }
376 void V8TestSerializedScriptValueInterface::derefObject(void* object)
377 {
378 static_cast<TestSerializedScriptValueInterface*>(object)->deref();
379 }
380
381 } // namespace WebCore
382
383 #endif // ENABLE(Condition1) || ENABLE(Condition2)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698