| 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(SPEECH_SYNTHESIS) |
| 24 | |
| 25 | #include "JSSpeechSynthesis.h" |
| 26 | |
| 27 | #include "JSDOMAttribute.h" |
| 28 | #include "JSDOMBinding.h" |
| 29 | #include "JSDOMConvertBoolean.h" |
| 30 | #include "JSDOMConvertInterface.h" |
| 31 | #include "JSDOMConvertSequences.h" |
| 32 | #include "JSDOMExceptionHandling.h" |
| 33 | #include "JSDOMGlobalObject.h" |
| 34 | #include "JSDOMOperation.h" |
| 35 | #include "JSDOMWrapperCache.h" |
| 36 | #include "JSSpeechSynthesisUtterance.h" |
| 37 | #include "JSSpeechSynthesisVoice.h" |
| 38 | #include "ScriptExecutionContext.h" |
| 39 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
| 40 | #include <JavaScriptCore/JSArray.h> |
| 41 | #include <JavaScriptCore/JSCInlines.h> |
| 42 | #include <wtf/GetPtr.h> |
| 43 | #include <wtf/PointerPreparations.h> |
| 44 | #include <wtf/URL.h> |
| 45 | |
| 46 | |
| 47 | namespace WebCore { |
| 48 | using namespace JSC; |
| 49 | |
| 50 | // Functions |
| 51 | |
| 52 | JSC::EncodedJSValue JSC_HOST_CALL jsSpeechSynthesisPrototypeFunctionSpeak(JSC::ExecState*); |
| 53 | JSC::EncodedJSValue JSC_HOST_CALL jsSpeechSynthesisPrototypeFunctionCancel(JSC::ExecState*); |
| 54 | JSC::EncodedJSValue JSC_HOST_CALL jsSpeechSynthesisPrototypeFunctionPause(JSC::ExecState*); |
| 55 | JSC::EncodedJSValue JSC_HOST_CALL jsSpeechSynthesisPrototypeFunctionResume(JSC::ExecState*); |
| 56 | JSC::EncodedJSValue JSC_HOST_CALL jsSpeechSynthesisPrototypeFunctionGetVoices(JSC::ExecState*); |
| 57 | |
| 58 | // Attributes |
| 59 | |
| 60 | JSC::EncodedJSValue jsSpeechSynthesisPending(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 61 | JSC::EncodedJSValue jsSpeechSynthesisSpeaking(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 62 | JSC::EncodedJSValue jsSpeechSynthesisPaused(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 63 | |
| 64 | class JSSpeechSynthesisPrototype : public JSC::JSNonFinalObject { |
| 65 | public: |
| 66 | using Base = JSC::JSNonFinalObject; |
| 67 | static JSSpeechSynthesisPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
| 68 | { |
| 69 | JSSpeechSynthesisPrototype* ptr = new (NotNull, JSC::allocateCell<JSSpeechSynthesisPrototype>(vm.heap)) JSSpeechSynthesisPrototype(vm, globalObject, structure); |
| 70 | ptr->finishCreation(vm); |
| 71 | return ptr; |
| 72 | } |
| 73 | |
| 74 | DECLARE_INFO; |
| 75 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
| 76 | { |
| 77 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
| 78 | } |
| 79 | |
| 80 | private: |
| 81 | JSSpeechSynthesisPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
| 82 | : JSC::JSNonFinalObject(vm, structure) |
| 83 | { |
| 84 | } |
| 85 | |
| 86 | void finishCreation(JSC::VM&); |
| 87 | }; |
| 88 | |
| 89 | /* Hash table for prototype */ |
| 90 | |
| 91 | static const HashTableValue JSSpeechSynthesisPrototypeTableValues[] = |
| 92 | { |
| 93 | { "pending" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSpeechSynthesisPending), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 94 | { "speaking" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSpeechSynthesisSpeaking), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 95 | { "paused" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSpeechSynthesisPaused), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 96 | { "speak" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsSpeechSynthesisPrototypeFunctionSpeak), (intptr_t) (1) } }, |
| 97 | { "cancel" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsSpeechSynthesisPrototypeFunctionCancel), (intptr_t) (0) } }, |
| 98 | { "pause" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsSpeechSynthesisPrototypeFunctionPause), (intptr_t) (0) } }, |
| 99 | { "resume" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsSpeechSynthesisPrototypeFunctionResume), (intptr_t) (0) } }, |
| 100 | { "getVoices" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsSpeechSynthesisPrototypeFunctionGetVoices), (intptr_t) (0) } }, |
| 101 | }; |
| 102 | |
| 103 | const ClassInfo JSSpeechSynthesisPrototype::s_info = { "SpeechSynthesisPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSSpeechSynthesisPrototype) }; |
| 104 | |
| 105 | void JSSpeechSynthesisPrototype::finishCreation(VM& vm) |
| 106 | { |
| 107 | Base::finishCreation(vm); |
| 108 | reifyStaticProperties(vm, JSSpeechSynthesis::info(), JSSpeechSynthesisPrototypeTableValues, *this); |
| 109 | } |
| 110 | |
| 111 | const ClassInfo JSSpeechSynthesis::s_info = { "SpeechSynthesis" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSSpeechSynthesis) }; |
| 112 | |
| 113 | JSSpeechSynthesis::JSSpeechSynthesis(Structure* structure, JSDOMGlobalObject& globalObject, Ref<SpeechSynthesis>&& impl) |
| 114 | : JSDOMWrapper<SpeechSynthesis>(structure, globalObject, WTFMove(impl)) |
| 115 | { |
| 116 | } |
| 117 | |
| 118 | void JSSpeechSynthesis::finishCreation(VM& vm) |
| 119 | { |
| 120 | Base::finishCreation(vm); |
| 121 | ASSERT(inherits(vm, info())); |
| 122 | |
| 123 | } |
| 124 | |
| 125 | JSObject* JSSpeechSynthesis::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 126 | { |
| 127 | return JSSpeechSynthesisPrototype::create(vm, &globalObject, JSSpeechSynthesisPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
| 128 | } |
| 129 | |
| 130 | JSObject* JSSpeechSynthesis::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 131 | { |
| 132 | return getDOMPrototype<JSSpeechSynthesis>(vm, globalObject); |
| 133 | } |
| 134 | |
| 135 | void JSSpeechSynthesis::destroy(JSC::JSCell* cell) |
| 136 | { |
| 137 | JSSpeechSynthesis* thisObject = static_cast<JSSpeechSynthesis*>(cell); |
| 138 | thisObject->JSSpeechSynthesis::~JSSpeechSynthesis(); |
| 139 | } |
| 140 | |
| 141 | template<> inline JSSpeechSynthesis* IDLAttribute<JSSpeechSynthesis>::cast(ExecState& state, EncodedJSValue thisValue) |
| 142 | { |
| 143 | return jsDynamicCast<JSSpeechSynthesis*>(state.vm(), JSValue::decode(thisValue)); |
| 144 | } |
| 145 | |
| 146 | template<> inline JSSpeechSynthesis* IDLOperation<JSSpeechSynthesis>::cast(ExecState& state) |
| 147 | { |
| 148 | return jsDynamicCast<JSSpeechSynthesis*>(state.vm(), state.thisValue()); |
| 149 | } |
| 150 | |
| 151 | static inline JSValue jsSpeechSynthesisPendingGetter(ExecState& state, JSSpeechSynthesis& thisObject, ThrowScope& throwScope) |
| 152 | { |
| 153 | UNUSED_PARAM(throwScope); |
| 154 | UNUSED_PARAM(state); |
| 155 | auto& impl = thisObject.wrapped(); |
| 156 | JSValue result = toJS<IDLBoolean>(state, throwScope, impl.pending()); |
| 157 | return result; |
| 158 | } |
| 159 | |
| 160 | EncodedJSValue jsSpeechSynthesisPending(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 161 | { |
| 162 | return IDLAttribute<JSSpeechSynthesis>::get<jsSpeechSynthesisPendingGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "pending" ); |
| 163 | } |
| 164 | |
| 165 | static inline JSValue jsSpeechSynthesisSpeakingGetter(ExecState& state, JSSpeechSynthesis& thisObject, ThrowScope& throwScope) |
| 166 | { |
| 167 | UNUSED_PARAM(throwScope); |
| 168 | UNUSED_PARAM(state); |
| 169 | auto& impl = thisObject.wrapped(); |
| 170 | JSValue result = toJS<IDLBoolean>(state, throwScope, impl.speaking()); |
| 171 | return result; |
| 172 | } |
| 173 | |
| 174 | EncodedJSValue jsSpeechSynthesisSpeaking(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 175 | { |
| 176 | return IDLAttribute<JSSpeechSynthesis>::get<jsSpeechSynthesisSpeakingGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "speaking" ); |
| 177 | } |
| 178 | |
| 179 | static inline JSValue jsSpeechSynthesisPausedGetter(ExecState& state, JSSpeechSynthesis& thisObject, ThrowScope& throwScope) |
| 180 | { |
| 181 | UNUSED_PARAM(throwScope); |
| 182 | UNUSED_PARAM(state); |
| 183 | auto& impl = thisObject.wrapped(); |
| 184 | JSValue result = toJS<IDLBoolean>(state, throwScope, impl.paused()); |
| 185 | return result; |
| 186 | } |
| 187 | |
| 188 | EncodedJSValue jsSpeechSynthesisPaused(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 189 | { |
| 190 | return IDLAttribute<JSSpeechSynthesis>::get<jsSpeechSynthesisPausedGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "paused" ); |
| 191 | } |
| 192 | |
| 193 | static inline JSC::EncodedJSValue jsSpeechSynthesisPrototypeFunctionSpeakBody(JSC::ExecState* state, typename IDLOperation<JSSpeechSynthesis>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 194 | { |
| 195 | UNUSED_PARAM(state); |
| 196 | UNUSED_PARAM(throwScope); |
| 197 | auto& impl = castedThis->wrapped(); |
| 198 | if (UNLIKELY(state->argumentCount() < 1)) |
| 199 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| 200 | auto utterance = convert<IDLInterface<SpeechSynthesisUtterance>>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentTypeError(state, scope, 0, "utterance" , "SpeechSynthesis" , "speak" , "SpeechSynthesisUtterance" ); }); |
| 201 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 202 | impl.speak(*utterance); |
| 203 | return JSValue::encode(jsUndefined()); |
| 204 | } |
| 205 | |
| 206 | EncodedJSValue JSC_HOST_CALL jsSpeechSynthesisPrototypeFunctionSpeak(ExecState* state) |
| 207 | { |
| 208 | return IDLOperation<JSSpeechSynthesis>::call<jsSpeechSynthesisPrototypeFunctionSpeakBody>(*state, "speak" ); |
| 209 | } |
| 210 | |
| 211 | static inline JSC::EncodedJSValue jsSpeechSynthesisPrototypeFunctionCancelBody(JSC::ExecState* state, typename IDLOperation<JSSpeechSynthesis>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 212 | { |
| 213 | UNUSED_PARAM(state); |
| 214 | UNUSED_PARAM(throwScope); |
| 215 | auto& impl = castedThis->wrapped(); |
| 216 | impl.cancel(); |
| 217 | return JSValue::encode(jsUndefined()); |
| 218 | } |
| 219 | |
| 220 | EncodedJSValue JSC_HOST_CALL jsSpeechSynthesisPrototypeFunctionCancel(ExecState* state) |
| 221 | { |
| 222 | return IDLOperation<JSSpeechSynthesis>::call<jsSpeechSynthesisPrototypeFunctionCancelBody>(*state, "cancel" ); |
| 223 | } |
| 224 | |
| 225 | static inline JSC::EncodedJSValue jsSpeechSynthesisPrototypeFunctionPauseBody(JSC::ExecState* state, typename IDLOperation<JSSpeechSynthesis>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 226 | { |
| 227 | UNUSED_PARAM(state); |
| 228 | UNUSED_PARAM(throwScope); |
| 229 | auto& impl = castedThis->wrapped(); |
| 230 | impl.pause(); |
| 231 | return JSValue::encode(jsUndefined()); |
| 232 | } |
| 233 | |
| 234 | EncodedJSValue JSC_HOST_CALL jsSpeechSynthesisPrototypeFunctionPause(ExecState* state) |
| 235 | { |
| 236 | return IDLOperation<JSSpeechSynthesis>::call<jsSpeechSynthesisPrototypeFunctionPauseBody>(*state, "pause" ); |
| 237 | } |
| 238 | |
| 239 | static inline JSC::EncodedJSValue jsSpeechSynthesisPrototypeFunctionResumeBody(JSC::ExecState* state, typename IDLOperation<JSSpeechSynthesis>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 240 | { |
| 241 | UNUSED_PARAM(state); |
| 242 | UNUSED_PARAM(throwScope); |
| 243 | auto& impl = castedThis->wrapped(); |
| 244 | impl.resume(); |
| 245 | return JSValue::encode(jsUndefined()); |
| 246 | } |
| 247 | |
| 248 | EncodedJSValue JSC_HOST_CALL jsSpeechSynthesisPrototypeFunctionResume(ExecState* state) |
| 249 | { |
| 250 | return IDLOperation<JSSpeechSynthesis>::call<jsSpeechSynthesisPrototypeFunctionResumeBody>(*state, "resume" ); |
| 251 | } |
| 252 | |
| 253 | static inline JSC::EncodedJSValue jsSpeechSynthesisPrototypeFunctionGetVoicesBody(JSC::ExecState* state, typename IDLOperation<JSSpeechSynthesis>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 254 | { |
| 255 | UNUSED_PARAM(state); |
| 256 | UNUSED_PARAM(throwScope); |
| 257 | auto& impl = castedThis->wrapped(); |
| 258 | return JSValue::encode(toJS<IDLSequence<IDLInterface<SpeechSynthesisVoice>>>(*state, *castedThis->globalObject(), impl.getVoices())); |
| 259 | } |
| 260 | |
| 261 | EncodedJSValue JSC_HOST_CALL jsSpeechSynthesisPrototypeFunctionGetVoices(ExecState* state) |
| 262 | { |
| 263 | return IDLOperation<JSSpeechSynthesis>::call<jsSpeechSynthesisPrototypeFunctionGetVoicesBody>(*state, "getVoices" ); |
| 264 | } |
| 265 | |
| 266 | void JSSpeechSynthesis::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
| 267 | { |
| 268 | auto* thisObject = jsCast<JSSpeechSynthesis*>(cell); |
| 269 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
| 270 | if (thisObject->scriptExecutionContext()) |
| 271 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
| 272 | Base::heapSnapshot(cell, builder); |
| 273 | } |
| 274 | |
| 275 | bool JSSpeechSynthesisOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
| 276 | { |
| 277 | UNUSED_PARAM(handle); |
| 278 | UNUSED_PARAM(visitor); |
| 279 | UNUSED_PARAM(reason); |
| 280 | return false; |
| 281 | } |
| 282 | |
| 283 | void JSSpeechSynthesisOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
| 284 | { |
| 285 | auto* jsSpeechSynthesis = static_cast<JSSpeechSynthesis*>(handle.slot()->asCell()); |
| 286 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
| 287 | uncacheWrapper(world, &jsSpeechSynthesis->wrapped(), jsSpeechSynthesis); |
| 288 | } |
| 289 | |
| 290 | #if ENABLE(BINDING_INTEGRITY) |
| 291 | #if PLATFORM(WIN) |
| 292 | #pragma warning(disable: 4483) |
| 293 | extern "C" { extern void (*const __identifier("??_7SpeechSynthesis@WebCore@@6B@" )[])(); } |
| 294 | #else |
| 295 | extern "C" { extern void* _ZTVN7WebCore15SpeechSynthesisE[]; } |
| 296 | #endif |
| 297 | #endif |
| 298 | |
| 299 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<SpeechSynthesis>&& impl) |
| 300 | { |
| 301 | |
| 302 | #if ENABLE(BINDING_INTEGRITY) |
| 303 | void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr())); |
| 304 | #if PLATFORM(WIN) |
| 305 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7SpeechSynthesis@WebCore@@6B@" )); |
| 306 | #else |
| 307 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore15SpeechSynthesisE[2]); |
| 308 | #endif |
| 309 | |
| 310 | // If this fails SpeechSynthesis does not have a vtable, so you need to add the |
| 311 | // ImplementationLacksVTable attribute to the interface definition |
| 312 | static_assert(std::is_polymorphic<SpeechSynthesis>::value, "SpeechSynthesis is not polymorphic" ); |
| 313 | |
| 314 | // If you hit this assertion you either have a use after free bug, or |
| 315 | // SpeechSynthesis has subclasses. If SpeechSynthesis has subclasses that get passed |
| 316 | // to toJS() we currently require SpeechSynthesis you to opt out of binding hardening |
| 317 | // by adding the SkipVTableValidation attribute to the interface IDL definition |
| 318 | RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer); |
| 319 | #endif |
| 320 | return createWrapper<SpeechSynthesis>(globalObject, WTFMove(impl)); |
| 321 | } |
| 322 | |
| 323 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, SpeechSynthesis& impl) |
| 324 | { |
| 325 | return wrap(state, globalObject, impl); |
| 326 | } |
| 327 | |
| 328 | SpeechSynthesis* JSSpeechSynthesis::toWrapped(JSC::VM& vm, JSC::JSValue value) |
| 329 | { |
| 330 | if (auto* wrapper = jsDynamicCast<JSSpeechSynthesis*>(vm, value)) |
| 331 | return &wrapper->wrapped(); |
| 332 | return nullptr; |
| 333 | } |
| 334 | |
| 335 | } |
| 336 | |
| 337 | #endif // ENABLE(SPEECH_SYNTHESIS) |
| 338 | |