| 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(SERVICE_WORKER) |
| 24 | |
| 25 | #include "JSServiceWorkerClient.h" |
| 26 | |
| 27 | #include "JSDOMAttribute.h" |
| 28 | #include "JSDOMBinding.h" |
| 29 | #include "JSDOMConstructorNotConstructable.h" |
| 30 | #include "JSDOMConvertAny.h" |
| 31 | #include "JSDOMConvertObject.h" |
| 32 | #include "JSDOMConvertSequences.h" |
| 33 | #include "JSDOMConvertStrings.h" |
| 34 | #include "JSDOMExceptionHandling.h" |
| 35 | #include "JSDOMOperation.h" |
| 36 | #include "JSDOMWrapperCache.h" |
| 37 | #include "JSServiceWorkerClientType.h" |
| 38 | #include "ScriptExecutionContext.h" |
| 39 | #include <JavaScriptCore/FunctionPrototype.h> |
| 40 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
| 41 | #include <JavaScriptCore/JSArray.h> |
| 42 | #include <JavaScriptCore/JSCInlines.h> |
| 43 | #include <JavaScriptCore/JSString.h> |
| 44 | #include <wtf/GetPtr.h> |
| 45 | #include <wtf/PointerPreparations.h> |
| 46 | #include <wtf/URL.h> |
| 47 | |
| 48 | |
| 49 | namespace WebCore { |
| 50 | using namespace JSC; |
| 51 | |
| 52 | String convertEnumerationToString(ServiceWorkerClient::FrameType enumerationValue) |
| 53 | { |
| 54 | static const NeverDestroyed<String> values[] = { |
| 55 | MAKE_STATIC_STRING_IMPL("auxiliary" ), |
| 56 | MAKE_STATIC_STRING_IMPL("top-level" ), |
| 57 | MAKE_STATIC_STRING_IMPL("nested" ), |
| 58 | MAKE_STATIC_STRING_IMPL("none" ), |
| 59 | }; |
| 60 | static_assert(static_cast<size_t>(ServiceWorkerClient::FrameType::Auxiliary) == 0, "ServiceWorkerClient::FrameType::Auxiliary is not 0 as expected" ); |
| 61 | static_assert(static_cast<size_t>(ServiceWorkerClient::FrameType::TopLevel) == 1, "ServiceWorkerClient::FrameType::TopLevel is not 1 as expected" ); |
| 62 | static_assert(static_cast<size_t>(ServiceWorkerClient::FrameType::Nested) == 2, "ServiceWorkerClient::FrameType::Nested is not 2 as expected" ); |
| 63 | static_assert(static_cast<size_t>(ServiceWorkerClient::FrameType::None) == 3, "ServiceWorkerClient::FrameType::None is not 3 as expected" ); |
| 64 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
| 65 | return values[static_cast<size_t>(enumerationValue)]; |
| 66 | } |
| 67 | |
| 68 | template<> JSString* convertEnumerationToJS(ExecState& state, ServiceWorkerClient::FrameType enumerationValue) |
| 69 | { |
| 70 | return jsStringWithCache(&state, convertEnumerationToString(enumerationValue)); |
| 71 | } |
| 72 | |
| 73 | template<> Optional<ServiceWorkerClient::FrameType> parseEnumeration<ServiceWorkerClient::FrameType>(ExecState& state, JSValue value) |
| 74 | { |
| 75 | auto stringValue = value.toWTFString(&state); |
| 76 | if (stringValue == "auxiliary" ) |
| 77 | return ServiceWorkerClient::FrameType::Auxiliary; |
| 78 | if (stringValue == "top-level" ) |
| 79 | return ServiceWorkerClient::FrameType::TopLevel; |
| 80 | if (stringValue == "nested" ) |
| 81 | return ServiceWorkerClient::FrameType::Nested; |
| 82 | if (stringValue == "none" ) |
| 83 | return ServiceWorkerClient::FrameType::None; |
| 84 | return WTF::nullopt; |
| 85 | } |
| 86 | |
| 87 | template<> const char* expectedEnumerationValues<ServiceWorkerClient::FrameType>() |
| 88 | { |
| 89 | return "\"auxiliary\", \"top-level\", \"nested\", \"none\"" ; |
| 90 | } |
| 91 | |
| 92 | // Functions |
| 93 | |
| 94 | JSC::EncodedJSValue JSC_HOST_CALL jsServiceWorkerClientPrototypeFunctionPostMessage(JSC::ExecState*); |
| 95 | |
| 96 | // Attributes |
| 97 | |
| 98 | JSC::EncodedJSValue jsServiceWorkerClientConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 99 | bool setJSServiceWorkerClientConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 100 | JSC::EncodedJSValue jsServiceWorkerClientUrl(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 101 | JSC::EncodedJSValue jsServiceWorkerClientFrameType(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 102 | JSC::EncodedJSValue jsServiceWorkerClientType(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 103 | JSC::EncodedJSValue jsServiceWorkerClientId(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 104 | |
| 105 | class JSServiceWorkerClientPrototype : public JSC::JSNonFinalObject { |
| 106 | public: |
| 107 | using Base = JSC::JSNonFinalObject; |
| 108 | static JSServiceWorkerClientPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
| 109 | { |
| 110 | JSServiceWorkerClientPrototype* ptr = new (NotNull, JSC::allocateCell<JSServiceWorkerClientPrototype>(vm.heap)) JSServiceWorkerClientPrototype(vm, globalObject, structure); |
| 111 | ptr->finishCreation(vm); |
| 112 | return ptr; |
| 113 | } |
| 114 | |
| 115 | DECLARE_INFO; |
| 116 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
| 117 | { |
| 118 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
| 119 | } |
| 120 | |
| 121 | private: |
| 122 | JSServiceWorkerClientPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
| 123 | : JSC::JSNonFinalObject(vm, structure) |
| 124 | { |
| 125 | } |
| 126 | |
| 127 | void finishCreation(JSC::VM&); |
| 128 | }; |
| 129 | |
| 130 | using JSServiceWorkerClientConstructor = JSDOMConstructorNotConstructable<JSServiceWorkerClient>; |
| 131 | |
| 132 | template<> JSValue JSServiceWorkerClientConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| 133 | { |
| 134 | UNUSED_PARAM(vm); |
| 135 | return globalObject.functionPrototype(); |
| 136 | } |
| 137 | |
| 138 | template<> void JSServiceWorkerClientConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
| 139 | { |
| 140 | putDirect(vm, vm.propertyNames->prototype, JSServiceWorkerClient::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 141 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("Client"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 142 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 143 | } |
| 144 | |
| 145 | template<> const ClassInfo JSServiceWorkerClientConstructor::s_info = { "Client" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSServiceWorkerClientConstructor) }; |
| 146 | |
| 147 | /* Hash table for prototype */ |
| 148 | |
| 149 | static const HashTableValue JSServiceWorkerClientPrototypeTableValues[] = |
| 150 | { |
| 151 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsServiceWorkerClientConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSServiceWorkerClientConstructor) } }, |
| 152 | { "url" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsServiceWorkerClientUrl), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 153 | { "frameType" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsServiceWorkerClientFrameType), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 154 | { "type" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsServiceWorkerClientType), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 155 | { "id" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsServiceWorkerClientId), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 156 | { "postMessage" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsServiceWorkerClientPrototypeFunctionPostMessage), (intptr_t) (1) } }, |
| 157 | }; |
| 158 | |
| 159 | const ClassInfo JSServiceWorkerClientPrototype::s_info = { "ClientPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSServiceWorkerClientPrototype) }; |
| 160 | |
| 161 | void JSServiceWorkerClientPrototype::finishCreation(VM& vm) |
| 162 | { |
| 163 | Base::finishCreation(vm); |
| 164 | reifyStaticProperties(vm, JSServiceWorkerClient::info(), JSServiceWorkerClientPrototypeTableValues, *this); |
| 165 | } |
| 166 | |
| 167 | const ClassInfo JSServiceWorkerClient::s_info = { "Client" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSServiceWorkerClient) }; |
| 168 | |
| 169 | JSServiceWorkerClient::JSServiceWorkerClient(Structure* structure, JSDOMGlobalObject& globalObject, Ref<ServiceWorkerClient>&& impl) |
| 170 | : JSDOMWrapper<ServiceWorkerClient>(structure, globalObject, WTFMove(impl)) |
| 171 | { |
| 172 | } |
| 173 | |
| 174 | void JSServiceWorkerClient::finishCreation(VM& vm) |
| 175 | { |
| 176 | Base::finishCreation(vm); |
| 177 | ASSERT(inherits(vm, info())); |
| 178 | |
| 179 | } |
| 180 | |
| 181 | JSObject* JSServiceWorkerClient::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 182 | { |
| 183 | return JSServiceWorkerClientPrototype::create(vm, &globalObject, JSServiceWorkerClientPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
| 184 | } |
| 185 | |
| 186 | JSObject* JSServiceWorkerClient::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 187 | { |
| 188 | return getDOMPrototype<JSServiceWorkerClient>(vm, globalObject); |
| 189 | } |
| 190 | |
| 191 | JSValue JSServiceWorkerClient::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| 192 | { |
| 193 | return getDOMConstructor<JSServiceWorkerClientConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| 194 | } |
| 195 | |
| 196 | void JSServiceWorkerClient::destroy(JSC::JSCell* cell) |
| 197 | { |
| 198 | JSServiceWorkerClient* thisObject = static_cast<JSServiceWorkerClient*>(cell); |
| 199 | thisObject->JSServiceWorkerClient::~JSServiceWorkerClient(); |
| 200 | } |
| 201 | |
| 202 | template<> inline JSServiceWorkerClient* IDLAttribute<JSServiceWorkerClient>::cast(ExecState& state, EncodedJSValue thisValue) |
| 203 | { |
| 204 | return jsDynamicCast<JSServiceWorkerClient*>(state.vm(), JSValue::decode(thisValue)); |
| 205 | } |
| 206 | |
| 207 | template<> inline JSServiceWorkerClient* IDLOperation<JSServiceWorkerClient>::cast(ExecState& state) |
| 208 | { |
| 209 | return jsDynamicCast<JSServiceWorkerClient*>(state.vm(), state.thisValue()); |
| 210 | } |
| 211 | |
| 212 | EncodedJSValue jsServiceWorkerClientConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 213 | { |
| 214 | VM& vm = state->vm(); |
| 215 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 216 | auto* prototype = jsDynamicCast<JSServiceWorkerClientPrototype*>(vm, JSValue::decode(thisValue)); |
| 217 | if (UNLIKELY(!prototype)) |
| 218 | return throwVMTypeError(state, throwScope); |
| 219 | return JSValue::encode(JSServiceWorkerClient::getConstructor(state->vm(), prototype->globalObject())); |
| 220 | } |
| 221 | |
| 222 | bool setJSServiceWorkerClientConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 223 | { |
| 224 | VM& vm = state->vm(); |
| 225 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 226 | auto* prototype = jsDynamicCast<JSServiceWorkerClientPrototype*>(vm, JSValue::decode(thisValue)); |
| 227 | if (UNLIKELY(!prototype)) { |
| 228 | throwVMTypeError(state, throwScope); |
| 229 | return false; |
| 230 | } |
| 231 | // Shadowing a built-in constructor |
| 232 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
| 233 | } |
| 234 | |
| 235 | static inline JSValue jsServiceWorkerClientUrlGetter(ExecState& state, JSServiceWorkerClient& thisObject, ThrowScope& throwScope) |
| 236 | { |
| 237 | UNUSED_PARAM(throwScope); |
| 238 | UNUSED_PARAM(state); |
| 239 | auto& impl = thisObject.wrapped(); |
| 240 | JSValue result = toJS<IDLUSVString>(state, throwScope, impl.url()); |
| 241 | return result; |
| 242 | } |
| 243 | |
| 244 | EncodedJSValue jsServiceWorkerClientUrl(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 245 | { |
| 246 | return IDLAttribute<JSServiceWorkerClient>::get<jsServiceWorkerClientUrlGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "url" ); |
| 247 | } |
| 248 | |
| 249 | static inline JSValue jsServiceWorkerClientFrameTypeGetter(ExecState& state, JSServiceWorkerClient& thisObject, ThrowScope& throwScope) |
| 250 | { |
| 251 | UNUSED_PARAM(throwScope); |
| 252 | UNUSED_PARAM(state); |
| 253 | auto& impl = thisObject.wrapped(); |
| 254 | JSValue result = toJS<IDLEnumeration<ServiceWorkerClient::FrameType>>(state, throwScope, impl.frameType()); |
| 255 | return result; |
| 256 | } |
| 257 | |
| 258 | EncodedJSValue jsServiceWorkerClientFrameType(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 259 | { |
| 260 | return IDLAttribute<JSServiceWorkerClient>::get<jsServiceWorkerClientFrameTypeGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "frameType" ); |
| 261 | } |
| 262 | |
| 263 | static inline JSValue jsServiceWorkerClientTypeGetter(ExecState& state, JSServiceWorkerClient& thisObject, ThrowScope& throwScope) |
| 264 | { |
| 265 | UNUSED_PARAM(throwScope); |
| 266 | UNUSED_PARAM(state); |
| 267 | auto& impl = thisObject.wrapped(); |
| 268 | JSValue result = toJS<IDLEnumeration<ServiceWorkerClientType>>(state, throwScope, impl.type()); |
| 269 | return result; |
| 270 | } |
| 271 | |
| 272 | EncodedJSValue jsServiceWorkerClientType(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 273 | { |
| 274 | return IDLAttribute<JSServiceWorkerClient>::get<jsServiceWorkerClientTypeGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "type" ); |
| 275 | } |
| 276 | |
| 277 | static inline JSValue jsServiceWorkerClientIdGetter(ExecState& state, JSServiceWorkerClient& thisObject, ThrowScope& throwScope) |
| 278 | { |
| 279 | UNUSED_PARAM(throwScope); |
| 280 | UNUSED_PARAM(state); |
| 281 | auto& impl = thisObject.wrapped(); |
| 282 | JSValue result = toJS<IDLDOMString>(state, throwScope, impl.id()); |
| 283 | return result; |
| 284 | } |
| 285 | |
| 286 | EncodedJSValue jsServiceWorkerClientId(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 287 | { |
| 288 | return IDLAttribute<JSServiceWorkerClient>::get<jsServiceWorkerClientIdGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "id" ); |
| 289 | } |
| 290 | |
| 291 | static inline JSC::EncodedJSValue jsServiceWorkerClientPrototypeFunctionPostMessageBody(JSC::ExecState* state, typename IDLOperation<JSServiceWorkerClient>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 292 | { |
| 293 | UNUSED_PARAM(state); |
| 294 | UNUSED_PARAM(throwScope); |
| 295 | auto& impl = castedThis->wrapped(); |
| 296 | if (UNLIKELY(state->argumentCount() < 1)) |
| 297 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| 298 | auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext(); |
| 299 | if (UNLIKELY(!context)) |
| 300 | return JSValue::encode(jsUndefined()); |
| 301 | auto message = convert<IDLAny>(*state, state->uncheckedArgument(0)); |
| 302 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 303 | auto transfer = state->argument(1).isUndefined() ? Converter<IDLSequence<IDLObject>>::ReturnType{ } : convert<IDLSequence<IDLObject>>(*state, state->uncheckedArgument(1)); |
| 304 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 305 | propagateException(*state, throwScope, impl.postMessage(*context, WTFMove(message), WTFMove(transfer))); |
| 306 | return JSValue::encode(jsUndefined()); |
| 307 | } |
| 308 | |
| 309 | EncodedJSValue JSC_HOST_CALL jsServiceWorkerClientPrototypeFunctionPostMessage(ExecState* state) |
| 310 | { |
| 311 | return IDLOperation<JSServiceWorkerClient>::call<jsServiceWorkerClientPrototypeFunctionPostMessageBody>(*state, "postMessage" ); |
| 312 | } |
| 313 | |
| 314 | void JSServiceWorkerClient::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
| 315 | { |
| 316 | auto* thisObject = jsCast<JSServiceWorkerClient*>(cell); |
| 317 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
| 318 | if (thisObject->scriptExecutionContext()) |
| 319 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
| 320 | Base::heapSnapshot(cell, builder); |
| 321 | } |
| 322 | |
| 323 | bool JSServiceWorkerClientOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
| 324 | { |
| 325 | UNUSED_PARAM(handle); |
| 326 | UNUSED_PARAM(visitor); |
| 327 | UNUSED_PARAM(reason); |
| 328 | return false; |
| 329 | } |
| 330 | |
| 331 | void JSServiceWorkerClientOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
| 332 | { |
| 333 | auto* jsServiceWorkerClient = static_cast<JSServiceWorkerClient*>(handle.slot()->asCell()); |
| 334 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
| 335 | uncacheWrapper(world, &jsServiceWorkerClient->wrapped(), jsServiceWorkerClient); |
| 336 | } |
| 337 | |
| 338 | ServiceWorkerClient* JSServiceWorkerClient::toWrapped(JSC::VM& vm, JSC::JSValue value) |
| 339 | { |
| 340 | if (auto* wrapper = jsDynamicCast<JSServiceWorkerClient*>(vm, value)) |
| 341 | return &wrapper->wrapped(); |
| 342 | return nullptr; |
| 343 | } |
| 344 | |
| 345 | } |
| 346 | |
| 347 | #endif // ENABLE(SERVICE_WORKER) |
| 348 | |