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(NOTIFICATIONS) |
24 | |
25 | #include "JSNotification.h" |
26 | |
27 | #include "Document.h" |
28 | #include "EventNames.h" |
29 | #include "JSDOMAttribute.h" |
30 | #include "JSDOMBinding.h" |
31 | #include "JSDOMConstructor.h" |
32 | #include "JSDOMConvertCallbacks.h" |
33 | #include "JSDOMConvertInterface.h" |
34 | #include "JSDOMConvertNullable.h" |
35 | #include "JSDOMConvertStrings.h" |
36 | #include "JSDOMExceptionHandling.h" |
37 | #include "JSDOMGlobalObject.h" |
38 | #include "JSDOMOperation.h" |
39 | #include "JSDOMWrapperCache.h" |
40 | #include "JSEventListener.h" |
41 | #include "JSNotificationPermission.h" |
42 | #include "JSNotificationPermissionCallback.h" |
43 | #include "ScriptExecutionContext.h" |
44 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
45 | #include <JavaScriptCore/JSCInlines.h> |
46 | #include <JavaScriptCore/JSString.h> |
47 | #include <wtf/GetPtr.h> |
48 | #include <wtf/PointerPreparations.h> |
49 | #include <wtf/URL.h> |
50 | |
51 | |
52 | namespace WebCore { |
53 | using namespace JSC; |
54 | |
55 | #if ENABLE(NOTIFICATIONS) |
56 | |
57 | String convertEnumerationToString(Notification::Direction enumerationValue) |
58 | { |
59 | static const NeverDestroyed<String> values[] = { |
60 | MAKE_STATIC_STRING_IMPL("auto" ), |
61 | MAKE_STATIC_STRING_IMPL("ltr" ), |
62 | MAKE_STATIC_STRING_IMPL("rtl" ), |
63 | }; |
64 | static_assert(static_cast<size_t>(Notification::Direction::Auto) == 0, "Notification::Direction::Auto is not 0 as expected" ); |
65 | static_assert(static_cast<size_t>(Notification::Direction::Ltr) == 1, "Notification::Direction::Ltr is not 1 as expected" ); |
66 | static_assert(static_cast<size_t>(Notification::Direction::Rtl) == 2, "Notification::Direction::Rtl is not 2 as expected" ); |
67 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
68 | return values[static_cast<size_t>(enumerationValue)]; |
69 | } |
70 | |
71 | template<> JSString* convertEnumerationToJS(ExecState& state, Notification::Direction enumerationValue) |
72 | { |
73 | return jsStringWithCache(&state, convertEnumerationToString(enumerationValue)); |
74 | } |
75 | |
76 | template<> Optional<Notification::Direction> parseEnumeration<Notification::Direction>(ExecState& state, JSValue value) |
77 | { |
78 | auto stringValue = value.toWTFString(&state); |
79 | if (stringValue == "auto" ) |
80 | return Notification::Direction::Auto; |
81 | if (stringValue == "ltr" ) |
82 | return Notification::Direction::Ltr; |
83 | if (stringValue == "rtl" ) |
84 | return Notification::Direction::Rtl; |
85 | return WTF::nullopt; |
86 | } |
87 | |
88 | template<> const char* expectedEnumerationValues<Notification::Direction>() |
89 | { |
90 | return "\"auto\", \"ltr\", \"rtl\"" ; |
91 | } |
92 | |
93 | #endif |
94 | |
95 | #if ENABLE(NOTIFICATIONS) |
96 | |
97 | template<> Notification::Options convertDictionary<Notification::Options>(ExecState& state, JSValue value) |
98 | { |
99 | VM& vm = state.vm(); |
100 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
101 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
102 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
103 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
104 | throwTypeError(&state, throwScope); |
105 | return { }; |
106 | } |
107 | Notification::Options result; |
108 | JSValue bodyValue; |
109 | if (isNullOrUndefined) |
110 | bodyValue = jsUndefined(); |
111 | else { |
112 | bodyValue = object->get(&state, Identifier::fromString(&state, "body" )); |
113 | RETURN_IF_EXCEPTION(throwScope, { }); |
114 | } |
115 | if (!bodyValue.isUndefined()) { |
116 | result.body = convert<IDLDOMString>(state, bodyValue); |
117 | RETURN_IF_EXCEPTION(throwScope, { }); |
118 | } else |
119 | result.body = emptyString(); |
120 | JSValue dirValue; |
121 | if (isNullOrUndefined) |
122 | dirValue = jsUndefined(); |
123 | else { |
124 | dirValue = object->get(&state, Identifier::fromString(&state, "dir" )); |
125 | RETURN_IF_EXCEPTION(throwScope, { }); |
126 | } |
127 | if (!dirValue.isUndefined()) { |
128 | result.dir = convert<IDLEnumeration<Notification::Direction>>(state, dirValue); |
129 | RETURN_IF_EXCEPTION(throwScope, { }); |
130 | } else |
131 | result.dir = Notification::Direction::Auto; |
132 | JSValue iconValue; |
133 | if (isNullOrUndefined) |
134 | iconValue = jsUndefined(); |
135 | else { |
136 | iconValue = object->get(&state, Identifier::fromString(&state, "icon" )); |
137 | RETURN_IF_EXCEPTION(throwScope, { }); |
138 | } |
139 | if (!iconValue.isUndefined()) { |
140 | result.icon = convert<IDLUSVString>(state, iconValue); |
141 | RETURN_IF_EXCEPTION(throwScope, { }); |
142 | } |
143 | JSValue langValue; |
144 | if (isNullOrUndefined) |
145 | langValue = jsUndefined(); |
146 | else { |
147 | langValue = object->get(&state, Identifier::fromString(&state, "lang" )); |
148 | RETURN_IF_EXCEPTION(throwScope, { }); |
149 | } |
150 | if (!langValue.isUndefined()) { |
151 | result.lang = convert<IDLDOMString>(state, langValue); |
152 | RETURN_IF_EXCEPTION(throwScope, { }); |
153 | } else |
154 | result.lang = emptyString(); |
155 | JSValue tagValue; |
156 | if (isNullOrUndefined) |
157 | tagValue = jsUndefined(); |
158 | else { |
159 | tagValue = object->get(&state, Identifier::fromString(&state, "tag" )); |
160 | RETURN_IF_EXCEPTION(throwScope, { }); |
161 | } |
162 | if (!tagValue.isUndefined()) { |
163 | result.tag = convert<IDLDOMString>(state, tagValue); |
164 | RETURN_IF_EXCEPTION(throwScope, { }); |
165 | } else |
166 | result.tag = emptyString(); |
167 | return result; |
168 | } |
169 | |
170 | #endif |
171 | |
172 | // Functions |
173 | |
174 | JSC::EncodedJSValue JSC_HOST_CALL jsNotificationConstructorFunctionRequestPermission(JSC::ExecState*); |
175 | JSC::EncodedJSValue JSC_HOST_CALL jsNotificationPrototypeFunctionClose(JSC::ExecState*); |
176 | JSC::EncodedJSValue JSC_HOST_CALL jsNotificationPrototypeFunctionShow(JSC::ExecState*); |
177 | |
178 | // Attributes |
179 | |
180 | JSC::EncodedJSValue jsNotificationConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
181 | bool setJSNotificationConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
182 | JSC::EncodedJSValue jsNotificationConstructorPermission(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
183 | JSC::EncodedJSValue jsNotificationOnclick(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
184 | bool setJSNotificationOnclick(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
185 | JSC::EncodedJSValue jsNotificationOnerror(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
186 | bool setJSNotificationOnerror(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
187 | JSC::EncodedJSValue jsNotificationTitle(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
188 | JSC::EncodedJSValue jsNotificationDir(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
189 | JSC::EncodedJSValue jsNotificationLang(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
190 | JSC::EncodedJSValue jsNotificationBody(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
191 | JSC::EncodedJSValue jsNotificationTag(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
192 | JSC::EncodedJSValue jsNotificationIcon(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
193 | JSC::EncodedJSValue jsNotificationOnclose(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
194 | bool setJSNotificationOnclose(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
195 | JSC::EncodedJSValue jsNotificationOndisplay(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
196 | bool setJSNotificationOndisplay(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
197 | JSC::EncodedJSValue jsNotificationOnshow(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
198 | bool setJSNotificationOnshow(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
199 | |
200 | class JSNotificationPrototype : public JSC::JSNonFinalObject { |
201 | public: |
202 | using Base = JSC::JSNonFinalObject; |
203 | static JSNotificationPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
204 | { |
205 | JSNotificationPrototype* ptr = new (NotNull, JSC::allocateCell<JSNotificationPrototype>(vm.heap)) JSNotificationPrototype(vm, globalObject, structure); |
206 | ptr->finishCreation(vm); |
207 | return ptr; |
208 | } |
209 | |
210 | DECLARE_INFO; |
211 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
212 | { |
213 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
214 | } |
215 | |
216 | private: |
217 | JSNotificationPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
218 | : JSC::JSNonFinalObject(vm, structure) |
219 | { |
220 | } |
221 | |
222 | void finishCreation(JSC::VM&); |
223 | }; |
224 | |
225 | using JSNotificationConstructor = JSDOMConstructor<JSNotification>; |
226 | |
227 | /* Hash table for constructor */ |
228 | |
229 | static const HashTableValue JSNotificationConstructorTableValues[] = |
230 | { |
231 | { "permission" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationConstructorPermission), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
232 | { "requestPermission" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsNotificationConstructorFunctionRequestPermission), (intptr_t) (0) } }, |
233 | }; |
234 | |
235 | template<> EncodedJSValue JSC_HOST_CALL JSNotificationConstructor::construct(ExecState* state) |
236 | { |
237 | VM& vm = state->vm(); |
238 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
239 | UNUSED_PARAM(throwScope); |
240 | auto* castedThis = jsCast<JSNotificationConstructor*>(state->jsCallee()); |
241 | ASSERT(castedThis); |
242 | if (UNLIKELY(state->argumentCount() < 1)) |
243 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
244 | auto* context = castedThis->scriptExecutionContext(); |
245 | if (UNLIKELY(!context)) |
246 | return throwConstructorScriptExecutionContextUnavailableError(*state, throwScope, "Notification" ); |
247 | ASSERT(context->isDocument()); |
248 | auto& document = downcast<Document>(*context); |
249 | auto title = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
250 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
251 | auto options = convert<IDLDictionary<Notification::Options>>(*state, state->argument(1)); |
252 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
253 | auto object = Notification::create(document, WTFMove(title), WTFMove(options)); |
254 | return JSValue::encode(toJSNewlyCreated<IDLInterface<Notification>>(*state, *castedThis->globalObject(), WTFMove(object))); |
255 | } |
256 | |
257 | template<> JSValue JSNotificationConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
258 | { |
259 | return JSEventTarget::getConstructor(vm, &globalObject); |
260 | } |
261 | |
262 | template<> void JSNotificationConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
263 | { |
264 | putDirect(vm, vm.propertyNames->prototype, JSNotification::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
265 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("Notification"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
266 | putDirect(vm, vm.propertyNames->length, jsNumber(1), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
267 | reifyStaticProperties(vm, JSNotification::info(), JSNotificationConstructorTableValues, *this); |
268 | } |
269 | |
270 | template<> const ClassInfo JSNotificationConstructor::s_info = { "Notification" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSNotificationConstructor) }; |
271 | |
272 | /* Hash table for prototype */ |
273 | |
274 | static const HashTableValue JSNotificationPrototypeTableValues[] = |
275 | { |
276 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSNotificationConstructor) } }, |
277 | { "onclick" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationOnclick), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSNotificationOnclick) } }, |
278 | { "onerror" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationOnerror), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSNotificationOnerror) } }, |
279 | { "title" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationTitle), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
280 | { "dir" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationDir), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
281 | { "lang" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationLang), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
282 | { "body" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationBody), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
283 | { "tag" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationTag), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
284 | { "icon" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationIcon), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
285 | { "onclose" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationOnclose), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSNotificationOnclose) } }, |
286 | { "ondisplay" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationOndisplay), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSNotificationOndisplay) } }, |
287 | { "onshow" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationOnshow), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSNotificationOnshow) } }, |
288 | { "close" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsNotificationPrototypeFunctionClose), (intptr_t) (0) } }, |
289 | { "show" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsNotificationPrototypeFunctionShow), (intptr_t) (0) } }, |
290 | }; |
291 | |
292 | const ClassInfo JSNotificationPrototype::s_info = { "NotificationPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSNotificationPrototype) }; |
293 | |
294 | void JSNotificationPrototype::finishCreation(VM& vm) |
295 | { |
296 | Base::finishCreation(vm); |
297 | reifyStaticProperties(vm, JSNotification::info(), JSNotificationPrototypeTableValues, *this); |
298 | } |
299 | |
300 | const ClassInfo JSNotification::s_info = { "Notification" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSNotification) }; |
301 | |
302 | JSNotification::JSNotification(Structure* structure, JSDOMGlobalObject& globalObject, Ref<Notification>&& impl) |
303 | : JSEventTarget(structure, globalObject, WTFMove(impl)) |
304 | { |
305 | } |
306 | |
307 | void JSNotification::finishCreation(VM& vm) |
308 | { |
309 | Base::finishCreation(vm); |
310 | ASSERT(inherits(vm, info())); |
311 | |
312 | } |
313 | |
314 | JSObject* JSNotification::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
315 | { |
316 | return JSNotificationPrototype::create(vm, &globalObject, JSNotificationPrototype::createStructure(vm, &globalObject, JSEventTarget::prototype(vm, globalObject))); |
317 | } |
318 | |
319 | JSObject* JSNotification::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
320 | { |
321 | return getDOMPrototype<JSNotification>(vm, globalObject); |
322 | } |
323 | |
324 | JSValue JSNotification::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
325 | { |
326 | return getDOMConstructor<JSNotificationConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
327 | } |
328 | |
329 | template<> inline JSNotification* IDLAttribute<JSNotification>::cast(ExecState& state, EncodedJSValue thisValue) |
330 | { |
331 | return jsDynamicCast<JSNotification*>(state.vm(), JSValue::decode(thisValue)); |
332 | } |
333 | |
334 | template<> inline JSNotification* IDLOperation<JSNotification>::cast(ExecState& state) |
335 | { |
336 | return jsDynamicCast<JSNotification*>(state.vm(), state.thisValue()); |
337 | } |
338 | |
339 | EncodedJSValue jsNotificationConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
340 | { |
341 | VM& vm = state->vm(); |
342 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
343 | auto* prototype = jsDynamicCast<JSNotificationPrototype*>(vm, JSValue::decode(thisValue)); |
344 | if (UNLIKELY(!prototype)) |
345 | return throwVMTypeError(state, throwScope); |
346 | return JSValue::encode(JSNotification::getConstructor(state->vm(), prototype->globalObject())); |
347 | } |
348 | |
349 | bool setJSNotificationConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
350 | { |
351 | VM& vm = state->vm(); |
352 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
353 | auto* prototype = jsDynamicCast<JSNotificationPrototype*>(vm, JSValue::decode(thisValue)); |
354 | if (UNLIKELY(!prototype)) { |
355 | throwVMTypeError(state, throwScope); |
356 | return false; |
357 | } |
358 | // Shadowing a built-in constructor |
359 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
360 | } |
361 | |
362 | static inline JSValue jsNotificationConstructorPermissionGetter(ExecState& state, ThrowScope& throwScope) |
363 | { |
364 | UNUSED_PARAM(throwScope); |
365 | UNUSED_PARAM(state); |
366 | auto* context = jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject())->scriptExecutionContext(); |
367 | if (UNLIKELY(!context)) |
368 | return jsUndefined(); |
369 | ASSERT(context->isDocument()); |
370 | auto& document = downcast<Document>(*context); |
371 | JSValue result = toJS<IDLEnumeration<NotificationPermission>>(state, throwScope, Notification::permission(document)); |
372 | return result; |
373 | } |
374 | |
375 | EncodedJSValue jsNotificationConstructorPermission(ExecState* state, EncodedJSValue thisValue, PropertyName) |
376 | { |
377 | return IDLAttribute<JSNotification>::getStatic<jsNotificationConstructorPermissionGetter>(*state, thisValue, "permission" ); |
378 | } |
379 | |
380 | static inline JSValue jsNotificationOnclickGetter(ExecState& state, JSNotification& thisObject, ThrowScope& throwScope) |
381 | { |
382 | UNUSED_PARAM(throwScope); |
383 | UNUSED_PARAM(state); |
384 | return eventHandlerAttribute(thisObject.wrapped(), eventNames().clickEvent, worldForDOMObject(thisObject)); |
385 | } |
386 | |
387 | EncodedJSValue jsNotificationOnclick(ExecState* state, EncodedJSValue thisValue, PropertyName) |
388 | { |
389 | return IDLAttribute<JSNotification>::get<jsNotificationOnclickGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onclick" ); |
390 | } |
391 | |
392 | static inline bool setJSNotificationOnclickSetter(ExecState& state, JSNotification& thisObject, JSValue value, ThrowScope& throwScope) |
393 | { |
394 | UNUSED_PARAM(throwScope); |
395 | setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().clickEvent, value); |
396 | return true; |
397 | } |
398 | |
399 | bool setJSNotificationOnclick(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
400 | { |
401 | return IDLAttribute<JSNotification>::set<setJSNotificationOnclickSetter>(*state, thisValue, encodedValue, "onclick" ); |
402 | } |
403 | |
404 | static inline JSValue jsNotificationOnerrorGetter(ExecState& state, JSNotification& thisObject, ThrowScope& throwScope) |
405 | { |
406 | UNUSED_PARAM(throwScope); |
407 | UNUSED_PARAM(state); |
408 | return eventHandlerAttribute(thisObject.wrapped(), eventNames().errorEvent, worldForDOMObject(thisObject)); |
409 | } |
410 | |
411 | EncodedJSValue jsNotificationOnerror(ExecState* state, EncodedJSValue thisValue, PropertyName) |
412 | { |
413 | return IDLAttribute<JSNotification>::get<jsNotificationOnerrorGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onerror" ); |
414 | } |
415 | |
416 | static inline bool setJSNotificationOnerrorSetter(ExecState& state, JSNotification& thisObject, JSValue value, ThrowScope& throwScope) |
417 | { |
418 | UNUSED_PARAM(throwScope); |
419 | setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().errorEvent, value); |
420 | return true; |
421 | } |
422 | |
423 | bool setJSNotificationOnerror(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
424 | { |
425 | return IDLAttribute<JSNotification>::set<setJSNotificationOnerrorSetter>(*state, thisValue, encodedValue, "onerror" ); |
426 | } |
427 | |
428 | static inline JSValue jsNotificationTitleGetter(ExecState& state, JSNotification& thisObject, ThrowScope& throwScope) |
429 | { |
430 | UNUSED_PARAM(throwScope); |
431 | UNUSED_PARAM(state); |
432 | auto& impl = thisObject.wrapped(); |
433 | JSValue result = toJS<IDLDOMString>(state, throwScope, impl.title()); |
434 | return result; |
435 | } |
436 | |
437 | EncodedJSValue jsNotificationTitle(ExecState* state, EncodedJSValue thisValue, PropertyName) |
438 | { |
439 | return IDLAttribute<JSNotification>::get<jsNotificationTitleGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "title" ); |
440 | } |
441 | |
442 | static inline JSValue jsNotificationDirGetter(ExecState& state, JSNotification& thisObject, ThrowScope& throwScope) |
443 | { |
444 | UNUSED_PARAM(throwScope); |
445 | UNUSED_PARAM(state); |
446 | auto& impl = thisObject.wrapped(); |
447 | JSValue result = toJS<IDLEnumeration<Notification::Direction>>(state, throwScope, impl.dir()); |
448 | return result; |
449 | } |
450 | |
451 | EncodedJSValue jsNotificationDir(ExecState* state, EncodedJSValue thisValue, PropertyName) |
452 | { |
453 | return IDLAttribute<JSNotification>::get<jsNotificationDirGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "dir" ); |
454 | } |
455 | |
456 | static inline JSValue jsNotificationLangGetter(ExecState& state, JSNotification& thisObject, ThrowScope& throwScope) |
457 | { |
458 | UNUSED_PARAM(throwScope); |
459 | UNUSED_PARAM(state); |
460 | auto& impl = thisObject.wrapped(); |
461 | JSValue result = toJS<IDLDOMString>(state, throwScope, impl.lang()); |
462 | return result; |
463 | } |
464 | |
465 | EncodedJSValue jsNotificationLang(ExecState* state, EncodedJSValue thisValue, PropertyName) |
466 | { |
467 | return IDLAttribute<JSNotification>::get<jsNotificationLangGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "lang" ); |
468 | } |
469 | |
470 | static inline JSValue jsNotificationBodyGetter(ExecState& state, JSNotification& thisObject, ThrowScope& throwScope) |
471 | { |
472 | UNUSED_PARAM(throwScope); |
473 | UNUSED_PARAM(state); |
474 | auto& impl = thisObject.wrapped(); |
475 | JSValue result = toJS<IDLDOMString>(state, throwScope, impl.body()); |
476 | return result; |
477 | } |
478 | |
479 | EncodedJSValue jsNotificationBody(ExecState* state, EncodedJSValue thisValue, PropertyName) |
480 | { |
481 | return IDLAttribute<JSNotification>::get<jsNotificationBodyGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "body" ); |
482 | } |
483 | |
484 | static inline JSValue jsNotificationTagGetter(ExecState& state, JSNotification& thisObject, ThrowScope& throwScope) |
485 | { |
486 | UNUSED_PARAM(throwScope); |
487 | UNUSED_PARAM(state); |
488 | auto& impl = thisObject.wrapped(); |
489 | JSValue result = toJS<IDLDOMString>(state, throwScope, impl.tag()); |
490 | return result; |
491 | } |
492 | |
493 | EncodedJSValue jsNotificationTag(ExecState* state, EncodedJSValue thisValue, PropertyName) |
494 | { |
495 | return IDLAttribute<JSNotification>::get<jsNotificationTagGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "tag" ); |
496 | } |
497 | |
498 | static inline JSValue jsNotificationIconGetter(ExecState& state, JSNotification& thisObject, ThrowScope& throwScope) |
499 | { |
500 | UNUSED_PARAM(throwScope); |
501 | UNUSED_PARAM(state); |
502 | auto& impl = thisObject.wrapped(); |
503 | JSValue result = toJS<IDLUSVString>(state, throwScope, impl.icon()); |
504 | return result; |
505 | } |
506 | |
507 | EncodedJSValue jsNotificationIcon(ExecState* state, EncodedJSValue thisValue, PropertyName) |
508 | { |
509 | return IDLAttribute<JSNotification>::get<jsNotificationIconGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "icon" ); |
510 | } |
511 | |
512 | static inline JSValue jsNotificationOncloseGetter(ExecState& state, JSNotification& thisObject, ThrowScope& throwScope) |
513 | { |
514 | UNUSED_PARAM(throwScope); |
515 | UNUSED_PARAM(state); |
516 | return eventHandlerAttribute(thisObject.wrapped(), eventNames().closeEvent, worldForDOMObject(thisObject)); |
517 | } |
518 | |
519 | EncodedJSValue jsNotificationOnclose(ExecState* state, EncodedJSValue thisValue, PropertyName) |
520 | { |
521 | return IDLAttribute<JSNotification>::get<jsNotificationOncloseGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onclose" ); |
522 | } |
523 | |
524 | static inline bool setJSNotificationOncloseSetter(ExecState& state, JSNotification& thisObject, JSValue value, ThrowScope& throwScope) |
525 | { |
526 | UNUSED_PARAM(throwScope); |
527 | setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().closeEvent, value); |
528 | return true; |
529 | } |
530 | |
531 | bool setJSNotificationOnclose(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
532 | { |
533 | return IDLAttribute<JSNotification>::set<setJSNotificationOncloseSetter>(*state, thisValue, encodedValue, "onclose" ); |
534 | } |
535 | |
536 | static inline JSValue jsNotificationOndisplayGetter(ExecState& state, JSNotification& thisObject, ThrowScope& throwScope) |
537 | { |
538 | UNUSED_PARAM(throwScope); |
539 | UNUSED_PARAM(state); |
540 | return eventHandlerAttribute(thisObject.wrapped(), eventNames().showEvent, worldForDOMObject(thisObject)); |
541 | } |
542 | |
543 | EncodedJSValue jsNotificationOndisplay(ExecState* state, EncodedJSValue thisValue, PropertyName) |
544 | { |
545 | return IDLAttribute<JSNotification>::get<jsNotificationOndisplayGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "ondisplay" ); |
546 | } |
547 | |
548 | static inline bool setJSNotificationOndisplaySetter(ExecState& state, JSNotification& thisObject, JSValue value, ThrowScope& throwScope) |
549 | { |
550 | UNUSED_PARAM(throwScope); |
551 | setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().showEvent, value); |
552 | return true; |
553 | } |
554 | |
555 | bool setJSNotificationOndisplay(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
556 | { |
557 | return IDLAttribute<JSNotification>::set<setJSNotificationOndisplaySetter>(*state, thisValue, encodedValue, "ondisplay" ); |
558 | } |
559 | |
560 | static inline JSValue jsNotificationOnshowGetter(ExecState& state, JSNotification& thisObject, ThrowScope& throwScope) |
561 | { |
562 | UNUSED_PARAM(throwScope); |
563 | UNUSED_PARAM(state); |
564 | return eventHandlerAttribute(thisObject.wrapped(), eventNames().showEvent, worldForDOMObject(thisObject)); |
565 | } |
566 | |
567 | EncodedJSValue jsNotificationOnshow(ExecState* state, EncodedJSValue thisValue, PropertyName) |
568 | { |
569 | return IDLAttribute<JSNotification>::get<jsNotificationOnshowGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onshow" ); |
570 | } |
571 | |
572 | static inline bool setJSNotificationOnshowSetter(ExecState& state, JSNotification& thisObject, JSValue value, ThrowScope& throwScope) |
573 | { |
574 | UNUSED_PARAM(throwScope); |
575 | setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().showEvent, value); |
576 | return true; |
577 | } |
578 | |
579 | bool setJSNotificationOnshow(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
580 | { |
581 | return IDLAttribute<JSNotification>::set<setJSNotificationOnshowSetter>(*state, thisValue, encodedValue, "onshow" ); |
582 | } |
583 | |
584 | static inline JSC::EncodedJSValue jsNotificationConstructorFunctionRequestPermissionBody(JSC::ExecState* state, JSC::ThrowScope& throwScope) |
585 | { |
586 | UNUSED_PARAM(state); |
587 | UNUSED_PARAM(throwScope); |
588 | auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext(); |
589 | if (UNLIKELY(!context)) |
590 | return JSValue::encode(jsUndefined()); |
591 | ASSERT(context->isDocument()); |
592 | auto& document = downcast<Document>(*context); |
593 | auto deprecatedCallback = convert<IDLNullable<IDLCallbackFunction<JSNotificationPermissionCallback>>>(*state, state->argument(0), *jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject()), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(state, scope, 0, "deprecatedCallback" , "Notification" , "requestPermission" ); }); |
594 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
595 | Notification::requestPermission(document, WTFMove(deprecatedCallback)); |
596 | return JSValue::encode(jsUndefined()); |
597 | } |
598 | |
599 | EncodedJSValue JSC_HOST_CALL jsNotificationConstructorFunctionRequestPermission(ExecState* state) |
600 | { |
601 | return IDLOperation<JSNotification>::callStatic<jsNotificationConstructorFunctionRequestPermissionBody>(*state, "requestPermission" ); |
602 | } |
603 | |
604 | static inline JSC::EncodedJSValue jsNotificationPrototypeFunctionCloseBody(JSC::ExecState* state, typename IDLOperation<JSNotification>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
605 | { |
606 | UNUSED_PARAM(state); |
607 | UNUSED_PARAM(throwScope); |
608 | auto& impl = castedThis->wrapped(); |
609 | impl.close(); |
610 | return JSValue::encode(jsUndefined()); |
611 | } |
612 | |
613 | EncodedJSValue JSC_HOST_CALL jsNotificationPrototypeFunctionClose(ExecState* state) |
614 | { |
615 | return IDLOperation<JSNotification>::call<jsNotificationPrototypeFunctionCloseBody>(*state, "close" ); |
616 | } |
617 | |
618 | static inline JSC::EncodedJSValue jsNotificationPrototypeFunctionShowBody(JSC::ExecState* state, typename IDLOperation<JSNotification>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
619 | { |
620 | UNUSED_PARAM(state); |
621 | UNUSED_PARAM(throwScope); |
622 | auto& impl = castedThis->wrapped(); |
623 | impl.show(); |
624 | return JSValue::encode(jsUndefined()); |
625 | } |
626 | |
627 | EncodedJSValue JSC_HOST_CALL jsNotificationPrototypeFunctionShow(ExecState* state) |
628 | { |
629 | return IDLOperation<JSNotification>::call<jsNotificationPrototypeFunctionShowBody>(*state, "show" ); |
630 | } |
631 | |
632 | void JSNotification::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
633 | { |
634 | auto* thisObject = jsCast<JSNotification*>(cell); |
635 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
636 | if (thisObject->scriptExecutionContext()) |
637 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
638 | Base::heapSnapshot(cell, builder); |
639 | } |
640 | |
641 | bool JSNotificationOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
642 | { |
643 | auto* jsNotification = jsCast<JSNotification*>(handle.slot()->asCell()); |
644 | if (jsNotification->wrapped().hasPendingActivity()) { |
645 | if (UNLIKELY(reason)) |
646 | *reason = "ActiveDOMObject with pending activity" ; |
647 | return true; |
648 | } |
649 | if (jsNotification->wrapped().isFiringEventListeners()) { |
650 | if (UNLIKELY(reason)) |
651 | *reason = "EventTarget firing event listeners" ; |
652 | return true; |
653 | } |
654 | UNUSED_PARAM(visitor); |
655 | UNUSED_PARAM(reason); |
656 | return false; |
657 | } |
658 | |
659 | void JSNotificationOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
660 | { |
661 | auto* jsNotification = static_cast<JSNotification*>(handle.slot()->asCell()); |
662 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
663 | uncacheWrapper(world, &jsNotification->wrapped(), jsNotification); |
664 | } |
665 | |
666 | #if ENABLE(BINDING_INTEGRITY) |
667 | #if PLATFORM(WIN) |
668 | #pragma warning(disable: 4483) |
669 | extern "C" { extern void (*const __identifier("??_7Notification@WebCore@@6B@" )[])(); } |
670 | #else |
671 | extern "C" { extern void* _ZTVN7WebCore12NotificationE[]; } |
672 | #endif |
673 | #endif |
674 | |
675 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<Notification>&& impl) |
676 | { |
677 | |
678 | #if ENABLE(BINDING_INTEGRITY) |
679 | void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr())); |
680 | #if PLATFORM(WIN) |
681 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7Notification@WebCore@@6B@" )); |
682 | #else |
683 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore12NotificationE[2]); |
684 | #endif |
685 | |
686 | // If this fails Notification does not have a vtable, so you need to add the |
687 | // ImplementationLacksVTable attribute to the interface definition |
688 | static_assert(std::is_polymorphic<Notification>::value, "Notification is not polymorphic" ); |
689 | |
690 | // If you hit this assertion you either have a use after free bug, or |
691 | // Notification has subclasses. If Notification has subclasses that get passed |
692 | // to toJS() we currently require Notification you to opt out of binding hardening |
693 | // by adding the SkipVTableValidation attribute to the interface IDL definition |
694 | RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer); |
695 | #endif |
696 | return createWrapper<Notification>(globalObject, WTFMove(impl)); |
697 | } |
698 | |
699 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, Notification& impl) |
700 | { |
701 | return wrap(state, globalObject, impl); |
702 | } |
703 | |
704 | Notification* JSNotification::toWrapped(JSC::VM& vm, JSC::JSValue value) |
705 | { |
706 | if (auto* wrapper = jsDynamicCast<JSNotification*>(vm, value)) |
707 | return &wrapper->wrapped(); |
708 | return nullptr; |
709 | } |
710 | |
711 | } |
712 | |
713 | #endif // ENABLE(NOTIFICATIONS) |
714 | |