| /* |
| This file is part of the WebKit open source project. |
| This file has been generated by generate-bindings.pl. DO NOT MODIFY! |
| |
| This library is free software; you can redistribute it and/or |
| modify it under the terms of the GNU Library General Public |
| License as published by the Free Software Foundation; either |
| version 2 of the License, or (at your option) any later version. |
| |
| This library is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| Library General Public License for more details. |
| |
| You should have received a copy of the GNU Library General Public License |
| along with this library; see the file COPYING.LIB. If not, write to |
| the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| Boston, MA 02110-1301, USA. |
| */ |
| |
| #include "config.h" |
| |
| #if ENABLE(LEGACY_NOTIFICATIONS) || ENABLE(NOTIFICATIONS) |
| |
| #include "JSNotification.h" |
| |
| #include "CallbackFunction.h" |
| #include "Document.h" |
| #include "EventNames.h" |
| #include "ExceptionCode.h" |
| #include "JSDOMBinding.h" |
| #include "JSDOMConstructor.h" |
| #include "JSDOMConvert.h" |
| #include "JSEventListener.h" |
| #include "JSNotificationPermissionCallback.h" |
| #include <runtime/Error.h> |
| #include <runtime/JSString.h> |
| #include <wtf/GetPtr.h> |
| |
| #if ENABLE(LEGACY_NOTIFICATIONS) || ENABLE(NOTIFICATIONS) |
| #include "URL.h" |
| #endif |
| |
| using namespace JSC; |
| |
| namespace WebCore { |
| |
| template<typename T> Optional<T> parse(ExecState&, JSValue); |
| template<typename T> const char* expectedEnumerationValues(); |
| |
| #if ENABLE(NOTIFICATIONS) |
| |
| JSString* jsStringWithCache(ExecState*, Notification::Direction); |
| |
| JSString* jsStringWithCache(ExecState* state, Notification::Direction enumerationValue) |
| { |
| static NeverDestroyed<const String> values[] = { |
| ASCIILiteral("auto"), |
| ASCIILiteral("ltr"), |
| ASCIILiteral("rtl"), |
| }; |
| static_assert(static_cast<size_t>(Notification::Direction::Auto) == 0, "Notification::Direction::Auto is not 0 as expected"); |
| static_assert(static_cast<size_t>(Notification::Direction::Ltr) == 1, "Notification::Direction::Ltr is not 1 as expected"); |
| static_assert(static_cast<size_t>(Notification::Direction::Rtl) == 2, "Notification::Direction::Rtl is not 2 as expected"); |
| ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
| return jsStringWithCache(state, values[static_cast<size_t>(enumerationValue)]); |
| } |
| |
| template<> struct JSValueTraits<Notification::Direction> { |
| static JSString* arrayJSValue(ExecState* state, JSDOMGlobalObject*, Notification::Direction value) { return jsStringWithCache(state, value); } |
| }; |
| |
| template<> Optional<Notification::Direction> parse<Notification::Direction>(ExecState& state, JSValue value) |
| { |
| auto stringValue = value.toWTFString(&state); |
| if (stringValue == "auto") |
| return Notification::Direction::Auto; |
| if (stringValue == "ltr") |
| return Notification::Direction::Ltr; |
| if (stringValue == "rtl") |
| return Notification::Direction::Rtl; |
| return Nullopt; |
| } |
| |
| template<> Notification::Direction convert<Notification::Direction>(ExecState& state, JSValue value) |
| { |
| VM& vm = state.vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| auto result = parse<Notification::Direction>(state, value); |
| if (UNLIKELY(!result)) { |
| throwTypeError(&state, throwScope); |
| return { }; |
| } |
| return result.value(); |
| } |
| |
| template<> inline const char* expectedEnumerationValues<Notification::Direction>() |
| { |
| return "\"auto\", \"ltr\", \"rtl\""; |
| } |
| |
| #endif |
| |
| #if ENABLE(NOTIFICATIONS) |
| |
| template<> Optional<Notification::Options> convertDictionary<Notification::Options>(ExecState& state, JSValue value) |
| { |
| VM& vm = state.vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| if (value.isUndefinedOrNull()) |
| return Notification::Options { Notification::Direction::Auto, "", "", "", { } }; |
| auto* object = value.getObject(); |
| if (UNLIKELY(!object || object->type() == RegExpObjectType)) { |
| throwTypeError(&state, throwScope); |
| return Nullopt; |
| } |
| auto dir = convertOptional<Notification::Direction>(state, object->get(&state, Identifier::fromString(&state, "dir")), Notification::Direction::Auto); |
| RETURN_IF_EXCEPTION(throwScope, Nullopt); |
| auto lang = convertOptional<String>(state, object->get(&state, Identifier::fromString(&state, "lang")), ""); |
| RETURN_IF_EXCEPTION(throwScope, Nullopt); |
| auto body = convertOptional<String>(state, object->get(&state, Identifier::fromString(&state, "body")), ""); |
| RETURN_IF_EXCEPTION(throwScope, Nullopt); |
| auto tag = convertOptional<String>(state, object->get(&state, Identifier::fromString(&state, "tag")), ""); |
| RETURN_IF_EXCEPTION(throwScope, Nullopt); |
| auto icon = convertOptional<String>(state, object->get(&state, Identifier::fromString(&state, "icon"))); |
| return Notification::Options { WTFMove(dir), WTFMove(lang), WTFMove(body), WTFMove(tag), WTFMove(icon) }; |
| } |
| |
| #endif |
| |
| // Functions |
| |
| JSC::EncodedJSValue JSC_HOST_CALL jsNotificationPrototypeFunctionShow(JSC::ExecState*); |
| #if ENABLE(LEGACY_NOTIFICATIONS) |
| JSC::EncodedJSValue JSC_HOST_CALL jsNotificationPrototypeFunctionCancel(JSC::ExecState*); |
| #endif |
| #if ENABLE(NOTIFICATIONS) |
| JSC::EncodedJSValue JSC_HOST_CALL jsNotificationPrototypeFunctionClose(JSC::ExecState*); |
| #endif |
| #if ENABLE(NOTIFICATIONS) |
| JSC::EncodedJSValue JSC_HOST_CALL jsNotificationConstructorFunctionRequestPermission(JSC::ExecState*); |
| #endif |
| |
| // Attributes |
| |
| #if ENABLE(NOTIFICATIONS) |
| JSC::EncodedJSValue jsNotificationConstructorPermission(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| #endif |
| JSC::EncodedJSValue jsNotificationOnclick(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSNotificationOnclick(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| JSC::EncodedJSValue jsNotificationOnclose(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSNotificationOnclose(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| JSC::EncodedJSValue jsNotificationOndisplay(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSNotificationOndisplay(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| JSC::EncodedJSValue jsNotificationOnerror(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSNotificationOnerror(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| JSC::EncodedJSValue jsNotificationOnshow(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSNotificationOnshow(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| #if ENABLE(LEGACY_NOTIFICATIONS) |
| JSC::EncodedJSValue jsNotificationDir(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSNotificationDir(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| #endif |
| #if ENABLE(LEGACY_NOTIFICATIONS) |
| JSC::EncodedJSValue jsNotificationReplaceId(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSNotificationReplaceId(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| #endif |
| #if ENABLE(NOTIFICATIONS) |
| JSC::EncodedJSValue jsNotificationTag(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSNotificationTag(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| #endif |
| JSC::EncodedJSValue jsNotificationConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSNotificationConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| |
| class JSNotificationPrototype : public JSC::JSNonFinalObject { |
| public: |
| typedef JSC::JSNonFinalObject Base; |
| static JSNotificationPrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure) |
| { |
| JSNotificationPrototype* ptr = new (NotNull, JSC::allocateCell<JSNotificationPrototype>(vm.heap)) JSNotificationPrototype(vm, globalObject, structure); |
| ptr->finishCreation(vm); |
| return ptr; |
| } |
| |
| DECLARE_INFO; |
| static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
| { |
| return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
| } |
| |
| private: |
| JSNotificationPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
| : JSC::JSNonFinalObject(vm, structure) |
| { |
| } |
| |
| void finishCreation(JSC::VM&); |
| }; |
| |
| typedef JSDOMConstructorNotConstructable<JSNotification> JSNotificationConstructor; |
| |
| /* Hash table for constructor */ |
| |
| static const HashTableValue JSNotificationConstructorTableValues[] = |
| { |
| #if ENABLE(NOTIFICATIONS) |
| { "permission", DontDelete | ReadOnly, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationConstructorPermission), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| #else |
| { 0, 0, NoIntrinsic, { 0, 0 } }, |
| #endif |
| #if ENABLE(NOTIFICATIONS) |
| { "requestPermission", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsNotificationConstructorFunctionRequestPermission), (intptr_t) (0) } }, |
| #else |
| { 0, 0, NoIntrinsic, { 0, 0 } }, |
| #endif |
| }; |
| |
| template<> JSValue JSNotificationConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| { |
| return JSEventTarget::getConstructor(vm, &globalObject); |
| } |
| |
| template<> void JSNotificationConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
| { |
| putDirect(vm, vm.propertyNames->prototype, JSNotification::prototype(vm, &globalObject), DontDelete | ReadOnly | DontEnum); |
| putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("Notification"))), ReadOnly | DontEnum); |
| putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontEnum); |
| reifyStaticProperties(vm, JSNotificationConstructorTableValues, *this); |
| } |
| |
| template<> const ClassInfo JSNotificationConstructor::s_info = { "Notification", &Base::s_info, 0, CREATE_METHOD_TABLE(JSNotificationConstructor) }; |
| |
| /* Hash table for prototype */ |
| |
| static const HashTableValue JSNotificationPrototypeTableValues[] = |
| { |
| { "constructor", DontEnum, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSNotificationConstructor) } }, |
| { "onclick", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationOnclick), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSNotificationOnclick) } }, |
| { "onclose", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationOnclose), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSNotificationOnclose) } }, |
| { "ondisplay", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationOndisplay), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSNotificationOndisplay) } }, |
| { "onerror", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationOnerror), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSNotificationOnerror) } }, |
| { "onshow", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationOnshow), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSNotificationOnshow) } }, |
| #if ENABLE(LEGACY_NOTIFICATIONS) |
| { "dir", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationDir), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSNotificationDir) } }, |
| #else |
| { 0, 0, NoIntrinsic, { 0, 0 } }, |
| #endif |
| #if ENABLE(LEGACY_NOTIFICATIONS) |
| { "replaceId", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationReplaceId), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSNotificationReplaceId) } }, |
| #else |
| { 0, 0, NoIntrinsic, { 0, 0 } }, |
| #endif |
| #if ENABLE(NOTIFICATIONS) |
| { "tag", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNotificationTag), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSNotificationTag) } }, |
| #else |
| { 0, 0, NoIntrinsic, { 0, 0 } }, |
| #endif |
| { "show", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsNotificationPrototypeFunctionShow), (intptr_t) (0) } }, |
| #if ENABLE(LEGACY_NOTIFICATIONS) |
| { "cancel", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsNotificationPrototypeFunctionCancel), (intptr_t) (0) } }, |
| #else |
| { 0, 0, NoIntrinsic, { 0, 0 } }, |
| #endif |
| #if ENABLE(NOTIFICATIONS) |
| { "close", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsNotificationPrototypeFunctionClose), (intptr_t) (0) } }, |
| #else |
| { 0, 0, NoIntrinsic, { 0, 0 } }, |
| #endif |
| }; |
| |
| const ClassInfo JSNotificationPrototype::s_info = { "NotificationPrototype", &Base::s_info, 0, CREATE_METHOD_TABLE(JSNotificationPrototype) }; |
| |
| void JSNotificationPrototype::finishCreation(VM& vm) |
| { |
| Base::finishCreation(vm); |
| reifyStaticProperties(vm, JSNotificationPrototypeTableValues, *this); |
| } |
| |
| const ClassInfo JSNotification::s_info = { "Notification", &Base::s_info, 0, CREATE_METHOD_TABLE(JSNotification) }; |
| |
| JSNotification::JSNotification(Structure* structure, JSDOMGlobalObject& globalObject, Ref<Notification>&& impl) |
| : JSEventTarget(structure, globalObject, WTFMove(impl)) |
| { |
| } |
| |
| JSObject* JSNotification::createPrototype(VM& vm, JSGlobalObject* globalObject) |
| { |
| return JSNotificationPrototype::create(vm, globalObject, JSNotificationPrototype::createStructure(vm, globalObject, JSEventTarget::prototype(vm, globalObject))); |
| } |
| |
| JSObject* JSNotification::prototype(VM& vm, JSGlobalObject* globalObject) |
| { |
| return getDOMPrototype<JSNotification>(vm, globalObject); |
| } |
| |
| #if ENABLE(NOTIFICATIONS) |
| EncodedJSValue jsNotificationConstructorPermission(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext(); |
| if (!context) |
| return JSValue::encode(jsUndefined()); |
| ASSERT(context->isDocument()); |
| auto& document = downcast<Document>(*context); |
| JSValue result = jsStringWithCache(state, Notification::permission(document)); |
| return JSValue::encode(result); |
| } |
| |
| #endif |
| |
| EncodedJSValue jsNotificationOnclick(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSNotification*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Notification", "onclick"); |
| } |
| UNUSED_PARAM(state); |
| return JSValue::encode(eventHandlerAttribute(castedThis->wrapped(), eventNames().clickEvent)); |
| } |
| |
| |
| EncodedJSValue jsNotificationOnclose(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSNotification*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Notification", "onclose"); |
| } |
| UNUSED_PARAM(state); |
| return JSValue::encode(eventHandlerAttribute(castedThis->wrapped(), eventNames().closeEvent)); |
| } |
| |
| |
| EncodedJSValue jsNotificationOndisplay(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSNotification*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Notification", "ondisplay"); |
| } |
| UNUSED_PARAM(state); |
| return JSValue::encode(eventHandlerAttribute(castedThis->wrapped(), eventNames().showEvent)); |
| } |
| |
| |
| EncodedJSValue jsNotificationOnerror(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSNotification*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Notification", "onerror"); |
| } |
| UNUSED_PARAM(state); |
| return JSValue::encode(eventHandlerAttribute(castedThis->wrapped(), eventNames().errorEvent)); |
| } |
| |
| |
| EncodedJSValue jsNotificationOnshow(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSNotification*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Notification", "onshow"); |
| } |
| UNUSED_PARAM(state); |
| return JSValue::encode(eventHandlerAttribute(castedThis->wrapped(), eventNames().showEvent)); |
| } |
| |
| |
| #if ENABLE(LEGACY_NOTIFICATIONS) |
| EncodedJSValue jsNotificationDir(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSNotification*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Notification", "dir"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsStringWithCache(state, impl.dir()); |
| return JSValue::encode(result); |
| } |
| |
| #endif |
| |
| #if ENABLE(LEGACY_NOTIFICATIONS) |
| EncodedJSValue jsNotificationReplaceId(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSNotification*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Notification", "replaceId"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsStringWithCache(state, impl.replaceId()); |
| return JSValue::encode(result); |
| } |
| |
| #endif |
| |
| #if ENABLE(NOTIFICATIONS) |
| EncodedJSValue jsNotificationTag(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSNotification*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Notification", "tag"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsStringWithCache(state, impl.tag()); |
| return JSValue::encode(result); |
| } |
| |
| #endif |
| |
| EncodedJSValue jsNotificationConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| JSNotificationPrototype* domObject = jsDynamicCast<JSNotificationPrototype*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!domObject)) |
| return throwVMTypeError(state, throwScope); |
| return JSValue::encode(JSNotification::getConstructor(state->vm(), domObject->globalObject())); |
| } |
| |
| bool setJSNotificationConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| JSValue value = JSValue::decode(encodedValue); |
| JSNotificationPrototype* domObject = jsDynamicCast<JSNotificationPrototype*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!domObject)) { |
| throwVMTypeError(state, throwScope); |
| return false; |
| } |
| // Shadowing a built-in constructor |
| return domObject->putDirect(state->vm(), state->propertyNames().constructor, value); |
| } |
| |
| bool setJSNotificationOnclick(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue value = JSValue::decode(encodedValue); |
| UNUSED_PARAM(thisValue); |
| JSNotification* castedThis = jsDynamicCast<JSNotification*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!castedThis)) { |
| return throwSetterTypeError(*state, throwScope, "Notification", "onclick"); |
| } |
| setEventHandlerAttribute(*state, *castedThis, castedThis->wrapped(), eventNames().clickEvent, value); |
| return true; |
| } |
| |
| |
| bool setJSNotificationOnclose(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue value = JSValue::decode(encodedValue); |
| UNUSED_PARAM(thisValue); |
| JSNotification* castedThis = jsDynamicCast<JSNotification*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!castedThis)) { |
| return throwSetterTypeError(*state, throwScope, "Notification", "onclose"); |
| } |
| setEventHandlerAttribute(*state, *castedThis, castedThis->wrapped(), eventNames().closeEvent, value); |
| return true; |
| } |
| |
| |
| bool setJSNotificationOndisplay(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue value = JSValue::decode(encodedValue); |
| UNUSED_PARAM(thisValue); |
| JSNotification* castedThis = jsDynamicCast<JSNotification*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!castedThis)) { |
| return throwSetterTypeError(*state, throwScope, "Notification", "ondisplay"); |
| } |
| setEventHandlerAttribute(*state, *castedThis, castedThis->wrapped(), eventNames().showEvent, value); |
| return true; |
| } |
| |
| |
| bool setJSNotificationOnerror(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue value = JSValue::decode(encodedValue); |
| UNUSED_PARAM(thisValue); |
| JSNotification* castedThis = jsDynamicCast<JSNotification*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!castedThis)) { |
| return throwSetterTypeError(*state, throwScope, "Notification", "onerror"); |
| } |
| setEventHandlerAttribute(*state, *castedThis, castedThis->wrapped(), eventNames().errorEvent, value); |
| return true; |
| } |
| |
| |
| bool setJSNotificationOnshow(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue value = JSValue::decode(encodedValue); |
| UNUSED_PARAM(thisValue); |
| JSNotification* castedThis = jsDynamicCast<JSNotification*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!castedThis)) { |
| return throwSetterTypeError(*state, throwScope, "Notification", "onshow"); |
| } |
| setEventHandlerAttribute(*state, *castedThis, castedThis->wrapped(), eventNames().showEvent, value); |
| return true; |
| } |
| |
| |
| #if ENABLE(LEGACY_NOTIFICATIONS) |
| bool setJSNotificationDir(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue value = JSValue::decode(encodedValue); |
| UNUSED_PARAM(thisValue); |
| JSNotification* castedThis = jsDynamicCast<JSNotification*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!castedThis)) { |
| return throwSetterTypeError(*state, throwScope, "Notification", "dir"); |
| } |
| auto& impl = castedThis->wrapped(); |
| auto nativeValue = value.toWTFString(state); |
| RETURN_IF_EXCEPTION(throwScope, false); |
| impl.setDir(WTFMove(nativeValue)); |
| return true; |
| } |
| |
| #endif |
| |
| #if ENABLE(LEGACY_NOTIFICATIONS) |
| bool setJSNotificationReplaceId(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue value = JSValue::decode(encodedValue); |
| UNUSED_PARAM(thisValue); |
| JSNotification* castedThis = jsDynamicCast<JSNotification*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!castedThis)) { |
| return throwSetterTypeError(*state, throwScope, "Notification", "replaceId"); |
| } |
| auto& impl = castedThis->wrapped(); |
| auto nativeValue = value.toWTFString(state); |
| RETURN_IF_EXCEPTION(throwScope, false); |
| impl.setReplaceId(WTFMove(nativeValue)); |
| return true; |
| } |
| |
| #endif |
| |
| #if ENABLE(NOTIFICATIONS) |
| bool setJSNotificationTag(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue value = JSValue::decode(encodedValue); |
| UNUSED_PARAM(thisValue); |
| JSNotification* castedThis = jsDynamicCast<JSNotification*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!castedThis)) { |
| return throwSetterTypeError(*state, throwScope, "Notification", "tag"); |
| } |
| auto& impl = castedThis->wrapped(); |
| auto nativeValue = value.toWTFString(state); |
| RETURN_IF_EXCEPTION(throwScope, false); |
| impl.setTag(WTFMove(nativeValue)); |
| return true; |
| } |
| |
| #endif |
| |
| JSValue JSNotification::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| { |
| return getDOMConstructor<JSNotificationConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsNotificationPrototypeFunctionShow(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSNotification*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "Notification", "show"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSNotification::info()); |
| auto& impl = castedThis->wrapped(); |
| impl.show(); |
| return JSValue::encode(jsUndefined()); |
| } |
| |
| #if ENABLE(LEGACY_NOTIFICATIONS) |
| EncodedJSValue JSC_HOST_CALL jsNotificationPrototypeFunctionCancel(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSNotification*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "Notification", "cancel"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSNotification::info()); |
| auto& impl = castedThis->wrapped(); |
| impl.close(); |
| return JSValue::encode(jsUndefined()); |
| } |
| |
| #endif |
| |
| #if ENABLE(NOTIFICATIONS) |
| EncodedJSValue JSC_HOST_CALL jsNotificationPrototypeFunctionClose(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSNotification*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "Notification", "close"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSNotification::info()); |
| auto& impl = castedThis->wrapped(); |
| impl.close(); |
| return JSValue::encode(jsUndefined()); |
| } |
| |
| #endif |
| |
| #if ENABLE(NOTIFICATIONS) |
| EncodedJSValue JSC_HOST_CALL jsNotificationConstructorFunctionRequestPermission(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext(); |
| if (!context) |
| return JSValue::encode(jsUndefined()); |
| ASSERT(context->isDocument()); |
| auto& document = downcast<Document>(*context); |
| RefPtr<NotificationPermissionCallback> callback; |
| if (!state->argument(0).isUndefinedOrNull()) { |
| if (!state->uncheckedArgument(0).isFunction()) |
| return throwArgumentMustBeFunctionError(*state, throwScope, 0, "callback", "Notification", "requestPermission"); |
| callback = createFunctionOnlyCallback<JSNotificationPermissionCallback>(state, jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject()), state->uncheckedArgument(0)); |
| } |
| Notification::requestPermission(document, WTFMove(callback)); |
| return JSValue::encode(jsUndefined()); |
| } |
| |
| #endif |
| |
| void JSNotification::visitChildren(JSCell* cell, SlotVisitor& visitor) |
| { |
| auto* thisObject = jsCast<JSNotification*>(cell); |
| ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
| Base::visitChildren(thisObject, visitor); |
| thisObject->wrapped().visitJSEventListeners(visitor); |
| } |
| |
| bool JSNotificationOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor) |
| { |
| auto* jsNotification = jsCast<JSNotification*>(handle.slot()->asCell()); |
| if (jsNotification->wrapped().hasPendingActivity()) |
| return true; |
| if (jsNotification->wrapped().isFiringEventListeners()) |
| return true; |
| UNUSED_PARAM(visitor); |
| return false; |
| } |
| |
| void JSNotificationOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
| { |
| auto* jsNotification = jsCast<JSNotification*>(handle.slot()->asCell()); |
| auto& world = *static_cast<DOMWrapperWorld*>(context); |
| uncacheWrapper(world, &jsNotification->wrapped(), jsNotification); |
| } |
| |
| #if ENABLE(BINDING_INTEGRITY) |
| #if PLATFORM(WIN) |
| #pragma warning(disable: 4483) |
| extern "C" { extern void (*const __identifier("??_7Notification@WebCore@@6B@")[])(); } |
| #else |
| extern "C" { extern void* _ZTVN7WebCore12NotificationE[]; } |
| #endif |
| #endif |
| |
| JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<Notification>&& impl) |
| { |
| |
| #if ENABLE(BINDING_INTEGRITY) |
| void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr())); |
| #if PLATFORM(WIN) |
| void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7Notification@WebCore@@6B@")); |
| #else |
| void* expectedVTablePointer = &_ZTVN7WebCore12NotificationE[2]; |
| #if COMPILER(CLANG) |
| // If this fails Notification does not have a vtable, so you need to add the |
| // ImplementationLacksVTable attribute to the interface definition |
| static_assert(__is_polymorphic(Notification), "Notification is not polymorphic"); |
| #endif |
| #endif |
| // If you hit this assertion you either have a use after free bug, or |
| // Notification has subclasses. If Notification has subclasses that get passed |
| // to toJS() we currently require Notification you to opt out of binding hardening |
| // by adding the SkipVTableValidation attribute to the interface IDL definition |
| RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer); |
| #endif |
| return createWrapper<Notification>(globalObject, WTFMove(impl)); |
| } |
| |
| JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, Notification& impl) |
| { |
| return wrap(state, globalObject, impl); |
| } |
| |
| Notification* JSNotification::toWrapped(JSC::JSValue value) |
| { |
| if (auto* wrapper = jsDynamicCast<JSNotification*>(value)) |
| return &wrapper->wrapped(); |
| return nullptr; |
| } |
| |
| } |
| |
| #endif // ENABLE(LEGACY_NOTIFICATIONS) || ENABLE(NOTIFICATIONS) |