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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include "config.h"
22
23#if ENABLE(ENCRYPTED_MEDIA)
24
25#include "JSMediaKeyMessageEvent.h"
26
27#include "JSDOMAttribute.h"
28#include "JSDOMBinding.h"
29#include "JSDOMConstructor.h"
30#include "JSDOMConvertBoolean.h"
31#include "JSDOMConvertBufferSource.h"
32#include "JSDOMConvertInterface.h"
33#include "JSDOMExceptionHandling.h"
34#include "JSDOMGlobalObject.h"
35#include "JSDOMWrapperCache.h"
36#include "ScriptExecutionContext.h"
37#include <JavaScriptCore/HeapSnapshotBuilder.h>
38#include <JavaScriptCore/JSCInlines.h>
39#include <JavaScriptCore/JSString.h>
40#include <wtf/GetPtr.h>
41#include <wtf/NeverDestroyed.h>
42#include <wtf/PointerPreparations.h>
43#include <wtf/URL.h>
44
45#if ENABLE(ENCRYPTED_MEDIA)
46#include "JSDOMConvertStrings.h"
47#endif
48
49
50namespace WebCore {
51using namespace JSC;
52
53String convertEnumerationToString(MediaKeyMessageEvent::Type enumerationValue)
54{
55 static const NeverDestroyed<String> values[] = {
56 MAKE_STATIC_STRING_IMPL("license-request"),
57 MAKE_STATIC_STRING_IMPL("license-renewal"),
58 MAKE_STATIC_STRING_IMPL("license-release"),
59 MAKE_STATIC_STRING_IMPL("individualization-request"),
60 };
61 static_assert(static_cast<size_t>(MediaKeyMessageEvent::Type::LicenseRequest) == 0, "MediaKeyMessageEvent::Type::LicenseRequest is not 0 as expected");
62 static_assert(static_cast<size_t>(MediaKeyMessageEvent::Type::LicenseRenewal) == 1, "MediaKeyMessageEvent::Type::LicenseRenewal is not 1 as expected");
63 static_assert(static_cast<size_t>(MediaKeyMessageEvent::Type::LicenseRelease) == 2, "MediaKeyMessageEvent::Type::LicenseRelease is not 2 as expected");
64 static_assert(static_cast<size_t>(MediaKeyMessageEvent::Type::IndividualizationRequest) == 3, "MediaKeyMessageEvent::Type::IndividualizationRequest is not 3 as expected");
65 ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values));
66 return values[static_cast<size_t>(enumerationValue)];
67}
68
69template<> JSString* convertEnumerationToJS(ExecState& state, MediaKeyMessageEvent::Type enumerationValue)
70{
71 return jsStringWithCache(&state, convertEnumerationToString(enumerationValue));
72}
73
74template<> Optional<MediaKeyMessageEvent::Type> parseEnumeration<MediaKeyMessageEvent::Type>(ExecState& state, JSValue value)
75{
76 auto stringValue = value.toWTFString(&state);
77 if (stringValue == "license-request")
78 return MediaKeyMessageEvent::Type::LicenseRequest;
79 if (stringValue == "license-renewal")
80 return MediaKeyMessageEvent::Type::LicenseRenewal;
81 if (stringValue == "license-release")
82 return MediaKeyMessageEvent::Type::LicenseRelease;
83 if (stringValue == "individualization-request")
84 return MediaKeyMessageEvent::Type::IndividualizationRequest;
85 return WTF::nullopt;
86}
87
88template<> const char* expectedEnumerationValues<MediaKeyMessageEvent::Type>()
89{
90 return "\"license-request\", \"license-renewal\", \"license-release\", \"individualization-request\"";
91}
92
93template<> MediaKeyMessageEvent::Init convertDictionary<MediaKeyMessageEvent::Init>(ExecState& state, JSValue value)
94{
95 VM& vm = state.vm();
96 auto throwScope = DECLARE_THROW_SCOPE(vm);
97 bool isNullOrUndefined = value.isUndefinedOrNull();
98 auto* object = isNullOrUndefined ? nullptr : value.getObject();
99 if (UNLIKELY(!isNullOrUndefined && !object)) {
100 throwTypeError(&state, throwScope);
101 return { };
102 }
103 MediaKeyMessageEvent::Init result;
104 JSValue bubblesValue;
105 if (isNullOrUndefined)
106 bubblesValue = jsUndefined();
107 else {
108 bubblesValue = object->get(&state, Identifier::fromString(&state, "bubbles"));
109 RETURN_IF_EXCEPTION(throwScope, { });
110 }
111 if (!bubblesValue.isUndefined()) {
112 result.bubbles = convert<IDLBoolean>(state, bubblesValue);
113 RETURN_IF_EXCEPTION(throwScope, { });
114 } else
115 result.bubbles = false;
116 JSValue cancelableValue;
117 if (isNullOrUndefined)
118 cancelableValue = jsUndefined();
119 else {
120 cancelableValue = object->get(&state, Identifier::fromString(&state, "cancelable"));
121 RETURN_IF_EXCEPTION(throwScope, { });
122 }
123 if (!cancelableValue.isUndefined()) {
124 result.cancelable = convert<IDLBoolean>(state, cancelableValue);
125 RETURN_IF_EXCEPTION(throwScope, { });
126 } else
127 result.cancelable = false;
128 JSValue composedValue;
129 if (isNullOrUndefined)
130 composedValue = jsUndefined();
131 else {
132 composedValue = object->get(&state, Identifier::fromString(&state, "composed"));
133 RETURN_IF_EXCEPTION(throwScope, { });
134 }
135 if (!composedValue.isUndefined()) {
136 result.composed = convert<IDLBoolean>(state, composedValue);
137 RETURN_IF_EXCEPTION(throwScope, { });
138 } else
139 result.composed = false;
140 JSValue messageValue;
141 if (isNullOrUndefined)
142 messageValue = jsUndefined();
143 else {
144 messageValue = object->get(&state, Identifier::fromString(&state, "message"));
145 RETURN_IF_EXCEPTION(throwScope, { });
146 }
147 if (!messageValue.isUndefined()) {
148 result.message = convert<IDLArrayBuffer>(state, messageValue);
149 RETURN_IF_EXCEPTION(throwScope, { });
150 } else {
151 throwRequiredMemberTypeError(state, throwScope, "message", "MediaKeyMessageEventInit", "ArrayBuffer");
152 return { };
153 }
154 JSValue messageTypeValue;
155 if (isNullOrUndefined)
156 messageTypeValue = jsUndefined();
157 else {
158 messageTypeValue = object->get(&state, Identifier::fromString(&state, "messageType"));
159 RETURN_IF_EXCEPTION(throwScope, { });
160 }
161 if (!messageTypeValue.isUndefined()) {
162 result.messageType = convert<IDLEnumeration<MediaKeyMessageEvent::Type>>(state, messageTypeValue);
163 RETURN_IF_EXCEPTION(throwScope, { });
164 } else {
165 throwRequiredMemberTypeError(state, throwScope, "messageType", "MediaKeyMessageEventInit", "MediaKeyMessageType");
166 return { };
167 }
168 return result;
169}
170
171// Attributes
172
173JSC::EncodedJSValue jsMediaKeyMessageEventConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
174bool setJSMediaKeyMessageEventConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
175JSC::EncodedJSValue jsMediaKeyMessageEventMessageType(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
176JSC::EncodedJSValue jsMediaKeyMessageEventMessage(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
177
178class JSMediaKeyMessageEventPrototype : public JSC::JSNonFinalObject {
179public:
180 using Base = JSC::JSNonFinalObject;
181 static JSMediaKeyMessageEventPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
182 {
183 JSMediaKeyMessageEventPrototype* ptr = new (NotNull, JSC::allocateCell<JSMediaKeyMessageEventPrototype>(vm.heap)) JSMediaKeyMessageEventPrototype(vm, globalObject, structure);
184 ptr->finishCreation(vm);
185 return ptr;
186 }
187
188 DECLARE_INFO;
189 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
190 {
191 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
192 }
193
194private:
195 JSMediaKeyMessageEventPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
196 : JSC::JSNonFinalObject(vm, structure)
197 {
198 }
199
200 void finishCreation(JSC::VM&);
201};
202
203using JSMediaKeyMessageEventConstructor = JSDOMConstructor<JSMediaKeyMessageEvent>;
204
205template<> EncodedJSValue JSC_HOST_CALL JSMediaKeyMessageEventConstructor::construct(ExecState* state)
206{
207 VM& vm = state->vm();
208 auto throwScope = DECLARE_THROW_SCOPE(vm);
209 UNUSED_PARAM(throwScope);
210 auto* castedThis = jsCast<JSMediaKeyMessageEventConstructor*>(state->jsCallee());
211 ASSERT(castedThis);
212 if (UNLIKELY(state->argumentCount() < 2))
213 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
214 auto type = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
215 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
216 auto eventInitDict = convert<IDLDictionary<MediaKeyMessageEvent::Init>>(*state, state->uncheckedArgument(1));
217 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
218 auto object = MediaKeyMessageEvent::create(WTFMove(type), WTFMove(eventInitDict));
219 return JSValue::encode(toJSNewlyCreated<IDLInterface<MediaKeyMessageEvent>>(*state, *castedThis->globalObject(), WTFMove(object)));
220}
221
222template<> JSValue JSMediaKeyMessageEventConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
223{
224 return JSEvent::getConstructor(vm, &globalObject);
225}
226
227template<> void JSMediaKeyMessageEventConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
228{
229 putDirect(vm, vm.propertyNames->prototype, JSMediaKeyMessageEvent::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
230 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("MediaKeyMessageEvent"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
231 putDirect(vm, vm.propertyNames->length, jsNumber(2), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
232}
233
234template<> const ClassInfo JSMediaKeyMessageEventConstructor::s_info = { "MediaKeyMessageEvent", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSMediaKeyMessageEventConstructor) };
235
236/* Hash table for prototype */
237
238static const HashTableValue JSMediaKeyMessageEventPrototypeTableValues[] =
239{
240 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaKeyMessageEventConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSMediaKeyMessageEventConstructor) } },
241 { "messageType", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaKeyMessageEventMessageType), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
242 { "message", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaKeyMessageEventMessage), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
243};
244
245const ClassInfo JSMediaKeyMessageEventPrototype::s_info = { "MediaKeyMessageEventPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSMediaKeyMessageEventPrototype) };
246
247void JSMediaKeyMessageEventPrototype::finishCreation(VM& vm)
248{
249 Base::finishCreation(vm);
250 reifyStaticProperties(vm, JSMediaKeyMessageEvent::info(), JSMediaKeyMessageEventPrototypeTableValues, *this);
251}
252
253const ClassInfo JSMediaKeyMessageEvent::s_info = { "MediaKeyMessageEvent", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSMediaKeyMessageEvent) };
254
255JSMediaKeyMessageEvent::JSMediaKeyMessageEvent(Structure* structure, JSDOMGlobalObject& globalObject, Ref<MediaKeyMessageEvent>&& impl)
256 : JSEvent(structure, globalObject, WTFMove(impl))
257{
258}
259
260void JSMediaKeyMessageEvent::finishCreation(VM& vm)
261{
262 Base::finishCreation(vm);
263 ASSERT(inherits(vm, info()));
264
265}
266
267JSObject* JSMediaKeyMessageEvent::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
268{
269 return JSMediaKeyMessageEventPrototype::create(vm, &globalObject, JSMediaKeyMessageEventPrototype::createStructure(vm, &globalObject, JSEvent::prototype(vm, globalObject)));
270}
271
272JSObject* JSMediaKeyMessageEvent::prototype(VM& vm, JSDOMGlobalObject& globalObject)
273{
274 return getDOMPrototype<JSMediaKeyMessageEvent>(vm, globalObject);
275}
276
277JSValue JSMediaKeyMessageEvent::getConstructor(VM& vm, const JSGlobalObject* globalObject)
278{
279 return getDOMConstructor<JSMediaKeyMessageEventConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
280}
281
282template<> inline JSMediaKeyMessageEvent* IDLAttribute<JSMediaKeyMessageEvent>::cast(ExecState& state, EncodedJSValue thisValue)
283{
284 return jsDynamicCast<JSMediaKeyMessageEvent*>(state.vm(), JSValue::decode(thisValue));
285}
286
287EncodedJSValue jsMediaKeyMessageEventConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
288{
289 VM& vm = state->vm();
290 auto throwScope = DECLARE_THROW_SCOPE(vm);
291 auto* prototype = jsDynamicCast<JSMediaKeyMessageEventPrototype*>(vm, JSValue::decode(thisValue));
292 if (UNLIKELY(!prototype))
293 return throwVMTypeError(state, throwScope);
294 return JSValue::encode(JSMediaKeyMessageEvent::getConstructor(state->vm(), prototype->globalObject()));
295}
296
297bool setJSMediaKeyMessageEventConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
298{
299 VM& vm = state->vm();
300 auto throwScope = DECLARE_THROW_SCOPE(vm);
301 auto* prototype = jsDynamicCast<JSMediaKeyMessageEventPrototype*>(vm, JSValue::decode(thisValue));
302 if (UNLIKELY(!prototype)) {
303 throwVMTypeError(state, throwScope);
304 return false;
305 }
306 // Shadowing a built-in constructor
307 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
308}
309
310static inline JSValue jsMediaKeyMessageEventMessageTypeGetter(ExecState& state, JSMediaKeyMessageEvent& thisObject, ThrowScope& throwScope)
311{
312 UNUSED_PARAM(throwScope);
313 UNUSED_PARAM(state);
314 auto& impl = thisObject.wrapped();
315 JSValue result = toJS<IDLEnumeration<MediaKeyMessageEvent::Type>>(state, throwScope, impl.messageType());
316 return result;
317}
318
319EncodedJSValue jsMediaKeyMessageEventMessageType(ExecState* state, EncodedJSValue thisValue, PropertyName)
320{
321 return IDLAttribute<JSMediaKeyMessageEvent>::get<jsMediaKeyMessageEventMessageTypeGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "messageType");
322}
323
324static inline JSValue jsMediaKeyMessageEventMessageGetter(ExecState& state, JSMediaKeyMessageEvent& thisObject, ThrowScope& throwScope)
325{
326 UNUSED_PARAM(throwScope);
327 UNUSED_PARAM(state);
328 auto& impl = thisObject.wrapped();
329 JSValue result = toJS<IDLArrayBuffer>(state, *thisObject.globalObject(), throwScope, impl.message());
330 return result;
331}
332
333EncodedJSValue jsMediaKeyMessageEventMessage(ExecState* state, EncodedJSValue thisValue, PropertyName)
334{
335 return IDLAttribute<JSMediaKeyMessageEvent>::get<jsMediaKeyMessageEventMessageGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "message");
336}
337
338void JSMediaKeyMessageEvent::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
339{
340 auto* thisObject = jsCast<JSMediaKeyMessageEvent*>(cell);
341 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
342 if (thisObject->scriptExecutionContext())
343 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
344 Base::heapSnapshot(cell, builder);
345}
346
347#if ENABLE(BINDING_INTEGRITY)
348#if PLATFORM(WIN)
349#pragma warning(disable: 4483)
350extern "C" { extern void (*const __identifier("??_7MediaKeyMessageEvent@WebCore@@6B@")[])(); }
351#else
352extern "C" { extern void* _ZTVN7WebCore20MediaKeyMessageEventE[]; }
353#endif
354#endif
355
356JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<MediaKeyMessageEvent>&& impl)
357{
358
359#if ENABLE(BINDING_INTEGRITY)
360 void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
361#if PLATFORM(WIN)
362 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7MediaKeyMessageEvent@WebCore@@6B@"));
363#else
364 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore20MediaKeyMessageEventE[2]);
365#endif
366
367 // If this fails MediaKeyMessageEvent does not have a vtable, so you need to add the
368 // ImplementationLacksVTable attribute to the interface definition
369 static_assert(std::is_polymorphic<MediaKeyMessageEvent>::value, "MediaKeyMessageEvent is not polymorphic");
370
371 // If you hit this assertion you either have a use after free bug, or
372 // MediaKeyMessageEvent has subclasses. If MediaKeyMessageEvent has subclasses that get passed
373 // to toJS() we currently require MediaKeyMessageEvent you to opt out of binding hardening
374 // by adding the SkipVTableValidation attribute to the interface IDL definition
375 RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
376#endif
377 return createWrapper<MediaKeyMessageEvent>(globalObject, WTFMove(impl));
378}
379
380JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, MediaKeyMessageEvent& impl)
381{
382 return wrap(state, globalObject, impl);
383}
384
385
386}
387
388#endif // ENABLE(ENCRYPTED_MEDIA)
389