| 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 | #include "JSSpectreGadget.h" |
| 23 | |
| 24 | #include "JSDOMBinding.h" |
| 25 | #include "JSDOMConstructor.h" |
| 26 | #include "JSDOMConvertInterface.h" |
| 27 | #include "JSDOMConvertNumbers.h" |
| 28 | #include "JSDOMConvertStrings.h" |
| 29 | #include "JSDOMExceptionHandling.h" |
| 30 | #include "JSDOMOperation.h" |
| 31 | #include "JSDOMWrapperCache.h" |
| 32 | #include "ScriptExecutionContext.h" |
| 33 | #include <JavaScriptCore/FunctionPrototype.h> |
| 34 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
| 35 | #include <JavaScriptCore/JSCInlines.h> |
| 36 | #include <wtf/GetPtr.h> |
| 37 | #include <wtf/PointerPreparations.h> |
| 38 | #include <wtf/URL.h> |
| 39 | |
| 40 | |
| 41 | namespace WebCore { |
| 42 | using namespace JSC; |
| 43 | |
| 44 | // Functions |
| 45 | |
| 46 | JSC::EncodedJSValue JSC_HOST_CALL jsSpectreGadgetPrototypeFunctionSetReadLength(JSC::ExecState*); |
| 47 | JSC::EncodedJSValue JSC_HOST_CALL jsSpectreGadgetPrototypeFunctionCharCodeAt(JSC::ExecState*); |
| 48 | JSC::EncodedJSValue JSC_HOST_CALL jsSpectreGadgetPrototypeFunctionClflushReadLength(JSC::ExecState*); |
| 49 | |
| 50 | // Attributes |
| 51 | |
| 52 | JSC::EncodedJSValue jsSpectreGadgetConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 53 | bool setJSSpectreGadgetConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 54 | |
| 55 | class JSSpectreGadgetPrototype : public JSC::JSNonFinalObject { |
| 56 | public: |
| 57 | using Base = JSC::JSNonFinalObject; |
| 58 | static JSSpectreGadgetPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
| 59 | { |
| 60 | JSSpectreGadgetPrototype* ptr = new (NotNull, JSC::allocateCell<JSSpectreGadgetPrototype>(vm.heap)) JSSpectreGadgetPrototype(vm, globalObject, structure); |
| 61 | ptr->finishCreation(vm); |
| 62 | return ptr; |
| 63 | } |
| 64 | |
| 65 | DECLARE_INFO; |
| 66 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
| 67 | { |
| 68 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
| 69 | } |
| 70 | |
| 71 | private: |
| 72 | JSSpectreGadgetPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
| 73 | : JSC::JSNonFinalObject(vm, structure) |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | void finishCreation(JSC::VM&); |
| 78 | }; |
| 79 | |
| 80 | using JSSpectreGadgetConstructor = JSDOMConstructor<JSSpectreGadget>; |
| 81 | |
| 82 | template<> EncodedJSValue JSC_HOST_CALL JSSpectreGadgetConstructor::construct(ExecState* state) |
| 83 | { |
| 84 | VM& vm = state->vm(); |
| 85 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 86 | UNUSED_PARAM(throwScope); |
| 87 | auto* castedThis = jsCast<JSSpectreGadgetConstructor*>(state->jsCallee()); |
| 88 | ASSERT(castedThis); |
| 89 | if (UNLIKELY(state->argumentCount() < 1)) |
| 90 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| 91 | auto data = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
| 92 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 93 | auto object = SpectreGadget::create(WTFMove(data)); |
| 94 | return JSValue::encode(toJSNewlyCreated<IDLInterface<SpectreGadget>>(*state, *castedThis->globalObject(), WTFMove(object))); |
| 95 | } |
| 96 | |
| 97 | template<> JSValue JSSpectreGadgetConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| 98 | { |
| 99 | UNUSED_PARAM(vm); |
| 100 | return globalObject.functionPrototype(); |
| 101 | } |
| 102 | |
| 103 | template<> void JSSpectreGadgetConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
| 104 | { |
| 105 | putDirect(vm, vm.propertyNames->prototype, JSSpectreGadget::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 106 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("SpectreGadget"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 107 | putDirect(vm, vm.propertyNames->length, jsNumber(1), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 108 | } |
| 109 | |
| 110 | template<> const ClassInfo JSSpectreGadgetConstructor::s_info = { "SpectreGadget" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSSpectreGadgetConstructor) }; |
| 111 | |
| 112 | /* Hash table for prototype */ |
| 113 | |
| 114 | static const HashTableValue JSSpectreGadgetPrototypeTableValues[] = |
| 115 | { |
| 116 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSpectreGadgetConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSSpectreGadgetConstructor) } }, |
| 117 | { "setReadLength" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsSpectreGadgetPrototypeFunctionSetReadLength), (intptr_t) (1) } }, |
| 118 | { "charCodeAt" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsSpectreGadgetPrototypeFunctionCharCodeAt), (intptr_t) (1) } }, |
| 119 | { "clflushReadLength" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsSpectreGadgetPrototypeFunctionClflushReadLength), (intptr_t) (0) } }, |
| 120 | }; |
| 121 | |
| 122 | const ClassInfo JSSpectreGadgetPrototype::s_info = { "SpectreGadgetPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSSpectreGadgetPrototype) }; |
| 123 | |
| 124 | void JSSpectreGadgetPrototype::finishCreation(VM& vm) |
| 125 | { |
| 126 | Base::finishCreation(vm); |
| 127 | reifyStaticProperties(vm, JSSpectreGadget::info(), JSSpectreGadgetPrototypeTableValues, *this); |
| 128 | } |
| 129 | |
| 130 | const ClassInfo JSSpectreGadget::s_info = { "SpectreGadget" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSSpectreGadget) }; |
| 131 | |
| 132 | JSSpectreGadget::JSSpectreGadget(Structure* structure, JSDOMGlobalObject& globalObject, Ref<SpectreGadget>&& impl) |
| 133 | : JSDOMWrapper<SpectreGadget>(structure, globalObject, WTFMove(impl)) |
| 134 | { |
| 135 | } |
| 136 | |
| 137 | void JSSpectreGadget::finishCreation(VM& vm) |
| 138 | { |
| 139 | Base::finishCreation(vm); |
| 140 | ASSERT(inherits(vm, info())); |
| 141 | |
| 142 | } |
| 143 | |
| 144 | JSObject* JSSpectreGadget::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 145 | { |
| 146 | return JSSpectreGadgetPrototype::create(vm, &globalObject, JSSpectreGadgetPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
| 147 | } |
| 148 | |
| 149 | JSObject* JSSpectreGadget::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 150 | { |
| 151 | return getDOMPrototype<JSSpectreGadget>(vm, globalObject); |
| 152 | } |
| 153 | |
| 154 | JSValue JSSpectreGadget::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| 155 | { |
| 156 | return getDOMConstructor<JSSpectreGadgetConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| 157 | } |
| 158 | |
| 159 | void JSSpectreGadget::destroy(JSC::JSCell* cell) |
| 160 | { |
| 161 | JSSpectreGadget* thisObject = static_cast<JSSpectreGadget*>(cell); |
| 162 | thisObject->JSSpectreGadget::~JSSpectreGadget(); |
| 163 | } |
| 164 | |
| 165 | template<> inline JSSpectreGadget* IDLOperation<JSSpectreGadget>::cast(ExecState& state) |
| 166 | { |
| 167 | return jsDynamicCast<JSSpectreGadget*>(state.vm(), state.thisValue()); |
| 168 | } |
| 169 | |
| 170 | EncodedJSValue jsSpectreGadgetConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 171 | { |
| 172 | VM& vm = state->vm(); |
| 173 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 174 | auto* prototype = jsDynamicCast<JSSpectreGadgetPrototype*>(vm, JSValue::decode(thisValue)); |
| 175 | if (UNLIKELY(!prototype)) |
| 176 | return throwVMTypeError(state, throwScope); |
| 177 | return JSValue::encode(JSSpectreGadget::getConstructor(state->vm(), prototype->globalObject())); |
| 178 | } |
| 179 | |
| 180 | bool setJSSpectreGadgetConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 181 | { |
| 182 | VM& vm = state->vm(); |
| 183 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 184 | auto* prototype = jsDynamicCast<JSSpectreGadgetPrototype*>(vm, JSValue::decode(thisValue)); |
| 185 | if (UNLIKELY(!prototype)) { |
| 186 | throwVMTypeError(state, throwScope); |
| 187 | return false; |
| 188 | } |
| 189 | // Shadowing a built-in constructor |
| 190 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
| 191 | } |
| 192 | |
| 193 | static inline JSC::EncodedJSValue jsSpectreGadgetPrototypeFunctionSetReadLengthBody(JSC::ExecState* state, typename IDLOperation<JSSpectreGadget>::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 readLength = convert<IDLUnsignedLong>(*state, state->uncheckedArgument(0)); |
| 201 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 202 | impl.setReadLength(WTFMove(readLength)); |
| 203 | return JSValue::encode(jsUndefined()); |
| 204 | } |
| 205 | |
| 206 | EncodedJSValue JSC_HOST_CALL jsSpectreGadgetPrototypeFunctionSetReadLength(ExecState* state) |
| 207 | { |
| 208 | return IDLOperation<JSSpectreGadget>::call<jsSpectreGadgetPrototypeFunctionSetReadLengthBody>(*state, "setReadLength" ); |
| 209 | } |
| 210 | |
| 211 | static inline JSC::EncodedJSValue jsSpectreGadgetPrototypeFunctionCharCodeAtBody(JSC::ExecState* state, typename IDLOperation<JSSpectreGadget>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 212 | { |
| 213 | UNUSED_PARAM(state); |
| 214 | UNUSED_PARAM(throwScope); |
| 215 | auto& impl = castedThis->wrapped(); |
| 216 | if (UNLIKELY(state->argumentCount() < 1)) |
| 217 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| 218 | auto index = convert<IDLUnsignedLong>(*state, state->uncheckedArgument(0)); |
| 219 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 220 | return JSValue::encode(toJS<IDLUnsignedLong>(impl.charCodeAt(WTFMove(index)))); |
| 221 | } |
| 222 | |
| 223 | EncodedJSValue JSC_HOST_CALL jsSpectreGadgetPrototypeFunctionCharCodeAt(ExecState* state) |
| 224 | { |
| 225 | return IDLOperation<JSSpectreGadget>::call<jsSpectreGadgetPrototypeFunctionCharCodeAtBody>(*state, "charCodeAt" ); |
| 226 | } |
| 227 | |
| 228 | static inline JSC::EncodedJSValue jsSpectreGadgetPrototypeFunctionClflushReadLengthBody(JSC::ExecState* state, typename IDLOperation<JSSpectreGadget>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 229 | { |
| 230 | UNUSED_PARAM(state); |
| 231 | UNUSED_PARAM(throwScope); |
| 232 | auto& impl = castedThis->wrapped(); |
| 233 | impl.clflushReadLength(); |
| 234 | return JSValue::encode(jsUndefined()); |
| 235 | } |
| 236 | |
| 237 | EncodedJSValue JSC_HOST_CALL jsSpectreGadgetPrototypeFunctionClflushReadLength(ExecState* state) |
| 238 | { |
| 239 | return IDLOperation<JSSpectreGadget>::call<jsSpectreGadgetPrototypeFunctionClflushReadLengthBody>(*state, "clflushReadLength" ); |
| 240 | } |
| 241 | |
| 242 | void JSSpectreGadget::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
| 243 | { |
| 244 | auto* thisObject = jsCast<JSSpectreGadget*>(cell); |
| 245 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
| 246 | if (thisObject->scriptExecutionContext()) |
| 247 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
| 248 | Base::heapSnapshot(cell, builder); |
| 249 | } |
| 250 | |
| 251 | bool JSSpectreGadgetOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
| 252 | { |
| 253 | UNUSED_PARAM(handle); |
| 254 | UNUSED_PARAM(visitor); |
| 255 | UNUSED_PARAM(reason); |
| 256 | return false; |
| 257 | } |
| 258 | |
| 259 | void JSSpectreGadgetOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
| 260 | { |
| 261 | auto* jsSpectreGadget = static_cast<JSSpectreGadget*>(handle.slot()->asCell()); |
| 262 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
| 263 | uncacheWrapper(world, &jsSpectreGadget->wrapped(), jsSpectreGadget); |
| 264 | } |
| 265 | |
| 266 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<SpectreGadget>&& impl) |
| 267 | { |
| 268 | // If you hit this failure the interface definition has the ImplementationLacksVTable |
| 269 | // attribute. You should remove that attribute. If the class has subclasses |
| 270 | // that may be passed through this toJS() function you should use the SkipVTableValidation |
| 271 | // attribute to SpectreGadget. |
| 272 | static_assert(!std::is_polymorphic<SpectreGadget>::value, "SpectreGadget is polymorphic but the IDL claims it is not" ); |
| 273 | return createWrapper<SpectreGadget>(globalObject, WTFMove(impl)); |
| 274 | } |
| 275 | |
| 276 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, SpectreGadget& impl) |
| 277 | { |
| 278 | return wrap(state, globalObject, impl); |
| 279 | } |
| 280 | |
| 281 | SpectreGadget* JSSpectreGadget::toWrapped(JSC::VM& vm, JSC::JSValue value) |
| 282 | { |
| 283 | if (auto* wrapper = jsDynamicCast<JSSpectreGadget*>(vm, value)) |
| 284 | return &wrapper->wrapped(); |
| 285 | return nullptr; |
| 286 | } |
| 287 | |
| 288 | } |
| 289 | |