Unreviewed, rolling out r112199.
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / V8 / V8TestSerializedScriptValueInterface.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 "V8TestSerializedScriptValueInterface.h"
23
24 #if ENABLE(Condition1) || ENABLE(Condition2)
25
26 #include "ArrayBuffer.h"
27 #include "ExceptionCode.h"
28 #include "MessagePort.h"
29 #include "RuntimeEnabledFeatures.h"
30 #include "SerializedScriptValue.h"
31 #include "V8Binding.h"
32 #include "V8BindingMacros.h"
33 #include "V8BindingState.h"
34 #include "V8DOMWrapper.h"
35 #include "V8IsolatedContext.h"
36 #include "V8Proxy.h"
37 #include <wtf/UnusedParam.h>
38
39 namespace WebCore {
40
41 WrapperTypeInfo V8TestSerializedScriptValueInterface::info = { V8TestSerializedScriptValueInterface::GetTemplate, V8TestSerializedScriptValueInterface::derefObject, 0, 0 };
42
43 namespace TestSerializedScriptValueInterfaceInternal {
44
45 template <typename T> void V8_USE(T) { }
46
47 static v8::Handle<v8::Value> valueAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
48 {
49     INC_STATS("DOM.TestSerializedScriptValueInterface.value._get");
50     TestSerializedScriptValueInterface* imp = V8TestSerializedScriptValueInterface::toNative(info.Holder());
51     return imp->value() ? imp->value()->deserialize() : v8::Handle<v8::Value>(v8::Null());
52 }
53
54 static void valueAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
55 {
56     INC_STATS("DOM.TestSerializedScriptValueInterface.value._set");
57     TestSerializedScriptValueInterface* imp = V8TestSerializedScriptValueInterface::toNative(info.Holder());
58     RefPtr<SerializedScriptValue> v = SerializedScriptValue::create(value);
59     imp->setValue(WTF::getPtr(v));
60     return;
61 }
62
63 static v8::Handle<v8::Value> readonlyValueAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
64 {
65     INC_STATS("DOM.TestSerializedScriptValueInterface.readonlyValue._get");
66     TestSerializedScriptValueInterface* imp = V8TestSerializedScriptValueInterface::toNative(info.Holder());
67     return imp->readonlyValue() ? imp->readonlyValue()->deserialize() : v8::Handle<v8::Value>(v8::Null());
68 }
69
70 static v8::Handle<v8::Value> cachedValueAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
71 {
72     INC_STATS("DOM.TestSerializedScriptValueInterface.cachedValue._get");
73     v8::Handle<v8::String> propertyName = v8::String::NewSymbol("cachedValue");
74     v8::Handle<v8::Value> value = info.Holder()->GetHiddenValue(propertyName);
75     if (!value.IsEmpty())
76         return value;
77     TestSerializedScriptValueInterface* imp = V8TestSerializedScriptValueInterface::toNative(info.Holder());
78     SerializedScriptValue* serialized = imp->cachedValue();
79     value = serialized ? serialized->deserialize() : v8::Handle<v8::Value>(v8::Null());
80     info.Holder()->SetHiddenValue(propertyName, value);
81     return value;
82 }
83
84 static void cachedValueAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
85 {
86     INC_STATS("DOM.TestSerializedScriptValueInterface.cachedValue._set");
87     TestSerializedScriptValueInterface* imp = V8TestSerializedScriptValueInterface::toNative(info.Holder());
88     RefPtr<SerializedScriptValue> v = SerializedScriptValue::create(value);
89     imp->setCachedValue(WTF::getPtr(v));
90     info.Holder()->DeleteHiddenValue(v8::String::NewSymbol("cachedValue")); // Invalidate the cached value.
91     return;
92 }
93
94 static v8::Handle<v8::Value> cachedReadonlyValueAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
95 {
96     INC_STATS("DOM.TestSerializedScriptValueInterface.cachedReadonlyValue._get");
97     v8::Handle<v8::String> propertyName = v8::String::NewSymbol("cachedReadonlyValue");
98     v8::Handle<v8::Value> value = info.Holder()->GetHiddenValue(propertyName);
99     if (!value.IsEmpty())
100         return value;
101     TestSerializedScriptValueInterface* imp = V8TestSerializedScriptValueInterface::toNative(info.Holder());
102     SerializedScriptValue* serialized = imp->cachedReadonlyValue();
103     value = serialized ? serialized->deserialize() : v8::Handle<v8::Value>(v8::Null());
104     info.Holder()->SetHiddenValue(propertyName, value);
105     return value;
106 }
107
108 static v8::Handle<v8::Value> acceptTransferListCallback(const v8::Arguments& args)
109 {
110     INC_STATS("DOM.TestSerializedScriptValueInterface.acceptTransferList");
111     if (args.Length() < 1)
112         return throwError("Not enough arguments", V8Proxy::TypeError);
113     TestSerializedScriptValueInterface* imp = V8TestSerializedScriptValueInterface::toNative(args.Holder());
114     MessagePortArray messagePortArrayTransferList;
115     ArrayBufferArray arrayBufferArrayTransferList;
116     if (args.Length() > 1) {
117         if (!extractTransferables(args[1], messagePortArrayTransferList, arrayBufferArrayTransferList))
118             return throwError("Could not extract transferables", V8Proxy::TypeError);
119     }
120     bool dataDidThrow = false;
121     RefPtr<SerializedScriptValue> data = SerializedScriptValue::create(args[0], &messagePortArrayTransferList, &arrayBufferArrayTransferList, dataDidThrow);
122     if (dataDidThrow)
123         return v8::Undefined();
124     if (args.Length() <= 1) {
125         imp->acceptTransferList(data);
126         return v8::Handle<v8::Value>();
127     }
128     imp->acceptTransferList(data, messagePortArrayTransferList);
129     return v8::Handle<v8::Value>();
130 }
131
132 static v8::Handle<v8::Value> multiTransferListCallback(const v8::Arguments& args)
133 {
134     INC_STATS("DOM.TestSerializedScriptValueInterface.multiTransferList");
135     TestSerializedScriptValueInterface* imp = V8TestSerializedScriptValueInterface::toNative(args.Holder());
136     if (args.Length() <= 0) {
137         imp->multiTransferList();
138         return v8::Handle<v8::Value>();
139     }
140     MessagePortArray messagePortArrayTx;
141     ArrayBufferArray arrayBufferArrayTx;
142     if (args.Length() > 1) {
143         if (!extractTransferables(args[1], messagePortArrayTx, arrayBufferArrayTx))
144             return throwError("Could not extract transferables", V8Proxy::TypeError);
145     }
146     bool firstDidThrow = false;
147     RefPtr<SerializedScriptValue> first = SerializedScriptValue::create(args[0], &messagePortArrayTx, &arrayBufferArrayTx, firstDidThrow);
148     if (firstDidThrow)
149         return v8::Undefined();
150     if (args.Length() <= 1) {
151         imp->multiTransferList(first);
152         return v8::Handle<v8::Value>();
153     }
154     if (args.Length() <= 2) {
155         imp->multiTransferList(first, messagePortArrayTx);
156         return v8::Handle<v8::Value>();
157     }
158     MessagePortArray messagePortArrayTxx;
159     ArrayBufferArray arrayBufferArrayTxx;
160     if (args.Length() > 3) {
161         if (!extractTransferables(args[3], messagePortArrayTxx, arrayBufferArrayTxx))
162             return throwError("Could not extract transferables", V8Proxy::TypeError);
163     }
164     bool secondDidThrow = false;
165     RefPtr<SerializedScriptValue> second = SerializedScriptValue::create(args[2], &messagePortArrayTxx, &arrayBufferArrayTxx, secondDidThrow);
166     if (secondDidThrow)
167         return v8::Undefined();
168     if (args.Length() <= 3) {
169         imp->multiTransferList(first, messagePortArrayTx, second);
170         return v8::Handle<v8::Value>();
171     }
172     imp->multiTransferList(first, messagePortArrayTx, second, messagePortArrayTxx);
173     return v8::Handle<v8::Value>();
174 }
175
176 } // namespace TestSerializedScriptValueInterfaceInternal
177
178 static const BatchedAttribute TestSerializedScriptValueInterfaceAttrs[] = {
179     // Attribute 'value' (Type: 'attribute' ExtAttr: '')
180     {"value", TestSerializedScriptValueInterfaceInternal::valueAttrGetter, TestSerializedScriptValueInterfaceInternal::valueAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
181     // Attribute 'readonlyValue' (Type: 'readonly attribute' ExtAttr: '')
182     {"readonlyValue", TestSerializedScriptValueInterfaceInternal::readonlyValueAttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
183     // Attribute 'cachedValue' (Type: 'attribute' ExtAttr: 'CachedAttribute')
184     {"cachedValue", TestSerializedScriptValueInterfaceInternal::cachedValueAttrGetter, TestSerializedScriptValueInterfaceInternal::cachedValueAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
185     // Attribute 'cachedReadonlyValue' (Type: 'readonly attribute' ExtAttr: 'CachedAttribute')
186     {"cachedReadonlyValue", TestSerializedScriptValueInterfaceInternal::cachedReadonlyValueAttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
187 };
188
189 static const BatchedCallback TestSerializedScriptValueInterfaceCallbacks[] = {
190     {"acceptTransferList", TestSerializedScriptValueInterfaceInternal::acceptTransferListCallback},
191     {"multiTransferList", TestSerializedScriptValueInterfaceInternal::multiTransferListCallback},
192 };
193
194 v8::Handle<v8::Value> V8TestSerializedScriptValueInterface::constructorCallback(const v8::Arguments& args)
195 {
196     INC_STATS("DOM.TestSerializedScriptValueInterface.Constructor");
197
198     if (!args.IsConstructCall())
199         return throwError("DOM object constructor cannot be called as a function.", V8Proxy::TypeError);
200
201     if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
202         return args.Holder();
203     if (args.Length() < 2)
204         return throwError("Not enough arguments", V8Proxy::TypeError);
205     STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, hello, MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined));
206     MessagePortArray messagePortArrayTransferList;
207     ArrayBufferArray arrayBufferArrayTransferList;
208     if (args.Length() > 2) {
209         if (!extractTransferables(args[2], messagePortArrayTransferList, arrayBufferArrayTransferList))
210             return throwError("Could not extract transferables", V8Proxy::TypeError);
211     }
212     bool dataDidThrow = false;
213     RefPtr<SerializedScriptValue> data = SerializedScriptValue::create(args[1], &messagePortArrayTransferList, &arrayBufferArrayTransferList, dataDidThrow);
214     if (dataDidThrow)
215         return v8::Undefined();
216
217     RefPtr<TestSerializedScriptValueInterface> impl = TestSerializedScriptValueInterface::create(hello, data, messagePortArrayTransferList);
218     v8::Handle<v8::Object> wrapper = args.Holder();
219
220     V8DOMWrapper::setDOMWrapper(wrapper, &info, impl.get());
221     V8DOMWrapper::setJSWrapperForDOMObject(impl.release(), v8::Persistent<v8::Object>::New(wrapper));
222     return args.Holder();
223 }
224
225 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestSerializedScriptValueInterfaceTemplate(v8::Persistent<v8::FunctionTemplate> desc)
226 {
227     desc->ReadOnlyPrototype();
228
229     v8::Local<v8::Signature> defaultSignature;
230     defaultSignature = configureTemplate(desc, "TestSerializedScriptValueInterface", v8::Persistent<v8::FunctionTemplate>(), V8TestSerializedScriptValueInterface::internalFieldCount,
231         TestSerializedScriptValueInterfaceAttrs, WTF_ARRAY_LENGTH(TestSerializedScriptValueInterfaceAttrs),
232         TestSerializedScriptValueInterfaceCallbacks, WTF_ARRAY_LENGTH(TestSerializedScriptValueInterfaceCallbacks));
233     UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
234     desc->SetCallHandler(V8TestSerializedScriptValueInterface::constructorCallback);
235     v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
236     v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate();
237     UNUSED_PARAM(instance); // In some cases, it will not be used.
238     UNUSED_PARAM(proto); // In some cases, it will not be used.
239     
240
241     // Custom toString template
242     desc->Set(getToStringName(), getToStringTemplate());
243     return desc;
244 }
245
246 v8::Persistent<v8::FunctionTemplate> V8TestSerializedScriptValueInterface::GetRawTemplate()
247 {
248     V8BindingPerIsolateData* data = V8BindingPerIsolateData::current();
249     V8BindingPerIsolateData::TemplateMap::iterator result = data->rawTemplateMap().find(&info);
250     if (result != data->rawTemplateMap().end())
251         return result->second;
252
253     v8::HandleScope handleScope;
254     v8::Persistent<v8::FunctionTemplate> templ = createRawTemplate();
255     data->rawTemplateMap().add(&info, templ);
256     return templ;
257 }
258
259 v8::Persistent<v8::FunctionTemplate> V8TestSerializedScriptValueInterface::GetTemplate()
260 {
261     V8BindingPerIsolateData* data = V8BindingPerIsolateData::current();
262     V8BindingPerIsolateData::TemplateMap::iterator result = data->templateMap().find(&info);
263     if (result != data->templateMap().end())
264         return result->second;
265
266     v8::HandleScope handleScope;
267     v8::Persistent<v8::FunctionTemplate> templ =
268         ConfigureV8TestSerializedScriptValueInterfaceTemplate(GetRawTemplate());
269     data->templateMap().add(&info, templ);
270     return templ;
271 }
272
273 bool V8TestSerializedScriptValueInterface::HasInstance(v8::Handle<v8::Value> value)
274 {
275     return GetRawTemplate()->HasInstance(value);
276 }
277
278
279 v8::Handle<v8::Object> V8TestSerializedScriptValueInterface::wrapSlow(PassRefPtr<TestSerializedScriptValueInterface> impl)
280 {
281     v8::Handle<v8::Object> wrapper;
282     V8Proxy* proxy = 0;
283     wrapper = V8DOMWrapper::instantiateV8Object(proxy, &info, impl.get());
284     if (UNLIKELY(wrapper.IsEmpty()))
285         return wrapper;
286
287     v8::Persistent<v8::Object> wrapperHandle = v8::Persistent<v8::Object>::New(wrapper);
288
289     if (!hasDependentLifetime)
290         wrapperHandle.MarkIndependent();
291     getDOMObjectMap().set(impl.leakRef(), wrapperHandle);
292     return wrapper;
293 }
294
295 void V8TestSerializedScriptValueInterface::derefObject(void* object)
296 {
297     static_cast<TestSerializedScriptValueInterface*>(object)->deref();
298 }
299
300 } // namespace WebCore
301
302 #endif // ENABLE(Condition1) || ENABLE(Condition2)