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 "JSAbortSignal.h"
23
24#include "EventNames.h"
25#include "JSDOMAttribute.h"
26#include "JSDOMBinding.h"
27#include "JSDOMConstructorNotConstructable.h"
28#include "JSDOMConvertBoolean.h"
29#include "JSDOMExceptionHandling.h"
30#include "JSDOMWrapperCache.h"
31#include "JSEventListener.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
40namespace WebCore {
41using namespace JSC;
42
43// Attributes
44
45JSC::EncodedJSValue jsAbortSignalConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
46bool setJSAbortSignalConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
47JSC::EncodedJSValue jsAbortSignalAborted(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
48JSC::EncodedJSValue jsAbortSignalOnabort(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
49bool setJSAbortSignalOnabort(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
50
51class JSAbortSignalPrototype : public JSC::JSNonFinalObject {
52public:
53 using Base = JSC::JSNonFinalObject;
54 static JSAbortSignalPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
55 {
56 JSAbortSignalPrototype* ptr = new (NotNull, JSC::allocateCell<JSAbortSignalPrototype>(vm.heap)) JSAbortSignalPrototype(vm, globalObject, structure);
57 ptr->finishCreation(vm);
58 return ptr;
59 }
60
61 DECLARE_INFO;
62 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
63 {
64 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
65 }
66
67private:
68 JSAbortSignalPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
69 : JSC::JSNonFinalObject(vm, structure)
70 {
71 }
72
73 void finishCreation(JSC::VM&);
74};
75
76using JSAbortSignalConstructor = JSDOMConstructorNotConstructable<JSAbortSignal>;
77
78template<> JSValue JSAbortSignalConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
79{
80 return JSEventTarget::getConstructor(vm, &globalObject);
81}
82
83template<> void JSAbortSignalConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
84{
85 putDirect(vm, vm.propertyNames->prototype, JSAbortSignal::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
86 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("AbortSignal"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
87 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
88}
89
90template<> const ClassInfo JSAbortSignalConstructor::s_info = { "AbortSignal", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSAbortSignalConstructor) };
91
92/* Hash table for prototype */
93
94static const HashTableValue JSAbortSignalPrototypeTableValues[] =
95{
96 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAbortSignalConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSAbortSignalConstructor) } },
97 { "aborted", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAbortSignalAborted), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
98 { "onabort", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAbortSignalOnabort), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSAbortSignalOnabort) } },
99};
100
101const ClassInfo JSAbortSignalPrototype::s_info = { "AbortSignalPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSAbortSignalPrototype) };
102
103void JSAbortSignalPrototype::finishCreation(VM& vm)
104{
105 Base::finishCreation(vm);
106 reifyStaticProperties(vm, JSAbortSignal::info(), JSAbortSignalPrototypeTableValues, *this);
107}
108
109const ClassInfo JSAbortSignal::s_info = { "AbortSignal", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSAbortSignal) };
110
111JSAbortSignal::JSAbortSignal(Structure* structure, JSDOMGlobalObject& globalObject, Ref<AbortSignal>&& impl)
112 : JSEventTarget(structure, globalObject, WTFMove(impl))
113{
114}
115
116void JSAbortSignal::finishCreation(VM& vm)
117{
118 Base::finishCreation(vm);
119 ASSERT(inherits(vm, info()));
120
121}
122
123JSObject* JSAbortSignal::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
124{
125 return JSAbortSignalPrototype::create(vm, &globalObject, JSAbortSignalPrototype::createStructure(vm, &globalObject, JSEventTarget::prototype(vm, globalObject)));
126}
127
128JSObject* JSAbortSignal::prototype(VM& vm, JSDOMGlobalObject& globalObject)
129{
130 return getDOMPrototype<JSAbortSignal>(vm, globalObject);
131}
132
133JSValue JSAbortSignal::getConstructor(VM& vm, const JSGlobalObject* globalObject)
134{
135 return getDOMConstructor<JSAbortSignalConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
136}
137
138template<> inline JSAbortSignal* IDLAttribute<JSAbortSignal>::cast(ExecState& state, EncodedJSValue thisValue)
139{
140 return jsDynamicCast<JSAbortSignal*>(state.vm(), JSValue::decode(thisValue));
141}
142
143EncodedJSValue jsAbortSignalConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
144{
145 VM& vm = state->vm();
146 auto throwScope = DECLARE_THROW_SCOPE(vm);
147 auto* prototype = jsDynamicCast<JSAbortSignalPrototype*>(vm, JSValue::decode(thisValue));
148 if (UNLIKELY(!prototype))
149 return throwVMTypeError(state, throwScope);
150 return JSValue::encode(JSAbortSignal::getConstructor(state->vm(), prototype->globalObject()));
151}
152
153bool setJSAbortSignalConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
154{
155 VM& vm = state->vm();
156 auto throwScope = DECLARE_THROW_SCOPE(vm);
157 auto* prototype = jsDynamicCast<JSAbortSignalPrototype*>(vm, JSValue::decode(thisValue));
158 if (UNLIKELY(!prototype)) {
159 throwVMTypeError(state, throwScope);
160 return false;
161 }
162 // Shadowing a built-in constructor
163 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
164}
165
166static inline JSValue jsAbortSignalAbortedGetter(ExecState& state, JSAbortSignal& thisObject, ThrowScope& throwScope)
167{
168 UNUSED_PARAM(throwScope);
169 UNUSED_PARAM(state);
170 auto& impl = thisObject.wrapped();
171 JSValue result = toJS<IDLBoolean>(state, throwScope, impl.aborted());
172 return result;
173}
174
175EncodedJSValue jsAbortSignalAborted(ExecState* state, EncodedJSValue thisValue, PropertyName)
176{
177 return IDLAttribute<JSAbortSignal>::get<jsAbortSignalAbortedGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "aborted");
178}
179
180static inline JSValue jsAbortSignalOnabortGetter(ExecState& state, JSAbortSignal& thisObject, ThrowScope& throwScope)
181{
182 UNUSED_PARAM(throwScope);
183 UNUSED_PARAM(state);
184 return eventHandlerAttribute(thisObject.wrapped(), eventNames().abortEvent, worldForDOMObject(thisObject));
185}
186
187EncodedJSValue jsAbortSignalOnabort(ExecState* state, EncodedJSValue thisValue, PropertyName)
188{
189 return IDLAttribute<JSAbortSignal>::get<jsAbortSignalOnabortGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onabort");
190}
191
192static inline bool setJSAbortSignalOnabortSetter(ExecState& state, JSAbortSignal& thisObject, JSValue value, ThrowScope& throwScope)
193{
194 UNUSED_PARAM(throwScope);
195 setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().abortEvent, value);
196 return true;
197}
198
199bool setJSAbortSignalOnabort(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
200{
201 return IDLAttribute<JSAbortSignal>::set<setJSAbortSignalOnabortSetter>(*state, thisValue, encodedValue, "onabort");
202}
203
204void JSAbortSignal::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
205{
206 auto* thisObject = jsCast<JSAbortSignal*>(cell);
207 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
208 if (thisObject->scriptExecutionContext())
209 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
210 Base::heapSnapshot(cell, builder);
211}
212
213#if ENABLE(BINDING_INTEGRITY)
214#if PLATFORM(WIN)
215#pragma warning(disable: 4483)
216extern "C" { extern void (*const __identifier("??_7AbortSignal@WebCore@@6B@")[])(); }
217#else
218extern "C" { extern void* _ZTVN7WebCore11AbortSignalE[]; }
219#endif
220#endif
221
222JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<AbortSignal>&& impl)
223{
224
225#if ENABLE(BINDING_INTEGRITY)
226 void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
227#if PLATFORM(WIN)
228 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7AbortSignal@WebCore@@6B@"));
229#else
230 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore11AbortSignalE[2]);
231#endif
232
233 // If this fails AbortSignal does not have a vtable, so you need to add the
234 // ImplementationLacksVTable attribute to the interface definition
235 static_assert(std::is_polymorphic<AbortSignal>::value, "AbortSignal is not polymorphic");
236
237 // If you hit this assertion you either have a use after free bug, or
238 // AbortSignal has subclasses. If AbortSignal has subclasses that get passed
239 // to toJS() we currently require AbortSignal you to opt out of binding hardening
240 // by adding the SkipVTableValidation attribute to the interface IDL definition
241 RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
242#endif
243 return createWrapper<AbortSignal>(globalObject, WTFMove(impl));
244}
245
246JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, AbortSignal& impl)
247{
248 return wrap(state, globalObject, impl);
249}
250
251AbortSignal* JSAbortSignal::toWrapped(JSC::VM& vm, JSC::JSValue value)
252{
253 if (auto* wrapper = jsDynamicCast<JSAbortSignal*>(vm, value))
254 return &wrapper->wrapped();
255 return nullptr;
256}
257
258}
259