| 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(WEB_AUDIO) |
| 24 | |
| 25 | #include "JSOfflineAudioContext.h" |
| 26 | |
| 27 | #include "JSDOMBinding.h" |
| 28 | #include "JSDOMConstructor.h" |
| 29 | #include "JSDOMConvertInterface.h" |
| 30 | #include "JSDOMExceptionHandling.h" |
| 31 | #include "JSDOMWrapperCache.h" |
| 32 | #include "ScriptExecutionContext.h" |
| 33 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
| 34 | #include <JavaScriptCore/JSCInlines.h> |
| 35 | #include <wtf/GetPtr.h> |
| 36 | #include <wtf/PointerPreparations.h> |
| 37 | #include <wtf/URL.h> |
| 38 | |
| 39 | #if ENABLE(WEB_AUDIO) |
| 40 | #include "JSDOMConvertNumbers.h" |
| 41 | #endif |
| 42 | |
| 43 | |
| 44 | namespace WebCore { |
| 45 | using namespace JSC; |
| 46 | |
| 47 | // Attributes |
| 48 | |
| 49 | JSC::EncodedJSValue jsOfflineAudioContextConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 50 | bool setJSOfflineAudioContextConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 51 | |
| 52 | class JSOfflineAudioContextPrototype : public JSC::JSNonFinalObject { |
| 53 | public: |
| 54 | using Base = JSC::JSNonFinalObject; |
| 55 | static JSOfflineAudioContextPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
| 56 | { |
| 57 | JSOfflineAudioContextPrototype* ptr = new (NotNull, JSC::allocateCell<JSOfflineAudioContextPrototype>(vm.heap)) JSOfflineAudioContextPrototype(vm, globalObject, structure); |
| 58 | ptr->finishCreation(vm); |
| 59 | return ptr; |
| 60 | } |
| 61 | |
| 62 | DECLARE_INFO; |
| 63 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
| 64 | { |
| 65 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
| 66 | } |
| 67 | |
| 68 | private: |
| 69 | JSOfflineAudioContextPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
| 70 | : JSC::JSNonFinalObject(vm, structure) |
| 71 | { |
| 72 | } |
| 73 | |
| 74 | void finishCreation(JSC::VM&); |
| 75 | }; |
| 76 | |
| 77 | using JSOfflineAudioContextConstructor = JSDOMConstructor<JSOfflineAudioContext>; |
| 78 | |
| 79 | template<> EncodedJSValue JSC_HOST_CALL JSOfflineAudioContextConstructor::construct(ExecState* state) |
| 80 | { |
| 81 | VM& vm = state->vm(); |
| 82 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 83 | UNUSED_PARAM(throwScope); |
| 84 | auto* castedThis = jsCast<JSOfflineAudioContextConstructor*>(state->jsCallee()); |
| 85 | ASSERT(castedThis); |
| 86 | if (UNLIKELY(state->argumentCount() < 3)) |
| 87 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| 88 | auto* context = castedThis->scriptExecutionContext(); |
| 89 | if (UNLIKELY(!context)) |
| 90 | return throwConstructorScriptExecutionContextUnavailableError(*state, throwScope, "webkitOfflineAudioContext" ); |
| 91 | auto numberOfChannels = convert<IDLUnsignedLong>(*state, state->uncheckedArgument(0)); |
| 92 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 93 | auto numberOfFrames = convert<IDLUnsignedLong>(*state, state->uncheckedArgument(1)); |
| 94 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 95 | auto sampleRate = convert<IDLUnrestrictedFloat>(*state, state->uncheckedArgument(2)); |
| 96 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 97 | auto object = OfflineAudioContext::create(*context, WTFMove(numberOfChannels), WTFMove(numberOfFrames), WTFMove(sampleRate)); |
| 98 | return JSValue::encode(toJSNewlyCreated<IDLInterface<OfflineAudioContext>>(*state, *castedThis->globalObject(), throwScope, WTFMove(object))); |
| 99 | } |
| 100 | |
| 101 | template<> JSValue JSOfflineAudioContextConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| 102 | { |
| 103 | return JSAudioContext::getConstructor(vm, &globalObject); |
| 104 | } |
| 105 | |
| 106 | template<> void JSOfflineAudioContextConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
| 107 | { |
| 108 | putDirect(vm, vm.propertyNames->prototype, JSOfflineAudioContext::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 109 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("webkitOfflineAudioContext"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 110 | putDirect(vm, vm.propertyNames->length, jsNumber(3), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 111 | } |
| 112 | |
| 113 | template<> const ClassInfo JSOfflineAudioContextConstructor::s_info = { "webkitOfflineAudioContext" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSOfflineAudioContextConstructor) }; |
| 114 | |
| 115 | /* Hash table for prototype */ |
| 116 | |
| 117 | static const HashTableValue JSOfflineAudioContextPrototypeTableValues[] = |
| 118 | { |
| 119 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsOfflineAudioContextConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSOfflineAudioContextConstructor) } }, |
| 120 | }; |
| 121 | |
| 122 | const ClassInfo JSOfflineAudioContextPrototype::s_info = { "webkitOfflineAudioContextPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSOfflineAudioContextPrototype) }; |
| 123 | |
| 124 | void JSOfflineAudioContextPrototype::finishCreation(VM& vm) |
| 125 | { |
| 126 | Base::finishCreation(vm); |
| 127 | reifyStaticProperties(vm, JSOfflineAudioContext::info(), JSOfflineAudioContextPrototypeTableValues, *this); |
| 128 | } |
| 129 | |
| 130 | const ClassInfo JSOfflineAudioContext::s_info = { "webkitOfflineAudioContext" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSOfflineAudioContext) }; |
| 131 | |
| 132 | JSOfflineAudioContext::JSOfflineAudioContext(Structure* structure, JSDOMGlobalObject& globalObject, Ref<OfflineAudioContext>&& impl) |
| 133 | : JSAudioContext(structure, globalObject, WTFMove(impl)) |
| 134 | { |
| 135 | } |
| 136 | |
| 137 | void JSOfflineAudioContext::finishCreation(VM& vm) |
| 138 | { |
| 139 | Base::finishCreation(vm); |
| 140 | ASSERT(inherits(vm, info())); |
| 141 | |
| 142 | } |
| 143 | |
| 144 | JSObject* JSOfflineAudioContext::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 145 | { |
| 146 | return JSOfflineAudioContextPrototype::create(vm, &globalObject, JSOfflineAudioContextPrototype::createStructure(vm, &globalObject, JSAudioContext::prototype(vm, globalObject))); |
| 147 | } |
| 148 | |
| 149 | JSObject* JSOfflineAudioContext::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 150 | { |
| 151 | return getDOMPrototype<JSOfflineAudioContext>(vm, globalObject); |
| 152 | } |
| 153 | |
| 154 | JSValue JSOfflineAudioContext::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| 155 | { |
| 156 | return getDOMConstructor<JSOfflineAudioContextConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| 157 | } |
| 158 | |
| 159 | EncodedJSValue jsOfflineAudioContextConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 160 | { |
| 161 | VM& vm = state->vm(); |
| 162 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 163 | auto* prototype = jsDynamicCast<JSOfflineAudioContextPrototype*>(vm, JSValue::decode(thisValue)); |
| 164 | if (UNLIKELY(!prototype)) |
| 165 | return throwVMTypeError(state, throwScope); |
| 166 | return JSValue::encode(JSOfflineAudioContext::getConstructor(state->vm(), prototype->globalObject())); |
| 167 | } |
| 168 | |
| 169 | bool setJSOfflineAudioContextConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 170 | { |
| 171 | VM& vm = state->vm(); |
| 172 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 173 | auto* prototype = jsDynamicCast<JSOfflineAudioContextPrototype*>(vm, JSValue::decode(thisValue)); |
| 174 | if (UNLIKELY(!prototype)) { |
| 175 | throwVMTypeError(state, throwScope); |
| 176 | return false; |
| 177 | } |
| 178 | // Shadowing a built-in constructor |
| 179 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
| 180 | } |
| 181 | |
| 182 | void JSOfflineAudioContext::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
| 183 | { |
| 184 | auto* thisObject = jsCast<JSOfflineAudioContext*>(cell); |
| 185 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
| 186 | if (thisObject->scriptExecutionContext()) |
| 187 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
| 188 | Base::heapSnapshot(cell, builder); |
| 189 | } |
| 190 | |
| 191 | bool JSOfflineAudioContextOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
| 192 | { |
| 193 | auto* jsOfflineAudioContext = jsCast<JSOfflineAudioContext*>(handle.slot()->asCell()); |
| 194 | if (jsOfflineAudioContext->wrapped().hasPendingActivity()) { |
| 195 | if (UNLIKELY(reason)) |
| 196 | *reason = "ActiveDOMObject with pending activity" ; |
| 197 | return true; |
| 198 | } |
| 199 | if (jsOfflineAudioContext->wrapped().isFiringEventListeners()) { |
| 200 | if (UNLIKELY(reason)) |
| 201 | *reason = "EventTarget firing event listeners" ; |
| 202 | return true; |
| 203 | } |
| 204 | UNUSED_PARAM(visitor); |
| 205 | UNUSED_PARAM(reason); |
| 206 | return false; |
| 207 | } |
| 208 | |
| 209 | void JSOfflineAudioContextOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
| 210 | { |
| 211 | auto* jsOfflineAudioContext = static_cast<JSOfflineAudioContext*>(handle.slot()->asCell()); |
| 212 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
| 213 | uncacheWrapper(world, &jsOfflineAudioContext->wrapped(), jsOfflineAudioContext); |
| 214 | } |
| 215 | |
| 216 | #if ENABLE(BINDING_INTEGRITY) |
| 217 | #if PLATFORM(WIN) |
| 218 | #pragma warning(disable: 4483) |
| 219 | extern "C" { extern void (*const __identifier("??_7OfflineAudioContext@WebCore@@6B@" )[])(); } |
| 220 | #else |
| 221 | extern "C" { extern void* _ZTVN7WebCore19OfflineAudioContextE[]; } |
| 222 | #endif |
| 223 | #endif |
| 224 | |
| 225 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<OfflineAudioContext>&& impl) |
| 226 | { |
| 227 | |
| 228 | #if ENABLE(BINDING_INTEGRITY) |
| 229 | void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr())); |
| 230 | #if PLATFORM(WIN) |
| 231 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7OfflineAudioContext@WebCore@@6B@" )); |
| 232 | #else |
| 233 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore19OfflineAudioContextE[2]); |
| 234 | #endif |
| 235 | |
| 236 | // If this fails OfflineAudioContext does not have a vtable, so you need to add the |
| 237 | // ImplementationLacksVTable attribute to the interface definition |
| 238 | static_assert(std::is_polymorphic<OfflineAudioContext>::value, "OfflineAudioContext is not polymorphic" ); |
| 239 | |
| 240 | // If you hit this assertion you either have a use after free bug, or |
| 241 | // OfflineAudioContext has subclasses. If OfflineAudioContext has subclasses that get passed |
| 242 | // to toJS() we currently require OfflineAudioContext you to opt out of binding hardening |
| 243 | // by adding the SkipVTableValidation attribute to the interface IDL definition |
| 244 | RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer); |
| 245 | #endif |
| 246 | return createWrapper<OfflineAudioContext>(globalObject, WTFMove(impl)); |
| 247 | } |
| 248 | |
| 249 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, OfflineAudioContext& impl) |
| 250 | { |
| 251 | return wrap(state, globalObject, impl); |
| 252 | } |
| 253 | |
| 254 | |
| 255 | } |
| 256 | |
| 257 | #endif // ENABLE(WEB_AUDIO) |
| 258 | |