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(CSS_PAINTING_API) |
24 | |
25 | #include "JSWorklet.h" |
26 | |
27 | #include "Document.h" |
28 | #include "JSDOMBinding.h" |
29 | #include "JSDOMConstructorNotConstructable.h" |
30 | #include "JSDOMConvertStrings.h" |
31 | #include "JSDOMExceptionHandling.h" |
32 | #include "JSDOMOperation.h" |
33 | #include "JSDOMWrapperCache.h" |
34 | #include "ScriptExecutionContext.h" |
35 | #include <JavaScriptCore/FunctionPrototype.h> |
36 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
37 | #include <JavaScriptCore/JSCInlines.h> |
38 | #include <wtf/GetPtr.h> |
39 | #include <wtf/PointerPreparations.h> |
40 | #include <wtf/URL.h> |
41 | |
42 | |
43 | namespace WebCore { |
44 | using namespace JSC; |
45 | |
46 | // Functions |
47 | |
48 | JSC::EncodedJSValue JSC_HOST_CALL jsWorkletInstanceFunctionAddModule(JSC::ExecState*); |
49 | |
50 | // Attributes |
51 | |
52 | JSC::EncodedJSValue jsWorkletConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
53 | bool setJSWorkletConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
54 | |
55 | class JSWorkletPrototype : public JSC::JSNonFinalObject { |
56 | public: |
57 | using Base = JSC::JSNonFinalObject; |
58 | static JSWorkletPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
59 | { |
60 | JSWorkletPrototype* ptr = new (NotNull, JSC::allocateCell<JSWorkletPrototype>(vm.heap)) JSWorkletPrototype(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 | JSWorkletPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
73 | : JSC::JSNonFinalObject(vm, structure) |
74 | { |
75 | } |
76 | public: |
77 | static const unsigned StructureFlags = Base::StructureFlags | JSC::HasStaticPropertyTable; |
78 | }; |
79 | |
80 | using JSWorkletConstructor = JSDOMConstructorNotConstructable<JSWorklet>; |
81 | |
82 | /* Hash table */ |
83 | |
84 | static const struct CompactHashIndex JSWorkletTableIndex[2] = { |
85 | { 0, -1 }, |
86 | { -1, -1 }, |
87 | }; |
88 | |
89 | |
90 | static const HashTableValue JSWorkletTableValues[] = |
91 | { |
92 | { "addModule" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsWorkletInstanceFunctionAddModule), (intptr_t) (1) } }, |
93 | }; |
94 | |
95 | static const HashTable JSWorkletTable = { 1, 1, false, JSWorklet::info(), JSWorkletTableValues, JSWorkletTableIndex }; |
96 | template<> JSValue JSWorkletConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
97 | { |
98 | UNUSED_PARAM(vm); |
99 | return globalObject.functionPrototype(); |
100 | } |
101 | |
102 | template<> void JSWorkletConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
103 | { |
104 | putDirect(vm, vm.propertyNames->prototype, JSWorklet::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
105 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("Worklet"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
106 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
107 | } |
108 | |
109 | template<> const ClassInfo JSWorkletConstructor::s_info = { "Worklet" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWorkletConstructor) }; |
110 | |
111 | /* Hash table for prototype */ |
112 | |
113 | static const HashTableValue JSWorkletPrototypeTableValues[] = |
114 | { |
115 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsWorkletConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSWorkletConstructor) } }, |
116 | }; |
117 | |
118 | const ClassInfo JSWorkletPrototype::s_info = { "WorkletPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWorkletPrototype) }; |
119 | |
120 | const ClassInfo JSWorklet::s_info = { "Worklet" , &Base::s_info, &JSWorkletTable, nullptr, CREATE_METHOD_TABLE(JSWorklet) }; |
121 | |
122 | JSWorklet::JSWorklet(Structure* structure, JSDOMGlobalObject& globalObject, Ref<Worklet>&& impl) |
123 | : JSDOMWrapper<Worklet>(structure, globalObject, WTFMove(impl)) |
124 | { |
125 | } |
126 | |
127 | void JSWorklet::finishCreation(VM& vm) |
128 | { |
129 | Base::finishCreation(vm); |
130 | ASSERT(inherits(vm, info())); |
131 | |
132 | } |
133 | |
134 | JSObject* JSWorklet::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
135 | { |
136 | return JSWorkletPrototype::create(vm, &globalObject, JSWorkletPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
137 | } |
138 | |
139 | JSObject* JSWorklet::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
140 | { |
141 | return getDOMPrototype<JSWorklet>(vm, globalObject); |
142 | } |
143 | |
144 | JSValue JSWorklet::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
145 | { |
146 | return getDOMConstructor<JSWorkletConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
147 | } |
148 | |
149 | void JSWorklet::destroy(JSC::JSCell* cell) |
150 | { |
151 | JSWorklet* thisObject = static_cast<JSWorklet*>(cell); |
152 | thisObject->JSWorklet::~JSWorklet(); |
153 | } |
154 | |
155 | template<> inline JSWorklet* IDLOperation<JSWorklet>::cast(ExecState& state) |
156 | { |
157 | return jsDynamicCast<JSWorklet*>(state.vm(), state.thisValue()); |
158 | } |
159 | |
160 | EncodedJSValue jsWorkletConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
161 | { |
162 | VM& vm = state->vm(); |
163 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
164 | auto* prototype = jsDynamicCast<JSWorkletPrototype*>(vm, JSValue::decode(thisValue)); |
165 | if (UNLIKELY(!prototype)) |
166 | return throwVMTypeError(state, throwScope); |
167 | return JSValue::encode(JSWorklet::getConstructor(state->vm(), prototype->globalObject())); |
168 | } |
169 | |
170 | bool setJSWorkletConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
171 | { |
172 | VM& vm = state->vm(); |
173 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
174 | auto* prototype = jsDynamicCast<JSWorkletPrototype*>(vm, JSValue::decode(thisValue)); |
175 | if (UNLIKELY(!prototype)) { |
176 | throwVMTypeError(state, throwScope); |
177 | return false; |
178 | } |
179 | // Shadowing a built-in constructor |
180 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
181 | } |
182 | |
183 | static inline JSC::EncodedJSValue jsWorkletInstanceFunctionAddModuleBody(JSC::ExecState* state, typename IDLOperation<JSWorklet>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
184 | { |
185 | UNUSED_PARAM(state); |
186 | UNUSED_PARAM(throwScope); |
187 | auto& impl = castedThis->wrapped(); |
188 | if (UNLIKELY(state->argumentCount() < 1)) |
189 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
190 | auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext(); |
191 | if (UNLIKELY(!context)) |
192 | return JSValue::encode(jsUndefined()); |
193 | ASSERT(context->isDocument()); |
194 | auto& document = downcast<Document>(*context); |
195 | auto moduleURL = convert<IDLUSVString>(*state, state->uncheckedArgument(0)); |
196 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
197 | impl.addModule(document, WTFMove(moduleURL)); |
198 | return JSValue::encode(jsUndefined()); |
199 | } |
200 | |
201 | EncodedJSValue JSC_HOST_CALL jsWorkletInstanceFunctionAddModule(ExecState* state) |
202 | { |
203 | return IDLOperation<JSWorklet>::call<jsWorkletInstanceFunctionAddModuleBody>(*state, "addModule" ); |
204 | } |
205 | |
206 | void JSWorklet::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
207 | { |
208 | auto* thisObject = jsCast<JSWorklet*>(cell); |
209 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
210 | if (thisObject->scriptExecutionContext()) |
211 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
212 | Base::heapSnapshot(cell, builder); |
213 | } |
214 | |
215 | bool JSWorkletOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
216 | { |
217 | UNUSED_PARAM(handle); |
218 | UNUSED_PARAM(visitor); |
219 | UNUSED_PARAM(reason); |
220 | return false; |
221 | } |
222 | |
223 | void JSWorkletOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
224 | { |
225 | auto* jsWorklet = static_cast<JSWorklet*>(handle.slot()->asCell()); |
226 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
227 | uncacheWrapper(world, &jsWorklet->wrapped(), jsWorklet); |
228 | } |
229 | |
230 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<Worklet>&& impl) |
231 | { |
232 | // If you hit this failure the interface definition has the ImplementationLacksVTable |
233 | // attribute. You should remove that attribute. If the class has subclasses |
234 | // that may be passed through this toJS() function you should use the SkipVTableValidation |
235 | // attribute to Worklet. |
236 | static_assert(!std::is_polymorphic<Worklet>::value, "Worklet is polymorphic but the IDL claims it is not" ); |
237 | return createWrapper<Worklet>(globalObject, WTFMove(impl)); |
238 | } |
239 | |
240 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, Worklet& impl) |
241 | { |
242 | return wrap(state, globalObject, impl); |
243 | } |
244 | |
245 | Worklet* JSWorklet::toWrapped(JSC::VM& vm, JSC::JSValue value) |
246 | { |
247 | if (auto* wrapper = jsDynamicCast<JSWorklet*>(vm, value)) |
248 | return &wrapper->wrapped(); |
249 | return nullptr; |
250 | } |
251 | |
252 | } |
253 | |
254 | #endif // ENABLE(CSS_PAINTING_API) |
255 | |