/work/obj-fuzz/dom/bindings/WebGPUBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM WebGPU.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "WebGPUBinding.h" |
5 | | #include "WrapperFactory.h" |
6 | | #include "jsapi.h" |
7 | | #include "jsfriendapi.h" |
8 | | #include "mozilla/FloatingPoint.h" |
9 | | #include "mozilla/OwningNonNull.h" |
10 | | #include "mozilla/Preferences.h" |
11 | | #include "mozilla/dom/BindingUtils.h" |
12 | | #include "mozilla/dom/DOMJSClass.h" |
13 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
14 | | #include "mozilla/dom/Nullable.h" |
15 | | #include "mozilla/dom/PrimitiveConversions.h" |
16 | | #include "mozilla/dom/Promise.h" |
17 | | #include "mozilla/dom/ScriptSettings.h" |
18 | | #include "mozilla/dom/SimpleGlobalObject.h" |
19 | | #include "mozilla/dom/ToJSValue.h" |
20 | | #include "mozilla/dom/TypedArray.h" |
21 | | #include "mozilla/dom/UnionConversions.h" |
22 | | #include "mozilla/dom/XrayExpandoClass.h" |
23 | | #include "mozilla/webgpu/Adapter.h" |
24 | | #include "mozilla/webgpu/AttachmentState.h" |
25 | | #include "mozilla/webgpu/BindGroup.h" |
26 | | #include "mozilla/webgpu/BindGroupLayout.h" |
27 | | #include "mozilla/webgpu/BlendState.h" |
28 | | #include "mozilla/webgpu/Buffer.h" |
29 | | #include "mozilla/webgpu/CommandBuffer.h" |
30 | | #include "mozilla/webgpu/CommandEncoder.h" |
31 | | #include "mozilla/webgpu/ComputePipeline.h" |
32 | | #include "mozilla/webgpu/DepthStencilState.h" |
33 | | #include "mozilla/webgpu/Device.h" |
34 | | #include "mozilla/webgpu/Fence.h" |
35 | | #include "mozilla/webgpu/InputState.h" |
36 | | #include "mozilla/webgpu/Instance.h" |
37 | | #include "mozilla/webgpu/LogEntry.h" |
38 | | #include "mozilla/webgpu/PipelineLayout.h" |
39 | | #include "mozilla/webgpu/Queue.h" |
40 | | #include "mozilla/webgpu/RenderPipeline.h" |
41 | | #include "mozilla/webgpu/Sampler.h" |
42 | | #include "mozilla/webgpu/ShaderModule.h" |
43 | | #include "mozilla/webgpu/SwapChain.h" |
44 | | #include "mozilla/webgpu/Texture.h" |
45 | | #include "mozilla/webgpu/TextureView.h" |
46 | | |
47 | | namespace mozilla { |
48 | | namespace dom { |
49 | | |
50 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
51 | | using namespace mozilla::dom::binding_detail; |
52 | | |
53 | | |
54 | | namespace WebGPULogEntryTypeValues { |
55 | | extern const EnumEntry strings[4] = { |
56 | | {"device-lost", 11}, |
57 | | {"validation-error", 16}, |
58 | | {"recoverable-out-of-memory", 25}, |
59 | | { nullptr, 0 } |
60 | | }; |
61 | | } // namespace WebGPULogEntryTypeValues |
62 | | |
63 | | bool |
64 | | ToJSValue(JSContext* aCx, WebGPULogEntryType aArgument, JS::MutableHandle<JS::Value> aValue) |
65 | 0 | { |
66 | 0 | MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(WebGPULogEntryTypeValues::strings)); |
67 | 0 | JSString* resultStr = |
68 | 0 | JS_NewStringCopyN(aCx, WebGPULogEntryTypeValues::strings[uint32_t(aArgument)].value, |
69 | 0 | WebGPULogEntryTypeValues::strings[uint32_t(aArgument)].length); |
70 | 0 | if (!resultStr) { |
71 | 0 | return false; |
72 | 0 | } |
73 | 0 | aValue.setString(resultStr); |
74 | 0 | return true; |
75 | 0 | } |
76 | | |
77 | | |
78 | | namespace WebGPUObjectStatusValues { |
79 | | extern const EnumEntry strings[4] = { |
80 | | {"valid", 5}, |
81 | | {"out-of-memory", 13}, |
82 | | {"invalid", 7}, |
83 | | { nullptr, 0 } |
84 | | }; |
85 | | } // namespace WebGPUObjectStatusValues |
86 | | |
87 | | bool |
88 | | ToJSValue(JSContext* aCx, WebGPUObjectStatus aArgument, JS::MutableHandle<JS::Value> aValue) |
89 | 0 | { |
90 | 0 | MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(WebGPUObjectStatusValues::strings)); |
91 | 0 | JSString* resultStr = |
92 | 0 | JS_NewStringCopyN(aCx, WebGPUObjectStatusValues::strings[uint32_t(aArgument)].value, |
93 | 0 | WebGPUObjectStatusValues::strings[uint32_t(aArgument)].length); |
94 | 0 | if (!resultStr) { |
95 | 0 | return false; |
96 | 0 | } |
97 | 0 | aValue.setString(resultStr); |
98 | 0 | return true; |
99 | 0 | } |
100 | | |
101 | | |
102 | | namespace WebGPUPowerPreferenceValues { |
103 | | extern const EnumEntry strings[4] = { |
104 | | {"default", 7}, |
105 | | {"low-power", 9}, |
106 | | {"high-performance", 16}, |
107 | | { nullptr, 0 } |
108 | | }; |
109 | | } // namespace WebGPUPowerPreferenceValues |
110 | | |
111 | | bool |
112 | | ToJSValue(JSContext* aCx, WebGPUPowerPreference aArgument, JS::MutableHandle<JS::Value> aValue) |
113 | 0 | { |
114 | 0 | MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(WebGPUPowerPreferenceValues::strings)); |
115 | 0 | JSString* resultStr = |
116 | 0 | JS_NewStringCopyN(aCx, WebGPUPowerPreferenceValues::strings[uint32_t(aArgument)].value, |
117 | 0 | WebGPUPowerPreferenceValues::strings[uint32_t(aArgument)].length); |
118 | 0 | if (!resultStr) { |
119 | 0 | return false; |
120 | 0 | } |
121 | 0 | aValue.setString(resultStr); |
122 | 0 | return true; |
123 | 0 | } |
124 | | |
125 | | |
126 | | void |
127 | | ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningWebGPUBufferOrWebGPUTexture& aUnion, const char* aName, uint32_t aFlags) |
128 | 0 | { |
129 | 0 | if (aUnion.IsWebGPUBuffer()) { |
130 | 0 | ImplCycleCollectionTraverse(aCallback, aUnion.GetAsWebGPUBuffer(), "mWebGPUBuffer", aFlags); |
131 | 0 | } else if (aUnion.IsWebGPUTexture()) { |
132 | 0 | ImplCycleCollectionTraverse(aCallback, aUnion.GetAsWebGPUTexture(), "mWebGPUTexture", aFlags); |
133 | 0 | } |
134 | 0 | } |
135 | | |
136 | | |
137 | | void |
138 | | ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningWebGPUComputePipelineOrWebGPURenderPipeline& aUnion, const char* aName, uint32_t aFlags) |
139 | 0 | { |
140 | 0 | if (aUnion.IsWebGPUComputePipeline()) { |
141 | 0 | ImplCycleCollectionTraverse(aCallback, aUnion.GetAsWebGPUComputePipeline(), "mWebGPUComputePipeline", aFlags); |
142 | 0 | } else if (aUnion.IsWebGPURenderPipeline()) { |
143 | 0 | ImplCycleCollectionTraverse(aCallback, aUnion.GetAsWebGPURenderPipeline(), "mWebGPURenderPipeline", aFlags); |
144 | 0 | } |
145 | 0 | } |
146 | | |
147 | | |
148 | | void |
149 | | ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding& aUnion, const char* aName, uint32_t aFlags) |
150 | 0 | { |
151 | 0 | if (aUnion.IsWebGPUSampler()) { |
152 | 0 | ImplCycleCollectionTraverse(aCallback, aUnion.GetAsWebGPUSampler(), "mWebGPUSampler", aFlags); |
153 | 0 | } else if (aUnion.IsWebGPUTextureView()) { |
154 | 0 | ImplCycleCollectionTraverse(aCallback, aUnion.GetAsWebGPUTextureView(), "mWebGPUTextureView", aFlags); |
155 | 0 | } else if (aUnion.IsWebGPUBufferBinding()) { |
156 | 0 | ImplCycleCollectionTraverse(aCallback, aUnion.GetAsWebGPUBufferBinding(), "mWebGPUBufferBinding", aFlags); |
157 | 0 | } |
158 | 0 | } |
159 | | |
160 | | |
161 | | void |
162 | | ImplCycleCollectionUnlink(OwningWebGPUBufferOrWebGPUTexture& aUnion) |
163 | 0 | { |
164 | 0 | aUnion.Uninit(); |
165 | 0 | } |
166 | | |
167 | | |
168 | | void |
169 | | ImplCycleCollectionUnlink(OwningWebGPUComputePipelineOrWebGPURenderPipeline& aUnion) |
170 | 0 | { |
171 | 0 | aUnion.Uninit(); |
172 | 0 | } |
173 | | |
174 | | |
175 | | void |
176 | | ImplCycleCollectionUnlink(OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding& aUnion) |
177 | 0 | { |
178 | 0 | aUnion.Uninit(); |
179 | 0 | } |
180 | | |
181 | | |
182 | | |
183 | | WebGPUAdapterDescriptor::WebGPUAdapterDescriptor() |
184 | 0 | { |
185 | 0 | // Safe to pass a null context if we pass a null value |
186 | 0 | Init(nullptr, JS::NullHandleValue); |
187 | 0 | } |
188 | | |
189 | | |
190 | | |
191 | | bool |
192 | | WebGPUAdapterDescriptor::InitIds(JSContext* cx, WebGPUAdapterDescriptorAtoms* atomsCache) |
193 | 0 | { |
194 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
195 | 0 |
|
196 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
197 | 0 | // uninitialized. |
198 | 0 | if (!atomsCache->powerPreference_id.init(cx, "powerPreference")) { |
199 | 0 | return false; |
200 | 0 | } |
201 | 0 | return true; |
202 | 0 | } |
203 | | |
204 | | bool |
205 | | WebGPUAdapterDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
206 | 0 | { |
207 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
208 | 0 | // Since in that case we will not have to do any property gets |
209 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
210 | 0 | // checkers by static analysis tools |
211 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
212 | 0 | WebGPUAdapterDescriptorAtoms* atomsCache = nullptr; |
213 | 0 | if (cx) { |
214 | 0 | atomsCache = GetAtomCache<WebGPUAdapterDescriptorAtoms>(cx); |
215 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
216 | 0 | return false; |
217 | 0 | } |
218 | 0 | } |
219 | 0 | |
220 | 0 | if (!IsConvertibleToDictionary(val)) { |
221 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
222 | 0 | } |
223 | 0 | |
224 | 0 | bool isNull = val.isNullOrUndefined(); |
225 | 0 | // We only need these if !isNull, in which case we have |cx|. |
226 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
227 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
228 | 0 | if (!isNull) { |
229 | 0 | MOZ_ASSERT(cx); |
230 | 0 | object.emplace(cx, &val.toObject()); |
231 | 0 | temp.emplace(cx); |
232 | 0 | } |
233 | 0 | if (!isNull) { |
234 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->powerPreference_id, temp.ptr())) { |
235 | 0 | return false; |
236 | 0 | } |
237 | 0 | } |
238 | 0 | if (!isNull && !temp->isUndefined()) { |
239 | 0 | mPowerPreference.Construct(); |
240 | 0 | { |
241 | 0 | int index; |
242 | 0 | if (!FindEnumStringIndex<true>(cx, temp.ref(), WebGPUPowerPreferenceValues::strings, "WebGPUPowerPreference", "'powerPreference' member of WebGPUAdapterDescriptor", &index)) { |
243 | 0 | return false; |
244 | 0 | } |
245 | 0 | MOZ_ASSERT(index >= 0); |
246 | 0 | (mPowerPreference.Value()) = static_cast<WebGPUPowerPreference>(index); |
247 | 0 | } |
248 | 0 | mIsAnyMemberPresent = true; |
249 | 0 | } |
250 | 0 | return true; |
251 | 0 | } |
252 | | |
253 | | bool |
254 | | WebGPUAdapterDescriptor::Init(const nsAString& aJSON) |
255 | 0 | { |
256 | 0 | AutoJSAPI jsapi; |
257 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
258 | 0 | if (!cleanGlobal) { |
259 | 0 | return false; |
260 | 0 | } |
261 | 0 | if (!jsapi.Init(cleanGlobal)) { |
262 | 0 | return false; |
263 | 0 | } |
264 | 0 | JSContext* cx = jsapi.cx(); |
265 | 0 | JS::Rooted<JS::Value> json(cx); |
266 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
267 | 0 | NS_ENSURE_TRUE(ok, false); |
268 | 0 | return Init(cx, json); |
269 | 0 | } |
270 | | |
271 | | bool |
272 | | WebGPUAdapterDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
273 | 0 | { |
274 | 0 | WebGPUAdapterDescriptorAtoms* atomsCache = GetAtomCache<WebGPUAdapterDescriptorAtoms>(cx); |
275 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
276 | 0 | return false; |
277 | 0 | } |
278 | 0 | |
279 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
280 | 0 | if (!obj) { |
281 | 0 | return false; |
282 | 0 | } |
283 | 0 | rval.set(JS::ObjectValue(*obj)); |
284 | 0 |
|
285 | 0 | if (mPowerPreference.WasPassed()) { |
286 | 0 | do { |
287 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
288 | 0 | JS::Rooted<JS::Value> temp(cx); |
289 | 0 | WebGPUPowerPreference const & currentValue = mPowerPreference.InternalValue(); |
290 | 0 | if (!ToJSValue(cx, currentValue, &temp)) { |
291 | 0 | return false; |
292 | 0 | } |
293 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->powerPreference_id, temp, JSPROP_ENUMERATE)) { |
294 | 0 | return false; |
295 | 0 | } |
296 | 0 | break; |
297 | 0 | } while(false); |
298 | 0 | } |
299 | 0 |
|
300 | 0 | return true; |
301 | 0 | } |
302 | | |
303 | | bool |
304 | | WebGPUAdapterDescriptor::ToJSON(nsAString& aJSON) const |
305 | 0 | { |
306 | 0 | AutoJSAPI jsapi; |
307 | 0 | jsapi.Init(); |
308 | 0 | JSContext *cx = jsapi.cx(); |
309 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
310 | 0 | // because we'll only be creating objects, in ways that have no |
311 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
312 | 0 | // which likewise guarantees no side-effects for the sorts of |
313 | 0 | // things we will pass it. |
314 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
315 | 0 | JS::Rooted<JS::Value> val(cx); |
316 | 0 | if (!ToObjectInternal(cx, &val)) { |
317 | 0 | return false; |
318 | 0 | } |
319 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
320 | 0 | return StringifyToJSON(cx, obj, aJSON); |
321 | 0 | } |
322 | | |
323 | | void |
324 | | WebGPUAdapterDescriptor::TraceDictionary(JSTracer* trc) |
325 | 0 | { |
326 | 0 | } |
327 | | |
328 | | WebGPUAdapterDescriptor& |
329 | | WebGPUAdapterDescriptor::operator=(const WebGPUAdapterDescriptor& aOther) |
330 | 0 | { |
331 | 0 | DictionaryBase::operator=(aOther); |
332 | 0 | mPowerPreference.Reset(); |
333 | 0 | if (aOther.mPowerPreference.WasPassed()) { |
334 | 0 | mPowerPreference.Construct(aOther.mPowerPreference.Value()); |
335 | 0 | } |
336 | 0 | return *this; |
337 | 0 | } |
338 | | |
339 | | namespace binding_detail { |
340 | | } // namespace binding_detail |
341 | | |
342 | | |
343 | | |
344 | | WebGPUAttachmentStateDescriptor::WebGPUAttachmentStateDescriptor() |
345 | 0 | { |
346 | 0 | // Safe to pass a null context if we pass a null value |
347 | 0 | Init(nullptr, JS::NullHandleValue); |
348 | 0 | } |
349 | | |
350 | | |
351 | | |
352 | | bool |
353 | | WebGPUAttachmentStateDescriptor::InitIds(JSContext* cx, WebGPUAttachmentStateDescriptorAtoms* atomsCache) |
354 | 0 | { |
355 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
356 | 0 |
|
357 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
358 | 0 | // uninitialized. |
359 | 0 | if (!atomsCache->formats_id.init(cx, "formats")) { |
360 | 0 | return false; |
361 | 0 | } |
362 | 0 | return true; |
363 | 0 | } |
364 | | |
365 | | bool |
366 | | WebGPUAttachmentStateDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
367 | 0 | { |
368 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
369 | 0 | // Since in that case we will not have to do any property gets |
370 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
371 | 0 | // checkers by static analysis tools |
372 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
373 | 0 | WebGPUAttachmentStateDescriptorAtoms* atomsCache = nullptr; |
374 | 0 | if (cx) { |
375 | 0 | atomsCache = GetAtomCache<WebGPUAttachmentStateDescriptorAtoms>(cx); |
376 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
377 | 0 | return false; |
378 | 0 | } |
379 | 0 | } |
380 | 0 | |
381 | 0 | if (!IsConvertibleToDictionary(val)) { |
382 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
383 | 0 | } |
384 | 0 | |
385 | 0 | bool isNull = val.isNullOrUndefined(); |
386 | 0 | // We only need these if !isNull, in which case we have |cx|. |
387 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
388 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
389 | 0 | if (!isNull) { |
390 | 0 | MOZ_ASSERT(cx); |
391 | 0 | object.emplace(cx, &val.toObject()); |
392 | 0 | temp.emplace(cx); |
393 | 0 | } |
394 | 0 | if (!isNull) { |
395 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->formats_id, temp.ptr())) { |
396 | 0 | return false; |
397 | 0 | } |
398 | 0 | } |
399 | 0 | if (!isNull && !temp->isUndefined()) { |
400 | 0 | mFormats.Construct(); |
401 | 0 | if (temp.ref().isObject()) { |
402 | 0 | JS::ForOfIterator iter(cx); |
403 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
404 | 0 | return false; |
405 | 0 | } |
406 | 0 | if (!iter.valueIsIterable()) { |
407 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'formats' member of WebGPUAttachmentStateDescriptor"); |
408 | 0 | return false; |
409 | 0 | } |
410 | 0 | Sequence<uint32_t> &arr = (mFormats.Value()); |
411 | 0 | JS::Rooted<JS::Value> temp(cx); |
412 | 0 | while (true) { |
413 | 0 | bool done; |
414 | 0 | if (!iter.next(&temp, &done)) { |
415 | 0 | return false; |
416 | 0 | } |
417 | 0 | if (done) { |
418 | 0 | break; |
419 | 0 | } |
420 | 0 | uint32_t* slotPtr = arr.AppendElement(mozilla::fallible); |
421 | 0 | if (!slotPtr) { |
422 | 0 | JS_ReportOutOfMemory(cx); |
423 | 0 | return false; |
424 | 0 | } |
425 | 0 | uint32_t& slot = *slotPtr; |
426 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp, &slot)) { |
427 | 0 | return false; |
428 | 0 | } |
429 | 0 | } |
430 | 0 | } else { |
431 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'formats' member of WebGPUAttachmentStateDescriptor"); |
432 | 0 | return false; |
433 | 0 | } |
434 | 0 | mIsAnyMemberPresent = true; |
435 | 0 | } |
436 | 0 | return true; |
437 | 0 | } |
438 | | |
439 | | bool |
440 | | WebGPUAttachmentStateDescriptor::Init(const nsAString& aJSON) |
441 | 0 | { |
442 | 0 | AutoJSAPI jsapi; |
443 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
444 | 0 | if (!cleanGlobal) { |
445 | 0 | return false; |
446 | 0 | } |
447 | 0 | if (!jsapi.Init(cleanGlobal)) { |
448 | 0 | return false; |
449 | 0 | } |
450 | 0 | JSContext* cx = jsapi.cx(); |
451 | 0 | JS::Rooted<JS::Value> json(cx); |
452 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
453 | 0 | NS_ENSURE_TRUE(ok, false); |
454 | 0 | return Init(cx, json); |
455 | 0 | } |
456 | | |
457 | | bool |
458 | | WebGPUAttachmentStateDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
459 | 0 | { |
460 | 0 | WebGPUAttachmentStateDescriptorAtoms* atomsCache = GetAtomCache<WebGPUAttachmentStateDescriptorAtoms>(cx); |
461 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
462 | 0 | return false; |
463 | 0 | } |
464 | 0 | |
465 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
466 | 0 | if (!obj) { |
467 | 0 | return false; |
468 | 0 | } |
469 | 0 | rval.set(JS::ObjectValue(*obj)); |
470 | 0 |
|
471 | 0 | if (mFormats.WasPassed()) { |
472 | 0 | do { |
473 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
474 | 0 | JS::Rooted<JS::Value> temp(cx); |
475 | 0 | Sequence<uint32_t> const & currentValue = mFormats.InternalValue(); |
476 | 0 |
|
477 | 0 | uint32_t length = currentValue.Length(); |
478 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
479 | 0 | if (!returnArray) { |
480 | 0 | return false; |
481 | 0 | } |
482 | 0 | // Scope for 'tmp' |
483 | 0 | { |
484 | 0 | JS::Rooted<JS::Value> tmp(cx); |
485 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
486 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
487 | 0 | // are different ways to succeed at wrapping the object. |
488 | 0 | do { |
489 | 0 | tmp.setNumber(currentValue[sequenceIdx0]); |
490 | 0 | break; |
491 | 0 | } while (false); |
492 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
493 | 0 | JSPROP_ENUMERATE)) { |
494 | 0 | return false; |
495 | 0 | } |
496 | 0 | } |
497 | 0 | } |
498 | 0 | temp.setObject(*returnArray); |
499 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->formats_id, temp, JSPROP_ENUMERATE)) { |
500 | 0 | return false; |
501 | 0 | } |
502 | 0 | break; |
503 | 0 | } while(false); |
504 | 0 | } |
505 | 0 |
|
506 | 0 | return true; |
507 | 0 | } |
508 | | |
509 | | bool |
510 | | WebGPUAttachmentStateDescriptor::ToJSON(nsAString& aJSON) const |
511 | 0 | { |
512 | 0 | AutoJSAPI jsapi; |
513 | 0 | jsapi.Init(); |
514 | 0 | JSContext *cx = jsapi.cx(); |
515 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
516 | 0 | // because we'll only be creating objects, in ways that have no |
517 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
518 | 0 | // which likewise guarantees no side-effects for the sorts of |
519 | 0 | // things we will pass it. |
520 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
521 | 0 | JS::Rooted<JS::Value> val(cx); |
522 | 0 | if (!ToObjectInternal(cx, &val)) { |
523 | 0 | return false; |
524 | 0 | } |
525 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
526 | 0 | return StringifyToJSON(cx, obj, aJSON); |
527 | 0 | } |
528 | | |
529 | | void |
530 | | WebGPUAttachmentStateDescriptor::TraceDictionary(JSTracer* trc) |
531 | 0 | { |
532 | 0 | } |
533 | | |
534 | | WebGPUAttachmentStateDescriptor& |
535 | | WebGPUAttachmentStateDescriptor::operator=(const WebGPUAttachmentStateDescriptor& aOther) |
536 | 0 | { |
537 | 0 | DictionaryBase::operator=(aOther); |
538 | 0 | mFormats.Reset(); |
539 | 0 | if (aOther.mFormats.WasPassed()) { |
540 | 0 | mFormats.Construct(aOther.mFormats.Value()); |
541 | 0 | } |
542 | 0 | return *this; |
543 | 0 | } |
544 | | |
545 | | namespace binding_detail { |
546 | | } // namespace binding_detail |
547 | | |
548 | | |
549 | | |
550 | | WebGPUBindGroupBinding::WebGPUBindGroupBinding() |
551 | 0 | { |
552 | 0 | // Safe to pass a null context if we pass a null value |
553 | 0 | Init(nullptr, JS::NullHandleValue); |
554 | 0 | } |
555 | | |
556 | | |
557 | | |
558 | | bool |
559 | | WebGPUBindGroupBinding::InitIds(JSContext* cx, WebGPUBindGroupBindingAtoms* atomsCache) |
560 | 0 | { |
561 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
562 | 0 |
|
563 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
564 | 0 | // uninitialized. |
565 | 0 | if (!atomsCache->visibility_id.init(cx, "visibility") || |
566 | 0 | !atomsCache->type_id.init(cx, "type") || |
567 | 0 | !atomsCache->start_id.init(cx, "start") || |
568 | 0 | !atomsCache->count_id.init(cx, "count")) { |
569 | 0 | return false; |
570 | 0 | } |
571 | 0 | return true; |
572 | 0 | } |
573 | | |
574 | | bool |
575 | | WebGPUBindGroupBinding::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
576 | 0 | { |
577 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
578 | 0 | // Since in that case we will not have to do any property gets |
579 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
580 | 0 | // checkers by static analysis tools |
581 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
582 | 0 | WebGPUBindGroupBindingAtoms* atomsCache = nullptr; |
583 | 0 | if (cx) { |
584 | 0 | atomsCache = GetAtomCache<WebGPUBindGroupBindingAtoms>(cx); |
585 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
586 | 0 | return false; |
587 | 0 | } |
588 | 0 | } |
589 | 0 | |
590 | 0 | if (!IsConvertibleToDictionary(val)) { |
591 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
592 | 0 | } |
593 | 0 | |
594 | 0 | bool isNull = val.isNullOrUndefined(); |
595 | 0 | // We only need these if !isNull, in which case we have |cx|. |
596 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
597 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
598 | 0 | if (!isNull) { |
599 | 0 | MOZ_ASSERT(cx); |
600 | 0 | object.emplace(cx, &val.toObject()); |
601 | 0 | temp.emplace(cx); |
602 | 0 | } |
603 | 0 | if (!isNull) { |
604 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->count_id, temp.ptr())) { |
605 | 0 | return false; |
606 | 0 | } |
607 | 0 | } |
608 | 0 | if (!isNull && !temp->isUndefined()) { |
609 | 0 | mCount.Construct(); |
610 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mCount.Value()))) { |
611 | 0 | return false; |
612 | 0 | } |
613 | 0 | mIsAnyMemberPresent = true; |
614 | 0 | } |
615 | 0 |
|
616 | 0 | if (!isNull) { |
617 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->start_id, temp.ptr())) { |
618 | 0 | return false; |
619 | 0 | } |
620 | 0 | } |
621 | 0 | if (!isNull && !temp->isUndefined()) { |
622 | 0 | mStart.Construct(); |
623 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mStart.Value()))) { |
624 | 0 | return false; |
625 | 0 | } |
626 | 0 | mIsAnyMemberPresent = true; |
627 | 0 | } |
628 | 0 |
|
629 | 0 | if (!isNull) { |
630 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->type_id, temp.ptr())) { |
631 | 0 | return false; |
632 | 0 | } |
633 | 0 | } |
634 | 0 | if (!isNull && !temp->isUndefined()) { |
635 | 0 | mType.Construct(); |
636 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mType.Value()))) { |
637 | 0 | return false; |
638 | 0 | } |
639 | 0 | mIsAnyMemberPresent = true; |
640 | 0 | } |
641 | 0 |
|
642 | 0 | if (!isNull) { |
643 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->visibility_id, temp.ptr())) { |
644 | 0 | return false; |
645 | 0 | } |
646 | 0 | } |
647 | 0 | if (!isNull && !temp->isUndefined()) { |
648 | 0 | mVisibility.Construct(); |
649 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mVisibility.Value()))) { |
650 | 0 | return false; |
651 | 0 | } |
652 | 0 | mIsAnyMemberPresent = true; |
653 | 0 | } |
654 | 0 | return true; |
655 | 0 | } |
656 | | |
657 | | bool |
658 | | WebGPUBindGroupBinding::Init(const nsAString& aJSON) |
659 | 0 | { |
660 | 0 | AutoJSAPI jsapi; |
661 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
662 | 0 | if (!cleanGlobal) { |
663 | 0 | return false; |
664 | 0 | } |
665 | 0 | if (!jsapi.Init(cleanGlobal)) { |
666 | 0 | return false; |
667 | 0 | } |
668 | 0 | JSContext* cx = jsapi.cx(); |
669 | 0 | JS::Rooted<JS::Value> json(cx); |
670 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
671 | 0 | NS_ENSURE_TRUE(ok, false); |
672 | 0 | return Init(cx, json); |
673 | 0 | } |
674 | | |
675 | | bool |
676 | | WebGPUBindGroupBinding::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
677 | 0 | { |
678 | 0 | WebGPUBindGroupBindingAtoms* atomsCache = GetAtomCache<WebGPUBindGroupBindingAtoms>(cx); |
679 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
680 | 0 | return false; |
681 | 0 | } |
682 | 0 | |
683 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
684 | 0 | if (!obj) { |
685 | 0 | return false; |
686 | 0 | } |
687 | 0 | rval.set(JS::ObjectValue(*obj)); |
688 | 0 |
|
689 | 0 | if (mCount.WasPassed()) { |
690 | 0 | do { |
691 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
692 | 0 | JS::Rooted<JS::Value> temp(cx); |
693 | 0 | uint32_t const & currentValue = mCount.InternalValue(); |
694 | 0 | temp.setNumber(currentValue); |
695 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->count_id, temp, JSPROP_ENUMERATE)) { |
696 | 0 | return false; |
697 | 0 | } |
698 | 0 | break; |
699 | 0 | } while(false); |
700 | 0 | } |
701 | 0 |
|
702 | 0 | if (mStart.WasPassed()) { |
703 | 0 | do { |
704 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
705 | 0 | JS::Rooted<JS::Value> temp(cx); |
706 | 0 | uint32_t const & currentValue = mStart.InternalValue(); |
707 | 0 | temp.setNumber(currentValue); |
708 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->start_id, temp, JSPROP_ENUMERATE)) { |
709 | 0 | return false; |
710 | 0 | } |
711 | 0 | break; |
712 | 0 | } while(false); |
713 | 0 | } |
714 | 0 |
|
715 | 0 | if (mType.WasPassed()) { |
716 | 0 | do { |
717 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
718 | 0 | JS::Rooted<JS::Value> temp(cx); |
719 | 0 | uint32_t const & currentValue = mType.InternalValue(); |
720 | 0 | temp.setNumber(currentValue); |
721 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->type_id, temp, JSPROP_ENUMERATE)) { |
722 | 0 | return false; |
723 | 0 | } |
724 | 0 | break; |
725 | 0 | } while(false); |
726 | 0 | } |
727 | 0 |
|
728 | 0 | if (mVisibility.WasPassed()) { |
729 | 0 | do { |
730 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
731 | 0 | JS::Rooted<JS::Value> temp(cx); |
732 | 0 | uint32_t const & currentValue = mVisibility.InternalValue(); |
733 | 0 | temp.setNumber(currentValue); |
734 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->visibility_id, temp, JSPROP_ENUMERATE)) { |
735 | 0 | return false; |
736 | 0 | } |
737 | 0 | break; |
738 | 0 | } while(false); |
739 | 0 | } |
740 | 0 |
|
741 | 0 | return true; |
742 | 0 | } |
743 | | |
744 | | bool |
745 | | WebGPUBindGroupBinding::ToJSON(nsAString& aJSON) const |
746 | 0 | { |
747 | 0 | AutoJSAPI jsapi; |
748 | 0 | jsapi.Init(); |
749 | 0 | JSContext *cx = jsapi.cx(); |
750 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
751 | 0 | // because we'll only be creating objects, in ways that have no |
752 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
753 | 0 | // which likewise guarantees no side-effects for the sorts of |
754 | 0 | // things we will pass it. |
755 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
756 | 0 | JS::Rooted<JS::Value> val(cx); |
757 | 0 | if (!ToObjectInternal(cx, &val)) { |
758 | 0 | return false; |
759 | 0 | } |
760 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
761 | 0 | return StringifyToJSON(cx, obj, aJSON); |
762 | 0 | } |
763 | | |
764 | | void |
765 | | WebGPUBindGroupBinding::TraceDictionary(JSTracer* trc) |
766 | 0 | { |
767 | 0 | } |
768 | | |
769 | | WebGPUBindGroupBinding& |
770 | | WebGPUBindGroupBinding::operator=(const WebGPUBindGroupBinding& aOther) |
771 | 0 | { |
772 | 0 | DictionaryBase::operator=(aOther); |
773 | 0 | mCount.Reset(); |
774 | 0 | if (aOther.mCount.WasPassed()) { |
775 | 0 | mCount.Construct(aOther.mCount.Value()); |
776 | 0 | } |
777 | 0 | mStart.Reset(); |
778 | 0 | if (aOther.mStart.WasPassed()) { |
779 | 0 | mStart.Construct(aOther.mStart.Value()); |
780 | 0 | } |
781 | 0 | mType.Reset(); |
782 | 0 | if (aOther.mType.WasPassed()) { |
783 | 0 | mType.Construct(aOther.mType.Value()); |
784 | 0 | } |
785 | 0 | mVisibility.Reset(); |
786 | 0 | if (aOther.mVisibility.WasPassed()) { |
787 | 0 | mVisibility.Construct(aOther.mVisibility.Value()); |
788 | 0 | } |
789 | 0 | return *this; |
790 | 0 | } |
791 | | |
792 | | namespace binding_detail { |
793 | | } // namespace binding_detail |
794 | | |
795 | | |
796 | | |
797 | | WebGPUBlendDescriptor::WebGPUBlendDescriptor() |
798 | 0 | { |
799 | 0 | // Safe to pass a null context if we pass a null value |
800 | 0 | Init(nullptr, JS::NullHandleValue); |
801 | 0 | } |
802 | | |
803 | | |
804 | | |
805 | | bool |
806 | | WebGPUBlendDescriptor::InitIds(JSContext* cx, WebGPUBlendDescriptorAtoms* atomsCache) |
807 | 0 | { |
808 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
809 | 0 |
|
810 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
811 | 0 | // uninitialized. |
812 | 0 | if (!atomsCache->srcFactor_id.init(cx, "srcFactor") || |
813 | 0 | !atomsCache->operation_id.init(cx, "operation") || |
814 | 0 | !atomsCache->dstFactor_id.init(cx, "dstFactor")) { |
815 | 0 | return false; |
816 | 0 | } |
817 | 0 | return true; |
818 | 0 | } |
819 | | |
820 | | bool |
821 | | WebGPUBlendDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
822 | 0 | { |
823 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
824 | 0 | // Since in that case we will not have to do any property gets |
825 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
826 | 0 | // checkers by static analysis tools |
827 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
828 | 0 | WebGPUBlendDescriptorAtoms* atomsCache = nullptr; |
829 | 0 | if (cx) { |
830 | 0 | atomsCache = GetAtomCache<WebGPUBlendDescriptorAtoms>(cx); |
831 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
832 | 0 | return false; |
833 | 0 | } |
834 | 0 | } |
835 | 0 | |
836 | 0 | if (!IsConvertibleToDictionary(val)) { |
837 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
838 | 0 | } |
839 | 0 | |
840 | 0 | bool isNull = val.isNullOrUndefined(); |
841 | 0 | // We only need these if !isNull, in which case we have |cx|. |
842 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
843 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
844 | 0 | if (!isNull) { |
845 | 0 | MOZ_ASSERT(cx); |
846 | 0 | object.emplace(cx, &val.toObject()); |
847 | 0 | temp.emplace(cx); |
848 | 0 | } |
849 | 0 | if (!isNull) { |
850 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->dstFactor_id, temp.ptr())) { |
851 | 0 | return false; |
852 | 0 | } |
853 | 0 | } |
854 | 0 | if (!isNull && !temp->isUndefined()) { |
855 | 0 | mDstFactor.Construct(); |
856 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mDstFactor.Value()))) { |
857 | 0 | return false; |
858 | 0 | } |
859 | 0 | mIsAnyMemberPresent = true; |
860 | 0 | } |
861 | 0 |
|
862 | 0 | if (!isNull) { |
863 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->operation_id, temp.ptr())) { |
864 | 0 | return false; |
865 | 0 | } |
866 | 0 | } |
867 | 0 | if (!isNull && !temp->isUndefined()) { |
868 | 0 | mOperation.Construct(); |
869 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mOperation.Value()))) { |
870 | 0 | return false; |
871 | 0 | } |
872 | 0 | mIsAnyMemberPresent = true; |
873 | 0 | } |
874 | 0 |
|
875 | 0 | if (!isNull) { |
876 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->srcFactor_id, temp.ptr())) { |
877 | 0 | return false; |
878 | 0 | } |
879 | 0 | } |
880 | 0 | if (!isNull && !temp->isUndefined()) { |
881 | 0 | mSrcFactor.Construct(); |
882 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mSrcFactor.Value()))) { |
883 | 0 | return false; |
884 | 0 | } |
885 | 0 | mIsAnyMemberPresent = true; |
886 | 0 | } |
887 | 0 | return true; |
888 | 0 | } |
889 | | |
890 | | bool |
891 | | WebGPUBlendDescriptor::Init(const nsAString& aJSON) |
892 | 0 | { |
893 | 0 | AutoJSAPI jsapi; |
894 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
895 | 0 | if (!cleanGlobal) { |
896 | 0 | return false; |
897 | 0 | } |
898 | 0 | if (!jsapi.Init(cleanGlobal)) { |
899 | 0 | return false; |
900 | 0 | } |
901 | 0 | JSContext* cx = jsapi.cx(); |
902 | 0 | JS::Rooted<JS::Value> json(cx); |
903 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
904 | 0 | NS_ENSURE_TRUE(ok, false); |
905 | 0 | return Init(cx, json); |
906 | 0 | } |
907 | | |
908 | | bool |
909 | | WebGPUBlendDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
910 | 0 | { |
911 | 0 | WebGPUBlendDescriptorAtoms* atomsCache = GetAtomCache<WebGPUBlendDescriptorAtoms>(cx); |
912 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
913 | 0 | return false; |
914 | 0 | } |
915 | 0 | |
916 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
917 | 0 | if (!obj) { |
918 | 0 | return false; |
919 | 0 | } |
920 | 0 | rval.set(JS::ObjectValue(*obj)); |
921 | 0 |
|
922 | 0 | if (mDstFactor.WasPassed()) { |
923 | 0 | do { |
924 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
925 | 0 | JS::Rooted<JS::Value> temp(cx); |
926 | 0 | uint32_t const & currentValue = mDstFactor.InternalValue(); |
927 | 0 | temp.setNumber(currentValue); |
928 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->dstFactor_id, temp, JSPROP_ENUMERATE)) { |
929 | 0 | return false; |
930 | 0 | } |
931 | 0 | break; |
932 | 0 | } while(false); |
933 | 0 | } |
934 | 0 |
|
935 | 0 | if (mOperation.WasPassed()) { |
936 | 0 | do { |
937 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
938 | 0 | JS::Rooted<JS::Value> temp(cx); |
939 | 0 | uint32_t const & currentValue = mOperation.InternalValue(); |
940 | 0 | temp.setNumber(currentValue); |
941 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->operation_id, temp, JSPROP_ENUMERATE)) { |
942 | 0 | return false; |
943 | 0 | } |
944 | 0 | break; |
945 | 0 | } while(false); |
946 | 0 | } |
947 | 0 |
|
948 | 0 | if (mSrcFactor.WasPassed()) { |
949 | 0 | do { |
950 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
951 | 0 | JS::Rooted<JS::Value> temp(cx); |
952 | 0 | uint32_t const & currentValue = mSrcFactor.InternalValue(); |
953 | 0 | temp.setNumber(currentValue); |
954 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->srcFactor_id, temp, JSPROP_ENUMERATE)) { |
955 | 0 | return false; |
956 | 0 | } |
957 | 0 | break; |
958 | 0 | } while(false); |
959 | 0 | } |
960 | 0 |
|
961 | 0 | return true; |
962 | 0 | } |
963 | | |
964 | | bool |
965 | | WebGPUBlendDescriptor::ToJSON(nsAString& aJSON) const |
966 | 0 | { |
967 | 0 | AutoJSAPI jsapi; |
968 | 0 | jsapi.Init(); |
969 | 0 | JSContext *cx = jsapi.cx(); |
970 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
971 | 0 | // because we'll only be creating objects, in ways that have no |
972 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
973 | 0 | // which likewise guarantees no side-effects for the sorts of |
974 | 0 | // things we will pass it. |
975 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
976 | 0 | JS::Rooted<JS::Value> val(cx); |
977 | 0 | if (!ToObjectInternal(cx, &val)) { |
978 | 0 | return false; |
979 | 0 | } |
980 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
981 | 0 | return StringifyToJSON(cx, obj, aJSON); |
982 | 0 | } |
983 | | |
984 | | void |
985 | | WebGPUBlendDescriptor::TraceDictionary(JSTracer* trc) |
986 | 0 | { |
987 | 0 | } |
988 | | |
989 | | WebGPUBlendDescriptor& |
990 | | WebGPUBlendDescriptor::operator=(const WebGPUBlendDescriptor& aOther) |
991 | 0 | { |
992 | 0 | DictionaryBase::operator=(aOther); |
993 | 0 | mDstFactor.Reset(); |
994 | 0 | if (aOther.mDstFactor.WasPassed()) { |
995 | 0 | mDstFactor.Construct(aOther.mDstFactor.Value()); |
996 | 0 | } |
997 | 0 | mOperation.Reset(); |
998 | 0 | if (aOther.mOperation.WasPassed()) { |
999 | 0 | mOperation.Construct(aOther.mOperation.Value()); |
1000 | 0 | } |
1001 | 0 | mSrcFactor.Reset(); |
1002 | 0 | if (aOther.mSrcFactor.WasPassed()) { |
1003 | 0 | mSrcFactor.Construct(aOther.mSrcFactor.Value()); |
1004 | 0 | } |
1005 | 0 | return *this; |
1006 | 0 | } |
1007 | | |
1008 | | namespace binding_detail { |
1009 | | } // namespace binding_detail |
1010 | | |
1011 | | |
1012 | | |
1013 | | WebGPUBufferDescriptor::WebGPUBufferDescriptor() |
1014 | 0 | { |
1015 | 0 | // Safe to pass a null context if we pass a null value |
1016 | 0 | Init(nullptr, JS::NullHandleValue); |
1017 | 0 | } |
1018 | | |
1019 | | |
1020 | | |
1021 | | bool |
1022 | | WebGPUBufferDescriptor::InitIds(JSContext* cx, WebGPUBufferDescriptorAtoms* atomsCache) |
1023 | 0 | { |
1024 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
1025 | 0 |
|
1026 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
1027 | 0 | // uninitialized. |
1028 | 0 | if (!atomsCache->usage_id.init(cx, "usage") || |
1029 | 0 | !atomsCache->size_id.init(cx, "size")) { |
1030 | 0 | return false; |
1031 | 0 | } |
1032 | 0 | return true; |
1033 | 0 | } |
1034 | | |
1035 | | bool |
1036 | | WebGPUBufferDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
1037 | 0 | { |
1038 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
1039 | 0 | // Since in that case we will not have to do any property gets |
1040 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
1041 | 0 | // checkers by static analysis tools |
1042 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
1043 | 0 | WebGPUBufferDescriptorAtoms* atomsCache = nullptr; |
1044 | 0 | if (cx) { |
1045 | 0 | atomsCache = GetAtomCache<WebGPUBufferDescriptorAtoms>(cx); |
1046 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
1047 | 0 | return false; |
1048 | 0 | } |
1049 | 0 | } |
1050 | 0 | |
1051 | 0 | if (!IsConvertibleToDictionary(val)) { |
1052 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
1053 | 0 | } |
1054 | 0 | |
1055 | 0 | bool isNull = val.isNullOrUndefined(); |
1056 | 0 | // We only need these if !isNull, in which case we have |cx|. |
1057 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
1058 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
1059 | 0 | if (!isNull) { |
1060 | 0 | MOZ_ASSERT(cx); |
1061 | 0 | object.emplace(cx, &val.toObject()); |
1062 | 0 | temp.emplace(cx); |
1063 | 0 | } |
1064 | 0 | if (!isNull) { |
1065 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->size_id, temp.ptr())) { |
1066 | 0 | return false; |
1067 | 0 | } |
1068 | 0 | } |
1069 | 0 | if (!isNull && !temp->isUndefined()) { |
1070 | 0 | mSize.Construct(); |
1071 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mSize.Value()))) { |
1072 | 0 | return false; |
1073 | 0 | } |
1074 | 0 | mIsAnyMemberPresent = true; |
1075 | 0 | } |
1076 | 0 |
|
1077 | 0 | if (!isNull) { |
1078 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->usage_id, temp.ptr())) { |
1079 | 0 | return false; |
1080 | 0 | } |
1081 | 0 | } |
1082 | 0 | if (!isNull && !temp->isUndefined()) { |
1083 | 0 | mUsage.Construct(); |
1084 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mUsage.Value()))) { |
1085 | 0 | return false; |
1086 | 0 | } |
1087 | 0 | mIsAnyMemberPresent = true; |
1088 | 0 | } |
1089 | 0 | return true; |
1090 | 0 | } |
1091 | | |
1092 | | bool |
1093 | | WebGPUBufferDescriptor::Init(const nsAString& aJSON) |
1094 | 0 | { |
1095 | 0 | AutoJSAPI jsapi; |
1096 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
1097 | 0 | if (!cleanGlobal) { |
1098 | 0 | return false; |
1099 | 0 | } |
1100 | 0 | if (!jsapi.Init(cleanGlobal)) { |
1101 | 0 | return false; |
1102 | 0 | } |
1103 | 0 | JSContext* cx = jsapi.cx(); |
1104 | 0 | JS::Rooted<JS::Value> json(cx); |
1105 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
1106 | 0 | NS_ENSURE_TRUE(ok, false); |
1107 | 0 | return Init(cx, json); |
1108 | 0 | } |
1109 | | |
1110 | | bool |
1111 | | WebGPUBufferDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
1112 | 0 | { |
1113 | 0 | WebGPUBufferDescriptorAtoms* atomsCache = GetAtomCache<WebGPUBufferDescriptorAtoms>(cx); |
1114 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
1115 | 0 | return false; |
1116 | 0 | } |
1117 | 0 | |
1118 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
1119 | 0 | if (!obj) { |
1120 | 0 | return false; |
1121 | 0 | } |
1122 | 0 | rval.set(JS::ObjectValue(*obj)); |
1123 | 0 |
|
1124 | 0 | if (mSize.WasPassed()) { |
1125 | 0 | do { |
1126 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1127 | 0 | JS::Rooted<JS::Value> temp(cx); |
1128 | 0 | uint32_t const & currentValue = mSize.InternalValue(); |
1129 | 0 | temp.setNumber(currentValue); |
1130 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->size_id, temp, JSPROP_ENUMERATE)) { |
1131 | 0 | return false; |
1132 | 0 | } |
1133 | 0 | break; |
1134 | 0 | } while(false); |
1135 | 0 | } |
1136 | 0 |
|
1137 | 0 | if (mUsage.WasPassed()) { |
1138 | 0 | do { |
1139 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1140 | 0 | JS::Rooted<JS::Value> temp(cx); |
1141 | 0 | uint32_t const & currentValue = mUsage.InternalValue(); |
1142 | 0 | temp.setNumber(currentValue); |
1143 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->usage_id, temp, JSPROP_ENUMERATE)) { |
1144 | 0 | return false; |
1145 | 0 | } |
1146 | 0 | break; |
1147 | 0 | } while(false); |
1148 | 0 | } |
1149 | 0 |
|
1150 | 0 | return true; |
1151 | 0 | } |
1152 | | |
1153 | | bool |
1154 | | WebGPUBufferDescriptor::ToJSON(nsAString& aJSON) const |
1155 | 0 | { |
1156 | 0 | AutoJSAPI jsapi; |
1157 | 0 | jsapi.Init(); |
1158 | 0 | JSContext *cx = jsapi.cx(); |
1159 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
1160 | 0 | // because we'll only be creating objects, in ways that have no |
1161 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
1162 | 0 | // which likewise guarantees no side-effects for the sorts of |
1163 | 0 | // things we will pass it. |
1164 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
1165 | 0 | JS::Rooted<JS::Value> val(cx); |
1166 | 0 | if (!ToObjectInternal(cx, &val)) { |
1167 | 0 | return false; |
1168 | 0 | } |
1169 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
1170 | 0 | return StringifyToJSON(cx, obj, aJSON); |
1171 | 0 | } |
1172 | | |
1173 | | void |
1174 | | WebGPUBufferDescriptor::TraceDictionary(JSTracer* trc) |
1175 | 0 | { |
1176 | 0 | } |
1177 | | |
1178 | | WebGPUBufferDescriptor& |
1179 | | WebGPUBufferDescriptor::operator=(const WebGPUBufferDescriptor& aOther) |
1180 | 0 | { |
1181 | 0 | DictionaryBase::operator=(aOther); |
1182 | 0 | mSize.Reset(); |
1183 | 0 | if (aOther.mSize.WasPassed()) { |
1184 | 0 | mSize.Construct(aOther.mSize.Value()); |
1185 | 0 | } |
1186 | 0 | mUsage.Reset(); |
1187 | 0 | if (aOther.mUsage.WasPassed()) { |
1188 | 0 | mUsage.Construct(aOther.mUsage.Value()); |
1189 | 0 | } |
1190 | 0 | return *this; |
1191 | 0 | } |
1192 | | |
1193 | | namespace binding_detail { |
1194 | | } // namespace binding_detail |
1195 | | |
1196 | | |
1197 | | bool |
1198 | | WebGPUBufferOrWebGPUTexture::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const |
1199 | 0 | { |
1200 | 0 | switch (mType) { |
1201 | 0 | case eUninitialized: { |
1202 | 0 | return false; |
1203 | 0 | break; |
1204 | 0 | } |
1205 | 0 | case eWebGPUBuffer: { |
1206 | 0 | if (!GetOrCreateDOMReflector(cx, mValue.mWebGPUBuffer.Value(), rval)) { |
1207 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
1208 | 0 | return false; |
1209 | 0 | } |
1210 | 0 | return true; |
1211 | 0 | break; |
1212 | 0 | } |
1213 | 0 | case eWebGPUTexture: { |
1214 | 0 | if (!GetOrCreateDOMReflector(cx, mValue.mWebGPUTexture.Value(), rval)) { |
1215 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
1216 | 0 | return false; |
1217 | 0 | } |
1218 | 0 | return true; |
1219 | 0 | break; |
1220 | 0 | } |
1221 | 0 | default: { |
1222 | 0 | return false; |
1223 | 0 | break; |
1224 | 0 | } |
1225 | 0 | } |
1226 | 0 | |
1227 | 0 | return false; |
1228 | 0 | } |
1229 | | |
1230 | | |
1231 | | OwningNonNull<mozilla::webgpu::Buffer>& |
1232 | | OwningWebGPUBufferOrWebGPUTexture::RawSetAsWebGPUBuffer() |
1233 | 0 | { |
1234 | 0 | if (mType == eWebGPUBuffer) { |
1235 | 0 | return mValue.mWebGPUBuffer.Value(); |
1236 | 0 | } |
1237 | 0 | MOZ_ASSERT(mType == eUninitialized); |
1238 | 0 | mType = eWebGPUBuffer; |
1239 | 0 | return mValue.mWebGPUBuffer.SetValue(); |
1240 | 0 | } |
1241 | | |
1242 | | OwningNonNull<mozilla::webgpu::Buffer>& |
1243 | | OwningWebGPUBufferOrWebGPUTexture::SetAsWebGPUBuffer() |
1244 | 0 | { |
1245 | 0 | if (mType == eWebGPUBuffer) { |
1246 | 0 | return mValue.mWebGPUBuffer.Value(); |
1247 | 0 | } |
1248 | 0 | Uninit(); |
1249 | 0 | mType = eWebGPUBuffer; |
1250 | 0 | return mValue.mWebGPUBuffer.SetValue(); |
1251 | 0 | } |
1252 | | |
1253 | | bool |
1254 | | OwningWebGPUBufferOrWebGPUTexture::TrySetToWebGPUBuffer(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl) |
1255 | 0 | { |
1256 | 0 | tryNext = false; |
1257 | 0 | { // scope for memberSlot |
1258 | 0 | OwningNonNull<mozilla::webgpu::Buffer>& memberSlot = RawSetAsWebGPUBuffer(); |
1259 | 0 | static_assert(IsRefcounted<mozilla::webgpu::Buffer>::value, "We can only store refcounted classes.");{ |
1260 | 0 | nsresult rv = UnwrapObject<prototypes::id::WebGPUBuffer, mozilla::webgpu::Buffer>(value, memberSlot); |
1261 | 0 | if (NS_FAILED(rv)) { |
1262 | 0 | DestroyWebGPUBuffer(); |
1263 | 0 | tryNext = true; |
1264 | 0 | return true; |
1265 | 0 | } |
1266 | 0 | } |
1267 | 0 | } |
1268 | 0 | return true; |
1269 | 0 | } |
1270 | | |
1271 | | void |
1272 | | OwningWebGPUBufferOrWebGPUTexture::DestroyWebGPUBuffer() |
1273 | 0 | { |
1274 | 0 | MOZ_ASSERT(IsWebGPUBuffer(), "Wrong type!"); |
1275 | 0 | mValue.mWebGPUBuffer.Destroy(); |
1276 | 0 | mType = eUninitialized; |
1277 | 0 | } |
1278 | | |
1279 | | |
1280 | | |
1281 | | |
1282 | | OwningNonNull<mozilla::webgpu::Texture>& |
1283 | | OwningWebGPUBufferOrWebGPUTexture::RawSetAsWebGPUTexture() |
1284 | 0 | { |
1285 | 0 | if (mType == eWebGPUTexture) { |
1286 | 0 | return mValue.mWebGPUTexture.Value(); |
1287 | 0 | } |
1288 | 0 | MOZ_ASSERT(mType == eUninitialized); |
1289 | 0 | mType = eWebGPUTexture; |
1290 | 0 | return mValue.mWebGPUTexture.SetValue(); |
1291 | 0 | } |
1292 | | |
1293 | | OwningNonNull<mozilla::webgpu::Texture>& |
1294 | | OwningWebGPUBufferOrWebGPUTexture::SetAsWebGPUTexture() |
1295 | 0 | { |
1296 | 0 | if (mType == eWebGPUTexture) { |
1297 | 0 | return mValue.mWebGPUTexture.Value(); |
1298 | 0 | } |
1299 | 0 | Uninit(); |
1300 | 0 | mType = eWebGPUTexture; |
1301 | 0 | return mValue.mWebGPUTexture.SetValue(); |
1302 | 0 | } |
1303 | | |
1304 | | bool |
1305 | | OwningWebGPUBufferOrWebGPUTexture::TrySetToWebGPUTexture(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl) |
1306 | 0 | { |
1307 | 0 | tryNext = false; |
1308 | 0 | { // scope for memberSlot |
1309 | 0 | OwningNonNull<mozilla::webgpu::Texture>& memberSlot = RawSetAsWebGPUTexture(); |
1310 | 0 | static_assert(IsRefcounted<mozilla::webgpu::Texture>::value, "We can only store refcounted classes.");{ |
1311 | 0 | nsresult rv = UnwrapObject<prototypes::id::WebGPUTexture, mozilla::webgpu::Texture>(value, memberSlot); |
1312 | 0 | if (NS_FAILED(rv)) { |
1313 | 0 | DestroyWebGPUTexture(); |
1314 | 0 | tryNext = true; |
1315 | 0 | return true; |
1316 | 0 | } |
1317 | 0 | } |
1318 | 0 | } |
1319 | 0 | return true; |
1320 | 0 | } |
1321 | | |
1322 | | void |
1323 | | OwningWebGPUBufferOrWebGPUTexture::DestroyWebGPUTexture() |
1324 | 0 | { |
1325 | 0 | MOZ_ASSERT(IsWebGPUTexture(), "Wrong type!"); |
1326 | 0 | mValue.mWebGPUTexture.Destroy(); |
1327 | 0 | mType = eUninitialized; |
1328 | 0 | } |
1329 | | |
1330 | | |
1331 | | |
1332 | | |
1333 | | void |
1334 | | OwningWebGPUBufferOrWebGPUTexture::Uninit() |
1335 | | { |
1336 | | switch (mType) { |
1337 | | case eUninitialized: { |
1338 | | break; |
1339 | | } |
1340 | | case eWebGPUBuffer: { |
1341 | | DestroyWebGPUBuffer(); |
1342 | | break; |
1343 | | } |
1344 | | case eWebGPUTexture: { |
1345 | | DestroyWebGPUTexture(); |
1346 | | break; |
1347 | | } |
1348 | | } |
1349 | | } |
1350 | | |
1351 | | bool |
1352 | | OwningWebGPUBufferOrWebGPUTexture::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const |
1353 | 0 | { |
1354 | 0 | switch (mType) { |
1355 | 0 | case eUninitialized: { |
1356 | 0 | return false; |
1357 | 0 | break; |
1358 | 0 | } |
1359 | 0 | case eWebGPUBuffer: { |
1360 | 0 | if (!GetOrCreateDOMReflector(cx, mValue.mWebGPUBuffer.Value(), rval)) { |
1361 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
1362 | 0 | return false; |
1363 | 0 | } |
1364 | 0 | return true; |
1365 | 0 | break; |
1366 | 0 | } |
1367 | 0 | case eWebGPUTexture: { |
1368 | 0 | if (!GetOrCreateDOMReflector(cx, mValue.mWebGPUTexture.Value(), rval)) { |
1369 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
1370 | 0 | return false; |
1371 | 0 | } |
1372 | 0 | return true; |
1373 | 0 | break; |
1374 | 0 | } |
1375 | 0 | default: { |
1376 | 0 | return false; |
1377 | 0 | break; |
1378 | 0 | } |
1379 | 0 | } |
1380 | 0 | |
1381 | 0 | return false; |
1382 | 0 | } |
1383 | | |
1384 | | void |
1385 | | OwningWebGPUBufferOrWebGPUTexture::TraceUnion(JSTracer* trc) |
1386 | 0 | { |
1387 | 0 | } |
1388 | | |
1389 | | OwningWebGPUBufferOrWebGPUTexture& |
1390 | | OwningWebGPUBufferOrWebGPUTexture::operator=(const OwningWebGPUBufferOrWebGPUTexture& aOther) |
1391 | 0 | { |
1392 | 0 | switch (aOther.mType) { |
1393 | 0 | case eUninitialized: { |
1394 | 0 | MOZ_ASSERT(mType == eUninitialized, |
1395 | 0 | "We need to destroy ourselves?"); |
1396 | 0 | break; |
1397 | 0 | } |
1398 | 0 | case eWebGPUBuffer: { |
1399 | 0 | SetAsWebGPUBuffer() = aOther.GetAsWebGPUBuffer(); |
1400 | 0 | break; |
1401 | 0 | } |
1402 | 0 | case eWebGPUTexture: { |
1403 | 0 | SetAsWebGPUTexture() = aOther.GetAsWebGPUTexture(); |
1404 | 0 | break; |
1405 | 0 | } |
1406 | 0 | } |
1407 | 0 | return *this; |
1408 | 0 | } |
1409 | | |
1410 | | |
1411 | | |
1412 | | WebGPUCommandEncoderDescriptor::WebGPUCommandEncoderDescriptor() |
1413 | 0 | { |
1414 | 0 | // Safe to pass a null context if we pass a null value |
1415 | 0 | Init(nullptr, JS::NullHandleValue); |
1416 | 0 | } |
1417 | | |
1418 | | |
1419 | | |
1420 | | bool |
1421 | | WebGPUCommandEncoderDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
1422 | 0 | { |
1423 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
1424 | 0 | // Since in that case we will not have to do any property gets |
1425 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
1426 | 0 | // checkers by static analysis tools |
1427 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
1428 | 0 | if (!IsConvertibleToDictionary(val)) { |
1429 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
1430 | 0 | } |
1431 | 0 | |
1432 | 0 | return true; |
1433 | 0 | } |
1434 | | |
1435 | | bool |
1436 | | WebGPUCommandEncoderDescriptor::Init(const nsAString& aJSON) |
1437 | 0 | { |
1438 | 0 | AutoJSAPI jsapi; |
1439 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
1440 | 0 | if (!cleanGlobal) { |
1441 | 0 | return false; |
1442 | 0 | } |
1443 | 0 | if (!jsapi.Init(cleanGlobal)) { |
1444 | 0 | return false; |
1445 | 0 | } |
1446 | 0 | JSContext* cx = jsapi.cx(); |
1447 | 0 | JS::Rooted<JS::Value> json(cx); |
1448 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
1449 | 0 | NS_ENSURE_TRUE(ok, false); |
1450 | 0 | return Init(cx, json); |
1451 | 0 | } |
1452 | | |
1453 | | bool |
1454 | | WebGPUCommandEncoderDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
1455 | 0 | { |
1456 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
1457 | 0 | if (!obj) { |
1458 | 0 | return false; |
1459 | 0 | } |
1460 | 0 | rval.set(JS::ObjectValue(*obj)); |
1461 | 0 |
|
1462 | 0 |
|
1463 | 0 | return true; |
1464 | 0 | } |
1465 | | |
1466 | | bool |
1467 | | WebGPUCommandEncoderDescriptor::ToJSON(nsAString& aJSON) const |
1468 | 0 | { |
1469 | 0 | AutoJSAPI jsapi; |
1470 | 0 | jsapi.Init(); |
1471 | 0 | JSContext *cx = jsapi.cx(); |
1472 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
1473 | 0 | // because we'll only be creating objects, in ways that have no |
1474 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
1475 | 0 | // which likewise guarantees no side-effects for the sorts of |
1476 | 0 | // things we will pass it. |
1477 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
1478 | 0 | JS::Rooted<JS::Value> val(cx); |
1479 | 0 | if (!ToObjectInternal(cx, &val)) { |
1480 | 0 | return false; |
1481 | 0 | } |
1482 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
1483 | 0 | return StringifyToJSON(cx, obj, aJSON); |
1484 | 0 | } |
1485 | | |
1486 | | void |
1487 | | WebGPUCommandEncoderDescriptor::TraceDictionary(JSTracer* trc) |
1488 | 0 | { |
1489 | 0 | } |
1490 | | |
1491 | | WebGPUCommandEncoderDescriptor& |
1492 | | WebGPUCommandEncoderDescriptor::operator=(const WebGPUCommandEncoderDescriptor& aOther) |
1493 | 0 | { |
1494 | 0 | DictionaryBase::operator=(aOther); |
1495 | 0 | return *this; |
1496 | 0 | } |
1497 | | |
1498 | | namespace binding_detail { |
1499 | | } // namespace binding_detail |
1500 | | |
1501 | | |
1502 | | bool |
1503 | | WebGPUComputePipelineOrWebGPURenderPipeline::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const |
1504 | 0 | { |
1505 | 0 | switch (mType) { |
1506 | 0 | case eUninitialized: { |
1507 | 0 | return false; |
1508 | 0 | break; |
1509 | 0 | } |
1510 | 0 | case eWebGPUComputePipeline: { |
1511 | 0 | if (!GetOrCreateDOMReflector(cx, mValue.mWebGPUComputePipeline.Value(), rval)) { |
1512 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
1513 | 0 | return false; |
1514 | 0 | } |
1515 | 0 | return true; |
1516 | 0 | break; |
1517 | 0 | } |
1518 | 0 | case eWebGPURenderPipeline: { |
1519 | 0 | if (!GetOrCreateDOMReflector(cx, mValue.mWebGPURenderPipeline.Value(), rval)) { |
1520 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
1521 | 0 | return false; |
1522 | 0 | } |
1523 | 0 | return true; |
1524 | 0 | break; |
1525 | 0 | } |
1526 | 0 | default: { |
1527 | 0 | return false; |
1528 | 0 | break; |
1529 | 0 | } |
1530 | 0 | } |
1531 | 0 | |
1532 | 0 | return false; |
1533 | 0 | } |
1534 | | |
1535 | | |
1536 | | OwningNonNull<mozilla::webgpu::ComputePipeline>& |
1537 | | OwningWebGPUComputePipelineOrWebGPURenderPipeline::RawSetAsWebGPUComputePipeline() |
1538 | 0 | { |
1539 | 0 | if (mType == eWebGPUComputePipeline) { |
1540 | 0 | return mValue.mWebGPUComputePipeline.Value(); |
1541 | 0 | } |
1542 | 0 | MOZ_ASSERT(mType == eUninitialized); |
1543 | 0 | mType = eWebGPUComputePipeline; |
1544 | 0 | return mValue.mWebGPUComputePipeline.SetValue(); |
1545 | 0 | } |
1546 | | |
1547 | | OwningNonNull<mozilla::webgpu::ComputePipeline>& |
1548 | | OwningWebGPUComputePipelineOrWebGPURenderPipeline::SetAsWebGPUComputePipeline() |
1549 | 0 | { |
1550 | 0 | if (mType == eWebGPUComputePipeline) { |
1551 | 0 | return mValue.mWebGPUComputePipeline.Value(); |
1552 | 0 | } |
1553 | 0 | Uninit(); |
1554 | 0 | mType = eWebGPUComputePipeline; |
1555 | 0 | return mValue.mWebGPUComputePipeline.SetValue(); |
1556 | 0 | } |
1557 | | |
1558 | | bool |
1559 | | OwningWebGPUComputePipelineOrWebGPURenderPipeline::TrySetToWebGPUComputePipeline(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl) |
1560 | 0 | { |
1561 | 0 | tryNext = false; |
1562 | 0 | { // scope for memberSlot |
1563 | 0 | OwningNonNull<mozilla::webgpu::ComputePipeline>& memberSlot = RawSetAsWebGPUComputePipeline(); |
1564 | 0 | static_assert(IsRefcounted<mozilla::webgpu::ComputePipeline>::value, "We can only store refcounted classes.");{ |
1565 | 0 | nsresult rv = UnwrapObject<prototypes::id::WebGPUComputePipeline, mozilla::webgpu::ComputePipeline>(value, memberSlot); |
1566 | 0 | if (NS_FAILED(rv)) { |
1567 | 0 | DestroyWebGPUComputePipeline(); |
1568 | 0 | tryNext = true; |
1569 | 0 | return true; |
1570 | 0 | } |
1571 | 0 | } |
1572 | 0 | } |
1573 | 0 | return true; |
1574 | 0 | } |
1575 | | |
1576 | | void |
1577 | | OwningWebGPUComputePipelineOrWebGPURenderPipeline::DestroyWebGPUComputePipeline() |
1578 | 0 | { |
1579 | 0 | MOZ_ASSERT(IsWebGPUComputePipeline(), "Wrong type!"); |
1580 | 0 | mValue.mWebGPUComputePipeline.Destroy(); |
1581 | 0 | mType = eUninitialized; |
1582 | 0 | } |
1583 | | |
1584 | | |
1585 | | |
1586 | | |
1587 | | OwningNonNull<mozilla::webgpu::RenderPipeline>& |
1588 | | OwningWebGPUComputePipelineOrWebGPURenderPipeline::RawSetAsWebGPURenderPipeline() |
1589 | 0 | { |
1590 | 0 | if (mType == eWebGPURenderPipeline) { |
1591 | 0 | return mValue.mWebGPURenderPipeline.Value(); |
1592 | 0 | } |
1593 | 0 | MOZ_ASSERT(mType == eUninitialized); |
1594 | 0 | mType = eWebGPURenderPipeline; |
1595 | 0 | return mValue.mWebGPURenderPipeline.SetValue(); |
1596 | 0 | } |
1597 | | |
1598 | | OwningNonNull<mozilla::webgpu::RenderPipeline>& |
1599 | | OwningWebGPUComputePipelineOrWebGPURenderPipeline::SetAsWebGPURenderPipeline() |
1600 | 0 | { |
1601 | 0 | if (mType == eWebGPURenderPipeline) { |
1602 | 0 | return mValue.mWebGPURenderPipeline.Value(); |
1603 | 0 | } |
1604 | 0 | Uninit(); |
1605 | 0 | mType = eWebGPURenderPipeline; |
1606 | 0 | return mValue.mWebGPURenderPipeline.SetValue(); |
1607 | 0 | } |
1608 | | |
1609 | | bool |
1610 | | OwningWebGPUComputePipelineOrWebGPURenderPipeline::TrySetToWebGPURenderPipeline(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl) |
1611 | 0 | { |
1612 | 0 | tryNext = false; |
1613 | 0 | { // scope for memberSlot |
1614 | 0 | OwningNonNull<mozilla::webgpu::RenderPipeline>& memberSlot = RawSetAsWebGPURenderPipeline(); |
1615 | 0 | static_assert(IsRefcounted<mozilla::webgpu::RenderPipeline>::value, "We can only store refcounted classes.");{ |
1616 | 0 | nsresult rv = UnwrapObject<prototypes::id::WebGPURenderPipeline, mozilla::webgpu::RenderPipeline>(value, memberSlot); |
1617 | 0 | if (NS_FAILED(rv)) { |
1618 | 0 | DestroyWebGPURenderPipeline(); |
1619 | 0 | tryNext = true; |
1620 | 0 | return true; |
1621 | 0 | } |
1622 | 0 | } |
1623 | 0 | } |
1624 | 0 | return true; |
1625 | 0 | } |
1626 | | |
1627 | | void |
1628 | | OwningWebGPUComputePipelineOrWebGPURenderPipeline::DestroyWebGPURenderPipeline() |
1629 | 0 | { |
1630 | 0 | MOZ_ASSERT(IsWebGPURenderPipeline(), "Wrong type!"); |
1631 | 0 | mValue.mWebGPURenderPipeline.Destroy(); |
1632 | 0 | mType = eUninitialized; |
1633 | 0 | } |
1634 | | |
1635 | | |
1636 | | |
1637 | | |
1638 | | void |
1639 | | OwningWebGPUComputePipelineOrWebGPURenderPipeline::Uninit() |
1640 | | { |
1641 | | switch (mType) { |
1642 | | case eUninitialized: { |
1643 | | break; |
1644 | | } |
1645 | | case eWebGPUComputePipeline: { |
1646 | | DestroyWebGPUComputePipeline(); |
1647 | | break; |
1648 | | } |
1649 | | case eWebGPURenderPipeline: { |
1650 | | DestroyWebGPURenderPipeline(); |
1651 | | break; |
1652 | | } |
1653 | | } |
1654 | | } |
1655 | | |
1656 | | bool |
1657 | | OwningWebGPUComputePipelineOrWebGPURenderPipeline::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const |
1658 | 0 | { |
1659 | 0 | switch (mType) { |
1660 | 0 | case eUninitialized: { |
1661 | 0 | return false; |
1662 | 0 | break; |
1663 | 0 | } |
1664 | 0 | case eWebGPUComputePipeline: { |
1665 | 0 | if (!GetOrCreateDOMReflector(cx, mValue.mWebGPUComputePipeline.Value(), rval)) { |
1666 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
1667 | 0 | return false; |
1668 | 0 | } |
1669 | 0 | return true; |
1670 | 0 | break; |
1671 | 0 | } |
1672 | 0 | case eWebGPURenderPipeline: { |
1673 | 0 | if (!GetOrCreateDOMReflector(cx, mValue.mWebGPURenderPipeline.Value(), rval)) { |
1674 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
1675 | 0 | return false; |
1676 | 0 | } |
1677 | 0 | return true; |
1678 | 0 | break; |
1679 | 0 | } |
1680 | 0 | default: { |
1681 | 0 | return false; |
1682 | 0 | break; |
1683 | 0 | } |
1684 | 0 | } |
1685 | 0 | |
1686 | 0 | return false; |
1687 | 0 | } |
1688 | | |
1689 | | void |
1690 | | OwningWebGPUComputePipelineOrWebGPURenderPipeline::TraceUnion(JSTracer* trc) |
1691 | 0 | { |
1692 | 0 | } |
1693 | | |
1694 | | OwningWebGPUComputePipelineOrWebGPURenderPipeline& |
1695 | | OwningWebGPUComputePipelineOrWebGPURenderPipeline::operator=(const OwningWebGPUComputePipelineOrWebGPURenderPipeline& aOther) |
1696 | 0 | { |
1697 | 0 | switch (aOther.mType) { |
1698 | 0 | case eUninitialized: { |
1699 | 0 | MOZ_ASSERT(mType == eUninitialized, |
1700 | 0 | "We need to destroy ourselves?"); |
1701 | 0 | break; |
1702 | 0 | } |
1703 | 0 | case eWebGPUComputePipeline: { |
1704 | 0 | SetAsWebGPUComputePipeline() = aOther.GetAsWebGPUComputePipeline(); |
1705 | 0 | break; |
1706 | 0 | } |
1707 | 0 | case eWebGPURenderPipeline: { |
1708 | 0 | SetAsWebGPURenderPipeline() = aOther.GetAsWebGPURenderPipeline(); |
1709 | 0 | break; |
1710 | 0 | } |
1711 | 0 | } |
1712 | 0 | return *this; |
1713 | 0 | } |
1714 | | |
1715 | | |
1716 | | |
1717 | | WebGPUExtensions::WebGPUExtensions() |
1718 | 0 | { |
1719 | 0 | // Safe to pass a null context if we pass a null value |
1720 | 0 | Init(nullptr, JS::NullHandleValue); |
1721 | 0 | } |
1722 | | |
1723 | | |
1724 | | |
1725 | | bool |
1726 | | WebGPUExtensions::InitIds(JSContext* cx, WebGPUExtensionsAtoms* atomsCache) |
1727 | 0 | { |
1728 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
1729 | 0 |
|
1730 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
1731 | 0 | // uninitialized. |
1732 | 0 | if (!atomsCache->logicOp_id.init(cx, "logicOp") || |
1733 | 0 | !atomsCache->anisotropicFiltering_id.init(cx, "anisotropicFiltering")) { |
1734 | 0 | return false; |
1735 | 0 | } |
1736 | 0 | return true; |
1737 | 0 | } |
1738 | | |
1739 | | bool |
1740 | | WebGPUExtensions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
1741 | 0 | { |
1742 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
1743 | 0 | // Since in that case we will not have to do any property gets |
1744 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
1745 | 0 | // checkers by static analysis tools |
1746 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
1747 | 0 | WebGPUExtensionsAtoms* atomsCache = nullptr; |
1748 | 0 | if (cx) { |
1749 | 0 | atomsCache = GetAtomCache<WebGPUExtensionsAtoms>(cx); |
1750 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
1751 | 0 | return false; |
1752 | 0 | } |
1753 | 0 | } |
1754 | 0 | |
1755 | 0 | if (!IsConvertibleToDictionary(val)) { |
1756 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
1757 | 0 | } |
1758 | 0 | |
1759 | 0 | bool isNull = val.isNullOrUndefined(); |
1760 | 0 | // We only need these if !isNull, in which case we have |cx|. |
1761 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
1762 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
1763 | 0 | if (!isNull) { |
1764 | 0 | MOZ_ASSERT(cx); |
1765 | 0 | object.emplace(cx, &val.toObject()); |
1766 | 0 | temp.emplace(cx); |
1767 | 0 | } |
1768 | 0 | if (!isNull) { |
1769 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->anisotropicFiltering_id, temp.ptr())) { |
1770 | 0 | return false; |
1771 | 0 | } |
1772 | 0 | } |
1773 | 0 | if (!isNull && !temp->isUndefined()) { |
1774 | 0 | mAnisotropicFiltering.Construct(); |
1775 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &(mAnisotropicFiltering.Value()))) { |
1776 | 0 | return false; |
1777 | 0 | } |
1778 | 0 | mIsAnyMemberPresent = true; |
1779 | 0 | } |
1780 | 0 |
|
1781 | 0 | if (!isNull) { |
1782 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->logicOp_id, temp.ptr())) { |
1783 | 0 | return false; |
1784 | 0 | } |
1785 | 0 | } |
1786 | 0 | if (!isNull && !temp->isUndefined()) { |
1787 | 0 | mLogicOp.Construct(); |
1788 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &(mLogicOp.Value()))) { |
1789 | 0 | return false; |
1790 | 0 | } |
1791 | 0 | mIsAnyMemberPresent = true; |
1792 | 0 | } |
1793 | 0 | return true; |
1794 | 0 | } |
1795 | | |
1796 | | bool |
1797 | | WebGPUExtensions::Init(const nsAString& aJSON) |
1798 | 0 | { |
1799 | 0 | AutoJSAPI jsapi; |
1800 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
1801 | 0 | if (!cleanGlobal) { |
1802 | 0 | return false; |
1803 | 0 | } |
1804 | 0 | if (!jsapi.Init(cleanGlobal)) { |
1805 | 0 | return false; |
1806 | 0 | } |
1807 | 0 | JSContext* cx = jsapi.cx(); |
1808 | 0 | JS::Rooted<JS::Value> json(cx); |
1809 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
1810 | 0 | NS_ENSURE_TRUE(ok, false); |
1811 | 0 | return Init(cx, json); |
1812 | 0 | } |
1813 | | |
1814 | | bool |
1815 | | WebGPUExtensions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
1816 | 0 | { |
1817 | 0 | WebGPUExtensionsAtoms* atomsCache = GetAtomCache<WebGPUExtensionsAtoms>(cx); |
1818 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
1819 | 0 | return false; |
1820 | 0 | } |
1821 | 0 | |
1822 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
1823 | 0 | if (!obj) { |
1824 | 0 | return false; |
1825 | 0 | } |
1826 | 0 | rval.set(JS::ObjectValue(*obj)); |
1827 | 0 |
|
1828 | 0 | if (mAnisotropicFiltering.WasPassed()) { |
1829 | 0 | do { |
1830 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1831 | 0 | JS::Rooted<JS::Value> temp(cx); |
1832 | 0 | bool const & currentValue = mAnisotropicFiltering.InternalValue(); |
1833 | 0 | temp.setBoolean(currentValue); |
1834 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->anisotropicFiltering_id, temp, JSPROP_ENUMERATE)) { |
1835 | 0 | return false; |
1836 | 0 | } |
1837 | 0 | break; |
1838 | 0 | } while(false); |
1839 | 0 | } |
1840 | 0 |
|
1841 | 0 | if (mLogicOp.WasPassed()) { |
1842 | 0 | do { |
1843 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1844 | 0 | JS::Rooted<JS::Value> temp(cx); |
1845 | 0 | bool const & currentValue = mLogicOp.InternalValue(); |
1846 | 0 | temp.setBoolean(currentValue); |
1847 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->logicOp_id, temp, JSPROP_ENUMERATE)) { |
1848 | 0 | return false; |
1849 | 0 | } |
1850 | 0 | break; |
1851 | 0 | } while(false); |
1852 | 0 | } |
1853 | 0 |
|
1854 | 0 | return true; |
1855 | 0 | } |
1856 | | |
1857 | | bool |
1858 | | WebGPUExtensions::ToJSON(nsAString& aJSON) const |
1859 | 0 | { |
1860 | 0 | AutoJSAPI jsapi; |
1861 | 0 | jsapi.Init(); |
1862 | 0 | JSContext *cx = jsapi.cx(); |
1863 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
1864 | 0 | // because we'll only be creating objects, in ways that have no |
1865 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
1866 | 0 | // which likewise guarantees no side-effects for the sorts of |
1867 | 0 | // things we will pass it. |
1868 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
1869 | 0 | JS::Rooted<JS::Value> val(cx); |
1870 | 0 | if (!ToObjectInternal(cx, &val)) { |
1871 | 0 | return false; |
1872 | 0 | } |
1873 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
1874 | 0 | return StringifyToJSON(cx, obj, aJSON); |
1875 | 0 | } |
1876 | | |
1877 | | void |
1878 | | WebGPUExtensions::TraceDictionary(JSTracer* trc) |
1879 | 0 | { |
1880 | 0 | } |
1881 | | |
1882 | | WebGPUExtensions& |
1883 | | WebGPUExtensions::operator=(const WebGPUExtensions& aOther) |
1884 | 0 | { |
1885 | 0 | DictionaryBase::operator=(aOther); |
1886 | 0 | mAnisotropicFiltering.Reset(); |
1887 | 0 | if (aOther.mAnisotropicFiltering.WasPassed()) { |
1888 | 0 | mAnisotropicFiltering.Construct(aOther.mAnisotropicFiltering.Value()); |
1889 | 0 | } |
1890 | 0 | mLogicOp.Reset(); |
1891 | 0 | if (aOther.mLogicOp.WasPassed()) { |
1892 | 0 | mLogicOp.Construct(aOther.mLogicOp.Value()); |
1893 | 0 | } |
1894 | 0 | return *this; |
1895 | 0 | } |
1896 | | |
1897 | | namespace binding_detail { |
1898 | | } // namespace binding_detail |
1899 | | |
1900 | | |
1901 | | |
1902 | | WebGPULimits::WebGPULimits() |
1903 | 0 | { |
1904 | 0 | // Safe to pass a null context if we pass a null value |
1905 | 0 | Init(nullptr, JS::NullHandleValue); |
1906 | 0 | } |
1907 | | |
1908 | | |
1909 | | |
1910 | | bool |
1911 | | WebGPULimits::InitIds(JSContext* cx, WebGPULimitsAtoms* atomsCache) |
1912 | 0 | { |
1913 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
1914 | 0 |
|
1915 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
1916 | 0 | // uninitialized. |
1917 | 0 | if (!atomsCache->maxBindGroups_id.init(cx, "maxBindGroups")) { |
1918 | 0 | return false; |
1919 | 0 | } |
1920 | 0 | return true; |
1921 | 0 | } |
1922 | | |
1923 | | bool |
1924 | | WebGPULimits::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
1925 | 0 | { |
1926 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
1927 | 0 | // Since in that case we will not have to do any property gets |
1928 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
1929 | 0 | // checkers by static analysis tools |
1930 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
1931 | 0 | WebGPULimitsAtoms* atomsCache = nullptr; |
1932 | 0 | if (cx) { |
1933 | 0 | atomsCache = GetAtomCache<WebGPULimitsAtoms>(cx); |
1934 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
1935 | 0 | return false; |
1936 | 0 | } |
1937 | 0 | } |
1938 | 0 | |
1939 | 0 | if (!IsConvertibleToDictionary(val)) { |
1940 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
1941 | 0 | } |
1942 | 0 | |
1943 | 0 | bool isNull = val.isNullOrUndefined(); |
1944 | 0 | // We only need these if !isNull, in which case we have |cx|. |
1945 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
1946 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
1947 | 0 | if (!isNull) { |
1948 | 0 | MOZ_ASSERT(cx); |
1949 | 0 | object.emplace(cx, &val.toObject()); |
1950 | 0 | temp.emplace(cx); |
1951 | 0 | } |
1952 | 0 | if (!isNull) { |
1953 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->maxBindGroups_id, temp.ptr())) { |
1954 | 0 | return false; |
1955 | 0 | } |
1956 | 0 | } |
1957 | 0 | if (!isNull && !temp->isUndefined()) { |
1958 | 0 | mMaxBindGroups.Construct(); |
1959 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mMaxBindGroups.Value()))) { |
1960 | 0 | return false; |
1961 | 0 | } |
1962 | 0 | mIsAnyMemberPresent = true; |
1963 | 0 | } |
1964 | 0 | return true; |
1965 | 0 | } |
1966 | | |
1967 | | bool |
1968 | | WebGPULimits::Init(const nsAString& aJSON) |
1969 | 0 | { |
1970 | 0 | AutoJSAPI jsapi; |
1971 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
1972 | 0 | if (!cleanGlobal) { |
1973 | 0 | return false; |
1974 | 0 | } |
1975 | 0 | if (!jsapi.Init(cleanGlobal)) { |
1976 | 0 | return false; |
1977 | 0 | } |
1978 | 0 | JSContext* cx = jsapi.cx(); |
1979 | 0 | JS::Rooted<JS::Value> json(cx); |
1980 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
1981 | 0 | NS_ENSURE_TRUE(ok, false); |
1982 | 0 | return Init(cx, json); |
1983 | 0 | } |
1984 | | |
1985 | | bool |
1986 | | WebGPULimits::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
1987 | 0 | { |
1988 | 0 | WebGPULimitsAtoms* atomsCache = GetAtomCache<WebGPULimitsAtoms>(cx); |
1989 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
1990 | 0 | return false; |
1991 | 0 | } |
1992 | 0 | |
1993 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
1994 | 0 | if (!obj) { |
1995 | 0 | return false; |
1996 | 0 | } |
1997 | 0 | rval.set(JS::ObjectValue(*obj)); |
1998 | 0 |
|
1999 | 0 | if (mMaxBindGroups.WasPassed()) { |
2000 | 0 | do { |
2001 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2002 | 0 | JS::Rooted<JS::Value> temp(cx); |
2003 | 0 | uint32_t const & currentValue = mMaxBindGroups.InternalValue(); |
2004 | 0 | temp.setNumber(currentValue); |
2005 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->maxBindGroups_id, temp, JSPROP_ENUMERATE)) { |
2006 | 0 | return false; |
2007 | 0 | } |
2008 | 0 | break; |
2009 | 0 | } while(false); |
2010 | 0 | } |
2011 | 0 |
|
2012 | 0 | return true; |
2013 | 0 | } |
2014 | | |
2015 | | bool |
2016 | | WebGPULimits::ToJSON(nsAString& aJSON) const |
2017 | 0 | { |
2018 | 0 | AutoJSAPI jsapi; |
2019 | 0 | jsapi.Init(); |
2020 | 0 | JSContext *cx = jsapi.cx(); |
2021 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
2022 | 0 | // because we'll only be creating objects, in ways that have no |
2023 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
2024 | 0 | // which likewise guarantees no side-effects for the sorts of |
2025 | 0 | // things we will pass it. |
2026 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
2027 | 0 | JS::Rooted<JS::Value> val(cx); |
2028 | 0 | if (!ToObjectInternal(cx, &val)) { |
2029 | 0 | return false; |
2030 | 0 | } |
2031 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
2032 | 0 | return StringifyToJSON(cx, obj, aJSON); |
2033 | 0 | } |
2034 | | |
2035 | | void |
2036 | | WebGPULimits::TraceDictionary(JSTracer* trc) |
2037 | 0 | { |
2038 | 0 | } |
2039 | | |
2040 | | WebGPULimits& |
2041 | | WebGPULimits::operator=(const WebGPULimits& aOther) |
2042 | 0 | { |
2043 | 0 | DictionaryBase::operator=(aOther); |
2044 | 0 | mMaxBindGroups.Reset(); |
2045 | 0 | if (aOther.mMaxBindGroups.WasPassed()) { |
2046 | 0 | mMaxBindGroups.Construct(aOther.mMaxBindGroups.Value()); |
2047 | 0 | } |
2048 | 0 | return *this; |
2049 | 0 | } |
2050 | | |
2051 | | namespace binding_detail { |
2052 | | } // namespace binding_detail |
2053 | | |
2054 | | |
2055 | | |
2056 | | WebGPUPipelineLayoutDescriptor::WebGPUPipelineLayoutDescriptor() |
2057 | 0 | { |
2058 | 0 | // Safe to pass a null context if we pass a null value |
2059 | 0 | Init(nullptr, JS::NullHandleValue); |
2060 | 0 | } |
2061 | | |
2062 | | |
2063 | | |
2064 | | bool |
2065 | | WebGPUPipelineLayoutDescriptor::InitIds(JSContext* cx, WebGPUPipelineLayoutDescriptorAtoms* atomsCache) |
2066 | 0 | { |
2067 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
2068 | 0 |
|
2069 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
2070 | 0 | // uninitialized. |
2071 | 0 | if (!atomsCache->bindGroupLayouts_id.init(cx, "bindGroupLayouts")) { |
2072 | 0 | return false; |
2073 | 0 | } |
2074 | 0 | return true; |
2075 | 0 | } |
2076 | | |
2077 | | bool |
2078 | | WebGPUPipelineLayoutDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
2079 | 0 | { |
2080 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
2081 | 0 | // Since in that case we will not have to do any property gets |
2082 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
2083 | 0 | // checkers by static analysis tools |
2084 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
2085 | 0 | WebGPUPipelineLayoutDescriptorAtoms* atomsCache = nullptr; |
2086 | 0 | if (cx) { |
2087 | 0 | atomsCache = GetAtomCache<WebGPUPipelineLayoutDescriptorAtoms>(cx); |
2088 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
2089 | 0 | return false; |
2090 | 0 | } |
2091 | 0 | } |
2092 | 0 | |
2093 | 0 | if (!IsConvertibleToDictionary(val)) { |
2094 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
2095 | 0 | } |
2096 | 0 | |
2097 | 0 | bool isNull = val.isNullOrUndefined(); |
2098 | 0 | // We only need these if !isNull, in which case we have |cx|. |
2099 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
2100 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
2101 | 0 | if (!isNull) { |
2102 | 0 | MOZ_ASSERT(cx); |
2103 | 0 | object.emplace(cx, &val.toObject()); |
2104 | 0 | temp.emplace(cx); |
2105 | 0 | } |
2106 | 0 | if (!isNull) { |
2107 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->bindGroupLayouts_id, temp.ptr())) { |
2108 | 0 | return false; |
2109 | 0 | } |
2110 | 0 | } |
2111 | 0 | if (!isNull && !temp->isUndefined()) { |
2112 | 0 | mBindGroupLayouts.Construct(); |
2113 | 0 | if (temp.ref().isObject()) { |
2114 | 0 | JS::ForOfIterator iter(cx); |
2115 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
2116 | 0 | return false; |
2117 | 0 | } |
2118 | 0 | if (!iter.valueIsIterable()) { |
2119 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'bindGroupLayouts' member of WebGPUPipelineLayoutDescriptor"); |
2120 | 0 | return false; |
2121 | 0 | } |
2122 | 0 | Sequence<OwningNonNull<mozilla::webgpu::BindGroupLayout>> &arr = (mBindGroupLayouts.Value()); |
2123 | 0 | JS::Rooted<JS::Value> temp(cx); |
2124 | 0 | while (true) { |
2125 | 0 | bool done; |
2126 | 0 | if (!iter.next(&temp, &done)) { |
2127 | 0 | return false; |
2128 | 0 | } |
2129 | 0 | if (done) { |
2130 | 0 | break; |
2131 | 0 | } |
2132 | 0 | OwningNonNull<mozilla::webgpu::BindGroupLayout>* slotPtr = arr.AppendElement(mozilla::fallible); |
2133 | 0 | if (!slotPtr) { |
2134 | 0 | JS_ReportOutOfMemory(cx); |
2135 | 0 | return false; |
2136 | 0 | } |
2137 | 0 | OwningNonNull<mozilla::webgpu::BindGroupLayout>& slot = *slotPtr; |
2138 | 0 | if (temp.isObject()) { |
2139 | 0 | static_assert(IsRefcounted<mozilla::webgpu::BindGroupLayout>::value, "We can only store refcounted classes.");{ |
2140 | 0 | nsresult rv = UnwrapObject<prototypes::id::WebGPUBindGroupLayout, mozilla::webgpu::BindGroupLayout>(&temp, slot); |
2141 | 0 | if (NS_FAILED(rv)) { |
2142 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of 'bindGroupLayouts' member of WebGPUPipelineLayoutDescriptor", "WebGPUBindGroupLayout"); |
2143 | 0 | return false; |
2144 | 0 | } |
2145 | 0 | } |
2146 | 0 | } else { |
2147 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of 'bindGroupLayouts' member of WebGPUPipelineLayoutDescriptor"); |
2148 | 0 | return false; |
2149 | 0 | } |
2150 | 0 | } |
2151 | 0 | } else { |
2152 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'bindGroupLayouts' member of WebGPUPipelineLayoutDescriptor"); |
2153 | 0 | return false; |
2154 | 0 | } |
2155 | 0 | mIsAnyMemberPresent = true; |
2156 | 0 | } |
2157 | 0 | return true; |
2158 | 0 | } |
2159 | | |
2160 | | bool |
2161 | | WebGPUPipelineLayoutDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
2162 | 0 | { |
2163 | 0 | WebGPUPipelineLayoutDescriptorAtoms* atomsCache = GetAtomCache<WebGPUPipelineLayoutDescriptorAtoms>(cx); |
2164 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
2165 | 0 | return false; |
2166 | 0 | } |
2167 | 0 | |
2168 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
2169 | 0 | if (!obj) { |
2170 | 0 | return false; |
2171 | 0 | } |
2172 | 0 | rval.set(JS::ObjectValue(*obj)); |
2173 | 0 |
|
2174 | 0 | if (mBindGroupLayouts.WasPassed()) { |
2175 | 0 | do { |
2176 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2177 | 0 | JS::Rooted<JS::Value> temp(cx); |
2178 | 0 | Sequence<OwningNonNull<mozilla::webgpu::BindGroupLayout>> const & currentValue = mBindGroupLayouts.InternalValue(); |
2179 | 0 |
|
2180 | 0 | uint32_t length = currentValue.Length(); |
2181 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
2182 | 0 | if (!returnArray) { |
2183 | 0 | return false; |
2184 | 0 | } |
2185 | 0 | // Scope for 'tmp' |
2186 | 0 | { |
2187 | 0 | JS::Rooted<JS::Value> tmp(cx); |
2188 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
2189 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
2190 | 0 | // are different ways to succeed at wrapping the object. |
2191 | 0 | do { |
2192 | 0 | if (!GetOrCreateDOMReflector(cx, currentValue[sequenceIdx0], &tmp)) { |
2193 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
2194 | 0 | return false; |
2195 | 0 | } |
2196 | 0 | break; |
2197 | 0 | } while (false); |
2198 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
2199 | 0 | JSPROP_ENUMERATE)) { |
2200 | 0 | return false; |
2201 | 0 | } |
2202 | 0 | } |
2203 | 0 | } |
2204 | 0 | temp.setObject(*returnArray); |
2205 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->bindGroupLayouts_id, temp, JSPROP_ENUMERATE)) { |
2206 | 0 | return false; |
2207 | 0 | } |
2208 | 0 | break; |
2209 | 0 | } while(false); |
2210 | 0 | } |
2211 | 0 |
|
2212 | 0 | return true; |
2213 | 0 | } |
2214 | | |
2215 | | void |
2216 | | WebGPUPipelineLayoutDescriptor::TraceDictionary(JSTracer* trc) |
2217 | 0 | { |
2218 | 0 | } |
2219 | | |
2220 | | |
2221 | | |
2222 | | WebGPUPipelineLayoutDescriptor& |
2223 | | WebGPUPipelineLayoutDescriptor::operator=(const WebGPUPipelineLayoutDescriptor& aOther) |
2224 | 0 | { |
2225 | 0 | DictionaryBase::operator=(aOther); |
2226 | 0 | mBindGroupLayouts.Reset(); |
2227 | 0 | if (aOther.mBindGroupLayouts.WasPassed()) { |
2228 | 0 | mBindGroupLayouts.Construct(aOther.mBindGroupLayouts.Value()); |
2229 | 0 | } |
2230 | 0 | return *this; |
2231 | 0 | } |
2232 | | |
2233 | | namespace binding_detail { |
2234 | | } // namespace binding_detail |
2235 | | |
2236 | | |
2237 | | |
2238 | | WebGPUPipelineStageDescriptor::WebGPUPipelineStageDescriptor() |
2239 | 0 | { |
2240 | 0 | // Safe to pass a null context if we pass a null value |
2241 | 0 | Init(nullptr, JS::NullHandleValue); |
2242 | 0 | } |
2243 | | |
2244 | | |
2245 | | |
2246 | | bool |
2247 | | WebGPUPipelineStageDescriptor::InitIds(JSContext* cx, WebGPUPipelineStageDescriptorAtoms* atomsCache) |
2248 | 0 | { |
2249 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
2250 | 0 |
|
2251 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
2252 | 0 | // uninitialized. |
2253 | 0 | if (!atomsCache->stage_id.init(cx, "stage") || |
2254 | 0 | !atomsCache->shaderModule_id.init(cx, "shaderModule") || |
2255 | 0 | !atomsCache->entryPoint_id.init(cx, "entryPoint")) { |
2256 | 0 | return false; |
2257 | 0 | } |
2258 | 0 | return true; |
2259 | 0 | } |
2260 | | |
2261 | | bool |
2262 | | WebGPUPipelineStageDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
2263 | 0 | { |
2264 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
2265 | 0 | // Since in that case we will not have to do any property gets |
2266 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
2267 | 0 | // checkers by static analysis tools |
2268 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
2269 | 0 | WebGPUPipelineStageDescriptorAtoms* atomsCache = nullptr; |
2270 | 0 | if (cx) { |
2271 | 0 | atomsCache = GetAtomCache<WebGPUPipelineStageDescriptorAtoms>(cx); |
2272 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
2273 | 0 | return false; |
2274 | 0 | } |
2275 | 0 | } |
2276 | 0 | |
2277 | 0 | if (!IsConvertibleToDictionary(val)) { |
2278 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
2279 | 0 | } |
2280 | 0 | |
2281 | 0 | bool isNull = val.isNullOrUndefined(); |
2282 | 0 | // We only need these if !isNull, in which case we have |cx|. |
2283 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
2284 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
2285 | 0 | if (!isNull) { |
2286 | 0 | MOZ_ASSERT(cx); |
2287 | 0 | object.emplace(cx, &val.toObject()); |
2288 | 0 | temp.emplace(cx); |
2289 | 0 | } |
2290 | 0 | if (!isNull) { |
2291 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->entryPoint_id, temp.ptr())) { |
2292 | 0 | return false; |
2293 | 0 | } |
2294 | 0 | } |
2295 | 0 | if (!isNull && !temp->isUndefined()) { |
2296 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mEntryPoint)) { |
2297 | 0 | return false; |
2298 | 0 | } |
2299 | 0 | mIsAnyMemberPresent = true; |
2300 | 0 | } else if (cx) { |
2301 | 0 | // Don't error out if we have no cx. In that |
2302 | 0 | // situation the caller is default-constructing us and we'll |
2303 | 0 | // just assume they know what they're doing. |
2304 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
2305 | 0 | "'entryPoint' member of WebGPUPipelineStageDescriptor"); |
2306 | 0 | } |
2307 | 0 | |
2308 | 0 | if (!isNull) { |
2309 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->shaderModule_id, temp.ptr())) { |
2310 | 0 | return false; |
2311 | 0 | } |
2312 | 0 | } |
2313 | 0 | if (!isNull && !temp->isUndefined()) { |
2314 | 0 | if (temp.ref().isObject()) { |
2315 | 0 | static_assert(IsRefcounted<mozilla::webgpu::ShaderModule>::value, "We can only store refcounted classes.");{ |
2316 | 0 | nsresult rv = UnwrapObject<prototypes::id::WebGPUShaderModule, mozilla::webgpu::ShaderModule>(temp.ptr(), mShaderModule); |
2317 | 0 | if (NS_FAILED(rv)) { |
2318 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'shaderModule' member of WebGPUPipelineStageDescriptor", "WebGPUShaderModule"); |
2319 | 0 | return false; |
2320 | 0 | } |
2321 | 0 | } |
2322 | 0 | } else { |
2323 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'shaderModule' member of WebGPUPipelineStageDescriptor"); |
2324 | 0 | return false; |
2325 | 0 | } |
2326 | 0 | mIsAnyMemberPresent = true; |
2327 | 0 | } else if (cx) { |
2328 | 0 | // Don't error out if we have no cx. In that |
2329 | 0 | // situation the caller is default-constructing us and we'll |
2330 | 0 | // just assume they know what they're doing. |
2331 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
2332 | 0 | "'shaderModule' member of WebGPUPipelineStageDescriptor"); |
2333 | 0 | } |
2334 | 0 | |
2335 | 0 | if (!isNull) { |
2336 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->stage_id, temp.ptr())) { |
2337 | 0 | return false; |
2338 | 0 | } |
2339 | 0 | } |
2340 | 0 | if (!isNull && !temp->isUndefined()) { |
2341 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &mStage)) { |
2342 | 0 | return false; |
2343 | 0 | } |
2344 | 0 | mIsAnyMemberPresent = true; |
2345 | 0 | } else if (cx) { |
2346 | 0 | // Don't error out if we have no cx. In that |
2347 | 0 | // situation the caller is default-constructing us and we'll |
2348 | 0 | // just assume they know what they're doing. |
2349 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
2350 | 0 | "'stage' member of WebGPUPipelineStageDescriptor"); |
2351 | 0 | } |
2352 | 0 | return true; |
2353 | 0 | } |
2354 | | |
2355 | | bool |
2356 | | WebGPUPipelineStageDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
2357 | 0 | { |
2358 | 0 | WebGPUPipelineStageDescriptorAtoms* atomsCache = GetAtomCache<WebGPUPipelineStageDescriptorAtoms>(cx); |
2359 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
2360 | 0 | return false; |
2361 | 0 | } |
2362 | 0 | |
2363 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
2364 | 0 | if (!obj) { |
2365 | 0 | return false; |
2366 | 0 | } |
2367 | 0 | rval.set(JS::ObjectValue(*obj)); |
2368 | 0 |
|
2369 | 0 | do { |
2370 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2371 | 0 | JS::Rooted<JS::Value> temp(cx); |
2372 | 0 | nsString const & currentValue = mEntryPoint; |
2373 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
2374 | 0 | return false; |
2375 | 0 | } |
2376 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->entryPoint_id, temp, JSPROP_ENUMERATE)) { |
2377 | 0 | return false; |
2378 | 0 | } |
2379 | 0 | break; |
2380 | 0 | } while(false); |
2381 | 0 |
|
2382 | 0 | do { |
2383 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2384 | 0 | JS::Rooted<JS::Value> temp(cx); |
2385 | 0 | OwningNonNull<mozilla::webgpu::ShaderModule> const & currentValue = mShaderModule; |
2386 | 0 | if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) { |
2387 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
2388 | 0 | return false; |
2389 | 0 | } |
2390 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->shaderModule_id, temp, JSPROP_ENUMERATE)) { |
2391 | 0 | return false; |
2392 | 0 | } |
2393 | 0 | break; |
2394 | 0 | } while(false); |
2395 | 0 |
|
2396 | 0 | do { |
2397 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2398 | 0 | JS::Rooted<JS::Value> temp(cx); |
2399 | 0 | uint32_t const & currentValue = mStage; |
2400 | 0 | temp.setNumber(currentValue); |
2401 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->stage_id, temp, JSPROP_ENUMERATE)) { |
2402 | 0 | return false; |
2403 | 0 | } |
2404 | 0 | break; |
2405 | 0 | } while(false); |
2406 | 0 |
|
2407 | 0 | return true; |
2408 | 0 | } |
2409 | | |
2410 | | void |
2411 | | WebGPUPipelineStageDescriptor::TraceDictionary(JSTracer* trc) |
2412 | 0 | { |
2413 | 0 | } |
2414 | | |
2415 | | |
2416 | | |
2417 | | WebGPUPipelineStageDescriptor& |
2418 | | WebGPUPipelineStageDescriptor::operator=(const WebGPUPipelineStageDescriptor& aOther) |
2419 | 0 | { |
2420 | 0 | DictionaryBase::operator=(aOther); |
2421 | 0 | mEntryPoint = aOther.mEntryPoint; |
2422 | 0 | mShaderModule = aOther.mShaderModule; |
2423 | 0 | mStage = aOther.mStage; |
2424 | 0 | return *this; |
2425 | 0 | } |
2426 | | |
2427 | | namespace binding_detail { |
2428 | | } // namespace binding_detail |
2429 | | |
2430 | | |
2431 | | |
2432 | | WebGPURenderPassAttachmentDescriptor::WebGPURenderPassAttachmentDescriptor() |
2433 | 0 | { |
2434 | 0 | // Safe to pass a null context if we pass a null value |
2435 | 0 | Init(nullptr, JS::NullHandleValue); |
2436 | 0 | } |
2437 | | |
2438 | | |
2439 | | |
2440 | | bool |
2441 | | WebGPURenderPassAttachmentDescriptor::InitIds(JSContext* cx, WebGPURenderPassAttachmentDescriptorAtoms* atomsCache) |
2442 | 0 | { |
2443 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
2444 | 0 |
|
2445 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
2446 | 0 | // uninitialized. |
2447 | 0 | if (!atomsCache->storeOp_id.init(cx, "storeOp") || |
2448 | 0 | !atomsCache->loadOp_id.init(cx, "loadOp") || |
2449 | 0 | !atomsCache->attachment_id.init(cx, "attachment")) { |
2450 | 0 | return false; |
2451 | 0 | } |
2452 | 0 | return true; |
2453 | 0 | } |
2454 | | |
2455 | | bool |
2456 | | WebGPURenderPassAttachmentDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
2457 | 0 | { |
2458 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
2459 | 0 | // Since in that case we will not have to do any property gets |
2460 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
2461 | 0 | // checkers by static analysis tools |
2462 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
2463 | 0 | WebGPURenderPassAttachmentDescriptorAtoms* atomsCache = nullptr; |
2464 | 0 | if (cx) { |
2465 | 0 | atomsCache = GetAtomCache<WebGPURenderPassAttachmentDescriptorAtoms>(cx); |
2466 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
2467 | 0 | return false; |
2468 | 0 | } |
2469 | 0 | } |
2470 | 0 | |
2471 | 0 | if (!IsConvertibleToDictionary(val)) { |
2472 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
2473 | 0 | } |
2474 | 0 | |
2475 | 0 | bool isNull = val.isNullOrUndefined(); |
2476 | 0 | // We only need these if !isNull, in which case we have |cx|. |
2477 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
2478 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
2479 | 0 | if (!isNull) { |
2480 | 0 | MOZ_ASSERT(cx); |
2481 | 0 | object.emplace(cx, &val.toObject()); |
2482 | 0 | temp.emplace(cx); |
2483 | 0 | } |
2484 | 0 | if (!isNull) { |
2485 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->attachment_id, temp.ptr())) { |
2486 | 0 | return false; |
2487 | 0 | } |
2488 | 0 | } |
2489 | 0 | if (!isNull && !temp->isUndefined()) { |
2490 | 0 | mAttachment.Construct(); |
2491 | 0 | if (temp.ref().isObject()) { |
2492 | 0 | static_assert(IsRefcounted<mozilla::webgpu::TextureView>::value, "We can only store refcounted classes.");{ |
2493 | 0 | nsresult rv = UnwrapObject<prototypes::id::WebGPUTextureView, mozilla::webgpu::TextureView>(temp.ptr(), (mAttachment.Value())); |
2494 | 0 | if (NS_FAILED(rv)) { |
2495 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'attachment' member of WebGPURenderPassAttachmentDescriptor", "WebGPUTextureView"); |
2496 | 0 | return false; |
2497 | 0 | } |
2498 | 0 | } |
2499 | 0 | } else { |
2500 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'attachment' member of WebGPURenderPassAttachmentDescriptor"); |
2501 | 0 | return false; |
2502 | 0 | } |
2503 | 0 | mIsAnyMemberPresent = true; |
2504 | 0 | } |
2505 | 0 |
|
2506 | 0 | if (!isNull) { |
2507 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->loadOp_id, temp.ptr())) { |
2508 | 0 | return false; |
2509 | 0 | } |
2510 | 0 | } |
2511 | 0 | if (!isNull && !temp->isUndefined()) { |
2512 | 0 | mLoadOp.Construct(); |
2513 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mLoadOp.Value()))) { |
2514 | 0 | return false; |
2515 | 0 | } |
2516 | 0 | mIsAnyMemberPresent = true; |
2517 | 0 | } |
2518 | 0 |
|
2519 | 0 | if (!isNull) { |
2520 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->storeOp_id, temp.ptr())) { |
2521 | 0 | return false; |
2522 | 0 | } |
2523 | 0 | } |
2524 | 0 | if (!isNull && !temp->isUndefined()) { |
2525 | 0 | mStoreOp.Construct(); |
2526 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mStoreOp.Value()))) { |
2527 | 0 | return false; |
2528 | 0 | } |
2529 | 0 | mIsAnyMemberPresent = true; |
2530 | 0 | } |
2531 | 0 | return true; |
2532 | 0 | } |
2533 | | |
2534 | | bool |
2535 | | WebGPURenderPassAttachmentDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
2536 | 0 | { |
2537 | 0 | WebGPURenderPassAttachmentDescriptorAtoms* atomsCache = GetAtomCache<WebGPURenderPassAttachmentDescriptorAtoms>(cx); |
2538 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
2539 | 0 | return false; |
2540 | 0 | } |
2541 | 0 | |
2542 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
2543 | 0 | if (!obj) { |
2544 | 0 | return false; |
2545 | 0 | } |
2546 | 0 | rval.set(JS::ObjectValue(*obj)); |
2547 | 0 |
|
2548 | 0 | if (mAttachment.WasPassed()) { |
2549 | 0 | do { |
2550 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2551 | 0 | JS::Rooted<JS::Value> temp(cx); |
2552 | 0 | OwningNonNull<mozilla::webgpu::TextureView> const & currentValue = mAttachment.InternalValue(); |
2553 | 0 | if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) { |
2554 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
2555 | 0 | return false; |
2556 | 0 | } |
2557 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->attachment_id, temp, JSPROP_ENUMERATE)) { |
2558 | 0 | return false; |
2559 | 0 | } |
2560 | 0 | break; |
2561 | 0 | } while(false); |
2562 | 0 | } |
2563 | 0 |
|
2564 | 0 | if (mLoadOp.WasPassed()) { |
2565 | 0 | do { |
2566 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2567 | 0 | JS::Rooted<JS::Value> temp(cx); |
2568 | 0 | uint32_t const & currentValue = mLoadOp.InternalValue(); |
2569 | 0 | temp.setNumber(currentValue); |
2570 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->loadOp_id, temp, JSPROP_ENUMERATE)) { |
2571 | 0 | return false; |
2572 | 0 | } |
2573 | 0 | break; |
2574 | 0 | } while(false); |
2575 | 0 | } |
2576 | 0 |
|
2577 | 0 | if (mStoreOp.WasPassed()) { |
2578 | 0 | do { |
2579 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2580 | 0 | JS::Rooted<JS::Value> temp(cx); |
2581 | 0 | uint32_t const & currentValue = mStoreOp.InternalValue(); |
2582 | 0 | temp.setNumber(currentValue); |
2583 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->storeOp_id, temp, JSPROP_ENUMERATE)) { |
2584 | 0 | return false; |
2585 | 0 | } |
2586 | 0 | break; |
2587 | 0 | } while(false); |
2588 | 0 | } |
2589 | 0 |
|
2590 | 0 | return true; |
2591 | 0 | } |
2592 | | |
2593 | | void |
2594 | | WebGPURenderPassAttachmentDescriptor::TraceDictionary(JSTracer* trc) |
2595 | 0 | { |
2596 | 0 | } |
2597 | | |
2598 | | |
2599 | | |
2600 | | WebGPURenderPassAttachmentDescriptor& |
2601 | | WebGPURenderPassAttachmentDescriptor::operator=(const WebGPURenderPassAttachmentDescriptor& aOther) |
2602 | 0 | { |
2603 | 0 | DictionaryBase::operator=(aOther); |
2604 | 0 | mAttachment.Reset(); |
2605 | 0 | if (aOther.mAttachment.WasPassed()) { |
2606 | 0 | mAttachment.Construct(aOther.mAttachment.Value()); |
2607 | 0 | } |
2608 | 0 | mLoadOp.Reset(); |
2609 | 0 | if (aOther.mLoadOp.WasPassed()) { |
2610 | 0 | mLoadOp.Construct(aOther.mLoadOp.Value()); |
2611 | 0 | } |
2612 | 0 | mStoreOp.Reset(); |
2613 | 0 | if (aOther.mStoreOp.WasPassed()) { |
2614 | 0 | mStoreOp.Construct(aOther.mStoreOp.Value()); |
2615 | 0 | } |
2616 | 0 | return *this; |
2617 | 0 | } |
2618 | | |
2619 | | namespace binding_detail { |
2620 | | } // namespace binding_detail |
2621 | | |
2622 | | |
2623 | | |
2624 | | WebGPUSamplerDescriptor::WebGPUSamplerDescriptor() |
2625 | 0 | { |
2626 | 0 | // Safe to pass a null context if we pass a null value |
2627 | 0 | Init(nullptr, JS::NullHandleValue); |
2628 | 0 | } |
2629 | | |
2630 | | |
2631 | | |
2632 | | bool |
2633 | | WebGPUSamplerDescriptor::InitIds(JSContext* cx, WebGPUSamplerDescriptorAtoms* atomsCache) |
2634 | 0 | { |
2635 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
2636 | 0 |
|
2637 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
2638 | 0 | // uninitialized. |
2639 | 0 | if (!atomsCache->mipmapFilter_id.init(cx, "mipmapFilter") || |
2640 | 0 | !atomsCache->minFilter_id.init(cx, "minFilter") || |
2641 | 0 | !atomsCache->magFilter_id.init(cx, "magFilter")) { |
2642 | 0 | return false; |
2643 | 0 | } |
2644 | 0 | return true; |
2645 | 0 | } |
2646 | | |
2647 | | bool |
2648 | | WebGPUSamplerDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
2649 | 0 | { |
2650 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
2651 | 0 | // Since in that case we will not have to do any property gets |
2652 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
2653 | 0 | // checkers by static analysis tools |
2654 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
2655 | 0 | WebGPUSamplerDescriptorAtoms* atomsCache = nullptr; |
2656 | 0 | if (cx) { |
2657 | 0 | atomsCache = GetAtomCache<WebGPUSamplerDescriptorAtoms>(cx); |
2658 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
2659 | 0 | return false; |
2660 | 0 | } |
2661 | 0 | } |
2662 | 0 | |
2663 | 0 | if (!IsConvertibleToDictionary(val)) { |
2664 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
2665 | 0 | } |
2666 | 0 | |
2667 | 0 | bool isNull = val.isNullOrUndefined(); |
2668 | 0 | // We only need these if !isNull, in which case we have |cx|. |
2669 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
2670 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
2671 | 0 | if (!isNull) { |
2672 | 0 | MOZ_ASSERT(cx); |
2673 | 0 | object.emplace(cx, &val.toObject()); |
2674 | 0 | temp.emplace(cx); |
2675 | 0 | } |
2676 | 0 | if (!isNull) { |
2677 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->magFilter_id, temp.ptr())) { |
2678 | 0 | return false; |
2679 | 0 | } |
2680 | 0 | } |
2681 | 0 | if (!isNull && !temp->isUndefined()) { |
2682 | 0 | mMagFilter.Construct(); |
2683 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mMagFilter.Value()))) { |
2684 | 0 | return false; |
2685 | 0 | } |
2686 | 0 | mIsAnyMemberPresent = true; |
2687 | 0 | } |
2688 | 0 |
|
2689 | 0 | if (!isNull) { |
2690 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->minFilter_id, temp.ptr())) { |
2691 | 0 | return false; |
2692 | 0 | } |
2693 | 0 | } |
2694 | 0 | if (!isNull && !temp->isUndefined()) { |
2695 | 0 | mMinFilter.Construct(); |
2696 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mMinFilter.Value()))) { |
2697 | 0 | return false; |
2698 | 0 | } |
2699 | 0 | mIsAnyMemberPresent = true; |
2700 | 0 | } |
2701 | 0 |
|
2702 | 0 | if (!isNull) { |
2703 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->mipmapFilter_id, temp.ptr())) { |
2704 | 0 | return false; |
2705 | 0 | } |
2706 | 0 | } |
2707 | 0 | if (!isNull && !temp->isUndefined()) { |
2708 | 0 | mMipmapFilter.Construct(); |
2709 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mMipmapFilter.Value()))) { |
2710 | 0 | return false; |
2711 | 0 | } |
2712 | 0 | mIsAnyMemberPresent = true; |
2713 | 0 | } |
2714 | 0 | return true; |
2715 | 0 | } |
2716 | | |
2717 | | bool |
2718 | | WebGPUSamplerDescriptor::Init(const nsAString& aJSON) |
2719 | 0 | { |
2720 | 0 | AutoJSAPI jsapi; |
2721 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
2722 | 0 | if (!cleanGlobal) { |
2723 | 0 | return false; |
2724 | 0 | } |
2725 | 0 | if (!jsapi.Init(cleanGlobal)) { |
2726 | 0 | return false; |
2727 | 0 | } |
2728 | 0 | JSContext* cx = jsapi.cx(); |
2729 | 0 | JS::Rooted<JS::Value> json(cx); |
2730 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
2731 | 0 | NS_ENSURE_TRUE(ok, false); |
2732 | 0 | return Init(cx, json); |
2733 | 0 | } |
2734 | | |
2735 | | bool |
2736 | | WebGPUSamplerDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
2737 | 0 | { |
2738 | 0 | WebGPUSamplerDescriptorAtoms* atomsCache = GetAtomCache<WebGPUSamplerDescriptorAtoms>(cx); |
2739 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
2740 | 0 | return false; |
2741 | 0 | } |
2742 | 0 | |
2743 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
2744 | 0 | if (!obj) { |
2745 | 0 | return false; |
2746 | 0 | } |
2747 | 0 | rval.set(JS::ObjectValue(*obj)); |
2748 | 0 |
|
2749 | 0 | if (mMagFilter.WasPassed()) { |
2750 | 0 | do { |
2751 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2752 | 0 | JS::Rooted<JS::Value> temp(cx); |
2753 | 0 | uint32_t const & currentValue = mMagFilter.InternalValue(); |
2754 | 0 | temp.setNumber(currentValue); |
2755 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->magFilter_id, temp, JSPROP_ENUMERATE)) { |
2756 | 0 | return false; |
2757 | 0 | } |
2758 | 0 | break; |
2759 | 0 | } while(false); |
2760 | 0 | } |
2761 | 0 |
|
2762 | 0 | if (mMinFilter.WasPassed()) { |
2763 | 0 | do { |
2764 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2765 | 0 | JS::Rooted<JS::Value> temp(cx); |
2766 | 0 | uint32_t const & currentValue = mMinFilter.InternalValue(); |
2767 | 0 | temp.setNumber(currentValue); |
2768 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->minFilter_id, temp, JSPROP_ENUMERATE)) { |
2769 | 0 | return false; |
2770 | 0 | } |
2771 | 0 | break; |
2772 | 0 | } while(false); |
2773 | 0 | } |
2774 | 0 |
|
2775 | 0 | if (mMipmapFilter.WasPassed()) { |
2776 | 0 | do { |
2777 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
2778 | 0 | JS::Rooted<JS::Value> temp(cx); |
2779 | 0 | uint32_t const & currentValue = mMipmapFilter.InternalValue(); |
2780 | 0 | temp.setNumber(currentValue); |
2781 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->mipmapFilter_id, temp, JSPROP_ENUMERATE)) { |
2782 | 0 | return false; |
2783 | 0 | } |
2784 | 0 | break; |
2785 | 0 | } while(false); |
2786 | 0 | } |
2787 | 0 |
|
2788 | 0 | return true; |
2789 | 0 | } |
2790 | | |
2791 | | bool |
2792 | | WebGPUSamplerDescriptor::ToJSON(nsAString& aJSON) const |
2793 | 0 | { |
2794 | 0 | AutoJSAPI jsapi; |
2795 | 0 | jsapi.Init(); |
2796 | 0 | JSContext *cx = jsapi.cx(); |
2797 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
2798 | 0 | // because we'll only be creating objects, in ways that have no |
2799 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
2800 | 0 | // which likewise guarantees no side-effects for the sorts of |
2801 | 0 | // things we will pass it. |
2802 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
2803 | 0 | JS::Rooted<JS::Value> val(cx); |
2804 | 0 | if (!ToObjectInternal(cx, &val)) { |
2805 | 0 | return false; |
2806 | 0 | } |
2807 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
2808 | 0 | return StringifyToJSON(cx, obj, aJSON); |
2809 | 0 | } |
2810 | | |
2811 | | void |
2812 | | WebGPUSamplerDescriptor::TraceDictionary(JSTracer* trc) |
2813 | 0 | { |
2814 | 0 | } |
2815 | | |
2816 | | WebGPUSamplerDescriptor& |
2817 | | WebGPUSamplerDescriptor::operator=(const WebGPUSamplerDescriptor& aOther) |
2818 | 0 | { |
2819 | 0 | DictionaryBase::operator=(aOther); |
2820 | 0 | mMagFilter.Reset(); |
2821 | 0 | if (aOther.mMagFilter.WasPassed()) { |
2822 | 0 | mMagFilter.Construct(aOther.mMagFilter.Value()); |
2823 | 0 | } |
2824 | 0 | mMinFilter.Reset(); |
2825 | 0 | if (aOther.mMinFilter.WasPassed()) { |
2826 | 0 | mMinFilter.Construct(aOther.mMinFilter.Value()); |
2827 | 0 | } |
2828 | 0 | mMipmapFilter.Reset(); |
2829 | 0 | if (aOther.mMipmapFilter.WasPassed()) { |
2830 | 0 | mMipmapFilter.Construct(aOther.mMipmapFilter.Value()); |
2831 | 0 | } |
2832 | 0 | return *this; |
2833 | 0 | } |
2834 | | |
2835 | | namespace binding_detail { |
2836 | | } // namespace binding_detail |
2837 | | |
2838 | | |
2839 | | bool |
2840 | | WebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const |
2841 | 0 | { |
2842 | 0 | switch (mType) { |
2843 | 0 | case eUninitialized: { |
2844 | 0 | return false; |
2845 | 0 | break; |
2846 | 0 | } |
2847 | 0 | case eWebGPUSampler: { |
2848 | 0 | if (!GetOrCreateDOMReflector(cx, mValue.mWebGPUSampler.Value(), rval)) { |
2849 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
2850 | 0 | return false; |
2851 | 0 | } |
2852 | 0 | return true; |
2853 | 0 | break; |
2854 | 0 | } |
2855 | 0 | case eWebGPUTextureView: { |
2856 | 0 | if (!GetOrCreateDOMReflector(cx, mValue.mWebGPUTextureView.Value(), rval)) { |
2857 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
2858 | 0 | return false; |
2859 | 0 | } |
2860 | 0 | return true; |
2861 | 0 | break; |
2862 | 0 | } |
2863 | 0 | case eWebGPUBufferBinding: { |
2864 | 0 | if (!mValue.mWebGPUBufferBinding.Value().ToObjectInternal(cx, rval)) { |
2865 | 0 | return false; |
2866 | 0 | } |
2867 | 0 | return true; |
2868 | 0 | break; |
2869 | 0 | } |
2870 | 0 | default: { |
2871 | 0 | return false; |
2872 | 0 | break; |
2873 | 0 | } |
2874 | 0 | } |
2875 | 0 | |
2876 | 0 | return false; |
2877 | 0 | } |
2878 | | |
2879 | | |
2880 | | OwningNonNull<mozilla::webgpu::Sampler>& |
2881 | | OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding::RawSetAsWebGPUSampler() |
2882 | 0 | { |
2883 | 0 | if (mType == eWebGPUSampler) { |
2884 | 0 | return mValue.mWebGPUSampler.Value(); |
2885 | 0 | } |
2886 | 0 | MOZ_ASSERT(mType == eUninitialized); |
2887 | 0 | mType = eWebGPUSampler; |
2888 | 0 | return mValue.mWebGPUSampler.SetValue(); |
2889 | 0 | } |
2890 | | |
2891 | | OwningNonNull<mozilla::webgpu::Sampler>& |
2892 | | OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding::SetAsWebGPUSampler() |
2893 | 0 | { |
2894 | 0 | if (mType == eWebGPUSampler) { |
2895 | 0 | return mValue.mWebGPUSampler.Value(); |
2896 | 0 | } |
2897 | 0 | Uninit(); |
2898 | 0 | mType = eWebGPUSampler; |
2899 | 0 | return mValue.mWebGPUSampler.SetValue(); |
2900 | 0 | } |
2901 | | |
2902 | | bool |
2903 | | OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding::TrySetToWebGPUSampler(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl) |
2904 | 0 | { |
2905 | 0 | tryNext = false; |
2906 | 0 | { // scope for memberSlot |
2907 | 0 | OwningNonNull<mozilla::webgpu::Sampler>& memberSlot = RawSetAsWebGPUSampler(); |
2908 | 0 | static_assert(IsRefcounted<mozilla::webgpu::Sampler>::value, "We can only store refcounted classes.");{ |
2909 | 0 | nsresult rv = UnwrapObject<prototypes::id::WebGPUSampler, mozilla::webgpu::Sampler>(value, memberSlot); |
2910 | 0 | if (NS_FAILED(rv)) { |
2911 | 0 | DestroyWebGPUSampler(); |
2912 | 0 | tryNext = true; |
2913 | 0 | return true; |
2914 | 0 | } |
2915 | 0 | } |
2916 | 0 | } |
2917 | 0 | return true; |
2918 | 0 | } |
2919 | | |
2920 | | void |
2921 | | OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding::DestroyWebGPUSampler() |
2922 | 0 | { |
2923 | 0 | MOZ_ASSERT(IsWebGPUSampler(), "Wrong type!"); |
2924 | 0 | mValue.mWebGPUSampler.Destroy(); |
2925 | 0 | mType = eUninitialized; |
2926 | 0 | } |
2927 | | |
2928 | | |
2929 | | |
2930 | | |
2931 | | OwningNonNull<mozilla::webgpu::TextureView>& |
2932 | | OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding::RawSetAsWebGPUTextureView() |
2933 | 0 | { |
2934 | 0 | if (mType == eWebGPUTextureView) { |
2935 | 0 | return mValue.mWebGPUTextureView.Value(); |
2936 | 0 | } |
2937 | 0 | MOZ_ASSERT(mType == eUninitialized); |
2938 | 0 | mType = eWebGPUTextureView; |
2939 | 0 | return mValue.mWebGPUTextureView.SetValue(); |
2940 | 0 | } |
2941 | | |
2942 | | OwningNonNull<mozilla::webgpu::TextureView>& |
2943 | | OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding::SetAsWebGPUTextureView() |
2944 | 0 | { |
2945 | 0 | if (mType == eWebGPUTextureView) { |
2946 | 0 | return mValue.mWebGPUTextureView.Value(); |
2947 | 0 | } |
2948 | 0 | Uninit(); |
2949 | 0 | mType = eWebGPUTextureView; |
2950 | 0 | return mValue.mWebGPUTextureView.SetValue(); |
2951 | 0 | } |
2952 | | |
2953 | | bool |
2954 | | OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding::TrySetToWebGPUTextureView(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl) |
2955 | 0 | { |
2956 | 0 | tryNext = false; |
2957 | 0 | { // scope for memberSlot |
2958 | 0 | OwningNonNull<mozilla::webgpu::TextureView>& memberSlot = RawSetAsWebGPUTextureView(); |
2959 | 0 | static_assert(IsRefcounted<mozilla::webgpu::TextureView>::value, "We can only store refcounted classes.");{ |
2960 | 0 | nsresult rv = UnwrapObject<prototypes::id::WebGPUTextureView, mozilla::webgpu::TextureView>(value, memberSlot); |
2961 | 0 | if (NS_FAILED(rv)) { |
2962 | 0 | DestroyWebGPUTextureView(); |
2963 | 0 | tryNext = true; |
2964 | 0 | return true; |
2965 | 0 | } |
2966 | 0 | } |
2967 | 0 | } |
2968 | 0 | return true; |
2969 | 0 | } |
2970 | | |
2971 | | void |
2972 | | OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding::DestroyWebGPUTextureView() |
2973 | 0 | { |
2974 | 0 | MOZ_ASSERT(IsWebGPUTextureView(), "Wrong type!"); |
2975 | 0 | mValue.mWebGPUTextureView.Destroy(); |
2976 | 0 | mType = eUninitialized; |
2977 | 0 | } |
2978 | | |
2979 | | |
2980 | | |
2981 | | |
2982 | | WebGPUBufferBinding& |
2983 | | OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding::RawSetAsWebGPUBufferBinding() |
2984 | 0 | { |
2985 | 0 | if (mType == eWebGPUBufferBinding) { |
2986 | 0 | return mValue.mWebGPUBufferBinding.Value(); |
2987 | 0 | } |
2988 | 0 | MOZ_ASSERT(mType == eUninitialized); |
2989 | 0 | mType = eWebGPUBufferBinding; |
2990 | 0 | return mValue.mWebGPUBufferBinding.SetValue(); |
2991 | 0 | } |
2992 | | |
2993 | | WebGPUBufferBinding& |
2994 | | OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding::SetAsWebGPUBufferBinding() |
2995 | 0 | { |
2996 | 0 | if (mType == eWebGPUBufferBinding) { |
2997 | 0 | return mValue.mWebGPUBufferBinding.Value(); |
2998 | 0 | } |
2999 | 0 | Uninit(); |
3000 | 0 | mType = eWebGPUBufferBinding; |
3001 | 0 | return mValue.mWebGPUBufferBinding.SetValue(); |
3002 | 0 | } |
3003 | | |
3004 | | bool |
3005 | | OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding::TrySetToWebGPUBufferBinding(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl) |
3006 | 0 | { |
3007 | 0 | tryNext = false; |
3008 | 0 | { // scope for memberSlot |
3009 | 0 | WebGPUBufferBinding& memberSlot = RawSetAsWebGPUBufferBinding(); |
3010 | 0 | if (!IsConvertibleToDictionary(value)) { |
3011 | 0 | DestroyWebGPUBufferBinding(); |
3012 | 0 | tryNext = true; |
3013 | 0 | return true; |
3014 | 0 | } |
3015 | 0 | if (!memberSlot.Init(cx, value, "Member of WebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding", passedToJSImpl)) { |
3016 | 0 | return false; |
3017 | 0 | } |
3018 | 0 | } |
3019 | 0 | return true; |
3020 | 0 | } |
3021 | | |
3022 | | void |
3023 | | OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding::DestroyWebGPUBufferBinding() |
3024 | 0 | { |
3025 | 0 | MOZ_ASSERT(IsWebGPUBufferBinding(), "Wrong type!"); |
3026 | 0 | mValue.mWebGPUBufferBinding.Destroy(); |
3027 | 0 | mType = eUninitialized; |
3028 | 0 | } |
3029 | | |
3030 | | |
3031 | | |
3032 | | |
3033 | | void |
3034 | | OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding::Uninit() |
3035 | | { |
3036 | | switch (mType) { |
3037 | | case eUninitialized: { |
3038 | | break; |
3039 | | } |
3040 | | case eWebGPUSampler: { |
3041 | | DestroyWebGPUSampler(); |
3042 | | break; |
3043 | | } |
3044 | | case eWebGPUTextureView: { |
3045 | | DestroyWebGPUTextureView(); |
3046 | | break; |
3047 | | } |
3048 | | case eWebGPUBufferBinding: { |
3049 | | DestroyWebGPUBufferBinding(); |
3050 | | break; |
3051 | | } |
3052 | | } |
3053 | | } |
3054 | | |
3055 | | bool |
3056 | | OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const |
3057 | 0 | { |
3058 | 0 | switch (mType) { |
3059 | 0 | case eUninitialized: { |
3060 | 0 | return false; |
3061 | 0 | break; |
3062 | 0 | } |
3063 | 0 | case eWebGPUSampler: { |
3064 | 0 | if (!GetOrCreateDOMReflector(cx, mValue.mWebGPUSampler.Value(), rval)) { |
3065 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
3066 | 0 | return false; |
3067 | 0 | } |
3068 | 0 | return true; |
3069 | 0 | break; |
3070 | 0 | } |
3071 | 0 | case eWebGPUTextureView: { |
3072 | 0 | if (!GetOrCreateDOMReflector(cx, mValue.mWebGPUTextureView.Value(), rval)) { |
3073 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
3074 | 0 | return false; |
3075 | 0 | } |
3076 | 0 | return true; |
3077 | 0 | break; |
3078 | 0 | } |
3079 | 0 | case eWebGPUBufferBinding: { |
3080 | 0 | if (!mValue.mWebGPUBufferBinding.Value().ToObjectInternal(cx, rval)) { |
3081 | 0 | return false; |
3082 | 0 | } |
3083 | 0 | return true; |
3084 | 0 | break; |
3085 | 0 | } |
3086 | 0 | default: { |
3087 | 0 | return false; |
3088 | 0 | break; |
3089 | 0 | } |
3090 | 0 | } |
3091 | 0 | |
3092 | 0 | return false; |
3093 | 0 | } |
3094 | | |
3095 | | void |
3096 | | OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding::TraceUnion(JSTracer* trc) |
3097 | 0 | { |
3098 | 0 | } |
3099 | | |
3100 | | OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding& |
3101 | | OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding::operator=(const OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding& aOther) |
3102 | 0 | { |
3103 | 0 | switch (aOther.mType) { |
3104 | 0 | case eUninitialized: { |
3105 | 0 | MOZ_ASSERT(mType == eUninitialized, |
3106 | 0 | "We need to destroy ourselves?"); |
3107 | 0 | break; |
3108 | 0 | } |
3109 | 0 | case eWebGPUSampler: { |
3110 | 0 | SetAsWebGPUSampler() = aOther.GetAsWebGPUSampler(); |
3111 | 0 | break; |
3112 | 0 | } |
3113 | 0 | case eWebGPUTextureView: { |
3114 | 0 | SetAsWebGPUTextureView() = aOther.GetAsWebGPUTextureView(); |
3115 | 0 | break; |
3116 | 0 | } |
3117 | 0 | case eWebGPUBufferBinding: { |
3118 | 0 | SetAsWebGPUBufferBinding() = aOther.GetAsWebGPUBufferBinding(); |
3119 | 0 | break; |
3120 | 0 | } |
3121 | 0 | } |
3122 | 0 | return *this; |
3123 | 0 | } |
3124 | | |
3125 | | |
3126 | | |
3127 | | WebGPUShaderModuleDescriptor::WebGPUShaderModuleDescriptor() |
3128 | 0 | { |
3129 | 0 | // Safe to pass a null context if we pass a null value |
3130 | 0 | Init(nullptr, JS::NullHandleValue); |
3131 | 0 | } |
3132 | | |
3133 | | |
3134 | | bool |
3135 | | WebGPUShaderModuleDescriptor::InitIds(JSContext* cx, WebGPUShaderModuleDescriptorAtoms* atomsCache) |
3136 | 0 | { |
3137 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
3138 | 0 |
|
3139 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
3140 | 0 | // uninitialized. |
3141 | 0 | if (!atomsCache->code_id.init(cx, "code")) { |
3142 | 0 | return false; |
3143 | 0 | } |
3144 | 0 | return true; |
3145 | 0 | } |
3146 | | |
3147 | | bool |
3148 | | WebGPUShaderModuleDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
3149 | 0 | { |
3150 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
3151 | 0 | // Since in that case we will not have to do any property gets |
3152 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
3153 | 0 | // checkers by static analysis tools |
3154 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
3155 | 0 | WebGPUShaderModuleDescriptorAtoms* atomsCache = nullptr; |
3156 | 0 | if (cx) { |
3157 | 0 | atomsCache = GetAtomCache<WebGPUShaderModuleDescriptorAtoms>(cx); |
3158 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
3159 | 0 | return false; |
3160 | 0 | } |
3161 | 0 | } |
3162 | 0 | |
3163 | 0 | if (!IsConvertibleToDictionary(val)) { |
3164 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
3165 | 0 | } |
3166 | 0 | |
3167 | 0 | bool isNull = val.isNullOrUndefined(); |
3168 | 0 | // We only need these if !isNull, in which case we have |cx|. |
3169 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
3170 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
3171 | 0 | if (!isNull) { |
3172 | 0 | MOZ_ASSERT(cx); |
3173 | 0 | object.emplace(cx, &val.toObject()); |
3174 | 0 | temp.emplace(cx); |
3175 | 0 | } |
3176 | 0 | if (!isNull) { |
3177 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->code_id, temp.ptr())) { |
3178 | 0 | return false; |
3179 | 0 | } |
3180 | 0 | } |
3181 | 0 | if (!isNull && !temp->isUndefined()) { |
3182 | 0 | if (temp.ref().isObject()) { |
3183 | 0 | if (!mCode.Init(&temp.ref().toObject())) { |
3184 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'code' member of WebGPUShaderModuleDescriptor", "ArrayBuffer"); |
3185 | 0 | return false; |
3186 | 0 | } |
3187 | 0 | } else { |
3188 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'code' member of WebGPUShaderModuleDescriptor"); |
3189 | 0 | return false; |
3190 | 0 | } |
3191 | 0 | mIsAnyMemberPresent = true; |
3192 | 0 | } else if (cx) { |
3193 | 0 | // Don't error out if we have no cx. In that |
3194 | 0 | // situation the caller is default-constructing us and we'll |
3195 | 0 | // just assume they know what they're doing. |
3196 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
3197 | 0 | "'code' member of WebGPUShaderModuleDescriptor"); |
3198 | 0 | } |
3199 | 0 | return true; |
3200 | 0 | } |
3201 | | |
3202 | | bool |
3203 | | WebGPUShaderModuleDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
3204 | 0 | { |
3205 | 0 | WebGPUShaderModuleDescriptorAtoms* atomsCache = GetAtomCache<WebGPUShaderModuleDescriptorAtoms>(cx); |
3206 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
3207 | 0 | return false; |
3208 | 0 | } |
3209 | 0 | |
3210 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
3211 | 0 | if (!obj) { |
3212 | 0 | return false; |
3213 | 0 | } |
3214 | 0 | rval.set(JS::ObjectValue(*obj)); |
3215 | 0 |
|
3216 | 0 | do { |
3217 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
3218 | 0 | JS::Rooted<JS::Value> temp(cx); |
3219 | 0 | ArrayBuffer const & currentValue = mCode; |
3220 | 0 | temp.setObject(*currentValue.Obj()); |
3221 | 0 | if (!MaybeWrapNonDOMObjectValue(cx, &temp)) { |
3222 | 0 | return false; |
3223 | 0 | } |
3224 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->code_id, temp, JSPROP_ENUMERATE)) { |
3225 | 0 | return false; |
3226 | 0 | } |
3227 | 0 | break; |
3228 | 0 | } while(false); |
3229 | 0 |
|
3230 | 0 | return true; |
3231 | 0 | } |
3232 | | |
3233 | | void |
3234 | | WebGPUShaderModuleDescriptor::TraceDictionary(JSTracer* trc) |
3235 | 0 | { |
3236 | 0 | mCode.TraceSelf(trc); |
3237 | 0 | } |
3238 | | |
3239 | | namespace binding_detail { |
3240 | | } // namespace binding_detail |
3241 | | |
3242 | | |
3243 | | |
3244 | | WebGPUStencilStateFaceDescriptor::WebGPUStencilStateFaceDescriptor() |
3245 | 0 | { |
3246 | 0 | // Safe to pass a null context if we pass a null value |
3247 | 0 | Init(nullptr, JS::NullHandleValue); |
3248 | 0 | } |
3249 | | |
3250 | | |
3251 | | |
3252 | | bool |
3253 | | WebGPUStencilStateFaceDescriptor::InitIds(JSContext* cx, WebGPUStencilStateFaceDescriptorAtoms* atomsCache) |
3254 | 0 | { |
3255 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
3256 | 0 |
|
3257 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
3258 | 0 | // uninitialized. |
3259 | 0 | if (!atomsCache->stencilFailOp_id.init(cx, "stencilFailOp") || |
3260 | 0 | !atomsCache->passOp_id.init(cx, "passOp") || |
3261 | 0 | !atomsCache->depthFailOp_id.init(cx, "depthFailOp") || |
3262 | 0 | !atomsCache->compare_id.init(cx, "compare")) { |
3263 | 0 | return false; |
3264 | 0 | } |
3265 | 0 | return true; |
3266 | 0 | } |
3267 | | |
3268 | | bool |
3269 | | WebGPUStencilStateFaceDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
3270 | 0 | { |
3271 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
3272 | 0 | // Since in that case we will not have to do any property gets |
3273 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
3274 | 0 | // checkers by static analysis tools |
3275 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
3276 | 0 | WebGPUStencilStateFaceDescriptorAtoms* atomsCache = nullptr; |
3277 | 0 | if (cx) { |
3278 | 0 | atomsCache = GetAtomCache<WebGPUStencilStateFaceDescriptorAtoms>(cx); |
3279 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
3280 | 0 | return false; |
3281 | 0 | } |
3282 | 0 | } |
3283 | 0 | |
3284 | 0 | if (!IsConvertibleToDictionary(val)) { |
3285 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
3286 | 0 | } |
3287 | 0 | |
3288 | 0 | bool isNull = val.isNullOrUndefined(); |
3289 | 0 | // We only need these if !isNull, in which case we have |cx|. |
3290 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
3291 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
3292 | 0 | if (!isNull) { |
3293 | 0 | MOZ_ASSERT(cx); |
3294 | 0 | object.emplace(cx, &val.toObject()); |
3295 | 0 | temp.emplace(cx); |
3296 | 0 | } |
3297 | 0 | if (!isNull) { |
3298 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->compare_id, temp.ptr())) { |
3299 | 0 | return false; |
3300 | 0 | } |
3301 | 0 | } |
3302 | 0 | if (!isNull && !temp->isUndefined()) { |
3303 | 0 | mCompare.Construct(); |
3304 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mCompare.Value()))) { |
3305 | 0 | return false; |
3306 | 0 | } |
3307 | 0 | mIsAnyMemberPresent = true; |
3308 | 0 | } |
3309 | 0 |
|
3310 | 0 | if (!isNull) { |
3311 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->depthFailOp_id, temp.ptr())) { |
3312 | 0 | return false; |
3313 | 0 | } |
3314 | 0 | } |
3315 | 0 | if (!isNull && !temp->isUndefined()) { |
3316 | 0 | mDepthFailOp.Construct(); |
3317 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mDepthFailOp.Value()))) { |
3318 | 0 | return false; |
3319 | 0 | } |
3320 | 0 | mIsAnyMemberPresent = true; |
3321 | 0 | } |
3322 | 0 |
|
3323 | 0 | if (!isNull) { |
3324 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->passOp_id, temp.ptr())) { |
3325 | 0 | return false; |
3326 | 0 | } |
3327 | 0 | } |
3328 | 0 | if (!isNull && !temp->isUndefined()) { |
3329 | 0 | mPassOp.Construct(); |
3330 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mPassOp.Value()))) { |
3331 | 0 | return false; |
3332 | 0 | } |
3333 | 0 | mIsAnyMemberPresent = true; |
3334 | 0 | } |
3335 | 0 |
|
3336 | 0 | if (!isNull) { |
3337 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->stencilFailOp_id, temp.ptr())) { |
3338 | 0 | return false; |
3339 | 0 | } |
3340 | 0 | } |
3341 | 0 | if (!isNull && !temp->isUndefined()) { |
3342 | 0 | mStencilFailOp.Construct(); |
3343 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mStencilFailOp.Value()))) { |
3344 | 0 | return false; |
3345 | 0 | } |
3346 | 0 | mIsAnyMemberPresent = true; |
3347 | 0 | } |
3348 | 0 | return true; |
3349 | 0 | } |
3350 | | |
3351 | | bool |
3352 | | WebGPUStencilStateFaceDescriptor::Init(const nsAString& aJSON) |
3353 | 0 | { |
3354 | 0 | AutoJSAPI jsapi; |
3355 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
3356 | 0 | if (!cleanGlobal) { |
3357 | 0 | return false; |
3358 | 0 | } |
3359 | 0 | if (!jsapi.Init(cleanGlobal)) { |
3360 | 0 | return false; |
3361 | 0 | } |
3362 | 0 | JSContext* cx = jsapi.cx(); |
3363 | 0 | JS::Rooted<JS::Value> json(cx); |
3364 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
3365 | 0 | NS_ENSURE_TRUE(ok, false); |
3366 | 0 | return Init(cx, json); |
3367 | 0 | } |
3368 | | |
3369 | | bool |
3370 | | WebGPUStencilStateFaceDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
3371 | 0 | { |
3372 | 0 | WebGPUStencilStateFaceDescriptorAtoms* atomsCache = GetAtomCache<WebGPUStencilStateFaceDescriptorAtoms>(cx); |
3373 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
3374 | 0 | return false; |
3375 | 0 | } |
3376 | 0 | |
3377 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
3378 | 0 | if (!obj) { |
3379 | 0 | return false; |
3380 | 0 | } |
3381 | 0 | rval.set(JS::ObjectValue(*obj)); |
3382 | 0 |
|
3383 | 0 | if (mCompare.WasPassed()) { |
3384 | 0 | do { |
3385 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
3386 | 0 | JS::Rooted<JS::Value> temp(cx); |
3387 | 0 | uint32_t const & currentValue = mCompare.InternalValue(); |
3388 | 0 | temp.setNumber(currentValue); |
3389 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->compare_id, temp, JSPROP_ENUMERATE)) { |
3390 | 0 | return false; |
3391 | 0 | } |
3392 | 0 | break; |
3393 | 0 | } while(false); |
3394 | 0 | } |
3395 | 0 |
|
3396 | 0 | if (mDepthFailOp.WasPassed()) { |
3397 | 0 | do { |
3398 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
3399 | 0 | JS::Rooted<JS::Value> temp(cx); |
3400 | 0 | uint32_t const & currentValue = mDepthFailOp.InternalValue(); |
3401 | 0 | temp.setNumber(currentValue); |
3402 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->depthFailOp_id, temp, JSPROP_ENUMERATE)) { |
3403 | 0 | return false; |
3404 | 0 | } |
3405 | 0 | break; |
3406 | 0 | } while(false); |
3407 | 0 | } |
3408 | 0 |
|
3409 | 0 | if (mPassOp.WasPassed()) { |
3410 | 0 | do { |
3411 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
3412 | 0 | JS::Rooted<JS::Value> temp(cx); |
3413 | 0 | uint32_t const & currentValue = mPassOp.InternalValue(); |
3414 | 0 | temp.setNumber(currentValue); |
3415 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->passOp_id, temp, JSPROP_ENUMERATE)) { |
3416 | 0 | return false; |
3417 | 0 | } |
3418 | 0 | break; |
3419 | 0 | } while(false); |
3420 | 0 | } |
3421 | 0 |
|
3422 | 0 | if (mStencilFailOp.WasPassed()) { |
3423 | 0 | do { |
3424 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
3425 | 0 | JS::Rooted<JS::Value> temp(cx); |
3426 | 0 | uint32_t const & currentValue = mStencilFailOp.InternalValue(); |
3427 | 0 | temp.setNumber(currentValue); |
3428 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->stencilFailOp_id, temp, JSPROP_ENUMERATE)) { |
3429 | 0 | return false; |
3430 | 0 | } |
3431 | 0 | break; |
3432 | 0 | } while(false); |
3433 | 0 | } |
3434 | 0 |
|
3435 | 0 | return true; |
3436 | 0 | } |
3437 | | |
3438 | | bool |
3439 | | WebGPUStencilStateFaceDescriptor::ToJSON(nsAString& aJSON) const |
3440 | 0 | { |
3441 | 0 | AutoJSAPI jsapi; |
3442 | 0 | jsapi.Init(); |
3443 | 0 | JSContext *cx = jsapi.cx(); |
3444 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
3445 | 0 | // because we'll only be creating objects, in ways that have no |
3446 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
3447 | 0 | // which likewise guarantees no side-effects for the sorts of |
3448 | 0 | // things we will pass it. |
3449 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
3450 | 0 | JS::Rooted<JS::Value> val(cx); |
3451 | 0 | if (!ToObjectInternal(cx, &val)) { |
3452 | 0 | return false; |
3453 | 0 | } |
3454 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
3455 | 0 | return StringifyToJSON(cx, obj, aJSON); |
3456 | 0 | } |
3457 | | |
3458 | | void |
3459 | | WebGPUStencilStateFaceDescriptor::TraceDictionary(JSTracer* trc) |
3460 | 0 | { |
3461 | 0 | } |
3462 | | |
3463 | | WebGPUStencilStateFaceDescriptor& |
3464 | | WebGPUStencilStateFaceDescriptor::operator=(const WebGPUStencilStateFaceDescriptor& aOther) |
3465 | 0 | { |
3466 | 0 | DictionaryBase::operator=(aOther); |
3467 | 0 | mCompare.Reset(); |
3468 | 0 | if (aOther.mCompare.WasPassed()) { |
3469 | 0 | mCompare.Construct(aOther.mCompare.Value()); |
3470 | 0 | } |
3471 | 0 | mDepthFailOp.Reset(); |
3472 | 0 | if (aOther.mDepthFailOp.WasPassed()) { |
3473 | 0 | mDepthFailOp.Construct(aOther.mDepthFailOp.Value()); |
3474 | 0 | } |
3475 | 0 | mPassOp.Reset(); |
3476 | 0 | if (aOther.mPassOp.WasPassed()) { |
3477 | 0 | mPassOp.Construct(aOther.mPassOp.Value()); |
3478 | 0 | } |
3479 | 0 | mStencilFailOp.Reset(); |
3480 | 0 | if (aOther.mStencilFailOp.WasPassed()) { |
3481 | 0 | mStencilFailOp.Construct(aOther.mStencilFailOp.Value()); |
3482 | 0 | } |
3483 | 0 | return *this; |
3484 | 0 | } |
3485 | | |
3486 | | namespace binding_detail { |
3487 | | } // namespace binding_detail |
3488 | | |
3489 | | |
3490 | | |
3491 | | WebGPUSwapChainDescriptor::WebGPUSwapChainDescriptor() |
3492 | 0 | { |
3493 | 0 | // Safe to pass a null context if we pass a null value |
3494 | 0 | Init(nullptr, JS::NullHandleValue); |
3495 | 0 | } |
3496 | | |
3497 | | |
3498 | | |
3499 | | bool |
3500 | | WebGPUSwapChainDescriptor::InitIds(JSContext* cx, WebGPUSwapChainDescriptorAtoms* atomsCache) |
3501 | 0 | { |
3502 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
3503 | 0 |
|
3504 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
3505 | 0 | // uninitialized. |
3506 | 0 | if (!atomsCache->width_id.init(cx, "width") || |
3507 | 0 | !atomsCache->usage_id.init(cx, "usage") || |
3508 | 0 | !atomsCache->height_id.init(cx, "height") || |
3509 | 0 | !atomsCache->format_id.init(cx, "format")) { |
3510 | 0 | return false; |
3511 | 0 | } |
3512 | 0 | return true; |
3513 | 0 | } |
3514 | | |
3515 | | bool |
3516 | | WebGPUSwapChainDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
3517 | 0 | { |
3518 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
3519 | 0 | // Since in that case we will not have to do any property gets |
3520 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
3521 | 0 | // checkers by static analysis tools |
3522 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
3523 | 0 | WebGPUSwapChainDescriptorAtoms* atomsCache = nullptr; |
3524 | 0 | if (cx) { |
3525 | 0 | atomsCache = GetAtomCache<WebGPUSwapChainDescriptorAtoms>(cx); |
3526 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
3527 | 0 | return false; |
3528 | 0 | } |
3529 | 0 | } |
3530 | 0 | |
3531 | 0 | if (!IsConvertibleToDictionary(val)) { |
3532 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
3533 | 0 | } |
3534 | 0 | |
3535 | 0 | bool isNull = val.isNullOrUndefined(); |
3536 | 0 | // We only need these if !isNull, in which case we have |cx|. |
3537 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
3538 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
3539 | 0 | if (!isNull) { |
3540 | 0 | MOZ_ASSERT(cx); |
3541 | 0 | object.emplace(cx, &val.toObject()); |
3542 | 0 | temp.emplace(cx); |
3543 | 0 | } |
3544 | 0 | if (!isNull) { |
3545 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->format_id, temp.ptr())) { |
3546 | 0 | return false; |
3547 | 0 | } |
3548 | 0 | } |
3549 | 0 | if (!isNull && !temp->isUndefined()) { |
3550 | 0 | mFormat.Construct(); |
3551 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mFormat.Value()))) { |
3552 | 0 | return false; |
3553 | 0 | } |
3554 | 0 | mIsAnyMemberPresent = true; |
3555 | 0 | } |
3556 | 0 |
|
3557 | 0 | if (!isNull) { |
3558 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->height_id, temp.ptr())) { |
3559 | 0 | return false; |
3560 | 0 | } |
3561 | 0 | } |
3562 | 0 | if (!isNull && !temp->isUndefined()) { |
3563 | 0 | mHeight.Construct(); |
3564 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mHeight.Value()))) { |
3565 | 0 | return false; |
3566 | 0 | } |
3567 | 0 | mIsAnyMemberPresent = true; |
3568 | 0 | } |
3569 | 0 |
|
3570 | 0 | if (!isNull) { |
3571 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->usage_id, temp.ptr())) { |
3572 | 0 | return false; |
3573 | 0 | } |
3574 | 0 | } |
3575 | 0 | if (!isNull && !temp->isUndefined()) { |
3576 | 0 | mUsage.Construct(); |
3577 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mUsage.Value()))) { |
3578 | 0 | return false; |
3579 | 0 | } |
3580 | 0 | mIsAnyMemberPresent = true; |
3581 | 0 | } |
3582 | 0 |
|
3583 | 0 | if (!isNull) { |
3584 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->width_id, temp.ptr())) { |
3585 | 0 | return false; |
3586 | 0 | } |
3587 | 0 | } |
3588 | 0 | if (!isNull && !temp->isUndefined()) { |
3589 | 0 | mWidth.Construct(); |
3590 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mWidth.Value()))) { |
3591 | 0 | return false; |
3592 | 0 | } |
3593 | 0 | mIsAnyMemberPresent = true; |
3594 | 0 | } |
3595 | 0 | return true; |
3596 | 0 | } |
3597 | | |
3598 | | bool |
3599 | | WebGPUSwapChainDescriptor::Init(const nsAString& aJSON) |
3600 | 0 | { |
3601 | 0 | AutoJSAPI jsapi; |
3602 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
3603 | 0 | if (!cleanGlobal) { |
3604 | 0 | return false; |
3605 | 0 | } |
3606 | 0 | if (!jsapi.Init(cleanGlobal)) { |
3607 | 0 | return false; |
3608 | 0 | } |
3609 | 0 | JSContext* cx = jsapi.cx(); |
3610 | 0 | JS::Rooted<JS::Value> json(cx); |
3611 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
3612 | 0 | NS_ENSURE_TRUE(ok, false); |
3613 | 0 | return Init(cx, json); |
3614 | 0 | } |
3615 | | |
3616 | | bool |
3617 | | WebGPUSwapChainDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
3618 | 0 | { |
3619 | 0 | WebGPUSwapChainDescriptorAtoms* atomsCache = GetAtomCache<WebGPUSwapChainDescriptorAtoms>(cx); |
3620 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
3621 | 0 | return false; |
3622 | 0 | } |
3623 | 0 | |
3624 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
3625 | 0 | if (!obj) { |
3626 | 0 | return false; |
3627 | 0 | } |
3628 | 0 | rval.set(JS::ObjectValue(*obj)); |
3629 | 0 |
|
3630 | 0 | if (mFormat.WasPassed()) { |
3631 | 0 | do { |
3632 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
3633 | 0 | JS::Rooted<JS::Value> temp(cx); |
3634 | 0 | uint32_t const & currentValue = mFormat.InternalValue(); |
3635 | 0 | temp.setNumber(currentValue); |
3636 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->format_id, temp, JSPROP_ENUMERATE)) { |
3637 | 0 | return false; |
3638 | 0 | } |
3639 | 0 | break; |
3640 | 0 | } while(false); |
3641 | 0 | } |
3642 | 0 |
|
3643 | 0 | if (mHeight.WasPassed()) { |
3644 | 0 | do { |
3645 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
3646 | 0 | JS::Rooted<JS::Value> temp(cx); |
3647 | 0 | uint32_t const & currentValue = mHeight.InternalValue(); |
3648 | 0 | temp.setNumber(currentValue); |
3649 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->height_id, temp, JSPROP_ENUMERATE)) { |
3650 | 0 | return false; |
3651 | 0 | } |
3652 | 0 | break; |
3653 | 0 | } while(false); |
3654 | 0 | } |
3655 | 0 |
|
3656 | 0 | if (mUsage.WasPassed()) { |
3657 | 0 | do { |
3658 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
3659 | 0 | JS::Rooted<JS::Value> temp(cx); |
3660 | 0 | uint32_t const & currentValue = mUsage.InternalValue(); |
3661 | 0 | temp.setNumber(currentValue); |
3662 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->usage_id, temp, JSPROP_ENUMERATE)) { |
3663 | 0 | return false; |
3664 | 0 | } |
3665 | 0 | break; |
3666 | 0 | } while(false); |
3667 | 0 | } |
3668 | 0 |
|
3669 | 0 | if (mWidth.WasPassed()) { |
3670 | 0 | do { |
3671 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
3672 | 0 | JS::Rooted<JS::Value> temp(cx); |
3673 | 0 | uint32_t const & currentValue = mWidth.InternalValue(); |
3674 | 0 | temp.setNumber(currentValue); |
3675 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->width_id, temp, JSPROP_ENUMERATE)) { |
3676 | 0 | return false; |
3677 | 0 | } |
3678 | 0 | break; |
3679 | 0 | } while(false); |
3680 | 0 | } |
3681 | 0 |
|
3682 | 0 | return true; |
3683 | 0 | } |
3684 | | |
3685 | | bool |
3686 | | WebGPUSwapChainDescriptor::ToJSON(nsAString& aJSON) const |
3687 | 0 | { |
3688 | 0 | AutoJSAPI jsapi; |
3689 | 0 | jsapi.Init(); |
3690 | 0 | JSContext *cx = jsapi.cx(); |
3691 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
3692 | 0 | // because we'll only be creating objects, in ways that have no |
3693 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
3694 | 0 | // which likewise guarantees no side-effects for the sorts of |
3695 | 0 | // things we will pass it. |
3696 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
3697 | 0 | JS::Rooted<JS::Value> val(cx); |
3698 | 0 | if (!ToObjectInternal(cx, &val)) { |
3699 | 0 | return false; |
3700 | 0 | } |
3701 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
3702 | 0 | return StringifyToJSON(cx, obj, aJSON); |
3703 | 0 | } |
3704 | | |
3705 | | void |
3706 | | WebGPUSwapChainDescriptor::TraceDictionary(JSTracer* trc) |
3707 | 0 | { |
3708 | 0 | } |
3709 | | |
3710 | | WebGPUSwapChainDescriptor& |
3711 | | WebGPUSwapChainDescriptor::operator=(const WebGPUSwapChainDescriptor& aOther) |
3712 | 0 | { |
3713 | 0 | DictionaryBase::operator=(aOther); |
3714 | 0 | mFormat.Reset(); |
3715 | 0 | if (aOther.mFormat.WasPassed()) { |
3716 | 0 | mFormat.Construct(aOther.mFormat.Value()); |
3717 | 0 | } |
3718 | 0 | mHeight.Reset(); |
3719 | 0 | if (aOther.mHeight.WasPassed()) { |
3720 | 0 | mHeight.Construct(aOther.mHeight.Value()); |
3721 | 0 | } |
3722 | 0 | mUsage.Reset(); |
3723 | 0 | if (aOther.mUsage.WasPassed()) { |
3724 | 0 | mUsage.Construct(aOther.mUsage.Value()); |
3725 | 0 | } |
3726 | 0 | mWidth.Reset(); |
3727 | 0 | if (aOther.mWidth.WasPassed()) { |
3728 | 0 | mWidth.Construct(aOther.mWidth.Value()); |
3729 | 0 | } |
3730 | 0 | return *this; |
3731 | 0 | } |
3732 | | |
3733 | | namespace binding_detail { |
3734 | | } // namespace binding_detail |
3735 | | |
3736 | | |
3737 | | |
3738 | | WebGPUTextureDescriptor::WebGPUTextureDescriptor() |
3739 | 0 | { |
3740 | 0 | // Safe to pass a null context if we pass a null value |
3741 | 0 | Init(nullptr, JS::NullHandleValue); |
3742 | 0 | } |
3743 | | |
3744 | | |
3745 | | |
3746 | | bool |
3747 | | WebGPUTextureDescriptor::InitIds(JSContext* cx, WebGPUTextureDescriptorAtoms* atomsCache) |
3748 | 0 | { |
3749 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
3750 | 0 |
|
3751 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
3752 | 0 | // uninitialized. |
3753 | 0 | if (!atomsCache->width_id.init(cx, "width") || |
3754 | 0 | !atomsCache->usage_id.init(cx, "usage") || |
3755 | 0 | !atomsCache->height_id.init(cx, "height") || |
3756 | 0 | !atomsCache->format_id.init(cx, "format") || |
3757 | 0 | !atomsCache->dimension_id.init(cx, "dimension") || |
3758 | 0 | !atomsCache->depth_id.init(cx, "depth") || |
3759 | 0 | !atomsCache->arraySize_id.init(cx, "arraySize")) { |
3760 | 0 | return false; |
3761 | 0 | } |
3762 | 0 | return true; |
3763 | 0 | } |
3764 | | |
3765 | | bool |
3766 | | WebGPUTextureDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
3767 | 0 | { |
3768 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
3769 | 0 | // Since in that case we will not have to do any property gets |
3770 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
3771 | 0 | // checkers by static analysis tools |
3772 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
3773 | 0 | WebGPUTextureDescriptorAtoms* atomsCache = nullptr; |
3774 | 0 | if (cx) { |
3775 | 0 | atomsCache = GetAtomCache<WebGPUTextureDescriptorAtoms>(cx); |
3776 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
3777 | 0 | return false; |
3778 | 0 | } |
3779 | 0 | } |
3780 | 0 | |
3781 | 0 | if (!IsConvertibleToDictionary(val)) { |
3782 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
3783 | 0 | } |
3784 | 0 | |
3785 | 0 | bool isNull = val.isNullOrUndefined(); |
3786 | 0 | // We only need these if !isNull, in which case we have |cx|. |
3787 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
3788 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
3789 | 0 | if (!isNull) { |
3790 | 0 | MOZ_ASSERT(cx); |
3791 | 0 | object.emplace(cx, &val.toObject()); |
3792 | 0 | temp.emplace(cx); |
3793 | 0 | } |
3794 | 0 | if (!isNull) { |
3795 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->arraySize_id, temp.ptr())) { |
3796 | 0 | return false; |
3797 | 0 | } |
3798 | 0 | } |
3799 | 0 | if (!isNull && !temp->isUndefined()) { |
3800 | 0 | mArraySize.Construct(); |
3801 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mArraySize.Value()))) { |
3802 | 0 | return false; |
3803 | 0 | } |
3804 | 0 | mIsAnyMemberPresent = true; |
3805 | 0 | } |
3806 | 0 |
|
3807 | 0 | if (!isNull) { |
3808 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->depth_id, temp.ptr())) { |
3809 | 0 | return false; |
3810 | 0 | } |
3811 | 0 | } |
3812 | 0 | if (!isNull && !temp->isUndefined()) { |
3813 | 0 | mDepth.Construct(); |
3814 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mDepth.Value()))) { |
3815 | 0 | return false; |
3816 | 0 | } |
3817 | 0 | mIsAnyMemberPresent = true; |
3818 | 0 | } |
3819 | 0 |
|
3820 | 0 | if (!isNull) { |
3821 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->dimension_id, temp.ptr())) { |
3822 | 0 | return false; |
3823 | 0 | } |
3824 | 0 | } |
3825 | 0 | if (!isNull && !temp->isUndefined()) { |
3826 | 0 | mDimension.Construct(); |
3827 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mDimension.Value()))) { |
3828 | 0 | return false; |
3829 | 0 | } |
3830 | 0 | mIsAnyMemberPresent = true; |
3831 | 0 | } |
3832 | 0 |
|
3833 | 0 | if (!isNull) { |
3834 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->format_id, temp.ptr())) { |
3835 | 0 | return false; |
3836 | 0 | } |
3837 | 0 | } |
3838 | 0 | if (!isNull && !temp->isUndefined()) { |
3839 | 0 | mFormat.Construct(); |
3840 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mFormat.Value()))) { |
3841 | 0 | return false; |
3842 | 0 | } |
3843 | 0 | mIsAnyMemberPresent = true; |
3844 | 0 | } |
3845 | 0 |
|
3846 | 0 | if (!isNull) { |
3847 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->height_id, temp.ptr())) { |
3848 | 0 | return false; |
3849 | 0 | } |
3850 | 0 | } |
3851 | 0 | if (!isNull && !temp->isUndefined()) { |
3852 | 0 | mHeight.Construct(); |
3853 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mHeight.Value()))) { |
3854 | 0 | return false; |
3855 | 0 | } |
3856 | 0 | mIsAnyMemberPresent = true; |
3857 | 0 | } |
3858 | 0 |
|
3859 | 0 | if (!isNull) { |
3860 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->usage_id, temp.ptr())) { |
3861 | 0 | return false; |
3862 | 0 | } |
3863 | 0 | } |
3864 | 0 | if (!isNull && !temp->isUndefined()) { |
3865 | 0 | mUsage.Construct(); |
3866 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mUsage.Value()))) { |
3867 | 0 | return false; |
3868 | 0 | } |
3869 | 0 | mIsAnyMemberPresent = true; |
3870 | 0 | } |
3871 | 0 |
|
3872 | 0 | if (!isNull) { |
3873 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->width_id, temp.ptr())) { |
3874 | 0 | return false; |
3875 | 0 | } |
3876 | 0 | } |
3877 | 0 | if (!isNull && !temp->isUndefined()) { |
3878 | 0 | mWidth.Construct(); |
3879 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mWidth.Value()))) { |
3880 | 0 | return false; |
3881 | 0 | } |
3882 | 0 | mIsAnyMemberPresent = true; |
3883 | 0 | } |
3884 | 0 | return true; |
3885 | 0 | } |
3886 | | |
3887 | | bool |
3888 | | WebGPUTextureDescriptor::Init(const nsAString& aJSON) |
3889 | 0 | { |
3890 | 0 | AutoJSAPI jsapi; |
3891 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
3892 | 0 | if (!cleanGlobal) { |
3893 | 0 | return false; |
3894 | 0 | } |
3895 | 0 | if (!jsapi.Init(cleanGlobal)) { |
3896 | 0 | return false; |
3897 | 0 | } |
3898 | 0 | JSContext* cx = jsapi.cx(); |
3899 | 0 | JS::Rooted<JS::Value> json(cx); |
3900 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
3901 | 0 | NS_ENSURE_TRUE(ok, false); |
3902 | 0 | return Init(cx, json); |
3903 | 0 | } |
3904 | | |
3905 | | bool |
3906 | | WebGPUTextureDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
3907 | 0 | { |
3908 | 0 | WebGPUTextureDescriptorAtoms* atomsCache = GetAtomCache<WebGPUTextureDescriptorAtoms>(cx); |
3909 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
3910 | 0 | return false; |
3911 | 0 | } |
3912 | 0 | |
3913 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
3914 | 0 | if (!obj) { |
3915 | 0 | return false; |
3916 | 0 | } |
3917 | 0 | rval.set(JS::ObjectValue(*obj)); |
3918 | 0 |
|
3919 | 0 | if (mArraySize.WasPassed()) { |
3920 | 0 | do { |
3921 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
3922 | 0 | JS::Rooted<JS::Value> temp(cx); |
3923 | 0 | uint32_t const & currentValue = mArraySize.InternalValue(); |
3924 | 0 | temp.setNumber(currentValue); |
3925 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->arraySize_id, temp, JSPROP_ENUMERATE)) { |
3926 | 0 | return false; |
3927 | 0 | } |
3928 | 0 | break; |
3929 | 0 | } while(false); |
3930 | 0 | } |
3931 | 0 |
|
3932 | 0 | if (mDepth.WasPassed()) { |
3933 | 0 | do { |
3934 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
3935 | 0 | JS::Rooted<JS::Value> temp(cx); |
3936 | 0 | uint32_t const & currentValue = mDepth.InternalValue(); |
3937 | 0 | temp.setNumber(currentValue); |
3938 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->depth_id, temp, JSPROP_ENUMERATE)) { |
3939 | 0 | return false; |
3940 | 0 | } |
3941 | 0 | break; |
3942 | 0 | } while(false); |
3943 | 0 | } |
3944 | 0 |
|
3945 | 0 | if (mDimension.WasPassed()) { |
3946 | 0 | do { |
3947 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
3948 | 0 | JS::Rooted<JS::Value> temp(cx); |
3949 | 0 | uint32_t const & currentValue = mDimension.InternalValue(); |
3950 | 0 | temp.setNumber(currentValue); |
3951 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->dimension_id, temp, JSPROP_ENUMERATE)) { |
3952 | 0 | return false; |
3953 | 0 | } |
3954 | 0 | break; |
3955 | 0 | } while(false); |
3956 | 0 | } |
3957 | 0 |
|
3958 | 0 | if (mFormat.WasPassed()) { |
3959 | 0 | do { |
3960 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
3961 | 0 | JS::Rooted<JS::Value> temp(cx); |
3962 | 0 | uint32_t const & currentValue = mFormat.InternalValue(); |
3963 | 0 | temp.setNumber(currentValue); |
3964 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->format_id, temp, JSPROP_ENUMERATE)) { |
3965 | 0 | return false; |
3966 | 0 | } |
3967 | 0 | break; |
3968 | 0 | } while(false); |
3969 | 0 | } |
3970 | 0 |
|
3971 | 0 | if (mHeight.WasPassed()) { |
3972 | 0 | do { |
3973 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
3974 | 0 | JS::Rooted<JS::Value> temp(cx); |
3975 | 0 | uint32_t const & currentValue = mHeight.InternalValue(); |
3976 | 0 | temp.setNumber(currentValue); |
3977 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->height_id, temp, JSPROP_ENUMERATE)) { |
3978 | 0 | return false; |
3979 | 0 | } |
3980 | 0 | break; |
3981 | 0 | } while(false); |
3982 | 0 | } |
3983 | 0 |
|
3984 | 0 | if (mUsage.WasPassed()) { |
3985 | 0 | do { |
3986 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
3987 | 0 | JS::Rooted<JS::Value> temp(cx); |
3988 | 0 | uint32_t const & currentValue = mUsage.InternalValue(); |
3989 | 0 | temp.setNumber(currentValue); |
3990 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->usage_id, temp, JSPROP_ENUMERATE)) { |
3991 | 0 | return false; |
3992 | 0 | } |
3993 | 0 | break; |
3994 | 0 | } while(false); |
3995 | 0 | } |
3996 | 0 |
|
3997 | 0 | if (mWidth.WasPassed()) { |
3998 | 0 | do { |
3999 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
4000 | 0 | JS::Rooted<JS::Value> temp(cx); |
4001 | 0 | uint32_t const & currentValue = mWidth.InternalValue(); |
4002 | 0 | temp.setNumber(currentValue); |
4003 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->width_id, temp, JSPROP_ENUMERATE)) { |
4004 | 0 | return false; |
4005 | 0 | } |
4006 | 0 | break; |
4007 | 0 | } while(false); |
4008 | 0 | } |
4009 | 0 |
|
4010 | 0 | return true; |
4011 | 0 | } |
4012 | | |
4013 | | bool |
4014 | | WebGPUTextureDescriptor::ToJSON(nsAString& aJSON) const |
4015 | 0 | { |
4016 | 0 | AutoJSAPI jsapi; |
4017 | 0 | jsapi.Init(); |
4018 | 0 | JSContext *cx = jsapi.cx(); |
4019 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
4020 | 0 | // because we'll only be creating objects, in ways that have no |
4021 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
4022 | 0 | // which likewise guarantees no side-effects for the sorts of |
4023 | 0 | // things we will pass it. |
4024 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
4025 | 0 | JS::Rooted<JS::Value> val(cx); |
4026 | 0 | if (!ToObjectInternal(cx, &val)) { |
4027 | 0 | return false; |
4028 | 0 | } |
4029 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
4030 | 0 | return StringifyToJSON(cx, obj, aJSON); |
4031 | 0 | } |
4032 | | |
4033 | | void |
4034 | | WebGPUTextureDescriptor::TraceDictionary(JSTracer* trc) |
4035 | 0 | { |
4036 | 0 | } |
4037 | | |
4038 | | WebGPUTextureDescriptor& |
4039 | | WebGPUTextureDescriptor::operator=(const WebGPUTextureDescriptor& aOther) |
4040 | 0 | { |
4041 | 0 | DictionaryBase::operator=(aOther); |
4042 | 0 | mArraySize.Reset(); |
4043 | 0 | if (aOther.mArraySize.WasPassed()) { |
4044 | 0 | mArraySize.Construct(aOther.mArraySize.Value()); |
4045 | 0 | } |
4046 | 0 | mDepth.Reset(); |
4047 | 0 | if (aOther.mDepth.WasPassed()) { |
4048 | 0 | mDepth.Construct(aOther.mDepth.Value()); |
4049 | 0 | } |
4050 | 0 | mDimension.Reset(); |
4051 | 0 | if (aOther.mDimension.WasPassed()) { |
4052 | 0 | mDimension.Construct(aOther.mDimension.Value()); |
4053 | 0 | } |
4054 | 0 | mFormat.Reset(); |
4055 | 0 | if (aOther.mFormat.WasPassed()) { |
4056 | 0 | mFormat.Construct(aOther.mFormat.Value()); |
4057 | 0 | } |
4058 | 0 | mHeight.Reset(); |
4059 | 0 | if (aOther.mHeight.WasPassed()) { |
4060 | 0 | mHeight.Construct(aOther.mHeight.Value()); |
4061 | 0 | } |
4062 | 0 | mUsage.Reset(); |
4063 | 0 | if (aOther.mUsage.WasPassed()) { |
4064 | 0 | mUsage.Construct(aOther.mUsage.Value()); |
4065 | 0 | } |
4066 | 0 | mWidth.Reset(); |
4067 | 0 | if (aOther.mWidth.WasPassed()) { |
4068 | 0 | mWidth.Construct(aOther.mWidth.Value()); |
4069 | 0 | } |
4070 | 0 | return *this; |
4071 | 0 | } |
4072 | | |
4073 | | namespace binding_detail { |
4074 | | } // namespace binding_detail |
4075 | | |
4076 | | |
4077 | | |
4078 | | WebGPUTextureViewDescriptor::WebGPUTextureViewDescriptor() |
4079 | 0 | { |
4080 | 0 | // Safe to pass a null context if we pass a null value |
4081 | 0 | Init(nullptr, JS::NullHandleValue); |
4082 | 0 | } |
4083 | | |
4084 | | |
4085 | | |
4086 | | bool |
4087 | | WebGPUTextureViewDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
4088 | 0 | { |
4089 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
4090 | 0 | // Since in that case we will not have to do any property gets |
4091 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
4092 | 0 | // checkers by static analysis tools |
4093 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
4094 | 0 | if (!IsConvertibleToDictionary(val)) { |
4095 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
4096 | 0 | } |
4097 | 0 | |
4098 | 0 | return true; |
4099 | 0 | } |
4100 | | |
4101 | | bool |
4102 | | WebGPUTextureViewDescriptor::Init(const nsAString& aJSON) |
4103 | 0 | { |
4104 | 0 | AutoJSAPI jsapi; |
4105 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
4106 | 0 | if (!cleanGlobal) { |
4107 | 0 | return false; |
4108 | 0 | } |
4109 | 0 | if (!jsapi.Init(cleanGlobal)) { |
4110 | 0 | return false; |
4111 | 0 | } |
4112 | 0 | JSContext* cx = jsapi.cx(); |
4113 | 0 | JS::Rooted<JS::Value> json(cx); |
4114 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
4115 | 0 | NS_ENSURE_TRUE(ok, false); |
4116 | 0 | return Init(cx, json); |
4117 | 0 | } |
4118 | | |
4119 | | bool |
4120 | | WebGPUTextureViewDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
4121 | 0 | { |
4122 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
4123 | 0 | if (!obj) { |
4124 | 0 | return false; |
4125 | 0 | } |
4126 | 0 | rval.set(JS::ObjectValue(*obj)); |
4127 | 0 |
|
4128 | 0 |
|
4129 | 0 | return true; |
4130 | 0 | } |
4131 | | |
4132 | | bool |
4133 | | WebGPUTextureViewDescriptor::ToJSON(nsAString& aJSON) const |
4134 | 0 | { |
4135 | 0 | AutoJSAPI jsapi; |
4136 | 0 | jsapi.Init(); |
4137 | 0 | JSContext *cx = jsapi.cx(); |
4138 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
4139 | 0 | // because we'll only be creating objects, in ways that have no |
4140 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
4141 | 0 | // which likewise guarantees no side-effects for the sorts of |
4142 | 0 | // things we will pass it. |
4143 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
4144 | 0 | JS::Rooted<JS::Value> val(cx); |
4145 | 0 | if (!ToObjectInternal(cx, &val)) { |
4146 | 0 | return false; |
4147 | 0 | } |
4148 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
4149 | 0 | return StringifyToJSON(cx, obj, aJSON); |
4150 | 0 | } |
4151 | | |
4152 | | void |
4153 | | WebGPUTextureViewDescriptor::TraceDictionary(JSTracer* trc) |
4154 | 0 | { |
4155 | 0 | } |
4156 | | |
4157 | | WebGPUTextureViewDescriptor& |
4158 | | WebGPUTextureViewDescriptor::operator=(const WebGPUTextureViewDescriptor& aOther) |
4159 | 0 | { |
4160 | 0 | DictionaryBase::operator=(aOther); |
4161 | 0 | return *this; |
4162 | 0 | } |
4163 | | |
4164 | | namespace binding_detail { |
4165 | | } // namespace binding_detail |
4166 | | |
4167 | | |
4168 | | |
4169 | | WebGPUVertexAttributeDescriptor::WebGPUVertexAttributeDescriptor() |
4170 | 0 | { |
4171 | 0 | // Safe to pass a null context if we pass a null value |
4172 | 0 | Init(nullptr, JS::NullHandleValue); |
4173 | 0 | } |
4174 | | |
4175 | | |
4176 | | |
4177 | | bool |
4178 | | WebGPUVertexAttributeDescriptor::InitIds(JSContext* cx, WebGPUVertexAttributeDescriptorAtoms* atomsCache) |
4179 | 0 | { |
4180 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
4181 | 0 |
|
4182 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
4183 | 0 | // uninitialized. |
4184 | 0 | if (!atomsCache->shaderLocation_id.init(cx, "shaderLocation") || |
4185 | 0 | !atomsCache->offset_id.init(cx, "offset") || |
4186 | 0 | !atomsCache->inputSlot_id.init(cx, "inputSlot") || |
4187 | 0 | !atomsCache->format_id.init(cx, "format")) { |
4188 | 0 | return false; |
4189 | 0 | } |
4190 | 0 | return true; |
4191 | 0 | } |
4192 | | |
4193 | | bool |
4194 | | WebGPUVertexAttributeDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
4195 | 0 | { |
4196 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
4197 | 0 | // Since in that case we will not have to do any property gets |
4198 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
4199 | 0 | // checkers by static analysis tools |
4200 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
4201 | 0 | WebGPUVertexAttributeDescriptorAtoms* atomsCache = nullptr; |
4202 | 0 | if (cx) { |
4203 | 0 | atomsCache = GetAtomCache<WebGPUVertexAttributeDescriptorAtoms>(cx); |
4204 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
4205 | 0 | return false; |
4206 | 0 | } |
4207 | 0 | } |
4208 | 0 | |
4209 | 0 | if (!IsConvertibleToDictionary(val)) { |
4210 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
4211 | 0 | } |
4212 | 0 | |
4213 | 0 | bool isNull = val.isNullOrUndefined(); |
4214 | 0 | // We only need these if !isNull, in which case we have |cx|. |
4215 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
4216 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
4217 | 0 | if (!isNull) { |
4218 | 0 | MOZ_ASSERT(cx); |
4219 | 0 | object.emplace(cx, &val.toObject()); |
4220 | 0 | temp.emplace(cx); |
4221 | 0 | } |
4222 | 0 | if (!isNull) { |
4223 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->format_id, temp.ptr())) { |
4224 | 0 | return false; |
4225 | 0 | } |
4226 | 0 | } |
4227 | 0 | if (!isNull && !temp->isUndefined()) { |
4228 | 0 | mFormat.Construct(); |
4229 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mFormat.Value()))) { |
4230 | 0 | return false; |
4231 | 0 | } |
4232 | 0 | mIsAnyMemberPresent = true; |
4233 | 0 | } |
4234 | 0 |
|
4235 | 0 | if (!isNull) { |
4236 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->inputSlot_id, temp.ptr())) { |
4237 | 0 | return false; |
4238 | 0 | } |
4239 | 0 | } |
4240 | 0 | if (!isNull && !temp->isUndefined()) { |
4241 | 0 | mInputSlot.Construct(); |
4242 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mInputSlot.Value()))) { |
4243 | 0 | return false; |
4244 | 0 | } |
4245 | 0 | mIsAnyMemberPresent = true; |
4246 | 0 | } |
4247 | 0 |
|
4248 | 0 | if (!isNull) { |
4249 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->offset_id, temp.ptr())) { |
4250 | 0 | return false; |
4251 | 0 | } |
4252 | 0 | } |
4253 | 0 | if (!isNull && !temp->isUndefined()) { |
4254 | 0 | mOffset.Construct(); |
4255 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mOffset.Value()))) { |
4256 | 0 | return false; |
4257 | 0 | } |
4258 | 0 | mIsAnyMemberPresent = true; |
4259 | 0 | } |
4260 | 0 |
|
4261 | 0 | if (!isNull) { |
4262 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->shaderLocation_id, temp.ptr())) { |
4263 | 0 | return false; |
4264 | 0 | } |
4265 | 0 | } |
4266 | 0 | if (!isNull && !temp->isUndefined()) { |
4267 | 0 | mShaderLocation.Construct(); |
4268 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mShaderLocation.Value()))) { |
4269 | 0 | return false; |
4270 | 0 | } |
4271 | 0 | mIsAnyMemberPresent = true; |
4272 | 0 | } |
4273 | 0 | return true; |
4274 | 0 | } |
4275 | | |
4276 | | bool |
4277 | | WebGPUVertexAttributeDescriptor::Init(const nsAString& aJSON) |
4278 | 0 | { |
4279 | 0 | AutoJSAPI jsapi; |
4280 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
4281 | 0 | if (!cleanGlobal) { |
4282 | 0 | return false; |
4283 | 0 | } |
4284 | 0 | if (!jsapi.Init(cleanGlobal)) { |
4285 | 0 | return false; |
4286 | 0 | } |
4287 | 0 | JSContext* cx = jsapi.cx(); |
4288 | 0 | JS::Rooted<JS::Value> json(cx); |
4289 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
4290 | 0 | NS_ENSURE_TRUE(ok, false); |
4291 | 0 | return Init(cx, json); |
4292 | 0 | } |
4293 | | |
4294 | | bool |
4295 | | WebGPUVertexAttributeDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
4296 | 0 | { |
4297 | 0 | WebGPUVertexAttributeDescriptorAtoms* atomsCache = GetAtomCache<WebGPUVertexAttributeDescriptorAtoms>(cx); |
4298 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
4299 | 0 | return false; |
4300 | 0 | } |
4301 | 0 | |
4302 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
4303 | 0 | if (!obj) { |
4304 | 0 | return false; |
4305 | 0 | } |
4306 | 0 | rval.set(JS::ObjectValue(*obj)); |
4307 | 0 |
|
4308 | 0 | if (mFormat.WasPassed()) { |
4309 | 0 | do { |
4310 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
4311 | 0 | JS::Rooted<JS::Value> temp(cx); |
4312 | 0 | uint32_t const & currentValue = mFormat.InternalValue(); |
4313 | 0 | temp.setNumber(currentValue); |
4314 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->format_id, temp, JSPROP_ENUMERATE)) { |
4315 | 0 | return false; |
4316 | 0 | } |
4317 | 0 | break; |
4318 | 0 | } while(false); |
4319 | 0 | } |
4320 | 0 |
|
4321 | 0 | if (mInputSlot.WasPassed()) { |
4322 | 0 | do { |
4323 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
4324 | 0 | JS::Rooted<JS::Value> temp(cx); |
4325 | 0 | uint32_t const & currentValue = mInputSlot.InternalValue(); |
4326 | 0 | temp.setNumber(currentValue); |
4327 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->inputSlot_id, temp, JSPROP_ENUMERATE)) { |
4328 | 0 | return false; |
4329 | 0 | } |
4330 | 0 | break; |
4331 | 0 | } while(false); |
4332 | 0 | } |
4333 | 0 |
|
4334 | 0 | if (mOffset.WasPassed()) { |
4335 | 0 | do { |
4336 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
4337 | 0 | JS::Rooted<JS::Value> temp(cx); |
4338 | 0 | uint32_t const & currentValue = mOffset.InternalValue(); |
4339 | 0 | temp.setNumber(currentValue); |
4340 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->offset_id, temp, JSPROP_ENUMERATE)) { |
4341 | 0 | return false; |
4342 | 0 | } |
4343 | 0 | break; |
4344 | 0 | } while(false); |
4345 | 0 | } |
4346 | 0 |
|
4347 | 0 | if (mShaderLocation.WasPassed()) { |
4348 | 0 | do { |
4349 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
4350 | 0 | JS::Rooted<JS::Value> temp(cx); |
4351 | 0 | uint32_t const & currentValue = mShaderLocation.InternalValue(); |
4352 | 0 | temp.setNumber(currentValue); |
4353 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->shaderLocation_id, temp, JSPROP_ENUMERATE)) { |
4354 | 0 | return false; |
4355 | 0 | } |
4356 | 0 | break; |
4357 | 0 | } while(false); |
4358 | 0 | } |
4359 | 0 |
|
4360 | 0 | return true; |
4361 | 0 | } |
4362 | | |
4363 | | bool |
4364 | | WebGPUVertexAttributeDescriptor::ToJSON(nsAString& aJSON) const |
4365 | 0 | { |
4366 | 0 | AutoJSAPI jsapi; |
4367 | 0 | jsapi.Init(); |
4368 | 0 | JSContext *cx = jsapi.cx(); |
4369 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
4370 | 0 | // because we'll only be creating objects, in ways that have no |
4371 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
4372 | 0 | // which likewise guarantees no side-effects for the sorts of |
4373 | 0 | // things we will pass it. |
4374 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
4375 | 0 | JS::Rooted<JS::Value> val(cx); |
4376 | 0 | if (!ToObjectInternal(cx, &val)) { |
4377 | 0 | return false; |
4378 | 0 | } |
4379 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
4380 | 0 | return StringifyToJSON(cx, obj, aJSON); |
4381 | 0 | } |
4382 | | |
4383 | | void |
4384 | | WebGPUVertexAttributeDescriptor::TraceDictionary(JSTracer* trc) |
4385 | 0 | { |
4386 | 0 | } |
4387 | | |
4388 | | WebGPUVertexAttributeDescriptor& |
4389 | | WebGPUVertexAttributeDescriptor::operator=(const WebGPUVertexAttributeDescriptor& aOther) |
4390 | 0 | { |
4391 | 0 | DictionaryBase::operator=(aOther); |
4392 | 0 | mFormat.Reset(); |
4393 | 0 | if (aOther.mFormat.WasPassed()) { |
4394 | 0 | mFormat.Construct(aOther.mFormat.Value()); |
4395 | 0 | } |
4396 | 0 | mInputSlot.Reset(); |
4397 | 0 | if (aOther.mInputSlot.WasPassed()) { |
4398 | 0 | mInputSlot.Construct(aOther.mInputSlot.Value()); |
4399 | 0 | } |
4400 | 0 | mOffset.Reset(); |
4401 | 0 | if (aOther.mOffset.WasPassed()) { |
4402 | 0 | mOffset.Construct(aOther.mOffset.Value()); |
4403 | 0 | } |
4404 | 0 | mShaderLocation.Reset(); |
4405 | 0 | if (aOther.mShaderLocation.WasPassed()) { |
4406 | 0 | mShaderLocation.Construct(aOther.mShaderLocation.Value()); |
4407 | 0 | } |
4408 | 0 | return *this; |
4409 | 0 | } |
4410 | | |
4411 | | namespace binding_detail { |
4412 | | } // namespace binding_detail |
4413 | | |
4414 | | |
4415 | | |
4416 | | WebGPUVertexInputDescriptor::WebGPUVertexInputDescriptor() |
4417 | 0 | { |
4418 | 0 | // Safe to pass a null context if we pass a null value |
4419 | 0 | Init(nullptr, JS::NullHandleValue); |
4420 | 0 | } |
4421 | | |
4422 | | |
4423 | | |
4424 | | bool |
4425 | | WebGPUVertexInputDescriptor::InitIds(JSContext* cx, WebGPUVertexInputDescriptorAtoms* atomsCache) |
4426 | 0 | { |
4427 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
4428 | 0 |
|
4429 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
4430 | 0 | // uninitialized. |
4431 | 0 | if (!atomsCache->stride_id.init(cx, "stride") || |
4432 | 0 | !atomsCache->stepMode_id.init(cx, "stepMode") || |
4433 | 0 | !atomsCache->inputSlot_id.init(cx, "inputSlot")) { |
4434 | 0 | return false; |
4435 | 0 | } |
4436 | 0 | return true; |
4437 | 0 | } |
4438 | | |
4439 | | bool |
4440 | | WebGPUVertexInputDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
4441 | 0 | { |
4442 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
4443 | 0 | // Since in that case we will not have to do any property gets |
4444 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
4445 | 0 | // checkers by static analysis tools |
4446 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
4447 | 0 | WebGPUVertexInputDescriptorAtoms* atomsCache = nullptr; |
4448 | 0 | if (cx) { |
4449 | 0 | atomsCache = GetAtomCache<WebGPUVertexInputDescriptorAtoms>(cx); |
4450 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
4451 | 0 | return false; |
4452 | 0 | } |
4453 | 0 | } |
4454 | 0 | |
4455 | 0 | if (!IsConvertibleToDictionary(val)) { |
4456 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
4457 | 0 | } |
4458 | 0 | |
4459 | 0 | bool isNull = val.isNullOrUndefined(); |
4460 | 0 | // We only need these if !isNull, in which case we have |cx|. |
4461 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
4462 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
4463 | 0 | if (!isNull) { |
4464 | 0 | MOZ_ASSERT(cx); |
4465 | 0 | object.emplace(cx, &val.toObject()); |
4466 | 0 | temp.emplace(cx); |
4467 | 0 | } |
4468 | 0 | if (!isNull) { |
4469 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->inputSlot_id, temp.ptr())) { |
4470 | 0 | return false; |
4471 | 0 | } |
4472 | 0 | } |
4473 | 0 | if (!isNull && !temp->isUndefined()) { |
4474 | 0 | mInputSlot.Construct(); |
4475 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mInputSlot.Value()))) { |
4476 | 0 | return false; |
4477 | 0 | } |
4478 | 0 | mIsAnyMemberPresent = true; |
4479 | 0 | } |
4480 | 0 |
|
4481 | 0 | if (!isNull) { |
4482 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->stepMode_id, temp.ptr())) { |
4483 | 0 | return false; |
4484 | 0 | } |
4485 | 0 | } |
4486 | 0 | if (!isNull && !temp->isUndefined()) { |
4487 | 0 | mStepMode.Construct(); |
4488 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mStepMode.Value()))) { |
4489 | 0 | return false; |
4490 | 0 | } |
4491 | 0 | mIsAnyMemberPresent = true; |
4492 | 0 | } |
4493 | 0 |
|
4494 | 0 | if (!isNull) { |
4495 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->stride_id, temp.ptr())) { |
4496 | 0 | return false; |
4497 | 0 | } |
4498 | 0 | } |
4499 | 0 | if (!isNull && !temp->isUndefined()) { |
4500 | 0 | mStride.Construct(); |
4501 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mStride.Value()))) { |
4502 | 0 | return false; |
4503 | 0 | } |
4504 | 0 | mIsAnyMemberPresent = true; |
4505 | 0 | } |
4506 | 0 | return true; |
4507 | 0 | } |
4508 | | |
4509 | | bool |
4510 | | WebGPUVertexInputDescriptor::Init(const nsAString& aJSON) |
4511 | 0 | { |
4512 | 0 | AutoJSAPI jsapi; |
4513 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
4514 | 0 | if (!cleanGlobal) { |
4515 | 0 | return false; |
4516 | 0 | } |
4517 | 0 | if (!jsapi.Init(cleanGlobal)) { |
4518 | 0 | return false; |
4519 | 0 | } |
4520 | 0 | JSContext* cx = jsapi.cx(); |
4521 | 0 | JS::Rooted<JS::Value> json(cx); |
4522 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
4523 | 0 | NS_ENSURE_TRUE(ok, false); |
4524 | 0 | return Init(cx, json); |
4525 | 0 | } |
4526 | | |
4527 | | bool |
4528 | | WebGPUVertexInputDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
4529 | 0 | { |
4530 | 0 | WebGPUVertexInputDescriptorAtoms* atomsCache = GetAtomCache<WebGPUVertexInputDescriptorAtoms>(cx); |
4531 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
4532 | 0 | return false; |
4533 | 0 | } |
4534 | 0 | |
4535 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
4536 | 0 | if (!obj) { |
4537 | 0 | return false; |
4538 | 0 | } |
4539 | 0 | rval.set(JS::ObjectValue(*obj)); |
4540 | 0 |
|
4541 | 0 | if (mInputSlot.WasPassed()) { |
4542 | 0 | do { |
4543 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
4544 | 0 | JS::Rooted<JS::Value> temp(cx); |
4545 | 0 | uint32_t const & currentValue = mInputSlot.InternalValue(); |
4546 | 0 | temp.setNumber(currentValue); |
4547 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->inputSlot_id, temp, JSPROP_ENUMERATE)) { |
4548 | 0 | return false; |
4549 | 0 | } |
4550 | 0 | break; |
4551 | 0 | } while(false); |
4552 | 0 | } |
4553 | 0 |
|
4554 | 0 | if (mStepMode.WasPassed()) { |
4555 | 0 | do { |
4556 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
4557 | 0 | JS::Rooted<JS::Value> temp(cx); |
4558 | 0 | uint32_t const & currentValue = mStepMode.InternalValue(); |
4559 | 0 | temp.setNumber(currentValue); |
4560 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->stepMode_id, temp, JSPROP_ENUMERATE)) { |
4561 | 0 | return false; |
4562 | 0 | } |
4563 | 0 | break; |
4564 | 0 | } while(false); |
4565 | 0 | } |
4566 | 0 |
|
4567 | 0 | if (mStride.WasPassed()) { |
4568 | 0 | do { |
4569 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
4570 | 0 | JS::Rooted<JS::Value> temp(cx); |
4571 | 0 | uint32_t const & currentValue = mStride.InternalValue(); |
4572 | 0 | temp.setNumber(currentValue); |
4573 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->stride_id, temp, JSPROP_ENUMERATE)) { |
4574 | 0 | return false; |
4575 | 0 | } |
4576 | 0 | break; |
4577 | 0 | } while(false); |
4578 | 0 | } |
4579 | 0 |
|
4580 | 0 | return true; |
4581 | 0 | } |
4582 | | |
4583 | | bool |
4584 | | WebGPUVertexInputDescriptor::ToJSON(nsAString& aJSON) const |
4585 | 0 | { |
4586 | 0 | AutoJSAPI jsapi; |
4587 | 0 | jsapi.Init(); |
4588 | 0 | JSContext *cx = jsapi.cx(); |
4589 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
4590 | 0 | // because we'll only be creating objects, in ways that have no |
4591 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
4592 | 0 | // which likewise guarantees no side-effects for the sorts of |
4593 | 0 | // things we will pass it. |
4594 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
4595 | 0 | JS::Rooted<JS::Value> val(cx); |
4596 | 0 | if (!ToObjectInternal(cx, &val)) { |
4597 | 0 | return false; |
4598 | 0 | } |
4599 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
4600 | 0 | return StringifyToJSON(cx, obj, aJSON); |
4601 | 0 | } |
4602 | | |
4603 | | void |
4604 | | WebGPUVertexInputDescriptor::TraceDictionary(JSTracer* trc) |
4605 | 0 | { |
4606 | 0 | } |
4607 | | |
4608 | | WebGPUVertexInputDescriptor& |
4609 | | WebGPUVertexInputDescriptor::operator=(const WebGPUVertexInputDescriptor& aOther) |
4610 | 0 | { |
4611 | 0 | DictionaryBase::operator=(aOther); |
4612 | 0 | mInputSlot.Reset(); |
4613 | 0 | if (aOther.mInputSlot.WasPassed()) { |
4614 | 0 | mInputSlot.Construct(aOther.mInputSlot.Value()); |
4615 | 0 | } |
4616 | 0 | mStepMode.Reset(); |
4617 | 0 | if (aOther.mStepMode.WasPassed()) { |
4618 | 0 | mStepMode.Construct(aOther.mStepMode.Value()); |
4619 | 0 | } |
4620 | 0 | mStride.Reset(); |
4621 | 0 | if (aOther.mStride.WasPassed()) { |
4622 | 0 | mStride.Construct(aOther.mStride.Value()); |
4623 | 0 | } |
4624 | 0 | return *this; |
4625 | 0 | } |
4626 | | |
4627 | | namespace binding_detail { |
4628 | | } // namespace binding_detail |
4629 | | |
4630 | | |
4631 | | |
4632 | | WebGPUBindGroupLayoutDescriptor::WebGPUBindGroupLayoutDescriptor() |
4633 | 0 | { |
4634 | 0 | // Safe to pass a null context if we pass a null value |
4635 | 0 | Init(nullptr, JS::NullHandleValue); |
4636 | 0 | } |
4637 | | |
4638 | | |
4639 | | |
4640 | | bool |
4641 | | WebGPUBindGroupLayoutDescriptor::InitIds(JSContext* cx, WebGPUBindGroupLayoutDescriptorAtoms* atomsCache) |
4642 | 0 | { |
4643 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
4644 | 0 |
|
4645 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
4646 | 0 | // uninitialized. |
4647 | 0 | if (!atomsCache->bindingTypes_id.init(cx, "bindingTypes")) { |
4648 | 0 | return false; |
4649 | 0 | } |
4650 | 0 | return true; |
4651 | 0 | } |
4652 | | |
4653 | | bool |
4654 | | WebGPUBindGroupLayoutDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
4655 | 0 | { |
4656 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
4657 | 0 | // Since in that case we will not have to do any property gets |
4658 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
4659 | 0 | // checkers by static analysis tools |
4660 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
4661 | 0 | WebGPUBindGroupLayoutDescriptorAtoms* atomsCache = nullptr; |
4662 | 0 | if (cx) { |
4663 | 0 | atomsCache = GetAtomCache<WebGPUBindGroupLayoutDescriptorAtoms>(cx); |
4664 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
4665 | 0 | return false; |
4666 | 0 | } |
4667 | 0 | } |
4668 | 0 | |
4669 | 0 | if (!IsConvertibleToDictionary(val)) { |
4670 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
4671 | 0 | } |
4672 | 0 | |
4673 | 0 | bool isNull = val.isNullOrUndefined(); |
4674 | 0 | // We only need these if !isNull, in which case we have |cx|. |
4675 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
4676 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
4677 | 0 | if (!isNull) { |
4678 | 0 | MOZ_ASSERT(cx); |
4679 | 0 | object.emplace(cx, &val.toObject()); |
4680 | 0 | temp.emplace(cx); |
4681 | 0 | } |
4682 | 0 | if (!isNull) { |
4683 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->bindingTypes_id, temp.ptr())) { |
4684 | 0 | return false; |
4685 | 0 | } |
4686 | 0 | } |
4687 | 0 | if (!isNull && !temp->isUndefined()) { |
4688 | 0 | mBindingTypes.Construct(); |
4689 | 0 | if (temp.ref().isObject()) { |
4690 | 0 | JS::ForOfIterator iter(cx); |
4691 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
4692 | 0 | return false; |
4693 | 0 | } |
4694 | 0 | if (!iter.valueIsIterable()) { |
4695 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'bindingTypes' member of WebGPUBindGroupLayoutDescriptor"); |
4696 | 0 | return false; |
4697 | 0 | } |
4698 | 0 | Sequence<WebGPUBindGroupBinding> &arr = (mBindingTypes.Value()); |
4699 | 0 | JS::Rooted<JS::Value> temp(cx); |
4700 | 0 | while (true) { |
4701 | 0 | bool done; |
4702 | 0 | if (!iter.next(&temp, &done)) { |
4703 | 0 | return false; |
4704 | 0 | } |
4705 | 0 | if (done) { |
4706 | 0 | break; |
4707 | 0 | } |
4708 | 0 | WebGPUBindGroupBinding* slotPtr = arr.AppendElement(mozilla::fallible); |
4709 | 0 | if (!slotPtr) { |
4710 | 0 | JS_ReportOutOfMemory(cx); |
4711 | 0 | return false; |
4712 | 0 | } |
4713 | 0 | WebGPUBindGroupBinding& slot = *slotPtr; |
4714 | 0 | if (!slot.Init(cx, temp, "Element of 'bindingTypes' member of WebGPUBindGroupLayoutDescriptor", passedToJSImpl)) { |
4715 | 0 | return false; |
4716 | 0 | } |
4717 | 0 | } |
4718 | 0 | } else { |
4719 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'bindingTypes' member of WebGPUBindGroupLayoutDescriptor"); |
4720 | 0 | return false; |
4721 | 0 | } |
4722 | 0 | mIsAnyMemberPresent = true; |
4723 | 0 | } |
4724 | 0 | return true; |
4725 | 0 | } |
4726 | | |
4727 | | bool |
4728 | | WebGPUBindGroupLayoutDescriptor::Init(const nsAString& aJSON) |
4729 | 0 | { |
4730 | 0 | AutoJSAPI jsapi; |
4731 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
4732 | 0 | if (!cleanGlobal) { |
4733 | 0 | return false; |
4734 | 0 | } |
4735 | 0 | if (!jsapi.Init(cleanGlobal)) { |
4736 | 0 | return false; |
4737 | 0 | } |
4738 | 0 | JSContext* cx = jsapi.cx(); |
4739 | 0 | JS::Rooted<JS::Value> json(cx); |
4740 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
4741 | 0 | NS_ENSURE_TRUE(ok, false); |
4742 | 0 | return Init(cx, json); |
4743 | 0 | } |
4744 | | |
4745 | | bool |
4746 | | WebGPUBindGroupLayoutDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
4747 | 0 | { |
4748 | 0 | WebGPUBindGroupLayoutDescriptorAtoms* atomsCache = GetAtomCache<WebGPUBindGroupLayoutDescriptorAtoms>(cx); |
4749 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
4750 | 0 | return false; |
4751 | 0 | } |
4752 | 0 | |
4753 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
4754 | 0 | if (!obj) { |
4755 | 0 | return false; |
4756 | 0 | } |
4757 | 0 | rval.set(JS::ObjectValue(*obj)); |
4758 | 0 |
|
4759 | 0 | if (mBindingTypes.WasPassed()) { |
4760 | 0 | do { |
4761 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
4762 | 0 | JS::Rooted<JS::Value> temp(cx); |
4763 | 0 | Sequence<WebGPUBindGroupBinding> const & currentValue = mBindingTypes.InternalValue(); |
4764 | 0 |
|
4765 | 0 | uint32_t length = currentValue.Length(); |
4766 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
4767 | 0 | if (!returnArray) { |
4768 | 0 | return false; |
4769 | 0 | } |
4770 | 0 | // Scope for 'tmp' |
4771 | 0 | { |
4772 | 0 | JS::Rooted<JS::Value> tmp(cx); |
4773 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
4774 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
4775 | 0 | // are different ways to succeed at wrapping the object. |
4776 | 0 | do { |
4777 | 0 | if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) { |
4778 | 0 | return false; |
4779 | 0 | } |
4780 | 0 | break; |
4781 | 0 | } while (false); |
4782 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
4783 | 0 | JSPROP_ENUMERATE)) { |
4784 | 0 | return false; |
4785 | 0 | } |
4786 | 0 | } |
4787 | 0 | } |
4788 | 0 | temp.setObject(*returnArray); |
4789 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->bindingTypes_id, temp, JSPROP_ENUMERATE)) { |
4790 | 0 | return false; |
4791 | 0 | } |
4792 | 0 | break; |
4793 | 0 | } while(false); |
4794 | 0 | } |
4795 | 0 |
|
4796 | 0 | return true; |
4797 | 0 | } |
4798 | | |
4799 | | bool |
4800 | | WebGPUBindGroupLayoutDescriptor::ToJSON(nsAString& aJSON) const |
4801 | 0 | { |
4802 | 0 | AutoJSAPI jsapi; |
4803 | 0 | jsapi.Init(); |
4804 | 0 | JSContext *cx = jsapi.cx(); |
4805 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
4806 | 0 | // because we'll only be creating objects, in ways that have no |
4807 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
4808 | 0 | // which likewise guarantees no side-effects for the sorts of |
4809 | 0 | // things we will pass it. |
4810 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
4811 | 0 | JS::Rooted<JS::Value> val(cx); |
4812 | 0 | if (!ToObjectInternal(cx, &val)) { |
4813 | 0 | return false; |
4814 | 0 | } |
4815 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
4816 | 0 | return StringifyToJSON(cx, obj, aJSON); |
4817 | 0 | } |
4818 | | |
4819 | | void |
4820 | | WebGPUBindGroupLayoutDescriptor::TraceDictionary(JSTracer* trc) |
4821 | 0 | { |
4822 | 0 | } |
4823 | | |
4824 | | WebGPUBindGroupLayoutDescriptor& |
4825 | | WebGPUBindGroupLayoutDescriptor::operator=(const WebGPUBindGroupLayoutDescriptor& aOther) |
4826 | 0 | { |
4827 | 0 | DictionaryBase::operator=(aOther); |
4828 | 0 | mBindingTypes.Reset(); |
4829 | 0 | if (aOther.mBindingTypes.WasPassed()) { |
4830 | 0 | mBindingTypes.Construct(aOther.mBindingTypes.Value()); |
4831 | 0 | } |
4832 | 0 | return *this; |
4833 | 0 | } |
4834 | | |
4835 | | namespace binding_detail { |
4836 | | } // namespace binding_detail |
4837 | | |
4838 | | |
4839 | | |
4840 | | WebGPUBinding::WebGPUBinding() |
4841 | 0 | { |
4842 | 0 | // Safe to pass a null context if we pass a null value |
4843 | 0 | Init(nullptr, JS::NullHandleValue); |
4844 | 0 | } |
4845 | | |
4846 | | |
4847 | | |
4848 | | bool |
4849 | | WebGPUBinding::InitIds(JSContext* cx, WebGPUBindingAtoms* atomsCache) |
4850 | 0 | { |
4851 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
4852 | 0 |
|
4853 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
4854 | 0 | // uninitialized. |
4855 | 0 | if (!atomsCache->start_id.init(cx, "start") || |
4856 | 0 | !atomsCache->resources_id.init(cx, "resources") || |
4857 | 0 | !atomsCache->count_id.init(cx, "count")) { |
4858 | 0 | return false; |
4859 | 0 | } |
4860 | 0 | return true; |
4861 | 0 | } |
4862 | | |
4863 | | bool |
4864 | | WebGPUBinding::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
4865 | 0 | { |
4866 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
4867 | 0 | // Since in that case we will not have to do any property gets |
4868 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
4869 | 0 | // checkers by static analysis tools |
4870 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
4871 | 0 | WebGPUBindingAtoms* atomsCache = nullptr; |
4872 | 0 | if (cx) { |
4873 | 0 | atomsCache = GetAtomCache<WebGPUBindingAtoms>(cx); |
4874 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
4875 | 0 | return false; |
4876 | 0 | } |
4877 | 0 | } |
4878 | 0 | |
4879 | 0 | if (!IsConvertibleToDictionary(val)) { |
4880 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
4881 | 0 | } |
4882 | 0 | |
4883 | 0 | bool isNull = val.isNullOrUndefined(); |
4884 | 0 | // We only need these if !isNull, in which case we have |cx|. |
4885 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
4886 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
4887 | 0 | if (!isNull) { |
4888 | 0 | MOZ_ASSERT(cx); |
4889 | 0 | object.emplace(cx, &val.toObject()); |
4890 | 0 | temp.emplace(cx); |
4891 | 0 | } |
4892 | 0 | if (!isNull) { |
4893 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->count_id, temp.ptr())) { |
4894 | 0 | return false; |
4895 | 0 | } |
4896 | 0 | } |
4897 | 0 | if (!isNull && !temp->isUndefined()) { |
4898 | 0 | mCount.Construct(); |
4899 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mCount.Value()))) { |
4900 | 0 | return false; |
4901 | 0 | } |
4902 | 0 | mIsAnyMemberPresent = true; |
4903 | 0 | } |
4904 | 0 |
|
4905 | 0 | if (!isNull) { |
4906 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->resources_id, temp.ptr())) { |
4907 | 0 | return false; |
4908 | 0 | } |
4909 | 0 | } |
4910 | 0 | if (!isNull && !temp->isUndefined()) { |
4911 | 0 | mResources.Construct(); |
4912 | 0 | if (temp.ref().isObject()) { |
4913 | 0 | JS::ForOfIterator iter(cx); |
4914 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
4915 | 0 | return false; |
4916 | 0 | } |
4917 | 0 | if (!iter.valueIsIterable()) { |
4918 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'resources' member of WebGPUBinding"); |
4919 | 0 | return false; |
4920 | 0 | } |
4921 | 0 | Sequence<OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding> &arr = (mResources.Value()); |
4922 | 0 | JS::Rooted<JS::Value> temp(cx); |
4923 | 0 | while (true) { |
4924 | 0 | bool done; |
4925 | 0 | if (!iter.next(&temp, &done)) { |
4926 | 0 | return false; |
4927 | 0 | } |
4928 | 0 | if (done) { |
4929 | 0 | break; |
4930 | 0 | } |
4931 | 0 | OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding* slotPtr = arr.AppendElement(mozilla::fallible); |
4932 | 0 | if (!slotPtr) { |
4933 | 0 | JS_ReportOutOfMemory(cx); |
4934 | 0 | return false; |
4935 | 0 | } |
4936 | 0 | OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding& slot = *slotPtr; |
4937 | 0 | { |
4938 | 0 | bool done = false, failed = false, tryNext; |
4939 | 0 | if (temp.isObject()) { |
4940 | 0 | done = (failed = !slot.TrySetToWebGPUSampler(cx, temp, tryNext, passedToJSImpl)) || !tryNext || |
4941 | 0 | (failed = !slot.TrySetToWebGPUTextureView(cx, temp, tryNext, passedToJSImpl)) || !tryNext; |
4942 | 0 |
|
4943 | 0 | } |
4944 | 0 | if (!done) { |
4945 | 0 | done = (failed = !slot.TrySetToWebGPUBufferBinding(cx, temp, tryNext, passedToJSImpl)) || !tryNext; |
4946 | 0 | } |
4947 | 0 | if (failed) { |
4948 | 0 | return false; |
4949 | 0 | } |
4950 | 0 | if (!done) { |
4951 | 0 | ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Element of 'resources' member of WebGPUBinding", "WebGPUSampler, WebGPUTextureView, WebGPUBufferBinding"); |
4952 | 0 | return false; |
4953 | 0 | } |
4954 | 0 | } |
4955 | 0 | } |
4956 | 0 | } else { |
4957 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'resources' member of WebGPUBinding"); |
4958 | 0 | return false; |
4959 | 0 | } |
4960 | 0 | mIsAnyMemberPresent = true; |
4961 | 0 | } |
4962 | 0 |
|
4963 | 0 | if (!isNull) { |
4964 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->start_id, temp.ptr())) { |
4965 | 0 | return false; |
4966 | 0 | } |
4967 | 0 | } |
4968 | 0 | if (!isNull && !temp->isUndefined()) { |
4969 | 0 | mStart.Construct(); |
4970 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mStart.Value()))) { |
4971 | 0 | return false; |
4972 | 0 | } |
4973 | 0 | mIsAnyMemberPresent = true; |
4974 | 0 | } |
4975 | 0 | return true; |
4976 | 0 | } |
4977 | | |
4978 | | bool |
4979 | | WebGPUBinding::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
4980 | 0 | { |
4981 | 0 | WebGPUBindingAtoms* atomsCache = GetAtomCache<WebGPUBindingAtoms>(cx); |
4982 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
4983 | 0 | return false; |
4984 | 0 | } |
4985 | 0 | |
4986 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
4987 | 0 | if (!obj) { |
4988 | 0 | return false; |
4989 | 0 | } |
4990 | 0 | rval.set(JS::ObjectValue(*obj)); |
4991 | 0 |
|
4992 | 0 | if (mCount.WasPassed()) { |
4993 | 0 | do { |
4994 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
4995 | 0 | JS::Rooted<JS::Value> temp(cx); |
4996 | 0 | uint32_t const & currentValue = mCount.InternalValue(); |
4997 | 0 | temp.setNumber(currentValue); |
4998 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->count_id, temp, JSPROP_ENUMERATE)) { |
4999 | 0 | return false; |
5000 | 0 | } |
5001 | 0 | break; |
5002 | 0 | } while(false); |
5003 | 0 | } |
5004 | 0 |
|
5005 | 0 | if (mResources.WasPassed()) { |
5006 | 0 | do { |
5007 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
5008 | 0 | JS::Rooted<JS::Value> temp(cx); |
5009 | 0 | Sequence<OwningWebGPUSamplerOrWebGPUTextureViewOrWebGPUBufferBinding> const & currentValue = mResources.InternalValue(); |
5010 | 0 |
|
5011 | 0 | uint32_t length = currentValue.Length(); |
5012 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
5013 | 0 | if (!returnArray) { |
5014 | 0 | return false; |
5015 | 0 | } |
5016 | 0 | // Scope for 'tmp' |
5017 | 0 | { |
5018 | 0 | JS::Rooted<JS::Value> tmp(cx); |
5019 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
5020 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
5021 | 0 | // are different ways to succeed at wrapping the object. |
5022 | 0 | do { |
5023 | 0 | if (!currentValue[sequenceIdx0].ToJSVal(cx, returnArray, &tmp)) { |
5024 | 0 | return false; |
5025 | 0 | } |
5026 | 0 | break; |
5027 | 0 | } while (false); |
5028 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
5029 | 0 | JSPROP_ENUMERATE)) { |
5030 | 0 | return false; |
5031 | 0 | } |
5032 | 0 | } |
5033 | 0 | } |
5034 | 0 | temp.setObject(*returnArray); |
5035 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->resources_id, temp, JSPROP_ENUMERATE)) { |
5036 | 0 | return false; |
5037 | 0 | } |
5038 | 0 | break; |
5039 | 0 | } while(false); |
5040 | 0 | } |
5041 | 0 |
|
5042 | 0 | if (mStart.WasPassed()) { |
5043 | 0 | do { |
5044 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
5045 | 0 | JS::Rooted<JS::Value> temp(cx); |
5046 | 0 | uint32_t const & currentValue = mStart.InternalValue(); |
5047 | 0 | temp.setNumber(currentValue); |
5048 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->start_id, temp, JSPROP_ENUMERATE)) { |
5049 | 0 | return false; |
5050 | 0 | } |
5051 | 0 | break; |
5052 | 0 | } while(false); |
5053 | 0 | } |
5054 | 0 |
|
5055 | 0 | return true; |
5056 | 0 | } |
5057 | | |
5058 | | void |
5059 | | WebGPUBinding::TraceDictionary(JSTracer* trc) |
5060 | 0 | { |
5061 | 0 | } |
5062 | | |
5063 | | |
5064 | | |
5065 | | WebGPUBinding& |
5066 | | WebGPUBinding::operator=(const WebGPUBinding& aOther) |
5067 | 0 | { |
5068 | 0 | DictionaryBase::operator=(aOther); |
5069 | 0 | mCount.Reset(); |
5070 | 0 | if (aOther.mCount.WasPassed()) { |
5071 | 0 | mCount.Construct(aOther.mCount.Value()); |
5072 | 0 | } |
5073 | 0 | mResources.Reset(); |
5074 | 0 | if (aOther.mResources.WasPassed()) { |
5075 | 0 | mResources.Construct(aOther.mResources.Value()); |
5076 | 0 | } |
5077 | 0 | mStart.Reset(); |
5078 | 0 | if (aOther.mStart.WasPassed()) { |
5079 | 0 | mStart.Construct(aOther.mStart.Value()); |
5080 | 0 | } |
5081 | 0 | return *this; |
5082 | 0 | } |
5083 | | |
5084 | | namespace binding_detail { |
5085 | | } // namespace binding_detail |
5086 | | |
5087 | | |
5088 | | |
5089 | | WebGPUBlendStateDescriptor::WebGPUBlendStateDescriptor() |
5090 | | : mAlpha(FastDictionaryInitializer()), |
5091 | | mColor(FastDictionaryInitializer()) |
5092 | 0 | { |
5093 | 0 | // Safe to pass a null context if we pass a null value |
5094 | 0 | Init(nullptr, JS::NullHandleValue); |
5095 | 0 | } |
5096 | | |
5097 | | |
5098 | | |
5099 | | bool |
5100 | | WebGPUBlendStateDescriptor::InitIds(JSContext* cx, WebGPUBlendStateDescriptorAtoms* atomsCache) |
5101 | 0 | { |
5102 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
5103 | 0 |
|
5104 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
5105 | 0 | // uninitialized. |
5106 | 0 | if (!atomsCache->writeMask_id.init(cx, "writeMask") || |
5107 | 0 | !atomsCache->color_id.init(cx, "color") || |
5108 | 0 | !atomsCache->blendEnabled_id.init(cx, "blendEnabled") || |
5109 | 0 | !atomsCache->alpha_id.init(cx, "alpha")) { |
5110 | 0 | return false; |
5111 | 0 | } |
5112 | 0 | return true; |
5113 | 0 | } |
5114 | | |
5115 | | bool |
5116 | | WebGPUBlendStateDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
5117 | 0 | { |
5118 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
5119 | 0 | // Since in that case we will not have to do any property gets |
5120 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
5121 | 0 | // checkers by static analysis tools |
5122 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
5123 | 0 | WebGPUBlendStateDescriptorAtoms* atomsCache = nullptr; |
5124 | 0 | if (cx) { |
5125 | 0 | atomsCache = GetAtomCache<WebGPUBlendStateDescriptorAtoms>(cx); |
5126 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
5127 | 0 | return false; |
5128 | 0 | } |
5129 | 0 | } |
5130 | 0 | |
5131 | 0 | if (!IsConvertibleToDictionary(val)) { |
5132 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
5133 | 0 | } |
5134 | 0 | |
5135 | 0 | bool isNull = val.isNullOrUndefined(); |
5136 | 0 | // We only need these if !isNull, in which case we have |cx|. |
5137 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
5138 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
5139 | 0 | if (!isNull) { |
5140 | 0 | MOZ_ASSERT(cx); |
5141 | 0 | object.emplace(cx, &val.toObject()); |
5142 | 0 | temp.emplace(cx); |
5143 | 0 | } |
5144 | 0 | if (!isNull) { |
5145 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->alpha_id, temp.ptr())) { |
5146 | 0 | return false; |
5147 | 0 | } |
5148 | 0 | } |
5149 | 0 | if (!mAlpha.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue, "'alpha' member of WebGPUBlendStateDescriptor", passedToJSImpl)) { |
5150 | 0 | return false; |
5151 | 0 | } |
5152 | 0 | mIsAnyMemberPresent = true; |
5153 | 0 |
|
5154 | 0 | if (!isNull) { |
5155 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->blendEnabled_id, temp.ptr())) { |
5156 | 0 | return false; |
5157 | 0 | } |
5158 | 0 | } |
5159 | 0 | if (!isNull && !temp->isUndefined()) { |
5160 | 0 | mBlendEnabled.Construct(); |
5161 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &(mBlendEnabled.Value()))) { |
5162 | 0 | return false; |
5163 | 0 | } |
5164 | 0 | mIsAnyMemberPresent = true; |
5165 | 0 | } |
5166 | 0 |
|
5167 | 0 | if (!isNull) { |
5168 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->color_id, temp.ptr())) { |
5169 | 0 | return false; |
5170 | 0 | } |
5171 | 0 | } |
5172 | 0 | if (!mColor.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue, "'color' member of WebGPUBlendStateDescriptor", passedToJSImpl)) { |
5173 | 0 | return false; |
5174 | 0 | } |
5175 | 0 | mIsAnyMemberPresent = true; |
5176 | 0 |
|
5177 | 0 | if (!isNull) { |
5178 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->writeMask_id, temp.ptr())) { |
5179 | 0 | return false; |
5180 | 0 | } |
5181 | 0 | } |
5182 | 0 | if (!isNull && !temp->isUndefined()) { |
5183 | 0 | mWriteMask.Construct(); |
5184 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mWriteMask.Value()))) { |
5185 | 0 | return false; |
5186 | 0 | } |
5187 | 0 | mIsAnyMemberPresent = true; |
5188 | 0 | } |
5189 | 0 | return true; |
5190 | 0 | } |
5191 | | |
5192 | | bool |
5193 | | WebGPUBlendStateDescriptor::Init(const nsAString& aJSON) |
5194 | 0 | { |
5195 | 0 | AutoJSAPI jsapi; |
5196 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
5197 | 0 | if (!cleanGlobal) { |
5198 | 0 | return false; |
5199 | 0 | } |
5200 | 0 | if (!jsapi.Init(cleanGlobal)) { |
5201 | 0 | return false; |
5202 | 0 | } |
5203 | 0 | JSContext* cx = jsapi.cx(); |
5204 | 0 | JS::Rooted<JS::Value> json(cx); |
5205 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
5206 | 0 | NS_ENSURE_TRUE(ok, false); |
5207 | 0 | return Init(cx, json); |
5208 | 0 | } |
5209 | | |
5210 | | bool |
5211 | | WebGPUBlendStateDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
5212 | 0 | { |
5213 | 0 | WebGPUBlendStateDescriptorAtoms* atomsCache = GetAtomCache<WebGPUBlendStateDescriptorAtoms>(cx); |
5214 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
5215 | 0 | return false; |
5216 | 0 | } |
5217 | 0 | |
5218 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
5219 | 0 | if (!obj) { |
5220 | 0 | return false; |
5221 | 0 | } |
5222 | 0 | rval.set(JS::ObjectValue(*obj)); |
5223 | 0 |
|
5224 | 0 | do { |
5225 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
5226 | 0 | JS::Rooted<JS::Value> temp(cx); |
5227 | 0 | WebGPUBlendDescriptor const & currentValue = mAlpha; |
5228 | 0 | if (!currentValue.ToObjectInternal(cx, &temp)) { |
5229 | 0 | return false; |
5230 | 0 | } |
5231 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->alpha_id, temp, JSPROP_ENUMERATE)) { |
5232 | 0 | return false; |
5233 | 0 | } |
5234 | 0 | break; |
5235 | 0 | } while(false); |
5236 | 0 |
|
5237 | 0 | if (mBlendEnabled.WasPassed()) { |
5238 | 0 | do { |
5239 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
5240 | 0 | JS::Rooted<JS::Value> temp(cx); |
5241 | 0 | bool const & currentValue = mBlendEnabled.InternalValue(); |
5242 | 0 | temp.setBoolean(currentValue); |
5243 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->blendEnabled_id, temp, JSPROP_ENUMERATE)) { |
5244 | 0 | return false; |
5245 | 0 | } |
5246 | 0 | break; |
5247 | 0 | } while(false); |
5248 | 0 | } |
5249 | 0 |
|
5250 | 0 | do { |
5251 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
5252 | 0 | JS::Rooted<JS::Value> temp(cx); |
5253 | 0 | WebGPUBlendDescriptor const & currentValue = mColor; |
5254 | 0 | if (!currentValue.ToObjectInternal(cx, &temp)) { |
5255 | 0 | return false; |
5256 | 0 | } |
5257 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->color_id, temp, JSPROP_ENUMERATE)) { |
5258 | 0 | return false; |
5259 | 0 | } |
5260 | 0 | break; |
5261 | 0 | } while(false); |
5262 | 0 |
|
5263 | 0 | if (mWriteMask.WasPassed()) { |
5264 | 0 | do { |
5265 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
5266 | 0 | JS::Rooted<JS::Value> temp(cx); |
5267 | 0 | uint32_t const & currentValue = mWriteMask.InternalValue(); |
5268 | 0 | temp.setNumber(currentValue); |
5269 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->writeMask_id, temp, JSPROP_ENUMERATE)) { |
5270 | 0 | return false; |
5271 | 0 | } |
5272 | 0 | break; |
5273 | 0 | } while(false); |
5274 | 0 | } |
5275 | 0 |
|
5276 | 0 | return true; |
5277 | 0 | } |
5278 | | |
5279 | | bool |
5280 | | WebGPUBlendStateDescriptor::ToJSON(nsAString& aJSON) const |
5281 | 0 | { |
5282 | 0 | AutoJSAPI jsapi; |
5283 | 0 | jsapi.Init(); |
5284 | 0 | JSContext *cx = jsapi.cx(); |
5285 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
5286 | 0 | // because we'll only be creating objects, in ways that have no |
5287 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
5288 | 0 | // which likewise guarantees no side-effects for the sorts of |
5289 | 0 | // things we will pass it. |
5290 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
5291 | 0 | JS::Rooted<JS::Value> val(cx); |
5292 | 0 | if (!ToObjectInternal(cx, &val)) { |
5293 | 0 | return false; |
5294 | 0 | } |
5295 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
5296 | 0 | return StringifyToJSON(cx, obj, aJSON); |
5297 | 0 | } |
5298 | | |
5299 | | void |
5300 | | WebGPUBlendStateDescriptor::TraceDictionary(JSTracer* trc) |
5301 | 0 | { |
5302 | 0 | } |
5303 | | |
5304 | | WebGPUBlendStateDescriptor& |
5305 | | WebGPUBlendStateDescriptor::operator=(const WebGPUBlendStateDescriptor& aOther) |
5306 | 0 | { |
5307 | 0 | DictionaryBase::operator=(aOther); |
5308 | 0 | mAlpha = aOther.mAlpha; |
5309 | 0 | mBlendEnabled.Reset(); |
5310 | 0 | if (aOther.mBlendEnabled.WasPassed()) { |
5311 | 0 | mBlendEnabled.Construct(aOther.mBlendEnabled.Value()); |
5312 | 0 | } |
5313 | 0 | mColor = aOther.mColor; |
5314 | 0 | mWriteMask.Reset(); |
5315 | 0 | if (aOther.mWriteMask.WasPassed()) { |
5316 | 0 | mWriteMask.Construct(aOther.mWriteMask.Value()); |
5317 | 0 | } |
5318 | 0 | return *this; |
5319 | 0 | } |
5320 | | |
5321 | | namespace binding_detail { |
5322 | | } // namespace binding_detail |
5323 | | |
5324 | | |
5325 | | |
5326 | | WebGPUDepthStencilStateDescriptor::WebGPUDepthStencilStateDescriptor() |
5327 | | : mBack(FastDictionaryInitializer()), |
5328 | | mFront(FastDictionaryInitializer()) |
5329 | 0 | { |
5330 | 0 | // Safe to pass a null context if we pass a null value |
5331 | 0 | Init(nullptr, JS::NullHandleValue); |
5332 | 0 | } |
5333 | | |
5334 | | |
5335 | | |
5336 | | bool |
5337 | | WebGPUDepthStencilStateDescriptor::InitIds(JSContext* cx, WebGPUDepthStencilStateDescriptorAtoms* atomsCache) |
5338 | 0 | { |
5339 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
5340 | 0 |
|
5341 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
5342 | 0 | // uninitialized. |
5343 | 0 | if (!atomsCache->stencilWriteMask_id.init(cx, "stencilWriteMask") || |
5344 | 0 | !atomsCache->stencilReadMask_id.init(cx, "stencilReadMask") || |
5345 | 0 | !atomsCache->front_id.init(cx, "front") || |
5346 | 0 | !atomsCache->depthWriteEnabled_id.init(cx, "depthWriteEnabled") || |
5347 | 0 | !atomsCache->depthCompare_id.init(cx, "depthCompare") || |
5348 | 0 | !atomsCache->back_id.init(cx, "back")) { |
5349 | 0 | return false; |
5350 | 0 | } |
5351 | 0 | return true; |
5352 | 0 | } |
5353 | | |
5354 | | bool |
5355 | | WebGPUDepthStencilStateDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
5356 | 0 | { |
5357 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
5358 | 0 | // Since in that case we will not have to do any property gets |
5359 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
5360 | 0 | // checkers by static analysis tools |
5361 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
5362 | 0 | WebGPUDepthStencilStateDescriptorAtoms* atomsCache = nullptr; |
5363 | 0 | if (cx) { |
5364 | 0 | atomsCache = GetAtomCache<WebGPUDepthStencilStateDescriptorAtoms>(cx); |
5365 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
5366 | 0 | return false; |
5367 | 0 | } |
5368 | 0 | } |
5369 | 0 | |
5370 | 0 | if (!IsConvertibleToDictionary(val)) { |
5371 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
5372 | 0 | } |
5373 | 0 | |
5374 | 0 | bool isNull = val.isNullOrUndefined(); |
5375 | 0 | // We only need these if !isNull, in which case we have |cx|. |
5376 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
5377 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
5378 | 0 | if (!isNull) { |
5379 | 0 | MOZ_ASSERT(cx); |
5380 | 0 | object.emplace(cx, &val.toObject()); |
5381 | 0 | temp.emplace(cx); |
5382 | 0 | } |
5383 | 0 | if (!isNull) { |
5384 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->back_id, temp.ptr())) { |
5385 | 0 | return false; |
5386 | 0 | } |
5387 | 0 | } |
5388 | 0 | if (!mBack.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue, "'back' member of WebGPUDepthStencilStateDescriptor", passedToJSImpl)) { |
5389 | 0 | return false; |
5390 | 0 | } |
5391 | 0 | mIsAnyMemberPresent = true; |
5392 | 0 |
|
5393 | 0 | if (!isNull) { |
5394 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->depthCompare_id, temp.ptr())) { |
5395 | 0 | return false; |
5396 | 0 | } |
5397 | 0 | } |
5398 | 0 | if (!isNull && !temp->isUndefined()) { |
5399 | 0 | mDepthCompare.Construct(); |
5400 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mDepthCompare.Value()))) { |
5401 | 0 | return false; |
5402 | 0 | } |
5403 | 0 | mIsAnyMemberPresent = true; |
5404 | 0 | } |
5405 | 0 |
|
5406 | 0 | if (!isNull) { |
5407 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->depthWriteEnabled_id, temp.ptr())) { |
5408 | 0 | return false; |
5409 | 0 | } |
5410 | 0 | } |
5411 | 0 | if (!isNull && !temp->isUndefined()) { |
5412 | 0 | mDepthWriteEnabled.Construct(); |
5413 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &(mDepthWriteEnabled.Value()))) { |
5414 | 0 | return false; |
5415 | 0 | } |
5416 | 0 | mIsAnyMemberPresent = true; |
5417 | 0 | } |
5418 | 0 |
|
5419 | 0 | if (!isNull) { |
5420 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->front_id, temp.ptr())) { |
5421 | 0 | return false; |
5422 | 0 | } |
5423 | 0 | } |
5424 | 0 | if (!mFront.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue, "'front' member of WebGPUDepthStencilStateDescriptor", passedToJSImpl)) { |
5425 | 0 | return false; |
5426 | 0 | } |
5427 | 0 | mIsAnyMemberPresent = true; |
5428 | 0 |
|
5429 | 0 | if (!isNull) { |
5430 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->stencilReadMask_id, temp.ptr())) { |
5431 | 0 | return false; |
5432 | 0 | } |
5433 | 0 | } |
5434 | 0 | if (!isNull && !temp->isUndefined()) { |
5435 | 0 | mStencilReadMask.Construct(); |
5436 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mStencilReadMask.Value()))) { |
5437 | 0 | return false; |
5438 | 0 | } |
5439 | 0 | mIsAnyMemberPresent = true; |
5440 | 0 | } |
5441 | 0 |
|
5442 | 0 | if (!isNull) { |
5443 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->stencilWriteMask_id, temp.ptr())) { |
5444 | 0 | return false; |
5445 | 0 | } |
5446 | 0 | } |
5447 | 0 | if (!isNull && !temp->isUndefined()) { |
5448 | 0 | mStencilWriteMask.Construct(); |
5449 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mStencilWriteMask.Value()))) { |
5450 | 0 | return false; |
5451 | 0 | } |
5452 | 0 | mIsAnyMemberPresent = true; |
5453 | 0 | } |
5454 | 0 | return true; |
5455 | 0 | } |
5456 | | |
5457 | | bool |
5458 | | WebGPUDepthStencilStateDescriptor::Init(const nsAString& aJSON) |
5459 | 0 | { |
5460 | 0 | AutoJSAPI jsapi; |
5461 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
5462 | 0 | if (!cleanGlobal) { |
5463 | 0 | return false; |
5464 | 0 | } |
5465 | 0 | if (!jsapi.Init(cleanGlobal)) { |
5466 | 0 | return false; |
5467 | 0 | } |
5468 | 0 | JSContext* cx = jsapi.cx(); |
5469 | 0 | JS::Rooted<JS::Value> json(cx); |
5470 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
5471 | 0 | NS_ENSURE_TRUE(ok, false); |
5472 | 0 | return Init(cx, json); |
5473 | 0 | } |
5474 | | |
5475 | | bool |
5476 | | WebGPUDepthStencilStateDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
5477 | 0 | { |
5478 | 0 | WebGPUDepthStencilStateDescriptorAtoms* atomsCache = GetAtomCache<WebGPUDepthStencilStateDescriptorAtoms>(cx); |
5479 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
5480 | 0 | return false; |
5481 | 0 | } |
5482 | 0 | |
5483 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
5484 | 0 | if (!obj) { |
5485 | 0 | return false; |
5486 | 0 | } |
5487 | 0 | rval.set(JS::ObjectValue(*obj)); |
5488 | 0 |
|
5489 | 0 | do { |
5490 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
5491 | 0 | JS::Rooted<JS::Value> temp(cx); |
5492 | 0 | WebGPUStencilStateFaceDescriptor const & currentValue = mBack; |
5493 | 0 | if (!currentValue.ToObjectInternal(cx, &temp)) { |
5494 | 0 | return false; |
5495 | 0 | } |
5496 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->back_id, temp, JSPROP_ENUMERATE)) { |
5497 | 0 | return false; |
5498 | 0 | } |
5499 | 0 | break; |
5500 | 0 | } while(false); |
5501 | 0 |
|
5502 | 0 | if (mDepthCompare.WasPassed()) { |
5503 | 0 | do { |
5504 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
5505 | 0 | JS::Rooted<JS::Value> temp(cx); |
5506 | 0 | uint32_t const & currentValue = mDepthCompare.InternalValue(); |
5507 | 0 | temp.setNumber(currentValue); |
5508 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->depthCompare_id, temp, JSPROP_ENUMERATE)) { |
5509 | 0 | return false; |
5510 | 0 | } |
5511 | 0 | break; |
5512 | 0 | } while(false); |
5513 | 0 | } |
5514 | 0 |
|
5515 | 0 | if (mDepthWriteEnabled.WasPassed()) { |
5516 | 0 | do { |
5517 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
5518 | 0 | JS::Rooted<JS::Value> temp(cx); |
5519 | 0 | bool const & currentValue = mDepthWriteEnabled.InternalValue(); |
5520 | 0 | temp.setBoolean(currentValue); |
5521 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->depthWriteEnabled_id, temp, JSPROP_ENUMERATE)) { |
5522 | 0 | return false; |
5523 | 0 | } |
5524 | 0 | break; |
5525 | 0 | } while(false); |
5526 | 0 | } |
5527 | 0 |
|
5528 | 0 | do { |
5529 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
5530 | 0 | JS::Rooted<JS::Value> temp(cx); |
5531 | 0 | WebGPUStencilStateFaceDescriptor const & currentValue = mFront; |
5532 | 0 | if (!currentValue.ToObjectInternal(cx, &temp)) { |
5533 | 0 | return false; |
5534 | 0 | } |
5535 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->front_id, temp, JSPROP_ENUMERATE)) { |
5536 | 0 | return false; |
5537 | 0 | } |
5538 | 0 | break; |
5539 | 0 | } while(false); |
5540 | 0 |
|
5541 | 0 | if (mStencilReadMask.WasPassed()) { |
5542 | 0 | do { |
5543 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
5544 | 0 | JS::Rooted<JS::Value> temp(cx); |
5545 | 0 | uint32_t const & currentValue = mStencilReadMask.InternalValue(); |
5546 | 0 | temp.setNumber(currentValue); |
5547 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->stencilReadMask_id, temp, JSPROP_ENUMERATE)) { |
5548 | 0 | return false; |
5549 | 0 | } |
5550 | 0 | break; |
5551 | 0 | } while(false); |
5552 | 0 | } |
5553 | 0 |
|
5554 | 0 | if (mStencilWriteMask.WasPassed()) { |
5555 | 0 | do { |
5556 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
5557 | 0 | JS::Rooted<JS::Value> temp(cx); |
5558 | 0 | uint32_t const & currentValue = mStencilWriteMask.InternalValue(); |
5559 | 0 | temp.setNumber(currentValue); |
5560 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->stencilWriteMask_id, temp, JSPROP_ENUMERATE)) { |
5561 | 0 | return false; |
5562 | 0 | } |
5563 | 0 | break; |
5564 | 0 | } while(false); |
5565 | 0 | } |
5566 | 0 |
|
5567 | 0 | return true; |
5568 | 0 | } |
5569 | | |
5570 | | bool |
5571 | | WebGPUDepthStencilStateDescriptor::ToJSON(nsAString& aJSON) const |
5572 | 0 | { |
5573 | 0 | AutoJSAPI jsapi; |
5574 | 0 | jsapi.Init(); |
5575 | 0 | JSContext *cx = jsapi.cx(); |
5576 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
5577 | 0 | // because we'll only be creating objects, in ways that have no |
5578 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
5579 | 0 | // which likewise guarantees no side-effects for the sorts of |
5580 | 0 | // things we will pass it. |
5581 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
5582 | 0 | JS::Rooted<JS::Value> val(cx); |
5583 | 0 | if (!ToObjectInternal(cx, &val)) { |
5584 | 0 | return false; |
5585 | 0 | } |
5586 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
5587 | 0 | return StringifyToJSON(cx, obj, aJSON); |
5588 | 0 | } |
5589 | | |
5590 | | void |
5591 | | WebGPUDepthStencilStateDescriptor::TraceDictionary(JSTracer* trc) |
5592 | 0 | { |
5593 | 0 | } |
5594 | | |
5595 | | WebGPUDepthStencilStateDescriptor& |
5596 | | WebGPUDepthStencilStateDescriptor::operator=(const WebGPUDepthStencilStateDescriptor& aOther) |
5597 | 0 | { |
5598 | 0 | DictionaryBase::operator=(aOther); |
5599 | 0 | mBack = aOther.mBack; |
5600 | 0 | mDepthCompare.Reset(); |
5601 | 0 | if (aOther.mDepthCompare.WasPassed()) { |
5602 | 0 | mDepthCompare.Construct(aOther.mDepthCompare.Value()); |
5603 | 0 | } |
5604 | 0 | mDepthWriteEnabled.Reset(); |
5605 | 0 | if (aOther.mDepthWriteEnabled.WasPassed()) { |
5606 | 0 | mDepthWriteEnabled.Construct(aOther.mDepthWriteEnabled.Value()); |
5607 | 0 | } |
5608 | 0 | mFront = aOther.mFront; |
5609 | 0 | mStencilReadMask.Reset(); |
5610 | 0 | if (aOther.mStencilReadMask.WasPassed()) { |
5611 | 0 | mStencilReadMask.Construct(aOther.mStencilReadMask.Value()); |
5612 | 0 | } |
5613 | 0 | mStencilWriteMask.Reset(); |
5614 | 0 | if (aOther.mStencilWriteMask.WasPassed()) { |
5615 | 0 | mStencilWriteMask.Construct(aOther.mStencilWriteMask.Value()); |
5616 | 0 | } |
5617 | 0 | return *this; |
5618 | 0 | } |
5619 | | |
5620 | | namespace binding_detail { |
5621 | | } // namespace binding_detail |
5622 | | |
5623 | | |
5624 | | |
5625 | | WebGPUDeviceDescriptor::WebGPUDeviceDescriptor() |
5626 | | : mExtensions(FastDictionaryInitializer()) |
5627 | 0 | { |
5628 | 0 | // Safe to pass a null context if we pass a null value |
5629 | 0 | Init(nullptr, JS::NullHandleValue); |
5630 | 0 | } |
5631 | | |
5632 | | |
5633 | | |
5634 | | bool |
5635 | | WebGPUDeviceDescriptor::InitIds(JSContext* cx, WebGPUDeviceDescriptorAtoms* atomsCache) |
5636 | 0 | { |
5637 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
5638 | 0 |
|
5639 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
5640 | 0 | // uninitialized. |
5641 | 0 | if (!atomsCache->extensions_id.init(cx, "extensions")) { |
5642 | 0 | return false; |
5643 | 0 | } |
5644 | 0 | return true; |
5645 | 0 | } |
5646 | | |
5647 | | bool |
5648 | | WebGPUDeviceDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
5649 | 0 | { |
5650 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
5651 | 0 | // Since in that case we will not have to do any property gets |
5652 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
5653 | 0 | // checkers by static analysis tools |
5654 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
5655 | 0 | WebGPUDeviceDescriptorAtoms* atomsCache = nullptr; |
5656 | 0 | if (cx) { |
5657 | 0 | atomsCache = GetAtomCache<WebGPUDeviceDescriptorAtoms>(cx); |
5658 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
5659 | 0 | return false; |
5660 | 0 | } |
5661 | 0 | } |
5662 | 0 | |
5663 | 0 | if (!IsConvertibleToDictionary(val)) { |
5664 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
5665 | 0 | } |
5666 | 0 | |
5667 | 0 | bool isNull = val.isNullOrUndefined(); |
5668 | 0 | // We only need these if !isNull, in which case we have |cx|. |
5669 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
5670 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
5671 | 0 | if (!isNull) { |
5672 | 0 | MOZ_ASSERT(cx); |
5673 | 0 | object.emplace(cx, &val.toObject()); |
5674 | 0 | temp.emplace(cx); |
5675 | 0 | } |
5676 | 0 | if (!isNull) { |
5677 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->extensions_id, temp.ptr())) { |
5678 | 0 | return false; |
5679 | 0 | } |
5680 | 0 | } |
5681 | 0 | if (!mExtensions.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue, "'extensions' member of WebGPUDeviceDescriptor", passedToJSImpl)) { |
5682 | 0 | return false; |
5683 | 0 | } |
5684 | 0 | mIsAnyMemberPresent = true; |
5685 | 0 | return true; |
5686 | 0 | } |
5687 | | |
5688 | | bool |
5689 | | WebGPUDeviceDescriptor::Init(const nsAString& aJSON) |
5690 | 0 | { |
5691 | 0 | AutoJSAPI jsapi; |
5692 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
5693 | 0 | if (!cleanGlobal) { |
5694 | 0 | return false; |
5695 | 0 | } |
5696 | 0 | if (!jsapi.Init(cleanGlobal)) { |
5697 | 0 | return false; |
5698 | 0 | } |
5699 | 0 | JSContext* cx = jsapi.cx(); |
5700 | 0 | JS::Rooted<JS::Value> json(cx); |
5701 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
5702 | 0 | NS_ENSURE_TRUE(ok, false); |
5703 | 0 | return Init(cx, json); |
5704 | 0 | } |
5705 | | |
5706 | | bool |
5707 | | WebGPUDeviceDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
5708 | 0 | { |
5709 | 0 | WebGPUDeviceDescriptorAtoms* atomsCache = GetAtomCache<WebGPUDeviceDescriptorAtoms>(cx); |
5710 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
5711 | 0 | return false; |
5712 | 0 | } |
5713 | 0 | |
5714 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
5715 | 0 | if (!obj) { |
5716 | 0 | return false; |
5717 | 0 | } |
5718 | 0 | rval.set(JS::ObjectValue(*obj)); |
5719 | 0 |
|
5720 | 0 | do { |
5721 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
5722 | 0 | JS::Rooted<JS::Value> temp(cx); |
5723 | 0 | WebGPUExtensions const & currentValue = mExtensions; |
5724 | 0 | if (!currentValue.ToObjectInternal(cx, &temp)) { |
5725 | 0 | return false; |
5726 | 0 | } |
5727 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->extensions_id, temp, JSPROP_ENUMERATE)) { |
5728 | 0 | return false; |
5729 | 0 | } |
5730 | 0 | break; |
5731 | 0 | } while(false); |
5732 | 0 |
|
5733 | 0 | return true; |
5734 | 0 | } |
5735 | | |
5736 | | bool |
5737 | | WebGPUDeviceDescriptor::ToJSON(nsAString& aJSON) const |
5738 | 0 | { |
5739 | 0 | AutoJSAPI jsapi; |
5740 | 0 | jsapi.Init(); |
5741 | 0 | JSContext *cx = jsapi.cx(); |
5742 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
5743 | 0 | // because we'll only be creating objects, in ways that have no |
5744 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
5745 | 0 | // which likewise guarantees no side-effects for the sorts of |
5746 | 0 | // things we will pass it. |
5747 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
5748 | 0 | JS::Rooted<JS::Value> val(cx); |
5749 | 0 | if (!ToObjectInternal(cx, &val)) { |
5750 | 0 | return false; |
5751 | 0 | } |
5752 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
5753 | 0 | return StringifyToJSON(cx, obj, aJSON); |
5754 | 0 | } |
5755 | | |
5756 | | void |
5757 | | WebGPUDeviceDescriptor::TraceDictionary(JSTracer* trc) |
5758 | 0 | { |
5759 | 0 | } |
5760 | | |
5761 | | WebGPUDeviceDescriptor& |
5762 | | WebGPUDeviceDescriptor::operator=(const WebGPUDeviceDescriptor& aOther) |
5763 | 0 | { |
5764 | 0 | DictionaryBase::operator=(aOther); |
5765 | 0 | mExtensions = aOther.mExtensions; |
5766 | 0 | return *this; |
5767 | 0 | } |
5768 | | |
5769 | | namespace binding_detail { |
5770 | | } // namespace binding_detail |
5771 | | |
5772 | | |
5773 | | |
5774 | | WebGPUInputStateDescriptor::WebGPUInputStateDescriptor() |
5775 | 0 | { |
5776 | 0 | // Safe to pass a null context if we pass a null value |
5777 | 0 | Init(nullptr, JS::NullHandleValue); |
5778 | 0 | } |
5779 | | |
5780 | | |
5781 | | |
5782 | | bool |
5783 | | WebGPUInputStateDescriptor::InitIds(JSContext* cx, WebGPUInputStateDescriptorAtoms* atomsCache) |
5784 | 0 | { |
5785 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
5786 | 0 |
|
5787 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
5788 | 0 | // uninitialized. |
5789 | 0 | if (!atomsCache->inputs_id.init(cx, "inputs") || |
5790 | 0 | !atomsCache->indexFormat_id.init(cx, "indexFormat") || |
5791 | 0 | !atomsCache->attributes_id.init(cx, "attributes")) { |
5792 | 0 | return false; |
5793 | 0 | } |
5794 | 0 | return true; |
5795 | 0 | } |
5796 | | |
5797 | | bool |
5798 | | WebGPUInputStateDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
5799 | 0 | { |
5800 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
5801 | 0 | // Since in that case we will not have to do any property gets |
5802 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
5803 | 0 | // checkers by static analysis tools |
5804 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
5805 | 0 | WebGPUInputStateDescriptorAtoms* atomsCache = nullptr; |
5806 | 0 | if (cx) { |
5807 | 0 | atomsCache = GetAtomCache<WebGPUInputStateDescriptorAtoms>(cx); |
5808 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
5809 | 0 | return false; |
5810 | 0 | } |
5811 | 0 | } |
5812 | 0 | |
5813 | 0 | if (!IsConvertibleToDictionary(val)) { |
5814 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
5815 | 0 | } |
5816 | 0 | |
5817 | 0 | bool isNull = val.isNullOrUndefined(); |
5818 | 0 | // We only need these if !isNull, in which case we have |cx|. |
5819 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
5820 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
5821 | 0 | if (!isNull) { |
5822 | 0 | MOZ_ASSERT(cx); |
5823 | 0 | object.emplace(cx, &val.toObject()); |
5824 | 0 | temp.emplace(cx); |
5825 | 0 | } |
5826 | 0 | if (!isNull) { |
5827 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->attributes_id, temp.ptr())) { |
5828 | 0 | return false; |
5829 | 0 | } |
5830 | 0 | } |
5831 | 0 | if (!isNull && !temp->isUndefined()) { |
5832 | 0 | mAttributes.Construct(); |
5833 | 0 | if (temp.ref().isObject()) { |
5834 | 0 | JS::ForOfIterator iter(cx); |
5835 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
5836 | 0 | return false; |
5837 | 0 | } |
5838 | 0 | if (!iter.valueIsIterable()) { |
5839 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'attributes' member of WebGPUInputStateDescriptor"); |
5840 | 0 | return false; |
5841 | 0 | } |
5842 | 0 | Sequence<WebGPUVertexAttributeDescriptor> &arr = (mAttributes.Value()); |
5843 | 0 | JS::Rooted<JS::Value> temp(cx); |
5844 | 0 | while (true) { |
5845 | 0 | bool done; |
5846 | 0 | if (!iter.next(&temp, &done)) { |
5847 | 0 | return false; |
5848 | 0 | } |
5849 | 0 | if (done) { |
5850 | 0 | break; |
5851 | 0 | } |
5852 | 0 | WebGPUVertexAttributeDescriptor* slotPtr = arr.AppendElement(mozilla::fallible); |
5853 | 0 | if (!slotPtr) { |
5854 | 0 | JS_ReportOutOfMemory(cx); |
5855 | 0 | return false; |
5856 | 0 | } |
5857 | 0 | WebGPUVertexAttributeDescriptor& slot = *slotPtr; |
5858 | 0 | if (!slot.Init(cx, temp, "Element of 'attributes' member of WebGPUInputStateDescriptor", passedToJSImpl)) { |
5859 | 0 | return false; |
5860 | 0 | } |
5861 | 0 | } |
5862 | 0 | } else { |
5863 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'attributes' member of WebGPUInputStateDescriptor"); |
5864 | 0 | return false; |
5865 | 0 | } |
5866 | 0 | mIsAnyMemberPresent = true; |
5867 | 0 | } |
5868 | 0 |
|
5869 | 0 | if (!isNull) { |
5870 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->indexFormat_id, temp.ptr())) { |
5871 | 0 | return false; |
5872 | 0 | } |
5873 | 0 | } |
5874 | 0 | if (!isNull && !temp->isUndefined()) { |
5875 | 0 | mIndexFormat.Construct(); |
5876 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mIndexFormat.Value()))) { |
5877 | 0 | return false; |
5878 | 0 | } |
5879 | 0 | mIsAnyMemberPresent = true; |
5880 | 0 | } |
5881 | 0 |
|
5882 | 0 | if (!isNull) { |
5883 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->inputs_id, temp.ptr())) { |
5884 | 0 | return false; |
5885 | 0 | } |
5886 | 0 | } |
5887 | 0 | if (!isNull && !temp->isUndefined()) { |
5888 | 0 | mInputs.Construct(); |
5889 | 0 | if (temp.ref().isObject()) { |
5890 | 0 | JS::ForOfIterator iter(cx); |
5891 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
5892 | 0 | return false; |
5893 | 0 | } |
5894 | 0 | if (!iter.valueIsIterable()) { |
5895 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'inputs' member of WebGPUInputStateDescriptor"); |
5896 | 0 | return false; |
5897 | 0 | } |
5898 | 0 | Sequence<WebGPUVertexInputDescriptor> &arr = (mInputs.Value()); |
5899 | 0 | JS::Rooted<JS::Value> temp(cx); |
5900 | 0 | while (true) { |
5901 | 0 | bool done; |
5902 | 0 | if (!iter.next(&temp, &done)) { |
5903 | 0 | return false; |
5904 | 0 | } |
5905 | 0 | if (done) { |
5906 | 0 | break; |
5907 | 0 | } |
5908 | 0 | WebGPUVertexInputDescriptor* slotPtr = arr.AppendElement(mozilla::fallible); |
5909 | 0 | if (!slotPtr) { |
5910 | 0 | JS_ReportOutOfMemory(cx); |
5911 | 0 | return false; |
5912 | 0 | } |
5913 | 0 | WebGPUVertexInputDescriptor& slot = *slotPtr; |
5914 | 0 | if (!slot.Init(cx, temp, "Element of 'inputs' member of WebGPUInputStateDescriptor", passedToJSImpl)) { |
5915 | 0 | return false; |
5916 | 0 | } |
5917 | 0 | } |
5918 | 0 | } else { |
5919 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'inputs' member of WebGPUInputStateDescriptor"); |
5920 | 0 | return false; |
5921 | 0 | } |
5922 | 0 | mIsAnyMemberPresent = true; |
5923 | 0 | } |
5924 | 0 | return true; |
5925 | 0 | } |
5926 | | |
5927 | | bool |
5928 | | WebGPUInputStateDescriptor::Init(const nsAString& aJSON) |
5929 | 0 | { |
5930 | 0 | AutoJSAPI jsapi; |
5931 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
5932 | 0 | if (!cleanGlobal) { |
5933 | 0 | return false; |
5934 | 0 | } |
5935 | 0 | if (!jsapi.Init(cleanGlobal)) { |
5936 | 0 | return false; |
5937 | 0 | } |
5938 | 0 | JSContext* cx = jsapi.cx(); |
5939 | 0 | JS::Rooted<JS::Value> json(cx); |
5940 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
5941 | 0 | NS_ENSURE_TRUE(ok, false); |
5942 | 0 | return Init(cx, json); |
5943 | 0 | } |
5944 | | |
5945 | | bool |
5946 | | WebGPUInputStateDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
5947 | 0 | { |
5948 | 0 | WebGPUInputStateDescriptorAtoms* atomsCache = GetAtomCache<WebGPUInputStateDescriptorAtoms>(cx); |
5949 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
5950 | 0 | return false; |
5951 | 0 | } |
5952 | 0 | |
5953 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
5954 | 0 | if (!obj) { |
5955 | 0 | return false; |
5956 | 0 | } |
5957 | 0 | rval.set(JS::ObjectValue(*obj)); |
5958 | 0 |
|
5959 | 0 | if (mAttributes.WasPassed()) { |
5960 | 0 | do { |
5961 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
5962 | 0 | JS::Rooted<JS::Value> temp(cx); |
5963 | 0 | Sequence<WebGPUVertexAttributeDescriptor> const & currentValue = mAttributes.InternalValue(); |
5964 | 0 |
|
5965 | 0 | uint32_t length = currentValue.Length(); |
5966 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
5967 | 0 | if (!returnArray) { |
5968 | 0 | return false; |
5969 | 0 | } |
5970 | 0 | // Scope for 'tmp' |
5971 | 0 | { |
5972 | 0 | JS::Rooted<JS::Value> tmp(cx); |
5973 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
5974 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
5975 | 0 | // are different ways to succeed at wrapping the object. |
5976 | 0 | do { |
5977 | 0 | if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) { |
5978 | 0 | return false; |
5979 | 0 | } |
5980 | 0 | break; |
5981 | 0 | } while (false); |
5982 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
5983 | 0 | JSPROP_ENUMERATE)) { |
5984 | 0 | return false; |
5985 | 0 | } |
5986 | 0 | } |
5987 | 0 | } |
5988 | 0 | temp.setObject(*returnArray); |
5989 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->attributes_id, temp, JSPROP_ENUMERATE)) { |
5990 | 0 | return false; |
5991 | 0 | } |
5992 | 0 | break; |
5993 | 0 | } while(false); |
5994 | 0 | } |
5995 | 0 |
|
5996 | 0 | if (mIndexFormat.WasPassed()) { |
5997 | 0 | do { |
5998 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
5999 | 0 | JS::Rooted<JS::Value> temp(cx); |
6000 | 0 | uint32_t const & currentValue = mIndexFormat.InternalValue(); |
6001 | 0 | temp.setNumber(currentValue); |
6002 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->indexFormat_id, temp, JSPROP_ENUMERATE)) { |
6003 | 0 | return false; |
6004 | 0 | } |
6005 | 0 | break; |
6006 | 0 | } while(false); |
6007 | 0 | } |
6008 | 0 |
|
6009 | 0 | if (mInputs.WasPassed()) { |
6010 | 0 | do { |
6011 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
6012 | 0 | JS::Rooted<JS::Value> temp(cx); |
6013 | 0 | Sequence<WebGPUVertexInputDescriptor> const & currentValue = mInputs.InternalValue(); |
6014 | 0 |
|
6015 | 0 | uint32_t length = currentValue.Length(); |
6016 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
6017 | 0 | if (!returnArray) { |
6018 | 0 | return false; |
6019 | 0 | } |
6020 | 0 | // Scope for 'tmp' |
6021 | 0 | { |
6022 | 0 | JS::Rooted<JS::Value> tmp(cx); |
6023 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
6024 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
6025 | 0 | // are different ways to succeed at wrapping the object. |
6026 | 0 | do { |
6027 | 0 | if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) { |
6028 | 0 | return false; |
6029 | 0 | } |
6030 | 0 | break; |
6031 | 0 | } while (false); |
6032 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
6033 | 0 | JSPROP_ENUMERATE)) { |
6034 | 0 | return false; |
6035 | 0 | } |
6036 | 0 | } |
6037 | 0 | } |
6038 | 0 | temp.setObject(*returnArray); |
6039 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->inputs_id, temp, JSPROP_ENUMERATE)) { |
6040 | 0 | return false; |
6041 | 0 | } |
6042 | 0 | break; |
6043 | 0 | } while(false); |
6044 | 0 | } |
6045 | 0 |
|
6046 | 0 | return true; |
6047 | 0 | } |
6048 | | |
6049 | | bool |
6050 | | WebGPUInputStateDescriptor::ToJSON(nsAString& aJSON) const |
6051 | 0 | { |
6052 | 0 | AutoJSAPI jsapi; |
6053 | 0 | jsapi.Init(); |
6054 | 0 | JSContext *cx = jsapi.cx(); |
6055 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
6056 | 0 | // because we'll only be creating objects, in ways that have no |
6057 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
6058 | 0 | // which likewise guarantees no side-effects for the sorts of |
6059 | 0 | // things we will pass it. |
6060 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
6061 | 0 | JS::Rooted<JS::Value> val(cx); |
6062 | 0 | if (!ToObjectInternal(cx, &val)) { |
6063 | 0 | return false; |
6064 | 0 | } |
6065 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
6066 | 0 | return StringifyToJSON(cx, obj, aJSON); |
6067 | 0 | } |
6068 | | |
6069 | | void |
6070 | | WebGPUInputStateDescriptor::TraceDictionary(JSTracer* trc) |
6071 | 0 | { |
6072 | 0 | } |
6073 | | |
6074 | | WebGPUInputStateDescriptor& |
6075 | | WebGPUInputStateDescriptor::operator=(const WebGPUInputStateDescriptor& aOther) |
6076 | 0 | { |
6077 | 0 | DictionaryBase::operator=(aOther); |
6078 | 0 | mAttributes.Reset(); |
6079 | 0 | if (aOther.mAttributes.WasPassed()) { |
6080 | 0 | mAttributes.Construct(aOther.mAttributes.Value()); |
6081 | 0 | } |
6082 | 0 | mIndexFormat.Reset(); |
6083 | 0 | if (aOther.mIndexFormat.WasPassed()) { |
6084 | 0 | mIndexFormat.Construct(aOther.mIndexFormat.Value()); |
6085 | 0 | } |
6086 | 0 | mInputs.Reset(); |
6087 | 0 | if (aOther.mInputs.WasPassed()) { |
6088 | 0 | mInputs.Construct(aOther.mInputs.Value()); |
6089 | 0 | } |
6090 | 0 | return *this; |
6091 | 0 | } |
6092 | | |
6093 | | namespace binding_detail { |
6094 | | } // namespace binding_detail |
6095 | | |
6096 | | |
6097 | | |
6098 | | WebGPUPipelineDescriptorBase::WebGPUPipelineDescriptorBase() |
6099 | 0 | { |
6100 | 0 | // Safe to pass a null context if we pass a null value |
6101 | 0 | Init(nullptr, JS::NullHandleValue); |
6102 | 0 | } |
6103 | | |
6104 | | |
6105 | | |
6106 | | bool |
6107 | | WebGPUPipelineDescriptorBase::InitIds(JSContext* cx, WebGPUPipelineDescriptorBaseAtoms* atomsCache) |
6108 | 0 | { |
6109 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
6110 | 0 |
|
6111 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
6112 | 0 | // uninitialized. |
6113 | 0 | if (!atomsCache->stages_id.init(cx, "stages") || |
6114 | 0 | !atomsCache->layout_id.init(cx, "layout")) { |
6115 | 0 | return false; |
6116 | 0 | } |
6117 | 0 | return true; |
6118 | 0 | } |
6119 | | |
6120 | | bool |
6121 | | WebGPUPipelineDescriptorBase::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
6122 | 0 | { |
6123 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
6124 | 0 | // Since in that case we will not have to do any property gets |
6125 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
6126 | 0 | // checkers by static analysis tools |
6127 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
6128 | 0 | WebGPUPipelineDescriptorBaseAtoms* atomsCache = nullptr; |
6129 | 0 | if (cx) { |
6130 | 0 | atomsCache = GetAtomCache<WebGPUPipelineDescriptorBaseAtoms>(cx); |
6131 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
6132 | 0 | return false; |
6133 | 0 | } |
6134 | 0 | } |
6135 | 0 | |
6136 | 0 | if (!IsConvertibleToDictionary(val)) { |
6137 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
6138 | 0 | } |
6139 | 0 | |
6140 | 0 | bool isNull = val.isNullOrUndefined(); |
6141 | 0 | // We only need these if !isNull, in which case we have |cx|. |
6142 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
6143 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
6144 | 0 | if (!isNull) { |
6145 | 0 | MOZ_ASSERT(cx); |
6146 | 0 | object.emplace(cx, &val.toObject()); |
6147 | 0 | temp.emplace(cx); |
6148 | 0 | } |
6149 | 0 | if (!isNull) { |
6150 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->layout_id, temp.ptr())) { |
6151 | 0 | return false; |
6152 | 0 | } |
6153 | 0 | } |
6154 | 0 | if (!isNull && !temp->isUndefined()) { |
6155 | 0 | if (temp.ref().isObject()) { |
6156 | 0 | static_assert(IsRefcounted<mozilla::webgpu::PipelineLayout>::value, "We can only store refcounted classes.");{ |
6157 | 0 | nsresult rv = UnwrapObject<prototypes::id::WebGPUPipelineLayout, mozilla::webgpu::PipelineLayout>(temp.ptr(), mLayout); |
6158 | 0 | if (NS_FAILED(rv)) { |
6159 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'layout' member of WebGPUPipelineDescriptorBase", "WebGPUPipelineLayout"); |
6160 | 0 | return false; |
6161 | 0 | } |
6162 | 0 | } |
6163 | 0 | } else { |
6164 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'layout' member of WebGPUPipelineDescriptorBase"); |
6165 | 0 | return false; |
6166 | 0 | } |
6167 | 0 | mIsAnyMemberPresent = true; |
6168 | 0 | } else if (cx) { |
6169 | 0 | // Don't error out if we have no cx. In that |
6170 | 0 | // situation the caller is default-constructing us and we'll |
6171 | 0 | // just assume they know what they're doing. |
6172 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
6173 | 0 | "'layout' member of WebGPUPipelineDescriptorBase"); |
6174 | 0 | } |
6175 | 0 | |
6176 | 0 | if (!isNull) { |
6177 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->stages_id, temp.ptr())) { |
6178 | 0 | return false; |
6179 | 0 | } |
6180 | 0 | } |
6181 | 0 | if (!isNull && !temp->isUndefined()) { |
6182 | 0 | mStages.Construct(); |
6183 | 0 | if (temp.ref().isObject()) { |
6184 | 0 | JS::ForOfIterator iter(cx); |
6185 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
6186 | 0 | return false; |
6187 | 0 | } |
6188 | 0 | if (!iter.valueIsIterable()) { |
6189 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'stages' member of WebGPUPipelineDescriptorBase"); |
6190 | 0 | return false; |
6191 | 0 | } |
6192 | 0 | Sequence<WebGPUPipelineStageDescriptor> &arr = (mStages.Value()); |
6193 | 0 | JS::Rooted<JS::Value> temp(cx); |
6194 | 0 | while (true) { |
6195 | 0 | bool done; |
6196 | 0 | if (!iter.next(&temp, &done)) { |
6197 | 0 | return false; |
6198 | 0 | } |
6199 | 0 | if (done) { |
6200 | 0 | break; |
6201 | 0 | } |
6202 | 0 | WebGPUPipelineStageDescriptor* slotPtr = arr.AppendElement(mozilla::fallible); |
6203 | 0 | if (!slotPtr) { |
6204 | 0 | JS_ReportOutOfMemory(cx); |
6205 | 0 | return false; |
6206 | 0 | } |
6207 | 0 | WebGPUPipelineStageDescriptor& slot = *slotPtr; |
6208 | 0 | if (!slot.Init(cx, temp, "Element of 'stages' member of WebGPUPipelineDescriptorBase", passedToJSImpl)) { |
6209 | 0 | return false; |
6210 | 0 | } |
6211 | 0 | } |
6212 | 0 | } else { |
6213 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'stages' member of WebGPUPipelineDescriptorBase"); |
6214 | 0 | return false; |
6215 | 0 | } |
6216 | 0 | mIsAnyMemberPresent = true; |
6217 | 0 | } |
6218 | 0 | return true; |
6219 | 0 | } |
6220 | | |
6221 | | bool |
6222 | | WebGPUPipelineDescriptorBase::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
6223 | 0 | { |
6224 | 0 | WebGPUPipelineDescriptorBaseAtoms* atomsCache = GetAtomCache<WebGPUPipelineDescriptorBaseAtoms>(cx); |
6225 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
6226 | 0 | return false; |
6227 | 0 | } |
6228 | 0 | |
6229 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
6230 | 0 | if (!obj) { |
6231 | 0 | return false; |
6232 | 0 | } |
6233 | 0 | rval.set(JS::ObjectValue(*obj)); |
6234 | 0 |
|
6235 | 0 | do { |
6236 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
6237 | 0 | JS::Rooted<JS::Value> temp(cx); |
6238 | 0 | OwningNonNull<mozilla::webgpu::PipelineLayout> const & currentValue = mLayout; |
6239 | 0 | if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) { |
6240 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
6241 | 0 | return false; |
6242 | 0 | } |
6243 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->layout_id, temp, JSPROP_ENUMERATE)) { |
6244 | 0 | return false; |
6245 | 0 | } |
6246 | 0 | break; |
6247 | 0 | } while(false); |
6248 | 0 |
|
6249 | 0 | if (mStages.WasPassed()) { |
6250 | 0 | do { |
6251 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
6252 | 0 | JS::Rooted<JS::Value> temp(cx); |
6253 | 0 | Sequence<WebGPUPipelineStageDescriptor> const & currentValue = mStages.InternalValue(); |
6254 | 0 |
|
6255 | 0 | uint32_t length = currentValue.Length(); |
6256 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
6257 | 0 | if (!returnArray) { |
6258 | 0 | return false; |
6259 | 0 | } |
6260 | 0 | // Scope for 'tmp' |
6261 | 0 | { |
6262 | 0 | JS::Rooted<JS::Value> tmp(cx); |
6263 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
6264 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
6265 | 0 | // are different ways to succeed at wrapping the object. |
6266 | 0 | do { |
6267 | 0 | if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) { |
6268 | 0 | return false; |
6269 | 0 | } |
6270 | 0 | break; |
6271 | 0 | } while (false); |
6272 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
6273 | 0 | JSPROP_ENUMERATE)) { |
6274 | 0 | return false; |
6275 | 0 | } |
6276 | 0 | } |
6277 | 0 | } |
6278 | 0 | temp.setObject(*returnArray); |
6279 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->stages_id, temp, JSPROP_ENUMERATE)) { |
6280 | 0 | return false; |
6281 | 0 | } |
6282 | 0 | break; |
6283 | 0 | } while(false); |
6284 | 0 | } |
6285 | 0 |
|
6286 | 0 | return true; |
6287 | 0 | } |
6288 | | |
6289 | | void |
6290 | | WebGPUPipelineDescriptorBase::TraceDictionary(JSTracer* trc) |
6291 | 0 | { |
6292 | 0 | } |
6293 | | |
6294 | | |
6295 | | |
6296 | | WebGPUPipelineDescriptorBase& |
6297 | | WebGPUPipelineDescriptorBase::operator=(const WebGPUPipelineDescriptorBase& aOther) |
6298 | 0 | { |
6299 | 0 | DictionaryBase::operator=(aOther); |
6300 | 0 | mLayout = aOther.mLayout; |
6301 | 0 | mStages.Reset(); |
6302 | 0 | if (aOther.mStages.WasPassed()) { |
6303 | 0 | mStages.Construct(aOther.mStages.Value()); |
6304 | 0 | } |
6305 | 0 | return *this; |
6306 | 0 | } |
6307 | | |
6308 | | namespace binding_detail { |
6309 | | } // namespace binding_detail |
6310 | | |
6311 | | |
6312 | | |
6313 | | WebGPURenderPassDescriptor::WebGPURenderPassDescriptor() |
6314 | | : mDepthStencilAttachment(FastDictionaryInitializer()) |
6315 | 0 | { |
6316 | 0 | // Safe to pass a null context if we pass a null value |
6317 | 0 | Init(nullptr, JS::NullHandleValue); |
6318 | 0 | } |
6319 | | |
6320 | | |
6321 | | |
6322 | | bool |
6323 | | WebGPURenderPassDescriptor::InitIds(JSContext* cx, WebGPURenderPassDescriptorAtoms* atomsCache) |
6324 | 0 | { |
6325 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
6326 | 0 |
|
6327 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
6328 | 0 | // uninitialized. |
6329 | 0 | if (!atomsCache->depthStencilAttachment_id.init(cx, "depthStencilAttachment") || |
6330 | 0 | !atomsCache->colorAttachments_id.init(cx, "colorAttachments")) { |
6331 | 0 | return false; |
6332 | 0 | } |
6333 | 0 | return true; |
6334 | 0 | } |
6335 | | |
6336 | | bool |
6337 | | WebGPURenderPassDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
6338 | 0 | { |
6339 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
6340 | 0 | // Since in that case we will not have to do any property gets |
6341 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
6342 | 0 | // checkers by static analysis tools |
6343 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
6344 | 0 | WebGPURenderPassDescriptorAtoms* atomsCache = nullptr; |
6345 | 0 | if (cx) { |
6346 | 0 | atomsCache = GetAtomCache<WebGPURenderPassDescriptorAtoms>(cx); |
6347 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
6348 | 0 | return false; |
6349 | 0 | } |
6350 | 0 | } |
6351 | 0 | |
6352 | 0 | if (!IsConvertibleToDictionary(val)) { |
6353 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
6354 | 0 | } |
6355 | 0 | |
6356 | 0 | bool isNull = val.isNullOrUndefined(); |
6357 | 0 | // We only need these if !isNull, in which case we have |cx|. |
6358 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
6359 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
6360 | 0 | if (!isNull) { |
6361 | 0 | MOZ_ASSERT(cx); |
6362 | 0 | object.emplace(cx, &val.toObject()); |
6363 | 0 | temp.emplace(cx); |
6364 | 0 | } |
6365 | 0 | if (!isNull) { |
6366 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->colorAttachments_id, temp.ptr())) { |
6367 | 0 | return false; |
6368 | 0 | } |
6369 | 0 | } |
6370 | 0 | if (!isNull && !temp->isUndefined()) { |
6371 | 0 | mColorAttachments.Construct(); |
6372 | 0 | if (temp.ref().isObject()) { |
6373 | 0 | JS::ForOfIterator iter(cx); |
6374 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
6375 | 0 | return false; |
6376 | 0 | } |
6377 | 0 | if (!iter.valueIsIterable()) { |
6378 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'colorAttachments' member of WebGPURenderPassDescriptor"); |
6379 | 0 | return false; |
6380 | 0 | } |
6381 | 0 | Sequence<WebGPURenderPassAttachmentDescriptor> &arr = (mColorAttachments.Value()); |
6382 | 0 | JS::Rooted<JS::Value> temp(cx); |
6383 | 0 | while (true) { |
6384 | 0 | bool done; |
6385 | 0 | if (!iter.next(&temp, &done)) { |
6386 | 0 | return false; |
6387 | 0 | } |
6388 | 0 | if (done) { |
6389 | 0 | break; |
6390 | 0 | } |
6391 | 0 | WebGPURenderPassAttachmentDescriptor* slotPtr = arr.AppendElement(mozilla::fallible); |
6392 | 0 | if (!slotPtr) { |
6393 | 0 | JS_ReportOutOfMemory(cx); |
6394 | 0 | return false; |
6395 | 0 | } |
6396 | 0 | WebGPURenderPassAttachmentDescriptor& slot = *slotPtr; |
6397 | 0 | if (!slot.Init(cx, temp, "Element of 'colorAttachments' member of WebGPURenderPassDescriptor", passedToJSImpl)) { |
6398 | 0 | return false; |
6399 | 0 | } |
6400 | 0 | } |
6401 | 0 | } else { |
6402 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'colorAttachments' member of WebGPURenderPassDescriptor"); |
6403 | 0 | return false; |
6404 | 0 | } |
6405 | 0 | mIsAnyMemberPresent = true; |
6406 | 0 | } |
6407 | 0 |
|
6408 | 0 | if (!isNull) { |
6409 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->depthStencilAttachment_id, temp.ptr())) { |
6410 | 0 | return false; |
6411 | 0 | } |
6412 | 0 | } |
6413 | 0 | if (!mDepthStencilAttachment.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue, "'depthStencilAttachment' member of WebGPURenderPassDescriptor", passedToJSImpl)) { |
6414 | 0 | return false; |
6415 | 0 | } |
6416 | 0 | mIsAnyMemberPresent = true; |
6417 | 0 | return true; |
6418 | 0 | } |
6419 | | |
6420 | | bool |
6421 | | WebGPURenderPassDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
6422 | 0 | { |
6423 | 0 | WebGPURenderPassDescriptorAtoms* atomsCache = GetAtomCache<WebGPURenderPassDescriptorAtoms>(cx); |
6424 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
6425 | 0 | return false; |
6426 | 0 | } |
6427 | 0 | |
6428 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
6429 | 0 | if (!obj) { |
6430 | 0 | return false; |
6431 | 0 | } |
6432 | 0 | rval.set(JS::ObjectValue(*obj)); |
6433 | 0 |
|
6434 | 0 | if (mColorAttachments.WasPassed()) { |
6435 | 0 | do { |
6436 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
6437 | 0 | JS::Rooted<JS::Value> temp(cx); |
6438 | 0 | Sequence<WebGPURenderPassAttachmentDescriptor> const & currentValue = mColorAttachments.InternalValue(); |
6439 | 0 |
|
6440 | 0 | uint32_t length = currentValue.Length(); |
6441 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
6442 | 0 | if (!returnArray) { |
6443 | 0 | return false; |
6444 | 0 | } |
6445 | 0 | // Scope for 'tmp' |
6446 | 0 | { |
6447 | 0 | JS::Rooted<JS::Value> tmp(cx); |
6448 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
6449 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
6450 | 0 | // are different ways to succeed at wrapping the object. |
6451 | 0 | do { |
6452 | 0 | if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) { |
6453 | 0 | return false; |
6454 | 0 | } |
6455 | 0 | break; |
6456 | 0 | } while (false); |
6457 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
6458 | 0 | JSPROP_ENUMERATE)) { |
6459 | 0 | return false; |
6460 | 0 | } |
6461 | 0 | } |
6462 | 0 | } |
6463 | 0 | temp.setObject(*returnArray); |
6464 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->colorAttachments_id, temp, JSPROP_ENUMERATE)) { |
6465 | 0 | return false; |
6466 | 0 | } |
6467 | 0 | break; |
6468 | 0 | } while(false); |
6469 | 0 | } |
6470 | 0 |
|
6471 | 0 | do { |
6472 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
6473 | 0 | JS::Rooted<JS::Value> temp(cx); |
6474 | 0 | WebGPURenderPassAttachmentDescriptor const & currentValue = mDepthStencilAttachment; |
6475 | 0 | if (!currentValue.ToObjectInternal(cx, &temp)) { |
6476 | 0 | return false; |
6477 | 0 | } |
6478 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->depthStencilAttachment_id, temp, JSPROP_ENUMERATE)) { |
6479 | 0 | return false; |
6480 | 0 | } |
6481 | 0 | break; |
6482 | 0 | } while(false); |
6483 | 0 |
|
6484 | 0 | return true; |
6485 | 0 | } |
6486 | | |
6487 | | void |
6488 | | WebGPURenderPassDescriptor::TraceDictionary(JSTracer* trc) |
6489 | 0 | { |
6490 | 0 | } |
6491 | | |
6492 | | |
6493 | | |
6494 | | WebGPURenderPassDescriptor& |
6495 | | WebGPURenderPassDescriptor::operator=(const WebGPURenderPassDescriptor& aOther) |
6496 | 0 | { |
6497 | 0 | DictionaryBase::operator=(aOther); |
6498 | 0 | mColorAttachments.Reset(); |
6499 | 0 | if (aOther.mColorAttachments.WasPassed()) { |
6500 | 0 | mColorAttachments.Construct(aOther.mColorAttachments.Value()); |
6501 | 0 | } |
6502 | 0 | mDepthStencilAttachment = aOther.mDepthStencilAttachment; |
6503 | 0 | return *this; |
6504 | 0 | } |
6505 | | |
6506 | | namespace binding_detail { |
6507 | | } // namespace binding_detail |
6508 | | |
6509 | | |
6510 | | |
6511 | | WebGPUBindGroupDescriptor::WebGPUBindGroupDescriptor() |
6512 | 0 | { |
6513 | 0 | // Safe to pass a null context if we pass a null value |
6514 | 0 | Init(nullptr, JS::NullHandleValue); |
6515 | 0 | } |
6516 | | |
6517 | | |
6518 | | |
6519 | | bool |
6520 | | WebGPUBindGroupDescriptor::InitIds(JSContext* cx, WebGPUBindGroupDescriptorAtoms* atomsCache) |
6521 | 0 | { |
6522 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
6523 | 0 |
|
6524 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
6525 | 0 | // uninitialized. |
6526 | 0 | if (!atomsCache->layout_id.init(cx, "layout") || |
6527 | 0 | !atomsCache->bindings_id.init(cx, "bindings")) { |
6528 | 0 | return false; |
6529 | 0 | } |
6530 | 0 | return true; |
6531 | 0 | } |
6532 | | |
6533 | | bool |
6534 | | WebGPUBindGroupDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
6535 | 0 | { |
6536 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
6537 | 0 | // Since in that case we will not have to do any property gets |
6538 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
6539 | 0 | // checkers by static analysis tools |
6540 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
6541 | 0 | WebGPUBindGroupDescriptorAtoms* atomsCache = nullptr; |
6542 | 0 | if (cx) { |
6543 | 0 | atomsCache = GetAtomCache<WebGPUBindGroupDescriptorAtoms>(cx); |
6544 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
6545 | 0 | return false; |
6546 | 0 | } |
6547 | 0 | } |
6548 | 0 | |
6549 | 0 | if (!IsConvertibleToDictionary(val)) { |
6550 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
6551 | 0 | } |
6552 | 0 | |
6553 | 0 | bool isNull = val.isNullOrUndefined(); |
6554 | 0 | // We only need these if !isNull, in which case we have |cx|. |
6555 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
6556 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
6557 | 0 | if (!isNull) { |
6558 | 0 | MOZ_ASSERT(cx); |
6559 | 0 | object.emplace(cx, &val.toObject()); |
6560 | 0 | temp.emplace(cx); |
6561 | 0 | } |
6562 | 0 | if (!isNull) { |
6563 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->bindings_id, temp.ptr())) { |
6564 | 0 | return false; |
6565 | 0 | } |
6566 | 0 | } |
6567 | 0 | if (!isNull && !temp->isUndefined()) { |
6568 | 0 | mBindings.Construct(); |
6569 | 0 | if (temp.ref().isObject()) { |
6570 | 0 | JS::ForOfIterator iter(cx); |
6571 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
6572 | 0 | return false; |
6573 | 0 | } |
6574 | 0 | if (!iter.valueIsIterable()) { |
6575 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'bindings' member of WebGPUBindGroupDescriptor"); |
6576 | 0 | return false; |
6577 | 0 | } |
6578 | 0 | Sequence<WebGPUBinding> &arr = (mBindings.Value()); |
6579 | 0 | JS::Rooted<JS::Value> temp(cx); |
6580 | 0 | while (true) { |
6581 | 0 | bool done; |
6582 | 0 | if (!iter.next(&temp, &done)) { |
6583 | 0 | return false; |
6584 | 0 | } |
6585 | 0 | if (done) { |
6586 | 0 | break; |
6587 | 0 | } |
6588 | 0 | WebGPUBinding* slotPtr = arr.AppendElement(mozilla::fallible); |
6589 | 0 | if (!slotPtr) { |
6590 | 0 | JS_ReportOutOfMemory(cx); |
6591 | 0 | return false; |
6592 | 0 | } |
6593 | 0 | WebGPUBinding& slot = *slotPtr; |
6594 | 0 | if (!slot.Init(cx, temp, "Element of 'bindings' member of WebGPUBindGroupDescriptor", passedToJSImpl)) { |
6595 | 0 | return false; |
6596 | 0 | } |
6597 | 0 | } |
6598 | 0 | } else { |
6599 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'bindings' member of WebGPUBindGroupDescriptor"); |
6600 | 0 | return false; |
6601 | 0 | } |
6602 | 0 | mIsAnyMemberPresent = true; |
6603 | 0 | } |
6604 | 0 |
|
6605 | 0 | if (!isNull) { |
6606 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->layout_id, temp.ptr())) { |
6607 | 0 | return false; |
6608 | 0 | } |
6609 | 0 | } |
6610 | 0 | if (!isNull && !temp->isUndefined()) { |
6611 | 0 | mLayout.Construct(); |
6612 | 0 | if (temp.ref().isObject()) { |
6613 | 0 | static_assert(IsRefcounted<mozilla::webgpu::BindGroupLayout>::value, "We can only store refcounted classes.");{ |
6614 | 0 | nsresult rv = UnwrapObject<prototypes::id::WebGPUBindGroupLayout, mozilla::webgpu::BindGroupLayout>(temp.ptr(), (mLayout.Value())); |
6615 | 0 | if (NS_FAILED(rv)) { |
6616 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'layout' member of WebGPUBindGroupDescriptor", "WebGPUBindGroupLayout"); |
6617 | 0 | return false; |
6618 | 0 | } |
6619 | 0 | } |
6620 | 0 | } else { |
6621 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'layout' member of WebGPUBindGroupDescriptor"); |
6622 | 0 | return false; |
6623 | 0 | } |
6624 | 0 | mIsAnyMemberPresent = true; |
6625 | 0 | } |
6626 | 0 | return true; |
6627 | 0 | } |
6628 | | |
6629 | | bool |
6630 | | WebGPUBindGroupDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
6631 | 0 | { |
6632 | 0 | WebGPUBindGroupDescriptorAtoms* atomsCache = GetAtomCache<WebGPUBindGroupDescriptorAtoms>(cx); |
6633 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
6634 | 0 | return false; |
6635 | 0 | } |
6636 | 0 | |
6637 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
6638 | 0 | if (!obj) { |
6639 | 0 | return false; |
6640 | 0 | } |
6641 | 0 | rval.set(JS::ObjectValue(*obj)); |
6642 | 0 |
|
6643 | 0 | if (mBindings.WasPassed()) { |
6644 | 0 | do { |
6645 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
6646 | 0 | JS::Rooted<JS::Value> temp(cx); |
6647 | 0 | Sequence<WebGPUBinding> const & currentValue = mBindings.InternalValue(); |
6648 | 0 |
|
6649 | 0 | uint32_t length = currentValue.Length(); |
6650 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
6651 | 0 | if (!returnArray) { |
6652 | 0 | return false; |
6653 | 0 | } |
6654 | 0 | // Scope for 'tmp' |
6655 | 0 | { |
6656 | 0 | JS::Rooted<JS::Value> tmp(cx); |
6657 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
6658 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
6659 | 0 | // are different ways to succeed at wrapping the object. |
6660 | 0 | do { |
6661 | 0 | if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) { |
6662 | 0 | return false; |
6663 | 0 | } |
6664 | 0 | break; |
6665 | 0 | } while (false); |
6666 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
6667 | 0 | JSPROP_ENUMERATE)) { |
6668 | 0 | return false; |
6669 | 0 | } |
6670 | 0 | } |
6671 | 0 | } |
6672 | 0 | temp.setObject(*returnArray); |
6673 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->bindings_id, temp, JSPROP_ENUMERATE)) { |
6674 | 0 | return false; |
6675 | 0 | } |
6676 | 0 | break; |
6677 | 0 | } while(false); |
6678 | 0 | } |
6679 | 0 |
|
6680 | 0 | if (mLayout.WasPassed()) { |
6681 | 0 | do { |
6682 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
6683 | 0 | JS::Rooted<JS::Value> temp(cx); |
6684 | 0 | OwningNonNull<mozilla::webgpu::BindGroupLayout> const & currentValue = mLayout.InternalValue(); |
6685 | 0 | if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) { |
6686 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
6687 | 0 | return false; |
6688 | 0 | } |
6689 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->layout_id, temp, JSPROP_ENUMERATE)) { |
6690 | 0 | return false; |
6691 | 0 | } |
6692 | 0 | break; |
6693 | 0 | } while(false); |
6694 | 0 | } |
6695 | 0 |
|
6696 | 0 | return true; |
6697 | 0 | } |
6698 | | |
6699 | | void |
6700 | | WebGPUBindGroupDescriptor::TraceDictionary(JSTracer* trc) |
6701 | 0 | { |
6702 | 0 | } |
6703 | | |
6704 | | |
6705 | | |
6706 | | WebGPUBindGroupDescriptor& |
6707 | | WebGPUBindGroupDescriptor::operator=(const WebGPUBindGroupDescriptor& aOther) |
6708 | 0 | { |
6709 | 0 | DictionaryBase::operator=(aOther); |
6710 | 0 | mBindings.Reset(); |
6711 | 0 | if (aOther.mBindings.WasPassed()) { |
6712 | 0 | mBindings.Construct(aOther.mBindings.Value()); |
6713 | 0 | } |
6714 | 0 | mLayout.Reset(); |
6715 | 0 | if (aOther.mLayout.WasPassed()) { |
6716 | 0 | mLayout.Construct(aOther.mLayout.Value()); |
6717 | 0 | } |
6718 | 0 | return *this; |
6719 | 0 | } |
6720 | | |
6721 | | namespace binding_detail { |
6722 | | } // namespace binding_detail |
6723 | | |
6724 | | |
6725 | | |
6726 | | WebGPUComputePipelineDescriptor::WebGPUComputePipelineDescriptor() |
6727 | | : WebGPUPipelineDescriptorBase(FastDictionaryInitializer()) |
6728 | 0 | { |
6729 | 0 | // Safe to pass a null context if we pass a null value |
6730 | 0 | Init(nullptr, JS::NullHandleValue); |
6731 | 0 | } |
6732 | | |
6733 | | |
6734 | | |
6735 | | bool |
6736 | | WebGPUComputePipelineDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
6737 | 0 | { |
6738 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
6739 | 0 | // Since in that case we will not have to do any property gets |
6740 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
6741 | 0 | // checkers by static analysis tools |
6742 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
6743 | 0 | // Per spec, we init the parent's members first |
6744 | 0 | if (!WebGPUPipelineDescriptorBase::Init(cx, val)) { |
6745 | 0 | return false; |
6746 | 0 | } |
6747 | 0 | |
6748 | 0 | return true; |
6749 | 0 | } |
6750 | | |
6751 | | bool |
6752 | | WebGPUComputePipelineDescriptor::Init(const nsAString& aJSON) |
6753 | 0 | { |
6754 | 0 | AutoJSAPI jsapi; |
6755 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
6756 | 0 | if (!cleanGlobal) { |
6757 | 0 | return false; |
6758 | 0 | } |
6759 | 0 | if (!jsapi.Init(cleanGlobal)) { |
6760 | 0 | return false; |
6761 | 0 | } |
6762 | 0 | JSContext* cx = jsapi.cx(); |
6763 | 0 | JS::Rooted<JS::Value> json(cx); |
6764 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
6765 | 0 | NS_ENSURE_TRUE(ok, false); |
6766 | 0 | return Init(cx, json); |
6767 | 0 | } |
6768 | | |
6769 | | bool |
6770 | | WebGPUComputePipelineDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
6771 | 0 | { |
6772 | 0 | // Per spec, we define the parent's members first |
6773 | 0 | if (!WebGPUPipelineDescriptorBase::ToObjectInternal(cx, rval)) { |
6774 | 0 | return false; |
6775 | 0 | } |
6776 | 0 | JS::Rooted<JSObject*> obj(cx, &rval.toObject()); |
6777 | 0 |
|
6778 | 0 |
|
6779 | 0 | return true; |
6780 | 0 | } |
6781 | | |
6782 | | bool |
6783 | | WebGPUComputePipelineDescriptor::ToJSON(nsAString& aJSON) const |
6784 | 0 | { |
6785 | 0 | AutoJSAPI jsapi; |
6786 | 0 | jsapi.Init(); |
6787 | 0 | JSContext *cx = jsapi.cx(); |
6788 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
6789 | 0 | // because we'll only be creating objects, in ways that have no |
6790 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
6791 | 0 | // which likewise guarantees no side-effects for the sorts of |
6792 | 0 | // things we will pass it. |
6793 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
6794 | 0 | JS::Rooted<JS::Value> val(cx); |
6795 | 0 | if (!ToObjectInternal(cx, &val)) { |
6796 | 0 | return false; |
6797 | 0 | } |
6798 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
6799 | 0 | return StringifyToJSON(cx, obj, aJSON); |
6800 | 0 | } |
6801 | | |
6802 | | void |
6803 | | WebGPUComputePipelineDescriptor::TraceDictionary(JSTracer* trc) |
6804 | 0 | { |
6805 | 0 | WebGPUPipelineDescriptorBase::TraceDictionary(trc); |
6806 | 0 | } |
6807 | | |
6808 | | |
6809 | | |
6810 | | WebGPUComputePipelineDescriptor& |
6811 | | WebGPUComputePipelineDescriptor::operator=(const WebGPUComputePipelineDescriptor& aOther) |
6812 | 0 | { |
6813 | 0 | WebGPUPipelineDescriptorBase::operator=(aOther); |
6814 | 0 | return *this; |
6815 | 0 | } |
6816 | | |
6817 | | namespace binding_detail { |
6818 | | } // namespace binding_detail |
6819 | | |
6820 | | |
6821 | | |
6822 | | WebGPURenderPipelineDescriptor::WebGPURenderPipelineDescriptor() |
6823 | | : WebGPUPipelineDescriptorBase(FastDictionaryInitializer()) |
6824 | 0 | { |
6825 | 0 | // Safe to pass a null context if we pass a null value |
6826 | 0 | Init(nullptr, JS::NullHandleValue); |
6827 | 0 | } |
6828 | | |
6829 | | |
6830 | | |
6831 | | bool |
6832 | | WebGPURenderPipelineDescriptor::InitIds(JSContext* cx, WebGPURenderPipelineDescriptorAtoms* atomsCache) |
6833 | 0 | { |
6834 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
6835 | 0 |
|
6836 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
6837 | 0 | // uninitialized. |
6838 | 0 | if (!atomsCache->primitiveTopology_id.init(cx, "primitiveTopology") || |
6839 | 0 | !atomsCache->inputState_id.init(cx, "inputState") || |
6840 | 0 | !atomsCache->depthStencilState_id.init(cx, "depthStencilState") || |
6841 | 0 | !atomsCache->blendState_id.init(cx, "blendState") || |
6842 | 0 | !atomsCache->attachmentState_id.init(cx, "attachmentState")) { |
6843 | 0 | return false; |
6844 | 0 | } |
6845 | 0 | return true; |
6846 | 0 | } |
6847 | | |
6848 | | bool |
6849 | | WebGPURenderPipelineDescriptor::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
6850 | 0 | { |
6851 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
6852 | 0 | // Since in that case we will not have to do any property gets |
6853 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
6854 | 0 | // checkers by static analysis tools |
6855 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
6856 | 0 | WebGPURenderPipelineDescriptorAtoms* atomsCache = nullptr; |
6857 | 0 | if (cx) { |
6858 | 0 | atomsCache = GetAtomCache<WebGPURenderPipelineDescriptorAtoms>(cx); |
6859 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
6860 | 0 | return false; |
6861 | 0 | } |
6862 | 0 | } |
6863 | 0 | |
6864 | 0 | // Per spec, we init the parent's members first |
6865 | 0 | if (!WebGPUPipelineDescriptorBase::Init(cx, val)) { |
6866 | 0 | return false; |
6867 | 0 | } |
6868 | 0 | |
6869 | 0 | bool isNull = val.isNullOrUndefined(); |
6870 | 0 | // We only need these if !isNull, in which case we have |cx|. |
6871 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
6872 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
6873 | 0 | if (!isNull) { |
6874 | 0 | MOZ_ASSERT(cx); |
6875 | 0 | object.emplace(cx, &val.toObject()); |
6876 | 0 | temp.emplace(cx); |
6877 | 0 | } |
6878 | 0 | if (!isNull) { |
6879 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->attachmentState_id, temp.ptr())) { |
6880 | 0 | return false; |
6881 | 0 | } |
6882 | 0 | } |
6883 | 0 | if (!isNull && !temp->isUndefined()) { |
6884 | 0 | mAttachmentState.Construct(); |
6885 | 0 | if (temp.ref().isObject()) { |
6886 | 0 | static_assert(IsRefcounted<mozilla::webgpu::AttachmentState>::value, "We can only store refcounted classes.");{ |
6887 | 0 | nsresult rv = UnwrapObject<prototypes::id::WebGPUAttachmentState, mozilla::webgpu::AttachmentState>(temp.ptr(), (mAttachmentState.Value())); |
6888 | 0 | if (NS_FAILED(rv)) { |
6889 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'attachmentState' member of WebGPURenderPipelineDescriptor", "WebGPUAttachmentState"); |
6890 | 0 | return false; |
6891 | 0 | } |
6892 | 0 | } |
6893 | 0 | } else { |
6894 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'attachmentState' member of WebGPURenderPipelineDescriptor"); |
6895 | 0 | return false; |
6896 | 0 | } |
6897 | 0 | mIsAnyMemberPresent = true; |
6898 | 0 | } |
6899 | 0 |
|
6900 | 0 | if (!isNull) { |
6901 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->blendState_id, temp.ptr())) { |
6902 | 0 | return false; |
6903 | 0 | } |
6904 | 0 | } |
6905 | 0 | if (!isNull && !temp->isUndefined()) { |
6906 | 0 | mBlendState.Construct(); |
6907 | 0 | if (temp.ref().isObject()) { |
6908 | 0 | JS::ForOfIterator iter(cx); |
6909 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
6910 | 0 | return false; |
6911 | 0 | } |
6912 | 0 | if (!iter.valueIsIterable()) { |
6913 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'blendState' member of WebGPURenderPipelineDescriptor"); |
6914 | 0 | return false; |
6915 | 0 | } |
6916 | 0 | Sequence<OwningNonNull<mozilla::webgpu::BlendState>> &arr = (mBlendState.Value()); |
6917 | 0 | JS::Rooted<JS::Value> temp(cx); |
6918 | 0 | while (true) { |
6919 | 0 | bool done; |
6920 | 0 | if (!iter.next(&temp, &done)) { |
6921 | 0 | return false; |
6922 | 0 | } |
6923 | 0 | if (done) { |
6924 | 0 | break; |
6925 | 0 | } |
6926 | 0 | OwningNonNull<mozilla::webgpu::BlendState>* slotPtr = arr.AppendElement(mozilla::fallible); |
6927 | 0 | if (!slotPtr) { |
6928 | 0 | JS_ReportOutOfMemory(cx); |
6929 | 0 | return false; |
6930 | 0 | } |
6931 | 0 | OwningNonNull<mozilla::webgpu::BlendState>& slot = *slotPtr; |
6932 | 0 | if (temp.isObject()) { |
6933 | 0 | static_assert(IsRefcounted<mozilla::webgpu::BlendState>::value, "We can only store refcounted classes.");{ |
6934 | 0 | nsresult rv = UnwrapObject<prototypes::id::WebGPUBlendState, mozilla::webgpu::BlendState>(&temp, slot); |
6935 | 0 | if (NS_FAILED(rv)) { |
6936 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of 'blendState' member of WebGPURenderPipelineDescriptor", "WebGPUBlendState"); |
6937 | 0 | return false; |
6938 | 0 | } |
6939 | 0 | } |
6940 | 0 | } else { |
6941 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of 'blendState' member of WebGPURenderPipelineDescriptor"); |
6942 | 0 | return false; |
6943 | 0 | } |
6944 | 0 | } |
6945 | 0 | } else { |
6946 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'blendState' member of WebGPURenderPipelineDescriptor"); |
6947 | 0 | return false; |
6948 | 0 | } |
6949 | 0 | mIsAnyMemberPresent = true; |
6950 | 0 | } |
6951 | 0 |
|
6952 | 0 | if (!isNull) { |
6953 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->depthStencilState_id, temp.ptr())) { |
6954 | 0 | return false; |
6955 | 0 | } |
6956 | 0 | } |
6957 | 0 | if (!isNull && !temp->isUndefined()) { |
6958 | 0 | mDepthStencilState.Construct(); |
6959 | 0 | if (temp.ref().isObject()) { |
6960 | 0 | static_assert(IsRefcounted<mozilla::webgpu::DepthStencilState>::value, "We can only store refcounted classes.");{ |
6961 | 0 | nsresult rv = UnwrapObject<prototypes::id::WebGPUDepthStencilState, mozilla::webgpu::DepthStencilState>(temp.ptr(), (mDepthStencilState.Value())); |
6962 | 0 | if (NS_FAILED(rv)) { |
6963 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'depthStencilState' member of WebGPURenderPipelineDescriptor", "WebGPUDepthStencilState"); |
6964 | 0 | return false; |
6965 | 0 | } |
6966 | 0 | } |
6967 | 0 | } else { |
6968 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'depthStencilState' member of WebGPURenderPipelineDescriptor"); |
6969 | 0 | return false; |
6970 | 0 | } |
6971 | 0 | mIsAnyMemberPresent = true; |
6972 | 0 | } |
6973 | 0 |
|
6974 | 0 | if (!isNull) { |
6975 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->inputState_id, temp.ptr())) { |
6976 | 0 | return false; |
6977 | 0 | } |
6978 | 0 | } |
6979 | 0 | if (!isNull && !temp->isUndefined()) { |
6980 | 0 | mInputState.Construct(); |
6981 | 0 | if (temp.ref().isObject()) { |
6982 | 0 | static_assert(IsRefcounted<mozilla::webgpu::InputState>::value, "We can only store refcounted classes.");{ |
6983 | 0 | nsresult rv = UnwrapObject<prototypes::id::WebGPUInputState, mozilla::webgpu::InputState>(temp.ptr(), (mInputState.Value())); |
6984 | 0 | if (NS_FAILED(rv)) { |
6985 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'inputState' member of WebGPURenderPipelineDescriptor", "WebGPUInputState"); |
6986 | 0 | return false; |
6987 | 0 | } |
6988 | 0 | } |
6989 | 0 | } else { |
6990 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'inputState' member of WebGPURenderPipelineDescriptor"); |
6991 | 0 | return false; |
6992 | 0 | } |
6993 | 0 | mIsAnyMemberPresent = true; |
6994 | 0 | } |
6995 | 0 |
|
6996 | 0 | if (!isNull) { |
6997 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->primitiveTopology_id, temp.ptr())) { |
6998 | 0 | return false; |
6999 | 0 | } |
7000 | 0 | } |
7001 | 0 | if (!isNull && !temp->isUndefined()) { |
7002 | 0 | mPrimitiveTopology.Construct(); |
7003 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mPrimitiveTopology.Value()))) { |
7004 | 0 | return false; |
7005 | 0 | } |
7006 | 0 | mIsAnyMemberPresent = true; |
7007 | 0 | } |
7008 | 0 | return true; |
7009 | 0 | } |
7010 | | |
7011 | | bool |
7012 | | WebGPURenderPipelineDescriptor::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
7013 | 0 | { |
7014 | 0 | WebGPURenderPipelineDescriptorAtoms* atomsCache = GetAtomCache<WebGPURenderPipelineDescriptorAtoms>(cx); |
7015 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
7016 | 0 | return false; |
7017 | 0 | } |
7018 | 0 | |
7019 | 0 | // Per spec, we define the parent's members first |
7020 | 0 | if (!WebGPUPipelineDescriptorBase::ToObjectInternal(cx, rval)) { |
7021 | 0 | return false; |
7022 | 0 | } |
7023 | 0 | JS::Rooted<JSObject*> obj(cx, &rval.toObject()); |
7024 | 0 |
|
7025 | 0 | if (mAttachmentState.WasPassed()) { |
7026 | 0 | do { |
7027 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
7028 | 0 | JS::Rooted<JS::Value> temp(cx); |
7029 | 0 | OwningNonNull<mozilla::webgpu::AttachmentState> const & currentValue = mAttachmentState.InternalValue(); |
7030 | 0 | if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) { |
7031 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
7032 | 0 | return false; |
7033 | 0 | } |
7034 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->attachmentState_id, temp, JSPROP_ENUMERATE)) { |
7035 | 0 | return false; |
7036 | 0 | } |
7037 | 0 | break; |
7038 | 0 | } while(false); |
7039 | 0 | } |
7040 | 0 |
|
7041 | 0 | if (mBlendState.WasPassed()) { |
7042 | 0 | do { |
7043 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
7044 | 0 | JS::Rooted<JS::Value> temp(cx); |
7045 | 0 | Sequence<OwningNonNull<mozilla::webgpu::BlendState>> const & currentValue = mBlendState.InternalValue(); |
7046 | 0 |
|
7047 | 0 | uint32_t length = currentValue.Length(); |
7048 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
7049 | 0 | if (!returnArray) { |
7050 | 0 | return false; |
7051 | 0 | } |
7052 | 0 | // Scope for 'tmp' |
7053 | 0 | { |
7054 | 0 | JS::Rooted<JS::Value> tmp(cx); |
7055 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
7056 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
7057 | 0 | // are different ways to succeed at wrapping the object. |
7058 | 0 | do { |
7059 | 0 | if (!GetOrCreateDOMReflector(cx, currentValue[sequenceIdx0], &tmp)) { |
7060 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
7061 | 0 | return false; |
7062 | 0 | } |
7063 | 0 | break; |
7064 | 0 | } while (false); |
7065 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
7066 | 0 | JSPROP_ENUMERATE)) { |
7067 | 0 | return false; |
7068 | 0 | } |
7069 | 0 | } |
7070 | 0 | } |
7071 | 0 | temp.setObject(*returnArray); |
7072 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->blendState_id, temp, JSPROP_ENUMERATE)) { |
7073 | 0 | return false; |
7074 | 0 | } |
7075 | 0 | break; |
7076 | 0 | } while(false); |
7077 | 0 | } |
7078 | 0 |
|
7079 | 0 | if (mDepthStencilState.WasPassed()) { |
7080 | 0 | do { |
7081 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
7082 | 0 | JS::Rooted<JS::Value> temp(cx); |
7083 | 0 | OwningNonNull<mozilla::webgpu::DepthStencilState> const & currentValue = mDepthStencilState.InternalValue(); |
7084 | 0 | if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) { |
7085 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
7086 | 0 | return false; |
7087 | 0 | } |
7088 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->depthStencilState_id, temp, JSPROP_ENUMERATE)) { |
7089 | 0 | return false; |
7090 | 0 | } |
7091 | 0 | break; |
7092 | 0 | } while(false); |
7093 | 0 | } |
7094 | 0 |
|
7095 | 0 | if (mInputState.WasPassed()) { |
7096 | 0 | do { |
7097 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
7098 | 0 | JS::Rooted<JS::Value> temp(cx); |
7099 | 0 | OwningNonNull<mozilla::webgpu::InputState> const & currentValue = mInputState.InternalValue(); |
7100 | 0 | if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) { |
7101 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
7102 | 0 | return false; |
7103 | 0 | } |
7104 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->inputState_id, temp, JSPROP_ENUMERATE)) { |
7105 | 0 | return false; |
7106 | 0 | } |
7107 | 0 | break; |
7108 | 0 | } while(false); |
7109 | 0 | } |
7110 | 0 |
|
7111 | 0 | if (mPrimitiveTopology.WasPassed()) { |
7112 | 0 | do { |
7113 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
7114 | 0 | JS::Rooted<JS::Value> temp(cx); |
7115 | 0 | uint32_t const & currentValue = mPrimitiveTopology.InternalValue(); |
7116 | 0 | temp.setNumber(currentValue); |
7117 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->primitiveTopology_id, temp, JSPROP_ENUMERATE)) { |
7118 | 0 | return false; |
7119 | 0 | } |
7120 | 0 | break; |
7121 | 0 | } while(false); |
7122 | 0 | } |
7123 | 0 |
|
7124 | 0 | return true; |
7125 | 0 | } |
7126 | | |
7127 | | void |
7128 | | WebGPURenderPipelineDescriptor::TraceDictionary(JSTracer* trc) |
7129 | 0 | { |
7130 | 0 | WebGPUPipelineDescriptorBase::TraceDictionary(trc); |
7131 | 0 | } |
7132 | | |
7133 | | |
7134 | | |
7135 | | WebGPURenderPipelineDescriptor& |
7136 | | WebGPURenderPipelineDescriptor::operator=(const WebGPURenderPipelineDescriptor& aOther) |
7137 | 0 | { |
7138 | 0 | WebGPUPipelineDescriptorBase::operator=(aOther); |
7139 | 0 | mAttachmentState.Reset(); |
7140 | 0 | if (aOther.mAttachmentState.WasPassed()) { |
7141 | 0 | mAttachmentState.Construct(aOther.mAttachmentState.Value()); |
7142 | 0 | } |
7143 | 0 | mBlendState.Reset(); |
7144 | 0 | if (aOther.mBlendState.WasPassed()) { |
7145 | 0 | mBlendState.Construct(aOther.mBlendState.Value()); |
7146 | 0 | } |
7147 | 0 | mDepthStencilState.Reset(); |
7148 | 0 | if (aOther.mDepthStencilState.WasPassed()) { |
7149 | 0 | mDepthStencilState.Construct(aOther.mDepthStencilState.Value()); |
7150 | 0 | } |
7151 | 0 | mInputState.Reset(); |
7152 | 0 | if (aOther.mInputState.WasPassed()) { |
7153 | 0 | mInputState.Construct(aOther.mInputState.Value()); |
7154 | 0 | } |
7155 | 0 | mPrimitiveTopology.Reset(); |
7156 | 0 | if (aOther.mPrimitiveTopology.WasPassed()) { |
7157 | 0 | mPrimitiveTopology.Construct(aOther.mPrimitiveTopology.Value()); |
7158 | 0 | } |
7159 | 0 | return *this; |
7160 | 0 | } |
7161 | | |
7162 | | namespace binding_detail { |
7163 | | } // namespace binding_detail |
7164 | | |
7165 | | |
7166 | | void |
7167 | | WebGPULogCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, webgpu::LogEntry& error, ErrorResult& aRv) |
7168 | 0 | { |
7169 | 0 | JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); |
7170 | 0 | JS::AutoValueVector argv(cx); |
7171 | 0 | if (!argv.resize(1)) { |
7172 | 0 | aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
7173 | 0 | return; |
7174 | 0 | } |
7175 | 0 | unsigned argc = 1; |
7176 | 0 |
|
7177 | 0 | do { |
7178 | 0 | if (!GetOrCreateDOMReflector(cx, error, argv[0])) { |
7179 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
7180 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
7181 | 0 | return; |
7182 | 0 | } |
7183 | 0 | break; |
7184 | 0 | } while (false); |
7185 | 0 |
|
7186 | 0 | JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback)); |
7187 | 0 | if (!JS::Call(cx, aThisVal, callable, |
7188 | 0 | JS::HandleValueArray::subarray(argv, 0, argc), &rval)) { |
7189 | 0 | aRv.NoteJSContextException(cx); |
7190 | 0 | return; |
7191 | 0 | } |
7192 | 0 | } |
7193 | | |
7194 | | |
7195 | | |
7196 | | namespace binding_detail { |
7197 | | } // namespace binding_detail |
7198 | | |
7199 | | |
7200 | | namespace WebGPU_Binding { |
7201 | | |
7202 | | MOZ_CAN_RUN_SCRIPT static bool |
7203 | | getAdapter(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Instance* self, const JSJitMethodCallArgs& args) |
7204 | 0 | { |
7205 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPU.getAdapter", DOM, cx); |
7206 | 0 |
|
7207 | 0 | binding_detail::FastWebGPUAdapterDescriptor arg0; |
7208 | 0 | if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of WebGPU.getAdapter", false)) { |
7209 | 0 | return false; |
7210 | 0 | } |
7211 | 0 | auto result(StrongOrRawPtr<mozilla::webgpu::Adapter>(self->GetAdapter(Constify(arg0)))); |
7212 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
7213 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
7214 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
7215 | 0 | return false; |
7216 | 0 | } |
7217 | 0 | return true; |
7218 | 0 | } |
7219 | | |
7220 | | static const JSJitInfo getAdapter_methodinfo = { |
7221 | | { (JSJitGetterOp)getAdapter }, |
7222 | | { prototypes::id::WebGPU }, |
7223 | | { PrototypeTraits<prototypes::id::WebGPU>::Depth }, |
7224 | | JSJitInfo::Method, |
7225 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
7226 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
7227 | | false, /* isInfallible. False in setters. */ |
7228 | | false, /* isMovable. Not relevant for setters. */ |
7229 | | false, /* isEliminatable. Not relevant for setters. */ |
7230 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
7231 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
7232 | | false, /* isTypedMethod. Only relevant for methods. */ |
7233 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
7234 | | }; |
7235 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
7236 | | static_assert(0 < 1, "There is no slot for us"); |
7237 | | |
7238 | | static bool |
7239 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
7240 | 0 | { |
7241 | 0 | mozilla::webgpu::Instance* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Instance>(obj); |
7242 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
7243 | 0 | // obviously can't preserve if we're not initialized. |
7244 | 0 | if (self && self->GetWrapperPreserveColor()) { |
7245 | 0 | PreserveWrapper(self); |
7246 | 0 | } |
7247 | 0 | return true; |
7248 | 0 | } |
7249 | | |
7250 | | static void |
7251 | | _finalize(js::FreeOp* fop, JSObject* obj) |
7252 | 0 | { |
7253 | 0 | mozilla::webgpu::Instance* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Instance>(obj); |
7254 | 0 | if (self) { |
7255 | 0 | ClearWrapper(self, self, obj); |
7256 | 0 | AddForDeferredFinalization<mozilla::webgpu::Instance>(self); |
7257 | 0 | } |
7258 | 0 | } |
7259 | | |
7260 | | static size_t |
7261 | | _objectMoved(JSObject* obj, JSObject* old) |
7262 | 0 | { |
7263 | 0 | mozilla::webgpu::Instance* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Instance>(obj); |
7264 | 0 | if (self) { |
7265 | 0 | UpdateWrapper(self, self, obj, old); |
7266 | 0 | } |
7267 | 0 |
|
7268 | 0 | return 0; |
7269 | 0 | } |
7270 | | |
7271 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
7272 | | #if defined(__clang__) |
7273 | | #pragma clang diagnostic push |
7274 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
7275 | | #endif |
7276 | | static const JSFunctionSpec sMethods_specs[] = { |
7277 | | JS_FNSPEC("getAdapter", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getAdapter_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
7278 | | JS_FS_END |
7279 | | }; |
7280 | | #if defined(__clang__) |
7281 | | #pragma clang diagnostic pop |
7282 | | #endif |
7283 | | |
7284 | | |
7285 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
7286 | | { nullptr, &sMethods_specs[0] }, |
7287 | | { nullptr, nullptr } |
7288 | | }; |
7289 | | |
7290 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
7291 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
7292 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
7293 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
7294 | | |
7295 | | |
7296 | | static uint16_t sNativeProperties_sortedPropertyIndices[1]; |
7297 | | static PropertyInfo sNativeProperties_propertyInfos[1]; |
7298 | | |
7299 | | static const NativePropertiesN<1> sNativeProperties = { |
7300 | | false, 0, |
7301 | | false, 0, |
7302 | | true, 0 /* sMethods */, |
7303 | | false, 0, |
7304 | | false, 0, |
7305 | | false, 0, |
7306 | | false, 0, |
7307 | | -1, |
7308 | | 1, |
7309 | | sNativeProperties_sortedPropertyIndices, |
7310 | | { |
7311 | | { sMethods, &sNativeProperties_propertyInfos[0] } |
7312 | | } |
7313 | | }; |
7314 | | static_assert(1 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
7315 | | "We have a property info count that is oversized"); |
7316 | | |
7317 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
7318 | | { |
7319 | | "Function", |
7320 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
7321 | | &sBoringInterfaceObjectClassClassOps, |
7322 | | JS_NULL_CLASS_SPEC, |
7323 | | JS_NULL_CLASS_EXT, |
7324 | | &sInterfaceObjectClassObjectOps |
7325 | | }, |
7326 | | eInterface, |
7327 | | true, |
7328 | | prototypes::id::WebGPU, |
7329 | | PrototypeTraits<prototypes::id::WebGPU>::Depth, |
7330 | | sNativePropertyHooks, |
7331 | | "function WebGPU() {\n [native code]\n}", |
7332 | | JS::GetRealmFunctionPrototype |
7333 | | }; |
7334 | | |
7335 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
7336 | | { |
7337 | | "WebGPUPrototype", |
7338 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
7339 | | JS_NULL_CLASS_OPS, |
7340 | | JS_NULL_CLASS_SPEC, |
7341 | | JS_NULL_CLASS_EXT, |
7342 | | JS_NULL_OBJECT_OPS |
7343 | | }, |
7344 | | eInterfacePrototype, |
7345 | | false, |
7346 | | prototypes::id::WebGPU, |
7347 | | PrototypeTraits<prototypes::id::WebGPU>::Depth, |
7348 | | sNativePropertyHooks, |
7349 | | "[object WebGPUPrototype]", |
7350 | | JS::GetRealmObjectPrototype |
7351 | | }; |
7352 | | |
7353 | | bool |
7354 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
7355 | 0 | { |
7356 | 0 | static bool sPrefValue; |
7357 | 0 | static bool sPrefCacheSetUp = false; |
7358 | 0 | if (!sPrefCacheSetUp) { |
7359 | 0 | sPrefCacheSetUp = true; |
7360 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
7361 | 0 | } |
7362 | 0 |
|
7363 | 0 | return sPrefValue; |
7364 | 0 | } |
7365 | | |
7366 | | static const js::ClassOps sClassOps = { |
7367 | | _addProperty, /* addProperty */ |
7368 | | nullptr, /* delProperty */ |
7369 | | nullptr, /* enumerate */ |
7370 | | nullptr, /* newEnumerate */ |
7371 | | nullptr, /* resolve */ |
7372 | | nullptr, /* mayResolve */ |
7373 | | _finalize, /* finalize */ |
7374 | | nullptr, /* call */ |
7375 | | nullptr, /* hasInstance */ |
7376 | | nullptr, /* construct */ |
7377 | | nullptr, /* trace */ |
7378 | | }; |
7379 | | |
7380 | | static const js::ClassExtension sClassExtension = { |
7381 | | nullptr, /* weakmapKeyDelegateOp */ |
7382 | | _objectMoved /* objectMovedOp */ |
7383 | | }; |
7384 | | |
7385 | | static const DOMJSClass sClass = { |
7386 | | { "WebGPU", |
7387 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
7388 | | &sClassOps, |
7389 | | JS_NULL_CLASS_SPEC, |
7390 | | &sClassExtension, |
7391 | | JS_NULL_OBJECT_OPS |
7392 | | }, |
7393 | | { prototypes::id::WebGPU, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
7394 | | IsBaseOf<nsISupports, mozilla::webgpu::Instance >::value, |
7395 | | sNativePropertyHooks, |
7396 | | FindAssociatedGlobalForNative<mozilla::webgpu::Instance>::Get, |
7397 | | GetProtoObjectHandle, |
7398 | | GetCCParticipant<mozilla::webgpu::Instance>::Get() |
7399 | | }; |
7400 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
7401 | | "Must have the right minimal number of reserved slots."); |
7402 | | static_assert(1 >= 1, |
7403 | | "Must have enough reserved slots."); |
7404 | | |
7405 | | const JSClass* |
7406 | | GetJSClass() |
7407 | 0 | { |
7408 | 0 | return sClass.ToJSClass(); |
7409 | 0 | } |
7410 | | |
7411 | | bool |
7412 | | Wrap(JSContext* aCx, mozilla::webgpu::Instance* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
7413 | 0 | { |
7414 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::Instance>::value, |
7415 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
7416 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::Instance*>(aObject) == |
7417 | 0 | reinterpret_cast<mozilla::webgpu::Instance*>(aObject), |
7418 | 0 | "Multiple inheritance for mozilla::webgpu::Instance is broken."); |
7419 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
7420 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
7421 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
7422 | 0 | "You should probably not be using Wrap() directly; use " |
7423 | 0 | "GetOrCreateDOMReflector instead"); |
7424 | 0 |
|
7425 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
7426 | 0 | "nsISupports must be on our primary inheritance chain"); |
7427 | 0 |
|
7428 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
7429 | 0 | if (!global) { |
7430 | 0 | return false; |
7431 | 0 | } |
7432 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
7433 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
7434 | 0 |
|
7435 | 0 | // That might have ended up wrapping us already, due to the wonders |
7436 | 0 | // of XBL. Check for that, and bail out as needed. |
7437 | 0 | aReflector.set(aCache->GetWrapper()); |
7438 | 0 | if (aReflector) { |
7439 | | #ifdef DEBUG |
7440 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
7441 | | #endif // DEBUG |
7442 | | return true; |
7443 | 0 | } |
7444 | 0 |
|
7445 | 0 | JSAutoRealm ar(aCx, global); |
7446 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
7447 | 0 | if (!canonicalProto) { |
7448 | 0 | return false; |
7449 | 0 | } |
7450 | 0 | JS::Rooted<JSObject*> proto(aCx); |
7451 | 0 | if (aGivenProto) { |
7452 | 0 | proto = aGivenProto; |
7453 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
7454 | 0 | // coming in, we changed compartments to that of "parent" so may need |
7455 | 0 | // to wrap the proto here. |
7456 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
7457 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
7458 | 0 | return false; |
7459 | 0 | } |
7460 | 0 | } |
7461 | 0 | } else { |
7462 | 0 | proto = canonicalProto; |
7463 | 0 | } |
7464 | 0 |
|
7465 | 0 | BindingJSObjectCreator<mozilla::webgpu::Instance> creator(aCx); |
7466 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
7467 | 0 | if (!aReflector) { |
7468 | 0 | return false; |
7469 | 0 | } |
7470 | 0 | |
7471 | 0 | aCache->SetWrapper(aReflector); |
7472 | 0 | creator.InitializationSucceeded(); |
7473 | 0 |
|
7474 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
7475 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
7476 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
7477 | 0 | // otherwise we won't be able to properly recreate it later, since |
7478 | 0 | // we won't know what proto to use. Note that we don't check |
7479 | 0 | // aGivenProto here, since it's entirely possible (and even |
7480 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
7481 | 0 | // same as canonicalProto. |
7482 | 0 | if (proto != canonicalProto) { |
7483 | 0 | PreserveWrapper(aObject); |
7484 | 0 | } |
7485 | 0 |
|
7486 | 0 | return true; |
7487 | 0 | } |
7488 | | |
7489 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
7490 | | nullptr, |
7491 | | nullptr, |
7492 | | nullptr, |
7493 | | { sNativeProperties.Upcast(), nullptr }, |
7494 | | prototypes::id::WebGPU, |
7495 | | constructors::id::WebGPU, |
7496 | | nullptr, |
7497 | | &DefaultXrayExpandoObjectClass |
7498 | | } }; |
7499 | | |
7500 | | void |
7501 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
7502 | 0 | { |
7503 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
7504 | 0 | if (!parentProto) { |
7505 | 0 | return; |
7506 | 0 | } |
7507 | 0 | |
7508 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
7509 | 0 | if (!constructorProto) { |
7510 | 0 | return; |
7511 | 0 | } |
7512 | 0 | |
7513 | 0 | static bool sIdsInited = false; |
7514 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
7515 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
7516 | 0 | return; |
7517 | 0 | } |
7518 | 0 | sIdsInited = true; |
7519 | 0 | } |
7520 | 0 |
|
7521 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPU); |
7522 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPU); |
7523 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
7524 | 0 | &sPrototypeClass.mBase, protoCache, |
7525 | 0 | nullptr, |
7526 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
7527 | 0 | interfaceCache, |
7528 | 0 | sNativeProperties.Upcast(), |
7529 | 0 | nullptr, |
7530 | 0 | "WebGPU", aDefineOnGlobal, |
7531 | 0 | nullptr, |
7532 | 0 | false); |
7533 | 0 | } |
7534 | | |
7535 | | JSObject* |
7536 | | GetConstructorObject(JSContext* aCx) |
7537 | 0 | { |
7538 | 0 | return GetConstructorObjectHandle(aCx); |
7539 | 0 | } |
7540 | | |
7541 | | } // namespace WebGPU_Binding |
7542 | | |
7543 | | |
7544 | | |
7545 | | namespace WebGPUAdapter_Binding { |
7546 | | |
7547 | | MOZ_CAN_RUN_SCRIPT static bool |
7548 | | get_name(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Adapter* self, JSJitGetterCallArgs args) |
7549 | 0 | { |
7550 | 0 | AUTO_PROFILER_LABEL_FAST("get WebGPUAdapter.name", DOM, cx); |
7551 | 0 |
|
7552 | 0 | DOMString result; |
7553 | 0 | self->GetName(result); |
7554 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
7555 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
7556 | 0 | return false; |
7557 | 0 | } |
7558 | 0 | return true; |
7559 | 0 | } |
7560 | | |
7561 | | static const JSJitInfo name_getterinfo = { |
7562 | | { (JSJitGetterOp)get_name }, |
7563 | | { prototypes::id::WebGPUAdapter }, |
7564 | | { PrototypeTraits<prototypes::id::WebGPUAdapter>::Depth }, |
7565 | | JSJitInfo::Getter, |
7566 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
7567 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
7568 | | false, /* isInfallible. False in setters. */ |
7569 | | false, /* isMovable. Not relevant for setters. */ |
7570 | | false, /* isEliminatable. Not relevant for setters. */ |
7571 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
7572 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
7573 | | false, /* isTypedMethod. Only relevant for methods. */ |
7574 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
7575 | | }; |
7576 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
7577 | | static_assert(0 < 1, "There is no slot for us"); |
7578 | | |
7579 | | MOZ_CAN_RUN_SCRIPT static bool |
7580 | | extensions(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Adapter* self, const JSJitMethodCallArgs& args) |
7581 | 0 | { |
7582 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUAdapter.extensions", DOM, cx); |
7583 | 0 |
|
7584 | 0 | WebGPUExtensions result; |
7585 | 0 | self->Extensions(result); |
7586 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
7587 | 0 | if (!result.ToObjectInternal(cx, args.rval())) { |
7588 | 0 | return false; |
7589 | 0 | } |
7590 | 0 | return true; |
7591 | 0 | } |
7592 | | |
7593 | | static const JSJitInfo extensions_methodinfo = { |
7594 | | { (JSJitGetterOp)extensions }, |
7595 | | { prototypes::id::WebGPUAdapter }, |
7596 | | { PrototypeTraits<prototypes::id::WebGPUAdapter>::Depth }, |
7597 | | JSJitInfo::Method, |
7598 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
7599 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
7600 | | false, /* isInfallible. False in setters. */ |
7601 | | false, /* isMovable. Not relevant for setters. */ |
7602 | | false, /* isEliminatable. Not relevant for setters. */ |
7603 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
7604 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
7605 | | false, /* isTypedMethod. Only relevant for methods. */ |
7606 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
7607 | | }; |
7608 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
7609 | | static_assert(0 < 1, "There is no slot for us"); |
7610 | | |
7611 | | MOZ_CAN_RUN_SCRIPT static bool |
7612 | | createDevice(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Adapter* self, const JSJitMethodCallArgs& args) |
7613 | 0 | { |
7614 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUAdapter.createDevice", DOM, cx); |
7615 | 0 |
|
7616 | 0 | binding_detail::FastWebGPUDeviceDescriptor arg0; |
7617 | 0 | if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of WebGPUAdapter.createDevice", false)) { |
7618 | 0 | return false; |
7619 | 0 | } |
7620 | 0 | auto result(StrongOrRawPtr<mozilla::webgpu::Device>(self->CreateDevice(Constify(arg0)))); |
7621 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
7622 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
7623 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
7624 | 0 | return false; |
7625 | 0 | } |
7626 | 0 | return true; |
7627 | 0 | } |
7628 | | |
7629 | | static const JSJitInfo createDevice_methodinfo = { |
7630 | | { (JSJitGetterOp)createDevice }, |
7631 | | { prototypes::id::WebGPUAdapter }, |
7632 | | { PrototypeTraits<prototypes::id::WebGPUAdapter>::Depth }, |
7633 | | JSJitInfo::Method, |
7634 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
7635 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
7636 | | false, /* isInfallible. False in setters. */ |
7637 | | false, /* isMovable. Not relevant for setters. */ |
7638 | | false, /* isEliminatable. Not relevant for setters. */ |
7639 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
7640 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
7641 | | false, /* isTypedMethod. Only relevant for methods. */ |
7642 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
7643 | | }; |
7644 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
7645 | | static_assert(0 < 1, "There is no slot for us"); |
7646 | | |
7647 | | static bool |
7648 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
7649 | 0 | { |
7650 | 0 | mozilla::webgpu::Adapter* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Adapter>(obj); |
7651 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
7652 | 0 | // obviously can't preserve if we're not initialized. |
7653 | 0 | if (self && self->GetWrapperPreserveColor()) { |
7654 | 0 | PreserveWrapper(self); |
7655 | 0 | } |
7656 | 0 | return true; |
7657 | 0 | } |
7658 | | |
7659 | | static void |
7660 | | _finalize(js::FreeOp* fop, JSObject* obj) |
7661 | 0 | { |
7662 | 0 | mozilla::webgpu::Adapter* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Adapter>(obj); |
7663 | 0 | if (self) { |
7664 | 0 | ClearWrapper(self, self, obj); |
7665 | 0 | AddForDeferredFinalization<mozilla::webgpu::Adapter>(self); |
7666 | 0 | } |
7667 | 0 | } |
7668 | | |
7669 | | static size_t |
7670 | | _objectMoved(JSObject* obj, JSObject* old) |
7671 | 0 | { |
7672 | 0 | mozilla::webgpu::Adapter* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Adapter>(obj); |
7673 | 0 | if (self) { |
7674 | 0 | UpdateWrapper(self, self, obj, old); |
7675 | 0 | } |
7676 | 0 |
|
7677 | 0 | return 0; |
7678 | 0 | } |
7679 | | |
7680 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
7681 | | #if defined(__clang__) |
7682 | | #pragma clang diagnostic push |
7683 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
7684 | | #endif |
7685 | | static const JSFunctionSpec sMethods_specs[] = { |
7686 | | JS_FNSPEC("extensions", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&extensions_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
7687 | | JS_FNSPEC("createDevice", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createDevice_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
7688 | | JS_FS_END |
7689 | | }; |
7690 | | #if defined(__clang__) |
7691 | | #pragma clang diagnostic pop |
7692 | | #endif |
7693 | | |
7694 | | |
7695 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
7696 | | { nullptr, &sMethods_specs[0] }, |
7697 | | { nullptr, nullptr } |
7698 | | }; |
7699 | | |
7700 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
7701 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
7702 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
7703 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
7704 | | |
7705 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
7706 | | #if defined(__clang__) |
7707 | | #pragma clang diagnostic push |
7708 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
7709 | | #endif |
7710 | | static const JSPropertySpec sAttributes_specs[] = { |
7711 | | { "name", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &name_getterinfo, nullptr, nullptr }, |
7712 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
7713 | | }; |
7714 | | #if defined(__clang__) |
7715 | | #pragma clang diagnostic pop |
7716 | | #endif |
7717 | | |
7718 | | |
7719 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
7720 | | { nullptr, &sAttributes_specs[0] }, |
7721 | | { nullptr, nullptr } |
7722 | | }; |
7723 | | |
7724 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
7725 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
7726 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
7727 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
7728 | | |
7729 | | |
7730 | | static uint16_t sNativeProperties_sortedPropertyIndices[3]; |
7731 | | static PropertyInfo sNativeProperties_propertyInfos[3]; |
7732 | | |
7733 | | static const NativePropertiesN<2> sNativeProperties = { |
7734 | | false, 0, |
7735 | | false, 0, |
7736 | | true, 0 /* sMethods */, |
7737 | | true, 1 /* sAttributes */, |
7738 | | false, 0, |
7739 | | false, 0, |
7740 | | false, 0, |
7741 | | -1, |
7742 | | 3, |
7743 | | sNativeProperties_sortedPropertyIndices, |
7744 | | { |
7745 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
7746 | | { sAttributes, &sNativeProperties_propertyInfos[2] } |
7747 | | } |
7748 | | }; |
7749 | | static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
7750 | | "We have a property info count that is oversized"); |
7751 | | |
7752 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
7753 | | { |
7754 | | "Function", |
7755 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
7756 | | &sBoringInterfaceObjectClassClassOps, |
7757 | | JS_NULL_CLASS_SPEC, |
7758 | | JS_NULL_CLASS_EXT, |
7759 | | &sInterfaceObjectClassObjectOps |
7760 | | }, |
7761 | | eInterface, |
7762 | | true, |
7763 | | prototypes::id::WebGPUAdapter, |
7764 | | PrototypeTraits<prototypes::id::WebGPUAdapter>::Depth, |
7765 | | sNativePropertyHooks, |
7766 | | "function WebGPUAdapter() {\n [native code]\n}", |
7767 | | JS::GetRealmFunctionPrototype |
7768 | | }; |
7769 | | |
7770 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
7771 | | { |
7772 | | "WebGPUAdapterPrototype", |
7773 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
7774 | | JS_NULL_CLASS_OPS, |
7775 | | JS_NULL_CLASS_SPEC, |
7776 | | JS_NULL_CLASS_EXT, |
7777 | | JS_NULL_OBJECT_OPS |
7778 | | }, |
7779 | | eInterfacePrototype, |
7780 | | false, |
7781 | | prototypes::id::WebGPUAdapter, |
7782 | | PrototypeTraits<prototypes::id::WebGPUAdapter>::Depth, |
7783 | | sNativePropertyHooks, |
7784 | | "[object WebGPUAdapterPrototype]", |
7785 | | JS::GetRealmObjectPrototype |
7786 | | }; |
7787 | | |
7788 | | bool |
7789 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
7790 | 0 | { |
7791 | 0 | static bool sPrefValue; |
7792 | 0 | static bool sPrefCacheSetUp = false; |
7793 | 0 | if (!sPrefCacheSetUp) { |
7794 | 0 | sPrefCacheSetUp = true; |
7795 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
7796 | 0 | } |
7797 | 0 |
|
7798 | 0 | return sPrefValue; |
7799 | 0 | } |
7800 | | |
7801 | | static const js::ClassOps sClassOps = { |
7802 | | _addProperty, /* addProperty */ |
7803 | | nullptr, /* delProperty */ |
7804 | | nullptr, /* enumerate */ |
7805 | | nullptr, /* newEnumerate */ |
7806 | | nullptr, /* resolve */ |
7807 | | nullptr, /* mayResolve */ |
7808 | | _finalize, /* finalize */ |
7809 | | nullptr, /* call */ |
7810 | | nullptr, /* hasInstance */ |
7811 | | nullptr, /* construct */ |
7812 | | nullptr, /* trace */ |
7813 | | }; |
7814 | | |
7815 | | static const js::ClassExtension sClassExtension = { |
7816 | | nullptr, /* weakmapKeyDelegateOp */ |
7817 | | _objectMoved /* objectMovedOp */ |
7818 | | }; |
7819 | | |
7820 | | static const DOMJSClass sClass = { |
7821 | | { "WebGPUAdapter", |
7822 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
7823 | | &sClassOps, |
7824 | | JS_NULL_CLASS_SPEC, |
7825 | | &sClassExtension, |
7826 | | JS_NULL_OBJECT_OPS |
7827 | | }, |
7828 | | { prototypes::id::WebGPUAdapter, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
7829 | | IsBaseOf<nsISupports, mozilla::webgpu::Adapter >::value, |
7830 | | sNativePropertyHooks, |
7831 | | FindAssociatedGlobalForNative<mozilla::webgpu::Adapter>::Get, |
7832 | | GetProtoObjectHandle, |
7833 | | GetCCParticipant<mozilla::webgpu::Adapter>::Get() |
7834 | | }; |
7835 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
7836 | | "Must have the right minimal number of reserved slots."); |
7837 | | static_assert(1 >= 1, |
7838 | | "Must have enough reserved slots."); |
7839 | | |
7840 | | const JSClass* |
7841 | | GetJSClass() |
7842 | 0 | { |
7843 | 0 | return sClass.ToJSClass(); |
7844 | 0 | } |
7845 | | |
7846 | | bool |
7847 | | Wrap(JSContext* aCx, mozilla::webgpu::Adapter* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
7848 | 0 | { |
7849 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::Adapter>::value, |
7850 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
7851 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::Adapter*>(aObject) == |
7852 | 0 | reinterpret_cast<mozilla::webgpu::Adapter*>(aObject), |
7853 | 0 | "Multiple inheritance for mozilla::webgpu::Adapter is broken."); |
7854 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
7855 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
7856 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
7857 | 0 | "You should probably not be using Wrap() directly; use " |
7858 | 0 | "GetOrCreateDOMReflector instead"); |
7859 | 0 |
|
7860 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
7861 | 0 | "nsISupports must be on our primary inheritance chain"); |
7862 | 0 |
|
7863 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
7864 | 0 | if (!global) { |
7865 | 0 | return false; |
7866 | 0 | } |
7867 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
7868 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
7869 | 0 |
|
7870 | 0 | // That might have ended up wrapping us already, due to the wonders |
7871 | 0 | // of XBL. Check for that, and bail out as needed. |
7872 | 0 | aReflector.set(aCache->GetWrapper()); |
7873 | 0 | if (aReflector) { |
7874 | | #ifdef DEBUG |
7875 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
7876 | | #endif // DEBUG |
7877 | | return true; |
7878 | 0 | } |
7879 | 0 |
|
7880 | 0 | JSAutoRealm ar(aCx, global); |
7881 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
7882 | 0 | if (!canonicalProto) { |
7883 | 0 | return false; |
7884 | 0 | } |
7885 | 0 | JS::Rooted<JSObject*> proto(aCx); |
7886 | 0 | if (aGivenProto) { |
7887 | 0 | proto = aGivenProto; |
7888 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
7889 | 0 | // coming in, we changed compartments to that of "parent" so may need |
7890 | 0 | // to wrap the proto here. |
7891 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
7892 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
7893 | 0 | return false; |
7894 | 0 | } |
7895 | 0 | } |
7896 | 0 | } else { |
7897 | 0 | proto = canonicalProto; |
7898 | 0 | } |
7899 | 0 |
|
7900 | 0 | BindingJSObjectCreator<mozilla::webgpu::Adapter> creator(aCx); |
7901 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
7902 | 0 | if (!aReflector) { |
7903 | 0 | return false; |
7904 | 0 | } |
7905 | 0 | |
7906 | 0 | aCache->SetWrapper(aReflector); |
7907 | 0 | creator.InitializationSucceeded(); |
7908 | 0 |
|
7909 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
7910 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
7911 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
7912 | 0 | // otherwise we won't be able to properly recreate it later, since |
7913 | 0 | // we won't know what proto to use. Note that we don't check |
7914 | 0 | // aGivenProto here, since it's entirely possible (and even |
7915 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
7916 | 0 | // same as canonicalProto. |
7917 | 0 | if (proto != canonicalProto) { |
7918 | 0 | PreserveWrapper(aObject); |
7919 | 0 | } |
7920 | 0 |
|
7921 | 0 | return true; |
7922 | 0 | } |
7923 | | |
7924 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
7925 | | nullptr, |
7926 | | nullptr, |
7927 | | nullptr, |
7928 | | { sNativeProperties.Upcast(), nullptr }, |
7929 | | prototypes::id::WebGPUAdapter, |
7930 | | constructors::id::WebGPUAdapter, |
7931 | | nullptr, |
7932 | | &DefaultXrayExpandoObjectClass |
7933 | | } }; |
7934 | | |
7935 | | void |
7936 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
7937 | 0 | { |
7938 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
7939 | 0 | if (!parentProto) { |
7940 | 0 | return; |
7941 | 0 | } |
7942 | 0 | |
7943 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
7944 | 0 | if (!constructorProto) { |
7945 | 0 | return; |
7946 | 0 | } |
7947 | 0 | |
7948 | 0 | static bool sIdsInited = false; |
7949 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
7950 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
7951 | 0 | return; |
7952 | 0 | } |
7953 | 0 | sIdsInited = true; |
7954 | 0 | } |
7955 | 0 |
|
7956 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPUAdapter); |
7957 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUAdapter); |
7958 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
7959 | 0 | &sPrototypeClass.mBase, protoCache, |
7960 | 0 | nullptr, |
7961 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
7962 | 0 | interfaceCache, |
7963 | 0 | sNativeProperties.Upcast(), |
7964 | 0 | nullptr, |
7965 | 0 | "WebGPUAdapter", aDefineOnGlobal, |
7966 | 0 | nullptr, |
7967 | 0 | false); |
7968 | 0 | } |
7969 | | |
7970 | | JSObject* |
7971 | | GetConstructorObject(JSContext* aCx) |
7972 | 0 | { |
7973 | 0 | return GetConstructorObjectHandle(aCx); |
7974 | 0 | } |
7975 | | |
7976 | | } // namespace WebGPUAdapter_Binding |
7977 | | |
7978 | | |
7979 | | |
7980 | | namespace WebGPUAttachmentState_Binding { |
7981 | | |
7982 | | static bool |
7983 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
7984 | 0 | { |
7985 | 0 | mozilla::webgpu::AttachmentState* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::AttachmentState>(obj); |
7986 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
7987 | 0 | // obviously can't preserve if we're not initialized. |
7988 | 0 | if (self && self->GetWrapperPreserveColor()) { |
7989 | 0 | PreserveWrapper(self); |
7990 | 0 | } |
7991 | 0 | return true; |
7992 | 0 | } |
7993 | | |
7994 | | static void |
7995 | | _finalize(js::FreeOp* fop, JSObject* obj) |
7996 | 0 | { |
7997 | 0 | mozilla::webgpu::AttachmentState* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::AttachmentState>(obj); |
7998 | 0 | if (self) { |
7999 | 0 | ClearWrapper(self, self, obj); |
8000 | 0 | AddForDeferredFinalization<mozilla::webgpu::AttachmentState>(self); |
8001 | 0 | } |
8002 | 0 | } |
8003 | | |
8004 | | static size_t |
8005 | | _objectMoved(JSObject* obj, JSObject* old) |
8006 | 0 | { |
8007 | 0 | mozilla::webgpu::AttachmentState* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::AttachmentState>(obj); |
8008 | 0 | if (self) { |
8009 | 0 | UpdateWrapper(self, self, obj, old); |
8010 | 0 | } |
8011 | 0 |
|
8012 | 0 | return 0; |
8013 | 0 | } |
8014 | | |
8015 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
8016 | | { |
8017 | | "Function", |
8018 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
8019 | | &sBoringInterfaceObjectClassClassOps, |
8020 | | JS_NULL_CLASS_SPEC, |
8021 | | JS_NULL_CLASS_EXT, |
8022 | | &sInterfaceObjectClassObjectOps |
8023 | | }, |
8024 | | eInterface, |
8025 | | true, |
8026 | | prototypes::id::WebGPUAttachmentState, |
8027 | | PrototypeTraits<prototypes::id::WebGPUAttachmentState>::Depth, |
8028 | | sNativePropertyHooks, |
8029 | | "function WebGPUAttachmentState() {\n [native code]\n}", |
8030 | | JS::GetRealmFunctionPrototype |
8031 | | }; |
8032 | | |
8033 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
8034 | | { |
8035 | | "WebGPUAttachmentStatePrototype", |
8036 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
8037 | | JS_NULL_CLASS_OPS, |
8038 | | JS_NULL_CLASS_SPEC, |
8039 | | JS_NULL_CLASS_EXT, |
8040 | | JS_NULL_OBJECT_OPS |
8041 | | }, |
8042 | | eInterfacePrototype, |
8043 | | false, |
8044 | | prototypes::id::WebGPUAttachmentState, |
8045 | | PrototypeTraits<prototypes::id::WebGPUAttachmentState>::Depth, |
8046 | | sNativePropertyHooks, |
8047 | | "[object WebGPUAttachmentStatePrototype]", |
8048 | | JS::GetRealmObjectPrototype |
8049 | | }; |
8050 | | |
8051 | | bool |
8052 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
8053 | 0 | { |
8054 | 0 | static bool sPrefValue; |
8055 | 0 | static bool sPrefCacheSetUp = false; |
8056 | 0 | if (!sPrefCacheSetUp) { |
8057 | 0 | sPrefCacheSetUp = true; |
8058 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
8059 | 0 | } |
8060 | 0 |
|
8061 | 0 | return sPrefValue; |
8062 | 0 | } |
8063 | | |
8064 | | static const js::ClassOps sClassOps = { |
8065 | | _addProperty, /* addProperty */ |
8066 | | nullptr, /* delProperty */ |
8067 | | nullptr, /* enumerate */ |
8068 | | nullptr, /* newEnumerate */ |
8069 | | nullptr, /* resolve */ |
8070 | | nullptr, /* mayResolve */ |
8071 | | _finalize, /* finalize */ |
8072 | | nullptr, /* call */ |
8073 | | nullptr, /* hasInstance */ |
8074 | | nullptr, /* construct */ |
8075 | | nullptr, /* trace */ |
8076 | | }; |
8077 | | |
8078 | | static const js::ClassExtension sClassExtension = { |
8079 | | nullptr, /* weakmapKeyDelegateOp */ |
8080 | | _objectMoved /* objectMovedOp */ |
8081 | | }; |
8082 | | |
8083 | | static const DOMJSClass sClass = { |
8084 | | { "WebGPUAttachmentState", |
8085 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
8086 | | &sClassOps, |
8087 | | JS_NULL_CLASS_SPEC, |
8088 | | &sClassExtension, |
8089 | | JS_NULL_OBJECT_OPS |
8090 | | }, |
8091 | | { prototypes::id::WebGPUAttachmentState, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
8092 | | IsBaseOf<nsISupports, mozilla::webgpu::AttachmentState >::value, |
8093 | | sNativePropertyHooks, |
8094 | | FindAssociatedGlobalForNative<mozilla::webgpu::AttachmentState>::Get, |
8095 | | GetProtoObjectHandle, |
8096 | | GetCCParticipant<mozilla::webgpu::AttachmentState>::Get() |
8097 | | }; |
8098 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
8099 | | "Must have the right minimal number of reserved slots."); |
8100 | | static_assert(1 >= 1, |
8101 | | "Must have enough reserved slots."); |
8102 | | |
8103 | | const JSClass* |
8104 | | GetJSClass() |
8105 | 0 | { |
8106 | 0 | return sClass.ToJSClass(); |
8107 | 0 | } |
8108 | | |
8109 | | bool |
8110 | | Wrap(JSContext* aCx, mozilla::webgpu::AttachmentState* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
8111 | 0 | { |
8112 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::AttachmentState>::value, |
8113 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
8114 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::AttachmentState*>(aObject) == |
8115 | 0 | reinterpret_cast<mozilla::webgpu::AttachmentState*>(aObject), |
8116 | 0 | "Multiple inheritance for mozilla::webgpu::AttachmentState is broken."); |
8117 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
8118 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
8119 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
8120 | 0 | "You should probably not be using Wrap() directly; use " |
8121 | 0 | "GetOrCreateDOMReflector instead"); |
8122 | 0 |
|
8123 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
8124 | 0 | "nsISupports must be on our primary inheritance chain"); |
8125 | 0 |
|
8126 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
8127 | 0 | if (!global) { |
8128 | 0 | return false; |
8129 | 0 | } |
8130 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
8131 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
8132 | 0 |
|
8133 | 0 | // That might have ended up wrapping us already, due to the wonders |
8134 | 0 | // of XBL. Check for that, and bail out as needed. |
8135 | 0 | aReflector.set(aCache->GetWrapper()); |
8136 | 0 | if (aReflector) { |
8137 | | #ifdef DEBUG |
8138 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
8139 | | #endif // DEBUG |
8140 | | return true; |
8141 | 0 | } |
8142 | 0 |
|
8143 | 0 | JSAutoRealm ar(aCx, global); |
8144 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
8145 | 0 | if (!canonicalProto) { |
8146 | 0 | return false; |
8147 | 0 | } |
8148 | 0 | JS::Rooted<JSObject*> proto(aCx); |
8149 | 0 | if (aGivenProto) { |
8150 | 0 | proto = aGivenProto; |
8151 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
8152 | 0 | // coming in, we changed compartments to that of "parent" so may need |
8153 | 0 | // to wrap the proto here. |
8154 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
8155 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
8156 | 0 | return false; |
8157 | 0 | } |
8158 | 0 | } |
8159 | 0 | } else { |
8160 | 0 | proto = canonicalProto; |
8161 | 0 | } |
8162 | 0 |
|
8163 | 0 | BindingJSObjectCreator<mozilla::webgpu::AttachmentState> creator(aCx); |
8164 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
8165 | 0 | if (!aReflector) { |
8166 | 0 | return false; |
8167 | 0 | } |
8168 | 0 | |
8169 | 0 | aCache->SetWrapper(aReflector); |
8170 | 0 | creator.InitializationSucceeded(); |
8171 | 0 |
|
8172 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
8173 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
8174 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
8175 | 0 | // otherwise we won't be able to properly recreate it later, since |
8176 | 0 | // we won't know what proto to use. Note that we don't check |
8177 | 0 | // aGivenProto here, since it's entirely possible (and even |
8178 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
8179 | 0 | // same as canonicalProto. |
8180 | 0 | if (proto != canonicalProto) { |
8181 | 0 | PreserveWrapper(aObject); |
8182 | 0 | } |
8183 | 0 |
|
8184 | 0 | return true; |
8185 | 0 | } |
8186 | | |
8187 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
8188 | | nullptr, |
8189 | | nullptr, |
8190 | | nullptr, |
8191 | | { nullptr, nullptr }, |
8192 | | prototypes::id::WebGPUAttachmentState, |
8193 | | constructors::id::WebGPUAttachmentState, |
8194 | | nullptr, |
8195 | | &DefaultXrayExpandoObjectClass |
8196 | | } }; |
8197 | | |
8198 | | void |
8199 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
8200 | 0 | { |
8201 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
8202 | 0 | if (!parentProto) { |
8203 | 0 | return; |
8204 | 0 | } |
8205 | 0 | |
8206 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
8207 | 0 | if (!constructorProto) { |
8208 | 0 | return; |
8209 | 0 | } |
8210 | 0 | |
8211 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPUAttachmentState); |
8212 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUAttachmentState); |
8213 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
8214 | 0 | &sPrototypeClass.mBase, protoCache, |
8215 | 0 | nullptr, |
8216 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
8217 | 0 | interfaceCache, |
8218 | 0 | nullptr, |
8219 | 0 | nullptr, |
8220 | 0 | "WebGPUAttachmentState", aDefineOnGlobal, |
8221 | 0 | nullptr, |
8222 | 0 | false); |
8223 | 0 | } |
8224 | | |
8225 | | JSObject* |
8226 | | GetConstructorObject(JSContext* aCx) |
8227 | 0 | { |
8228 | 0 | return GetConstructorObjectHandle(aCx); |
8229 | 0 | } |
8230 | | |
8231 | | } // namespace WebGPUAttachmentState_Binding |
8232 | | |
8233 | | |
8234 | | |
8235 | | namespace WebGPUBindGroup_Binding { |
8236 | | |
8237 | | static bool |
8238 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
8239 | 0 | { |
8240 | 0 | mozilla::webgpu::BindGroup* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::BindGroup>(obj); |
8241 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
8242 | 0 | // obviously can't preserve if we're not initialized. |
8243 | 0 | if (self && self->GetWrapperPreserveColor()) { |
8244 | 0 | PreserveWrapper(self); |
8245 | 0 | } |
8246 | 0 | return true; |
8247 | 0 | } |
8248 | | |
8249 | | static void |
8250 | | _finalize(js::FreeOp* fop, JSObject* obj) |
8251 | 0 | { |
8252 | 0 | mozilla::webgpu::BindGroup* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::BindGroup>(obj); |
8253 | 0 | if (self) { |
8254 | 0 | ClearWrapper(self, self, obj); |
8255 | 0 | AddForDeferredFinalization<mozilla::webgpu::BindGroup>(self); |
8256 | 0 | } |
8257 | 0 | } |
8258 | | |
8259 | | static size_t |
8260 | | _objectMoved(JSObject* obj, JSObject* old) |
8261 | 0 | { |
8262 | 0 | mozilla::webgpu::BindGroup* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::BindGroup>(obj); |
8263 | 0 | if (self) { |
8264 | 0 | UpdateWrapper(self, self, obj, old); |
8265 | 0 | } |
8266 | 0 |
|
8267 | 0 | return 0; |
8268 | 0 | } |
8269 | | |
8270 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
8271 | | { |
8272 | | "Function", |
8273 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
8274 | | &sBoringInterfaceObjectClassClassOps, |
8275 | | JS_NULL_CLASS_SPEC, |
8276 | | JS_NULL_CLASS_EXT, |
8277 | | &sInterfaceObjectClassObjectOps |
8278 | | }, |
8279 | | eInterface, |
8280 | | true, |
8281 | | prototypes::id::WebGPUBindGroup, |
8282 | | PrototypeTraits<prototypes::id::WebGPUBindGroup>::Depth, |
8283 | | sNativePropertyHooks, |
8284 | | "function WebGPUBindGroup() {\n [native code]\n}", |
8285 | | JS::GetRealmFunctionPrototype |
8286 | | }; |
8287 | | |
8288 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
8289 | | { |
8290 | | "WebGPUBindGroupPrototype", |
8291 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
8292 | | JS_NULL_CLASS_OPS, |
8293 | | JS_NULL_CLASS_SPEC, |
8294 | | JS_NULL_CLASS_EXT, |
8295 | | JS_NULL_OBJECT_OPS |
8296 | | }, |
8297 | | eInterfacePrototype, |
8298 | | false, |
8299 | | prototypes::id::WebGPUBindGroup, |
8300 | | PrototypeTraits<prototypes::id::WebGPUBindGroup>::Depth, |
8301 | | sNativePropertyHooks, |
8302 | | "[object WebGPUBindGroupPrototype]", |
8303 | | JS::GetRealmObjectPrototype |
8304 | | }; |
8305 | | |
8306 | | bool |
8307 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
8308 | 0 | { |
8309 | 0 | static bool sPrefValue; |
8310 | 0 | static bool sPrefCacheSetUp = false; |
8311 | 0 | if (!sPrefCacheSetUp) { |
8312 | 0 | sPrefCacheSetUp = true; |
8313 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
8314 | 0 | } |
8315 | 0 |
|
8316 | 0 | return sPrefValue; |
8317 | 0 | } |
8318 | | |
8319 | | static const js::ClassOps sClassOps = { |
8320 | | _addProperty, /* addProperty */ |
8321 | | nullptr, /* delProperty */ |
8322 | | nullptr, /* enumerate */ |
8323 | | nullptr, /* newEnumerate */ |
8324 | | nullptr, /* resolve */ |
8325 | | nullptr, /* mayResolve */ |
8326 | | _finalize, /* finalize */ |
8327 | | nullptr, /* call */ |
8328 | | nullptr, /* hasInstance */ |
8329 | | nullptr, /* construct */ |
8330 | | nullptr, /* trace */ |
8331 | | }; |
8332 | | |
8333 | | static const js::ClassExtension sClassExtension = { |
8334 | | nullptr, /* weakmapKeyDelegateOp */ |
8335 | | _objectMoved /* objectMovedOp */ |
8336 | | }; |
8337 | | |
8338 | | static const DOMJSClass sClass = { |
8339 | | { "WebGPUBindGroup", |
8340 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
8341 | | &sClassOps, |
8342 | | JS_NULL_CLASS_SPEC, |
8343 | | &sClassExtension, |
8344 | | JS_NULL_OBJECT_OPS |
8345 | | }, |
8346 | | { prototypes::id::WebGPUBindGroup, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
8347 | | IsBaseOf<nsISupports, mozilla::webgpu::BindGroup >::value, |
8348 | | sNativePropertyHooks, |
8349 | | FindAssociatedGlobalForNative<mozilla::webgpu::BindGroup>::Get, |
8350 | | GetProtoObjectHandle, |
8351 | | GetCCParticipant<mozilla::webgpu::BindGroup>::Get() |
8352 | | }; |
8353 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
8354 | | "Must have the right minimal number of reserved slots."); |
8355 | | static_assert(1 >= 1, |
8356 | | "Must have enough reserved slots."); |
8357 | | |
8358 | | const JSClass* |
8359 | | GetJSClass() |
8360 | 0 | { |
8361 | 0 | return sClass.ToJSClass(); |
8362 | 0 | } |
8363 | | |
8364 | | bool |
8365 | | Wrap(JSContext* aCx, mozilla::webgpu::BindGroup* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
8366 | 0 | { |
8367 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::BindGroup>::value, |
8368 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
8369 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::BindGroup*>(aObject) == |
8370 | 0 | reinterpret_cast<mozilla::webgpu::BindGroup*>(aObject), |
8371 | 0 | "Multiple inheritance for mozilla::webgpu::BindGroup is broken."); |
8372 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
8373 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
8374 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
8375 | 0 | "You should probably not be using Wrap() directly; use " |
8376 | 0 | "GetOrCreateDOMReflector instead"); |
8377 | 0 |
|
8378 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
8379 | 0 | "nsISupports must be on our primary inheritance chain"); |
8380 | 0 |
|
8381 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
8382 | 0 | if (!global) { |
8383 | 0 | return false; |
8384 | 0 | } |
8385 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
8386 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
8387 | 0 |
|
8388 | 0 | // That might have ended up wrapping us already, due to the wonders |
8389 | 0 | // of XBL. Check for that, and bail out as needed. |
8390 | 0 | aReflector.set(aCache->GetWrapper()); |
8391 | 0 | if (aReflector) { |
8392 | | #ifdef DEBUG |
8393 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
8394 | | #endif // DEBUG |
8395 | | return true; |
8396 | 0 | } |
8397 | 0 |
|
8398 | 0 | JSAutoRealm ar(aCx, global); |
8399 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
8400 | 0 | if (!canonicalProto) { |
8401 | 0 | return false; |
8402 | 0 | } |
8403 | 0 | JS::Rooted<JSObject*> proto(aCx); |
8404 | 0 | if (aGivenProto) { |
8405 | 0 | proto = aGivenProto; |
8406 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
8407 | 0 | // coming in, we changed compartments to that of "parent" so may need |
8408 | 0 | // to wrap the proto here. |
8409 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
8410 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
8411 | 0 | return false; |
8412 | 0 | } |
8413 | 0 | } |
8414 | 0 | } else { |
8415 | 0 | proto = canonicalProto; |
8416 | 0 | } |
8417 | 0 |
|
8418 | 0 | BindingJSObjectCreator<mozilla::webgpu::BindGroup> creator(aCx); |
8419 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
8420 | 0 | if (!aReflector) { |
8421 | 0 | return false; |
8422 | 0 | } |
8423 | 0 | |
8424 | 0 | aCache->SetWrapper(aReflector); |
8425 | 0 | creator.InitializationSucceeded(); |
8426 | 0 |
|
8427 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
8428 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
8429 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
8430 | 0 | // otherwise we won't be able to properly recreate it later, since |
8431 | 0 | // we won't know what proto to use. Note that we don't check |
8432 | 0 | // aGivenProto here, since it's entirely possible (and even |
8433 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
8434 | 0 | // same as canonicalProto. |
8435 | 0 | if (proto != canonicalProto) { |
8436 | 0 | PreserveWrapper(aObject); |
8437 | 0 | } |
8438 | 0 |
|
8439 | 0 | return true; |
8440 | 0 | } |
8441 | | |
8442 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
8443 | | nullptr, |
8444 | | nullptr, |
8445 | | nullptr, |
8446 | | { nullptr, nullptr }, |
8447 | | prototypes::id::WebGPUBindGroup, |
8448 | | constructors::id::WebGPUBindGroup, |
8449 | | nullptr, |
8450 | | &DefaultXrayExpandoObjectClass |
8451 | | } }; |
8452 | | |
8453 | | void |
8454 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
8455 | 0 | { |
8456 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
8457 | 0 | if (!parentProto) { |
8458 | 0 | return; |
8459 | 0 | } |
8460 | 0 | |
8461 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
8462 | 0 | if (!constructorProto) { |
8463 | 0 | return; |
8464 | 0 | } |
8465 | 0 | |
8466 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPUBindGroup); |
8467 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUBindGroup); |
8468 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
8469 | 0 | &sPrototypeClass.mBase, protoCache, |
8470 | 0 | nullptr, |
8471 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
8472 | 0 | interfaceCache, |
8473 | 0 | nullptr, |
8474 | 0 | nullptr, |
8475 | 0 | "WebGPUBindGroup", aDefineOnGlobal, |
8476 | 0 | nullptr, |
8477 | 0 | false); |
8478 | 0 | } |
8479 | | |
8480 | | JSObject* |
8481 | | GetConstructorObject(JSContext* aCx) |
8482 | 0 | { |
8483 | 0 | return GetConstructorObjectHandle(aCx); |
8484 | 0 | } |
8485 | | |
8486 | | } // namespace WebGPUBindGroup_Binding |
8487 | | |
8488 | | |
8489 | | |
8490 | | namespace WebGPUBindGroupLayout_Binding { |
8491 | | |
8492 | | static bool |
8493 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
8494 | 0 | { |
8495 | 0 | mozilla::webgpu::BindGroupLayout* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::BindGroupLayout>(obj); |
8496 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
8497 | 0 | // obviously can't preserve if we're not initialized. |
8498 | 0 | if (self && self->GetWrapperPreserveColor()) { |
8499 | 0 | PreserveWrapper(self); |
8500 | 0 | } |
8501 | 0 | return true; |
8502 | 0 | } |
8503 | | |
8504 | | static void |
8505 | | _finalize(js::FreeOp* fop, JSObject* obj) |
8506 | 0 | { |
8507 | 0 | mozilla::webgpu::BindGroupLayout* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::BindGroupLayout>(obj); |
8508 | 0 | if (self) { |
8509 | 0 | ClearWrapper(self, self, obj); |
8510 | 0 | AddForDeferredFinalization<mozilla::webgpu::BindGroupLayout>(self); |
8511 | 0 | } |
8512 | 0 | } |
8513 | | |
8514 | | static size_t |
8515 | | _objectMoved(JSObject* obj, JSObject* old) |
8516 | 0 | { |
8517 | 0 | mozilla::webgpu::BindGroupLayout* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::BindGroupLayout>(obj); |
8518 | 0 | if (self) { |
8519 | 0 | UpdateWrapper(self, self, obj, old); |
8520 | 0 | } |
8521 | 0 |
|
8522 | 0 | return 0; |
8523 | 0 | } |
8524 | | |
8525 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
8526 | | { |
8527 | | "Function", |
8528 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
8529 | | &sBoringInterfaceObjectClassClassOps, |
8530 | | JS_NULL_CLASS_SPEC, |
8531 | | JS_NULL_CLASS_EXT, |
8532 | | &sInterfaceObjectClassObjectOps |
8533 | | }, |
8534 | | eInterface, |
8535 | | true, |
8536 | | prototypes::id::WebGPUBindGroupLayout, |
8537 | | PrototypeTraits<prototypes::id::WebGPUBindGroupLayout>::Depth, |
8538 | | sNativePropertyHooks, |
8539 | | "function WebGPUBindGroupLayout() {\n [native code]\n}", |
8540 | | JS::GetRealmFunctionPrototype |
8541 | | }; |
8542 | | |
8543 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
8544 | | { |
8545 | | "WebGPUBindGroupLayoutPrototype", |
8546 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
8547 | | JS_NULL_CLASS_OPS, |
8548 | | JS_NULL_CLASS_SPEC, |
8549 | | JS_NULL_CLASS_EXT, |
8550 | | JS_NULL_OBJECT_OPS |
8551 | | }, |
8552 | | eInterfacePrototype, |
8553 | | false, |
8554 | | prototypes::id::WebGPUBindGroupLayout, |
8555 | | PrototypeTraits<prototypes::id::WebGPUBindGroupLayout>::Depth, |
8556 | | sNativePropertyHooks, |
8557 | | "[object WebGPUBindGroupLayoutPrototype]", |
8558 | | JS::GetRealmObjectPrototype |
8559 | | }; |
8560 | | |
8561 | | bool |
8562 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
8563 | 0 | { |
8564 | 0 | static bool sPrefValue; |
8565 | 0 | static bool sPrefCacheSetUp = false; |
8566 | 0 | if (!sPrefCacheSetUp) { |
8567 | 0 | sPrefCacheSetUp = true; |
8568 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
8569 | 0 | } |
8570 | 0 |
|
8571 | 0 | return sPrefValue; |
8572 | 0 | } |
8573 | | |
8574 | | static const js::ClassOps sClassOps = { |
8575 | | _addProperty, /* addProperty */ |
8576 | | nullptr, /* delProperty */ |
8577 | | nullptr, /* enumerate */ |
8578 | | nullptr, /* newEnumerate */ |
8579 | | nullptr, /* resolve */ |
8580 | | nullptr, /* mayResolve */ |
8581 | | _finalize, /* finalize */ |
8582 | | nullptr, /* call */ |
8583 | | nullptr, /* hasInstance */ |
8584 | | nullptr, /* construct */ |
8585 | | nullptr, /* trace */ |
8586 | | }; |
8587 | | |
8588 | | static const js::ClassExtension sClassExtension = { |
8589 | | nullptr, /* weakmapKeyDelegateOp */ |
8590 | | _objectMoved /* objectMovedOp */ |
8591 | | }; |
8592 | | |
8593 | | static const DOMJSClass sClass = { |
8594 | | { "WebGPUBindGroupLayout", |
8595 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
8596 | | &sClassOps, |
8597 | | JS_NULL_CLASS_SPEC, |
8598 | | &sClassExtension, |
8599 | | JS_NULL_OBJECT_OPS |
8600 | | }, |
8601 | | { prototypes::id::WebGPUBindGroupLayout, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
8602 | | IsBaseOf<nsISupports, mozilla::webgpu::BindGroupLayout >::value, |
8603 | | sNativePropertyHooks, |
8604 | | FindAssociatedGlobalForNative<mozilla::webgpu::BindGroupLayout>::Get, |
8605 | | GetProtoObjectHandle, |
8606 | | GetCCParticipant<mozilla::webgpu::BindGroupLayout>::Get() |
8607 | | }; |
8608 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
8609 | | "Must have the right minimal number of reserved slots."); |
8610 | | static_assert(1 >= 1, |
8611 | | "Must have enough reserved slots."); |
8612 | | |
8613 | | const JSClass* |
8614 | | GetJSClass() |
8615 | 0 | { |
8616 | 0 | return sClass.ToJSClass(); |
8617 | 0 | } |
8618 | | |
8619 | | bool |
8620 | | Wrap(JSContext* aCx, mozilla::webgpu::BindGroupLayout* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
8621 | 0 | { |
8622 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::BindGroupLayout>::value, |
8623 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
8624 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::BindGroupLayout*>(aObject) == |
8625 | 0 | reinterpret_cast<mozilla::webgpu::BindGroupLayout*>(aObject), |
8626 | 0 | "Multiple inheritance for mozilla::webgpu::BindGroupLayout is broken."); |
8627 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
8628 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
8629 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
8630 | 0 | "You should probably not be using Wrap() directly; use " |
8631 | 0 | "GetOrCreateDOMReflector instead"); |
8632 | 0 |
|
8633 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
8634 | 0 | "nsISupports must be on our primary inheritance chain"); |
8635 | 0 |
|
8636 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
8637 | 0 | if (!global) { |
8638 | 0 | return false; |
8639 | 0 | } |
8640 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
8641 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
8642 | 0 |
|
8643 | 0 | // That might have ended up wrapping us already, due to the wonders |
8644 | 0 | // of XBL. Check for that, and bail out as needed. |
8645 | 0 | aReflector.set(aCache->GetWrapper()); |
8646 | 0 | if (aReflector) { |
8647 | | #ifdef DEBUG |
8648 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
8649 | | #endif // DEBUG |
8650 | | return true; |
8651 | 0 | } |
8652 | 0 |
|
8653 | 0 | JSAutoRealm ar(aCx, global); |
8654 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
8655 | 0 | if (!canonicalProto) { |
8656 | 0 | return false; |
8657 | 0 | } |
8658 | 0 | JS::Rooted<JSObject*> proto(aCx); |
8659 | 0 | if (aGivenProto) { |
8660 | 0 | proto = aGivenProto; |
8661 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
8662 | 0 | // coming in, we changed compartments to that of "parent" so may need |
8663 | 0 | // to wrap the proto here. |
8664 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
8665 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
8666 | 0 | return false; |
8667 | 0 | } |
8668 | 0 | } |
8669 | 0 | } else { |
8670 | 0 | proto = canonicalProto; |
8671 | 0 | } |
8672 | 0 |
|
8673 | 0 | BindingJSObjectCreator<mozilla::webgpu::BindGroupLayout> creator(aCx); |
8674 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
8675 | 0 | if (!aReflector) { |
8676 | 0 | return false; |
8677 | 0 | } |
8678 | 0 | |
8679 | 0 | aCache->SetWrapper(aReflector); |
8680 | 0 | creator.InitializationSucceeded(); |
8681 | 0 |
|
8682 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
8683 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
8684 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
8685 | 0 | // otherwise we won't be able to properly recreate it later, since |
8686 | 0 | // we won't know what proto to use. Note that we don't check |
8687 | 0 | // aGivenProto here, since it's entirely possible (and even |
8688 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
8689 | 0 | // same as canonicalProto. |
8690 | 0 | if (proto != canonicalProto) { |
8691 | 0 | PreserveWrapper(aObject); |
8692 | 0 | } |
8693 | 0 |
|
8694 | 0 | return true; |
8695 | 0 | } |
8696 | | |
8697 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
8698 | | nullptr, |
8699 | | nullptr, |
8700 | | nullptr, |
8701 | | { nullptr, nullptr }, |
8702 | | prototypes::id::WebGPUBindGroupLayout, |
8703 | | constructors::id::WebGPUBindGroupLayout, |
8704 | | nullptr, |
8705 | | &DefaultXrayExpandoObjectClass |
8706 | | } }; |
8707 | | |
8708 | | void |
8709 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
8710 | 0 | { |
8711 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
8712 | 0 | if (!parentProto) { |
8713 | 0 | return; |
8714 | 0 | } |
8715 | 0 | |
8716 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
8717 | 0 | if (!constructorProto) { |
8718 | 0 | return; |
8719 | 0 | } |
8720 | 0 | |
8721 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPUBindGroupLayout); |
8722 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUBindGroupLayout); |
8723 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
8724 | 0 | &sPrototypeClass.mBase, protoCache, |
8725 | 0 | nullptr, |
8726 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
8727 | 0 | interfaceCache, |
8728 | 0 | nullptr, |
8729 | 0 | nullptr, |
8730 | 0 | "WebGPUBindGroupLayout", aDefineOnGlobal, |
8731 | 0 | nullptr, |
8732 | 0 | false); |
8733 | 0 | } |
8734 | | |
8735 | | JSObject* |
8736 | | GetConstructorObject(JSContext* aCx) |
8737 | 0 | { |
8738 | 0 | return GetConstructorObjectHandle(aCx); |
8739 | 0 | } |
8740 | | |
8741 | | } // namespace WebGPUBindGroupLayout_Binding |
8742 | | |
8743 | | |
8744 | | |
8745 | | namespace WebGPUBindingType_Binding { |
8746 | | |
8747 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
8748 | | #if defined(__clang__) |
8749 | | #pragma clang diagnostic push |
8750 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
8751 | | #endif |
8752 | | static const ConstantSpec sConstants_specs[] = { |
8753 | | { "UNIFORM_BUFFER", JS::NumberValue(0U) }, |
8754 | | { "SAMPLER", JS::NumberValue(1U) }, |
8755 | | { "SAMPLED_TEXTURE", JS::NumberValue(2U) }, |
8756 | | { "STORAGE_BUFFER", JS::NumberValue(3U) }, |
8757 | | { 0, JS::UndefinedValue() } |
8758 | | }; |
8759 | | #if defined(__clang__) |
8760 | | #pragma clang diagnostic pop |
8761 | | #endif |
8762 | | |
8763 | | |
8764 | | static const Prefable<const ConstantSpec> sConstants[] = { |
8765 | | { nullptr, &sConstants_specs[0] }, |
8766 | | { nullptr, nullptr } |
8767 | | }; |
8768 | | |
8769 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
8770 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
8771 | | static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
8772 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
8773 | | |
8774 | | |
8775 | | static uint16_t sNativeProperties_sortedPropertyIndices[4]; |
8776 | | static PropertyInfo sNativeProperties_propertyInfos[4]; |
8777 | | |
8778 | | static const NativePropertiesN<1> sNativeProperties = { |
8779 | | false, 0, |
8780 | | false, 0, |
8781 | | false, 0, |
8782 | | false, 0, |
8783 | | false, 0, |
8784 | | false, 0, |
8785 | | true, 0 /* sConstants */, |
8786 | | -1, |
8787 | | 4, |
8788 | | sNativeProperties_sortedPropertyIndices, |
8789 | | { |
8790 | | { sConstants, &sNativeProperties_propertyInfos[0] } |
8791 | | } |
8792 | | }; |
8793 | | static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
8794 | | "We have a property info count that is oversized"); |
8795 | | |
8796 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
8797 | | { |
8798 | | "Function", |
8799 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
8800 | | &sBoringInterfaceObjectClassClassOps, |
8801 | | JS_NULL_CLASS_SPEC, |
8802 | | JS_NULL_CLASS_EXT, |
8803 | | &sInterfaceObjectClassObjectOps |
8804 | | }, |
8805 | | eInterface, |
8806 | | false, |
8807 | | prototypes::id::_ID_Count, |
8808 | | 0, |
8809 | | sNativePropertyHooks, |
8810 | | "function WebGPUBindingType() {\n [native code]\n}", |
8811 | | JS::GetRealmFunctionPrototype |
8812 | | }; |
8813 | | |
8814 | | bool |
8815 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
8816 | 0 | { |
8817 | 0 | static bool sPrefValue; |
8818 | 0 | static bool sPrefCacheSetUp = false; |
8819 | 0 | if (!sPrefCacheSetUp) { |
8820 | 0 | sPrefCacheSetUp = true; |
8821 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
8822 | 0 | } |
8823 | 0 |
|
8824 | 0 | return sPrefValue; |
8825 | 0 | } |
8826 | | |
8827 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
8828 | | nullptr, |
8829 | | nullptr, |
8830 | | nullptr, |
8831 | | { sNativeProperties.Upcast(), nullptr }, |
8832 | | prototypes::id::_ID_Count, |
8833 | | constructors::id::WebGPUBindingType, |
8834 | | nullptr, |
8835 | | &DefaultXrayExpandoObjectClass |
8836 | | } }; |
8837 | | |
8838 | | void |
8839 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
8840 | 0 | { |
8841 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
8842 | 0 | if (!constructorProto) { |
8843 | 0 | return; |
8844 | 0 | } |
8845 | 0 | |
8846 | 0 | static bool sIdsInited = false; |
8847 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
8848 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
8849 | 0 | return; |
8850 | 0 | } |
8851 | 0 | sIdsInited = true; |
8852 | 0 | } |
8853 | 0 |
|
8854 | 0 | JS::Heap<JSObject*>* protoCache = nullptr; |
8855 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUBindingType); |
8856 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, nullptr, |
8857 | 0 | nullptr, protoCache, |
8858 | 0 | nullptr, |
8859 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
8860 | 0 | interfaceCache, |
8861 | 0 | sNativeProperties.Upcast(), |
8862 | 0 | nullptr, |
8863 | 0 | "WebGPUBindingType", aDefineOnGlobal, |
8864 | 0 | nullptr, |
8865 | 0 | false); |
8866 | 0 | } |
8867 | | |
8868 | | JSObject* |
8869 | | GetConstructorObject(JSContext* aCx) |
8870 | 0 | { |
8871 | 0 | return GetConstructorObjectHandle(aCx); |
8872 | 0 | } |
8873 | | |
8874 | | } // namespace WebGPUBindingType_Binding |
8875 | | |
8876 | | |
8877 | | |
8878 | | namespace WebGPUBlendFactor_Binding { |
8879 | | |
8880 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
8881 | | #if defined(__clang__) |
8882 | | #pragma clang diagnostic push |
8883 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
8884 | | #endif |
8885 | | static const ConstantSpec sConstants_specs[] = { |
8886 | | { "ZERO", JS::NumberValue(0U) }, |
8887 | | { "ONE", JS::NumberValue(1U) }, |
8888 | | { "SRC_COLOR", JS::NumberValue(2U) }, |
8889 | | { "ONE_MINUS_SRC_COLOR", JS::NumberValue(3U) }, |
8890 | | { "SRC_ALPHA", JS::NumberValue(4U) }, |
8891 | | { "ONE_MINUS_SRC_ALPHA", JS::NumberValue(5U) }, |
8892 | | { "DST_COLOR", JS::NumberValue(6U) }, |
8893 | | { "ONE_MINUS_DST_COLOR", JS::NumberValue(7U) }, |
8894 | | { "DST_ALPHA", JS::NumberValue(8U) }, |
8895 | | { "ONE_MINUS_DST_ALPHA", JS::NumberValue(9U) }, |
8896 | | { "SRC_ALPHA_SATURATED", JS::NumberValue(10U) }, |
8897 | | { "BLEND_COLOR", JS::NumberValue(11U) }, |
8898 | | { "ONE_MINUS_BLEND_COLOR", JS::NumberValue(12U) }, |
8899 | | { 0, JS::UndefinedValue() } |
8900 | | }; |
8901 | | #if defined(__clang__) |
8902 | | #pragma clang diagnostic pop |
8903 | | #endif |
8904 | | |
8905 | | |
8906 | | static const Prefable<const ConstantSpec> sConstants[] = { |
8907 | | { nullptr, &sConstants_specs[0] }, |
8908 | | { nullptr, nullptr } |
8909 | | }; |
8910 | | |
8911 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
8912 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
8913 | | static_assert(13 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
8914 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
8915 | | |
8916 | | |
8917 | | static uint16_t sNativeProperties_sortedPropertyIndices[13]; |
8918 | | static PropertyInfo sNativeProperties_propertyInfos[13]; |
8919 | | |
8920 | | static const NativePropertiesN<1> sNativeProperties = { |
8921 | | false, 0, |
8922 | | false, 0, |
8923 | | false, 0, |
8924 | | false, 0, |
8925 | | false, 0, |
8926 | | false, 0, |
8927 | | true, 0 /* sConstants */, |
8928 | | -1, |
8929 | | 13, |
8930 | | sNativeProperties_sortedPropertyIndices, |
8931 | | { |
8932 | | { sConstants, &sNativeProperties_propertyInfos[0] } |
8933 | | } |
8934 | | }; |
8935 | | static_assert(13 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
8936 | | "We have a property info count that is oversized"); |
8937 | | |
8938 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
8939 | | { |
8940 | | "Function", |
8941 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
8942 | | &sBoringInterfaceObjectClassClassOps, |
8943 | | JS_NULL_CLASS_SPEC, |
8944 | | JS_NULL_CLASS_EXT, |
8945 | | &sInterfaceObjectClassObjectOps |
8946 | | }, |
8947 | | eInterface, |
8948 | | false, |
8949 | | prototypes::id::_ID_Count, |
8950 | | 0, |
8951 | | sNativePropertyHooks, |
8952 | | "function WebGPUBlendFactor() {\n [native code]\n}", |
8953 | | JS::GetRealmFunctionPrototype |
8954 | | }; |
8955 | | |
8956 | | bool |
8957 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
8958 | 0 | { |
8959 | 0 | static bool sPrefValue; |
8960 | 0 | static bool sPrefCacheSetUp = false; |
8961 | 0 | if (!sPrefCacheSetUp) { |
8962 | 0 | sPrefCacheSetUp = true; |
8963 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
8964 | 0 | } |
8965 | 0 |
|
8966 | 0 | return sPrefValue; |
8967 | 0 | } |
8968 | | |
8969 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
8970 | | nullptr, |
8971 | | nullptr, |
8972 | | nullptr, |
8973 | | { sNativeProperties.Upcast(), nullptr }, |
8974 | | prototypes::id::_ID_Count, |
8975 | | constructors::id::WebGPUBlendFactor, |
8976 | | nullptr, |
8977 | | &DefaultXrayExpandoObjectClass |
8978 | | } }; |
8979 | | |
8980 | | void |
8981 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
8982 | 0 | { |
8983 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
8984 | 0 | if (!constructorProto) { |
8985 | 0 | return; |
8986 | 0 | } |
8987 | 0 | |
8988 | 0 | static bool sIdsInited = false; |
8989 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
8990 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
8991 | 0 | return; |
8992 | 0 | } |
8993 | 0 | sIdsInited = true; |
8994 | 0 | } |
8995 | 0 |
|
8996 | 0 | JS::Heap<JSObject*>* protoCache = nullptr; |
8997 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUBlendFactor); |
8998 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, nullptr, |
8999 | 0 | nullptr, protoCache, |
9000 | 0 | nullptr, |
9001 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
9002 | 0 | interfaceCache, |
9003 | 0 | sNativeProperties.Upcast(), |
9004 | 0 | nullptr, |
9005 | 0 | "WebGPUBlendFactor", aDefineOnGlobal, |
9006 | 0 | nullptr, |
9007 | 0 | false); |
9008 | 0 | } |
9009 | | |
9010 | | JSObject* |
9011 | | GetConstructorObject(JSContext* aCx) |
9012 | 0 | { |
9013 | 0 | return GetConstructorObjectHandle(aCx); |
9014 | 0 | } |
9015 | | |
9016 | | } // namespace WebGPUBlendFactor_Binding |
9017 | | |
9018 | | |
9019 | | |
9020 | | namespace WebGPUBlendOperation_Binding { |
9021 | | |
9022 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
9023 | | #if defined(__clang__) |
9024 | | #pragma clang diagnostic push |
9025 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
9026 | | #endif |
9027 | | static const ConstantSpec sConstants_specs[] = { |
9028 | | { "ADD", JS::NumberValue(0U) }, |
9029 | | { "SUBTRACT", JS::NumberValue(1U) }, |
9030 | | { "REVERSE_SUBTRACT", JS::NumberValue(2U) }, |
9031 | | { "MIN", JS::NumberValue(3U) }, |
9032 | | { "MAX", JS::NumberValue(4U) }, |
9033 | | { 0, JS::UndefinedValue() } |
9034 | | }; |
9035 | | #if defined(__clang__) |
9036 | | #pragma clang diagnostic pop |
9037 | | #endif |
9038 | | |
9039 | | |
9040 | | static const Prefable<const ConstantSpec> sConstants[] = { |
9041 | | { nullptr, &sConstants_specs[0] }, |
9042 | | { nullptr, nullptr } |
9043 | | }; |
9044 | | |
9045 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
9046 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
9047 | | static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
9048 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
9049 | | |
9050 | | |
9051 | | static uint16_t sNativeProperties_sortedPropertyIndices[5]; |
9052 | | static PropertyInfo sNativeProperties_propertyInfos[5]; |
9053 | | |
9054 | | static const NativePropertiesN<1> sNativeProperties = { |
9055 | | false, 0, |
9056 | | false, 0, |
9057 | | false, 0, |
9058 | | false, 0, |
9059 | | false, 0, |
9060 | | false, 0, |
9061 | | true, 0 /* sConstants */, |
9062 | | -1, |
9063 | | 5, |
9064 | | sNativeProperties_sortedPropertyIndices, |
9065 | | { |
9066 | | { sConstants, &sNativeProperties_propertyInfos[0] } |
9067 | | } |
9068 | | }; |
9069 | | static_assert(5 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
9070 | | "We have a property info count that is oversized"); |
9071 | | |
9072 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
9073 | | { |
9074 | | "Function", |
9075 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
9076 | | &sBoringInterfaceObjectClassClassOps, |
9077 | | JS_NULL_CLASS_SPEC, |
9078 | | JS_NULL_CLASS_EXT, |
9079 | | &sInterfaceObjectClassObjectOps |
9080 | | }, |
9081 | | eInterface, |
9082 | | false, |
9083 | | prototypes::id::_ID_Count, |
9084 | | 0, |
9085 | | sNativePropertyHooks, |
9086 | | "function WebGPUBlendOperation() {\n [native code]\n}", |
9087 | | JS::GetRealmFunctionPrototype |
9088 | | }; |
9089 | | |
9090 | | bool |
9091 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
9092 | 0 | { |
9093 | 0 | static bool sPrefValue; |
9094 | 0 | static bool sPrefCacheSetUp = false; |
9095 | 0 | if (!sPrefCacheSetUp) { |
9096 | 0 | sPrefCacheSetUp = true; |
9097 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
9098 | 0 | } |
9099 | 0 |
|
9100 | 0 | return sPrefValue; |
9101 | 0 | } |
9102 | | |
9103 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
9104 | | nullptr, |
9105 | | nullptr, |
9106 | | nullptr, |
9107 | | { sNativeProperties.Upcast(), nullptr }, |
9108 | | prototypes::id::_ID_Count, |
9109 | | constructors::id::WebGPUBlendOperation, |
9110 | | nullptr, |
9111 | | &DefaultXrayExpandoObjectClass |
9112 | | } }; |
9113 | | |
9114 | | void |
9115 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
9116 | 0 | { |
9117 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
9118 | 0 | if (!constructorProto) { |
9119 | 0 | return; |
9120 | 0 | } |
9121 | 0 | |
9122 | 0 | static bool sIdsInited = false; |
9123 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
9124 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
9125 | 0 | return; |
9126 | 0 | } |
9127 | 0 | sIdsInited = true; |
9128 | 0 | } |
9129 | 0 |
|
9130 | 0 | JS::Heap<JSObject*>* protoCache = nullptr; |
9131 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUBlendOperation); |
9132 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, nullptr, |
9133 | 0 | nullptr, protoCache, |
9134 | 0 | nullptr, |
9135 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
9136 | 0 | interfaceCache, |
9137 | 0 | sNativeProperties.Upcast(), |
9138 | 0 | nullptr, |
9139 | 0 | "WebGPUBlendOperation", aDefineOnGlobal, |
9140 | 0 | nullptr, |
9141 | 0 | false); |
9142 | 0 | } |
9143 | | |
9144 | | JSObject* |
9145 | | GetConstructorObject(JSContext* aCx) |
9146 | 0 | { |
9147 | 0 | return GetConstructorObjectHandle(aCx); |
9148 | 0 | } |
9149 | | |
9150 | | } // namespace WebGPUBlendOperation_Binding |
9151 | | |
9152 | | |
9153 | | |
9154 | | namespace WebGPUBlendState_Binding { |
9155 | | |
9156 | | static bool |
9157 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
9158 | 0 | { |
9159 | 0 | mozilla::webgpu::BlendState* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::BlendState>(obj); |
9160 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
9161 | 0 | // obviously can't preserve if we're not initialized. |
9162 | 0 | if (self && self->GetWrapperPreserveColor()) { |
9163 | 0 | PreserveWrapper(self); |
9164 | 0 | } |
9165 | 0 | return true; |
9166 | 0 | } |
9167 | | |
9168 | | static void |
9169 | | _finalize(js::FreeOp* fop, JSObject* obj) |
9170 | 0 | { |
9171 | 0 | mozilla::webgpu::BlendState* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::BlendState>(obj); |
9172 | 0 | if (self) { |
9173 | 0 | ClearWrapper(self, self, obj); |
9174 | 0 | AddForDeferredFinalization<mozilla::webgpu::BlendState>(self); |
9175 | 0 | } |
9176 | 0 | } |
9177 | | |
9178 | | static size_t |
9179 | | _objectMoved(JSObject* obj, JSObject* old) |
9180 | 0 | { |
9181 | 0 | mozilla::webgpu::BlendState* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::BlendState>(obj); |
9182 | 0 | if (self) { |
9183 | 0 | UpdateWrapper(self, self, obj, old); |
9184 | 0 | } |
9185 | 0 |
|
9186 | 0 | return 0; |
9187 | 0 | } |
9188 | | |
9189 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
9190 | | { |
9191 | | "Function", |
9192 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
9193 | | &sBoringInterfaceObjectClassClassOps, |
9194 | | JS_NULL_CLASS_SPEC, |
9195 | | JS_NULL_CLASS_EXT, |
9196 | | &sInterfaceObjectClassObjectOps |
9197 | | }, |
9198 | | eInterface, |
9199 | | true, |
9200 | | prototypes::id::WebGPUBlendState, |
9201 | | PrototypeTraits<prototypes::id::WebGPUBlendState>::Depth, |
9202 | | sNativePropertyHooks, |
9203 | | "function WebGPUBlendState() {\n [native code]\n}", |
9204 | | JS::GetRealmFunctionPrototype |
9205 | | }; |
9206 | | |
9207 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
9208 | | { |
9209 | | "WebGPUBlendStatePrototype", |
9210 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
9211 | | JS_NULL_CLASS_OPS, |
9212 | | JS_NULL_CLASS_SPEC, |
9213 | | JS_NULL_CLASS_EXT, |
9214 | | JS_NULL_OBJECT_OPS |
9215 | | }, |
9216 | | eInterfacePrototype, |
9217 | | false, |
9218 | | prototypes::id::WebGPUBlendState, |
9219 | | PrototypeTraits<prototypes::id::WebGPUBlendState>::Depth, |
9220 | | sNativePropertyHooks, |
9221 | | "[object WebGPUBlendStatePrototype]", |
9222 | | JS::GetRealmObjectPrototype |
9223 | | }; |
9224 | | |
9225 | | bool |
9226 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
9227 | 0 | { |
9228 | 0 | static bool sPrefValue; |
9229 | 0 | static bool sPrefCacheSetUp = false; |
9230 | 0 | if (!sPrefCacheSetUp) { |
9231 | 0 | sPrefCacheSetUp = true; |
9232 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
9233 | 0 | } |
9234 | 0 |
|
9235 | 0 | return sPrefValue; |
9236 | 0 | } |
9237 | | |
9238 | | static const js::ClassOps sClassOps = { |
9239 | | _addProperty, /* addProperty */ |
9240 | | nullptr, /* delProperty */ |
9241 | | nullptr, /* enumerate */ |
9242 | | nullptr, /* newEnumerate */ |
9243 | | nullptr, /* resolve */ |
9244 | | nullptr, /* mayResolve */ |
9245 | | _finalize, /* finalize */ |
9246 | | nullptr, /* call */ |
9247 | | nullptr, /* hasInstance */ |
9248 | | nullptr, /* construct */ |
9249 | | nullptr, /* trace */ |
9250 | | }; |
9251 | | |
9252 | | static const js::ClassExtension sClassExtension = { |
9253 | | nullptr, /* weakmapKeyDelegateOp */ |
9254 | | _objectMoved /* objectMovedOp */ |
9255 | | }; |
9256 | | |
9257 | | static const DOMJSClass sClass = { |
9258 | | { "WebGPUBlendState", |
9259 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
9260 | | &sClassOps, |
9261 | | JS_NULL_CLASS_SPEC, |
9262 | | &sClassExtension, |
9263 | | JS_NULL_OBJECT_OPS |
9264 | | }, |
9265 | | { prototypes::id::WebGPUBlendState, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
9266 | | IsBaseOf<nsISupports, mozilla::webgpu::BlendState >::value, |
9267 | | sNativePropertyHooks, |
9268 | | FindAssociatedGlobalForNative<mozilla::webgpu::BlendState>::Get, |
9269 | | GetProtoObjectHandle, |
9270 | | GetCCParticipant<mozilla::webgpu::BlendState>::Get() |
9271 | | }; |
9272 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
9273 | | "Must have the right minimal number of reserved slots."); |
9274 | | static_assert(1 >= 1, |
9275 | | "Must have enough reserved slots."); |
9276 | | |
9277 | | const JSClass* |
9278 | | GetJSClass() |
9279 | 0 | { |
9280 | 0 | return sClass.ToJSClass(); |
9281 | 0 | } |
9282 | | |
9283 | | bool |
9284 | | Wrap(JSContext* aCx, mozilla::webgpu::BlendState* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
9285 | 0 | { |
9286 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::BlendState>::value, |
9287 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
9288 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::BlendState*>(aObject) == |
9289 | 0 | reinterpret_cast<mozilla::webgpu::BlendState*>(aObject), |
9290 | 0 | "Multiple inheritance for mozilla::webgpu::BlendState is broken."); |
9291 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
9292 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
9293 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
9294 | 0 | "You should probably not be using Wrap() directly; use " |
9295 | 0 | "GetOrCreateDOMReflector instead"); |
9296 | 0 |
|
9297 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
9298 | 0 | "nsISupports must be on our primary inheritance chain"); |
9299 | 0 |
|
9300 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
9301 | 0 | if (!global) { |
9302 | 0 | return false; |
9303 | 0 | } |
9304 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
9305 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
9306 | 0 |
|
9307 | 0 | // That might have ended up wrapping us already, due to the wonders |
9308 | 0 | // of XBL. Check for that, and bail out as needed. |
9309 | 0 | aReflector.set(aCache->GetWrapper()); |
9310 | 0 | if (aReflector) { |
9311 | | #ifdef DEBUG |
9312 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
9313 | | #endif // DEBUG |
9314 | | return true; |
9315 | 0 | } |
9316 | 0 |
|
9317 | 0 | JSAutoRealm ar(aCx, global); |
9318 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
9319 | 0 | if (!canonicalProto) { |
9320 | 0 | return false; |
9321 | 0 | } |
9322 | 0 | JS::Rooted<JSObject*> proto(aCx); |
9323 | 0 | if (aGivenProto) { |
9324 | 0 | proto = aGivenProto; |
9325 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
9326 | 0 | // coming in, we changed compartments to that of "parent" so may need |
9327 | 0 | // to wrap the proto here. |
9328 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
9329 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
9330 | 0 | return false; |
9331 | 0 | } |
9332 | 0 | } |
9333 | 0 | } else { |
9334 | 0 | proto = canonicalProto; |
9335 | 0 | } |
9336 | 0 |
|
9337 | 0 | BindingJSObjectCreator<mozilla::webgpu::BlendState> creator(aCx); |
9338 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
9339 | 0 | if (!aReflector) { |
9340 | 0 | return false; |
9341 | 0 | } |
9342 | 0 | |
9343 | 0 | aCache->SetWrapper(aReflector); |
9344 | 0 | creator.InitializationSucceeded(); |
9345 | 0 |
|
9346 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
9347 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
9348 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
9349 | 0 | // otherwise we won't be able to properly recreate it later, since |
9350 | 0 | // we won't know what proto to use. Note that we don't check |
9351 | 0 | // aGivenProto here, since it's entirely possible (and even |
9352 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
9353 | 0 | // same as canonicalProto. |
9354 | 0 | if (proto != canonicalProto) { |
9355 | 0 | PreserveWrapper(aObject); |
9356 | 0 | } |
9357 | 0 |
|
9358 | 0 | return true; |
9359 | 0 | } |
9360 | | |
9361 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
9362 | | nullptr, |
9363 | | nullptr, |
9364 | | nullptr, |
9365 | | { nullptr, nullptr }, |
9366 | | prototypes::id::WebGPUBlendState, |
9367 | | constructors::id::WebGPUBlendState, |
9368 | | nullptr, |
9369 | | &DefaultXrayExpandoObjectClass |
9370 | | } }; |
9371 | | |
9372 | | void |
9373 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
9374 | 0 | { |
9375 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
9376 | 0 | if (!parentProto) { |
9377 | 0 | return; |
9378 | 0 | } |
9379 | 0 | |
9380 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
9381 | 0 | if (!constructorProto) { |
9382 | 0 | return; |
9383 | 0 | } |
9384 | 0 | |
9385 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPUBlendState); |
9386 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUBlendState); |
9387 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
9388 | 0 | &sPrototypeClass.mBase, protoCache, |
9389 | 0 | nullptr, |
9390 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
9391 | 0 | interfaceCache, |
9392 | 0 | nullptr, |
9393 | 0 | nullptr, |
9394 | 0 | "WebGPUBlendState", aDefineOnGlobal, |
9395 | 0 | nullptr, |
9396 | 0 | false); |
9397 | 0 | } |
9398 | | |
9399 | | JSObject* |
9400 | | GetConstructorObject(JSContext* aCx) |
9401 | 0 | { |
9402 | 0 | return GetConstructorObjectHandle(aCx); |
9403 | 0 | } |
9404 | | |
9405 | | } // namespace WebGPUBlendState_Binding |
9406 | | |
9407 | | |
9408 | | |
9409 | | namespace WebGPUBuffer_Binding { |
9410 | | |
9411 | | MOZ_CAN_RUN_SCRIPT static bool |
9412 | | get_mapping(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Buffer* self, JSJitGetterCallArgs args) |
9413 | 0 | { |
9414 | 0 | AUTO_PROFILER_LABEL_FAST("get WebGPUBuffer.mapping", DOM, cx); |
9415 | 0 |
|
9416 | 0 | JS::Rooted<JSObject*> result(cx); |
9417 | 0 | self->GetMapping(cx, &result); |
9418 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
9419 | 0 | if (result) { |
9420 | 0 | JS::ExposeObjectToActiveJS(result); |
9421 | 0 | } |
9422 | 0 | args.rval().setObjectOrNull(result); |
9423 | 0 | if (!MaybeWrapNonDOMObjectOrNullValue(cx, args.rval())) { |
9424 | 0 | return false; |
9425 | 0 | } |
9426 | 0 | return true; |
9427 | 0 | } |
9428 | | |
9429 | | static const JSJitInfo mapping_getterinfo = { |
9430 | | { (JSJitGetterOp)get_mapping }, |
9431 | | { prototypes::id::WebGPUBuffer }, |
9432 | | { PrototypeTraits<prototypes::id::WebGPUBuffer>::Depth }, |
9433 | | JSJitInfo::Getter, |
9434 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
9435 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
9436 | | false, /* isInfallible. False in setters. */ |
9437 | | false, /* isMovable. Not relevant for setters. */ |
9438 | | false, /* isEliminatable. Not relevant for setters. */ |
9439 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
9440 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
9441 | | false, /* isTypedMethod. Only relevant for methods. */ |
9442 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
9443 | | }; |
9444 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
9445 | | static_assert(0 < 1, "There is no slot for us"); |
9446 | | |
9447 | | MOZ_CAN_RUN_SCRIPT static bool |
9448 | | unmap(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Buffer* self, const JSJitMethodCallArgs& args) |
9449 | 0 | { |
9450 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUBuffer.unmap", DOM, cx); |
9451 | 0 |
|
9452 | 0 | self->Unmap(); |
9453 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
9454 | 0 | args.rval().setUndefined(); |
9455 | 0 | return true; |
9456 | 0 | } |
9457 | | |
9458 | | static const JSJitInfo unmap_methodinfo = { |
9459 | | { (JSJitGetterOp)unmap }, |
9460 | | { prototypes::id::WebGPUBuffer }, |
9461 | | { PrototypeTraits<prototypes::id::WebGPUBuffer>::Depth }, |
9462 | | JSJitInfo::Method, |
9463 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
9464 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
9465 | | true, /* isInfallible. False in setters. */ |
9466 | | false, /* isMovable. Not relevant for setters. */ |
9467 | | false, /* isEliminatable. Not relevant for setters. */ |
9468 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
9469 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
9470 | | false, /* isTypedMethod. Only relevant for methods. */ |
9471 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
9472 | | }; |
9473 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
9474 | | static_assert(0 < 1, "There is no slot for us"); |
9475 | | |
9476 | | static bool |
9477 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
9478 | 0 | { |
9479 | 0 | mozilla::webgpu::Buffer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Buffer>(obj); |
9480 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
9481 | 0 | // obviously can't preserve if we're not initialized. |
9482 | 0 | if (self && self->GetWrapperPreserveColor()) { |
9483 | 0 | PreserveWrapper(self); |
9484 | 0 | } |
9485 | 0 | return true; |
9486 | 0 | } |
9487 | | |
9488 | | static void |
9489 | | _finalize(js::FreeOp* fop, JSObject* obj) |
9490 | 0 | { |
9491 | 0 | mozilla::webgpu::Buffer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Buffer>(obj); |
9492 | 0 | if (self) { |
9493 | 0 | ClearWrapper(self, self, obj); |
9494 | 0 | AddForDeferredFinalization<mozilla::webgpu::Buffer>(self); |
9495 | 0 | } |
9496 | 0 | } |
9497 | | |
9498 | | static size_t |
9499 | | _objectMoved(JSObject* obj, JSObject* old) |
9500 | 0 | { |
9501 | 0 | mozilla::webgpu::Buffer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Buffer>(obj); |
9502 | 0 | if (self) { |
9503 | 0 | UpdateWrapper(self, self, obj, old); |
9504 | 0 | } |
9505 | 0 |
|
9506 | 0 | return 0; |
9507 | 0 | } |
9508 | | |
9509 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
9510 | | #if defined(__clang__) |
9511 | | #pragma clang diagnostic push |
9512 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
9513 | | #endif |
9514 | | static const JSFunctionSpec sMethods_specs[] = { |
9515 | | JS_FNSPEC("unmap", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&unmap_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
9516 | | JS_FS_END |
9517 | | }; |
9518 | | #if defined(__clang__) |
9519 | | #pragma clang diagnostic pop |
9520 | | #endif |
9521 | | |
9522 | | |
9523 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
9524 | | { nullptr, &sMethods_specs[0] }, |
9525 | | { nullptr, nullptr } |
9526 | | }; |
9527 | | |
9528 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
9529 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
9530 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
9531 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
9532 | | |
9533 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
9534 | | #if defined(__clang__) |
9535 | | #pragma clang diagnostic push |
9536 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
9537 | | #endif |
9538 | | static const JSPropertySpec sAttributes_specs[] = { |
9539 | | { "mapping", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &mapping_getterinfo, nullptr, nullptr }, |
9540 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
9541 | | }; |
9542 | | #if defined(__clang__) |
9543 | | #pragma clang diagnostic pop |
9544 | | #endif |
9545 | | |
9546 | | |
9547 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
9548 | | { nullptr, &sAttributes_specs[0] }, |
9549 | | { nullptr, nullptr } |
9550 | | }; |
9551 | | |
9552 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
9553 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
9554 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
9555 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
9556 | | |
9557 | | |
9558 | | static uint16_t sNativeProperties_sortedPropertyIndices[2]; |
9559 | | static PropertyInfo sNativeProperties_propertyInfos[2]; |
9560 | | |
9561 | | static const NativePropertiesN<2> sNativeProperties = { |
9562 | | false, 0, |
9563 | | false, 0, |
9564 | | true, 0 /* sMethods */, |
9565 | | true, 1 /* sAttributes */, |
9566 | | false, 0, |
9567 | | false, 0, |
9568 | | false, 0, |
9569 | | -1, |
9570 | | 2, |
9571 | | sNativeProperties_sortedPropertyIndices, |
9572 | | { |
9573 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
9574 | | { sAttributes, &sNativeProperties_propertyInfos[1] } |
9575 | | } |
9576 | | }; |
9577 | | static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
9578 | | "We have a property info count that is oversized"); |
9579 | | |
9580 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
9581 | | { |
9582 | | "Function", |
9583 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
9584 | | &sBoringInterfaceObjectClassClassOps, |
9585 | | JS_NULL_CLASS_SPEC, |
9586 | | JS_NULL_CLASS_EXT, |
9587 | | &sInterfaceObjectClassObjectOps |
9588 | | }, |
9589 | | eInterface, |
9590 | | true, |
9591 | | prototypes::id::WebGPUBuffer, |
9592 | | PrototypeTraits<prototypes::id::WebGPUBuffer>::Depth, |
9593 | | sNativePropertyHooks, |
9594 | | "function WebGPUBuffer() {\n [native code]\n}", |
9595 | | JS::GetRealmFunctionPrototype |
9596 | | }; |
9597 | | |
9598 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
9599 | | { |
9600 | | "WebGPUBufferPrototype", |
9601 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
9602 | | JS_NULL_CLASS_OPS, |
9603 | | JS_NULL_CLASS_SPEC, |
9604 | | JS_NULL_CLASS_EXT, |
9605 | | JS_NULL_OBJECT_OPS |
9606 | | }, |
9607 | | eInterfacePrototype, |
9608 | | false, |
9609 | | prototypes::id::WebGPUBuffer, |
9610 | | PrototypeTraits<prototypes::id::WebGPUBuffer>::Depth, |
9611 | | sNativePropertyHooks, |
9612 | | "[object WebGPUBufferPrototype]", |
9613 | | JS::GetRealmObjectPrototype |
9614 | | }; |
9615 | | |
9616 | | bool |
9617 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
9618 | 0 | { |
9619 | 0 | static bool sPrefValue; |
9620 | 0 | static bool sPrefCacheSetUp = false; |
9621 | 0 | if (!sPrefCacheSetUp) { |
9622 | 0 | sPrefCacheSetUp = true; |
9623 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
9624 | 0 | } |
9625 | 0 |
|
9626 | 0 | return sPrefValue; |
9627 | 0 | } |
9628 | | |
9629 | | static const js::ClassOps sClassOps = { |
9630 | | _addProperty, /* addProperty */ |
9631 | | nullptr, /* delProperty */ |
9632 | | nullptr, /* enumerate */ |
9633 | | nullptr, /* newEnumerate */ |
9634 | | nullptr, /* resolve */ |
9635 | | nullptr, /* mayResolve */ |
9636 | | _finalize, /* finalize */ |
9637 | | nullptr, /* call */ |
9638 | | nullptr, /* hasInstance */ |
9639 | | nullptr, /* construct */ |
9640 | | nullptr, /* trace */ |
9641 | | }; |
9642 | | |
9643 | | static const js::ClassExtension sClassExtension = { |
9644 | | nullptr, /* weakmapKeyDelegateOp */ |
9645 | | _objectMoved /* objectMovedOp */ |
9646 | | }; |
9647 | | |
9648 | | static const DOMJSClass sClass = { |
9649 | | { "WebGPUBuffer", |
9650 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
9651 | | &sClassOps, |
9652 | | JS_NULL_CLASS_SPEC, |
9653 | | &sClassExtension, |
9654 | | JS_NULL_OBJECT_OPS |
9655 | | }, |
9656 | | { prototypes::id::WebGPUBuffer, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
9657 | | IsBaseOf<nsISupports, mozilla::webgpu::Buffer >::value, |
9658 | | sNativePropertyHooks, |
9659 | | FindAssociatedGlobalForNative<mozilla::webgpu::Buffer>::Get, |
9660 | | GetProtoObjectHandle, |
9661 | | GetCCParticipant<mozilla::webgpu::Buffer>::Get() |
9662 | | }; |
9663 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
9664 | | "Must have the right minimal number of reserved slots."); |
9665 | | static_assert(1 >= 1, |
9666 | | "Must have enough reserved slots."); |
9667 | | |
9668 | | const JSClass* |
9669 | | GetJSClass() |
9670 | 0 | { |
9671 | 0 | return sClass.ToJSClass(); |
9672 | 0 | } |
9673 | | |
9674 | | bool |
9675 | | Wrap(JSContext* aCx, mozilla::webgpu::Buffer* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
9676 | 0 | { |
9677 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::Buffer>::value, |
9678 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
9679 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::Buffer*>(aObject) == |
9680 | 0 | reinterpret_cast<mozilla::webgpu::Buffer*>(aObject), |
9681 | 0 | "Multiple inheritance for mozilla::webgpu::Buffer is broken."); |
9682 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
9683 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
9684 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
9685 | 0 | "You should probably not be using Wrap() directly; use " |
9686 | 0 | "GetOrCreateDOMReflector instead"); |
9687 | 0 |
|
9688 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
9689 | 0 | "nsISupports must be on our primary inheritance chain"); |
9690 | 0 |
|
9691 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
9692 | 0 | if (!global) { |
9693 | 0 | return false; |
9694 | 0 | } |
9695 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
9696 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
9697 | 0 |
|
9698 | 0 | // That might have ended up wrapping us already, due to the wonders |
9699 | 0 | // of XBL. Check for that, and bail out as needed. |
9700 | 0 | aReflector.set(aCache->GetWrapper()); |
9701 | 0 | if (aReflector) { |
9702 | | #ifdef DEBUG |
9703 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
9704 | | #endif // DEBUG |
9705 | | return true; |
9706 | 0 | } |
9707 | 0 |
|
9708 | 0 | JSAutoRealm ar(aCx, global); |
9709 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
9710 | 0 | if (!canonicalProto) { |
9711 | 0 | return false; |
9712 | 0 | } |
9713 | 0 | JS::Rooted<JSObject*> proto(aCx); |
9714 | 0 | if (aGivenProto) { |
9715 | 0 | proto = aGivenProto; |
9716 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
9717 | 0 | // coming in, we changed compartments to that of "parent" so may need |
9718 | 0 | // to wrap the proto here. |
9719 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
9720 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
9721 | 0 | return false; |
9722 | 0 | } |
9723 | 0 | } |
9724 | 0 | } else { |
9725 | 0 | proto = canonicalProto; |
9726 | 0 | } |
9727 | 0 |
|
9728 | 0 | BindingJSObjectCreator<mozilla::webgpu::Buffer> creator(aCx); |
9729 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
9730 | 0 | if (!aReflector) { |
9731 | 0 | return false; |
9732 | 0 | } |
9733 | 0 | |
9734 | 0 | aCache->SetWrapper(aReflector); |
9735 | 0 | creator.InitializationSucceeded(); |
9736 | 0 |
|
9737 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
9738 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
9739 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
9740 | 0 | // otherwise we won't be able to properly recreate it later, since |
9741 | 0 | // we won't know what proto to use. Note that we don't check |
9742 | 0 | // aGivenProto here, since it's entirely possible (and even |
9743 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
9744 | 0 | // same as canonicalProto. |
9745 | 0 | if (proto != canonicalProto) { |
9746 | 0 | PreserveWrapper(aObject); |
9747 | 0 | } |
9748 | 0 |
|
9749 | 0 | return true; |
9750 | 0 | } |
9751 | | |
9752 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
9753 | | nullptr, |
9754 | | nullptr, |
9755 | | nullptr, |
9756 | | { sNativeProperties.Upcast(), nullptr }, |
9757 | | prototypes::id::WebGPUBuffer, |
9758 | | constructors::id::WebGPUBuffer, |
9759 | | nullptr, |
9760 | | &DefaultXrayExpandoObjectClass |
9761 | | } }; |
9762 | | |
9763 | | void |
9764 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
9765 | 0 | { |
9766 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
9767 | 0 | if (!parentProto) { |
9768 | 0 | return; |
9769 | 0 | } |
9770 | 0 | |
9771 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
9772 | 0 | if (!constructorProto) { |
9773 | 0 | return; |
9774 | 0 | } |
9775 | 0 | |
9776 | 0 | static bool sIdsInited = false; |
9777 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
9778 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
9779 | 0 | return; |
9780 | 0 | } |
9781 | 0 | sIdsInited = true; |
9782 | 0 | } |
9783 | 0 |
|
9784 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPUBuffer); |
9785 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUBuffer); |
9786 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
9787 | 0 | &sPrototypeClass.mBase, protoCache, |
9788 | 0 | nullptr, |
9789 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
9790 | 0 | interfaceCache, |
9791 | 0 | sNativeProperties.Upcast(), |
9792 | 0 | nullptr, |
9793 | 0 | "WebGPUBuffer", aDefineOnGlobal, |
9794 | 0 | nullptr, |
9795 | 0 | false); |
9796 | 0 | } |
9797 | | |
9798 | | JSObject* |
9799 | | GetConstructorObject(JSContext* aCx) |
9800 | 0 | { |
9801 | 0 | return GetConstructorObjectHandle(aCx); |
9802 | 0 | } |
9803 | | |
9804 | | } // namespace WebGPUBuffer_Binding |
9805 | | |
9806 | | |
9807 | | |
9808 | | namespace WebGPUBufferUsage_Binding { |
9809 | | |
9810 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
9811 | | #if defined(__clang__) |
9812 | | #pragma clang diagnostic push |
9813 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
9814 | | #endif |
9815 | | static const ConstantSpec sConstants_specs[] = { |
9816 | | { "NONE", JS::NumberValue(0U) }, |
9817 | | { "MAP_READ", JS::NumberValue(1U) }, |
9818 | | { "MAP_WRITE", JS::NumberValue(2U) }, |
9819 | | { "TRANSFER_SRC", JS::NumberValue(4U) }, |
9820 | | { "TRANSFER_DST", JS::NumberValue(8U) }, |
9821 | | { "INDEX", JS::NumberValue(16U) }, |
9822 | | { "VERTEX", JS::NumberValue(32U) }, |
9823 | | { "UNIFORM", JS::NumberValue(64U) }, |
9824 | | { "STORAGE", JS::NumberValue(128U) }, |
9825 | | { 0, JS::UndefinedValue() } |
9826 | | }; |
9827 | | #if defined(__clang__) |
9828 | | #pragma clang diagnostic pop |
9829 | | #endif |
9830 | | |
9831 | | |
9832 | | static const Prefable<const ConstantSpec> sConstants[] = { |
9833 | | { nullptr, &sConstants_specs[0] }, |
9834 | | { nullptr, nullptr } |
9835 | | }; |
9836 | | |
9837 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
9838 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
9839 | | static_assert(9 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
9840 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
9841 | | |
9842 | | |
9843 | | static uint16_t sNativeProperties_sortedPropertyIndices[9]; |
9844 | | static PropertyInfo sNativeProperties_propertyInfos[9]; |
9845 | | |
9846 | | static const NativePropertiesN<1> sNativeProperties = { |
9847 | | false, 0, |
9848 | | false, 0, |
9849 | | false, 0, |
9850 | | false, 0, |
9851 | | false, 0, |
9852 | | false, 0, |
9853 | | true, 0 /* sConstants */, |
9854 | | -1, |
9855 | | 9, |
9856 | | sNativeProperties_sortedPropertyIndices, |
9857 | | { |
9858 | | { sConstants, &sNativeProperties_propertyInfos[0] } |
9859 | | } |
9860 | | }; |
9861 | | static_assert(9 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
9862 | | "We have a property info count that is oversized"); |
9863 | | |
9864 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
9865 | | { |
9866 | | "Function", |
9867 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
9868 | | &sBoringInterfaceObjectClassClassOps, |
9869 | | JS_NULL_CLASS_SPEC, |
9870 | | JS_NULL_CLASS_EXT, |
9871 | | &sInterfaceObjectClassObjectOps |
9872 | | }, |
9873 | | eInterface, |
9874 | | false, |
9875 | | prototypes::id::_ID_Count, |
9876 | | 0, |
9877 | | sNativePropertyHooks, |
9878 | | "function WebGPUBufferUsage() {\n [native code]\n}", |
9879 | | JS::GetRealmFunctionPrototype |
9880 | | }; |
9881 | | |
9882 | | bool |
9883 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
9884 | 0 | { |
9885 | 0 | static bool sPrefValue; |
9886 | 0 | static bool sPrefCacheSetUp = false; |
9887 | 0 | if (!sPrefCacheSetUp) { |
9888 | 0 | sPrefCacheSetUp = true; |
9889 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
9890 | 0 | } |
9891 | 0 |
|
9892 | 0 | return sPrefValue; |
9893 | 0 | } |
9894 | | |
9895 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
9896 | | nullptr, |
9897 | | nullptr, |
9898 | | nullptr, |
9899 | | { sNativeProperties.Upcast(), nullptr }, |
9900 | | prototypes::id::_ID_Count, |
9901 | | constructors::id::WebGPUBufferUsage, |
9902 | | nullptr, |
9903 | | &DefaultXrayExpandoObjectClass |
9904 | | } }; |
9905 | | |
9906 | | void |
9907 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
9908 | 0 | { |
9909 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
9910 | 0 | if (!constructorProto) { |
9911 | 0 | return; |
9912 | 0 | } |
9913 | 0 | |
9914 | 0 | static bool sIdsInited = false; |
9915 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
9916 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
9917 | 0 | return; |
9918 | 0 | } |
9919 | 0 | sIdsInited = true; |
9920 | 0 | } |
9921 | 0 |
|
9922 | 0 | JS::Heap<JSObject*>* protoCache = nullptr; |
9923 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUBufferUsage); |
9924 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, nullptr, |
9925 | 0 | nullptr, protoCache, |
9926 | 0 | nullptr, |
9927 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
9928 | 0 | interfaceCache, |
9929 | 0 | sNativeProperties.Upcast(), |
9930 | 0 | nullptr, |
9931 | 0 | "WebGPUBufferUsage", aDefineOnGlobal, |
9932 | 0 | nullptr, |
9933 | 0 | false); |
9934 | 0 | } |
9935 | | |
9936 | | JSObject* |
9937 | | GetConstructorObject(JSContext* aCx) |
9938 | 0 | { |
9939 | 0 | return GetConstructorObjectHandle(aCx); |
9940 | 0 | } |
9941 | | |
9942 | | } // namespace WebGPUBufferUsage_Binding |
9943 | | |
9944 | | |
9945 | | |
9946 | | namespace WebGPUColorWriteBits_Binding { |
9947 | | |
9948 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
9949 | | #if defined(__clang__) |
9950 | | #pragma clang diagnostic push |
9951 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
9952 | | #endif |
9953 | | static const ConstantSpec sConstants_specs[] = { |
9954 | | { "NONE", JS::NumberValue(0U) }, |
9955 | | { "RED", JS::NumberValue(1U) }, |
9956 | | { "GREEN", JS::NumberValue(2U) }, |
9957 | | { "BLUE", JS::NumberValue(4U) }, |
9958 | | { "ALPHA", JS::NumberValue(8U) }, |
9959 | | { "ALL", JS::NumberValue(15U) }, |
9960 | | { 0, JS::UndefinedValue() } |
9961 | | }; |
9962 | | #if defined(__clang__) |
9963 | | #pragma clang diagnostic pop |
9964 | | #endif |
9965 | | |
9966 | | |
9967 | | static const Prefable<const ConstantSpec> sConstants[] = { |
9968 | | { nullptr, &sConstants_specs[0] }, |
9969 | | { nullptr, nullptr } |
9970 | | }; |
9971 | | |
9972 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
9973 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
9974 | | static_assert(6 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
9975 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
9976 | | |
9977 | | |
9978 | | static uint16_t sNativeProperties_sortedPropertyIndices[6]; |
9979 | | static PropertyInfo sNativeProperties_propertyInfos[6]; |
9980 | | |
9981 | | static const NativePropertiesN<1> sNativeProperties = { |
9982 | | false, 0, |
9983 | | false, 0, |
9984 | | false, 0, |
9985 | | false, 0, |
9986 | | false, 0, |
9987 | | false, 0, |
9988 | | true, 0 /* sConstants */, |
9989 | | -1, |
9990 | | 6, |
9991 | | sNativeProperties_sortedPropertyIndices, |
9992 | | { |
9993 | | { sConstants, &sNativeProperties_propertyInfos[0] } |
9994 | | } |
9995 | | }; |
9996 | | static_assert(6 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
9997 | | "We have a property info count that is oversized"); |
9998 | | |
9999 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
10000 | | { |
10001 | | "Function", |
10002 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
10003 | | &sBoringInterfaceObjectClassClassOps, |
10004 | | JS_NULL_CLASS_SPEC, |
10005 | | JS_NULL_CLASS_EXT, |
10006 | | &sInterfaceObjectClassObjectOps |
10007 | | }, |
10008 | | eInterface, |
10009 | | false, |
10010 | | prototypes::id::_ID_Count, |
10011 | | 0, |
10012 | | sNativePropertyHooks, |
10013 | | "function WebGPUColorWriteBits() {\n [native code]\n}", |
10014 | | JS::GetRealmFunctionPrototype |
10015 | | }; |
10016 | | |
10017 | | bool |
10018 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
10019 | 0 | { |
10020 | 0 | static bool sPrefValue; |
10021 | 0 | static bool sPrefCacheSetUp = false; |
10022 | 0 | if (!sPrefCacheSetUp) { |
10023 | 0 | sPrefCacheSetUp = true; |
10024 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
10025 | 0 | } |
10026 | 0 |
|
10027 | 0 | return sPrefValue; |
10028 | 0 | } |
10029 | | |
10030 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
10031 | | nullptr, |
10032 | | nullptr, |
10033 | | nullptr, |
10034 | | { sNativeProperties.Upcast(), nullptr }, |
10035 | | prototypes::id::_ID_Count, |
10036 | | constructors::id::WebGPUColorWriteBits, |
10037 | | nullptr, |
10038 | | &DefaultXrayExpandoObjectClass |
10039 | | } }; |
10040 | | |
10041 | | void |
10042 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
10043 | 0 | { |
10044 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
10045 | 0 | if (!constructorProto) { |
10046 | 0 | return; |
10047 | 0 | } |
10048 | 0 | |
10049 | 0 | static bool sIdsInited = false; |
10050 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
10051 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
10052 | 0 | return; |
10053 | 0 | } |
10054 | 0 | sIdsInited = true; |
10055 | 0 | } |
10056 | 0 |
|
10057 | 0 | JS::Heap<JSObject*>* protoCache = nullptr; |
10058 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUColorWriteBits); |
10059 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, nullptr, |
10060 | 0 | nullptr, protoCache, |
10061 | 0 | nullptr, |
10062 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
10063 | 0 | interfaceCache, |
10064 | 0 | sNativeProperties.Upcast(), |
10065 | 0 | nullptr, |
10066 | 0 | "WebGPUColorWriteBits", aDefineOnGlobal, |
10067 | 0 | nullptr, |
10068 | 0 | false); |
10069 | 0 | } |
10070 | | |
10071 | | JSObject* |
10072 | | GetConstructorObject(JSContext* aCx) |
10073 | 0 | { |
10074 | 0 | return GetConstructorObjectHandle(aCx); |
10075 | 0 | } |
10076 | | |
10077 | | } // namespace WebGPUColorWriteBits_Binding |
10078 | | |
10079 | | |
10080 | | |
10081 | | namespace WebGPUCommandBuffer_Binding { |
10082 | | |
10083 | | static bool |
10084 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
10085 | 0 | { |
10086 | 0 | mozilla::webgpu::CommandBuffer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::CommandBuffer>(obj); |
10087 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
10088 | 0 | // obviously can't preserve if we're not initialized. |
10089 | 0 | if (self && self->GetWrapperPreserveColor()) { |
10090 | 0 | PreserveWrapper(self); |
10091 | 0 | } |
10092 | 0 | return true; |
10093 | 0 | } |
10094 | | |
10095 | | static void |
10096 | | _finalize(js::FreeOp* fop, JSObject* obj) |
10097 | 0 | { |
10098 | 0 | mozilla::webgpu::CommandBuffer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::CommandBuffer>(obj); |
10099 | 0 | if (self) { |
10100 | 0 | ClearWrapper(self, self, obj); |
10101 | 0 | AddForDeferredFinalization<mozilla::webgpu::CommandBuffer>(self); |
10102 | 0 | } |
10103 | 0 | } |
10104 | | |
10105 | | static size_t |
10106 | | _objectMoved(JSObject* obj, JSObject* old) |
10107 | 0 | { |
10108 | 0 | mozilla::webgpu::CommandBuffer* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::CommandBuffer>(obj); |
10109 | 0 | if (self) { |
10110 | 0 | UpdateWrapper(self, self, obj, old); |
10111 | 0 | } |
10112 | 0 |
|
10113 | 0 | return 0; |
10114 | 0 | } |
10115 | | |
10116 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
10117 | | { |
10118 | | "Function", |
10119 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
10120 | | &sBoringInterfaceObjectClassClassOps, |
10121 | | JS_NULL_CLASS_SPEC, |
10122 | | JS_NULL_CLASS_EXT, |
10123 | | &sInterfaceObjectClassObjectOps |
10124 | | }, |
10125 | | eInterface, |
10126 | | true, |
10127 | | prototypes::id::WebGPUCommandBuffer, |
10128 | | PrototypeTraits<prototypes::id::WebGPUCommandBuffer>::Depth, |
10129 | | sNativePropertyHooks, |
10130 | | "function WebGPUCommandBuffer() {\n [native code]\n}", |
10131 | | JS::GetRealmFunctionPrototype |
10132 | | }; |
10133 | | |
10134 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
10135 | | { |
10136 | | "WebGPUCommandBufferPrototype", |
10137 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
10138 | | JS_NULL_CLASS_OPS, |
10139 | | JS_NULL_CLASS_SPEC, |
10140 | | JS_NULL_CLASS_EXT, |
10141 | | JS_NULL_OBJECT_OPS |
10142 | | }, |
10143 | | eInterfacePrototype, |
10144 | | false, |
10145 | | prototypes::id::WebGPUCommandBuffer, |
10146 | | PrototypeTraits<prototypes::id::WebGPUCommandBuffer>::Depth, |
10147 | | sNativePropertyHooks, |
10148 | | "[object WebGPUCommandBufferPrototype]", |
10149 | | JS::GetRealmObjectPrototype |
10150 | | }; |
10151 | | |
10152 | | bool |
10153 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
10154 | 0 | { |
10155 | 0 | static bool sPrefValue; |
10156 | 0 | static bool sPrefCacheSetUp = false; |
10157 | 0 | if (!sPrefCacheSetUp) { |
10158 | 0 | sPrefCacheSetUp = true; |
10159 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
10160 | 0 | } |
10161 | 0 |
|
10162 | 0 | return sPrefValue; |
10163 | 0 | } |
10164 | | |
10165 | | static const js::ClassOps sClassOps = { |
10166 | | _addProperty, /* addProperty */ |
10167 | | nullptr, /* delProperty */ |
10168 | | nullptr, /* enumerate */ |
10169 | | nullptr, /* newEnumerate */ |
10170 | | nullptr, /* resolve */ |
10171 | | nullptr, /* mayResolve */ |
10172 | | _finalize, /* finalize */ |
10173 | | nullptr, /* call */ |
10174 | | nullptr, /* hasInstance */ |
10175 | | nullptr, /* construct */ |
10176 | | nullptr, /* trace */ |
10177 | | }; |
10178 | | |
10179 | | static const js::ClassExtension sClassExtension = { |
10180 | | nullptr, /* weakmapKeyDelegateOp */ |
10181 | | _objectMoved /* objectMovedOp */ |
10182 | | }; |
10183 | | |
10184 | | static const DOMJSClass sClass = { |
10185 | | { "WebGPUCommandBuffer", |
10186 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
10187 | | &sClassOps, |
10188 | | JS_NULL_CLASS_SPEC, |
10189 | | &sClassExtension, |
10190 | | JS_NULL_OBJECT_OPS |
10191 | | }, |
10192 | | { prototypes::id::WebGPUCommandBuffer, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
10193 | | IsBaseOf<nsISupports, mozilla::webgpu::CommandBuffer >::value, |
10194 | | sNativePropertyHooks, |
10195 | | FindAssociatedGlobalForNative<mozilla::webgpu::CommandBuffer>::Get, |
10196 | | GetProtoObjectHandle, |
10197 | | GetCCParticipant<mozilla::webgpu::CommandBuffer>::Get() |
10198 | | }; |
10199 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
10200 | | "Must have the right minimal number of reserved slots."); |
10201 | | static_assert(1 >= 1, |
10202 | | "Must have enough reserved slots."); |
10203 | | |
10204 | | const JSClass* |
10205 | | GetJSClass() |
10206 | 0 | { |
10207 | 0 | return sClass.ToJSClass(); |
10208 | 0 | } |
10209 | | |
10210 | | bool |
10211 | | Wrap(JSContext* aCx, mozilla::webgpu::CommandBuffer* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
10212 | 0 | { |
10213 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::CommandBuffer>::value, |
10214 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
10215 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::CommandBuffer*>(aObject) == |
10216 | 0 | reinterpret_cast<mozilla::webgpu::CommandBuffer*>(aObject), |
10217 | 0 | "Multiple inheritance for mozilla::webgpu::CommandBuffer is broken."); |
10218 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
10219 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
10220 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
10221 | 0 | "You should probably not be using Wrap() directly; use " |
10222 | 0 | "GetOrCreateDOMReflector instead"); |
10223 | 0 |
|
10224 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
10225 | 0 | "nsISupports must be on our primary inheritance chain"); |
10226 | 0 |
|
10227 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
10228 | 0 | if (!global) { |
10229 | 0 | return false; |
10230 | 0 | } |
10231 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
10232 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
10233 | 0 |
|
10234 | 0 | // That might have ended up wrapping us already, due to the wonders |
10235 | 0 | // of XBL. Check for that, and bail out as needed. |
10236 | 0 | aReflector.set(aCache->GetWrapper()); |
10237 | 0 | if (aReflector) { |
10238 | | #ifdef DEBUG |
10239 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
10240 | | #endif // DEBUG |
10241 | | return true; |
10242 | 0 | } |
10243 | 0 |
|
10244 | 0 | JSAutoRealm ar(aCx, global); |
10245 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
10246 | 0 | if (!canonicalProto) { |
10247 | 0 | return false; |
10248 | 0 | } |
10249 | 0 | JS::Rooted<JSObject*> proto(aCx); |
10250 | 0 | if (aGivenProto) { |
10251 | 0 | proto = aGivenProto; |
10252 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
10253 | 0 | // coming in, we changed compartments to that of "parent" so may need |
10254 | 0 | // to wrap the proto here. |
10255 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
10256 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
10257 | 0 | return false; |
10258 | 0 | } |
10259 | 0 | } |
10260 | 0 | } else { |
10261 | 0 | proto = canonicalProto; |
10262 | 0 | } |
10263 | 0 |
|
10264 | 0 | BindingJSObjectCreator<mozilla::webgpu::CommandBuffer> creator(aCx); |
10265 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
10266 | 0 | if (!aReflector) { |
10267 | 0 | return false; |
10268 | 0 | } |
10269 | 0 | |
10270 | 0 | aCache->SetWrapper(aReflector); |
10271 | 0 | creator.InitializationSucceeded(); |
10272 | 0 |
|
10273 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
10274 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
10275 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
10276 | 0 | // otherwise we won't be able to properly recreate it later, since |
10277 | 0 | // we won't know what proto to use. Note that we don't check |
10278 | 0 | // aGivenProto here, since it's entirely possible (and even |
10279 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
10280 | 0 | // same as canonicalProto. |
10281 | 0 | if (proto != canonicalProto) { |
10282 | 0 | PreserveWrapper(aObject); |
10283 | 0 | } |
10284 | 0 |
|
10285 | 0 | return true; |
10286 | 0 | } |
10287 | | |
10288 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
10289 | | nullptr, |
10290 | | nullptr, |
10291 | | nullptr, |
10292 | | { nullptr, nullptr }, |
10293 | | prototypes::id::WebGPUCommandBuffer, |
10294 | | constructors::id::WebGPUCommandBuffer, |
10295 | | nullptr, |
10296 | | &DefaultXrayExpandoObjectClass |
10297 | | } }; |
10298 | | |
10299 | | void |
10300 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
10301 | 0 | { |
10302 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
10303 | 0 | if (!parentProto) { |
10304 | 0 | return; |
10305 | 0 | } |
10306 | 0 | |
10307 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
10308 | 0 | if (!constructorProto) { |
10309 | 0 | return; |
10310 | 0 | } |
10311 | 0 | |
10312 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPUCommandBuffer); |
10313 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUCommandBuffer); |
10314 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
10315 | 0 | &sPrototypeClass.mBase, protoCache, |
10316 | 0 | nullptr, |
10317 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
10318 | 0 | interfaceCache, |
10319 | 0 | nullptr, |
10320 | 0 | nullptr, |
10321 | 0 | "WebGPUCommandBuffer", aDefineOnGlobal, |
10322 | 0 | nullptr, |
10323 | 0 | false); |
10324 | 0 | } |
10325 | | |
10326 | | JSObject* |
10327 | | GetConstructorObject(JSContext* aCx) |
10328 | 0 | { |
10329 | 0 | return GetConstructorObjectHandle(aCx); |
10330 | 0 | } |
10331 | | |
10332 | | } // namespace WebGPUCommandBuffer_Binding |
10333 | | |
10334 | | |
10335 | | |
10336 | | namespace WebGPUCommandEncoder_Binding { |
10337 | | |
10338 | | MOZ_CAN_RUN_SCRIPT static bool |
10339 | | finishEncoding(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::CommandEncoder* self, const JSJitMethodCallArgs& args) |
10340 | 0 | { |
10341 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUCommandEncoder.finishEncoding", DOM, cx); |
10342 | 0 |
|
10343 | 0 | auto result(StrongOrRawPtr<mozilla::webgpu::CommandBuffer>(self->FinishEncoding())); |
10344 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
10345 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
10346 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
10347 | 0 | return false; |
10348 | 0 | } |
10349 | 0 | return true; |
10350 | 0 | } |
10351 | | |
10352 | | static const JSJitInfo finishEncoding_methodinfo = { |
10353 | | { (JSJitGetterOp)finishEncoding }, |
10354 | | { prototypes::id::WebGPUCommandEncoder }, |
10355 | | { PrototypeTraits<prototypes::id::WebGPUCommandEncoder>::Depth }, |
10356 | | JSJitInfo::Method, |
10357 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
10358 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
10359 | | false, /* isInfallible. False in setters. */ |
10360 | | false, /* isMovable. Not relevant for setters. */ |
10361 | | false, /* isEliminatable. Not relevant for setters. */ |
10362 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
10363 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
10364 | | false, /* isTypedMethod. Only relevant for methods. */ |
10365 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
10366 | | }; |
10367 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
10368 | | static_assert(0 < 1, "There is no slot for us"); |
10369 | | |
10370 | | MOZ_CAN_RUN_SCRIPT static bool |
10371 | | copyBufferToBuffer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::CommandEncoder* self, const JSJitMethodCallArgs& args) |
10372 | 0 | { |
10373 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUCommandEncoder.copyBufferToBuffer", DOM, cx); |
10374 | 0 |
|
10375 | 0 | if (MOZ_UNLIKELY(args.length() < 5)) { |
10376 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebGPUCommandEncoder.copyBufferToBuffer"); |
10377 | 0 | } |
10378 | 0 | NonNull<mozilla::webgpu::Buffer> arg0; |
10379 | 0 | if (args[0].isObject()) { |
10380 | 0 | { |
10381 | 0 | nsresult rv = UnwrapObject<prototypes::id::WebGPUBuffer, mozilla::webgpu::Buffer>(args[0], arg0); |
10382 | 0 | if (NS_FAILED(rv)) { |
10383 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of WebGPUCommandEncoder.copyBufferToBuffer", "WebGPUBuffer"); |
10384 | 0 | return false; |
10385 | 0 | } |
10386 | 0 | } |
10387 | 0 | } else { |
10388 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of WebGPUCommandEncoder.copyBufferToBuffer"); |
10389 | 0 | return false; |
10390 | 0 | } |
10391 | 0 | uint32_t arg1; |
10392 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) { |
10393 | 0 | return false; |
10394 | 0 | } |
10395 | 0 | NonNull<mozilla::webgpu::Buffer> arg2; |
10396 | 0 | if (args[2].isObject()) { |
10397 | 0 | { |
10398 | 0 | nsresult rv = UnwrapObject<prototypes::id::WebGPUBuffer, mozilla::webgpu::Buffer>(args[2], arg2); |
10399 | 0 | if (NS_FAILED(rv)) { |
10400 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 3 of WebGPUCommandEncoder.copyBufferToBuffer", "WebGPUBuffer"); |
10401 | 0 | return false; |
10402 | 0 | } |
10403 | 0 | } |
10404 | 0 | } else { |
10405 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of WebGPUCommandEncoder.copyBufferToBuffer"); |
10406 | 0 | return false; |
10407 | 0 | } |
10408 | 0 | uint32_t arg3; |
10409 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[3], &arg3)) { |
10410 | 0 | return false; |
10411 | 0 | } |
10412 | 0 | uint32_t arg4; |
10413 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[4], &arg4)) { |
10414 | 0 | return false; |
10415 | 0 | } |
10416 | 0 | self->CopyBufferToBuffer(MOZ_KnownLive(NonNullHelper(arg0)), arg1, MOZ_KnownLive(NonNullHelper(arg2)), arg3, arg4); |
10417 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
10418 | 0 | args.rval().setUndefined(); |
10419 | 0 | return true; |
10420 | 0 | } |
10421 | | |
10422 | | static const JSJitInfo copyBufferToBuffer_methodinfo = { |
10423 | | { (JSJitGetterOp)copyBufferToBuffer }, |
10424 | | { prototypes::id::WebGPUCommandEncoder }, |
10425 | | { PrototypeTraits<prototypes::id::WebGPUCommandEncoder>::Depth }, |
10426 | | JSJitInfo::Method, |
10427 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
10428 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
10429 | | false, /* isInfallible. False in setters. */ |
10430 | | false, /* isMovable. Not relevant for setters. */ |
10431 | | false, /* isEliminatable. Not relevant for setters. */ |
10432 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
10433 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
10434 | | false, /* isTypedMethod. Only relevant for methods. */ |
10435 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
10436 | | }; |
10437 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
10438 | | static_assert(0 < 1, "There is no slot for us"); |
10439 | | |
10440 | | MOZ_CAN_RUN_SCRIPT static bool |
10441 | | copyBufferToTexture(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::CommandEncoder* self, const JSJitMethodCallArgs& args) |
10442 | 0 | { |
10443 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUCommandEncoder.copyBufferToTexture", DOM, cx); |
10444 | 0 |
|
10445 | 0 | self->CopyBufferToTexture(); |
10446 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
10447 | 0 | args.rval().setUndefined(); |
10448 | 0 | return true; |
10449 | 0 | } |
10450 | | |
10451 | | static const JSJitInfo copyBufferToTexture_methodinfo = { |
10452 | | { (JSJitGetterOp)copyBufferToTexture }, |
10453 | | { prototypes::id::WebGPUCommandEncoder }, |
10454 | | { PrototypeTraits<prototypes::id::WebGPUCommandEncoder>::Depth }, |
10455 | | JSJitInfo::Method, |
10456 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
10457 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
10458 | | true, /* isInfallible. False in setters. */ |
10459 | | false, /* isMovable. Not relevant for setters. */ |
10460 | | false, /* isEliminatable. Not relevant for setters. */ |
10461 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
10462 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
10463 | | false, /* isTypedMethod. Only relevant for methods. */ |
10464 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
10465 | | }; |
10466 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
10467 | | static_assert(0 < 1, "There is no slot for us"); |
10468 | | |
10469 | | MOZ_CAN_RUN_SCRIPT static bool |
10470 | | copyTextureToBuffer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::CommandEncoder* self, const JSJitMethodCallArgs& args) |
10471 | 0 | { |
10472 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUCommandEncoder.copyTextureToBuffer", DOM, cx); |
10473 | 0 |
|
10474 | 0 | self->CopyTextureToBuffer(); |
10475 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
10476 | 0 | args.rval().setUndefined(); |
10477 | 0 | return true; |
10478 | 0 | } |
10479 | | |
10480 | | static const JSJitInfo copyTextureToBuffer_methodinfo = { |
10481 | | { (JSJitGetterOp)copyTextureToBuffer }, |
10482 | | { prototypes::id::WebGPUCommandEncoder }, |
10483 | | { PrototypeTraits<prototypes::id::WebGPUCommandEncoder>::Depth }, |
10484 | | JSJitInfo::Method, |
10485 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
10486 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
10487 | | true, /* isInfallible. False in setters. */ |
10488 | | false, /* isMovable. Not relevant for setters. */ |
10489 | | false, /* isEliminatable. Not relevant for setters. */ |
10490 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
10491 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
10492 | | false, /* isTypedMethod. Only relevant for methods. */ |
10493 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
10494 | | }; |
10495 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
10496 | | static_assert(0 < 1, "There is no slot for us"); |
10497 | | |
10498 | | MOZ_CAN_RUN_SCRIPT static bool |
10499 | | copyTextureToTexture(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::CommandEncoder* self, const JSJitMethodCallArgs& args) |
10500 | 0 | { |
10501 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUCommandEncoder.copyTextureToTexture", DOM, cx); |
10502 | 0 |
|
10503 | 0 | self->CopyTextureToTexture(); |
10504 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
10505 | 0 | args.rval().setUndefined(); |
10506 | 0 | return true; |
10507 | 0 | } |
10508 | | |
10509 | | static const JSJitInfo copyTextureToTexture_methodinfo = { |
10510 | | { (JSJitGetterOp)copyTextureToTexture }, |
10511 | | { prototypes::id::WebGPUCommandEncoder }, |
10512 | | { PrototypeTraits<prototypes::id::WebGPUCommandEncoder>::Depth }, |
10513 | | JSJitInfo::Method, |
10514 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
10515 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
10516 | | true, /* isInfallible. False in setters. */ |
10517 | | false, /* isMovable. Not relevant for setters. */ |
10518 | | false, /* isEliminatable. Not relevant for setters. */ |
10519 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
10520 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
10521 | | false, /* isTypedMethod. Only relevant for methods. */ |
10522 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
10523 | | }; |
10524 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
10525 | | static_assert(0 < 1, "There is no slot for us"); |
10526 | | |
10527 | | MOZ_CAN_RUN_SCRIPT static bool |
10528 | | blit(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::CommandEncoder* self, const JSJitMethodCallArgs& args) |
10529 | 0 | { |
10530 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUCommandEncoder.blit", DOM, cx); |
10531 | 0 |
|
10532 | 0 | self->Blit(); |
10533 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
10534 | 0 | args.rval().setUndefined(); |
10535 | 0 | return true; |
10536 | 0 | } |
10537 | | |
10538 | | static const JSJitInfo blit_methodinfo = { |
10539 | | { (JSJitGetterOp)blit }, |
10540 | | { prototypes::id::WebGPUCommandEncoder }, |
10541 | | { PrototypeTraits<prototypes::id::WebGPUCommandEncoder>::Depth }, |
10542 | | JSJitInfo::Method, |
10543 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
10544 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
10545 | | true, /* isInfallible. False in setters. */ |
10546 | | false, /* isMovable. Not relevant for setters. */ |
10547 | | false, /* isEliminatable. Not relevant for setters. */ |
10548 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
10549 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
10550 | | false, /* isTypedMethod. Only relevant for methods. */ |
10551 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
10552 | | }; |
10553 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
10554 | | static_assert(0 < 1, "There is no slot for us"); |
10555 | | |
10556 | | MOZ_CAN_RUN_SCRIPT static bool |
10557 | | transitionBuffer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::CommandEncoder* self, const JSJitMethodCallArgs& args) |
10558 | 0 | { |
10559 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUCommandEncoder.transitionBuffer", DOM, cx); |
10560 | 0 |
|
10561 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
10562 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebGPUCommandEncoder.transitionBuffer"); |
10563 | 0 | } |
10564 | 0 | NonNull<mozilla::webgpu::Buffer> arg0; |
10565 | 0 | if (args[0].isObject()) { |
10566 | 0 | { |
10567 | 0 | nsresult rv = UnwrapObject<prototypes::id::WebGPUBuffer, mozilla::webgpu::Buffer>(args[0], arg0); |
10568 | 0 | if (NS_FAILED(rv)) { |
10569 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of WebGPUCommandEncoder.transitionBuffer", "WebGPUBuffer"); |
10570 | 0 | return false; |
10571 | 0 | } |
10572 | 0 | } |
10573 | 0 | } else { |
10574 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of WebGPUCommandEncoder.transitionBuffer"); |
10575 | 0 | return false; |
10576 | 0 | } |
10577 | 0 | uint32_t arg1; |
10578 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) { |
10579 | 0 | return false; |
10580 | 0 | } |
10581 | 0 | self->TransitionBuffer(MOZ_KnownLive(NonNullHelper(arg0)), arg1); |
10582 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
10583 | 0 | args.rval().setUndefined(); |
10584 | 0 | return true; |
10585 | 0 | } |
10586 | | |
10587 | | static const JSJitInfo transitionBuffer_methodinfo = { |
10588 | | { (JSJitGetterOp)transitionBuffer }, |
10589 | | { prototypes::id::WebGPUCommandEncoder }, |
10590 | | { PrototypeTraits<prototypes::id::WebGPUCommandEncoder>::Depth }, |
10591 | | JSJitInfo::Method, |
10592 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
10593 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
10594 | | false, /* isInfallible. False in setters. */ |
10595 | | false, /* isMovable. Not relevant for setters. */ |
10596 | | false, /* isEliminatable. Not relevant for setters. */ |
10597 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
10598 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
10599 | | false, /* isTypedMethod. Only relevant for methods. */ |
10600 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
10601 | | }; |
10602 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
10603 | | static_assert(0 < 1, "There is no slot for us"); |
10604 | | |
10605 | | MOZ_CAN_RUN_SCRIPT static bool |
10606 | | setPushConstants(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::CommandEncoder* self, const JSJitMethodCallArgs& args) |
10607 | 0 | { |
10608 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUCommandEncoder.setPushConstants", DOM, cx); |
10609 | 0 |
|
10610 | 0 | if (MOZ_UNLIKELY(args.length() < 4)) { |
10611 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebGPUCommandEncoder.setPushConstants"); |
10612 | 0 | } |
10613 | 0 | uint32_t arg0; |
10614 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) { |
10615 | 0 | return false; |
10616 | 0 | } |
10617 | 0 | uint32_t arg1; |
10618 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) { |
10619 | 0 | return false; |
10620 | 0 | } |
10621 | 0 | uint32_t arg2; |
10622 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[2], &arg2)) { |
10623 | 0 | return false; |
10624 | 0 | } |
10625 | 0 | RootedSpiderMonkeyInterface<ArrayBuffer> arg3(cx); |
10626 | 0 | if (args[3].isObject()) { |
10627 | 0 | if (!arg3.Init(&args[3].toObject())) { |
10628 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 4 of WebGPUCommandEncoder.setPushConstants", "ArrayBuffer"); |
10629 | 0 | return false; |
10630 | 0 | } |
10631 | 0 | } else { |
10632 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 4 of WebGPUCommandEncoder.setPushConstants"); |
10633 | 0 | return false; |
10634 | 0 | } |
10635 | 0 | self->SetPushConstants(arg0, arg1, arg2, Constify(arg3)); |
10636 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
10637 | 0 | args.rval().setUndefined(); |
10638 | 0 | return true; |
10639 | 0 | } |
10640 | | |
10641 | | static const JSJitInfo setPushConstants_methodinfo = { |
10642 | | { (JSJitGetterOp)setPushConstants }, |
10643 | | { prototypes::id::WebGPUCommandEncoder }, |
10644 | | { PrototypeTraits<prototypes::id::WebGPUCommandEncoder>::Depth }, |
10645 | | JSJitInfo::Method, |
10646 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
10647 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
10648 | | false, /* isInfallible. False in setters. */ |
10649 | | false, /* isMovable. Not relevant for setters. */ |
10650 | | false, /* isEliminatable. Not relevant for setters. */ |
10651 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
10652 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
10653 | | false, /* isTypedMethod. Only relevant for methods. */ |
10654 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
10655 | | }; |
10656 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
10657 | | static_assert(0 < 1, "There is no slot for us"); |
10658 | | |
10659 | | MOZ_CAN_RUN_SCRIPT static bool |
10660 | | setBindGroup(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::CommandEncoder* self, const JSJitMethodCallArgs& args) |
10661 | 0 | { |
10662 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUCommandEncoder.setBindGroup", DOM, cx); |
10663 | 0 |
|
10664 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
10665 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebGPUCommandEncoder.setBindGroup"); |
10666 | 0 | } |
10667 | 0 | uint32_t arg0; |
10668 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) { |
10669 | 0 | return false; |
10670 | 0 | } |
10671 | 0 | NonNull<mozilla::webgpu::BindGroup> arg1; |
10672 | 0 | if (args[1].isObject()) { |
10673 | 0 | { |
10674 | 0 | nsresult rv = UnwrapObject<prototypes::id::WebGPUBindGroup, mozilla::webgpu::BindGroup>(args[1], arg1); |
10675 | 0 | if (NS_FAILED(rv)) { |
10676 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 2 of WebGPUCommandEncoder.setBindGroup", "WebGPUBindGroup"); |
10677 | 0 | return false; |
10678 | 0 | } |
10679 | 0 | } |
10680 | 0 | } else { |
10681 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of WebGPUCommandEncoder.setBindGroup"); |
10682 | 0 | return false; |
10683 | 0 | } |
10684 | 0 | self->SetBindGroup(arg0, MOZ_KnownLive(NonNullHelper(arg1))); |
10685 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
10686 | 0 | args.rval().setUndefined(); |
10687 | 0 | return true; |
10688 | 0 | } |
10689 | | |
10690 | | static const JSJitInfo setBindGroup_methodinfo = { |
10691 | | { (JSJitGetterOp)setBindGroup }, |
10692 | | { prototypes::id::WebGPUCommandEncoder }, |
10693 | | { PrototypeTraits<prototypes::id::WebGPUCommandEncoder>::Depth }, |
10694 | | JSJitInfo::Method, |
10695 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
10696 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
10697 | | false, /* isInfallible. False in setters. */ |
10698 | | false, /* isMovable. Not relevant for setters. */ |
10699 | | false, /* isEliminatable. Not relevant for setters. */ |
10700 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
10701 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
10702 | | false, /* isTypedMethod. Only relevant for methods. */ |
10703 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
10704 | | }; |
10705 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
10706 | | static_assert(0 < 1, "There is no slot for us"); |
10707 | | |
10708 | | MOZ_CAN_RUN_SCRIPT static bool |
10709 | | setPipeline(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::CommandEncoder* self, const JSJitMethodCallArgs& args) |
10710 | 0 | { |
10711 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUCommandEncoder.setPipeline", DOM, cx); |
10712 | 0 |
|
10713 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
10714 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebGPUCommandEncoder.setPipeline"); |
10715 | 0 | } |
10716 | 0 | WebGPUComputePipelineOrWebGPURenderPipeline arg0; |
10717 | 0 | WebGPUComputePipelineOrWebGPURenderPipelineArgument arg0_holder(arg0); |
10718 | 0 | { |
10719 | 0 | bool done = false, failed = false, tryNext; |
10720 | 0 | if (args[0].isObject()) { |
10721 | 0 | done = (failed = !arg0_holder.TrySetToWebGPUComputePipeline(cx, args[0], tryNext, false)) || !tryNext || |
10722 | 0 | (failed = !arg0_holder.TrySetToWebGPURenderPipeline(cx, args[0], tryNext, false)) || !tryNext; |
10723 | 0 |
|
10724 | 0 | } |
10725 | 0 | if (failed) { |
10726 | 0 | return false; |
10727 | 0 | } |
10728 | 0 | if (!done) { |
10729 | 0 | ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of WebGPUCommandEncoder.setPipeline", "WebGPUComputePipeline, WebGPURenderPipeline"); |
10730 | 0 | return false; |
10731 | 0 | } |
10732 | 0 | } |
10733 | 0 | self->SetPipeline(Constify(arg0)); |
10734 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
10735 | 0 | args.rval().setUndefined(); |
10736 | 0 | return true; |
10737 | 0 | } |
10738 | | |
10739 | | static const JSJitInfo setPipeline_methodinfo = { |
10740 | | { (JSJitGetterOp)setPipeline }, |
10741 | | { prototypes::id::WebGPUCommandEncoder }, |
10742 | | { PrototypeTraits<prototypes::id::WebGPUCommandEncoder>::Depth }, |
10743 | | JSJitInfo::Method, |
10744 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
10745 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
10746 | | false, /* isInfallible. False in setters. */ |
10747 | | false, /* isMovable. Not relevant for setters. */ |
10748 | | false, /* isEliminatable. Not relevant for setters. */ |
10749 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
10750 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
10751 | | false, /* isTypedMethod. Only relevant for methods. */ |
10752 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
10753 | | }; |
10754 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
10755 | | static_assert(0 < 1, "There is no slot for us"); |
10756 | | |
10757 | | MOZ_CAN_RUN_SCRIPT static bool |
10758 | | beginComputePass(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::CommandEncoder* self, const JSJitMethodCallArgs& args) |
10759 | 0 | { |
10760 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUCommandEncoder.beginComputePass", DOM, cx); |
10761 | 0 |
|
10762 | 0 | self->BeginComputePass(); |
10763 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
10764 | 0 | args.rval().setUndefined(); |
10765 | 0 | return true; |
10766 | 0 | } |
10767 | | |
10768 | | static const JSJitInfo beginComputePass_methodinfo = { |
10769 | | { (JSJitGetterOp)beginComputePass }, |
10770 | | { prototypes::id::WebGPUCommandEncoder }, |
10771 | | { PrototypeTraits<prototypes::id::WebGPUCommandEncoder>::Depth }, |
10772 | | JSJitInfo::Method, |
10773 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
10774 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
10775 | | true, /* isInfallible. False in setters. */ |
10776 | | false, /* isMovable. Not relevant for setters. */ |
10777 | | false, /* isEliminatable. Not relevant for setters. */ |
10778 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
10779 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
10780 | | false, /* isTypedMethod. Only relevant for methods. */ |
10781 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
10782 | | }; |
10783 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
10784 | | static_assert(0 < 1, "There is no slot for us"); |
10785 | | |
10786 | | MOZ_CAN_RUN_SCRIPT static bool |
10787 | | endComputePass(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::CommandEncoder* self, const JSJitMethodCallArgs& args) |
10788 | 0 | { |
10789 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUCommandEncoder.endComputePass", DOM, cx); |
10790 | 0 |
|
10791 | 0 | self->EndComputePass(); |
10792 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
10793 | 0 | args.rval().setUndefined(); |
10794 | 0 | return true; |
10795 | 0 | } |
10796 | | |
10797 | | static const JSJitInfo endComputePass_methodinfo = { |
10798 | | { (JSJitGetterOp)endComputePass }, |
10799 | | { prototypes::id::WebGPUCommandEncoder }, |
10800 | | { PrototypeTraits<prototypes::id::WebGPUCommandEncoder>::Depth }, |
10801 | | JSJitInfo::Method, |
10802 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
10803 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
10804 | | true, /* isInfallible. False in setters. */ |
10805 | | false, /* isMovable. Not relevant for setters. */ |
10806 | | false, /* isEliminatable. Not relevant for setters. */ |
10807 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
10808 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
10809 | | false, /* isTypedMethod. Only relevant for methods. */ |
10810 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
10811 | | }; |
10812 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
10813 | | static_assert(0 < 1, "There is no slot for us"); |
10814 | | |
10815 | | MOZ_CAN_RUN_SCRIPT static bool |
10816 | | dispatch(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::CommandEncoder* self, const JSJitMethodCallArgs& args) |
10817 | 0 | { |
10818 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUCommandEncoder.dispatch", DOM, cx); |
10819 | 0 |
|
10820 | 0 | if (MOZ_UNLIKELY(args.length() < 3)) { |
10821 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebGPUCommandEncoder.dispatch"); |
10822 | 0 | } |
10823 | 0 | uint32_t arg0; |
10824 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) { |
10825 | 0 | return false; |
10826 | 0 | } |
10827 | 0 | uint32_t arg1; |
10828 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) { |
10829 | 0 | return false; |
10830 | 0 | } |
10831 | 0 | uint32_t arg2; |
10832 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[2], &arg2)) { |
10833 | 0 | return false; |
10834 | 0 | } |
10835 | 0 | self->Dispatch(arg0, arg1, arg2); |
10836 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
10837 | 0 | args.rval().setUndefined(); |
10838 | 0 | return true; |
10839 | 0 | } |
10840 | | |
10841 | | static const JSJitInfo dispatch_methodinfo = { |
10842 | | { (JSJitGetterOp)dispatch }, |
10843 | | { prototypes::id::WebGPUCommandEncoder }, |
10844 | | { PrototypeTraits<prototypes::id::WebGPUCommandEncoder>::Depth }, |
10845 | | JSJitInfo::Method, |
10846 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
10847 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
10848 | | false, /* isInfallible. False in setters. */ |
10849 | | false, /* isMovable. Not relevant for setters. */ |
10850 | | false, /* isEliminatable. Not relevant for setters. */ |
10851 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
10852 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
10853 | | false, /* isTypedMethod. Only relevant for methods. */ |
10854 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
10855 | | }; |
10856 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
10857 | | static_assert(0 < 1, "There is no slot for us"); |
10858 | | |
10859 | | MOZ_CAN_RUN_SCRIPT static bool |
10860 | | beginRenderPass(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::CommandEncoder* self, const JSJitMethodCallArgs& args) |
10861 | 0 | { |
10862 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUCommandEncoder.beginRenderPass", DOM, cx); |
10863 | 0 |
|
10864 | 0 | binding_detail::FastWebGPURenderPassDescriptor arg0; |
10865 | 0 | if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of WebGPUCommandEncoder.beginRenderPass", false)) { |
10866 | 0 | return false; |
10867 | 0 | } |
10868 | 0 | self->BeginRenderPass(Constify(arg0)); |
10869 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
10870 | 0 | args.rval().setUndefined(); |
10871 | 0 | return true; |
10872 | 0 | } |
10873 | | |
10874 | | static const JSJitInfo beginRenderPass_methodinfo = { |
10875 | | { (JSJitGetterOp)beginRenderPass }, |
10876 | | { prototypes::id::WebGPUCommandEncoder }, |
10877 | | { PrototypeTraits<prototypes::id::WebGPUCommandEncoder>::Depth }, |
10878 | | JSJitInfo::Method, |
10879 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
10880 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
10881 | | false, /* isInfallible. False in setters. */ |
10882 | | false, /* isMovable. Not relevant for setters. */ |
10883 | | false, /* isEliminatable. Not relevant for setters. */ |
10884 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
10885 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
10886 | | false, /* isTypedMethod. Only relevant for methods. */ |
10887 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
10888 | | }; |
10889 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
10890 | | static_assert(0 < 1, "There is no slot for us"); |
10891 | | |
10892 | | MOZ_CAN_RUN_SCRIPT static bool |
10893 | | endRenderPass(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::CommandEncoder* self, const JSJitMethodCallArgs& args) |
10894 | 0 | { |
10895 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUCommandEncoder.endRenderPass", DOM, cx); |
10896 | 0 |
|
10897 | 0 | self->EndRenderPass(); |
10898 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
10899 | 0 | args.rval().setUndefined(); |
10900 | 0 | return true; |
10901 | 0 | } |
10902 | | |
10903 | | static const JSJitInfo endRenderPass_methodinfo = { |
10904 | | { (JSJitGetterOp)endRenderPass }, |
10905 | | { prototypes::id::WebGPUCommandEncoder }, |
10906 | | { PrototypeTraits<prototypes::id::WebGPUCommandEncoder>::Depth }, |
10907 | | JSJitInfo::Method, |
10908 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
10909 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
10910 | | true, /* isInfallible. False in setters. */ |
10911 | | false, /* isMovable. Not relevant for setters. */ |
10912 | | false, /* isEliminatable. Not relevant for setters. */ |
10913 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
10914 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
10915 | | false, /* isTypedMethod. Only relevant for methods. */ |
10916 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
10917 | | }; |
10918 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
10919 | | static_assert(0 < 1, "There is no slot for us"); |
10920 | | |
10921 | | MOZ_CAN_RUN_SCRIPT static bool |
10922 | | setBlendColor(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::CommandEncoder* self, const JSJitMethodCallArgs& args) |
10923 | 0 | { |
10924 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUCommandEncoder.setBlendColor", DOM, cx); |
10925 | 0 |
|
10926 | 0 | if (MOZ_UNLIKELY(args.length() < 4)) { |
10927 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebGPUCommandEncoder.setBlendColor"); |
10928 | 0 | } |
10929 | 0 | float arg0; |
10930 | 0 | if (!ValueToPrimitive<float, eDefault>(cx, args[0], &arg0)) { |
10931 | 0 | return false; |
10932 | 0 | } else if (!mozilla::IsFinite(arg0)) { |
10933 | 0 | ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 1 of WebGPUCommandEncoder.setBlendColor"); |
10934 | 0 | return false; |
10935 | 0 | } |
10936 | 0 | float arg1; |
10937 | 0 | if (!ValueToPrimitive<float, eDefault>(cx, args[1], &arg1)) { |
10938 | 0 | return false; |
10939 | 0 | } else if (!mozilla::IsFinite(arg1)) { |
10940 | 0 | ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 2 of WebGPUCommandEncoder.setBlendColor"); |
10941 | 0 | return false; |
10942 | 0 | } |
10943 | 0 | float arg2; |
10944 | 0 | if (!ValueToPrimitive<float, eDefault>(cx, args[2], &arg2)) { |
10945 | 0 | return false; |
10946 | 0 | } else if (!mozilla::IsFinite(arg2)) { |
10947 | 0 | ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 3 of WebGPUCommandEncoder.setBlendColor"); |
10948 | 0 | return false; |
10949 | 0 | } |
10950 | 0 | float arg3; |
10951 | 0 | if (!ValueToPrimitive<float, eDefault>(cx, args[3], &arg3)) { |
10952 | 0 | return false; |
10953 | 0 | } else if (!mozilla::IsFinite(arg3)) { |
10954 | 0 | ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 4 of WebGPUCommandEncoder.setBlendColor"); |
10955 | 0 | return false; |
10956 | 0 | } |
10957 | 0 | self->SetBlendColor(arg0, arg1, arg2, arg3); |
10958 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
10959 | 0 | args.rval().setUndefined(); |
10960 | 0 | return true; |
10961 | 0 | } |
10962 | | |
10963 | | static const JSJitInfo setBlendColor_methodinfo = { |
10964 | | { (JSJitGetterOp)setBlendColor }, |
10965 | | { prototypes::id::WebGPUCommandEncoder }, |
10966 | | { PrototypeTraits<prototypes::id::WebGPUCommandEncoder>::Depth }, |
10967 | | JSJitInfo::Method, |
10968 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
10969 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
10970 | | false, /* isInfallible. False in setters. */ |
10971 | | false, /* isMovable. Not relevant for setters. */ |
10972 | | false, /* isEliminatable. Not relevant for setters. */ |
10973 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
10974 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
10975 | | false, /* isTypedMethod. Only relevant for methods. */ |
10976 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
10977 | | }; |
10978 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
10979 | | static_assert(0 < 1, "There is no slot for us"); |
10980 | | |
10981 | | MOZ_CAN_RUN_SCRIPT static bool |
10982 | | setIndexBuffer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::CommandEncoder* self, const JSJitMethodCallArgs& args) |
10983 | 0 | { |
10984 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUCommandEncoder.setIndexBuffer", DOM, cx); |
10985 | 0 |
|
10986 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
10987 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebGPUCommandEncoder.setIndexBuffer"); |
10988 | 0 | } |
10989 | 0 | NonNull<mozilla::webgpu::Buffer> arg0; |
10990 | 0 | if (args[0].isObject()) { |
10991 | 0 | { |
10992 | 0 | nsresult rv = UnwrapObject<prototypes::id::WebGPUBuffer, mozilla::webgpu::Buffer>(args[0], arg0); |
10993 | 0 | if (NS_FAILED(rv)) { |
10994 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of WebGPUCommandEncoder.setIndexBuffer", "WebGPUBuffer"); |
10995 | 0 | return false; |
10996 | 0 | } |
10997 | 0 | } |
10998 | 0 | } else { |
10999 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of WebGPUCommandEncoder.setIndexBuffer"); |
11000 | 0 | return false; |
11001 | 0 | } |
11002 | 0 | uint32_t arg1; |
11003 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) { |
11004 | 0 | return false; |
11005 | 0 | } |
11006 | 0 | self->SetIndexBuffer(MOZ_KnownLive(NonNullHelper(arg0)), arg1); |
11007 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
11008 | 0 | args.rval().setUndefined(); |
11009 | 0 | return true; |
11010 | 0 | } |
11011 | | |
11012 | | static const JSJitInfo setIndexBuffer_methodinfo = { |
11013 | | { (JSJitGetterOp)setIndexBuffer }, |
11014 | | { prototypes::id::WebGPUCommandEncoder }, |
11015 | | { PrototypeTraits<prototypes::id::WebGPUCommandEncoder>::Depth }, |
11016 | | JSJitInfo::Method, |
11017 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
11018 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
11019 | | false, /* isInfallible. False in setters. */ |
11020 | | false, /* isMovable. Not relevant for setters. */ |
11021 | | false, /* isEliminatable. Not relevant for setters. */ |
11022 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
11023 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
11024 | | false, /* isTypedMethod. Only relevant for methods. */ |
11025 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
11026 | | }; |
11027 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
11028 | | static_assert(0 < 1, "There is no slot for us"); |
11029 | | |
11030 | | MOZ_CAN_RUN_SCRIPT static bool |
11031 | | setVertexBuffers(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::CommandEncoder* self, const JSJitMethodCallArgs& args) |
11032 | 0 | { |
11033 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUCommandEncoder.setVertexBuffers", DOM, cx); |
11034 | 0 |
|
11035 | 0 | if (MOZ_UNLIKELY(args.length() < 3)) { |
11036 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebGPUCommandEncoder.setVertexBuffers"); |
11037 | 0 | } |
11038 | 0 | uint32_t arg0; |
11039 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) { |
11040 | 0 | return false; |
11041 | 0 | } |
11042 | 0 | binding_detail::AutoSequence<OwningNonNull<mozilla::webgpu::Buffer>> arg1; |
11043 | 0 | if (args[1].isObject()) { |
11044 | 0 | JS::ForOfIterator iter(cx); |
11045 | 0 | if (!iter.init(args[1], JS::ForOfIterator::AllowNonIterable)) { |
11046 | 0 | return false; |
11047 | 0 | } |
11048 | 0 | if (!iter.valueIsIterable()) { |
11049 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 2 of WebGPUCommandEncoder.setVertexBuffers"); |
11050 | 0 | return false; |
11051 | 0 | } |
11052 | 0 | binding_detail::AutoSequence<OwningNonNull<mozilla::webgpu::Buffer>> &arr = arg1; |
11053 | 0 | JS::Rooted<JS::Value> temp(cx); |
11054 | 0 | while (true) { |
11055 | 0 | bool done; |
11056 | 0 | if (!iter.next(&temp, &done)) { |
11057 | 0 | return false; |
11058 | 0 | } |
11059 | 0 | if (done) { |
11060 | 0 | break; |
11061 | 0 | } |
11062 | 0 | OwningNonNull<mozilla::webgpu::Buffer>* slotPtr = arr.AppendElement(mozilla::fallible); |
11063 | 0 | if (!slotPtr) { |
11064 | 0 | JS_ReportOutOfMemory(cx); |
11065 | 0 | return false; |
11066 | 0 | } |
11067 | 0 | OwningNonNull<mozilla::webgpu::Buffer>& slot = *slotPtr; |
11068 | 0 | if (temp.isObject()) { |
11069 | 0 | static_assert(IsRefcounted<mozilla::webgpu::Buffer>::value, "We can only store refcounted classes.");{ |
11070 | 0 | nsresult rv = UnwrapObject<prototypes::id::WebGPUBuffer, mozilla::webgpu::Buffer>(&temp, slot); |
11071 | 0 | if (NS_FAILED(rv)) { |
11072 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of argument 2 of WebGPUCommandEncoder.setVertexBuffers", "WebGPUBuffer"); |
11073 | 0 | return false; |
11074 | 0 | } |
11075 | 0 | } |
11076 | 0 | } else { |
11077 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of argument 2 of WebGPUCommandEncoder.setVertexBuffers"); |
11078 | 0 | return false; |
11079 | 0 | } |
11080 | 0 | } |
11081 | 0 | } else { |
11082 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 2 of WebGPUCommandEncoder.setVertexBuffers"); |
11083 | 0 | return false; |
11084 | 0 | } |
11085 | 0 | binding_detail::AutoSequence<uint32_t> arg2; |
11086 | 0 | if (args[2].isObject()) { |
11087 | 0 | JS::ForOfIterator iter(cx); |
11088 | 0 | if (!iter.init(args[2], JS::ForOfIterator::AllowNonIterable)) { |
11089 | 0 | return false; |
11090 | 0 | } |
11091 | 0 | if (!iter.valueIsIterable()) { |
11092 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 3 of WebGPUCommandEncoder.setVertexBuffers"); |
11093 | 0 | return false; |
11094 | 0 | } |
11095 | 0 | binding_detail::AutoSequence<uint32_t> &arr = arg2; |
11096 | 0 | JS::Rooted<JS::Value> temp(cx); |
11097 | 0 | while (true) { |
11098 | 0 | bool done; |
11099 | 0 | if (!iter.next(&temp, &done)) { |
11100 | 0 | return false; |
11101 | 0 | } |
11102 | 0 | if (done) { |
11103 | 0 | break; |
11104 | 0 | } |
11105 | 0 | uint32_t* slotPtr = arr.AppendElement(mozilla::fallible); |
11106 | 0 | if (!slotPtr) { |
11107 | 0 | JS_ReportOutOfMemory(cx); |
11108 | 0 | return false; |
11109 | 0 | } |
11110 | 0 | uint32_t& slot = *slotPtr; |
11111 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp, &slot)) { |
11112 | 0 | return false; |
11113 | 0 | } |
11114 | 0 | } |
11115 | 0 | } else { |
11116 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 3 of WebGPUCommandEncoder.setVertexBuffers"); |
11117 | 0 | return false; |
11118 | 0 | } |
11119 | 0 | self->SetVertexBuffers(arg0, Constify(arg1), Constify(arg2)); |
11120 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
11121 | 0 | args.rval().setUndefined(); |
11122 | 0 | return true; |
11123 | 0 | } |
11124 | | |
11125 | | static const JSJitInfo setVertexBuffers_methodinfo = { |
11126 | | { (JSJitGetterOp)setVertexBuffers }, |
11127 | | { prototypes::id::WebGPUCommandEncoder }, |
11128 | | { PrototypeTraits<prototypes::id::WebGPUCommandEncoder>::Depth }, |
11129 | | JSJitInfo::Method, |
11130 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
11131 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
11132 | | false, /* isInfallible. False in setters. */ |
11133 | | false, /* isMovable. Not relevant for setters. */ |
11134 | | false, /* isEliminatable. Not relevant for setters. */ |
11135 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
11136 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
11137 | | false, /* isTypedMethod. Only relevant for methods. */ |
11138 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
11139 | | }; |
11140 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
11141 | | static_assert(0 < 1, "There is no slot for us"); |
11142 | | |
11143 | | MOZ_CAN_RUN_SCRIPT static bool |
11144 | | draw(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::CommandEncoder* self, const JSJitMethodCallArgs& args) |
11145 | 0 | { |
11146 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUCommandEncoder.draw", DOM, cx); |
11147 | 0 |
|
11148 | 0 | if (MOZ_UNLIKELY(args.length() < 4)) { |
11149 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebGPUCommandEncoder.draw"); |
11150 | 0 | } |
11151 | 0 | uint32_t arg0; |
11152 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) { |
11153 | 0 | return false; |
11154 | 0 | } |
11155 | 0 | uint32_t arg1; |
11156 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) { |
11157 | 0 | return false; |
11158 | 0 | } |
11159 | 0 | uint32_t arg2; |
11160 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[2], &arg2)) { |
11161 | 0 | return false; |
11162 | 0 | } |
11163 | 0 | uint32_t arg3; |
11164 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[3], &arg3)) { |
11165 | 0 | return false; |
11166 | 0 | } |
11167 | 0 | self->Draw(arg0, arg1, arg2, arg3); |
11168 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
11169 | 0 | args.rval().setUndefined(); |
11170 | 0 | return true; |
11171 | 0 | } |
11172 | | |
11173 | | static const JSJitInfo draw_methodinfo = { |
11174 | | { (JSJitGetterOp)draw }, |
11175 | | { prototypes::id::WebGPUCommandEncoder }, |
11176 | | { PrototypeTraits<prototypes::id::WebGPUCommandEncoder>::Depth }, |
11177 | | JSJitInfo::Method, |
11178 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
11179 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
11180 | | false, /* isInfallible. False in setters. */ |
11181 | | false, /* isMovable. Not relevant for setters. */ |
11182 | | false, /* isEliminatable. Not relevant for setters. */ |
11183 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
11184 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
11185 | | false, /* isTypedMethod. Only relevant for methods. */ |
11186 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
11187 | | }; |
11188 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
11189 | | static_assert(0 < 1, "There is no slot for us"); |
11190 | | |
11191 | | MOZ_CAN_RUN_SCRIPT static bool |
11192 | | drawIndexed(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::CommandEncoder* self, const JSJitMethodCallArgs& args) |
11193 | 0 | { |
11194 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUCommandEncoder.drawIndexed", DOM, cx); |
11195 | 0 |
|
11196 | 0 | if (MOZ_UNLIKELY(args.length() < 5)) { |
11197 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebGPUCommandEncoder.drawIndexed"); |
11198 | 0 | } |
11199 | 0 | uint32_t arg0; |
11200 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) { |
11201 | 0 | return false; |
11202 | 0 | } |
11203 | 0 | uint32_t arg1; |
11204 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) { |
11205 | 0 | return false; |
11206 | 0 | } |
11207 | 0 | uint32_t arg2; |
11208 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[2], &arg2)) { |
11209 | 0 | return false; |
11210 | 0 | } |
11211 | 0 | uint32_t arg3; |
11212 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[3], &arg3)) { |
11213 | 0 | return false; |
11214 | 0 | } |
11215 | 0 | uint32_t arg4; |
11216 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[4], &arg4)) { |
11217 | 0 | return false; |
11218 | 0 | } |
11219 | 0 | self->DrawIndexed(arg0, arg1, arg2, arg3, arg4); |
11220 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
11221 | 0 | args.rval().setUndefined(); |
11222 | 0 | return true; |
11223 | 0 | } |
11224 | | |
11225 | | static const JSJitInfo drawIndexed_methodinfo = { |
11226 | | { (JSJitGetterOp)drawIndexed }, |
11227 | | { prototypes::id::WebGPUCommandEncoder }, |
11228 | | { PrototypeTraits<prototypes::id::WebGPUCommandEncoder>::Depth }, |
11229 | | JSJitInfo::Method, |
11230 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
11231 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
11232 | | false, /* isInfallible. False in setters. */ |
11233 | | false, /* isMovable. Not relevant for setters. */ |
11234 | | false, /* isEliminatable. Not relevant for setters. */ |
11235 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
11236 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
11237 | | false, /* isTypedMethod. Only relevant for methods. */ |
11238 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
11239 | | }; |
11240 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
11241 | | static_assert(0 < 1, "There is no slot for us"); |
11242 | | |
11243 | | static bool |
11244 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
11245 | 0 | { |
11246 | 0 | mozilla::webgpu::CommandEncoder* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::CommandEncoder>(obj); |
11247 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
11248 | 0 | // obviously can't preserve if we're not initialized. |
11249 | 0 | if (self && self->GetWrapperPreserveColor()) { |
11250 | 0 | PreserveWrapper(self); |
11251 | 0 | } |
11252 | 0 | return true; |
11253 | 0 | } |
11254 | | |
11255 | | static void |
11256 | | _finalize(js::FreeOp* fop, JSObject* obj) |
11257 | 0 | { |
11258 | 0 | mozilla::webgpu::CommandEncoder* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::CommandEncoder>(obj); |
11259 | 0 | if (self) { |
11260 | 0 | ClearWrapper(self, self, obj); |
11261 | 0 | AddForDeferredFinalization<mozilla::webgpu::CommandEncoder>(self); |
11262 | 0 | } |
11263 | 0 | } |
11264 | | |
11265 | | static size_t |
11266 | | _objectMoved(JSObject* obj, JSObject* old) |
11267 | 0 | { |
11268 | 0 | mozilla::webgpu::CommandEncoder* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::CommandEncoder>(obj); |
11269 | 0 | if (self) { |
11270 | 0 | UpdateWrapper(self, self, obj, old); |
11271 | 0 | } |
11272 | 0 |
|
11273 | 0 | return 0; |
11274 | 0 | } |
11275 | | |
11276 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
11277 | | #if defined(__clang__) |
11278 | | #pragma clang diagnostic push |
11279 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
11280 | | #endif |
11281 | | static const JSFunctionSpec sMethods_specs[] = { |
11282 | | JS_FNSPEC("finishEncoding", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&finishEncoding_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
11283 | | JS_FNSPEC("copyBufferToBuffer", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(©BufferToBuffer_methodinfo), 5, JSPROP_ENUMERATE, nullptr), |
11284 | | JS_FNSPEC("copyBufferToTexture", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(©BufferToTexture_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
11285 | | JS_FNSPEC("copyTextureToBuffer", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(©TextureToBuffer_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
11286 | | JS_FNSPEC("copyTextureToTexture", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(©TextureToTexture_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
11287 | | JS_FNSPEC("blit", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&blit_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
11288 | | JS_FNSPEC("transitionBuffer", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&transitionBuffer_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
11289 | | JS_FNSPEC("setPushConstants", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&setPushConstants_methodinfo), 4, JSPROP_ENUMERATE, nullptr), |
11290 | | JS_FNSPEC("setBindGroup", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&setBindGroup_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
11291 | | JS_FNSPEC("setPipeline", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&setPipeline_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
11292 | | JS_FNSPEC("beginComputePass", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&beginComputePass_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
11293 | | JS_FNSPEC("endComputePass", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&endComputePass_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
11294 | | JS_FNSPEC("dispatch", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&dispatch_methodinfo), 3, JSPROP_ENUMERATE, nullptr), |
11295 | | JS_FNSPEC("beginRenderPass", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&beginRenderPass_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
11296 | | JS_FNSPEC("endRenderPass", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&endRenderPass_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
11297 | | JS_FNSPEC("setBlendColor", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&setBlendColor_methodinfo), 4, JSPROP_ENUMERATE, nullptr), |
11298 | | JS_FNSPEC("setIndexBuffer", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&setIndexBuffer_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
11299 | | JS_FNSPEC("setVertexBuffers", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&setVertexBuffers_methodinfo), 3, JSPROP_ENUMERATE, nullptr), |
11300 | | JS_FNSPEC("draw", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&draw_methodinfo), 4, JSPROP_ENUMERATE, nullptr), |
11301 | | JS_FNSPEC("drawIndexed", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&drawIndexed_methodinfo), 5, JSPROP_ENUMERATE, nullptr), |
11302 | | JS_FS_END |
11303 | | }; |
11304 | | #if defined(__clang__) |
11305 | | #pragma clang diagnostic pop |
11306 | | #endif |
11307 | | |
11308 | | |
11309 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
11310 | | { nullptr, &sMethods_specs[0] }, |
11311 | | { nullptr, nullptr } |
11312 | | }; |
11313 | | |
11314 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
11315 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
11316 | | static_assert(20 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
11317 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
11318 | | |
11319 | | |
11320 | | static uint16_t sNativeProperties_sortedPropertyIndices[20]; |
11321 | | static PropertyInfo sNativeProperties_propertyInfos[20]; |
11322 | | |
11323 | | static const NativePropertiesN<1> sNativeProperties = { |
11324 | | false, 0, |
11325 | | false, 0, |
11326 | | true, 0 /* sMethods */, |
11327 | | false, 0, |
11328 | | false, 0, |
11329 | | false, 0, |
11330 | | false, 0, |
11331 | | -1, |
11332 | | 20, |
11333 | | sNativeProperties_sortedPropertyIndices, |
11334 | | { |
11335 | | { sMethods, &sNativeProperties_propertyInfos[0] } |
11336 | | } |
11337 | | }; |
11338 | | static_assert(20 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
11339 | | "We have a property info count that is oversized"); |
11340 | | |
11341 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
11342 | | { |
11343 | | "Function", |
11344 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
11345 | | &sBoringInterfaceObjectClassClassOps, |
11346 | | JS_NULL_CLASS_SPEC, |
11347 | | JS_NULL_CLASS_EXT, |
11348 | | &sInterfaceObjectClassObjectOps |
11349 | | }, |
11350 | | eInterface, |
11351 | | true, |
11352 | | prototypes::id::WebGPUCommandEncoder, |
11353 | | PrototypeTraits<prototypes::id::WebGPUCommandEncoder>::Depth, |
11354 | | sNativePropertyHooks, |
11355 | | "function WebGPUCommandEncoder() {\n [native code]\n}", |
11356 | | JS::GetRealmFunctionPrototype |
11357 | | }; |
11358 | | |
11359 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
11360 | | { |
11361 | | "WebGPUCommandEncoderPrototype", |
11362 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
11363 | | JS_NULL_CLASS_OPS, |
11364 | | JS_NULL_CLASS_SPEC, |
11365 | | JS_NULL_CLASS_EXT, |
11366 | | JS_NULL_OBJECT_OPS |
11367 | | }, |
11368 | | eInterfacePrototype, |
11369 | | false, |
11370 | | prototypes::id::WebGPUCommandEncoder, |
11371 | | PrototypeTraits<prototypes::id::WebGPUCommandEncoder>::Depth, |
11372 | | sNativePropertyHooks, |
11373 | | "[object WebGPUCommandEncoderPrototype]", |
11374 | | JS::GetRealmObjectPrototype |
11375 | | }; |
11376 | | |
11377 | | bool |
11378 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
11379 | 0 | { |
11380 | 0 | static bool sPrefValue; |
11381 | 0 | static bool sPrefCacheSetUp = false; |
11382 | 0 | if (!sPrefCacheSetUp) { |
11383 | 0 | sPrefCacheSetUp = true; |
11384 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
11385 | 0 | } |
11386 | 0 |
|
11387 | 0 | return sPrefValue; |
11388 | 0 | } |
11389 | | |
11390 | | static const js::ClassOps sClassOps = { |
11391 | | _addProperty, /* addProperty */ |
11392 | | nullptr, /* delProperty */ |
11393 | | nullptr, /* enumerate */ |
11394 | | nullptr, /* newEnumerate */ |
11395 | | nullptr, /* resolve */ |
11396 | | nullptr, /* mayResolve */ |
11397 | | _finalize, /* finalize */ |
11398 | | nullptr, /* call */ |
11399 | | nullptr, /* hasInstance */ |
11400 | | nullptr, /* construct */ |
11401 | | nullptr, /* trace */ |
11402 | | }; |
11403 | | |
11404 | | static const js::ClassExtension sClassExtension = { |
11405 | | nullptr, /* weakmapKeyDelegateOp */ |
11406 | | _objectMoved /* objectMovedOp */ |
11407 | | }; |
11408 | | |
11409 | | static const DOMJSClass sClass = { |
11410 | | { "WebGPUCommandEncoder", |
11411 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
11412 | | &sClassOps, |
11413 | | JS_NULL_CLASS_SPEC, |
11414 | | &sClassExtension, |
11415 | | JS_NULL_OBJECT_OPS |
11416 | | }, |
11417 | | { prototypes::id::WebGPUCommandEncoder, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
11418 | | IsBaseOf<nsISupports, mozilla::webgpu::CommandEncoder >::value, |
11419 | | sNativePropertyHooks, |
11420 | | FindAssociatedGlobalForNative<mozilla::webgpu::CommandEncoder>::Get, |
11421 | | GetProtoObjectHandle, |
11422 | | GetCCParticipant<mozilla::webgpu::CommandEncoder>::Get() |
11423 | | }; |
11424 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
11425 | | "Must have the right minimal number of reserved slots."); |
11426 | | static_assert(1 >= 1, |
11427 | | "Must have enough reserved slots."); |
11428 | | |
11429 | | const JSClass* |
11430 | | GetJSClass() |
11431 | 0 | { |
11432 | 0 | return sClass.ToJSClass(); |
11433 | 0 | } |
11434 | | |
11435 | | bool |
11436 | | Wrap(JSContext* aCx, mozilla::webgpu::CommandEncoder* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
11437 | 0 | { |
11438 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::CommandEncoder>::value, |
11439 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
11440 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::CommandEncoder*>(aObject) == |
11441 | 0 | reinterpret_cast<mozilla::webgpu::CommandEncoder*>(aObject), |
11442 | 0 | "Multiple inheritance for mozilla::webgpu::CommandEncoder is broken."); |
11443 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
11444 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
11445 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
11446 | 0 | "You should probably not be using Wrap() directly; use " |
11447 | 0 | "GetOrCreateDOMReflector instead"); |
11448 | 0 |
|
11449 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
11450 | 0 | "nsISupports must be on our primary inheritance chain"); |
11451 | 0 |
|
11452 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
11453 | 0 | if (!global) { |
11454 | 0 | return false; |
11455 | 0 | } |
11456 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
11457 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
11458 | 0 |
|
11459 | 0 | // That might have ended up wrapping us already, due to the wonders |
11460 | 0 | // of XBL. Check for that, and bail out as needed. |
11461 | 0 | aReflector.set(aCache->GetWrapper()); |
11462 | 0 | if (aReflector) { |
11463 | | #ifdef DEBUG |
11464 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
11465 | | #endif // DEBUG |
11466 | | return true; |
11467 | 0 | } |
11468 | 0 |
|
11469 | 0 | JSAutoRealm ar(aCx, global); |
11470 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
11471 | 0 | if (!canonicalProto) { |
11472 | 0 | return false; |
11473 | 0 | } |
11474 | 0 | JS::Rooted<JSObject*> proto(aCx); |
11475 | 0 | if (aGivenProto) { |
11476 | 0 | proto = aGivenProto; |
11477 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
11478 | 0 | // coming in, we changed compartments to that of "parent" so may need |
11479 | 0 | // to wrap the proto here. |
11480 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
11481 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
11482 | 0 | return false; |
11483 | 0 | } |
11484 | 0 | } |
11485 | 0 | } else { |
11486 | 0 | proto = canonicalProto; |
11487 | 0 | } |
11488 | 0 |
|
11489 | 0 | BindingJSObjectCreator<mozilla::webgpu::CommandEncoder> creator(aCx); |
11490 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
11491 | 0 | if (!aReflector) { |
11492 | 0 | return false; |
11493 | 0 | } |
11494 | 0 | |
11495 | 0 | aCache->SetWrapper(aReflector); |
11496 | 0 | creator.InitializationSucceeded(); |
11497 | 0 |
|
11498 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
11499 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
11500 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
11501 | 0 | // otherwise we won't be able to properly recreate it later, since |
11502 | 0 | // we won't know what proto to use. Note that we don't check |
11503 | 0 | // aGivenProto here, since it's entirely possible (and even |
11504 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
11505 | 0 | // same as canonicalProto. |
11506 | 0 | if (proto != canonicalProto) { |
11507 | 0 | PreserveWrapper(aObject); |
11508 | 0 | } |
11509 | 0 |
|
11510 | 0 | return true; |
11511 | 0 | } |
11512 | | |
11513 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
11514 | | nullptr, |
11515 | | nullptr, |
11516 | | nullptr, |
11517 | | { sNativeProperties.Upcast(), nullptr }, |
11518 | | prototypes::id::WebGPUCommandEncoder, |
11519 | | constructors::id::WebGPUCommandEncoder, |
11520 | | nullptr, |
11521 | | &DefaultXrayExpandoObjectClass |
11522 | | } }; |
11523 | | |
11524 | | void |
11525 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
11526 | 0 | { |
11527 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
11528 | 0 | if (!parentProto) { |
11529 | 0 | return; |
11530 | 0 | } |
11531 | 0 | |
11532 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
11533 | 0 | if (!constructorProto) { |
11534 | 0 | return; |
11535 | 0 | } |
11536 | 0 | |
11537 | 0 | static bool sIdsInited = false; |
11538 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
11539 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
11540 | 0 | return; |
11541 | 0 | } |
11542 | 0 | sIdsInited = true; |
11543 | 0 | } |
11544 | 0 |
|
11545 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPUCommandEncoder); |
11546 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUCommandEncoder); |
11547 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
11548 | 0 | &sPrototypeClass.mBase, protoCache, |
11549 | 0 | nullptr, |
11550 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
11551 | 0 | interfaceCache, |
11552 | 0 | sNativeProperties.Upcast(), |
11553 | 0 | nullptr, |
11554 | 0 | "WebGPUCommandEncoder", aDefineOnGlobal, |
11555 | 0 | nullptr, |
11556 | 0 | false); |
11557 | 0 | } |
11558 | | |
11559 | | JSObject* |
11560 | | GetConstructorObject(JSContext* aCx) |
11561 | 0 | { |
11562 | 0 | return GetConstructorObjectHandle(aCx); |
11563 | 0 | } |
11564 | | |
11565 | | } // namespace WebGPUCommandEncoder_Binding |
11566 | | |
11567 | | |
11568 | | |
11569 | | namespace WebGPUCompareFunction_Binding { |
11570 | | |
11571 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
11572 | | #if defined(__clang__) |
11573 | | #pragma clang diagnostic push |
11574 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
11575 | | #endif |
11576 | | static const ConstantSpec sConstants_specs[] = { |
11577 | | { "NEVER", JS::NumberValue(0U) }, |
11578 | | { "LESS", JS::NumberValue(1U) }, |
11579 | | { "LESS_EQUAL", JS::NumberValue(2U) }, |
11580 | | { "GREATER", JS::NumberValue(3U) }, |
11581 | | { "GREATER_EQUAL", JS::NumberValue(4U) }, |
11582 | | { "EQUAL", JS::NumberValue(5U) }, |
11583 | | { "NOT_EQUAL", JS::NumberValue(6U) }, |
11584 | | { "ALWAYS", JS::NumberValue(7U) }, |
11585 | | { 0, JS::UndefinedValue() } |
11586 | | }; |
11587 | | #if defined(__clang__) |
11588 | | #pragma clang diagnostic pop |
11589 | | #endif |
11590 | | |
11591 | | |
11592 | | static const Prefable<const ConstantSpec> sConstants[] = { |
11593 | | { nullptr, &sConstants_specs[0] }, |
11594 | | { nullptr, nullptr } |
11595 | | }; |
11596 | | |
11597 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
11598 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
11599 | | static_assert(8 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
11600 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
11601 | | |
11602 | | |
11603 | | static uint16_t sNativeProperties_sortedPropertyIndices[8]; |
11604 | | static PropertyInfo sNativeProperties_propertyInfos[8]; |
11605 | | |
11606 | | static const NativePropertiesN<1> sNativeProperties = { |
11607 | | false, 0, |
11608 | | false, 0, |
11609 | | false, 0, |
11610 | | false, 0, |
11611 | | false, 0, |
11612 | | false, 0, |
11613 | | true, 0 /* sConstants */, |
11614 | | -1, |
11615 | | 8, |
11616 | | sNativeProperties_sortedPropertyIndices, |
11617 | | { |
11618 | | { sConstants, &sNativeProperties_propertyInfos[0] } |
11619 | | } |
11620 | | }; |
11621 | | static_assert(8 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
11622 | | "We have a property info count that is oversized"); |
11623 | | |
11624 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
11625 | | { |
11626 | | "Function", |
11627 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
11628 | | &sBoringInterfaceObjectClassClassOps, |
11629 | | JS_NULL_CLASS_SPEC, |
11630 | | JS_NULL_CLASS_EXT, |
11631 | | &sInterfaceObjectClassObjectOps |
11632 | | }, |
11633 | | eInterface, |
11634 | | false, |
11635 | | prototypes::id::_ID_Count, |
11636 | | 0, |
11637 | | sNativePropertyHooks, |
11638 | | "function WebGPUCompareFunction() {\n [native code]\n}", |
11639 | | JS::GetRealmFunctionPrototype |
11640 | | }; |
11641 | | |
11642 | | bool |
11643 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
11644 | 0 | { |
11645 | 0 | static bool sPrefValue; |
11646 | 0 | static bool sPrefCacheSetUp = false; |
11647 | 0 | if (!sPrefCacheSetUp) { |
11648 | 0 | sPrefCacheSetUp = true; |
11649 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
11650 | 0 | } |
11651 | 0 |
|
11652 | 0 | return sPrefValue; |
11653 | 0 | } |
11654 | | |
11655 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
11656 | | nullptr, |
11657 | | nullptr, |
11658 | | nullptr, |
11659 | | { sNativeProperties.Upcast(), nullptr }, |
11660 | | prototypes::id::_ID_Count, |
11661 | | constructors::id::WebGPUCompareFunction, |
11662 | | nullptr, |
11663 | | &DefaultXrayExpandoObjectClass |
11664 | | } }; |
11665 | | |
11666 | | void |
11667 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
11668 | 0 | { |
11669 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
11670 | 0 | if (!constructorProto) { |
11671 | 0 | return; |
11672 | 0 | } |
11673 | 0 | |
11674 | 0 | static bool sIdsInited = false; |
11675 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
11676 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
11677 | 0 | return; |
11678 | 0 | } |
11679 | 0 | sIdsInited = true; |
11680 | 0 | } |
11681 | 0 |
|
11682 | 0 | JS::Heap<JSObject*>* protoCache = nullptr; |
11683 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUCompareFunction); |
11684 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, nullptr, |
11685 | 0 | nullptr, protoCache, |
11686 | 0 | nullptr, |
11687 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
11688 | 0 | interfaceCache, |
11689 | 0 | sNativeProperties.Upcast(), |
11690 | 0 | nullptr, |
11691 | 0 | "WebGPUCompareFunction", aDefineOnGlobal, |
11692 | 0 | nullptr, |
11693 | 0 | false); |
11694 | 0 | } |
11695 | | |
11696 | | JSObject* |
11697 | | GetConstructorObject(JSContext* aCx) |
11698 | 0 | { |
11699 | 0 | return GetConstructorObjectHandle(aCx); |
11700 | 0 | } |
11701 | | |
11702 | | } // namespace WebGPUCompareFunction_Binding |
11703 | | |
11704 | | |
11705 | | |
11706 | | namespace WebGPUComputePipeline_Binding { |
11707 | | |
11708 | | static bool |
11709 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
11710 | 0 | { |
11711 | 0 | mozilla::webgpu::ComputePipeline* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::ComputePipeline>(obj); |
11712 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
11713 | 0 | // obviously can't preserve if we're not initialized. |
11714 | 0 | if (self && self->GetWrapperPreserveColor()) { |
11715 | 0 | PreserveWrapper(self); |
11716 | 0 | } |
11717 | 0 | return true; |
11718 | 0 | } |
11719 | | |
11720 | | static void |
11721 | | _finalize(js::FreeOp* fop, JSObject* obj) |
11722 | 0 | { |
11723 | 0 | mozilla::webgpu::ComputePipeline* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::ComputePipeline>(obj); |
11724 | 0 | if (self) { |
11725 | 0 | ClearWrapper(self, self, obj); |
11726 | 0 | AddForDeferredFinalization<mozilla::webgpu::ComputePipeline>(self); |
11727 | 0 | } |
11728 | 0 | } |
11729 | | |
11730 | | static size_t |
11731 | | _objectMoved(JSObject* obj, JSObject* old) |
11732 | 0 | { |
11733 | 0 | mozilla::webgpu::ComputePipeline* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::ComputePipeline>(obj); |
11734 | 0 | if (self) { |
11735 | 0 | UpdateWrapper(self, self, obj, old); |
11736 | 0 | } |
11737 | 0 |
|
11738 | 0 | return 0; |
11739 | 0 | } |
11740 | | |
11741 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
11742 | | { |
11743 | | "Function", |
11744 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
11745 | | &sBoringInterfaceObjectClassClassOps, |
11746 | | JS_NULL_CLASS_SPEC, |
11747 | | JS_NULL_CLASS_EXT, |
11748 | | &sInterfaceObjectClassObjectOps |
11749 | | }, |
11750 | | eInterface, |
11751 | | true, |
11752 | | prototypes::id::WebGPUComputePipeline, |
11753 | | PrototypeTraits<prototypes::id::WebGPUComputePipeline>::Depth, |
11754 | | sNativePropertyHooks, |
11755 | | "function WebGPUComputePipeline() {\n [native code]\n}", |
11756 | | JS::GetRealmFunctionPrototype |
11757 | | }; |
11758 | | |
11759 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
11760 | | { |
11761 | | "WebGPUComputePipelinePrototype", |
11762 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
11763 | | JS_NULL_CLASS_OPS, |
11764 | | JS_NULL_CLASS_SPEC, |
11765 | | JS_NULL_CLASS_EXT, |
11766 | | JS_NULL_OBJECT_OPS |
11767 | | }, |
11768 | | eInterfacePrototype, |
11769 | | false, |
11770 | | prototypes::id::WebGPUComputePipeline, |
11771 | | PrototypeTraits<prototypes::id::WebGPUComputePipeline>::Depth, |
11772 | | sNativePropertyHooks, |
11773 | | "[object WebGPUComputePipelinePrototype]", |
11774 | | JS::GetRealmObjectPrototype |
11775 | | }; |
11776 | | |
11777 | | bool |
11778 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
11779 | 0 | { |
11780 | 0 | static bool sPrefValue; |
11781 | 0 | static bool sPrefCacheSetUp = false; |
11782 | 0 | if (!sPrefCacheSetUp) { |
11783 | 0 | sPrefCacheSetUp = true; |
11784 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
11785 | 0 | } |
11786 | 0 |
|
11787 | 0 | return sPrefValue; |
11788 | 0 | } |
11789 | | |
11790 | | static const js::ClassOps sClassOps = { |
11791 | | _addProperty, /* addProperty */ |
11792 | | nullptr, /* delProperty */ |
11793 | | nullptr, /* enumerate */ |
11794 | | nullptr, /* newEnumerate */ |
11795 | | nullptr, /* resolve */ |
11796 | | nullptr, /* mayResolve */ |
11797 | | _finalize, /* finalize */ |
11798 | | nullptr, /* call */ |
11799 | | nullptr, /* hasInstance */ |
11800 | | nullptr, /* construct */ |
11801 | | nullptr, /* trace */ |
11802 | | }; |
11803 | | |
11804 | | static const js::ClassExtension sClassExtension = { |
11805 | | nullptr, /* weakmapKeyDelegateOp */ |
11806 | | _objectMoved /* objectMovedOp */ |
11807 | | }; |
11808 | | |
11809 | | static const DOMJSClass sClass = { |
11810 | | { "WebGPUComputePipeline", |
11811 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
11812 | | &sClassOps, |
11813 | | JS_NULL_CLASS_SPEC, |
11814 | | &sClassExtension, |
11815 | | JS_NULL_OBJECT_OPS |
11816 | | }, |
11817 | | { prototypes::id::WebGPUComputePipeline, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
11818 | | IsBaseOf<nsISupports, mozilla::webgpu::ComputePipeline >::value, |
11819 | | sNativePropertyHooks, |
11820 | | FindAssociatedGlobalForNative<mozilla::webgpu::ComputePipeline>::Get, |
11821 | | GetProtoObjectHandle, |
11822 | | GetCCParticipant<mozilla::webgpu::ComputePipeline>::Get() |
11823 | | }; |
11824 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
11825 | | "Must have the right minimal number of reserved slots."); |
11826 | | static_assert(1 >= 1, |
11827 | | "Must have enough reserved slots."); |
11828 | | |
11829 | | const JSClass* |
11830 | | GetJSClass() |
11831 | 0 | { |
11832 | 0 | return sClass.ToJSClass(); |
11833 | 0 | } |
11834 | | |
11835 | | bool |
11836 | | Wrap(JSContext* aCx, mozilla::webgpu::ComputePipeline* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
11837 | 0 | { |
11838 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::ComputePipeline>::value, |
11839 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
11840 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::ComputePipeline*>(aObject) == |
11841 | 0 | reinterpret_cast<mozilla::webgpu::ComputePipeline*>(aObject), |
11842 | 0 | "Multiple inheritance for mozilla::webgpu::ComputePipeline is broken."); |
11843 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
11844 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
11845 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
11846 | 0 | "You should probably not be using Wrap() directly; use " |
11847 | 0 | "GetOrCreateDOMReflector instead"); |
11848 | 0 |
|
11849 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
11850 | 0 | "nsISupports must be on our primary inheritance chain"); |
11851 | 0 |
|
11852 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
11853 | 0 | if (!global) { |
11854 | 0 | return false; |
11855 | 0 | } |
11856 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
11857 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
11858 | 0 |
|
11859 | 0 | // That might have ended up wrapping us already, due to the wonders |
11860 | 0 | // of XBL. Check for that, and bail out as needed. |
11861 | 0 | aReflector.set(aCache->GetWrapper()); |
11862 | 0 | if (aReflector) { |
11863 | | #ifdef DEBUG |
11864 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
11865 | | #endif // DEBUG |
11866 | | return true; |
11867 | 0 | } |
11868 | 0 |
|
11869 | 0 | JSAutoRealm ar(aCx, global); |
11870 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
11871 | 0 | if (!canonicalProto) { |
11872 | 0 | return false; |
11873 | 0 | } |
11874 | 0 | JS::Rooted<JSObject*> proto(aCx); |
11875 | 0 | if (aGivenProto) { |
11876 | 0 | proto = aGivenProto; |
11877 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
11878 | 0 | // coming in, we changed compartments to that of "parent" so may need |
11879 | 0 | // to wrap the proto here. |
11880 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
11881 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
11882 | 0 | return false; |
11883 | 0 | } |
11884 | 0 | } |
11885 | 0 | } else { |
11886 | 0 | proto = canonicalProto; |
11887 | 0 | } |
11888 | 0 |
|
11889 | 0 | BindingJSObjectCreator<mozilla::webgpu::ComputePipeline> creator(aCx); |
11890 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
11891 | 0 | if (!aReflector) { |
11892 | 0 | return false; |
11893 | 0 | } |
11894 | 0 | |
11895 | 0 | aCache->SetWrapper(aReflector); |
11896 | 0 | creator.InitializationSucceeded(); |
11897 | 0 |
|
11898 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
11899 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
11900 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
11901 | 0 | // otherwise we won't be able to properly recreate it later, since |
11902 | 0 | // we won't know what proto to use. Note that we don't check |
11903 | 0 | // aGivenProto here, since it's entirely possible (and even |
11904 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
11905 | 0 | // same as canonicalProto. |
11906 | 0 | if (proto != canonicalProto) { |
11907 | 0 | PreserveWrapper(aObject); |
11908 | 0 | } |
11909 | 0 |
|
11910 | 0 | return true; |
11911 | 0 | } |
11912 | | |
11913 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
11914 | | nullptr, |
11915 | | nullptr, |
11916 | | nullptr, |
11917 | | { nullptr, nullptr }, |
11918 | | prototypes::id::WebGPUComputePipeline, |
11919 | | constructors::id::WebGPUComputePipeline, |
11920 | | nullptr, |
11921 | | &DefaultXrayExpandoObjectClass |
11922 | | } }; |
11923 | | |
11924 | | void |
11925 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
11926 | 0 | { |
11927 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
11928 | 0 | if (!parentProto) { |
11929 | 0 | return; |
11930 | 0 | } |
11931 | 0 | |
11932 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
11933 | 0 | if (!constructorProto) { |
11934 | 0 | return; |
11935 | 0 | } |
11936 | 0 | |
11937 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPUComputePipeline); |
11938 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUComputePipeline); |
11939 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
11940 | 0 | &sPrototypeClass.mBase, protoCache, |
11941 | 0 | nullptr, |
11942 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
11943 | 0 | interfaceCache, |
11944 | 0 | nullptr, |
11945 | 0 | nullptr, |
11946 | 0 | "WebGPUComputePipeline", aDefineOnGlobal, |
11947 | 0 | nullptr, |
11948 | 0 | false); |
11949 | 0 | } |
11950 | | |
11951 | | JSObject* |
11952 | | GetConstructorObject(JSContext* aCx) |
11953 | 0 | { |
11954 | 0 | return GetConstructorObjectHandle(aCx); |
11955 | 0 | } |
11956 | | |
11957 | | } // namespace WebGPUComputePipeline_Binding |
11958 | | |
11959 | | |
11960 | | |
11961 | | namespace WebGPUDepthStencilState_Binding { |
11962 | | |
11963 | | static bool |
11964 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
11965 | 0 | { |
11966 | 0 | mozilla::webgpu::DepthStencilState* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::DepthStencilState>(obj); |
11967 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
11968 | 0 | // obviously can't preserve if we're not initialized. |
11969 | 0 | if (self && self->GetWrapperPreserveColor()) { |
11970 | 0 | PreserveWrapper(self); |
11971 | 0 | } |
11972 | 0 | return true; |
11973 | 0 | } |
11974 | | |
11975 | | static void |
11976 | | _finalize(js::FreeOp* fop, JSObject* obj) |
11977 | 0 | { |
11978 | 0 | mozilla::webgpu::DepthStencilState* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::DepthStencilState>(obj); |
11979 | 0 | if (self) { |
11980 | 0 | ClearWrapper(self, self, obj); |
11981 | 0 | AddForDeferredFinalization<mozilla::webgpu::DepthStencilState>(self); |
11982 | 0 | } |
11983 | 0 | } |
11984 | | |
11985 | | static size_t |
11986 | | _objectMoved(JSObject* obj, JSObject* old) |
11987 | 0 | { |
11988 | 0 | mozilla::webgpu::DepthStencilState* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::DepthStencilState>(obj); |
11989 | 0 | if (self) { |
11990 | 0 | UpdateWrapper(self, self, obj, old); |
11991 | 0 | } |
11992 | 0 |
|
11993 | 0 | return 0; |
11994 | 0 | } |
11995 | | |
11996 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
11997 | | { |
11998 | | "Function", |
11999 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
12000 | | &sBoringInterfaceObjectClassClassOps, |
12001 | | JS_NULL_CLASS_SPEC, |
12002 | | JS_NULL_CLASS_EXT, |
12003 | | &sInterfaceObjectClassObjectOps |
12004 | | }, |
12005 | | eInterface, |
12006 | | true, |
12007 | | prototypes::id::WebGPUDepthStencilState, |
12008 | | PrototypeTraits<prototypes::id::WebGPUDepthStencilState>::Depth, |
12009 | | sNativePropertyHooks, |
12010 | | "function WebGPUDepthStencilState() {\n [native code]\n}", |
12011 | | JS::GetRealmFunctionPrototype |
12012 | | }; |
12013 | | |
12014 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
12015 | | { |
12016 | | "WebGPUDepthStencilStatePrototype", |
12017 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
12018 | | JS_NULL_CLASS_OPS, |
12019 | | JS_NULL_CLASS_SPEC, |
12020 | | JS_NULL_CLASS_EXT, |
12021 | | JS_NULL_OBJECT_OPS |
12022 | | }, |
12023 | | eInterfacePrototype, |
12024 | | false, |
12025 | | prototypes::id::WebGPUDepthStencilState, |
12026 | | PrototypeTraits<prototypes::id::WebGPUDepthStencilState>::Depth, |
12027 | | sNativePropertyHooks, |
12028 | | "[object WebGPUDepthStencilStatePrototype]", |
12029 | | JS::GetRealmObjectPrototype |
12030 | | }; |
12031 | | |
12032 | | bool |
12033 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
12034 | 0 | { |
12035 | 0 | static bool sPrefValue; |
12036 | 0 | static bool sPrefCacheSetUp = false; |
12037 | 0 | if (!sPrefCacheSetUp) { |
12038 | 0 | sPrefCacheSetUp = true; |
12039 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
12040 | 0 | } |
12041 | 0 |
|
12042 | 0 | return sPrefValue; |
12043 | 0 | } |
12044 | | |
12045 | | static const js::ClassOps sClassOps = { |
12046 | | _addProperty, /* addProperty */ |
12047 | | nullptr, /* delProperty */ |
12048 | | nullptr, /* enumerate */ |
12049 | | nullptr, /* newEnumerate */ |
12050 | | nullptr, /* resolve */ |
12051 | | nullptr, /* mayResolve */ |
12052 | | _finalize, /* finalize */ |
12053 | | nullptr, /* call */ |
12054 | | nullptr, /* hasInstance */ |
12055 | | nullptr, /* construct */ |
12056 | | nullptr, /* trace */ |
12057 | | }; |
12058 | | |
12059 | | static const js::ClassExtension sClassExtension = { |
12060 | | nullptr, /* weakmapKeyDelegateOp */ |
12061 | | _objectMoved /* objectMovedOp */ |
12062 | | }; |
12063 | | |
12064 | | static const DOMJSClass sClass = { |
12065 | | { "WebGPUDepthStencilState", |
12066 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
12067 | | &sClassOps, |
12068 | | JS_NULL_CLASS_SPEC, |
12069 | | &sClassExtension, |
12070 | | JS_NULL_OBJECT_OPS |
12071 | | }, |
12072 | | { prototypes::id::WebGPUDepthStencilState, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
12073 | | IsBaseOf<nsISupports, mozilla::webgpu::DepthStencilState >::value, |
12074 | | sNativePropertyHooks, |
12075 | | FindAssociatedGlobalForNative<mozilla::webgpu::DepthStencilState>::Get, |
12076 | | GetProtoObjectHandle, |
12077 | | GetCCParticipant<mozilla::webgpu::DepthStencilState>::Get() |
12078 | | }; |
12079 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
12080 | | "Must have the right minimal number of reserved slots."); |
12081 | | static_assert(1 >= 1, |
12082 | | "Must have enough reserved slots."); |
12083 | | |
12084 | | const JSClass* |
12085 | | GetJSClass() |
12086 | 0 | { |
12087 | 0 | return sClass.ToJSClass(); |
12088 | 0 | } |
12089 | | |
12090 | | bool |
12091 | | Wrap(JSContext* aCx, mozilla::webgpu::DepthStencilState* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
12092 | 0 | { |
12093 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::DepthStencilState>::value, |
12094 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
12095 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::DepthStencilState*>(aObject) == |
12096 | 0 | reinterpret_cast<mozilla::webgpu::DepthStencilState*>(aObject), |
12097 | 0 | "Multiple inheritance for mozilla::webgpu::DepthStencilState is broken."); |
12098 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
12099 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
12100 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
12101 | 0 | "You should probably not be using Wrap() directly; use " |
12102 | 0 | "GetOrCreateDOMReflector instead"); |
12103 | 0 |
|
12104 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
12105 | 0 | "nsISupports must be on our primary inheritance chain"); |
12106 | 0 |
|
12107 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
12108 | 0 | if (!global) { |
12109 | 0 | return false; |
12110 | 0 | } |
12111 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
12112 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
12113 | 0 |
|
12114 | 0 | // That might have ended up wrapping us already, due to the wonders |
12115 | 0 | // of XBL. Check for that, and bail out as needed. |
12116 | 0 | aReflector.set(aCache->GetWrapper()); |
12117 | 0 | if (aReflector) { |
12118 | | #ifdef DEBUG |
12119 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
12120 | | #endif // DEBUG |
12121 | | return true; |
12122 | 0 | } |
12123 | 0 |
|
12124 | 0 | JSAutoRealm ar(aCx, global); |
12125 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
12126 | 0 | if (!canonicalProto) { |
12127 | 0 | return false; |
12128 | 0 | } |
12129 | 0 | JS::Rooted<JSObject*> proto(aCx); |
12130 | 0 | if (aGivenProto) { |
12131 | 0 | proto = aGivenProto; |
12132 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
12133 | 0 | // coming in, we changed compartments to that of "parent" so may need |
12134 | 0 | // to wrap the proto here. |
12135 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
12136 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
12137 | 0 | return false; |
12138 | 0 | } |
12139 | 0 | } |
12140 | 0 | } else { |
12141 | 0 | proto = canonicalProto; |
12142 | 0 | } |
12143 | 0 |
|
12144 | 0 | BindingJSObjectCreator<mozilla::webgpu::DepthStencilState> creator(aCx); |
12145 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
12146 | 0 | if (!aReflector) { |
12147 | 0 | return false; |
12148 | 0 | } |
12149 | 0 | |
12150 | 0 | aCache->SetWrapper(aReflector); |
12151 | 0 | creator.InitializationSucceeded(); |
12152 | 0 |
|
12153 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
12154 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
12155 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
12156 | 0 | // otherwise we won't be able to properly recreate it later, since |
12157 | 0 | // we won't know what proto to use. Note that we don't check |
12158 | 0 | // aGivenProto here, since it's entirely possible (and even |
12159 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
12160 | 0 | // same as canonicalProto. |
12161 | 0 | if (proto != canonicalProto) { |
12162 | 0 | PreserveWrapper(aObject); |
12163 | 0 | } |
12164 | 0 |
|
12165 | 0 | return true; |
12166 | 0 | } |
12167 | | |
12168 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
12169 | | nullptr, |
12170 | | nullptr, |
12171 | | nullptr, |
12172 | | { nullptr, nullptr }, |
12173 | | prototypes::id::WebGPUDepthStencilState, |
12174 | | constructors::id::WebGPUDepthStencilState, |
12175 | | nullptr, |
12176 | | &DefaultXrayExpandoObjectClass |
12177 | | } }; |
12178 | | |
12179 | | void |
12180 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
12181 | 0 | { |
12182 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
12183 | 0 | if (!parentProto) { |
12184 | 0 | return; |
12185 | 0 | } |
12186 | 0 | |
12187 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
12188 | 0 | if (!constructorProto) { |
12189 | 0 | return; |
12190 | 0 | } |
12191 | 0 | |
12192 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPUDepthStencilState); |
12193 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUDepthStencilState); |
12194 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
12195 | 0 | &sPrototypeClass.mBase, protoCache, |
12196 | 0 | nullptr, |
12197 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
12198 | 0 | interfaceCache, |
12199 | 0 | nullptr, |
12200 | 0 | nullptr, |
12201 | 0 | "WebGPUDepthStencilState", aDefineOnGlobal, |
12202 | 0 | nullptr, |
12203 | 0 | false); |
12204 | 0 | } |
12205 | | |
12206 | | JSObject* |
12207 | | GetConstructorObject(JSContext* aCx) |
12208 | 0 | { |
12209 | 0 | return GetConstructorObjectHandle(aCx); |
12210 | 0 | } |
12211 | | |
12212 | | } // namespace WebGPUDepthStencilState_Binding |
12213 | | |
12214 | | |
12215 | | |
12216 | | namespace WebGPUDevice_Binding { |
12217 | | |
12218 | | MOZ_CAN_RUN_SCRIPT static bool |
12219 | | get_adapter(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Device* self, JSJitGetterCallArgs args) |
12220 | 0 | { |
12221 | 0 | AUTO_PROFILER_LABEL_FAST("get WebGPUDevice.adapter", DOM, cx); |
12222 | 0 |
|
12223 | 0 | auto result(StrongOrRawPtr<mozilla::webgpu::Adapter>(self->Adapter())); |
12224 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
12225 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
12226 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
12227 | 0 | return false; |
12228 | 0 | } |
12229 | 0 | return true; |
12230 | 0 | } |
12231 | | |
12232 | | static const JSJitInfo adapter_getterinfo = { |
12233 | | { (JSJitGetterOp)get_adapter }, |
12234 | | { prototypes::id::WebGPUDevice }, |
12235 | | { PrototypeTraits<prototypes::id::WebGPUDevice>::Depth }, |
12236 | | JSJitInfo::Getter, |
12237 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
12238 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
12239 | | false, /* isInfallible. False in setters. */ |
12240 | | false, /* isMovable. Not relevant for setters. */ |
12241 | | false, /* isEliminatable. Not relevant for setters. */ |
12242 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
12243 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
12244 | | false, /* isTypedMethod. Only relevant for methods. */ |
12245 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
12246 | | }; |
12247 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
12248 | | static_assert(0 < 1, "There is no slot for us"); |
12249 | | |
12250 | | MOZ_CAN_RUN_SCRIPT static bool |
12251 | | extensions(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Device* self, const JSJitMethodCallArgs& args) |
12252 | 0 | { |
12253 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUDevice.extensions", DOM, cx); |
12254 | 0 |
|
12255 | 0 | WebGPUExtensions result; |
12256 | 0 | self->Extensions(result); |
12257 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
12258 | 0 | if (!result.ToObjectInternal(cx, args.rval())) { |
12259 | 0 | return false; |
12260 | 0 | } |
12261 | 0 | return true; |
12262 | 0 | } |
12263 | | |
12264 | | static const JSJitInfo extensions_methodinfo = { |
12265 | | { (JSJitGetterOp)extensions }, |
12266 | | { prototypes::id::WebGPUDevice }, |
12267 | | { PrototypeTraits<prototypes::id::WebGPUDevice>::Depth }, |
12268 | | JSJitInfo::Method, |
12269 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
12270 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
12271 | | false, /* isInfallible. False in setters. */ |
12272 | | false, /* isMovable. Not relevant for setters. */ |
12273 | | false, /* isEliminatable. Not relevant for setters. */ |
12274 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
12275 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
12276 | | false, /* isTypedMethod. Only relevant for methods. */ |
12277 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
12278 | | }; |
12279 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
12280 | | static_assert(0 < 1, "There is no slot for us"); |
12281 | | |
12282 | | MOZ_CAN_RUN_SCRIPT static bool |
12283 | | limits(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Device* self, const JSJitMethodCallArgs& args) |
12284 | 0 | { |
12285 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUDevice.limits", DOM, cx); |
12286 | 0 |
|
12287 | 0 | WebGPULimits result; |
12288 | 0 | self->Limits(result); |
12289 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
12290 | 0 | if (!result.ToObjectInternal(cx, args.rval())) { |
12291 | 0 | return false; |
12292 | 0 | } |
12293 | 0 | return true; |
12294 | 0 | } |
12295 | | |
12296 | | static const JSJitInfo limits_methodinfo = { |
12297 | | { (JSJitGetterOp)limits }, |
12298 | | { prototypes::id::WebGPUDevice }, |
12299 | | { PrototypeTraits<prototypes::id::WebGPUDevice>::Depth }, |
12300 | | JSJitInfo::Method, |
12301 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
12302 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
12303 | | false, /* isInfallible. False in setters. */ |
12304 | | false, /* isMovable. Not relevant for setters. */ |
12305 | | false, /* isEliminatable. Not relevant for setters. */ |
12306 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
12307 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
12308 | | false, /* isTypedMethod. Only relevant for methods. */ |
12309 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
12310 | | }; |
12311 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
12312 | | static_assert(0 < 1, "There is no slot for us"); |
12313 | | |
12314 | | MOZ_CAN_RUN_SCRIPT static bool |
12315 | | createBuffer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Device* self, const JSJitMethodCallArgs& args) |
12316 | 0 | { |
12317 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUDevice.createBuffer", DOM, cx); |
12318 | 0 |
|
12319 | 0 | binding_detail::FastWebGPUBufferDescriptor arg0; |
12320 | 0 | if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of WebGPUDevice.createBuffer", false)) { |
12321 | 0 | return false; |
12322 | 0 | } |
12323 | 0 | auto result(StrongOrRawPtr<mozilla::webgpu::Buffer>(self->CreateBuffer(Constify(arg0)))); |
12324 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
12325 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
12326 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
12327 | 0 | return false; |
12328 | 0 | } |
12329 | 0 | return true; |
12330 | 0 | } |
12331 | | |
12332 | | static const JSJitInfo createBuffer_methodinfo = { |
12333 | | { (JSJitGetterOp)createBuffer }, |
12334 | | { prototypes::id::WebGPUDevice }, |
12335 | | { PrototypeTraits<prototypes::id::WebGPUDevice>::Depth }, |
12336 | | JSJitInfo::Method, |
12337 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
12338 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
12339 | | false, /* isInfallible. False in setters. */ |
12340 | | false, /* isMovable. Not relevant for setters. */ |
12341 | | false, /* isEliminatable. Not relevant for setters. */ |
12342 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
12343 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
12344 | | false, /* isTypedMethod. Only relevant for methods. */ |
12345 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
12346 | | }; |
12347 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
12348 | | static_assert(0 < 1, "There is no slot for us"); |
12349 | | |
12350 | | MOZ_CAN_RUN_SCRIPT static bool |
12351 | | createTexture(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Device* self, const JSJitMethodCallArgs& args) |
12352 | 0 | { |
12353 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUDevice.createTexture", DOM, cx); |
12354 | 0 |
|
12355 | 0 | binding_detail::FastWebGPUTextureDescriptor arg0; |
12356 | 0 | if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of WebGPUDevice.createTexture", false)) { |
12357 | 0 | return false; |
12358 | 0 | } |
12359 | 0 | auto result(StrongOrRawPtr<mozilla::webgpu::Texture>(self->CreateTexture(Constify(arg0)))); |
12360 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
12361 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
12362 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
12363 | 0 | return false; |
12364 | 0 | } |
12365 | 0 | return true; |
12366 | 0 | } |
12367 | | |
12368 | | static const JSJitInfo createTexture_methodinfo = { |
12369 | | { (JSJitGetterOp)createTexture }, |
12370 | | { prototypes::id::WebGPUDevice }, |
12371 | | { PrototypeTraits<prototypes::id::WebGPUDevice>::Depth }, |
12372 | | JSJitInfo::Method, |
12373 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
12374 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
12375 | | false, /* isInfallible. False in setters. */ |
12376 | | false, /* isMovable. Not relevant for setters. */ |
12377 | | false, /* isEliminatable. Not relevant for setters. */ |
12378 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
12379 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
12380 | | false, /* isTypedMethod. Only relevant for methods. */ |
12381 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
12382 | | }; |
12383 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
12384 | | static_assert(0 < 1, "There is no slot for us"); |
12385 | | |
12386 | | MOZ_CAN_RUN_SCRIPT static bool |
12387 | | createSampler(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Device* self, const JSJitMethodCallArgs& args) |
12388 | 0 | { |
12389 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUDevice.createSampler", DOM, cx); |
12390 | 0 |
|
12391 | 0 | binding_detail::FastWebGPUSamplerDescriptor arg0; |
12392 | 0 | if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of WebGPUDevice.createSampler", false)) { |
12393 | 0 | return false; |
12394 | 0 | } |
12395 | 0 | auto result(StrongOrRawPtr<mozilla::webgpu::Sampler>(self->CreateSampler(Constify(arg0)))); |
12396 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
12397 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
12398 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
12399 | 0 | return false; |
12400 | 0 | } |
12401 | 0 | return true; |
12402 | 0 | } |
12403 | | |
12404 | | static const JSJitInfo createSampler_methodinfo = { |
12405 | | { (JSJitGetterOp)createSampler }, |
12406 | | { prototypes::id::WebGPUDevice }, |
12407 | | { PrototypeTraits<prototypes::id::WebGPUDevice>::Depth }, |
12408 | | JSJitInfo::Method, |
12409 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
12410 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
12411 | | false, /* isInfallible. False in setters. */ |
12412 | | false, /* isMovable. Not relevant for setters. */ |
12413 | | false, /* isEliminatable. Not relevant for setters. */ |
12414 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
12415 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
12416 | | false, /* isTypedMethod. Only relevant for methods. */ |
12417 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
12418 | | }; |
12419 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
12420 | | static_assert(0 < 1, "There is no slot for us"); |
12421 | | |
12422 | | MOZ_CAN_RUN_SCRIPT static bool |
12423 | | createBindGroupLayout(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Device* self, const JSJitMethodCallArgs& args) |
12424 | 0 | { |
12425 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUDevice.createBindGroupLayout", DOM, cx); |
12426 | 0 |
|
12427 | 0 | binding_detail::FastWebGPUBindGroupLayoutDescriptor arg0; |
12428 | 0 | if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of WebGPUDevice.createBindGroupLayout", false)) { |
12429 | 0 | return false; |
12430 | 0 | } |
12431 | 0 | auto result(StrongOrRawPtr<mozilla::webgpu::BindGroupLayout>(self->CreateBindGroupLayout(Constify(arg0)))); |
12432 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
12433 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
12434 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
12435 | 0 | return false; |
12436 | 0 | } |
12437 | 0 | return true; |
12438 | 0 | } |
12439 | | |
12440 | | static const JSJitInfo createBindGroupLayout_methodinfo = { |
12441 | | { (JSJitGetterOp)createBindGroupLayout }, |
12442 | | { prototypes::id::WebGPUDevice }, |
12443 | | { PrototypeTraits<prototypes::id::WebGPUDevice>::Depth }, |
12444 | | JSJitInfo::Method, |
12445 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
12446 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
12447 | | false, /* isInfallible. False in setters. */ |
12448 | | false, /* isMovable. Not relevant for setters. */ |
12449 | | false, /* isEliminatable. Not relevant for setters. */ |
12450 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
12451 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
12452 | | false, /* isTypedMethod. Only relevant for methods. */ |
12453 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
12454 | | }; |
12455 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
12456 | | static_assert(0 < 1, "There is no slot for us"); |
12457 | | |
12458 | | MOZ_CAN_RUN_SCRIPT static bool |
12459 | | createPipelineLayout(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Device* self, const JSJitMethodCallArgs& args) |
12460 | 0 | { |
12461 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUDevice.createPipelineLayout", DOM, cx); |
12462 | 0 |
|
12463 | 0 | binding_detail::FastWebGPUPipelineLayoutDescriptor arg0; |
12464 | 0 | if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of WebGPUDevice.createPipelineLayout", false)) { |
12465 | 0 | return false; |
12466 | 0 | } |
12467 | 0 | auto result(StrongOrRawPtr<mozilla::webgpu::PipelineLayout>(self->CreatePipelineLayout(Constify(arg0)))); |
12468 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
12469 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
12470 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
12471 | 0 | return false; |
12472 | 0 | } |
12473 | 0 | return true; |
12474 | 0 | } |
12475 | | |
12476 | | static const JSJitInfo createPipelineLayout_methodinfo = { |
12477 | | { (JSJitGetterOp)createPipelineLayout }, |
12478 | | { prototypes::id::WebGPUDevice }, |
12479 | | { PrototypeTraits<prototypes::id::WebGPUDevice>::Depth }, |
12480 | | JSJitInfo::Method, |
12481 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
12482 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
12483 | | false, /* isInfallible. False in setters. */ |
12484 | | false, /* isMovable. Not relevant for setters. */ |
12485 | | false, /* isEliminatable. Not relevant for setters. */ |
12486 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
12487 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
12488 | | false, /* isTypedMethod. Only relevant for methods. */ |
12489 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
12490 | | }; |
12491 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
12492 | | static_assert(0 < 1, "There is no slot for us"); |
12493 | | |
12494 | | MOZ_CAN_RUN_SCRIPT static bool |
12495 | | createBindGroup(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Device* self, const JSJitMethodCallArgs& args) |
12496 | 0 | { |
12497 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUDevice.createBindGroup", DOM, cx); |
12498 | 0 |
|
12499 | 0 | binding_detail::FastWebGPUBindGroupDescriptor arg0; |
12500 | 0 | if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of WebGPUDevice.createBindGroup", false)) { |
12501 | 0 | return false; |
12502 | 0 | } |
12503 | 0 | auto result(StrongOrRawPtr<mozilla::webgpu::BindGroup>(self->CreateBindGroup(Constify(arg0)))); |
12504 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
12505 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
12506 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
12507 | 0 | return false; |
12508 | 0 | } |
12509 | 0 | return true; |
12510 | 0 | } |
12511 | | |
12512 | | static const JSJitInfo createBindGroup_methodinfo = { |
12513 | | { (JSJitGetterOp)createBindGroup }, |
12514 | | { prototypes::id::WebGPUDevice }, |
12515 | | { PrototypeTraits<prototypes::id::WebGPUDevice>::Depth }, |
12516 | | JSJitInfo::Method, |
12517 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
12518 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
12519 | | false, /* isInfallible. False in setters. */ |
12520 | | false, /* isMovable. Not relevant for setters. */ |
12521 | | false, /* isEliminatable. Not relevant for setters. */ |
12522 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
12523 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
12524 | | false, /* isTypedMethod. Only relevant for methods. */ |
12525 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
12526 | | }; |
12527 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
12528 | | static_assert(0 < 1, "There is no slot for us"); |
12529 | | |
12530 | | MOZ_CAN_RUN_SCRIPT static bool |
12531 | | createBlendState(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Device* self, const JSJitMethodCallArgs& args) |
12532 | 0 | { |
12533 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUDevice.createBlendState", DOM, cx); |
12534 | 0 |
|
12535 | 0 | binding_detail::FastWebGPUBlendStateDescriptor arg0; |
12536 | 0 | if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of WebGPUDevice.createBlendState", false)) { |
12537 | 0 | return false; |
12538 | 0 | } |
12539 | 0 | auto result(StrongOrRawPtr<mozilla::webgpu::BlendState>(self->CreateBlendState(Constify(arg0)))); |
12540 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
12541 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
12542 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
12543 | 0 | return false; |
12544 | 0 | } |
12545 | 0 | return true; |
12546 | 0 | } |
12547 | | |
12548 | | static const JSJitInfo createBlendState_methodinfo = { |
12549 | | { (JSJitGetterOp)createBlendState }, |
12550 | | { prototypes::id::WebGPUDevice }, |
12551 | | { PrototypeTraits<prototypes::id::WebGPUDevice>::Depth }, |
12552 | | JSJitInfo::Method, |
12553 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
12554 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
12555 | | false, /* isInfallible. False in setters. */ |
12556 | | false, /* isMovable. Not relevant for setters. */ |
12557 | | false, /* isEliminatable. Not relevant for setters. */ |
12558 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
12559 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
12560 | | false, /* isTypedMethod. Only relevant for methods. */ |
12561 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
12562 | | }; |
12563 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
12564 | | static_assert(0 < 1, "There is no slot for us"); |
12565 | | |
12566 | | MOZ_CAN_RUN_SCRIPT static bool |
12567 | | createDepthStencilState(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Device* self, const JSJitMethodCallArgs& args) |
12568 | 0 | { |
12569 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUDevice.createDepthStencilState", DOM, cx); |
12570 | 0 |
|
12571 | 0 | binding_detail::FastWebGPUDepthStencilStateDescriptor arg0; |
12572 | 0 | if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of WebGPUDevice.createDepthStencilState", false)) { |
12573 | 0 | return false; |
12574 | 0 | } |
12575 | 0 | auto result(StrongOrRawPtr<mozilla::webgpu::DepthStencilState>(self->CreateDepthStencilState(Constify(arg0)))); |
12576 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
12577 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
12578 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
12579 | 0 | return false; |
12580 | 0 | } |
12581 | 0 | return true; |
12582 | 0 | } |
12583 | | |
12584 | | static const JSJitInfo createDepthStencilState_methodinfo = { |
12585 | | { (JSJitGetterOp)createDepthStencilState }, |
12586 | | { prototypes::id::WebGPUDevice }, |
12587 | | { PrototypeTraits<prototypes::id::WebGPUDevice>::Depth }, |
12588 | | JSJitInfo::Method, |
12589 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
12590 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
12591 | | false, /* isInfallible. False in setters. */ |
12592 | | false, /* isMovable. Not relevant for setters. */ |
12593 | | false, /* isEliminatable. Not relevant for setters. */ |
12594 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
12595 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
12596 | | false, /* isTypedMethod. Only relevant for methods. */ |
12597 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
12598 | | }; |
12599 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
12600 | | static_assert(0 < 1, "There is no slot for us"); |
12601 | | |
12602 | | MOZ_CAN_RUN_SCRIPT static bool |
12603 | | createInputState(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Device* self, const JSJitMethodCallArgs& args) |
12604 | 0 | { |
12605 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUDevice.createInputState", DOM, cx); |
12606 | 0 |
|
12607 | 0 | binding_detail::FastWebGPUInputStateDescriptor arg0; |
12608 | 0 | if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of WebGPUDevice.createInputState", false)) { |
12609 | 0 | return false; |
12610 | 0 | } |
12611 | 0 | auto result(StrongOrRawPtr<mozilla::webgpu::InputState>(self->CreateInputState(Constify(arg0)))); |
12612 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
12613 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
12614 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
12615 | 0 | return false; |
12616 | 0 | } |
12617 | 0 | return true; |
12618 | 0 | } |
12619 | | |
12620 | | static const JSJitInfo createInputState_methodinfo = { |
12621 | | { (JSJitGetterOp)createInputState }, |
12622 | | { prototypes::id::WebGPUDevice }, |
12623 | | { PrototypeTraits<prototypes::id::WebGPUDevice>::Depth }, |
12624 | | JSJitInfo::Method, |
12625 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
12626 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
12627 | | false, /* isInfallible. False in setters. */ |
12628 | | false, /* isMovable. Not relevant for setters. */ |
12629 | | false, /* isEliminatable. Not relevant for setters. */ |
12630 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
12631 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
12632 | | false, /* isTypedMethod. Only relevant for methods. */ |
12633 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
12634 | | }; |
12635 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
12636 | | static_assert(0 < 1, "There is no slot for us"); |
12637 | | |
12638 | | MOZ_CAN_RUN_SCRIPT static bool |
12639 | | createShaderModule(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Device* self, const JSJitMethodCallArgs& args) |
12640 | 0 | { |
12641 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUDevice.createShaderModule", DOM, cx); |
12642 | 0 |
|
12643 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
12644 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebGPUDevice.createShaderModule"); |
12645 | 0 | } |
12646 | 0 | RootedDictionary<binding_detail::FastWebGPUShaderModuleDescriptor> arg0(cx); |
12647 | 0 | if (!arg0.Init(cx, args[0], "Argument 1 of WebGPUDevice.createShaderModule", false)) { |
12648 | 0 | return false; |
12649 | 0 | } |
12650 | 0 | auto result(StrongOrRawPtr<mozilla::webgpu::ShaderModule>(self->CreateShaderModule(Constify(arg0)))); |
12651 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
12652 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
12653 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
12654 | 0 | return false; |
12655 | 0 | } |
12656 | 0 | return true; |
12657 | 0 | } |
12658 | | |
12659 | | static const JSJitInfo createShaderModule_methodinfo = { |
12660 | | { (JSJitGetterOp)createShaderModule }, |
12661 | | { prototypes::id::WebGPUDevice }, |
12662 | | { PrototypeTraits<prototypes::id::WebGPUDevice>::Depth }, |
12663 | | JSJitInfo::Method, |
12664 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
12665 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
12666 | | false, /* isInfallible. False in setters. */ |
12667 | | false, /* isMovable. Not relevant for setters. */ |
12668 | | false, /* isEliminatable. Not relevant for setters. */ |
12669 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
12670 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
12671 | | false, /* isTypedMethod. Only relevant for methods. */ |
12672 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
12673 | | }; |
12674 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
12675 | | static_assert(0 < 1, "There is no slot for us"); |
12676 | | |
12677 | | MOZ_CAN_RUN_SCRIPT static bool |
12678 | | createAttachmentState(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Device* self, const JSJitMethodCallArgs& args) |
12679 | 0 | { |
12680 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUDevice.createAttachmentState", DOM, cx); |
12681 | 0 |
|
12682 | 0 | binding_detail::FastWebGPUAttachmentStateDescriptor arg0; |
12683 | 0 | if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of WebGPUDevice.createAttachmentState", false)) { |
12684 | 0 | return false; |
12685 | 0 | } |
12686 | 0 | auto result(StrongOrRawPtr<mozilla::webgpu::AttachmentState>(self->CreateAttachmentState(Constify(arg0)))); |
12687 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
12688 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
12689 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
12690 | 0 | return false; |
12691 | 0 | } |
12692 | 0 | return true; |
12693 | 0 | } |
12694 | | |
12695 | | static const JSJitInfo createAttachmentState_methodinfo = { |
12696 | | { (JSJitGetterOp)createAttachmentState }, |
12697 | | { prototypes::id::WebGPUDevice }, |
12698 | | { PrototypeTraits<prototypes::id::WebGPUDevice>::Depth }, |
12699 | | JSJitInfo::Method, |
12700 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
12701 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
12702 | | false, /* isInfallible. False in setters. */ |
12703 | | false, /* isMovable. Not relevant for setters. */ |
12704 | | false, /* isEliminatable. Not relevant for setters. */ |
12705 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
12706 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
12707 | | false, /* isTypedMethod. Only relevant for methods. */ |
12708 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
12709 | | }; |
12710 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
12711 | | static_assert(0 < 1, "There is no slot for us"); |
12712 | | |
12713 | | MOZ_CAN_RUN_SCRIPT static bool |
12714 | | createComputePipeline(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Device* self, const JSJitMethodCallArgs& args) |
12715 | 0 | { |
12716 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUDevice.createComputePipeline", DOM, cx); |
12717 | 0 |
|
12718 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
12719 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebGPUDevice.createComputePipeline"); |
12720 | 0 | } |
12721 | 0 | binding_detail::FastWebGPUComputePipelineDescriptor arg0; |
12722 | 0 | if (!arg0.Init(cx, args[0], "Argument 1 of WebGPUDevice.createComputePipeline", false)) { |
12723 | 0 | return false; |
12724 | 0 | } |
12725 | 0 | auto result(StrongOrRawPtr<mozilla::webgpu::ComputePipeline>(self->CreateComputePipeline(Constify(arg0)))); |
12726 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
12727 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
12728 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
12729 | 0 | return false; |
12730 | 0 | } |
12731 | 0 | return true; |
12732 | 0 | } |
12733 | | |
12734 | | static const JSJitInfo createComputePipeline_methodinfo = { |
12735 | | { (JSJitGetterOp)createComputePipeline }, |
12736 | | { prototypes::id::WebGPUDevice }, |
12737 | | { PrototypeTraits<prototypes::id::WebGPUDevice>::Depth }, |
12738 | | JSJitInfo::Method, |
12739 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
12740 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
12741 | | false, /* isInfallible. False in setters. */ |
12742 | | false, /* isMovable. Not relevant for setters. */ |
12743 | | false, /* isEliminatable. Not relevant for setters. */ |
12744 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
12745 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
12746 | | false, /* isTypedMethod. Only relevant for methods. */ |
12747 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
12748 | | }; |
12749 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
12750 | | static_assert(0 < 1, "There is no slot for us"); |
12751 | | |
12752 | | MOZ_CAN_RUN_SCRIPT static bool |
12753 | | createRenderPipeline(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Device* self, const JSJitMethodCallArgs& args) |
12754 | 0 | { |
12755 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUDevice.createRenderPipeline", DOM, cx); |
12756 | 0 |
|
12757 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
12758 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebGPUDevice.createRenderPipeline"); |
12759 | 0 | } |
12760 | 0 | binding_detail::FastWebGPURenderPipelineDescriptor arg0; |
12761 | 0 | if (!arg0.Init(cx, args[0], "Argument 1 of WebGPUDevice.createRenderPipeline", false)) { |
12762 | 0 | return false; |
12763 | 0 | } |
12764 | 0 | auto result(StrongOrRawPtr<mozilla::webgpu::RenderPipeline>(self->CreateRenderPipeline(Constify(arg0)))); |
12765 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
12766 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
12767 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
12768 | 0 | return false; |
12769 | 0 | } |
12770 | 0 | return true; |
12771 | 0 | } |
12772 | | |
12773 | | static const JSJitInfo createRenderPipeline_methodinfo = { |
12774 | | { (JSJitGetterOp)createRenderPipeline }, |
12775 | | { prototypes::id::WebGPUDevice }, |
12776 | | { PrototypeTraits<prototypes::id::WebGPUDevice>::Depth }, |
12777 | | JSJitInfo::Method, |
12778 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
12779 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
12780 | | false, /* isInfallible. False in setters. */ |
12781 | | false, /* isMovable. Not relevant for setters. */ |
12782 | | false, /* isEliminatable. Not relevant for setters. */ |
12783 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
12784 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
12785 | | false, /* isTypedMethod. Only relevant for methods. */ |
12786 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
12787 | | }; |
12788 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
12789 | | static_assert(0 < 1, "There is no slot for us"); |
12790 | | |
12791 | | MOZ_CAN_RUN_SCRIPT static bool |
12792 | | createCommandEncoder(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Device* self, const JSJitMethodCallArgs& args) |
12793 | 0 | { |
12794 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUDevice.createCommandEncoder", DOM, cx); |
12795 | 0 |
|
12796 | 0 | binding_detail::FastWebGPUCommandEncoderDescriptor arg0; |
12797 | 0 | if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of WebGPUDevice.createCommandEncoder", false)) { |
12798 | 0 | return false; |
12799 | 0 | } |
12800 | 0 | auto result(StrongOrRawPtr<mozilla::webgpu::CommandEncoder>(self->CreateCommandEncoder(Constify(arg0)))); |
12801 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
12802 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
12803 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
12804 | 0 | return false; |
12805 | 0 | } |
12806 | 0 | return true; |
12807 | 0 | } |
12808 | | |
12809 | | static const JSJitInfo createCommandEncoder_methodinfo = { |
12810 | | { (JSJitGetterOp)createCommandEncoder }, |
12811 | | { prototypes::id::WebGPUDevice }, |
12812 | | { PrototypeTraits<prototypes::id::WebGPUDevice>::Depth }, |
12813 | | JSJitInfo::Method, |
12814 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
12815 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
12816 | | false, /* isInfallible. False in setters. */ |
12817 | | false, /* isMovable. Not relevant for setters. */ |
12818 | | false, /* isEliminatable. Not relevant for setters. */ |
12819 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
12820 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
12821 | | false, /* isTypedMethod. Only relevant for methods. */ |
12822 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
12823 | | }; |
12824 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
12825 | | static_assert(0 < 1, "There is no slot for us"); |
12826 | | |
12827 | | MOZ_CAN_RUN_SCRIPT static bool |
12828 | | getQueue(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Device* self, const JSJitMethodCallArgs& args) |
12829 | 0 | { |
12830 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUDevice.getQueue", DOM, cx); |
12831 | 0 |
|
12832 | 0 | auto result(StrongOrRawPtr<mozilla::webgpu::Queue>(self->GetQueue())); |
12833 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
12834 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
12835 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
12836 | 0 | return false; |
12837 | 0 | } |
12838 | 0 | return true; |
12839 | 0 | } |
12840 | | |
12841 | | static const JSJitInfo getQueue_methodinfo = { |
12842 | | { (JSJitGetterOp)getQueue }, |
12843 | | { prototypes::id::WebGPUDevice }, |
12844 | | { PrototypeTraits<prototypes::id::WebGPUDevice>::Depth }, |
12845 | | JSJitInfo::Method, |
12846 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
12847 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
12848 | | false, /* isInfallible. False in setters. */ |
12849 | | false, /* isMovable. Not relevant for setters. */ |
12850 | | false, /* isEliminatable. Not relevant for setters. */ |
12851 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
12852 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
12853 | | false, /* isTypedMethod. Only relevant for methods. */ |
12854 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
12855 | | }; |
12856 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
12857 | | static_assert(0 < 1, "There is no slot for us"); |
12858 | | |
12859 | | MOZ_CAN_RUN_SCRIPT static bool |
12860 | | get_onLog(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Device* self, JSJitGetterCallArgs args) |
12861 | 0 | { |
12862 | 0 | AUTO_PROFILER_LABEL_FAST("get WebGPUDevice.onLog", DOM, cx); |
12863 | 0 |
|
12864 | 0 | RefPtr<WebGPULogCallback> result(self->OnLog()); |
12865 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
12866 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
12867 | 0 | if (!MaybeWrapObjectValue(cx, args.rval())) { |
12868 | 0 | return false; |
12869 | 0 | } |
12870 | 0 | return true; |
12871 | 0 | } |
12872 | | |
12873 | | MOZ_CAN_RUN_SCRIPT static bool |
12874 | | set_onLog(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Device* self, JSJitSetterCallArgs args) |
12875 | 0 | { |
12876 | 0 | AUTO_PROFILER_LABEL_FAST("set WebGPUDevice.onLog", DOM, cx); |
12877 | 0 |
|
12878 | 0 | RootedCallback<OwningNonNull<binding_detail::FastWebGPULogCallback>> arg0(cx); |
12879 | 0 | if (args[0].isObject()) { |
12880 | 0 | if (JS::IsCallable(&args[0].toObject())) { |
12881 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
12882 | 0 | arg0 = new binding_detail::FastWebGPULogCallback(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
12883 | 0 | } |
12884 | 0 | } else { |
12885 | 0 | ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Value being assigned to WebGPUDevice.onLog"); |
12886 | 0 | return false; |
12887 | 0 | } |
12888 | 0 | } else { |
12889 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Value being assigned to WebGPUDevice.onLog"); |
12890 | 0 | return false; |
12891 | 0 | } |
12892 | 0 | self->SetOnLog(NonNullHelper(arg0)); |
12893 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
12894 | 0 |
|
12895 | 0 | return true; |
12896 | 0 | } |
12897 | | |
12898 | | static const JSJitInfo onLog_getterinfo = { |
12899 | | { (JSJitGetterOp)get_onLog }, |
12900 | | { prototypes::id::WebGPUDevice }, |
12901 | | { PrototypeTraits<prototypes::id::WebGPUDevice>::Depth }, |
12902 | | JSJitInfo::Getter, |
12903 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
12904 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
12905 | | false, /* isInfallible. False in setters. */ |
12906 | | false, /* isMovable. Not relevant for setters. */ |
12907 | | false, /* isEliminatable. Not relevant for setters. */ |
12908 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
12909 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
12910 | | false, /* isTypedMethod. Only relevant for methods. */ |
12911 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
12912 | | }; |
12913 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
12914 | | static_assert(0 < 1, "There is no slot for us"); |
12915 | | static const JSJitInfo onLog_setterinfo = { |
12916 | | { (JSJitGetterOp)set_onLog }, |
12917 | | { prototypes::id::WebGPUDevice }, |
12918 | | { PrototypeTraits<prototypes::id::WebGPUDevice>::Depth }, |
12919 | | JSJitInfo::Setter, |
12920 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
12921 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
12922 | | false, /* isInfallible. False in setters. */ |
12923 | | false, /* isMovable. Not relevant for setters. */ |
12924 | | false, /* isEliminatable. Not relevant for setters. */ |
12925 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
12926 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
12927 | | false, /* isTypedMethod. Only relevant for methods. */ |
12928 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
12929 | | }; |
12930 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
12931 | | static_assert(0 < 1, "There is no slot for us"); |
12932 | | |
12933 | | MOZ_CAN_RUN_SCRIPT static bool |
12934 | | getObjectStatus(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Device* self, const JSJitMethodCallArgs& args) |
12935 | 0 | { |
12936 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUDevice.getObjectStatus", DOM, cx); |
12937 | 0 |
|
12938 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
12939 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebGPUDevice.getObjectStatus"); |
12940 | 0 | } |
12941 | 0 | WebGPUBufferOrWebGPUTexture arg0; |
12942 | 0 | WebGPUBufferOrWebGPUTextureArgument arg0_holder(arg0); |
12943 | 0 | { |
12944 | 0 | bool done = false, failed = false, tryNext; |
12945 | 0 | if (args[0].isObject()) { |
12946 | 0 | done = (failed = !arg0_holder.TrySetToWebGPUBuffer(cx, args[0], tryNext, false)) || !tryNext || |
12947 | 0 | (failed = !arg0_holder.TrySetToWebGPUTexture(cx, args[0], tryNext, false)) || !tryNext; |
12948 | 0 |
|
12949 | 0 | } |
12950 | 0 | if (failed) { |
12951 | 0 | return false; |
12952 | 0 | } |
12953 | 0 | if (!done) { |
12954 | 0 | ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of WebGPUDevice.getObjectStatus", "WebGPUBuffer, WebGPUTexture"); |
12955 | 0 | return false; |
12956 | 0 | } |
12957 | 0 | } |
12958 | 0 | auto result(StrongOrRawPtr<Promise>(self->GetObjectStatus(Constify(arg0)))); |
12959 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
12960 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
12961 | 0 | return false; |
12962 | 0 | } |
12963 | 0 | return true; |
12964 | 0 | } |
12965 | | |
12966 | | MOZ_CAN_RUN_SCRIPT static bool |
12967 | | getObjectStatus_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Device* self, const JSJitMethodCallArgs& args) |
12968 | 0 | { |
12969 | 0 | bool ok = getObjectStatus(cx, obj, self, args); |
12970 | 0 | if (ok) { |
12971 | 0 | return true; |
12972 | 0 | } |
12973 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
12974 | 0 | } |
12975 | | |
12976 | | static const JSJitInfo getObjectStatus_methodinfo = { |
12977 | | { (JSJitGetterOp)getObjectStatus_promiseWrapper }, |
12978 | | { prototypes::id::WebGPUDevice }, |
12979 | | { PrototypeTraits<prototypes::id::WebGPUDevice>::Depth }, |
12980 | | JSJitInfo::Method, |
12981 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
12982 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
12983 | | false, /* isInfallible. False in setters. */ |
12984 | | false, /* isMovable. Not relevant for setters. */ |
12985 | | false, /* isEliminatable. Not relevant for setters. */ |
12986 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
12987 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
12988 | | false, /* isTypedMethod. Only relevant for methods. */ |
12989 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
12990 | | }; |
12991 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
12992 | | static_assert(0 < 1, "There is no slot for us"); |
12993 | | |
12994 | | static bool |
12995 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
12996 | 0 | { |
12997 | 0 | mozilla::webgpu::Device* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Device>(obj); |
12998 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
12999 | 0 | // obviously can't preserve if we're not initialized. |
13000 | 0 | if (self && self->GetWrapperPreserveColor()) { |
13001 | 0 | PreserveWrapper(self); |
13002 | 0 | } |
13003 | 0 | return true; |
13004 | 0 | } |
13005 | | |
13006 | | static void |
13007 | | _finalize(js::FreeOp* fop, JSObject* obj) |
13008 | 0 | { |
13009 | 0 | mozilla::webgpu::Device* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Device>(obj); |
13010 | 0 | if (self) { |
13011 | 0 | ClearWrapper(self, self, obj); |
13012 | 0 | AddForDeferredFinalization<mozilla::webgpu::Device>(self); |
13013 | 0 | } |
13014 | 0 | } |
13015 | | |
13016 | | static size_t |
13017 | | _objectMoved(JSObject* obj, JSObject* old) |
13018 | 0 | { |
13019 | 0 | mozilla::webgpu::Device* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Device>(obj); |
13020 | 0 | if (self) { |
13021 | 0 | UpdateWrapper(self, self, obj, old); |
13022 | 0 | } |
13023 | 0 |
|
13024 | 0 | return 0; |
13025 | 0 | } |
13026 | | |
13027 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
13028 | | #if defined(__clang__) |
13029 | | #pragma clang diagnostic push |
13030 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
13031 | | #endif |
13032 | | static const JSFunctionSpec sMethods_specs[] = { |
13033 | | JS_FNSPEC("extensions", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&extensions_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
13034 | | JS_FNSPEC("limits", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&limits_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
13035 | | JS_FNSPEC("createBuffer", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createBuffer_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
13036 | | JS_FNSPEC("createTexture", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createTexture_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
13037 | | JS_FNSPEC("createSampler", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createSampler_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
13038 | | JS_FNSPEC("createBindGroupLayout", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createBindGroupLayout_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
13039 | | JS_FNSPEC("createPipelineLayout", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createPipelineLayout_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
13040 | | JS_FNSPEC("createBindGroup", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createBindGroup_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
13041 | | JS_FNSPEC("createBlendState", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createBlendState_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
13042 | | JS_FNSPEC("createDepthStencilState", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createDepthStencilState_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
13043 | | JS_FNSPEC("createInputState", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createInputState_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
13044 | | JS_FNSPEC("createShaderModule", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createShaderModule_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
13045 | | JS_FNSPEC("createAttachmentState", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createAttachmentState_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
13046 | | JS_FNSPEC("createComputePipeline", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createComputePipeline_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
13047 | | JS_FNSPEC("createRenderPipeline", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createRenderPipeline_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
13048 | | JS_FNSPEC("createCommandEncoder", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createCommandEncoder_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
13049 | | JS_FNSPEC("getQueue", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getQueue_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
13050 | | JS_FNSPEC("getObjectStatus", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&getObjectStatus_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
13051 | | JS_FS_END |
13052 | | }; |
13053 | | #if defined(__clang__) |
13054 | | #pragma clang diagnostic pop |
13055 | | #endif |
13056 | | |
13057 | | |
13058 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
13059 | | { nullptr, &sMethods_specs[0] }, |
13060 | | { nullptr, nullptr } |
13061 | | }; |
13062 | | |
13063 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
13064 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
13065 | | static_assert(18 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
13066 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
13067 | | |
13068 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
13069 | | #if defined(__clang__) |
13070 | | #pragma clang diagnostic push |
13071 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
13072 | | #endif |
13073 | | static const JSPropertySpec sAttributes_specs[] = { |
13074 | | { "adapter", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &adapter_getterinfo, nullptr, nullptr }, |
13075 | | { "onLog", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onLog_getterinfo, GenericSetter<NormalThisPolicy>, &onLog_setterinfo }, |
13076 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
13077 | | }; |
13078 | | #if defined(__clang__) |
13079 | | #pragma clang diagnostic pop |
13080 | | #endif |
13081 | | |
13082 | | |
13083 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
13084 | | { nullptr, &sAttributes_specs[0] }, |
13085 | | { nullptr, nullptr } |
13086 | | }; |
13087 | | |
13088 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
13089 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
13090 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
13091 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
13092 | | |
13093 | | |
13094 | | static uint16_t sNativeProperties_sortedPropertyIndices[20]; |
13095 | | static PropertyInfo sNativeProperties_propertyInfos[20]; |
13096 | | |
13097 | | static const NativePropertiesN<2> sNativeProperties = { |
13098 | | false, 0, |
13099 | | false, 0, |
13100 | | true, 0 /* sMethods */, |
13101 | | true, 1 /* sAttributes */, |
13102 | | false, 0, |
13103 | | false, 0, |
13104 | | false, 0, |
13105 | | -1, |
13106 | | 20, |
13107 | | sNativeProperties_sortedPropertyIndices, |
13108 | | { |
13109 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
13110 | | { sAttributes, &sNativeProperties_propertyInfos[18] } |
13111 | | } |
13112 | | }; |
13113 | | static_assert(20 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
13114 | | "We have a property info count that is oversized"); |
13115 | | |
13116 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
13117 | | { |
13118 | | "Function", |
13119 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
13120 | | &sBoringInterfaceObjectClassClassOps, |
13121 | | JS_NULL_CLASS_SPEC, |
13122 | | JS_NULL_CLASS_EXT, |
13123 | | &sInterfaceObjectClassObjectOps |
13124 | | }, |
13125 | | eInterface, |
13126 | | true, |
13127 | | prototypes::id::WebGPUDevice, |
13128 | | PrototypeTraits<prototypes::id::WebGPUDevice>::Depth, |
13129 | | sNativePropertyHooks, |
13130 | | "function WebGPUDevice() {\n [native code]\n}", |
13131 | | JS::GetRealmFunctionPrototype |
13132 | | }; |
13133 | | |
13134 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
13135 | | { |
13136 | | "WebGPUDevicePrototype", |
13137 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
13138 | | JS_NULL_CLASS_OPS, |
13139 | | JS_NULL_CLASS_SPEC, |
13140 | | JS_NULL_CLASS_EXT, |
13141 | | JS_NULL_OBJECT_OPS |
13142 | | }, |
13143 | | eInterfacePrototype, |
13144 | | false, |
13145 | | prototypes::id::WebGPUDevice, |
13146 | | PrototypeTraits<prototypes::id::WebGPUDevice>::Depth, |
13147 | | sNativePropertyHooks, |
13148 | | "[object WebGPUDevicePrototype]", |
13149 | | JS::GetRealmObjectPrototype |
13150 | | }; |
13151 | | |
13152 | | bool |
13153 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
13154 | 0 | { |
13155 | 0 | static bool sPrefValue; |
13156 | 0 | static bool sPrefCacheSetUp = false; |
13157 | 0 | if (!sPrefCacheSetUp) { |
13158 | 0 | sPrefCacheSetUp = true; |
13159 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
13160 | 0 | } |
13161 | 0 |
|
13162 | 0 | return sPrefValue; |
13163 | 0 | } |
13164 | | |
13165 | | static const js::ClassOps sClassOps = { |
13166 | | _addProperty, /* addProperty */ |
13167 | | nullptr, /* delProperty */ |
13168 | | nullptr, /* enumerate */ |
13169 | | nullptr, /* newEnumerate */ |
13170 | | nullptr, /* resolve */ |
13171 | | nullptr, /* mayResolve */ |
13172 | | _finalize, /* finalize */ |
13173 | | nullptr, /* call */ |
13174 | | nullptr, /* hasInstance */ |
13175 | | nullptr, /* construct */ |
13176 | | nullptr, /* trace */ |
13177 | | }; |
13178 | | |
13179 | | static const js::ClassExtension sClassExtension = { |
13180 | | nullptr, /* weakmapKeyDelegateOp */ |
13181 | | _objectMoved /* objectMovedOp */ |
13182 | | }; |
13183 | | |
13184 | | static const DOMJSClass sClass = { |
13185 | | { "WebGPUDevice", |
13186 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
13187 | | &sClassOps, |
13188 | | JS_NULL_CLASS_SPEC, |
13189 | | &sClassExtension, |
13190 | | JS_NULL_OBJECT_OPS |
13191 | | }, |
13192 | | { prototypes::id::WebGPUDevice, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
13193 | | IsBaseOf<nsISupports, mozilla::webgpu::Device >::value, |
13194 | | sNativePropertyHooks, |
13195 | | FindAssociatedGlobalForNative<mozilla::webgpu::Device>::Get, |
13196 | | GetProtoObjectHandle, |
13197 | | GetCCParticipant<mozilla::webgpu::Device>::Get() |
13198 | | }; |
13199 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
13200 | | "Must have the right minimal number of reserved slots."); |
13201 | | static_assert(1 >= 1, |
13202 | | "Must have enough reserved slots."); |
13203 | | |
13204 | | const JSClass* |
13205 | | GetJSClass() |
13206 | 0 | { |
13207 | 0 | return sClass.ToJSClass(); |
13208 | 0 | } |
13209 | | |
13210 | | bool |
13211 | | Wrap(JSContext* aCx, mozilla::webgpu::Device* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
13212 | 0 | { |
13213 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::Device>::value, |
13214 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
13215 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::Device*>(aObject) == |
13216 | 0 | reinterpret_cast<mozilla::webgpu::Device*>(aObject), |
13217 | 0 | "Multiple inheritance for mozilla::webgpu::Device is broken."); |
13218 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
13219 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
13220 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
13221 | 0 | "You should probably not be using Wrap() directly; use " |
13222 | 0 | "GetOrCreateDOMReflector instead"); |
13223 | 0 |
|
13224 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
13225 | 0 | "nsISupports must be on our primary inheritance chain"); |
13226 | 0 |
|
13227 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
13228 | 0 | if (!global) { |
13229 | 0 | return false; |
13230 | 0 | } |
13231 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
13232 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
13233 | 0 |
|
13234 | 0 | // That might have ended up wrapping us already, due to the wonders |
13235 | 0 | // of XBL. Check for that, and bail out as needed. |
13236 | 0 | aReflector.set(aCache->GetWrapper()); |
13237 | 0 | if (aReflector) { |
13238 | | #ifdef DEBUG |
13239 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
13240 | | #endif // DEBUG |
13241 | | return true; |
13242 | 0 | } |
13243 | 0 |
|
13244 | 0 | JSAutoRealm ar(aCx, global); |
13245 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
13246 | 0 | if (!canonicalProto) { |
13247 | 0 | return false; |
13248 | 0 | } |
13249 | 0 | JS::Rooted<JSObject*> proto(aCx); |
13250 | 0 | if (aGivenProto) { |
13251 | 0 | proto = aGivenProto; |
13252 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
13253 | 0 | // coming in, we changed compartments to that of "parent" so may need |
13254 | 0 | // to wrap the proto here. |
13255 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
13256 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
13257 | 0 | return false; |
13258 | 0 | } |
13259 | 0 | } |
13260 | 0 | } else { |
13261 | 0 | proto = canonicalProto; |
13262 | 0 | } |
13263 | 0 |
|
13264 | 0 | BindingJSObjectCreator<mozilla::webgpu::Device> creator(aCx); |
13265 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
13266 | 0 | if (!aReflector) { |
13267 | 0 | return false; |
13268 | 0 | } |
13269 | 0 | |
13270 | 0 | aCache->SetWrapper(aReflector); |
13271 | 0 | creator.InitializationSucceeded(); |
13272 | 0 |
|
13273 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
13274 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
13275 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
13276 | 0 | // otherwise we won't be able to properly recreate it later, since |
13277 | 0 | // we won't know what proto to use. Note that we don't check |
13278 | 0 | // aGivenProto here, since it's entirely possible (and even |
13279 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
13280 | 0 | // same as canonicalProto. |
13281 | 0 | if (proto != canonicalProto) { |
13282 | 0 | PreserveWrapper(aObject); |
13283 | 0 | } |
13284 | 0 |
|
13285 | 0 | return true; |
13286 | 0 | } |
13287 | | |
13288 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
13289 | | nullptr, |
13290 | | nullptr, |
13291 | | nullptr, |
13292 | | { sNativeProperties.Upcast(), nullptr }, |
13293 | | prototypes::id::WebGPUDevice, |
13294 | | constructors::id::WebGPUDevice, |
13295 | | nullptr, |
13296 | | &DefaultXrayExpandoObjectClass |
13297 | | } }; |
13298 | | |
13299 | | void |
13300 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
13301 | 0 | { |
13302 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
13303 | 0 | if (!parentProto) { |
13304 | 0 | return; |
13305 | 0 | } |
13306 | 0 | |
13307 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
13308 | 0 | if (!constructorProto) { |
13309 | 0 | return; |
13310 | 0 | } |
13311 | 0 | |
13312 | 0 | static bool sIdsInited = false; |
13313 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
13314 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
13315 | 0 | return; |
13316 | 0 | } |
13317 | 0 | sIdsInited = true; |
13318 | 0 | } |
13319 | 0 |
|
13320 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPUDevice); |
13321 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUDevice); |
13322 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
13323 | 0 | &sPrototypeClass.mBase, protoCache, |
13324 | 0 | nullptr, |
13325 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
13326 | 0 | interfaceCache, |
13327 | 0 | sNativeProperties.Upcast(), |
13328 | 0 | nullptr, |
13329 | 0 | "WebGPUDevice", aDefineOnGlobal, |
13330 | 0 | nullptr, |
13331 | 0 | false); |
13332 | 0 | } |
13333 | | |
13334 | | JSObject* |
13335 | | GetConstructorObject(JSContext* aCx) |
13336 | 0 | { |
13337 | 0 | return GetConstructorObjectHandle(aCx); |
13338 | 0 | } |
13339 | | |
13340 | | } // namespace WebGPUDevice_Binding |
13341 | | |
13342 | | |
13343 | | |
13344 | | namespace WebGPUFence_Binding { |
13345 | | |
13346 | | MOZ_CAN_RUN_SCRIPT static bool |
13347 | | wait(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Fence* self, const JSJitMethodCallArgs& args) |
13348 | 0 | { |
13349 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUFence.wait", DOM, cx); |
13350 | 0 |
|
13351 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
13352 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebGPUFence.wait"); |
13353 | 0 | } |
13354 | 0 | double arg0; |
13355 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, args[0], &arg0)) { |
13356 | 0 | return false; |
13357 | 0 | } else if (!mozilla::IsFinite(arg0)) { |
13358 | 0 | ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 1 of WebGPUFence.wait"); |
13359 | 0 | return false; |
13360 | 0 | } |
13361 | 0 | bool result(self->Wait(arg0)); |
13362 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
13363 | 0 | args.rval().setBoolean(result); |
13364 | 0 | return true; |
13365 | 0 | } |
13366 | | |
13367 | | static const JSJitInfo wait_methodinfo = { |
13368 | | { (JSJitGetterOp)wait }, |
13369 | | { prototypes::id::WebGPUFence }, |
13370 | | { PrototypeTraits<prototypes::id::WebGPUFence>::Depth }, |
13371 | | JSJitInfo::Method, |
13372 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
13373 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
13374 | | false, /* isInfallible. False in setters. */ |
13375 | | false, /* isMovable. Not relevant for setters. */ |
13376 | | false, /* isEliminatable. Not relevant for setters. */ |
13377 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
13378 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
13379 | | false, /* isTypedMethod. Only relevant for methods. */ |
13380 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
13381 | | }; |
13382 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
13383 | | static_assert(0 < 1, "There is no slot for us"); |
13384 | | |
13385 | | MOZ_CAN_RUN_SCRIPT static bool |
13386 | | get_promise(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Fence* self, JSJitGetterCallArgs args) |
13387 | 0 | { |
13388 | 0 | AUTO_PROFILER_LABEL_FAST("get WebGPUFence.promise", DOM, cx); |
13389 | 0 |
|
13390 | 0 | auto result(StrongOrRawPtr<Promise>(self->Promise())); |
13391 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
13392 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
13393 | 0 | return false; |
13394 | 0 | } |
13395 | 0 | return true; |
13396 | 0 | } |
13397 | | |
13398 | | MOZ_CAN_RUN_SCRIPT static bool |
13399 | | get_promise_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Fence* self, JSJitGetterCallArgs args) |
13400 | 0 | { |
13401 | 0 | bool ok = get_promise(cx, obj, self, args); |
13402 | 0 | if (ok) { |
13403 | 0 | return true; |
13404 | 0 | } |
13405 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
13406 | 0 | } |
13407 | | |
13408 | | static const JSJitInfo promise_getterinfo = { |
13409 | | { (JSJitGetterOp)get_promise_promiseWrapper }, |
13410 | | { prototypes::id::WebGPUFence }, |
13411 | | { PrototypeTraits<prototypes::id::WebGPUFence>::Depth }, |
13412 | | JSJitInfo::Getter, |
13413 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
13414 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
13415 | | false, /* isInfallible. False in setters. */ |
13416 | | false, /* isMovable. Not relevant for setters. */ |
13417 | | false, /* isEliminatable. Not relevant for setters. */ |
13418 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
13419 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
13420 | | false, /* isTypedMethod. Only relevant for methods. */ |
13421 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
13422 | | }; |
13423 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
13424 | | static_assert(0 < 1, "There is no slot for us"); |
13425 | | |
13426 | | static bool |
13427 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
13428 | 0 | { |
13429 | 0 | mozilla::webgpu::Fence* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Fence>(obj); |
13430 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
13431 | 0 | // obviously can't preserve if we're not initialized. |
13432 | 0 | if (self && self->GetWrapperPreserveColor()) { |
13433 | 0 | PreserveWrapper(self); |
13434 | 0 | } |
13435 | 0 | return true; |
13436 | 0 | } |
13437 | | |
13438 | | static void |
13439 | | _finalize(js::FreeOp* fop, JSObject* obj) |
13440 | 0 | { |
13441 | 0 | mozilla::webgpu::Fence* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Fence>(obj); |
13442 | 0 | if (self) { |
13443 | 0 | ClearWrapper(self, self, obj); |
13444 | 0 | AddForDeferredFinalization<mozilla::webgpu::Fence>(self); |
13445 | 0 | } |
13446 | 0 | } |
13447 | | |
13448 | | static size_t |
13449 | | _objectMoved(JSObject* obj, JSObject* old) |
13450 | 0 | { |
13451 | 0 | mozilla::webgpu::Fence* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Fence>(obj); |
13452 | 0 | if (self) { |
13453 | 0 | UpdateWrapper(self, self, obj, old); |
13454 | 0 | } |
13455 | 0 |
|
13456 | 0 | return 0; |
13457 | 0 | } |
13458 | | |
13459 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
13460 | | #if defined(__clang__) |
13461 | | #pragma clang diagnostic push |
13462 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
13463 | | #endif |
13464 | | static const JSFunctionSpec sMethods_specs[] = { |
13465 | | JS_FNSPEC("wait", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&wait_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
13466 | | JS_FS_END |
13467 | | }; |
13468 | | #if defined(__clang__) |
13469 | | #pragma clang diagnostic pop |
13470 | | #endif |
13471 | | |
13472 | | |
13473 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
13474 | | { nullptr, &sMethods_specs[0] }, |
13475 | | { nullptr, nullptr } |
13476 | | }; |
13477 | | |
13478 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
13479 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
13480 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
13481 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
13482 | | |
13483 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
13484 | | #if defined(__clang__) |
13485 | | #pragma clang diagnostic push |
13486 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
13487 | | #endif |
13488 | | static const JSPropertySpec sAttributes_specs[] = { |
13489 | | { "promise", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ConvertExceptionsToPromises>, &promise_getterinfo, nullptr, nullptr }, |
13490 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
13491 | | }; |
13492 | | #if defined(__clang__) |
13493 | | #pragma clang diagnostic pop |
13494 | | #endif |
13495 | | |
13496 | | |
13497 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
13498 | | { nullptr, &sAttributes_specs[0] }, |
13499 | | { nullptr, nullptr } |
13500 | | }; |
13501 | | |
13502 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
13503 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
13504 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
13505 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
13506 | | |
13507 | | |
13508 | | static uint16_t sNativeProperties_sortedPropertyIndices[2]; |
13509 | | static PropertyInfo sNativeProperties_propertyInfos[2]; |
13510 | | |
13511 | | static const NativePropertiesN<2> sNativeProperties = { |
13512 | | false, 0, |
13513 | | false, 0, |
13514 | | true, 0 /* sMethods */, |
13515 | | true, 1 /* sAttributes */, |
13516 | | false, 0, |
13517 | | false, 0, |
13518 | | false, 0, |
13519 | | -1, |
13520 | | 2, |
13521 | | sNativeProperties_sortedPropertyIndices, |
13522 | | { |
13523 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
13524 | | { sAttributes, &sNativeProperties_propertyInfos[1] } |
13525 | | } |
13526 | | }; |
13527 | | static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
13528 | | "We have a property info count that is oversized"); |
13529 | | |
13530 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
13531 | | { |
13532 | | "Function", |
13533 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
13534 | | &sBoringInterfaceObjectClassClassOps, |
13535 | | JS_NULL_CLASS_SPEC, |
13536 | | JS_NULL_CLASS_EXT, |
13537 | | &sInterfaceObjectClassObjectOps |
13538 | | }, |
13539 | | eInterface, |
13540 | | true, |
13541 | | prototypes::id::WebGPUFence, |
13542 | | PrototypeTraits<prototypes::id::WebGPUFence>::Depth, |
13543 | | sNativePropertyHooks, |
13544 | | "function WebGPUFence() {\n [native code]\n}", |
13545 | | JS::GetRealmFunctionPrototype |
13546 | | }; |
13547 | | |
13548 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
13549 | | { |
13550 | | "WebGPUFencePrototype", |
13551 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
13552 | | JS_NULL_CLASS_OPS, |
13553 | | JS_NULL_CLASS_SPEC, |
13554 | | JS_NULL_CLASS_EXT, |
13555 | | JS_NULL_OBJECT_OPS |
13556 | | }, |
13557 | | eInterfacePrototype, |
13558 | | false, |
13559 | | prototypes::id::WebGPUFence, |
13560 | | PrototypeTraits<prototypes::id::WebGPUFence>::Depth, |
13561 | | sNativePropertyHooks, |
13562 | | "[object WebGPUFencePrototype]", |
13563 | | JS::GetRealmObjectPrototype |
13564 | | }; |
13565 | | |
13566 | | bool |
13567 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
13568 | 0 | { |
13569 | 0 | static bool sPrefValue; |
13570 | 0 | static bool sPrefCacheSetUp = false; |
13571 | 0 | if (!sPrefCacheSetUp) { |
13572 | 0 | sPrefCacheSetUp = true; |
13573 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
13574 | 0 | } |
13575 | 0 |
|
13576 | 0 | return sPrefValue; |
13577 | 0 | } |
13578 | | |
13579 | | static const js::ClassOps sClassOps = { |
13580 | | _addProperty, /* addProperty */ |
13581 | | nullptr, /* delProperty */ |
13582 | | nullptr, /* enumerate */ |
13583 | | nullptr, /* newEnumerate */ |
13584 | | nullptr, /* resolve */ |
13585 | | nullptr, /* mayResolve */ |
13586 | | _finalize, /* finalize */ |
13587 | | nullptr, /* call */ |
13588 | | nullptr, /* hasInstance */ |
13589 | | nullptr, /* construct */ |
13590 | | nullptr, /* trace */ |
13591 | | }; |
13592 | | |
13593 | | static const js::ClassExtension sClassExtension = { |
13594 | | nullptr, /* weakmapKeyDelegateOp */ |
13595 | | _objectMoved /* objectMovedOp */ |
13596 | | }; |
13597 | | |
13598 | | static const DOMJSClass sClass = { |
13599 | | { "WebGPUFence", |
13600 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
13601 | | &sClassOps, |
13602 | | JS_NULL_CLASS_SPEC, |
13603 | | &sClassExtension, |
13604 | | JS_NULL_OBJECT_OPS |
13605 | | }, |
13606 | | { prototypes::id::WebGPUFence, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
13607 | | IsBaseOf<nsISupports, mozilla::webgpu::Fence >::value, |
13608 | | sNativePropertyHooks, |
13609 | | FindAssociatedGlobalForNative<mozilla::webgpu::Fence>::Get, |
13610 | | GetProtoObjectHandle, |
13611 | | GetCCParticipant<mozilla::webgpu::Fence>::Get() |
13612 | | }; |
13613 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
13614 | | "Must have the right minimal number of reserved slots."); |
13615 | | static_assert(1 >= 1, |
13616 | | "Must have enough reserved slots."); |
13617 | | |
13618 | | const JSClass* |
13619 | | GetJSClass() |
13620 | 0 | { |
13621 | 0 | return sClass.ToJSClass(); |
13622 | 0 | } |
13623 | | |
13624 | | bool |
13625 | | Wrap(JSContext* aCx, mozilla::webgpu::Fence* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
13626 | 0 | { |
13627 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::Fence>::value, |
13628 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
13629 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::Fence*>(aObject) == |
13630 | 0 | reinterpret_cast<mozilla::webgpu::Fence*>(aObject), |
13631 | 0 | "Multiple inheritance for mozilla::webgpu::Fence is broken."); |
13632 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
13633 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
13634 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
13635 | 0 | "You should probably not be using Wrap() directly; use " |
13636 | 0 | "GetOrCreateDOMReflector instead"); |
13637 | 0 |
|
13638 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
13639 | 0 | "nsISupports must be on our primary inheritance chain"); |
13640 | 0 |
|
13641 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
13642 | 0 | if (!global) { |
13643 | 0 | return false; |
13644 | 0 | } |
13645 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
13646 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
13647 | 0 |
|
13648 | 0 | // That might have ended up wrapping us already, due to the wonders |
13649 | 0 | // of XBL. Check for that, and bail out as needed. |
13650 | 0 | aReflector.set(aCache->GetWrapper()); |
13651 | 0 | if (aReflector) { |
13652 | | #ifdef DEBUG |
13653 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
13654 | | #endif // DEBUG |
13655 | | return true; |
13656 | 0 | } |
13657 | 0 |
|
13658 | 0 | JSAutoRealm ar(aCx, global); |
13659 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
13660 | 0 | if (!canonicalProto) { |
13661 | 0 | return false; |
13662 | 0 | } |
13663 | 0 | JS::Rooted<JSObject*> proto(aCx); |
13664 | 0 | if (aGivenProto) { |
13665 | 0 | proto = aGivenProto; |
13666 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
13667 | 0 | // coming in, we changed compartments to that of "parent" so may need |
13668 | 0 | // to wrap the proto here. |
13669 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
13670 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
13671 | 0 | return false; |
13672 | 0 | } |
13673 | 0 | } |
13674 | 0 | } else { |
13675 | 0 | proto = canonicalProto; |
13676 | 0 | } |
13677 | 0 |
|
13678 | 0 | BindingJSObjectCreator<mozilla::webgpu::Fence> creator(aCx); |
13679 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
13680 | 0 | if (!aReflector) { |
13681 | 0 | return false; |
13682 | 0 | } |
13683 | 0 | |
13684 | 0 | aCache->SetWrapper(aReflector); |
13685 | 0 | creator.InitializationSucceeded(); |
13686 | 0 |
|
13687 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
13688 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
13689 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
13690 | 0 | // otherwise we won't be able to properly recreate it later, since |
13691 | 0 | // we won't know what proto to use. Note that we don't check |
13692 | 0 | // aGivenProto here, since it's entirely possible (and even |
13693 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
13694 | 0 | // same as canonicalProto. |
13695 | 0 | if (proto != canonicalProto) { |
13696 | 0 | PreserveWrapper(aObject); |
13697 | 0 | } |
13698 | 0 |
|
13699 | 0 | return true; |
13700 | 0 | } |
13701 | | |
13702 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
13703 | | nullptr, |
13704 | | nullptr, |
13705 | | nullptr, |
13706 | | { sNativeProperties.Upcast(), nullptr }, |
13707 | | prototypes::id::WebGPUFence, |
13708 | | constructors::id::WebGPUFence, |
13709 | | nullptr, |
13710 | | &DefaultXrayExpandoObjectClass |
13711 | | } }; |
13712 | | |
13713 | | void |
13714 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
13715 | 0 | { |
13716 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
13717 | 0 | if (!parentProto) { |
13718 | 0 | return; |
13719 | 0 | } |
13720 | 0 | |
13721 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
13722 | 0 | if (!constructorProto) { |
13723 | 0 | return; |
13724 | 0 | } |
13725 | 0 | |
13726 | 0 | static bool sIdsInited = false; |
13727 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
13728 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
13729 | 0 | return; |
13730 | 0 | } |
13731 | 0 | sIdsInited = true; |
13732 | 0 | } |
13733 | 0 |
|
13734 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPUFence); |
13735 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUFence); |
13736 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
13737 | 0 | &sPrototypeClass.mBase, protoCache, |
13738 | 0 | nullptr, |
13739 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
13740 | 0 | interfaceCache, |
13741 | 0 | sNativeProperties.Upcast(), |
13742 | 0 | nullptr, |
13743 | 0 | "WebGPUFence", aDefineOnGlobal, |
13744 | 0 | nullptr, |
13745 | 0 | false); |
13746 | 0 | } |
13747 | | |
13748 | | JSObject* |
13749 | | GetConstructorObject(JSContext* aCx) |
13750 | 0 | { |
13751 | 0 | return GetConstructorObjectHandle(aCx); |
13752 | 0 | } |
13753 | | |
13754 | | } // namespace WebGPUFence_Binding |
13755 | | |
13756 | | |
13757 | | |
13758 | | namespace WebGPUFilterMode_Binding { |
13759 | | |
13760 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
13761 | | #if defined(__clang__) |
13762 | | #pragma clang diagnostic push |
13763 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
13764 | | #endif |
13765 | | static const ConstantSpec sConstants_specs[] = { |
13766 | | { "NEAREST", JS::NumberValue(0U) }, |
13767 | | { "LINEAR", JS::NumberValue(1U) }, |
13768 | | { 0, JS::UndefinedValue() } |
13769 | | }; |
13770 | | #if defined(__clang__) |
13771 | | #pragma clang diagnostic pop |
13772 | | #endif |
13773 | | |
13774 | | |
13775 | | static const Prefable<const ConstantSpec> sConstants[] = { |
13776 | | { nullptr, &sConstants_specs[0] }, |
13777 | | { nullptr, nullptr } |
13778 | | }; |
13779 | | |
13780 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
13781 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
13782 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
13783 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
13784 | | |
13785 | | |
13786 | | static uint16_t sNativeProperties_sortedPropertyIndices[2]; |
13787 | | static PropertyInfo sNativeProperties_propertyInfos[2]; |
13788 | | |
13789 | | static const NativePropertiesN<1> sNativeProperties = { |
13790 | | false, 0, |
13791 | | false, 0, |
13792 | | false, 0, |
13793 | | false, 0, |
13794 | | false, 0, |
13795 | | false, 0, |
13796 | | true, 0 /* sConstants */, |
13797 | | -1, |
13798 | | 2, |
13799 | | sNativeProperties_sortedPropertyIndices, |
13800 | | { |
13801 | | { sConstants, &sNativeProperties_propertyInfos[0] } |
13802 | | } |
13803 | | }; |
13804 | | static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
13805 | | "We have a property info count that is oversized"); |
13806 | | |
13807 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
13808 | | { |
13809 | | "Function", |
13810 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
13811 | | &sBoringInterfaceObjectClassClassOps, |
13812 | | JS_NULL_CLASS_SPEC, |
13813 | | JS_NULL_CLASS_EXT, |
13814 | | &sInterfaceObjectClassObjectOps |
13815 | | }, |
13816 | | eInterface, |
13817 | | false, |
13818 | | prototypes::id::_ID_Count, |
13819 | | 0, |
13820 | | sNativePropertyHooks, |
13821 | | "function WebGPUFilterMode() {\n [native code]\n}", |
13822 | | JS::GetRealmFunctionPrototype |
13823 | | }; |
13824 | | |
13825 | | bool |
13826 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
13827 | 0 | { |
13828 | 0 | static bool sPrefValue; |
13829 | 0 | static bool sPrefCacheSetUp = false; |
13830 | 0 | if (!sPrefCacheSetUp) { |
13831 | 0 | sPrefCacheSetUp = true; |
13832 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
13833 | 0 | } |
13834 | 0 |
|
13835 | 0 | return sPrefValue; |
13836 | 0 | } |
13837 | | |
13838 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
13839 | | nullptr, |
13840 | | nullptr, |
13841 | | nullptr, |
13842 | | { sNativeProperties.Upcast(), nullptr }, |
13843 | | prototypes::id::_ID_Count, |
13844 | | constructors::id::WebGPUFilterMode, |
13845 | | nullptr, |
13846 | | &DefaultXrayExpandoObjectClass |
13847 | | } }; |
13848 | | |
13849 | | void |
13850 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
13851 | 0 | { |
13852 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
13853 | 0 | if (!constructorProto) { |
13854 | 0 | return; |
13855 | 0 | } |
13856 | 0 | |
13857 | 0 | static bool sIdsInited = false; |
13858 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
13859 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
13860 | 0 | return; |
13861 | 0 | } |
13862 | 0 | sIdsInited = true; |
13863 | 0 | } |
13864 | 0 |
|
13865 | 0 | JS::Heap<JSObject*>* protoCache = nullptr; |
13866 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUFilterMode); |
13867 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, nullptr, |
13868 | 0 | nullptr, protoCache, |
13869 | 0 | nullptr, |
13870 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
13871 | 0 | interfaceCache, |
13872 | 0 | sNativeProperties.Upcast(), |
13873 | 0 | nullptr, |
13874 | 0 | "WebGPUFilterMode", aDefineOnGlobal, |
13875 | 0 | nullptr, |
13876 | 0 | false); |
13877 | 0 | } |
13878 | | |
13879 | | JSObject* |
13880 | | GetConstructorObject(JSContext* aCx) |
13881 | 0 | { |
13882 | 0 | return GetConstructorObjectHandle(aCx); |
13883 | 0 | } |
13884 | | |
13885 | | } // namespace WebGPUFilterMode_Binding |
13886 | | |
13887 | | |
13888 | | |
13889 | | namespace WebGPUIndexFormat_Binding { |
13890 | | |
13891 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
13892 | | #if defined(__clang__) |
13893 | | #pragma clang diagnostic push |
13894 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
13895 | | #endif |
13896 | | static const ConstantSpec sConstants_specs[] = { |
13897 | | { "UINT16", JS::NumberValue(0U) }, |
13898 | | { "UINT32", JS::NumberValue(1U) }, |
13899 | | { 0, JS::UndefinedValue() } |
13900 | | }; |
13901 | | #if defined(__clang__) |
13902 | | #pragma clang diagnostic pop |
13903 | | #endif |
13904 | | |
13905 | | |
13906 | | static const Prefable<const ConstantSpec> sConstants[] = { |
13907 | | { nullptr, &sConstants_specs[0] }, |
13908 | | { nullptr, nullptr } |
13909 | | }; |
13910 | | |
13911 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
13912 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
13913 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
13914 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
13915 | | |
13916 | | |
13917 | | static uint16_t sNativeProperties_sortedPropertyIndices[2]; |
13918 | | static PropertyInfo sNativeProperties_propertyInfos[2]; |
13919 | | |
13920 | | static const NativePropertiesN<1> sNativeProperties = { |
13921 | | false, 0, |
13922 | | false, 0, |
13923 | | false, 0, |
13924 | | false, 0, |
13925 | | false, 0, |
13926 | | false, 0, |
13927 | | true, 0 /* sConstants */, |
13928 | | -1, |
13929 | | 2, |
13930 | | sNativeProperties_sortedPropertyIndices, |
13931 | | { |
13932 | | { sConstants, &sNativeProperties_propertyInfos[0] } |
13933 | | } |
13934 | | }; |
13935 | | static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
13936 | | "We have a property info count that is oversized"); |
13937 | | |
13938 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
13939 | | { |
13940 | | "Function", |
13941 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
13942 | | &sBoringInterfaceObjectClassClassOps, |
13943 | | JS_NULL_CLASS_SPEC, |
13944 | | JS_NULL_CLASS_EXT, |
13945 | | &sInterfaceObjectClassObjectOps |
13946 | | }, |
13947 | | eInterface, |
13948 | | false, |
13949 | | prototypes::id::_ID_Count, |
13950 | | 0, |
13951 | | sNativePropertyHooks, |
13952 | | "function WebGPUIndexFormat() {\n [native code]\n}", |
13953 | | JS::GetRealmFunctionPrototype |
13954 | | }; |
13955 | | |
13956 | | bool |
13957 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
13958 | 0 | { |
13959 | 0 | static bool sPrefValue; |
13960 | 0 | static bool sPrefCacheSetUp = false; |
13961 | 0 | if (!sPrefCacheSetUp) { |
13962 | 0 | sPrefCacheSetUp = true; |
13963 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
13964 | 0 | } |
13965 | 0 |
|
13966 | 0 | return sPrefValue; |
13967 | 0 | } |
13968 | | |
13969 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
13970 | | nullptr, |
13971 | | nullptr, |
13972 | | nullptr, |
13973 | | { sNativeProperties.Upcast(), nullptr }, |
13974 | | prototypes::id::_ID_Count, |
13975 | | constructors::id::WebGPUIndexFormat, |
13976 | | nullptr, |
13977 | | &DefaultXrayExpandoObjectClass |
13978 | | } }; |
13979 | | |
13980 | | void |
13981 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
13982 | 0 | { |
13983 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
13984 | 0 | if (!constructorProto) { |
13985 | 0 | return; |
13986 | 0 | } |
13987 | 0 | |
13988 | 0 | static bool sIdsInited = false; |
13989 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
13990 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
13991 | 0 | return; |
13992 | 0 | } |
13993 | 0 | sIdsInited = true; |
13994 | 0 | } |
13995 | 0 |
|
13996 | 0 | JS::Heap<JSObject*>* protoCache = nullptr; |
13997 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUIndexFormat); |
13998 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, nullptr, |
13999 | 0 | nullptr, protoCache, |
14000 | 0 | nullptr, |
14001 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
14002 | 0 | interfaceCache, |
14003 | 0 | sNativeProperties.Upcast(), |
14004 | 0 | nullptr, |
14005 | 0 | "WebGPUIndexFormat", aDefineOnGlobal, |
14006 | 0 | nullptr, |
14007 | 0 | false); |
14008 | 0 | } |
14009 | | |
14010 | | JSObject* |
14011 | | GetConstructorObject(JSContext* aCx) |
14012 | 0 | { |
14013 | 0 | return GetConstructorObjectHandle(aCx); |
14014 | 0 | } |
14015 | | |
14016 | | } // namespace WebGPUIndexFormat_Binding |
14017 | | |
14018 | | |
14019 | | |
14020 | | namespace WebGPUInputState_Binding { |
14021 | | |
14022 | | static bool |
14023 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
14024 | 0 | { |
14025 | 0 | mozilla::webgpu::InputState* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::InputState>(obj); |
14026 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
14027 | 0 | // obviously can't preserve if we're not initialized. |
14028 | 0 | if (self && self->GetWrapperPreserveColor()) { |
14029 | 0 | PreserveWrapper(self); |
14030 | 0 | } |
14031 | 0 | return true; |
14032 | 0 | } |
14033 | | |
14034 | | static void |
14035 | | _finalize(js::FreeOp* fop, JSObject* obj) |
14036 | 0 | { |
14037 | 0 | mozilla::webgpu::InputState* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::InputState>(obj); |
14038 | 0 | if (self) { |
14039 | 0 | ClearWrapper(self, self, obj); |
14040 | 0 | AddForDeferredFinalization<mozilla::webgpu::InputState>(self); |
14041 | 0 | } |
14042 | 0 | } |
14043 | | |
14044 | | static size_t |
14045 | | _objectMoved(JSObject* obj, JSObject* old) |
14046 | 0 | { |
14047 | 0 | mozilla::webgpu::InputState* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::InputState>(obj); |
14048 | 0 | if (self) { |
14049 | 0 | UpdateWrapper(self, self, obj, old); |
14050 | 0 | } |
14051 | 0 |
|
14052 | 0 | return 0; |
14053 | 0 | } |
14054 | | |
14055 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
14056 | | { |
14057 | | "Function", |
14058 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
14059 | | &sBoringInterfaceObjectClassClassOps, |
14060 | | JS_NULL_CLASS_SPEC, |
14061 | | JS_NULL_CLASS_EXT, |
14062 | | &sInterfaceObjectClassObjectOps |
14063 | | }, |
14064 | | eInterface, |
14065 | | true, |
14066 | | prototypes::id::WebGPUInputState, |
14067 | | PrototypeTraits<prototypes::id::WebGPUInputState>::Depth, |
14068 | | sNativePropertyHooks, |
14069 | | "function WebGPUInputState() {\n [native code]\n}", |
14070 | | JS::GetRealmFunctionPrototype |
14071 | | }; |
14072 | | |
14073 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
14074 | | { |
14075 | | "WebGPUInputStatePrototype", |
14076 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
14077 | | JS_NULL_CLASS_OPS, |
14078 | | JS_NULL_CLASS_SPEC, |
14079 | | JS_NULL_CLASS_EXT, |
14080 | | JS_NULL_OBJECT_OPS |
14081 | | }, |
14082 | | eInterfacePrototype, |
14083 | | false, |
14084 | | prototypes::id::WebGPUInputState, |
14085 | | PrototypeTraits<prototypes::id::WebGPUInputState>::Depth, |
14086 | | sNativePropertyHooks, |
14087 | | "[object WebGPUInputStatePrototype]", |
14088 | | JS::GetRealmObjectPrototype |
14089 | | }; |
14090 | | |
14091 | | bool |
14092 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
14093 | 0 | { |
14094 | 0 | static bool sPrefValue; |
14095 | 0 | static bool sPrefCacheSetUp = false; |
14096 | 0 | if (!sPrefCacheSetUp) { |
14097 | 0 | sPrefCacheSetUp = true; |
14098 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
14099 | 0 | } |
14100 | 0 |
|
14101 | 0 | return sPrefValue; |
14102 | 0 | } |
14103 | | |
14104 | | static const js::ClassOps sClassOps = { |
14105 | | _addProperty, /* addProperty */ |
14106 | | nullptr, /* delProperty */ |
14107 | | nullptr, /* enumerate */ |
14108 | | nullptr, /* newEnumerate */ |
14109 | | nullptr, /* resolve */ |
14110 | | nullptr, /* mayResolve */ |
14111 | | _finalize, /* finalize */ |
14112 | | nullptr, /* call */ |
14113 | | nullptr, /* hasInstance */ |
14114 | | nullptr, /* construct */ |
14115 | | nullptr, /* trace */ |
14116 | | }; |
14117 | | |
14118 | | static const js::ClassExtension sClassExtension = { |
14119 | | nullptr, /* weakmapKeyDelegateOp */ |
14120 | | _objectMoved /* objectMovedOp */ |
14121 | | }; |
14122 | | |
14123 | | static const DOMJSClass sClass = { |
14124 | | { "WebGPUInputState", |
14125 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
14126 | | &sClassOps, |
14127 | | JS_NULL_CLASS_SPEC, |
14128 | | &sClassExtension, |
14129 | | JS_NULL_OBJECT_OPS |
14130 | | }, |
14131 | | { prototypes::id::WebGPUInputState, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
14132 | | IsBaseOf<nsISupports, mozilla::webgpu::InputState >::value, |
14133 | | sNativePropertyHooks, |
14134 | | FindAssociatedGlobalForNative<mozilla::webgpu::InputState>::Get, |
14135 | | GetProtoObjectHandle, |
14136 | | GetCCParticipant<mozilla::webgpu::InputState>::Get() |
14137 | | }; |
14138 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
14139 | | "Must have the right minimal number of reserved slots."); |
14140 | | static_assert(1 >= 1, |
14141 | | "Must have enough reserved slots."); |
14142 | | |
14143 | | const JSClass* |
14144 | | GetJSClass() |
14145 | 0 | { |
14146 | 0 | return sClass.ToJSClass(); |
14147 | 0 | } |
14148 | | |
14149 | | bool |
14150 | | Wrap(JSContext* aCx, mozilla::webgpu::InputState* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
14151 | 0 | { |
14152 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::InputState>::value, |
14153 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
14154 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::InputState*>(aObject) == |
14155 | 0 | reinterpret_cast<mozilla::webgpu::InputState*>(aObject), |
14156 | 0 | "Multiple inheritance for mozilla::webgpu::InputState is broken."); |
14157 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
14158 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
14159 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
14160 | 0 | "You should probably not be using Wrap() directly; use " |
14161 | 0 | "GetOrCreateDOMReflector instead"); |
14162 | 0 |
|
14163 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
14164 | 0 | "nsISupports must be on our primary inheritance chain"); |
14165 | 0 |
|
14166 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
14167 | 0 | if (!global) { |
14168 | 0 | return false; |
14169 | 0 | } |
14170 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
14171 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
14172 | 0 |
|
14173 | 0 | // That might have ended up wrapping us already, due to the wonders |
14174 | 0 | // of XBL. Check for that, and bail out as needed. |
14175 | 0 | aReflector.set(aCache->GetWrapper()); |
14176 | 0 | if (aReflector) { |
14177 | | #ifdef DEBUG |
14178 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
14179 | | #endif // DEBUG |
14180 | | return true; |
14181 | 0 | } |
14182 | 0 |
|
14183 | 0 | JSAutoRealm ar(aCx, global); |
14184 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
14185 | 0 | if (!canonicalProto) { |
14186 | 0 | return false; |
14187 | 0 | } |
14188 | 0 | JS::Rooted<JSObject*> proto(aCx); |
14189 | 0 | if (aGivenProto) { |
14190 | 0 | proto = aGivenProto; |
14191 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
14192 | 0 | // coming in, we changed compartments to that of "parent" so may need |
14193 | 0 | // to wrap the proto here. |
14194 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
14195 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
14196 | 0 | return false; |
14197 | 0 | } |
14198 | 0 | } |
14199 | 0 | } else { |
14200 | 0 | proto = canonicalProto; |
14201 | 0 | } |
14202 | 0 |
|
14203 | 0 | BindingJSObjectCreator<mozilla::webgpu::InputState> creator(aCx); |
14204 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
14205 | 0 | if (!aReflector) { |
14206 | 0 | return false; |
14207 | 0 | } |
14208 | 0 | |
14209 | 0 | aCache->SetWrapper(aReflector); |
14210 | 0 | creator.InitializationSucceeded(); |
14211 | 0 |
|
14212 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
14213 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
14214 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
14215 | 0 | // otherwise we won't be able to properly recreate it later, since |
14216 | 0 | // we won't know what proto to use. Note that we don't check |
14217 | 0 | // aGivenProto here, since it's entirely possible (and even |
14218 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
14219 | 0 | // same as canonicalProto. |
14220 | 0 | if (proto != canonicalProto) { |
14221 | 0 | PreserveWrapper(aObject); |
14222 | 0 | } |
14223 | 0 |
|
14224 | 0 | return true; |
14225 | 0 | } |
14226 | | |
14227 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
14228 | | nullptr, |
14229 | | nullptr, |
14230 | | nullptr, |
14231 | | { nullptr, nullptr }, |
14232 | | prototypes::id::WebGPUInputState, |
14233 | | constructors::id::WebGPUInputState, |
14234 | | nullptr, |
14235 | | &DefaultXrayExpandoObjectClass |
14236 | | } }; |
14237 | | |
14238 | | void |
14239 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
14240 | 0 | { |
14241 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
14242 | 0 | if (!parentProto) { |
14243 | 0 | return; |
14244 | 0 | } |
14245 | 0 | |
14246 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
14247 | 0 | if (!constructorProto) { |
14248 | 0 | return; |
14249 | 0 | } |
14250 | 0 | |
14251 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPUInputState); |
14252 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUInputState); |
14253 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
14254 | 0 | &sPrototypeClass.mBase, protoCache, |
14255 | 0 | nullptr, |
14256 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
14257 | 0 | interfaceCache, |
14258 | 0 | nullptr, |
14259 | 0 | nullptr, |
14260 | 0 | "WebGPUInputState", aDefineOnGlobal, |
14261 | 0 | nullptr, |
14262 | 0 | false); |
14263 | 0 | } |
14264 | | |
14265 | | JSObject* |
14266 | | GetConstructorObject(JSContext* aCx) |
14267 | 0 | { |
14268 | 0 | return GetConstructorObjectHandle(aCx); |
14269 | 0 | } |
14270 | | |
14271 | | } // namespace WebGPUInputState_Binding |
14272 | | |
14273 | | |
14274 | | |
14275 | | namespace WebGPUInputStepMode_Binding { |
14276 | | |
14277 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
14278 | | #if defined(__clang__) |
14279 | | #pragma clang diagnostic push |
14280 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
14281 | | #endif |
14282 | | static const ConstantSpec sConstants_specs[] = { |
14283 | | { "VERTEX", JS::NumberValue(0U) }, |
14284 | | { "INSTANCE", JS::NumberValue(1U) }, |
14285 | | { 0, JS::UndefinedValue() } |
14286 | | }; |
14287 | | #if defined(__clang__) |
14288 | | #pragma clang diagnostic pop |
14289 | | #endif |
14290 | | |
14291 | | |
14292 | | static const Prefable<const ConstantSpec> sConstants[] = { |
14293 | | { nullptr, &sConstants_specs[0] }, |
14294 | | { nullptr, nullptr } |
14295 | | }; |
14296 | | |
14297 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
14298 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
14299 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
14300 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
14301 | | |
14302 | | |
14303 | | static uint16_t sNativeProperties_sortedPropertyIndices[2]; |
14304 | | static PropertyInfo sNativeProperties_propertyInfos[2]; |
14305 | | |
14306 | | static const NativePropertiesN<1> sNativeProperties = { |
14307 | | false, 0, |
14308 | | false, 0, |
14309 | | false, 0, |
14310 | | false, 0, |
14311 | | false, 0, |
14312 | | false, 0, |
14313 | | true, 0 /* sConstants */, |
14314 | | -1, |
14315 | | 2, |
14316 | | sNativeProperties_sortedPropertyIndices, |
14317 | | { |
14318 | | { sConstants, &sNativeProperties_propertyInfos[0] } |
14319 | | } |
14320 | | }; |
14321 | | static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
14322 | | "We have a property info count that is oversized"); |
14323 | | |
14324 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
14325 | | { |
14326 | | "Function", |
14327 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
14328 | | &sBoringInterfaceObjectClassClassOps, |
14329 | | JS_NULL_CLASS_SPEC, |
14330 | | JS_NULL_CLASS_EXT, |
14331 | | &sInterfaceObjectClassObjectOps |
14332 | | }, |
14333 | | eInterface, |
14334 | | false, |
14335 | | prototypes::id::_ID_Count, |
14336 | | 0, |
14337 | | sNativePropertyHooks, |
14338 | | "function WebGPUInputStepMode() {\n [native code]\n}", |
14339 | | JS::GetRealmFunctionPrototype |
14340 | | }; |
14341 | | |
14342 | | bool |
14343 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
14344 | 0 | { |
14345 | 0 | static bool sPrefValue; |
14346 | 0 | static bool sPrefCacheSetUp = false; |
14347 | 0 | if (!sPrefCacheSetUp) { |
14348 | 0 | sPrefCacheSetUp = true; |
14349 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
14350 | 0 | } |
14351 | 0 |
|
14352 | 0 | return sPrefValue; |
14353 | 0 | } |
14354 | | |
14355 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
14356 | | nullptr, |
14357 | | nullptr, |
14358 | | nullptr, |
14359 | | { sNativeProperties.Upcast(), nullptr }, |
14360 | | prototypes::id::_ID_Count, |
14361 | | constructors::id::WebGPUInputStepMode, |
14362 | | nullptr, |
14363 | | &DefaultXrayExpandoObjectClass |
14364 | | } }; |
14365 | | |
14366 | | void |
14367 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
14368 | 0 | { |
14369 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
14370 | 0 | if (!constructorProto) { |
14371 | 0 | return; |
14372 | 0 | } |
14373 | 0 | |
14374 | 0 | static bool sIdsInited = false; |
14375 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
14376 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
14377 | 0 | return; |
14378 | 0 | } |
14379 | 0 | sIdsInited = true; |
14380 | 0 | } |
14381 | 0 |
|
14382 | 0 | JS::Heap<JSObject*>* protoCache = nullptr; |
14383 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUInputStepMode); |
14384 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, nullptr, |
14385 | 0 | nullptr, protoCache, |
14386 | 0 | nullptr, |
14387 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
14388 | 0 | interfaceCache, |
14389 | 0 | sNativeProperties.Upcast(), |
14390 | 0 | nullptr, |
14391 | 0 | "WebGPUInputStepMode", aDefineOnGlobal, |
14392 | 0 | nullptr, |
14393 | 0 | false); |
14394 | 0 | } |
14395 | | |
14396 | | JSObject* |
14397 | | GetConstructorObject(JSContext* aCx) |
14398 | 0 | { |
14399 | 0 | return GetConstructorObjectHandle(aCx); |
14400 | 0 | } |
14401 | | |
14402 | | } // namespace WebGPUInputStepMode_Binding |
14403 | | |
14404 | | |
14405 | | |
14406 | | namespace WebGPULoadOp_Binding { |
14407 | | |
14408 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
14409 | | #if defined(__clang__) |
14410 | | #pragma clang diagnostic push |
14411 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
14412 | | #endif |
14413 | | static const ConstantSpec sConstants_specs[] = { |
14414 | | { "CLEAR", JS::NumberValue(0U) }, |
14415 | | { "LOAD", JS::NumberValue(1U) }, |
14416 | | { 0, JS::UndefinedValue() } |
14417 | | }; |
14418 | | #if defined(__clang__) |
14419 | | #pragma clang diagnostic pop |
14420 | | #endif |
14421 | | |
14422 | | |
14423 | | static const Prefable<const ConstantSpec> sConstants[] = { |
14424 | | { nullptr, &sConstants_specs[0] }, |
14425 | | { nullptr, nullptr } |
14426 | | }; |
14427 | | |
14428 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
14429 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
14430 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
14431 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
14432 | | |
14433 | | |
14434 | | static uint16_t sNativeProperties_sortedPropertyIndices[2]; |
14435 | | static PropertyInfo sNativeProperties_propertyInfos[2]; |
14436 | | |
14437 | | static const NativePropertiesN<1> sNativeProperties = { |
14438 | | false, 0, |
14439 | | false, 0, |
14440 | | false, 0, |
14441 | | false, 0, |
14442 | | false, 0, |
14443 | | false, 0, |
14444 | | true, 0 /* sConstants */, |
14445 | | -1, |
14446 | | 2, |
14447 | | sNativeProperties_sortedPropertyIndices, |
14448 | | { |
14449 | | { sConstants, &sNativeProperties_propertyInfos[0] } |
14450 | | } |
14451 | | }; |
14452 | | static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
14453 | | "We have a property info count that is oversized"); |
14454 | | |
14455 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
14456 | | { |
14457 | | "Function", |
14458 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
14459 | | &sBoringInterfaceObjectClassClassOps, |
14460 | | JS_NULL_CLASS_SPEC, |
14461 | | JS_NULL_CLASS_EXT, |
14462 | | &sInterfaceObjectClassObjectOps |
14463 | | }, |
14464 | | eInterface, |
14465 | | false, |
14466 | | prototypes::id::_ID_Count, |
14467 | | 0, |
14468 | | sNativePropertyHooks, |
14469 | | "function WebGPULoadOp() {\n [native code]\n}", |
14470 | | JS::GetRealmFunctionPrototype |
14471 | | }; |
14472 | | |
14473 | | bool |
14474 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
14475 | 0 | { |
14476 | 0 | static bool sPrefValue; |
14477 | 0 | static bool sPrefCacheSetUp = false; |
14478 | 0 | if (!sPrefCacheSetUp) { |
14479 | 0 | sPrefCacheSetUp = true; |
14480 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
14481 | 0 | } |
14482 | 0 |
|
14483 | 0 | return sPrefValue; |
14484 | 0 | } |
14485 | | |
14486 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
14487 | | nullptr, |
14488 | | nullptr, |
14489 | | nullptr, |
14490 | | { sNativeProperties.Upcast(), nullptr }, |
14491 | | prototypes::id::_ID_Count, |
14492 | | constructors::id::WebGPULoadOp, |
14493 | | nullptr, |
14494 | | &DefaultXrayExpandoObjectClass |
14495 | | } }; |
14496 | | |
14497 | | void |
14498 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
14499 | 0 | { |
14500 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
14501 | 0 | if (!constructorProto) { |
14502 | 0 | return; |
14503 | 0 | } |
14504 | 0 | |
14505 | 0 | static bool sIdsInited = false; |
14506 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
14507 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
14508 | 0 | return; |
14509 | 0 | } |
14510 | 0 | sIdsInited = true; |
14511 | 0 | } |
14512 | 0 |
|
14513 | 0 | JS::Heap<JSObject*>* protoCache = nullptr; |
14514 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPULoadOp); |
14515 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, nullptr, |
14516 | 0 | nullptr, protoCache, |
14517 | 0 | nullptr, |
14518 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
14519 | 0 | interfaceCache, |
14520 | 0 | sNativeProperties.Upcast(), |
14521 | 0 | nullptr, |
14522 | 0 | "WebGPULoadOp", aDefineOnGlobal, |
14523 | 0 | nullptr, |
14524 | 0 | false); |
14525 | 0 | } |
14526 | | |
14527 | | JSObject* |
14528 | | GetConstructorObject(JSContext* aCx) |
14529 | 0 | { |
14530 | 0 | return GetConstructorObjectHandle(aCx); |
14531 | 0 | } |
14532 | | |
14533 | | } // namespace WebGPULoadOp_Binding |
14534 | | |
14535 | | |
14536 | | |
14537 | | namespace WebGPULogEntry_Binding { |
14538 | | |
14539 | | MOZ_CAN_RUN_SCRIPT static bool |
14540 | | get_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::LogEntry* self, JSJitGetterCallArgs args) |
14541 | 0 | { |
14542 | 0 | AUTO_PROFILER_LABEL_FAST("get WebGPULogEntry.type", DOM, cx); |
14543 | 0 |
|
14544 | 0 | WebGPULogEntryType result(self->Type()); |
14545 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
14546 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
14547 | 0 | return false; |
14548 | 0 | } |
14549 | 0 | return true; |
14550 | 0 | } |
14551 | | |
14552 | | static const JSJitInfo type_getterinfo = { |
14553 | | { (JSJitGetterOp)get_type }, |
14554 | | { prototypes::id::WebGPULogEntry }, |
14555 | | { PrototypeTraits<prototypes::id::WebGPULogEntry>::Depth }, |
14556 | | JSJitInfo::Getter, |
14557 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
14558 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
14559 | | false, /* isInfallible. False in setters. */ |
14560 | | false, /* isMovable. Not relevant for setters. */ |
14561 | | false, /* isEliminatable. Not relevant for setters. */ |
14562 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
14563 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
14564 | | false, /* isTypedMethod. Only relevant for methods. */ |
14565 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
14566 | | }; |
14567 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
14568 | | static_assert(0 < 1, "There is no slot for us"); |
14569 | | |
14570 | | MOZ_CAN_RUN_SCRIPT static bool |
14571 | | get_obj(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::LogEntry* self, JSJitGetterCallArgs args) |
14572 | 0 | { |
14573 | 0 | AUTO_PROFILER_LABEL_FAST("get WebGPULogEntry.obj", DOM, cx); |
14574 | 0 |
|
14575 | 0 | JS::Rooted<JS::Value> result(cx); |
14576 | 0 | self->GetObj(cx, &result); |
14577 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
14578 | 0 | JS::ExposeValueToActiveJS(result); |
14579 | 0 | args.rval().set(result); |
14580 | 0 | if (!MaybeWrapValue(cx, args.rval())) { |
14581 | 0 | return false; |
14582 | 0 | } |
14583 | 0 | return true; |
14584 | 0 | } |
14585 | | |
14586 | | static const JSJitInfo obj_getterinfo = { |
14587 | | { (JSJitGetterOp)get_obj }, |
14588 | | { prototypes::id::WebGPULogEntry }, |
14589 | | { PrototypeTraits<prototypes::id::WebGPULogEntry>::Depth }, |
14590 | | JSJitInfo::Getter, |
14591 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
14592 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
14593 | | false, /* isInfallible. False in setters. */ |
14594 | | false, /* isMovable. Not relevant for setters. */ |
14595 | | false, /* isEliminatable. Not relevant for setters. */ |
14596 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
14597 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
14598 | | false, /* isTypedMethod. Only relevant for methods. */ |
14599 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
14600 | | }; |
14601 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
14602 | | static_assert(0 < 1, "There is no slot for us"); |
14603 | | |
14604 | | MOZ_CAN_RUN_SCRIPT static bool |
14605 | | get_reason(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::LogEntry* self, JSJitGetterCallArgs args) |
14606 | 0 | { |
14607 | 0 | AUTO_PROFILER_LABEL_FAST("get WebGPULogEntry.reason", DOM, cx); |
14608 | 0 |
|
14609 | 0 | DOMString result; |
14610 | 0 | self->GetReason(result); |
14611 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
14612 | 0 | if (!xpc::StringToJsval(cx, result, args.rval())) { |
14613 | 0 | return false; |
14614 | 0 | } |
14615 | 0 | return true; |
14616 | 0 | } |
14617 | | |
14618 | | static const JSJitInfo reason_getterinfo = { |
14619 | | { (JSJitGetterOp)get_reason }, |
14620 | | { prototypes::id::WebGPULogEntry }, |
14621 | | { PrototypeTraits<prototypes::id::WebGPULogEntry>::Depth }, |
14622 | | JSJitInfo::Getter, |
14623 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
14624 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
14625 | | false, /* isInfallible. False in setters. */ |
14626 | | false, /* isMovable. Not relevant for setters. */ |
14627 | | false, /* isEliminatable. Not relevant for setters. */ |
14628 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
14629 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
14630 | | false, /* isTypedMethod. Only relevant for methods. */ |
14631 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
14632 | | }; |
14633 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
14634 | | static_assert(0 < 1, "There is no slot for us"); |
14635 | | |
14636 | | static bool |
14637 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
14638 | 0 | { |
14639 | 0 | mozilla::webgpu::LogEntry* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::LogEntry>(obj); |
14640 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
14641 | 0 | // obviously can't preserve if we're not initialized. |
14642 | 0 | if (self && self->GetWrapperPreserveColor()) { |
14643 | 0 | PreserveWrapper(self); |
14644 | 0 | } |
14645 | 0 | return true; |
14646 | 0 | } |
14647 | | |
14648 | | static void |
14649 | | _finalize(js::FreeOp* fop, JSObject* obj) |
14650 | 0 | { |
14651 | 0 | mozilla::webgpu::LogEntry* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::LogEntry>(obj); |
14652 | 0 | if (self) { |
14653 | 0 | ClearWrapper(self, self, obj); |
14654 | 0 | AddForDeferredFinalization<mozilla::webgpu::LogEntry>(self); |
14655 | 0 | } |
14656 | 0 | } |
14657 | | |
14658 | | static size_t |
14659 | | _objectMoved(JSObject* obj, JSObject* old) |
14660 | 0 | { |
14661 | 0 | mozilla::webgpu::LogEntry* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::LogEntry>(obj); |
14662 | 0 | if (self) { |
14663 | 0 | UpdateWrapper(self, self, obj, old); |
14664 | 0 | } |
14665 | 0 |
|
14666 | 0 | return 0; |
14667 | 0 | } |
14668 | | |
14669 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
14670 | | #if defined(__clang__) |
14671 | | #pragma clang diagnostic push |
14672 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
14673 | | #endif |
14674 | | static const JSPropertySpec sAttributes_specs[] = { |
14675 | | { "type", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &type_getterinfo, nullptr, nullptr }, |
14676 | | { "obj", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &obj_getterinfo, nullptr, nullptr }, |
14677 | | { "reason", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &reason_getterinfo, nullptr, nullptr }, |
14678 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
14679 | | }; |
14680 | | #if defined(__clang__) |
14681 | | #pragma clang diagnostic pop |
14682 | | #endif |
14683 | | |
14684 | | |
14685 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
14686 | | { nullptr, &sAttributes_specs[0] }, |
14687 | | { nullptr, nullptr } |
14688 | | }; |
14689 | | |
14690 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
14691 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
14692 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
14693 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
14694 | | |
14695 | | |
14696 | | static uint16_t sNativeProperties_sortedPropertyIndices[3]; |
14697 | | static PropertyInfo sNativeProperties_propertyInfos[3]; |
14698 | | |
14699 | | static const NativePropertiesN<1> sNativeProperties = { |
14700 | | false, 0, |
14701 | | false, 0, |
14702 | | false, 0, |
14703 | | true, 0 /* sAttributes */, |
14704 | | false, 0, |
14705 | | false, 0, |
14706 | | false, 0, |
14707 | | -1, |
14708 | | 3, |
14709 | | sNativeProperties_sortedPropertyIndices, |
14710 | | { |
14711 | | { sAttributes, &sNativeProperties_propertyInfos[0] } |
14712 | | } |
14713 | | }; |
14714 | | static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
14715 | | "We have a property info count that is oversized"); |
14716 | | |
14717 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
14718 | | { |
14719 | | "Function", |
14720 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
14721 | | &sBoringInterfaceObjectClassClassOps, |
14722 | | JS_NULL_CLASS_SPEC, |
14723 | | JS_NULL_CLASS_EXT, |
14724 | | &sInterfaceObjectClassObjectOps |
14725 | | }, |
14726 | | eInterface, |
14727 | | true, |
14728 | | prototypes::id::WebGPULogEntry, |
14729 | | PrototypeTraits<prototypes::id::WebGPULogEntry>::Depth, |
14730 | | sNativePropertyHooks, |
14731 | | "function WebGPULogEntry() {\n [native code]\n}", |
14732 | | JS::GetRealmFunctionPrototype |
14733 | | }; |
14734 | | |
14735 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
14736 | | { |
14737 | | "WebGPULogEntryPrototype", |
14738 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
14739 | | JS_NULL_CLASS_OPS, |
14740 | | JS_NULL_CLASS_SPEC, |
14741 | | JS_NULL_CLASS_EXT, |
14742 | | JS_NULL_OBJECT_OPS |
14743 | | }, |
14744 | | eInterfacePrototype, |
14745 | | false, |
14746 | | prototypes::id::WebGPULogEntry, |
14747 | | PrototypeTraits<prototypes::id::WebGPULogEntry>::Depth, |
14748 | | sNativePropertyHooks, |
14749 | | "[object WebGPULogEntryPrototype]", |
14750 | | JS::GetRealmObjectPrototype |
14751 | | }; |
14752 | | |
14753 | | bool |
14754 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
14755 | 0 | { |
14756 | 0 | static bool sPrefValue; |
14757 | 0 | static bool sPrefCacheSetUp = false; |
14758 | 0 | if (!sPrefCacheSetUp) { |
14759 | 0 | sPrefCacheSetUp = true; |
14760 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
14761 | 0 | } |
14762 | 0 |
|
14763 | 0 | return sPrefValue; |
14764 | 0 | } |
14765 | | |
14766 | | static const js::ClassOps sClassOps = { |
14767 | | _addProperty, /* addProperty */ |
14768 | | nullptr, /* delProperty */ |
14769 | | nullptr, /* enumerate */ |
14770 | | nullptr, /* newEnumerate */ |
14771 | | nullptr, /* resolve */ |
14772 | | nullptr, /* mayResolve */ |
14773 | | _finalize, /* finalize */ |
14774 | | nullptr, /* call */ |
14775 | | nullptr, /* hasInstance */ |
14776 | | nullptr, /* construct */ |
14777 | | nullptr, /* trace */ |
14778 | | }; |
14779 | | |
14780 | | static const js::ClassExtension sClassExtension = { |
14781 | | nullptr, /* weakmapKeyDelegateOp */ |
14782 | | _objectMoved /* objectMovedOp */ |
14783 | | }; |
14784 | | |
14785 | | static const DOMJSClass sClass = { |
14786 | | { "WebGPULogEntry", |
14787 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
14788 | | &sClassOps, |
14789 | | JS_NULL_CLASS_SPEC, |
14790 | | &sClassExtension, |
14791 | | JS_NULL_OBJECT_OPS |
14792 | | }, |
14793 | | { prototypes::id::WebGPULogEntry, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
14794 | | IsBaseOf<nsISupports, mozilla::webgpu::LogEntry >::value, |
14795 | | sNativePropertyHooks, |
14796 | | FindAssociatedGlobalForNative<mozilla::webgpu::LogEntry>::Get, |
14797 | | GetProtoObjectHandle, |
14798 | | GetCCParticipant<mozilla::webgpu::LogEntry>::Get() |
14799 | | }; |
14800 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
14801 | | "Must have the right minimal number of reserved slots."); |
14802 | | static_assert(1 >= 1, |
14803 | | "Must have enough reserved slots."); |
14804 | | |
14805 | | const JSClass* |
14806 | | GetJSClass() |
14807 | 0 | { |
14808 | 0 | return sClass.ToJSClass(); |
14809 | 0 | } |
14810 | | |
14811 | | bool |
14812 | | Wrap(JSContext* aCx, mozilla::webgpu::LogEntry* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
14813 | 0 | { |
14814 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::LogEntry>::value, |
14815 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
14816 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::LogEntry*>(aObject) == |
14817 | 0 | reinterpret_cast<mozilla::webgpu::LogEntry*>(aObject), |
14818 | 0 | "Multiple inheritance for mozilla::webgpu::LogEntry is broken."); |
14819 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
14820 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
14821 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
14822 | 0 | "You should probably not be using Wrap() directly; use " |
14823 | 0 | "GetOrCreateDOMReflector instead"); |
14824 | 0 |
|
14825 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
14826 | 0 | "nsISupports must be on our primary inheritance chain"); |
14827 | 0 |
|
14828 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
14829 | 0 | if (!global) { |
14830 | 0 | return false; |
14831 | 0 | } |
14832 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
14833 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
14834 | 0 |
|
14835 | 0 | // That might have ended up wrapping us already, due to the wonders |
14836 | 0 | // of XBL. Check for that, and bail out as needed. |
14837 | 0 | aReflector.set(aCache->GetWrapper()); |
14838 | 0 | if (aReflector) { |
14839 | | #ifdef DEBUG |
14840 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
14841 | | #endif // DEBUG |
14842 | | return true; |
14843 | 0 | } |
14844 | 0 |
|
14845 | 0 | JSAutoRealm ar(aCx, global); |
14846 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
14847 | 0 | if (!canonicalProto) { |
14848 | 0 | return false; |
14849 | 0 | } |
14850 | 0 | JS::Rooted<JSObject*> proto(aCx); |
14851 | 0 | if (aGivenProto) { |
14852 | 0 | proto = aGivenProto; |
14853 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
14854 | 0 | // coming in, we changed compartments to that of "parent" so may need |
14855 | 0 | // to wrap the proto here. |
14856 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
14857 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
14858 | 0 | return false; |
14859 | 0 | } |
14860 | 0 | } |
14861 | 0 | } else { |
14862 | 0 | proto = canonicalProto; |
14863 | 0 | } |
14864 | 0 |
|
14865 | 0 | BindingJSObjectCreator<mozilla::webgpu::LogEntry> creator(aCx); |
14866 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
14867 | 0 | if (!aReflector) { |
14868 | 0 | return false; |
14869 | 0 | } |
14870 | 0 | |
14871 | 0 | aCache->SetWrapper(aReflector); |
14872 | 0 | creator.InitializationSucceeded(); |
14873 | 0 |
|
14874 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
14875 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
14876 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
14877 | 0 | // otherwise we won't be able to properly recreate it later, since |
14878 | 0 | // we won't know what proto to use. Note that we don't check |
14879 | 0 | // aGivenProto here, since it's entirely possible (and even |
14880 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
14881 | 0 | // same as canonicalProto. |
14882 | 0 | if (proto != canonicalProto) { |
14883 | 0 | PreserveWrapper(aObject); |
14884 | 0 | } |
14885 | 0 |
|
14886 | 0 | return true; |
14887 | 0 | } |
14888 | | |
14889 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
14890 | | nullptr, |
14891 | | nullptr, |
14892 | | nullptr, |
14893 | | { sNativeProperties.Upcast(), nullptr }, |
14894 | | prototypes::id::WebGPULogEntry, |
14895 | | constructors::id::WebGPULogEntry, |
14896 | | nullptr, |
14897 | | &DefaultXrayExpandoObjectClass |
14898 | | } }; |
14899 | | |
14900 | | void |
14901 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
14902 | 0 | { |
14903 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
14904 | 0 | if (!parentProto) { |
14905 | 0 | return; |
14906 | 0 | } |
14907 | 0 | |
14908 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
14909 | 0 | if (!constructorProto) { |
14910 | 0 | return; |
14911 | 0 | } |
14912 | 0 | |
14913 | 0 | static bool sIdsInited = false; |
14914 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
14915 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
14916 | 0 | return; |
14917 | 0 | } |
14918 | 0 | sIdsInited = true; |
14919 | 0 | } |
14920 | 0 |
|
14921 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPULogEntry); |
14922 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPULogEntry); |
14923 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
14924 | 0 | &sPrototypeClass.mBase, protoCache, |
14925 | 0 | nullptr, |
14926 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
14927 | 0 | interfaceCache, |
14928 | 0 | sNativeProperties.Upcast(), |
14929 | 0 | nullptr, |
14930 | 0 | "WebGPULogEntry", aDefineOnGlobal, |
14931 | 0 | nullptr, |
14932 | 0 | false); |
14933 | 0 | } |
14934 | | |
14935 | | JSObject* |
14936 | | GetConstructorObject(JSContext* aCx) |
14937 | 0 | { |
14938 | 0 | return GetConstructorObjectHandle(aCx); |
14939 | 0 | } |
14940 | | |
14941 | | } // namespace WebGPULogEntry_Binding |
14942 | | |
14943 | | |
14944 | | |
14945 | | namespace WebGPUPipelineLayout_Binding { |
14946 | | |
14947 | | static bool |
14948 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
14949 | 0 | { |
14950 | 0 | mozilla::webgpu::PipelineLayout* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::PipelineLayout>(obj); |
14951 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
14952 | 0 | // obviously can't preserve if we're not initialized. |
14953 | 0 | if (self && self->GetWrapperPreserveColor()) { |
14954 | 0 | PreserveWrapper(self); |
14955 | 0 | } |
14956 | 0 | return true; |
14957 | 0 | } |
14958 | | |
14959 | | static void |
14960 | | _finalize(js::FreeOp* fop, JSObject* obj) |
14961 | 0 | { |
14962 | 0 | mozilla::webgpu::PipelineLayout* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::PipelineLayout>(obj); |
14963 | 0 | if (self) { |
14964 | 0 | ClearWrapper(self, self, obj); |
14965 | 0 | AddForDeferredFinalization<mozilla::webgpu::PipelineLayout>(self); |
14966 | 0 | } |
14967 | 0 | } |
14968 | | |
14969 | | static size_t |
14970 | | _objectMoved(JSObject* obj, JSObject* old) |
14971 | 0 | { |
14972 | 0 | mozilla::webgpu::PipelineLayout* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::PipelineLayout>(obj); |
14973 | 0 | if (self) { |
14974 | 0 | UpdateWrapper(self, self, obj, old); |
14975 | 0 | } |
14976 | 0 |
|
14977 | 0 | return 0; |
14978 | 0 | } |
14979 | | |
14980 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
14981 | | { |
14982 | | "Function", |
14983 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
14984 | | &sBoringInterfaceObjectClassClassOps, |
14985 | | JS_NULL_CLASS_SPEC, |
14986 | | JS_NULL_CLASS_EXT, |
14987 | | &sInterfaceObjectClassObjectOps |
14988 | | }, |
14989 | | eInterface, |
14990 | | true, |
14991 | | prototypes::id::WebGPUPipelineLayout, |
14992 | | PrototypeTraits<prototypes::id::WebGPUPipelineLayout>::Depth, |
14993 | | sNativePropertyHooks, |
14994 | | "function WebGPUPipelineLayout() {\n [native code]\n}", |
14995 | | JS::GetRealmFunctionPrototype |
14996 | | }; |
14997 | | |
14998 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
14999 | | { |
15000 | | "WebGPUPipelineLayoutPrototype", |
15001 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
15002 | | JS_NULL_CLASS_OPS, |
15003 | | JS_NULL_CLASS_SPEC, |
15004 | | JS_NULL_CLASS_EXT, |
15005 | | JS_NULL_OBJECT_OPS |
15006 | | }, |
15007 | | eInterfacePrototype, |
15008 | | false, |
15009 | | prototypes::id::WebGPUPipelineLayout, |
15010 | | PrototypeTraits<prototypes::id::WebGPUPipelineLayout>::Depth, |
15011 | | sNativePropertyHooks, |
15012 | | "[object WebGPUPipelineLayoutPrototype]", |
15013 | | JS::GetRealmObjectPrototype |
15014 | | }; |
15015 | | |
15016 | | bool |
15017 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
15018 | 0 | { |
15019 | 0 | static bool sPrefValue; |
15020 | 0 | static bool sPrefCacheSetUp = false; |
15021 | 0 | if (!sPrefCacheSetUp) { |
15022 | 0 | sPrefCacheSetUp = true; |
15023 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
15024 | 0 | } |
15025 | 0 |
|
15026 | 0 | return sPrefValue; |
15027 | 0 | } |
15028 | | |
15029 | | static const js::ClassOps sClassOps = { |
15030 | | _addProperty, /* addProperty */ |
15031 | | nullptr, /* delProperty */ |
15032 | | nullptr, /* enumerate */ |
15033 | | nullptr, /* newEnumerate */ |
15034 | | nullptr, /* resolve */ |
15035 | | nullptr, /* mayResolve */ |
15036 | | _finalize, /* finalize */ |
15037 | | nullptr, /* call */ |
15038 | | nullptr, /* hasInstance */ |
15039 | | nullptr, /* construct */ |
15040 | | nullptr, /* trace */ |
15041 | | }; |
15042 | | |
15043 | | static const js::ClassExtension sClassExtension = { |
15044 | | nullptr, /* weakmapKeyDelegateOp */ |
15045 | | _objectMoved /* objectMovedOp */ |
15046 | | }; |
15047 | | |
15048 | | static const DOMJSClass sClass = { |
15049 | | { "WebGPUPipelineLayout", |
15050 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
15051 | | &sClassOps, |
15052 | | JS_NULL_CLASS_SPEC, |
15053 | | &sClassExtension, |
15054 | | JS_NULL_OBJECT_OPS |
15055 | | }, |
15056 | | { prototypes::id::WebGPUPipelineLayout, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
15057 | | IsBaseOf<nsISupports, mozilla::webgpu::PipelineLayout >::value, |
15058 | | sNativePropertyHooks, |
15059 | | FindAssociatedGlobalForNative<mozilla::webgpu::PipelineLayout>::Get, |
15060 | | GetProtoObjectHandle, |
15061 | | GetCCParticipant<mozilla::webgpu::PipelineLayout>::Get() |
15062 | | }; |
15063 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
15064 | | "Must have the right minimal number of reserved slots."); |
15065 | | static_assert(1 >= 1, |
15066 | | "Must have enough reserved slots."); |
15067 | | |
15068 | | const JSClass* |
15069 | | GetJSClass() |
15070 | 0 | { |
15071 | 0 | return sClass.ToJSClass(); |
15072 | 0 | } |
15073 | | |
15074 | | bool |
15075 | | Wrap(JSContext* aCx, mozilla::webgpu::PipelineLayout* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
15076 | 0 | { |
15077 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::PipelineLayout>::value, |
15078 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
15079 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::PipelineLayout*>(aObject) == |
15080 | 0 | reinterpret_cast<mozilla::webgpu::PipelineLayout*>(aObject), |
15081 | 0 | "Multiple inheritance for mozilla::webgpu::PipelineLayout is broken."); |
15082 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
15083 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
15084 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
15085 | 0 | "You should probably not be using Wrap() directly; use " |
15086 | 0 | "GetOrCreateDOMReflector instead"); |
15087 | 0 |
|
15088 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
15089 | 0 | "nsISupports must be on our primary inheritance chain"); |
15090 | 0 |
|
15091 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
15092 | 0 | if (!global) { |
15093 | 0 | return false; |
15094 | 0 | } |
15095 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
15096 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
15097 | 0 |
|
15098 | 0 | // That might have ended up wrapping us already, due to the wonders |
15099 | 0 | // of XBL. Check for that, and bail out as needed. |
15100 | 0 | aReflector.set(aCache->GetWrapper()); |
15101 | 0 | if (aReflector) { |
15102 | | #ifdef DEBUG |
15103 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
15104 | | #endif // DEBUG |
15105 | | return true; |
15106 | 0 | } |
15107 | 0 |
|
15108 | 0 | JSAutoRealm ar(aCx, global); |
15109 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
15110 | 0 | if (!canonicalProto) { |
15111 | 0 | return false; |
15112 | 0 | } |
15113 | 0 | JS::Rooted<JSObject*> proto(aCx); |
15114 | 0 | if (aGivenProto) { |
15115 | 0 | proto = aGivenProto; |
15116 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
15117 | 0 | // coming in, we changed compartments to that of "parent" so may need |
15118 | 0 | // to wrap the proto here. |
15119 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
15120 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
15121 | 0 | return false; |
15122 | 0 | } |
15123 | 0 | } |
15124 | 0 | } else { |
15125 | 0 | proto = canonicalProto; |
15126 | 0 | } |
15127 | 0 |
|
15128 | 0 | BindingJSObjectCreator<mozilla::webgpu::PipelineLayout> creator(aCx); |
15129 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
15130 | 0 | if (!aReflector) { |
15131 | 0 | return false; |
15132 | 0 | } |
15133 | 0 | |
15134 | 0 | aCache->SetWrapper(aReflector); |
15135 | 0 | creator.InitializationSucceeded(); |
15136 | 0 |
|
15137 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
15138 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
15139 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
15140 | 0 | // otherwise we won't be able to properly recreate it later, since |
15141 | 0 | // we won't know what proto to use. Note that we don't check |
15142 | 0 | // aGivenProto here, since it's entirely possible (and even |
15143 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
15144 | 0 | // same as canonicalProto. |
15145 | 0 | if (proto != canonicalProto) { |
15146 | 0 | PreserveWrapper(aObject); |
15147 | 0 | } |
15148 | 0 |
|
15149 | 0 | return true; |
15150 | 0 | } |
15151 | | |
15152 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
15153 | | nullptr, |
15154 | | nullptr, |
15155 | | nullptr, |
15156 | | { nullptr, nullptr }, |
15157 | | prototypes::id::WebGPUPipelineLayout, |
15158 | | constructors::id::WebGPUPipelineLayout, |
15159 | | nullptr, |
15160 | | &DefaultXrayExpandoObjectClass |
15161 | | } }; |
15162 | | |
15163 | | void |
15164 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
15165 | 0 | { |
15166 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
15167 | 0 | if (!parentProto) { |
15168 | 0 | return; |
15169 | 0 | } |
15170 | 0 | |
15171 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
15172 | 0 | if (!constructorProto) { |
15173 | 0 | return; |
15174 | 0 | } |
15175 | 0 | |
15176 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPUPipelineLayout); |
15177 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUPipelineLayout); |
15178 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
15179 | 0 | &sPrototypeClass.mBase, protoCache, |
15180 | 0 | nullptr, |
15181 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
15182 | 0 | interfaceCache, |
15183 | 0 | nullptr, |
15184 | 0 | nullptr, |
15185 | 0 | "WebGPUPipelineLayout", aDefineOnGlobal, |
15186 | 0 | nullptr, |
15187 | 0 | false); |
15188 | 0 | } |
15189 | | |
15190 | | JSObject* |
15191 | | GetConstructorObject(JSContext* aCx) |
15192 | 0 | { |
15193 | 0 | return GetConstructorObjectHandle(aCx); |
15194 | 0 | } |
15195 | | |
15196 | | } // namespace WebGPUPipelineLayout_Binding |
15197 | | |
15198 | | |
15199 | | |
15200 | | namespace WebGPUPrimitiveTopology_Binding { |
15201 | | |
15202 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
15203 | | #if defined(__clang__) |
15204 | | #pragma clang diagnostic push |
15205 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
15206 | | #endif |
15207 | | static const ConstantSpec sConstants_specs[] = { |
15208 | | { "POINT_LIST", JS::NumberValue(0U) }, |
15209 | | { "LINE_LIST", JS::NumberValue(1U) }, |
15210 | | { "LINE_STRIP", JS::NumberValue(2U) }, |
15211 | | { "TRIANGLE_LIST", JS::NumberValue(3U) }, |
15212 | | { "TRIANGLE_STRIP", JS::NumberValue(4U) }, |
15213 | | { 0, JS::UndefinedValue() } |
15214 | | }; |
15215 | | #if defined(__clang__) |
15216 | | #pragma clang diagnostic pop |
15217 | | #endif |
15218 | | |
15219 | | |
15220 | | static const Prefable<const ConstantSpec> sConstants[] = { |
15221 | | { nullptr, &sConstants_specs[0] }, |
15222 | | { nullptr, nullptr } |
15223 | | }; |
15224 | | |
15225 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
15226 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
15227 | | static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
15228 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
15229 | | |
15230 | | |
15231 | | static uint16_t sNativeProperties_sortedPropertyIndices[5]; |
15232 | | static PropertyInfo sNativeProperties_propertyInfos[5]; |
15233 | | |
15234 | | static const NativePropertiesN<1> sNativeProperties = { |
15235 | | false, 0, |
15236 | | false, 0, |
15237 | | false, 0, |
15238 | | false, 0, |
15239 | | false, 0, |
15240 | | false, 0, |
15241 | | true, 0 /* sConstants */, |
15242 | | -1, |
15243 | | 5, |
15244 | | sNativeProperties_sortedPropertyIndices, |
15245 | | { |
15246 | | { sConstants, &sNativeProperties_propertyInfos[0] } |
15247 | | } |
15248 | | }; |
15249 | | static_assert(5 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
15250 | | "We have a property info count that is oversized"); |
15251 | | |
15252 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
15253 | | { |
15254 | | "Function", |
15255 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
15256 | | &sBoringInterfaceObjectClassClassOps, |
15257 | | JS_NULL_CLASS_SPEC, |
15258 | | JS_NULL_CLASS_EXT, |
15259 | | &sInterfaceObjectClassObjectOps |
15260 | | }, |
15261 | | eInterface, |
15262 | | false, |
15263 | | prototypes::id::_ID_Count, |
15264 | | 0, |
15265 | | sNativePropertyHooks, |
15266 | | "function WebGPUPrimitiveTopology() {\n [native code]\n}", |
15267 | | JS::GetRealmFunctionPrototype |
15268 | | }; |
15269 | | |
15270 | | bool |
15271 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
15272 | 0 | { |
15273 | 0 | static bool sPrefValue; |
15274 | 0 | static bool sPrefCacheSetUp = false; |
15275 | 0 | if (!sPrefCacheSetUp) { |
15276 | 0 | sPrefCacheSetUp = true; |
15277 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
15278 | 0 | } |
15279 | 0 |
|
15280 | 0 | return sPrefValue; |
15281 | 0 | } |
15282 | | |
15283 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
15284 | | nullptr, |
15285 | | nullptr, |
15286 | | nullptr, |
15287 | | { sNativeProperties.Upcast(), nullptr }, |
15288 | | prototypes::id::_ID_Count, |
15289 | | constructors::id::WebGPUPrimitiveTopology, |
15290 | | nullptr, |
15291 | | &DefaultXrayExpandoObjectClass |
15292 | | } }; |
15293 | | |
15294 | | void |
15295 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
15296 | 0 | { |
15297 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
15298 | 0 | if (!constructorProto) { |
15299 | 0 | return; |
15300 | 0 | } |
15301 | 0 | |
15302 | 0 | static bool sIdsInited = false; |
15303 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
15304 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
15305 | 0 | return; |
15306 | 0 | } |
15307 | 0 | sIdsInited = true; |
15308 | 0 | } |
15309 | 0 |
|
15310 | 0 | JS::Heap<JSObject*>* protoCache = nullptr; |
15311 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUPrimitiveTopology); |
15312 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, nullptr, |
15313 | 0 | nullptr, protoCache, |
15314 | 0 | nullptr, |
15315 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
15316 | 0 | interfaceCache, |
15317 | 0 | sNativeProperties.Upcast(), |
15318 | 0 | nullptr, |
15319 | 0 | "WebGPUPrimitiveTopology", aDefineOnGlobal, |
15320 | 0 | nullptr, |
15321 | 0 | false); |
15322 | 0 | } |
15323 | | |
15324 | | JSObject* |
15325 | | GetConstructorObject(JSContext* aCx) |
15326 | 0 | { |
15327 | 0 | return GetConstructorObjectHandle(aCx); |
15328 | 0 | } |
15329 | | |
15330 | | } // namespace WebGPUPrimitiveTopology_Binding |
15331 | | |
15332 | | |
15333 | | |
15334 | | namespace WebGPUQueue_Binding { |
15335 | | |
15336 | | MOZ_CAN_RUN_SCRIPT static bool |
15337 | | submit(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Queue* self, const JSJitMethodCallArgs& args) |
15338 | 0 | { |
15339 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUQueue.submit", DOM, cx); |
15340 | 0 |
|
15341 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
15342 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebGPUQueue.submit"); |
15343 | 0 | } |
15344 | 0 | binding_detail::AutoSequence<OwningNonNull<mozilla::webgpu::CommandBuffer>> arg0; |
15345 | 0 | if (args[0].isObject()) { |
15346 | 0 | JS::ForOfIterator iter(cx); |
15347 | 0 | if (!iter.init(args[0], JS::ForOfIterator::AllowNonIterable)) { |
15348 | 0 | return false; |
15349 | 0 | } |
15350 | 0 | if (!iter.valueIsIterable()) { |
15351 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 1 of WebGPUQueue.submit"); |
15352 | 0 | return false; |
15353 | 0 | } |
15354 | 0 | binding_detail::AutoSequence<OwningNonNull<mozilla::webgpu::CommandBuffer>> &arr = arg0; |
15355 | 0 | JS::Rooted<JS::Value> temp(cx); |
15356 | 0 | while (true) { |
15357 | 0 | bool done; |
15358 | 0 | if (!iter.next(&temp, &done)) { |
15359 | 0 | return false; |
15360 | 0 | } |
15361 | 0 | if (done) { |
15362 | 0 | break; |
15363 | 0 | } |
15364 | 0 | OwningNonNull<mozilla::webgpu::CommandBuffer>* slotPtr = arr.AppendElement(mozilla::fallible); |
15365 | 0 | if (!slotPtr) { |
15366 | 0 | JS_ReportOutOfMemory(cx); |
15367 | 0 | return false; |
15368 | 0 | } |
15369 | 0 | OwningNonNull<mozilla::webgpu::CommandBuffer>& slot = *slotPtr; |
15370 | 0 | if (temp.isObject()) { |
15371 | 0 | static_assert(IsRefcounted<mozilla::webgpu::CommandBuffer>::value, "We can only store refcounted classes.");{ |
15372 | 0 | nsresult rv = UnwrapObject<prototypes::id::WebGPUCommandBuffer, mozilla::webgpu::CommandBuffer>(&temp, slot); |
15373 | 0 | if (NS_FAILED(rv)) { |
15374 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of argument 1 of WebGPUQueue.submit", "WebGPUCommandBuffer"); |
15375 | 0 | return false; |
15376 | 0 | } |
15377 | 0 | } |
15378 | 0 | } else { |
15379 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of argument 1 of WebGPUQueue.submit"); |
15380 | 0 | return false; |
15381 | 0 | } |
15382 | 0 | } |
15383 | 0 | } else { |
15384 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 1 of WebGPUQueue.submit"); |
15385 | 0 | return false; |
15386 | 0 | } |
15387 | 0 | self->Submit(Constify(arg0)); |
15388 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
15389 | 0 | args.rval().setUndefined(); |
15390 | 0 | return true; |
15391 | 0 | } |
15392 | | |
15393 | | static const JSJitInfo submit_methodinfo = { |
15394 | | { (JSJitGetterOp)submit }, |
15395 | | { prototypes::id::WebGPUQueue }, |
15396 | | { PrototypeTraits<prototypes::id::WebGPUQueue>::Depth }, |
15397 | | JSJitInfo::Method, |
15398 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
15399 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
15400 | | false, /* isInfallible. False in setters. */ |
15401 | | false, /* isMovable. Not relevant for setters. */ |
15402 | | false, /* isEliminatable. Not relevant for setters. */ |
15403 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
15404 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
15405 | | false, /* isTypedMethod. Only relevant for methods. */ |
15406 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
15407 | | }; |
15408 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
15409 | | static_assert(0 < 1, "There is no slot for us"); |
15410 | | |
15411 | | MOZ_CAN_RUN_SCRIPT static bool |
15412 | | insertFence(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Queue* self, const JSJitMethodCallArgs& args) |
15413 | 0 | { |
15414 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUQueue.insertFence", DOM, cx); |
15415 | 0 |
|
15416 | 0 | auto result(StrongOrRawPtr<mozilla::webgpu::Fence>(self->InsertFence())); |
15417 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
15418 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
15419 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
15420 | 0 | return false; |
15421 | 0 | } |
15422 | 0 | return true; |
15423 | 0 | } |
15424 | | |
15425 | | static const JSJitInfo insertFence_methodinfo = { |
15426 | | { (JSJitGetterOp)insertFence }, |
15427 | | { prototypes::id::WebGPUQueue }, |
15428 | | { PrototypeTraits<prototypes::id::WebGPUQueue>::Depth }, |
15429 | | JSJitInfo::Method, |
15430 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
15431 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
15432 | | false, /* isInfallible. False in setters. */ |
15433 | | false, /* isMovable. Not relevant for setters. */ |
15434 | | false, /* isEliminatable. Not relevant for setters. */ |
15435 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
15436 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
15437 | | false, /* isTypedMethod. Only relevant for methods. */ |
15438 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
15439 | | }; |
15440 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
15441 | | static_assert(0 < 1, "There is no slot for us"); |
15442 | | |
15443 | | static bool |
15444 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
15445 | 0 | { |
15446 | 0 | mozilla::webgpu::Queue* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Queue>(obj); |
15447 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
15448 | 0 | // obviously can't preserve if we're not initialized. |
15449 | 0 | if (self && self->GetWrapperPreserveColor()) { |
15450 | 0 | PreserveWrapper(self); |
15451 | 0 | } |
15452 | 0 | return true; |
15453 | 0 | } |
15454 | | |
15455 | | static void |
15456 | | _finalize(js::FreeOp* fop, JSObject* obj) |
15457 | 0 | { |
15458 | 0 | mozilla::webgpu::Queue* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Queue>(obj); |
15459 | 0 | if (self) { |
15460 | 0 | ClearWrapper(self, self, obj); |
15461 | 0 | AddForDeferredFinalization<mozilla::webgpu::Queue>(self); |
15462 | 0 | } |
15463 | 0 | } |
15464 | | |
15465 | | static size_t |
15466 | | _objectMoved(JSObject* obj, JSObject* old) |
15467 | 0 | { |
15468 | 0 | mozilla::webgpu::Queue* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Queue>(obj); |
15469 | 0 | if (self) { |
15470 | 0 | UpdateWrapper(self, self, obj, old); |
15471 | 0 | } |
15472 | 0 |
|
15473 | 0 | return 0; |
15474 | 0 | } |
15475 | | |
15476 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
15477 | | #if defined(__clang__) |
15478 | | #pragma clang diagnostic push |
15479 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
15480 | | #endif |
15481 | | static const JSFunctionSpec sMethods_specs[] = { |
15482 | | JS_FNSPEC("submit", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&submit_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
15483 | | JS_FNSPEC("insertFence", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&insertFence_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
15484 | | JS_FS_END |
15485 | | }; |
15486 | | #if defined(__clang__) |
15487 | | #pragma clang diagnostic pop |
15488 | | #endif |
15489 | | |
15490 | | |
15491 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
15492 | | { nullptr, &sMethods_specs[0] }, |
15493 | | { nullptr, nullptr } |
15494 | | }; |
15495 | | |
15496 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
15497 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
15498 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
15499 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
15500 | | |
15501 | | |
15502 | | static uint16_t sNativeProperties_sortedPropertyIndices[2]; |
15503 | | static PropertyInfo sNativeProperties_propertyInfos[2]; |
15504 | | |
15505 | | static const NativePropertiesN<1> sNativeProperties = { |
15506 | | false, 0, |
15507 | | false, 0, |
15508 | | true, 0 /* sMethods */, |
15509 | | false, 0, |
15510 | | false, 0, |
15511 | | false, 0, |
15512 | | false, 0, |
15513 | | -1, |
15514 | | 2, |
15515 | | sNativeProperties_sortedPropertyIndices, |
15516 | | { |
15517 | | { sMethods, &sNativeProperties_propertyInfos[0] } |
15518 | | } |
15519 | | }; |
15520 | | static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
15521 | | "We have a property info count that is oversized"); |
15522 | | |
15523 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
15524 | | { |
15525 | | "Function", |
15526 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
15527 | | &sBoringInterfaceObjectClassClassOps, |
15528 | | JS_NULL_CLASS_SPEC, |
15529 | | JS_NULL_CLASS_EXT, |
15530 | | &sInterfaceObjectClassObjectOps |
15531 | | }, |
15532 | | eInterface, |
15533 | | true, |
15534 | | prototypes::id::WebGPUQueue, |
15535 | | PrototypeTraits<prototypes::id::WebGPUQueue>::Depth, |
15536 | | sNativePropertyHooks, |
15537 | | "function WebGPUQueue() {\n [native code]\n}", |
15538 | | JS::GetRealmFunctionPrototype |
15539 | | }; |
15540 | | |
15541 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
15542 | | { |
15543 | | "WebGPUQueuePrototype", |
15544 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
15545 | | JS_NULL_CLASS_OPS, |
15546 | | JS_NULL_CLASS_SPEC, |
15547 | | JS_NULL_CLASS_EXT, |
15548 | | JS_NULL_OBJECT_OPS |
15549 | | }, |
15550 | | eInterfacePrototype, |
15551 | | false, |
15552 | | prototypes::id::WebGPUQueue, |
15553 | | PrototypeTraits<prototypes::id::WebGPUQueue>::Depth, |
15554 | | sNativePropertyHooks, |
15555 | | "[object WebGPUQueuePrototype]", |
15556 | | JS::GetRealmObjectPrototype |
15557 | | }; |
15558 | | |
15559 | | bool |
15560 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
15561 | 0 | { |
15562 | 0 | static bool sPrefValue; |
15563 | 0 | static bool sPrefCacheSetUp = false; |
15564 | 0 | if (!sPrefCacheSetUp) { |
15565 | 0 | sPrefCacheSetUp = true; |
15566 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
15567 | 0 | } |
15568 | 0 |
|
15569 | 0 | return sPrefValue; |
15570 | 0 | } |
15571 | | |
15572 | | static const js::ClassOps sClassOps = { |
15573 | | _addProperty, /* addProperty */ |
15574 | | nullptr, /* delProperty */ |
15575 | | nullptr, /* enumerate */ |
15576 | | nullptr, /* newEnumerate */ |
15577 | | nullptr, /* resolve */ |
15578 | | nullptr, /* mayResolve */ |
15579 | | _finalize, /* finalize */ |
15580 | | nullptr, /* call */ |
15581 | | nullptr, /* hasInstance */ |
15582 | | nullptr, /* construct */ |
15583 | | nullptr, /* trace */ |
15584 | | }; |
15585 | | |
15586 | | static const js::ClassExtension sClassExtension = { |
15587 | | nullptr, /* weakmapKeyDelegateOp */ |
15588 | | _objectMoved /* objectMovedOp */ |
15589 | | }; |
15590 | | |
15591 | | static const DOMJSClass sClass = { |
15592 | | { "WebGPUQueue", |
15593 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
15594 | | &sClassOps, |
15595 | | JS_NULL_CLASS_SPEC, |
15596 | | &sClassExtension, |
15597 | | JS_NULL_OBJECT_OPS |
15598 | | }, |
15599 | | { prototypes::id::WebGPUQueue, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
15600 | | IsBaseOf<nsISupports, mozilla::webgpu::Queue >::value, |
15601 | | sNativePropertyHooks, |
15602 | | FindAssociatedGlobalForNative<mozilla::webgpu::Queue>::Get, |
15603 | | GetProtoObjectHandle, |
15604 | | GetCCParticipant<mozilla::webgpu::Queue>::Get() |
15605 | | }; |
15606 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
15607 | | "Must have the right minimal number of reserved slots."); |
15608 | | static_assert(1 >= 1, |
15609 | | "Must have enough reserved slots."); |
15610 | | |
15611 | | const JSClass* |
15612 | | GetJSClass() |
15613 | 0 | { |
15614 | 0 | return sClass.ToJSClass(); |
15615 | 0 | } |
15616 | | |
15617 | | bool |
15618 | | Wrap(JSContext* aCx, mozilla::webgpu::Queue* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
15619 | 0 | { |
15620 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::Queue>::value, |
15621 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
15622 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::Queue*>(aObject) == |
15623 | 0 | reinterpret_cast<mozilla::webgpu::Queue*>(aObject), |
15624 | 0 | "Multiple inheritance for mozilla::webgpu::Queue is broken."); |
15625 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
15626 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
15627 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
15628 | 0 | "You should probably not be using Wrap() directly; use " |
15629 | 0 | "GetOrCreateDOMReflector instead"); |
15630 | 0 |
|
15631 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
15632 | 0 | "nsISupports must be on our primary inheritance chain"); |
15633 | 0 |
|
15634 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
15635 | 0 | if (!global) { |
15636 | 0 | return false; |
15637 | 0 | } |
15638 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
15639 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
15640 | 0 |
|
15641 | 0 | // That might have ended up wrapping us already, due to the wonders |
15642 | 0 | // of XBL. Check for that, and bail out as needed. |
15643 | 0 | aReflector.set(aCache->GetWrapper()); |
15644 | 0 | if (aReflector) { |
15645 | | #ifdef DEBUG |
15646 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
15647 | | #endif // DEBUG |
15648 | | return true; |
15649 | 0 | } |
15650 | 0 |
|
15651 | 0 | JSAutoRealm ar(aCx, global); |
15652 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
15653 | 0 | if (!canonicalProto) { |
15654 | 0 | return false; |
15655 | 0 | } |
15656 | 0 | JS::Rooted<JSObject*> proto(aCx); |
15657 | 0 | if (aGivenProto) { |
15658 | 0 | proto = aGivenProto; |
15659 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
15660 | 0 | // coming in, we changed compartments to that of "parent" so may need |
15661 | 0 | // to wrap the proto here. |
15662 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
15663 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
15664 | 0 | return false; |
15665 | 0 | } |
15666 | 0 | } |
15667 | 0 | } else { |
15668 | 0 | proto = canonicalProto; |
15669 | 0 | } |
15670 | 0 |
|
15671 | 0 | BindingJSObjectCreator<mozilla::webgpu::Queue> creator(aCx); |
15672 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
15673 | 0 | if (!aReflector) { |
15674 | 0 | return false; |
15675 | 0 | } |
15676 | 0 | |
15677 | 0 | aCache->SetWrapper(aReflector); |
15678 | 0 | creator.InitializationSucceeded(); |
15679 | 0 |
|
15680 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
15681 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
15682 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
15683 | 0 | // otherwise we won't be able to properly recreate it later, since |
15684 | 0 | // we won't know what proto to use. Note that we don't check |
15685 | 0 | // aGivenProto here, since it's entirely possible (and even |
15686 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
15687 | 0 | // same as canonicalProto. |
15688 | 0 | if (proto != canonicalProto) { |
15689 | 0 | PreserveWrapper(aObject); |
15690 | 0 | } |
15691 | 0 |
|
15692 | 0 | return true; |
15693 | 0 | } |
15694 | | |
15695 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
15696 | | nullptr, |
15697 | | nullptr, |
15698 | | nullptr, |
15699 | | { sNativeProperties.Upcast(), nullptr }, |
15700 | | prototypes::id::WebGPUQueue, |
15701 | | constructors::id::WebGPUQueue, |
15702 | | nullptr, |
15703 | | &DefaultXrayExpandoObjectClass |
15704 | | } }; |
15705 | | |
15706 | | void |
15707 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
15708 | 0 | { |
15709 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
15710 | 0 | if (!parentProto) { |
15711 | 0 | return; |
15712 | 0 | } |
15713 | 0 | |
15714 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
15715 | 0 | if (!constructorProto) { |
15716 | 0 | return; |
15717 | 0 | } |
15718 | 0 | |
15719 | 0 | static bool sIdsInited = false; |
15720 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
15721 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
15722 | 0 | return; |
15723 | 0 | } |
15724 | 0 | sIdsInited = true; |
15725 | 0 | } |
15726 | 0 |
|
15727 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPUQueue); |
15728 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUQueue); |
15729 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
15730 | 0 | &sPrototypeClass.mBase, protoCache, |
15731 | 0 | nullptr, |
15732 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
15733 | 0 | interfaceCache, |
15734 | 0 | sNativeProperties.Upcast(), |
15735 | 0 | nullptr, |
15736 | 0 | "WebGPUQueue", aDefineOnGlobal, |
15737 | 0 | nullptr, |
15738 | 0 | false); |
15739 | 0 | } |
15740 | | |
15741 | | JSObject* |
15742 | | GetConstructorObject(JSContext* aCx) |
15743 | 0 | { |
15744 | 0 | return GetConstructorObjectHandle(aCx); |
15745 | 0 | } |
15746 | | |
15747 | | } // namespace WebGPUQueue_Binding |
15748 | | |
15749 | | |
15750 | | |
15751 | | namespace WebGPURenderPipeline_Binding { |
15752 | | |
15753 | | static bool |
15754 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
15755 | 0 | { |
15756 | 0 | mozilla::webgpu::RenderPipeline* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::RenderPipeline>(obj); |
15757 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
15758 | 0 | // obviously can't preserve if we're not initialized. |
15759 | 0 | if (self && self->GetWrapperPreserveColor()) { |
15760 | 0 | PreserveWrapper(self); |
15761 | 0 | } |
15762 | 0 | return true; |
15763 | 0 | } |
15764 | | |
15765 | | static void |
15766 | | _finalize(js::FreeOp* fop, JSObject* obj) |
15767 | 0 | { |
15768 | 0 | mozilla::webgpu::RenderPipeline* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::RenderPipeline>(obj); |
15769 | 0 | if (self) { |
15770 | 0 | ClearWrapper(self, self, obj); |
15771 | 0 | AddForDeferredFinalization<mozilla::webgpu::RenderPipeline>(self); |
15772 | 0 | } |
15773 | 0 | } |
15774 | | |
15775 | | static size_t |
15776 | | _objectMoved(JSObject* obj, JSObject* old) |
15777 | 0 | { |
15778 | 0 | mozilla::webgpu::RenderPipeline* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::RenderPipeline>(obj); |
15779 | 0 | if (self) { |
15780 | 0 | UpdateWrapper(self, self, obj, old); |
15781 | 0 | } |
15782 | 0 |
|
15783 | 0 | return 0; |
15784 | 0 | } |
15785 | | |
15786 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
15787 | | { |
15788 | | "Function", |
15789 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
15790 | | &sBoringInterfaceObjectClassClassOps, |
15791 | | JS_NULL_CLASS_SPEC, |
15792 | | JS_NULL_CLASS_EXT, |
15793 | | &sInterfaceObjectClassObjectOps |
15794 | | }, |
15795 | | eInterface, |
15796 | | true, |
15797 | | prototypes::id::WebGPURenderPipeline, |
15798 | | PrototypeTraits<prototypes::id::WebGPURenderPipeline>::Depth, |
15799 | | sNativePropertyHooks, |
15800 | | "function WebGPURenderPipeline() {\n [native code]\n}", |
15801 | | JS::GetRealmFunctionPrototype |
15802 | | }; |
15803 | | |
15804 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
15805 | | { |
15806 | | "WebGPURenderPipelinePrototype", |
15807 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
15808 | | JS_NULL_CLASS_OPS, |
15809 | | JS_NULL_CLASS_SPEC, |
15810 | | JS_NULL_CLASS_EXT, |
15811 | | JS_NULL_OBJECT_OPS |
15812 | | }, |
15813 | | eInterfacePrototype, |
15814 | | false, |
15815 | | prototypes::id::WebGPURenderPipeline, |
15816 | | PrototypeTraits<prototypes::id::WebGPURenderPipeline>::Depth, |
15817 | | sNativePropertyHooks, |
15818 | | "[object WebGPURenderPipelinePrototype]", |
15819 | | JS::GetRealmObjectPrototype |
15820 | | }; |
15821 | | |
15822 | | bool |
15823 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
15824 | 0 | { |
15825 | 0 | static bool sPrefValue; |
15826 | 0 | static bool sPrefCacheSetUp = false; |
15827 | 0 | if (!sPrefCacheSetUp) { |
15828 | 0 | sPrefCacheSetUp = true; |
15829 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
15830 | 0 | } |
15831 | 0 |
|
15832 | 0 | return sPrefValue; |
15833 | 0 | } |
15834 | | |
15835 | | static const js::ClassOps sClassOps = { |
15836 | | _addProperty, /* addProperty */ |
15837 | | nullptr, /* delProperty */ |
15838 | | nullptr, /* enumerate */ |
15839 | | nullptr, /* newEnumerate */ |
15840 | | nullptr, /* resolve */ |
15841 | | nullptr, /* mayResolve */ |
15842 | | _finalize, /* finalize */ |
15843 | | nullptr, /* call */ |
15844 | | nullptr, /* hasInstance */ |
15845 | | nullptr, /* construct */ |
15846 | | nullptr, /* trace */ |
15847 | | }; |
15848 | | |
15849 | | static const js::ClassExtension sClassExtension = { |
15850 | | nullptr, /* weakmapKeyDelegateOp */ |
15851 | | _objectMoved /* objectMovedOp */ |
15852 | | }; |
15853 | | |
15854 | | static const DOMJSClass sClass = { |
15855 | | { "WebGPURenderPipeline", |
15856 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
15857 | | &sClassOps, |
15858 | | JS_NULL_CLASS_SPEC, |
15859 | | &sClassExtension, |
15860 | | JS_NULL_OBJECT_OPS |
15861 | | }, |
15862 | | { prototypes::id::WebGPURenderPipeline, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
15863 | | IsBaseOf<nsISupports, mozilla::webgpu::RenderPipeline >::value, |
15864 | | sNativePropertyHooks, |
15865 | | FindAssociatedGlobalForNative<mozilla::webgpu::RenderPipeline>::Get, |
15866 | | GetProtoObjectHandle, |
15867 | | GetCCParticipant<mozilla::webgpu::RenderPipeline>::Get() |
15868 | | }; |
15869 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
15870 | | "Must have the right minimal number of reserved slots."); |
15871 | | static_assert(1 >= 1, |
15872 | | "Must have enough reserved slots."); |
15873 | | |
15874 | | const JSClass* |
15875 | | GetJSClass() |
15876 | 0 | { |
15877 | 0 | return sClass.ToJSClass(); |
15878 | 0 | } |
15879 | | |
15880 | | bool |
15881 | | Wrap(JSContext* aCx, mozilla::webgpu::RenderPipeline* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
15882 | 0 | { |
15883 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::RenderPipeline>::value, |
15884 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
15885 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::RenderPipeline*>(aObject) == |
15886 | 0 | reinterpret_cast<mozilla::webgpu::RenderPipeline*>(aObject), |
15887 | 0 | "Multiple inheritance for mozilla::webgpu::RenderPipeline is broken."); |
15888 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
15889 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
15890 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
15891 | 0 | "You should probably not be using Wrap() directly; use " |
15892 | 0 | "GetOrCreateDOMReflector instead"); |
15893 | 0 |
|
15894 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
15895 | 0 | "nsISupports must be on our primary inheritance chain"); |
15896 | 0 |
|
15897 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
15898 | 0 | if (!global) { |
15899 | 0 | return false; |
15900 | 0 | } |
15901 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
15902 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
15903 | 0 |
|
15904 | 0 | // That might have ended up wrapping us already, due to the wonders |
15905 | 0 | // of XBL. Check for that, and bail out as needed. |
15906 | 0 | aReflector.set(aCache->GetWrapper()); |
15907 | 0 | if (aReflector) { |
15908 | | #ifdef DEBUG |
15909 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
15910 | | #endif // DEBUG |
15911 | | return true; |
15912 | 0 | } |
15913 | 0 |
|
15914 | 0 | JSAutoRealm ar(aCx, global); |
15915 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
15916 | 0 | if (!canonicalProto) { |
15917 | 0 | return false; |
15918 | 0 | } |
15919 | 0 | JS::Rooted<JSObject*> proto(aCx); |
15920 | 0 | if (aGivenProto) { |
15921 | 0 | proto = aGivenProto; |
15922 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
15923 | 0 | // coming in, we changed compartments to that of "parent" so may need |
15924 | 0 | // to wrap the proto here. |
15925 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
15926 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
15927 | 0 | return false; |
15928 | 0 | } |
15929 | 0 | } |
15930 | 0 | } else { |
15931 | 0 | proto = canonicalProto; |
15932 | 0 | } |
15933 | 0 |
|
15934 | 0 | BindingJSObjectCreator<mozilla::webgpu::RenderPipeline> creator(aCx); |
15935 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
15936 | 0 | if (!aReflector) { |
15937 | 0 | return false; |
15938 | 0 | } |
15939 | 0 | |
15940 | 0 | aCache->SetWrapper(aReflector); |
15941 | 0 | creator.InitializationSucceeded(); |
15942 | 0 |
|
15943 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
15944 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
15945 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
15946 | 0 | // otherwise we won't be able to properly recreate it later, since |
15947 | 0 | // we won't know what proto to use. Note that we don't check |
15948 | 0 | // aGivenProto here, since it's entirely possible (and even |
15949 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
15950 | 0 | // same as canonicalProto. |
15951 | 0 | if (proto != canonicalProto) { |
15952 | 0 | PreserveWrapper(aObject); |
15953 | 0 | } |
15954 | 0 |
|
15955 | 0 | return true; |
15956 | 0 | } |
15957 | | |
15958 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
15959 | | nullptr, |
15960 | | nullptr, |
15961 | | nullptr, |
15962 | | { nullptr, nullptr }, |
15963 | | prototypes::id::WebGPURenderPipeline, |
15964 | | constructors::id::WebGPURenderPipeline, |
15965 | | nullptr, |
15966 | | &DefaultXrayExpandoObjectClass |
15967 | | } }; |
15968 | | |
15969 | | void |
15970 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
15971 | 0 | { |
15972 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
15973 | 0 | if (!parentProto) { |
15974 | 0 | return; |
15975 | 0 | } |
15976 | 0 | |
15977 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
15978 | 0 | if (!constructorProto) { |
15979 | 0 | return; |
15980 | 0 | } |
15981 | 0 | |
15982 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPURenderPipeline); |
15983 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPURenderPipeline); |
15984 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
15985 | 0 | &sPrototypeClass.mBase, protoCache, |
15986 | 0 | nullptr, |
15987 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
15988 | 0 | interfaceCache, |
15989 | 0 | nullptr, |
15990 | 0 | nullptr, |
15991 | 0 | "WebGPURenderPipeline", aDefineOnGlobal, |
15992 | 0 | nullptr, |
15993 | 0 | false); |
15994 | 0 | } |
15995 | | |
15996 | | JSObject* |
15997 | | GetConstructorObject(JSContext* aCx) |
15998 | 0 | { |
15999 | 0 | return GetConstructorObjectHandle(aCx); |
16000 | 0 | } |
16001 | | |
16002 | | } // namespace WebGPURenderPipeline_Binding |
16003 | | |
16004 | | |
16005 | | |
16006 | | namespace WebGPUSampler_Binding { |
16007 | | |
16008 | | static bool |
16009 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
16010 | 0 | { |
16011 | 0 | mozilla::webgpu::Sampler* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Sampler>(obj); |
16012 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
16013 | 0 | // obviously can't preserve if we're not initialized. |
16014 | 0 | if (self && self->GetWrapperPreserveColor()) { |
16015 | 0 | PreserveWrapper(self); |
16016 | 0 | } |
16017 | 0 | return true; |
16018 | 0 | } |
16019 | | |
16020 | | static void |
16021 | | _finalize(js::FreeOp* fop, JSObject* obj) |
16022 | 0 | { |
16023 | 0 | mozilla::webgpu::Sampler* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Sampler>(obj); |
16024 | 0 | if (self) { |
16025 | 0 | ClearWrapper(self, self, obj); |
16026 | 0 | AddForDeferredFinalization<mozilla::webgpu::Sampler>(self); |
16027 | 0 | } |
16028 | 0 | } |
16029 | | |
16030 | | static size_t |
16031 | | _objectMoved(JSObject* obj, JSObject* old) |
16032 | 0 | { |
16033 | 0 | mozilla::webgpu::Sampler* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Sampler>(obj); |
16034 | 0 | if (self) { |
16035 | 0 | UpdateWrapper(self, self, obj, old); |
16036 | 0 | } |
16037 | 0 |
|
16038 | 0 | return 0; |
16039 | 0 | } |
16040 | | |
16041 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
16042 | | { |
16043 | | "Function", |
16044 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
16045 | | &sBoringInterfaceObjectClassClassOps, |
16046 | | JS_NULL_CLASS_SPEC, |
16047 | | JS_NULL_CLASS_EXT, |
16048 | | &sInterfaceObjectClassObjectOps |
16049 | | }, |
16050 | | eInterface, |
16051 | | true, |
16052 | | prototypes::id::WebGPUSampler, |
16053 | | PrototypeTraits<prototypes::id::WebGPUSampler>::Depth, |
16054 | | sNativePropertyHooks, |
16055 | | "function WebGPUSampler() {\n [native code]\n}", |
16056 | | JS::GetRealmFunctionPrototype |
16057 | | }; |
16058 | | |
16059 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
16060 | | { |
16061 | | "WebGPUSamplerPrototype", |
16062 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
16063 | | JS_NULL_CLASS_OPS, |
16064 | | JS_NULL_CLASS_SPEC, |
16065 | | JS_NULL_CLASS_EXT, |
16066 | | JS_NULL_OBJECT_OPS |
16067 | | }, |
16068 | | eInterfacePrototype, |
16069 | | false, |
16070 | | prototypes::id::WebGPUSampler, |
16071 | | PrototypeTraits<prototypes::id::WebGPUSampler>::Depth, |
16072 | | sNativePropertyHooks, |
16073 | | "[object WebGPUSamplerPrototype]", |
16074 | | JS::GetRealmObjectPrototype |
16075 | | }; |
16076 | | |
16077 | | bool |
16078 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
16079 | 0 | { |
16080 | 0 | static bool sPrefValue; |
16081 | 0 | static bool sPrefCacheSetUp = false; |
16082 | 0 | if (!sPrefCacheSetUp) { |
16083 | 0 | sPrefCacheSetUp = true; |
16084 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
16085 | 0 | } |
16086 | 0 |
|
16087 | 0 | return sPrefValue; |
16088 | 0 | } |
16089 | | |
16090 | | static const js::ClassOps sClassOps = { |
16091 | | _addProperty, /* addProperty */ |
16092 | | nullptr, /* delProperty */ |
16093 | | nullptr, /* enumerate */ |
16094 | | nullptr, /* newEnumerate */ |
16095 | | nullptr, /* resolve */ |
16096 | | nullptr, /* mayResolve */ |
16097 | | _finalize, /* finalize */ |
16098 | | nullptr, /* call */ |
16099 | | nullptr, /* hasInstance */ |
16100 | | nullptr, /* construct */ |
16101 | | nullptr, /* trace */ |
16102 | | }; |
16103 | | |
16104 | | static const js::ClassExtension sClassExtension = { |
16105 | | nullptr, /* weakmapKeyDelegateOp */ |
16106 | | _objectMoved /* objectMovedOp */ |
16107 | | }; |
16108 | | |
16109 | | static const DOMJSClass sClass = { |
16110 | | { "WebGPUSampler", |
16111 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
16112 | | &sClassOps, |
16113 | | JS_NULL_CLASS_SPEC, |
16114 | | &sClassExtension, |
16115 | | JS_NULL_OBJECT_OPS |
16116 | | }, |
16117 | | { prototypes::id::WebGPUSampler, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
16118 | | IsBaseOf<nsISupports, mozilla::webgpu::Sampler >::value, |
16119 | | sNativePropertyHooks, |
16120 | | FindAssociatedGlobalForNative<mozilla::webgpu::Sampler>::Get, |
16121 | | GetProtoObjectHandle, |
16122 | | GetCCParticipant<mozilla::webgpu::Sampler>::Get() |
16123 | | }; |
16124 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
16125 | | "Must have the right minimal number of reserved slots."); |
16126 | | static_assert(1 >= 1, |
16127 | | "Must have enough reserved slots."); |
16128 | | |
16129 | | const JSClass* |
16130 | | GetJSClass() |
16131 | 0 | { |
16132 | 0 | return sClass.ToJSClass(); |
16133 | 0 | } |
16134 | | |
16135 | | bool |
16136 | | Wrap(JSContext* aCx, mozilla::webgpu::Sampler* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
16137 | 0 | { |
16138 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::Sampler>::value, |
16139 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
16140 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::Sampler*>(aObject) == |
16141 | 0 | reinterpret_cast<mozilla::webgpu::Sampler*>(aObject), |
16142 | 0 | "Multiple inheritance for mozilla::webgpu::Sampler is broken."); |
16143 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
16144 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
16145 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
16146 | 0 | "You should probably not be using Wrap() directly; use " |
16147 | 0 | "GetOrCreateDOMReflector instead"); |
16148 | 0 |
|
16149 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
16150 | 0 | "nsISupports must be on our primary inheritance chain"); |
16151 | 0 |
|
16152 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
16153 | 0 | if (!global) { |
16154 | 0 | return false; |
16155 | 0 | } |
16156 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
16157 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
16158 | 0 |
|
16159 | 0 | // That might have ended up wrapping us already, due to the wonders |
16160 | 0 | // of XBL. Check for that, and bail out as needed. |
16161 | 0 | aReflector.set(aCache->GetWrapper()); |
16162 | 0 | if (aReflector) { |
16163 | | #ifdef DEBUG |
16164 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
16165 | | #endif // DEBUG |
16166 | | return true; |
16167 | 0 | } |
16168 | 0 |
|
16169 | 0 | JSAutoRealm ar(aCx, global); |
16170 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
16171 | 0 | if (!canonicalProto) { |
16172 | 0 | return false; |
16173 | 0 | } |
16174 | 0 | JS::Rooted<JSObject*> proto(aCx); |
16175 | 0 | if (aGivenProto) { |
16176 | 0 | proto = aGivenProto; |
16177 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
16178 | 0 | // coming in, we changed compartments to that of "parent" so may need |
16179 | 0 | // to wrap the proto here. |
16180 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
16181 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
16182 | 0 | return false; |
16183 | 0 | } |
16184 | 0 | } |
16185 | 0 | } else { |
16186 | 0 | proto = canonicalProto; |
16187 | 0 | } |
16188 | 0 |
|
16189 | 0 | BindingJSObjectCreator<mozilla::webgpu::Sampler> creator(aCx); |
16190 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
16191 | 0 | if (!aReflector) { |
16192 | 0 | return false; |
16193 | 0 | } |
16194 | 0 | |
16195 | 0 | aCache->SetWrapper(aReflector); |
16196 | 0 | creator.InitializationSucceeded(); |
16197 | 0 |
|
16198 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
16199 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
16200 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
16201 | 0 | // otherwise we won't be able to properly recreate it later, since |
16202 | 0 | // we won't know what proto to use. Note that we don't check |
16203 | 0 | // aGivenProto here, since it's entirely possible (and even |
16204 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
16205 | 0 | // same as canonicalProto. |
16206 | 0 | if (proto != canonicalProto) { |
16207 | 0 | PreserveWrapper(aObject); |
16208 | 0 | } |
16209 | 0 |
|
16210 | 0 | return true; |
16211 | 0 | } |
16212 | | |
16213 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
16214 | | nullptr, |
16215 | | nullptr, |
16216 | | nullptr, |
16217 | | { nullptr, nullptr }, |
16218 | | prototypes::id::WebGPUSampler, |
16219 | | constructors::id::WebGPUSampler, |
16220 | | nullptr, |
16221 | | &DefaultXrayExpandoObjectClass |
16222 | | } }; |
16223 | | |
16224 | | void |
16225 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
16226 | 0 | { |
16227 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
16228 | 0 | if (!parentProto) { |
16229 | 0 | return; |
16230 | 0 | } |
16231 | 0 | |
16232 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
16233 | 0 | if (!constructorProto) { |
16234 | 0 | return; |
16235 | 0 | } |
16236 | 0 | |
16237 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPUSampler); |
16238 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUSampler); |
16239 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
16240 | 0 | &sPrototypeClass.mBase, protoCache, |
16241 | 0 | nullptr, |
16242 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
16243 | 0 | interfaceCache, |
16244 | 0 | nullptr, |
16245 | 0 | nullptr, |
16246 | 0 | "WebGPUSampler", aDefineOnGlobal, |
16247 | 0 | nullptr, |
16248 | 0 | false); |
16249 | 0 | } |
16250 | | |
16251 | | JSObject* |
16252 | | GetConstructorObject(JSContext* aCx) |
16253 | 0 | { |
16254 | 0 | return GetConstructorObjectHandle(aCx); |
16255 | 0 | } |
16256 | | |
16257 | | } // namespace WebGPUSampler_Binding |
16258 | | |
16259 | | |
16260 | | |
16261 | | namespace WebGPUShaderModule_Binding { |
16262 | | |
16263 | | static bool |
16264 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
16265 | 0 | { |
16266 | 0 | mozilla::webgpu::ShaderModule* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::ShaderModule>(obj); |
16267 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
16268 | 0 | // obviously can't preserve if we're not initialized. |
16269 | 0 | if (self && self->GetWrapperPreserveColor()) { |
16270 | 0 | PreserveWrapper(self); |
16271 | 0 | } |
16272 | 0 | return true; |
16273 | 0 | } |
16274 | | |
16275 | | static void |
16276 | | _finalize(js::FreeOp* fop, JSObject* obj) |
16277 | 0 | { |
16278 | 0 | mozilla::webgpu::ShaderModule* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::ShaderModule>(obj); |
16279 | 0 | if (self) { |
16280 | 0 | ClearWrapper(self, self, obj); |
16281 | 0 | AddForDeferredFinalization<mozilla::webgpu::ShaderModule>(self); |
16282 | 0 | } |
16283 | 0 | } |
16284 | | |
16285 | | static size_t |
16286 | | _objectMoved(JSObject* obj, JSObject* old) |
16287 | 0 | { |
16288 | 0 | mozilla::webgpu::ShaderModule* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::ShaderModule>(obj); |
16289 | 0 | if (self) { |
16290 | 0 | UpdateWrapper(self, self, obj, old); |
16291 | 0 | } |
16292 | 0 |
|
16293 | 0 | return 0; |
16294 | 0 | } |
16295 | | |
16296 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
16297 | | { |
16298 | | "Function", |
16299 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
16300 | | &sBoringInterfaceObjectClassClassOps, |
16301 | | JS_NULL_CLASS_SPEC, |
16302 | | JS_NULL_CLASS_EXT, |
16303 | | &sInterfaceObjectClassObjectOps |
16304 | | }, |
16305 | | eInterface, |
16306 | | true, |
16307 | | prototypes::id::WebGPUShaderModule, |
16308 | | PrototypeTraits<prototypes::id::WebGPUShaderModule>::Depth, |
16309 | | sNativePropertyHooks, |
16310 | | "function WebGPUShaderModule() {\n [native code]\n}", |
16311 | | JS::GetRealmFunctionPrototype |
16312 | | }; |
16313 | | |
16314 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
16315 | | { |
16316 | | "WebGPUShaderModulePrototype", |
16317 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
16318 | | JS_NULL_CLASS_OPS, |
16319 | | JS_NULL_CLASS_SPEC, |
16320 | | JS_NULL_CLASS_EXT, |
16321 | | JS_NULL_OBJECT_OPS |
16322 | | }, |
16323 | | eInterfacePrototype, |
16324 | | false, |
16325 | | prototypes::id::WebGPUShaderModule, |
16326 | | PrototypeTraits<prototypes::id::WebGPUShaderModule>::Depth, |
16327 | | sNativePropertyHooks, |
16328 | | "[object WebGPUShaderModulePrototype]", |
16329 | | JS::GetRealmObjectPrototype |
16330 | | }; |
16331 | | |
16332 | | bool |
16333 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
16334 | 0 | { |
16335 | 0 | static bool sPrefValue; |
16336 | 0 | static bool sPrefCacheSetUp = false; |
16337 | 0 | if (!sPrefCacheSetUp) { |
16338 | 0 | sPrefCacheSetUp = true; |
16339 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
16340 | 0 | } |
16341 | 0 |
|
16342 | 0 | return sPrefValue; |
16343 | 0 | } |
16344 | | |
16345 | | static const js::ClassOps sClassOps = { |
16346 | | _addProperty, /* addProperty */ |
16347 | | nullptr, /* delProperty */ |
16348 | | nullptr, /* enumerate */ |
16349 | | nullptr, /* newEnumerate */ |
16350 | | nullptr, /* resolve */ |
16351 | | nullptr, /* mayResolve */ |
16352 | | _finalize, /* finalize */ |
16353 | | nullptr, /* call */ |
16354 | | nullptr, /* hasInstance */ |
16355 | | nullptr, /* construct */ |
16356 | | nullptr, /* trace */ |
16357 | | }; |
16358 | | |
16359 | | static const js::ClassExtension sClassExtension = { |
16360 | | nullptr, /* weakmapKeyDelegateOp */ |
16361 | | _objectMoved /* objectMovedOp */ |
16362 | | }; |
16363 | | |
16364 | | static const DOMJSClass sClass = { |
16365 | | { "WebGPUShaderModule", |
16366 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
16367 | | &sClassOps, |
16368 | | JS_NULL_CLASS_SPEC, |
16369 | | &sClassExtension, |
16370 | | JS_NULL_OBJECT_OPS |
16371 | | }, |
16372 | | { prototypes::id::WebGPUShaderModule, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
16373 | | IsBaseOf<nsISupports, mozilla::webgpu::ShaderModule >::value, |
16374 | | sNativePropertyHooks, |
16375 | | FindAssociatedGlobalForNative<mozilla::webgpu::ShaderModule>::Get, |
16376 | | GetProtoObjectHandle, |
16377 | | GetCCParticipant<mozilla::webgpu::ShaderModule>::Get() |
16378 | | }; |
16379 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
16380 | | "Must have the right minimal number of reserved slots."); |
16381 | | static_assert(1 >= 1, |
16382 | | "Must have enough reserved slots."); |
16383 | | |
16384 | | const JSClass* |
16385 | | GetJSClass() |
16386 | 0 | { |
16387 | 0 | return sClass.ToJSClass(); |
16388 | 0 | } |
16389 | | |
16390 | | bool |
16391 | | Wrap(JSContext* aCx, mozilla::webgpu::ShaderModule* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
16392 | 0 | { |
16393 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::ShaderModule>::value, |
16394 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
16395 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::ShaderModule*>(aObject) == |
16396 | 0 | reinterpret_cast<mozilla::webgpu::ShaderModule*>(aObject), |
16397 | 0 | "Multiple inheritance for mozilla::webgpu::ShaderModule is broken."); |
16398 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
16399 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
16400 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
16401 | 0 | "You should probably not be using Wrap() directly; use " |
16402 | 0 | "GetOrCreateDOMReflector instead"); |
16403 | 0 |
|
16404 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
16405 | 0 | "nsISupports must be on our primary inheritance chain"); |
16406 | 0 |
|
16407 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
16408 | 0 | if (!global) { |
16409 | 0 | return false; |
16410 | 0 | } |
16411 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
16412 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
16413 | 0 |
|
16414 | 0 | // That might have ended up wrapping us already, due to the wonders |
16415 | 0 | // of XBL. Check for that, and bail out as needed. |
16416 | 0 | aReflector.set(aCache->GetWrapper()); |
16417 | 0 | if (aReflector) { |
16418 | | #ifdef DEBUG |
16419 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
16420 | | #endif // DEBUG |
16421 | | return true; |
16422 | 0 | } |
16423 | 0 |
|
16424 | 0 | JSAutoRealm ar(aCx, global); |
16425 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
16426 | 0 | if (!canonicalProto) { |
16427 | 0 | return false; |
16428 | 0 | } |
16429 | 0 | JS::Rooted<JSObject*> proto(aCx); |
16430 | 0 | if (aGivenProto) { |
16431 | 0 | proto = aGivenProto; |
16432 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
16433 | 0 | // coming in, we changed compartments to that of "parent" so may need |
16434 | 0 | // to wrap the proto here. |
16435 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
16436 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
16437 | 0 | return false; |
16438 | 0 | } |
16439 | 0 | } |
16440 | 0 | } else { |
16441 | 0 | proto = canonicalProto; |
16442 | 0 | } |
16443 | 0 |
|
16444 | 0 | BindingJSObjectCreator<mozilla::webgpu::ShaderModule> creator(aCx); |
16445 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
16446 | 0 | if (!aReflector) { |
16447 | 0 | return false; |
16448 | 0 | } |
16449 | 0 | |
16450 | 0 | aCache->SetWrapper(aReflector); |
16451 | 0 | creator.InitializationSucceeded(); |
16452 | 0 |
|
16453 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
16454 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
16455 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
16456 | 0 | // otherwise we won't be able to properly recreate it later, since |
16457 | 0 | // we won't know what proto to use. Note that we don't check |
16458 | 0 | // aGivenProto here, since it's entirely possible (and even |
16459 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
16460 | 0 | // same as canonicalProto. |
16461 | 0 | if (proto != canonicalProto) { |
16462 | 0 | PreserveWrapper(aObject); |
16463 | 0 | } |
16464 | 0 |
|
16465 | 0 | return true; |
16466 | 0 | } |
16467 | | |
16468 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
16469 | | nullptr, |
16470 | | nullptr, |
16471 | | nullptr, |
16472 | | { nullptr, nullptr }, |
16473 | | prototypes::id::WebGPUShaderModule, |
16474 | | constructors::id::WebGPUShaderModule, |
16475 | | nullptr, |
16476 | | &DefaultXrayExpandoObjectClass |
16477 | | } }; |
16478 | | |
16479 | | void |
16480 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
16481 | 0 | { |
16482 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
16483 | 0 | if (!parentProto) { |
16484 | 0 | return; |
16485 | 0 | } |
16486 | 0 | |
16487 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
16488 | 0 | if (!constructorProto) { |
16489 | 0 | return; |
16490 | 0 | } |
16491 | 0 | |
16492 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPUShaderModule); |
16493 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUShaderModule); |
16494 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
16495 | 0 | &sPrototypeClass.mBase, protoCache, |
16496 | 0 | nullptr, |
16497 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
16498 | 0 | interfaceCache, |
16499 | 0 | nullptr, |
16500 | 0 | nullptr, |
16501 | 0 | "WebGPUShaderModule", aDefineOnGlobal, |
16502 | 0 | nullptr, |
16503 | 0 | false); |
16504 | 0 | } |
16505 | | |
16506 | | JSObject* |
16507 | | GetConstructorObject(JSContext* aCx) |
16508 | 0 | { |
16509 | 0 | return GetConstructorObjectHandle(aCx); |
16510 | 0 | } |
16511 | | |
16512 | | } // namespace WebGPUShaderModule_Binding |
16513 | | |
16514 | | |
16515 | | |
16516 | | namespace WebGPUShaderStage_Binding { |
16517 | | |
16518 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
16519 | | #if defined(__clang__) |
16520 | | #pragma clang diagnostic push |
16521 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
16522 | | #endif |
16523 | | static const ConstantSpec sConstants_specs[] = { |
16524 | | { "VERTEX", JS::NumberValue(0U) }, |
16525 | | { "FRAGMENT", JS::NumberValue(1U) }, |
16526 | | { "COMPUTE", JS::NumberValue(2U) }, |
16527 | | { 0, JS::UndefinedValue() } |
16528 | | }; |
16529 | | #if defined(__clang__) |
16530 | | #pragma clang diagnostic pop |
16531 | | #endif |
16532 | | |
16533 | | |
16534 | | static const Prefable<const ConstantSpec> sConstants[] = { |
16535 | | { nullptr, &sConstants_specs[0] }, |
16536 | | { nullptr, nullptr } |
16537 | | }; |
16538 | | |
16539 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
16540 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
16541 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
16542 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
16543 | | |
16544 | | |
16545 | | static uint16_t sNativeProperties_sortedPropertyIndices[3]; |
16546 | | static PropertyInfo sNativeProperties_propertyInfos[3]; |
16547 | | |
16548 | | static const NativePropertiesN<1> sNativeProperties = { |
16549 | | false, 0, |
16550 | | false, 0, |
16551 | | false, 0, |
16552 | | false, 0, |
16553 | | false, 0, |
16554 | | false, 0, |
16555 | | true, 0 /* sConstants */, |
16556 | | -1, |
16557 | | 3, |
16558 | | sNativeProperties_sortedPropertyIndices, |
16559 | | { |
16560 | | { sConstants, &sNativeProperties_propertyInfos[0] } |
16561 | | } |
16562 | | }; |
16563 | | static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
16564 | | "We have a property info count that is oversized"); |
16565 | | |
16566 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
16567 | | { |
16568 | | "Function", |
16569 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
16570 | | &sBoringInterfaceObjectClassClassOps, |
16571 | | JS_NULL_CLASS_SPEC, |
16572 | | JS_NULL_CLASS_EXT, |
16573 | | &sInterfaceObjectClassObjectOps |
16574 | | }, |
16575 | | eInterface, |
16576 | | false, |
16577 | | prototypes::id::_ID_Count, |
16578 | | 0, |
16579 | | sNativePropertyHooks, |
16580 | | "function WebGPUShaderStage() {\n [native code]\n}", |
16581 | | JS::GetRealmFunctionPrototype |
16582 | | }; |
16583 | | |
16584 | | bool |
16585 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
16586 | 0 | { |
16587 | 0 | static bool sPrefValue; |
16588 | 0 | static bool sPrefCacheSetUp = false; |
16589 | 0 | if (!sPrefCacheSetUp) { |
16590 | 0 | sPrefCacheSetUp = true; |
16591 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
16592 | 0 | } |
16593 | 0 |
|
16594 | 0 | return sPrefValue; |
16595 | 0 | } |
16596 | | |
16597 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
16598 | | nullptr, |
16599 | | nullptr, |
16600 | | nullptr, |
16601 | | { sNativeProperties.Upcast(), nullptr }, |
16602 | | prototypes::id::_ID_Count, |
16603 | | constructors::id::WebGPUShaderStage, |
16604 | | nullptr, |
16605 | | &DefaultXrayExpandoObjectClass |
16606 | | } }; |
16607 | | |
16608 | | void |
16609 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
16610 | 0 | { |
16611 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
16612 | 0 | if (!constructorProto) { |
16613 | 0 | return; |
16614 | 0 | } |
16615 | 0 | |
16616 | 0 | static bool sIdsInited = false; |
16617 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
16618 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
16619 | 0 | return; |
16620 | 0 | } |
16621 | 0 | sIdsInited = true; |
16622 | 0 | } |
16623 | 0 |
|
16624 | 0 | JS::Heap<JSObject*>* protoCache = nullptr; |
16625 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUShaderStage); |
16626 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, nullptr, |
16627 | 0 | nullptr, protoCache, |
16628 | 0 | nullptr, |
16629 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
16630 | 0 | interfaceCache, |
16631 | 0 | sNativeProperties.Upcast(), |
16632 | 0 | nullptr, |
16633 | 0 | "WebGPUShaderStage", aDefineOnGlobal, |
16634 | 0 | nullptr, |
16635 | 0 | false); |
16636 | 0 | } |
16637 | | |
16638 | | JSObject* |
16639 | | GetConstructorObject(JSContext* aCx) |
16640 | 0 | { |
16641 | 0 | return GetConstructorObjectHandle(aCx); |
16642 | 0 | } |
16643 | | |
16644 | | } // namespace WebGPUShaderStage_Binding |
16645 | | |
16646 | | |
16647 | | |
16648 | | namespace WebGPUShaderStageBit_Binding { |
16649 | | |
16650 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
16651 | | #if defined(__clang__) |
16652 | | #pragma clang diagnostic push |
16653 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
16654 | | #endif |
16655 | | static const ConstantSpec sConstants_specs[] = { |
16656 | | { "NONE", JS::NumberValue(0U) }, |
16657 | | { "VERTEX", JS::NumberValue(1U) }, |
16658 | | { "FRAGMENT", JS::NumberValue(2U) }, |
16659 | | { "COMPUTE", JS::NumberValue(4U) }, |
16660 | | { 0, JS::UndefinedValue() } |
16661 | | }; |
16662 | | #if defined(__clang__) |
16663 | | #pragma clang diagnostic pop |
16664 | | #endif |
16665 | | |
16666 | | |
16667 | | static const Prefable<const ConstantSpec> sConstants[] = { |
16668 | | { nullptr, &sConstants_specs[0] }, |
16669 | | { nullptr, nullptr } |
16670 | | }; |
16671 | | |
16672 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
16673 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
16674 | | static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
16675 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
16676 | | |
16677 | | |
16678 | | static uint16_t sNativeProperties_sortedPropertyIndices[4]; |
16679 | | static PropertyInfo sNativeProperties_propertyInfos[4]; |
16680 | | |
16681 | | static const NativePropertiesN<1> sNativeProperties = { |
16682 | | false, 0, |
16683 | | false, 0, |
16684 | | false, 0, |
16685 | | false, 0, |
16686 | | false, 0, |
16687 | | false, 0, |
16688 | | true, 0 /* sConstants */, |
16689 | | -1, |
16690 | | 4, |
16691 | | sNativeProperties_sortedPropertyIndices, |
16692 | | { |
16693 | | { sConstants, &sNativeProperties_propertyInfos[0] } |
16694 | | } |
16695 | | }; |
16696 | | static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
16697 | | "We have a property info count that is oversized"); |
16698 | | |
16699 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
16700 | | { |
16701 | | "Function", |
16702 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
16703 | | &sBoringInterfaceObjectClassClassOps, |
16704 | | JS_NULL_CLASS_SPEC, |
16705 | | JS_NULL_CLASS_EXT, |
16706 | | &sInterfaceObjectClassObjectOps |
16707 | | }, |
16708 | | eInterface, |
16709 | | false, |
16710 | | prototypes::id::_ID_Count, |
16711 | | 0, |
16712 | | sNativePropertyHooks, |
16713 | | "function WebGPUShaderStageBit() {\n [native code]\n}", |
16714 | | JS::GetRealmFunctionPrototype |
16715 | | }; |
16716 | | |
16717 | | bool |
16718 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
16719 | 0 | { |
16720 | 0 | static bool sPrefValue; |
16721 | 0 | static bool sPrefCacheSetUp = false; |
16722 | 0 | if (!sPrefCacheSetUp) { |
16723 | 0 | sPrefCacheSetUp = true; |
16724 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
16725 | 0 | } |
16726 | 0 |
|
16727 | 0 | return sPrefValue; |
16728 | 0 | } |
16729 | | |
16730 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
16731 | | nullptr, |
16732 | | nullptr, |
16733 | | nullptr, |
16734 | | { sNativeProperties.Upcast(), nullptr }, |
16735 | | prototypes::id::_ID_Count, |
16736 | | constructors::id::WebGPUShaderStageBit, |
16737 | | nullptr, |
16738 | | &DefaultXrayExpandoObjectClass |
16739 | | } }; |
16740 | | |
16741 | | void |
16742 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
16743 | 0 | { |
16744 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
16745 | 0 | if (!constructorProto) { |
16746 | 0 | return; |
16747 | 0 | } |
16748 | 0 | |
16749 | 0 | static bool sIdsInited = false; |
16750 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
16751 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
16752 | 0 | return; |
16753 | 0 | } |
16754 | 0 | sIdsInited = true; |
16755 | 0 | } |
16756 | 0 |
|
16757 | 0 | JS::Heap<JSObject*>* protoCache = nullptr; |
16758 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUShaderStageBit); |
16759 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, nullptr, |
16760 | 0 | nullptr, protoCache, |
16761 | 0 | nullptr, |
16762 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
16763 | 0 | interfaceCache, |
16764 | 0 | sNativeProperties.Upcast(), |
16765 | 0 | nullptr, |
16766 | 0 | "WebGPUShaderStageBit", aDefineOnGlobal, |
16767 | 0 | nullptr, |
16768 | 0 | false); |
16769 | 0 | } |
16770 | | |
16771 | | JSObject* |
16772 | | GetConstructorObject(JSContext* aCx) |
16773 | 0 | { |
16774 | 0 | return GetConstructorObjectHandle(aCx); |
16775 | 0 | } |
16776 | | |
16777 | | } // namespace WebGPUShaderStageBit_Binding |
16778 | | |
16779 | | |
16780 | | |
16781 | | namespace WebGPUStencilOperation_Binding { |
16782 | | |
16783 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
16784 | | #if defined(__clang__) |
16785 | | #pragma clang diagnostic push |
16786 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
16787 | | #endif |
16788 | | static const ConstantSpec sConstants_specs[] = { |
16789 | | { "KEEP", JS::NumberValue(0U) }, |
16790 | | { "ZERO", JS::NumberValue(1U) }, |
16791 | | { "REPLACE", JS::NumberValue(2U) }, |
16792 | | { "INVERT", JS::NumberValue(3U) }, |
16793 | | { "INCREMENT_CLAMP", JS::NumberValue(4U) }, |
16794 | | { "DECREMENT_CLAMP", JS::NumberValue(5U) }, |
16795 | | { "INCREMENT_WRAP", JS::NumberValue(6U) }, |
16796 | | { "DECREMENT_WRAP", JS::NumberValue(7U) }, |
16797 | | { 0, JS::UndefinedValue() } |
16798 | | }; |
16799 | | #if defined(__clang__) |
16800 | | #pragma clang diagnostic pop |
16801 | | #endif |
16802 | | |
16803 | | |
16804 | | static const Prefable<const ConstantSpec> sConstants[] = { |
16805 | | { nullptr, &sConstants_specs[0] }, |
16806 | | { nullptr, nullptr } |
16807 | | }; |
16808 | | |
16809 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
16810 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
16811 | | static_assert(8 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
16812 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
16813 | | |
16814 | | |
16815 | | static uint16_t sNativeProperties_sortedPropertyIndices[8]; |
16816 | | static PropertyInfo sNativeProperties_propertyInfos[8]; |
16817 | | |
16818 | | static const NativePropertiesN<1> sNativeProperties = { |
16819 | | false, 0, |
16820 | | false, 0, |
16821 | | false, 0, |
16822 | | false, 0, |
16823 | | false, 0, |
16824 | | false, 0, |
16825 | | true, 0 /* sConstants */, |
16826 | | -1, |
16827 | | 8, |
16828 | | sNativeProperties_sortedPropertyIndices, |
16829 | | { |
16830 | | { sConstants, &sNativeProperties_propertyInfos[0] } |
16831 | | } |
16832 | | }; |
16833 | | static_assert(8 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
16834 | | "We have a property info count that is oversized"); |
16835 | | |
16836 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
16837 | | { |
16838 | | "Function", |
16839 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
16840 | | &sBoringInterfaceObjectClassClassOps, |
16841 | | JS_NULL_CLASS_SPEC, |
16842 | | JS_NULL_CLASS_EXT, |
16843 | | &sInterfaceObjectClassObjectOps |
16844 | | }, |
16845 | | eInterface, |
16846 | | false, |
16847 | | prototypes::id::_ID_Count, |
16848 | | 0, |
16849 | | sNativePropertyHooks, |
16850 | | "function WebGPUStencilOperation() {\n [native code]\n}", |
16851 | | JS::GetRealmFunctionPrototype |
16852 | | }; |
16853 | | |
16854 | | bool |
16855 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
16856 | 0 | { |
16857 | 0 | static bool sPrefValue; |
16858 | 0 | static bool sPrefCacheSetUp = false; |
16859 | 0 | if (!sPrefCacheSetUp) { |
16860 | 0 | sPrefCacheSetUp = true; |
16861 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
16862 | 0 | } |
16863 | 0 |
|
16864 | 0 | return sPrefValue; |
16865 | 0 | } |
16866 | | |
16867 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
16868 | | nullptr, |
16869 | | nullptr, |
16870 | | nullptr, |
16871 | | { sNativeProperties.Upcast(), nullptr }, |
16872 | | prototypes::id::_ID_Count, |
16873 | | constructors::id::WebGPUStencilOperation, |
16874 | | nullptr, |
16875 | | &DefaultXrayExpandoObjectClass |
16876 | | } }; |
16877 | | |
16878 | | void |
16879 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
16880 | 0 | { |
16881 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
16882 | 0 | if (!constructorProto) { |
16883 | 0 | return; |
16884 | 0 | } |
16885 | 0 | |
16886 | 0 | static bool sIdsInited = false; |
16887 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
16888 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
16889 | 0 | return; |
16890 | 0 | } |
16891 | 0 | sIdsInited = true; |
16892 | 0 | } |
16893 | 0 |
|
16894 | 0 | JS::Heap<JSObject*>* protoCache = nullptr; |
16895 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUStencilOperation); |
16896 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, nullptr, |
16897 | 0 | nullptr, protoCache, |
16898 | 0 | nullptr, |
16899 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
16900 | 0 | interfaceCache, |
16901 | 0 | sNativeProperties.Upcast(), |
16902 | 0 | nullptr, |
16903 | 0 | "WebGPUStencilOperation", aDefineOnGlobal, |
16904 | 0 | nullptr, |
16905 | 0 | false); |
16906 | 0 | } |
16907 | | |
16908 | | JSObject* |
16909 | | GetConstructorObject(JSContext* aCx) |
16910 | 0 | { |
16911 | 0 | return GetConstructorObjectHandle(aCx); |
16912 | 0 | } |
16913 | | |
16914 | | } // namespace WebGPUStencilOperation_Binding |
16915 | | |
16916 | | |
16917 | | |
16918 | | namespace WebGPUStoreOp_Binding { |
16919 | | |
16920 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
16921 | | #if defined(__clang__) |
16922 | | #pragma clang diagnostic push |
16923 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
16924 | | #endif |
16925 | | static const ConstantSpec sConstants_specs[] = { |
16926 | | { "STORE", JS::NumberValue(0U) }, |
16927 | | { 0, JS::UndefinedValue() } |
16928 | | }; |
16929 | | #if defined(__clang__) |
16930 | | #pragma clang diagnostic pop |
16931 | | #endif |
16932 | | |
16933 | | |
16934 | | static const Prefable<const ConstantSpec> sConstants[] = { |
16935 | | { nullptr, &sConstants_specs[0] }, |
16936 | | { nullptr, nullptr } |
16937 | | }; |
16938 | | |
16939 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
16940 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
16941 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
16942 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
16943 | | |
16944 | | |
16945 | | static uint16_t sNativeProperties_sortedPropertyIndices[1]; |
16946 | | static PropertyInfo sNativeProperties_propertyInfos[1]; |
16947 | | |
16948 | | static const NativePropertiesN<1> sNativeProperties = { |
16949 | | false, 0, |
16950 | | false, 0, |
16951 | | false, 0, |
16952 | | false, 0, |
16953 | | false, 0, |
16954 | | false, 0, |
16955 | | true, 0 /* sConstants */, |
16956 | | -1, |
16957 | | 1, |
16958 | | sNativeProperties_sortedPropertyIndices, |
16959 | | { |
16960 | | { sConstants, &sNativeProperties_propertyInfos[0] } |
16961 | | } |
16962 | | }; |
16963 | | static_assert(1 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
16964 | | "We have a property info count that is oversized"); |
16965 | | |
16966 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
16967 | | { |
16968 | | "Function", |
16969 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
16970 | | &sBoringInterfaceObjectClassClassOps, |
16971 | | JS_NULL_CLASS_SPEC, |
16972 | | JS_NULL_CLASS_EXT, |
16973 | | &sInterfaceObjectClassObjectOps |
16974 | | }, |
16975 | | eInterface, |
16976 | | false, |
16977 | | prototypes::id::_ID_Count, |
16978 | | 0, |
16979 | | sNativePropertyHooks, |
16980 | | "function WebGPUStoreOp() {\n [native code]\n}", |
16981 | | JS::GetRealmFunctionPrototype |
16982 | | }; |
16983 | | |
16984 | | bool |
16985 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
16986 | 0 | { |
16987 | 0 | static bool sPrefValue; |
16988 | 0 | static bool sPrefCacheSetUp = false; |
16989 | 0 | if (!sPrefCacheSetUp) { |
16990 | 0 | sPrefCacheSetUp = true; |
16991 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
16992 | 0 | } |
16993 | 0 |
|
16994 | 0 | return sPrefValue; |
16995 | 0 | } |
16996 | | |
16997 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
16998 | | nullptr, |
16999 | | nullptr, |
17000 | | nullptr, |
17001 | | { sNativeProperties.Upcast(), nullptr }, |
17002 | | prototypes::id::_ID_Count, |
17003 | | constructors::id::WebGPUStoreOp, |
17004 | | nullptr, |
17005 | | &DefaultXrayExpandoObjectClass |
17006 | | } }; |
17007 | | |
17008 | | void |
17009 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
17010 | 0 | { |
17011 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
17012 | 0 | if (!constructorProto) { |
17013 | 0 | return; |
17014 | 0 | } |
17015 | 0 | |
17016 | 0 | static bool sIdsInited = false; |
17017 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
17018 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
17019 | 0 | return; |
17020 | 0 | } |
17021 | 0 | sIdsInited = true; |
17022 | 0 | } |
17023 | 0 |
|
17024 | 0 | JS::Heap<JSObject*>* protoCache = nullptr; |
17025 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUStoreOp); |
17026 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, nullptr, |
17027 | 0 | nullptr, protoCache, |
17028 | 0 | nullptr, |
17029 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
17030 | 0 | interfaceCache, |
17031 | 0 | sNativeProperties.Upcast(), |
17032 | 0 | nullptr, |
17033 | 0 | "WebGPUStoreOp", aDefineOnGlobal, |
17034 | 0 | nullptr, |
17035 | 0 | false); |
17036 | 0 | } |
17037 | | |
17038 | | JSObject* |
17039 | | GetConstructorObject(JSContext* aCx) |
17040 | 0 | { |
17041 | 0 | return GetConstructorObjectHandle(aCx); |
17042 | 0 | } |
17043 | | |
17044 | | } // namespace WebGPUStoreOp_Binding |
17045 | | |
17046 | | |
17047 | | |
17048 | | namespace WebGPUSwapChain_Binding { |
17049 | | |
17050 | | MOZ_CAN_RUN_SCRIPT static bool |
17051 | | configure(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::SwapChain* self, const JSJitMethodCallArgs& args) |
17052 | 0 | { |
17053 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUSwapChain.configure", DOM, cx); |
17054 | 0 |
|
17055 | 0 | binding_detail::FastWebGPUSwapChainDescriptor arg0; |
17056 | 0 | if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of WebGPUSwapChain.configure", false)) { |
17057 | 0 | return false; |
17058 | 0 | } |
17059 | 0 | self->Configure(Constify(arg0)); |
17060 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
17061 | 0 | args.rval().setUndefined(); |
17062 | 0 | return true; |
17063 | 0 | } |
17064 | | |
17065 | | static const JSJitInfo configure_methodinfo = { |
17066 | | { (JSJitGetterOp)configure }, |
17067 | | { prototypes::id::WebGPUSwapChain }, |
17068 | | { PrototypeTraits<prototypes::id::WebGPUSwapChain>::Depth }, |
17069 | | JSJitInfo::Method, |
17070 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
17071 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
17072 | | false, /* isInfallible. False in setters. */ |
17073 | | false, /* isMovable. Not relevant for setters. */ |
17074 | | false, /* isEliminatable. Not relevant for setters. */ |
17075 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
17076 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
17077 | | false, /* isTypedMethod. Only relevant for methods. */ |
17078 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
17079 | | }; |
17080 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
17081 | | static_assert(0 < 1, "There is no slot for us"); |
17082 | | |
17083 | | MOZ_CAN_RUN_SCRIPT static bool |
17084 | | getNextTexture(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::SwapChain* self, const JSJitMethodCallArgs& args) |
17085 | 0 | { |
17086 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUSwapChain.getNextTexture", DOM, cx); |
17087 | 0 |
|
17088 | 0 | auto result(StrongOrRawPtr<mozilla::webgpu::Texture>(self->GetNextTexture())); |
17089 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
17090 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
17091 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
17092 | 0 | return false; |
17093 | 0 | } |
17094 | 0 | return true; |
17095 | 0 | } |
17096 | | |
17097 | | static const JSJitInfo getNextTexture_methodinfo = { |
17098 | | { (JSJitGetterOp)getNextTexture }, |
17099 | | { prototypes::id::WebGPUSwapChain }, |
17100 | | { PrototypeTraits<prototypes::id::WebGPUSwapChain>::Depth }, |
17101 | | JSJitInfo::Method, |
17102 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
17103 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
17104 | | false, /* isInfallible. False in setters. */ |
17105 | | false, /* isMovable. Not relevant for setters. */ |
17106 | | false, /* isEliminatable. Not relevant for setters. */ |
17107 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
17108 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
17109 | | false, /* isTypedMethod. Only relevant for methods. */ |
17110 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
17111 | | }; |
17112 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
17113 | | static_assert(0 < 1, "There is no slot for us"); |
17114 | | |
17115 | | MOZ_CAN_RUN_SCRIPT static bool |
17116 | | present(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::SwapChain* self, const JSJitMethodCallArgs& args) |
17117 | 0 | { |
17118 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUSwapChain.present", DOM, cx); |
17119 | 0 |
|
17120 | 0 | self->Present(); |
17121 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
17122 | 0 | args.rval().setUndefined(); |
17123 | 0 | return true; |
17124 | 0 | } |
17125 | | |
17126 | | static const JSJitInfo present_methodinfo = { |
17127 | | { (JSJitGetterOp)present }, |
17128 | | { prototypes::id::WebGPUSwapChain }, |
17129 | | { PrototypeTraits<prototypes::id::WebGPUSwapChain>::Depth }, |
17130 | | JSJitInfo::Method, |
17131 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
17132 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
17133 | | true, /* isInfallible. False in setters. */ |
17134 | | false, /* isMovable. Not relevant for setters. */ |
17135 | | false, /* isEliminatable. Not relevant for setters. */ |
17136 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
17137 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
17138 | | false, /* isTypedMethod. Only relevant for methods. */ |
17139 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
17140 | | }; |
17141 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
17142 | | static_assert(0 < 1, "There is no slot for us"); |
17143 | | |
17144 | | static bool |
17145 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
17146 | 0 | { |
17147 | 0 | mozilla::webgpu::SwapChain* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::SwapChain>(obj); |
17148 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
17149 | 0 | // obviously can't preserve if we're not initialized. |
17150 | 0 | if (self && self->GetWrapperPreserveColor()) { |
17151 | 0 | PreserveWrapper(self); |
17152 | 0 | } |
17153 | 0 | return true; |
17154 | 0 | } |
17155 | | |
17156 | | static void |
17157 | | _finalize(js::FreeOp* fop, JSObject* obj) |
17158 | 0 | { |
17159 | 0 | mozilla::webgpu::SwapChain* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::SwapChain>(obj); |
17160 | 0 | if (self) { |
17161 | 0 | ClearWrapper(self, self, obj); |
17162 | 0 | AddForDeferredFinalization<mozilla::webgpu::SwapChain>(self); |
17163 | 0 | } |
17164 | 0 | } |
17165 | | |
17166 | | static size_t |
17167 | | _objectMoved(JSObject* obj, JSObject* old) |
17168 | 0 | { |
17169 | 0 | mozilla::webgpu::SwapChain* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::SwapChain>(obj); |
17170 | 0 | if (self) { |
17171 | 0 | UpdateWrapper(self, self, obj, old); |
17172 | 0 | } |
17173 | 0 |
|
17174 | 0 | return 0; |
17175 | 0 | } |
17176 | | |
17177 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
17178 | | #if defined(__clang__) |
17179 | | #pragma clang diagnostic push |
17180 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
17181 | | #endif |
17182 | | static const JSFunctionSpec sMethods_specs[] = { |
17183 | | JS_FNSPEC("configure", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&configure_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
17184 | | JS_FNSPEC("getNextTexture", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getNextTexture_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
17185 | | JS_FNSPEC("present", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&present_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
17186 | | JS_FS_END |
17187 | | }; |
17188 | | #if defined(__clang__) |
17189 | | #pragma clang diagnostic pop |
17190 | | #endif |
17191 | | |
17192 | | |
17193 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
17194 | | { nullptr, &sMethods_specs[0] }, |
17195 | | { nullptr, nullptr } |
17196 | | }; |
17197 | | |
17198 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
17199 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
17200 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
17201 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
17202 | | |
17203 | | |
17204 | | static uint16_t sNativeProperties_sortedPropertyIndices[3]; |
17205 | | static PropertyInfo sNativeProperties_propertyInfos[3]; |
17206 | | |
17207 | | static const NativePropertiesN<1> sNativeProperties = { |
17208 | | false, 0, |
17209 | | false, 0, |
17210 | | true, 0 /* sMethods */, |
17211 | | false, 0, |
17212 | | false, 0, |
17213 | | false, 0, |
17214 | | false, 0, |
17215 | | -1, |
17216 | | 3, |
17217 | | sNativeProperties_sortedPropertyIndices, |
17218 | | { |
17219 | | { sMethods, &sNativeProperties_propertyInfos[0] } |
17220 | | } |
17221 | | }; |
17222 | | static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
17223 | | "We have a property info count that is oversized"); |
17224 | | |
17225 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
17226 | | { |
17227 | | "Function", |
17228 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
17229 | | &sBoringInterfaceObjectClassClassOps, |
17230 | | JS_NULL_CLASS_SPEC, |
17231 | | JS_NULL_CLASS_EXT, |
17232 | | &sInterfaceObjectClassObjectOps |
17233 | | }, |
17234 | | eInterface, |
17235 | | true, |
17236 | | prototypes::id::WebGPUSwapChain, |
17237 | | PrototypeTraits<prototypes::id::WebGPUSwapChain>::Depth, |
17238 | | sNativePropertyHooks, |
17239 | | "function WebGPUSwapChain() {\n [native code]\n}", |
17240 | | JS::GetRealmFunctionPrototype |
17241 | | }; |
17242 | | |
17243 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
17244 | | { |
17245 | | "WebGPUSwapChainPrototype", |
17246 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
17247 | | JS_NULL_CLASS_OPS, |
17248 | | JS_NULL_CLASS_SPEC, |
17249 | | JS_NULL_CLASS_EXT, |
17250 | | JS_NULL_OBJECT_OPS |
17251 | | }, |
17252 | | eInterfacePrototype, |
17253 | | false, |
17254 | | prototypes::id::WebGPUSwapChain, |
17255 | | PrototypeTraits<prototypes::id::WebGPUSwapChain>::Depth, |
17256 | | sNativePropertyHooks, |
17257 | | "[object WebGPUSwapChainPrototype]", |
17258 | | JS::GetRealmObjectPrototype |
17259 | | }; |
17260 | | |
17261 | | bool |
17262 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
17263 | 0 | { |
17264 | 0 | static bool sPrefValue; |
17265 | 0 | static bool sPrefCacheSetUp = false; |
17266 | 0 | if (!sPrefCacheSetUp) { |
17267 | 0 | sPrefCacheSetUp = true; |
17268 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
17269 | 0 | } |
17270 | 0 |
|
17271 | 0 | return sPrefValue; |
17272 | 0 | } |
17273 | | |
17274 | | static const js::ClassOps sClassOps = { |
17275 | | _addProperty, /* addProperty */ |
17276 | | nullptr, /* delProperty */ |
17277 | | nullptr, /* enumerate */ |
17278 | | nullptr, /* newEnumerate */ |
17279 | | nullptr, /* resolve */ |
17280 | | nullptr, /* mayResolve */ |
17281 | | _finalize, /* finalize */ |
17282 | | nullptr, /* call */ |
17283 | | nullptr, /* hasInstance */ |
17284 | | nullptr, /* construct */ |
17285 | | nullptr, /* trace */ |
17286 | | }; |
17287 | | |
17288 | | static const js::ClassExtension sClassExtension = { |
17289 | | nullptr, /* weakmapKeyDelegateOp */ |
17290 | | _objectMoved /* objectMovedOp */ |
17291 | | }; |
17292 | | |
17293 | | static const DOMJSClass sClass = { |
17294 | | { "WebGPUSwapChain", |
17295 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
17296 | | &sClassOps, |
17297 | | JS_NULL_CLASS_SPEC, |
17298 | | &sClassExtension, |
17299 | | JS_NULL_OBJECT_OPS |
17300 | | }, |
17301 | | { prototypes::id::WebGPUSwapChain, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
17302 | | IsBaseOf<nsISupports, mozilla::webgpu::SwapChain >::value, |
17303 | | sNativePropertyHooks, |
17304 | | FindAssociatedGlobalForNative<mozilla::webgpu::SwapChain>::Get, |
17305 | | GetProtoObjectHandle, |
17306 | | GetCCParticipant<mozilla::webgpu::SwapChain>::Get() |
17307 | | }; |
17308 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
17309 | | "Must have the right minimal number of reserved slots."); |
17310 | | static_assert(1 >= 1, |
17311 | | "Must have enough reserved slots."); |
17312 | | |
17313 | | const JSClass* |
17314 | | GetJSClass() |
17315 | 0 | { |
17316 | 0 | return sClass.ToJSClass(); |
17317 | 0 | } |
17318 | | |
17319 | | bool |
17320 | | Wrap(JSContext* aCx, mozilla::webgpu::SwapChain* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
17321 | 0 | { |
17322 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::SwapChain>::value, |
17323 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
17324 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::SwapChain*>(aObject) == |
17325 | 0 | reinterpret_cast<mozilla::webgpu::SwapChain*>(aObject), |
17326 | 0 | "Multiple inheritance for mozilla::webgpu::SwapChain is broken."); |
17327 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
17328 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
17329 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
17330 | 0 | "You should probably not be using Wrap() directly; use " |
17331 | 0 | "GetOrCreateDOMReflector instead"); |
17332 | 0 |
|
17333 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
17334 | 0 | "nsISupports must be on our primary inheritance chain"); |
17335 | 0 |
|
17336 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
17337 | 0 | if (!global) { |
17338 | 0 | return false; |
17339 | 0 | } |
17340 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
17341 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
17342 | 0 |
|
17343 | 0 | // That might have ended up wrapping us already, due to the wonders |
17344 | 0 | // of XBL. Check for that, and bail out as needed. |
17345 | 0 | aReflector.set(aCache->GetWrapper()); |
17346 | 0 | if (aReflector) { |
17347 | | #ifdef DEBUG |
17348 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
17349 | | #endif // DEBUG |
17350 | | return true; |
17351 | 0 | } |
17352 | 0 |
|
17353 | 0 | JSAutoRealm ar(aCx, global); |
17354 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
17355 | 0 | if (!canonicalProto) { |
17356 | 0 | return false; |
17357 | 0 | } |
17358 | 0 | JS::Rooted<JSObject*> proto(aCx); |
17359 | 0 | if (aGivenProto) { |
17360 | 0 | proto = aGivenProto; |
17361 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
17362 | 0 | // coming in, we changed compartments to that of "parent" so may need |
17363 | 0 | // to wrap the proto here. |
17364 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
17365 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
17366 | 0 | return false; |
17367 | 0 | } |
17368 | 0 | } |
17369 | 0 | } else { |
17370 | 0 | proto = canonicalProto; |
17371 | 0 | } |
17372 | 0 |
|
17373 | 0 | BindingJSObjectCreator<mozilla::webgpu::SwapChain> creator(aCx); |
17374 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
17375 | 0 | if (!aReflector) { |
17376 | 0 | return false; |
17377 | 0 | } |
17378 | 0 | |
17379 | 0 | aCache->SetWrapper(aReflector); |
17380 | 0 | creator.InitializationSucceeded(); |
17381 | 0 |
|
17382 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
17383 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
17384 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
17385 | 0 | // otherwise we won't be able to properly recreate it later, since |
17386 | 0 | // we won't know what proto to use. Note that we don't check |
17387 | 0 | // aGivenProto here, since it's entirely possible (and even |
17388 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
17389 | 0 | // same as canonicalProto. |
17390 | 0 | if (proto != canonicalProto) { |
17391 | 0 | PreserveWrapper(aObject); |
17392 | 0 | } |
17393 | 0 |
|
17394 | 0 | return true; |
17395 | 0 | } |
17396 | | |
17397 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
17398 | | nullptr, |
17399 | | nullptr, |
17400 | | nullptr, |
17401 | | { sNativeProperties.Upcast(), nullptr }, |
17402 | | prototypes::id::WebGPUSwapChain, |
17403 | | constructors::id::WebGPUSwapChain, |
17404 | | nullptr, |
17405 | | &DefaultXrayExpandoObjectClass |
17406 | | } }; |
17407 | | |
17408 | | void |
17409 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
17410 | 0 | { |
17411 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
17412 | 0 | if (!parentProto) { |
17413 | 0 | return; |
17414 | 0 | } |
17415 | 0 | |
17416 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
17417 | 0 | if (!constructorProto) { |
17418 | 0 | return; |
17419 | 0 | } |
17420 | 0 | |
17421 | 0 | static bool sIdsInited = false; |
17422 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
17423 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
17424 | 0 | return; |
17425 | 0 | } |
17426 | 0 | sIdsInited = true; |
17427 | 0 | } |
17428 | 0 |
|
17429 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPUSwapChain); |
17430 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUSwapChain); |
17431 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
17432 | 0 | &sPrototypeClass.mBase, protoCache, |
17433 | 0 | nullptr, |
17434 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
17435 | 0 | interfaceCache, |
17436 | 0 | sNativeProperties.Upcast(), |
17437 | 0 | nullptr, |
17438 | 0 | "WebGPUSwapChain", aDefineOnGlobal, |
17439 | 0 | nullptr, |
17440 | 0 | false); |
17441 | 0 | } |
17442 | | |
17443 | | JSObject* |
17444 | | GetConstructorObject(JSContext* aCx) |
17445 | 0 | { |
17446 | 0 | return GetConstructorObjectHandle(aCx); |
17447 | 0 | } |
17448 | | |
17449 | | } // namespace WebGPUSwapChain_Binding |
17450 | | |
17451 | | |
17452 | | |
17453 | | namespace WebGPUTexture_Binding { |
17454 | | |
17455 | | MOZ_CAN_RUN_SCRIPT static bool |
17456 | | createTextureView(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::webgpu::Texture* self, const JSJitMethodCallArgs& args) |
17457 | 0 | { |
17458 | 0 | AUTO_PROFILER_LABEL_FAST("WebGPUTexture.createTextureView", DOM, cx); |
17459 | 0 |
|
17460 | 0 | binding_detail::FastWebGPUTextureViewDescriptor arg0; |
17461 | 0 | if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of WebGPUTexture.createTextureView", false)) { |
17462 | 0 | return false; |
17463 | 0 | } |
17464 | 0 | auto result(StrongOrRawPtr<mozilla::webgpu::TextureView>(self->CreateTextureView(Constify(arg0)))); |
17465 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
17466 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
17467 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
17468 | 0 | return false; |
17469 | 0 | } |
17470 | 0 | return true; |
17471 | 0 | } |
17472 | | |
17473 | | static const JSJitInfo createTextureView_methodinfo = { |
17474 | | { (JSJitGetterOp)createTextureView }, |
17475 | | { prototypes::id::WebGPUTexture }, |
17476 | | { PrototypeTraits<prototypes::id::WebGPUTexture>::Depth }, |
17477 | | JSJitInfo::Method, |
17478 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
17479 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
17480 | | false, /* isInfallible. False in setters. */ |
17481 | | false, /* isMovable. Not relevant for setters. */ |
17482 | | false, /* isEliminatable. Not relevant for setters. */ |
17483 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
17484 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
17485 | | false, /* isTypedMethod. Only relevant for methods. */ |
17486 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
17487 | | }; |
17488 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
17489 | | static_assert(0 < 1, "There is no slot for us"); |
17490 | | |
17491 | | static bool |
17492 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
17493 | 0 | { |
17494 | 0 | mozilla::webgpu::Texture* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Texture>(obj); |
17495 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
17496 | 0 | // obviously can't preserve if we're not initialized. |
17497 | 0 | if (self && self->GetWrapperPreserveColor()) { |
17498 | 0 | PreserveWrapper(self); |
17499 | 0 | } |
17500 | 0 | return true; |
17501 | 0 | } |
17502 | | |
17503 | | static void |
17504 | | _finalize(js::FreeOp* fop, JSObject* obj) |
17505 | 0 | { |
17506 | 0 | mozilla::webgpu::Texture* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Texture>(obj); |
17507 | 0 | if (self) { |
17508 | 0 | ClearWrapper(self, self, obj); |
17509 | 0 | AddForDeferredFinalization<mozilla::webgpu::Texture>(self); |
17510 | 0 | } |
17511 | 0 | } |
17512 | | |
17513 | | static size_t |
17514 | | _objectMoved(JSObject* obj, JSObject* old) |
17515 | 0 | { |
17516 | 0 | mozilla::webgpu::Texture* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::Texture>(obj); |
17517 | 0 | if (self) { |
17518 | 0 | UpdateWrapper(self, self, obj, old); |
17519 | 0 | } |
17520 | 0 |
|
17521 | 0 | return 0; |
17522 | 0 | } |
17523 | | |
17524 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
17525 | | #if defined(__clang__) |
17526 | | #pragma clang diagnostic push |
17527 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
17528 | | #endif |
17529 | | static const JSFunctionSpec sMethods_specs[] = { |
17530 | | JS_FNSPEC("createTextureView", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createTextureView_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
17531 | | JS_FS_END |
17532 | | }; |
17533 | | #if defined(__clang__) |
17534 | | #pragma clang diagnostic pop |
17535 | | #endif |
17536 | | |
17537 | | |
17538 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
17539 | | { nullptr, &sMethods_specs[0] }, |
17540 | | { nullptr, nullptr } |
17541 | | }; |
17542 | | |
17543 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
17544 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
17545 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
17546 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
17547 | | |
17548 | | |
17549 | | static uint16_t sNativeProperties_sortedPropertyIndices[1]; |
17550 | | static PropertyInfo sNativeProperties_propertyInfos[1]; |
17551 | | |
17552 | | static const NativePropertiesN<1> sNativeProperties = { |
17553 | | false, 0, |
17554 | | false, 0, |
17555 | | true, 0 /* sMethods */, |
17556 | | false, 0, |
17557 | | false, 0, |
17558 | | false, 0, |
17559 | | false, 0, |
17560 | | -1, |
17561 | | 1, |
17562 | | sNativeProperties_sortedPropertyIndices, |
17563 | | { |
17564 | | { sMethods, &sNativeProperties_propertyInfos[0] } |
17565 | | } |
17566 | | }; |
17567 | | static_assert(1 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
17568 | | "We have a property info count that is oversized"); |
17569 | | |
17570 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
17571 | | { |
17572 | | "Function", |
17573 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
17574 | | &sBoringInterfaceObjectClassClassOps, |
17575 | | JS_NULL_CLASS_SPEC, |
17576 | | JS_NULL_CLASS_EXT, |
17577 | | &sInterfaceObjectClassObjectOps |
17578 | | }, |
17579 | | eInterface, |
17580 | | true, |
17581 | | prototypes::id::WebGPUTexture, |
17582 | | PrototypeTraits<prototypes::id::WebGPUTexture>::Depth, |
17583 | | sNativePropertyHooks, |
17584 | | "function WebGPUTexture() {\n [native code]\n}", |
17585 | | JS::GetRealmFunctionPrototype |
17586 | | }; |
17587 | | |
17588 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
17589 | | { |
17590 | | "WebGPUTexturePrototype", |
17591 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
17592 | | JS_NULL_CLASS_OPS, |
17593 | | JS_NULL_CLASS_SPEC, |
17594 | | JS_NULL_CLASS_EXT, |
17595 | | JS_NULL_OBJECT_OPS |
17596 | | }, |
17597 | | eInterfacePrototype, |
17598 | | false, |
17599 | | prototypes::id::WebGPUTexture, |
17600 | | PrototypeTraits<prototypes::id::WebGPUTexture>::Depth, |
17601 | | sNativePropertyHooks, |
17602 | | "[object WebGPUTexturePrototype]", |
17603 | | JS::GetRealmObjectPrototype |
17604 | | }; |
17605 | | |
17606 | | bool |
17607 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
17608 | 0 | { |
17609 | 0 | static bool sPrefValue; |
17610 | 0 | static bool sPrefCacheSetUp = false; |
17611 | 0 | if (!sPrefCacheSetUp) { |
17612 | 0 | sPrefCacheSetUp = true; |
17613 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
17614 | 0 | } |
17615 | 0 |
|
17616 | 0 | return sPrefValue; |
17617 | 0 | } |
17618 | | |
17619 | | static const js::ClassOps sClassOps = { |
17620 | | _addProperty, /* addProperty */ |
17621 | | nullptr, /* delProperty */ |
17622 | | nullptr, /* enumerate */ |
17623 | | nullptr, /* newEnumerate */ |
17624 | | nullptr, /* resolve */ |
17625 | | nullptr, /* mayResolve */ |
17626 | | _finalize, /* finalize */ |
17627 | | nullptr, /* call */ |
17628 | | nullptr, /* hasInstance */ |
17629 | | nullptr, /* construct */ |
17630 | | nullptr, /* trace */ |
17631 | | }; |
17632 | | |
17633 | | static const js::ClassExtension sClassExtension = { |
17634 | | nullptr, /* weakmapKeyDelegateOp */ |
17635 | | _objectMoved /* objectMovedOp */ |
17636 | | }; |
17637 | | |
17638 | | static const DOMJSClass sClass = { |
17639 | | { "WebGPUTexture", |
17640 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
17641 | | &sClassOps, |
17642 | | JS_NULL_CLASS_SPEC, |
17643 | | &sClassExtension, |
17644 | | JS_NULL_OBJECT_OPS |
17645 | | }, |
17646 | | { prototypes::id::WebGPUTexture, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
17647 | | IsBaseOf<nsISupports, mozilla::webgpu::Texture >::value, |
17648 | | sNativePropertyHooks, |
17649 | | FindAssociatedGlobalForNative<mozilla::webgpu::Texture>::Get, |
17650 | | GetProtoObjectHandle, |
17651 | | GetCCParticipant<mozilla::webgpu::Texture>::Get() |
17652 | | }; |
17653 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
17654 | | "Must have the right minimal number of reserved slots."); |
17655 | | static_assert(1 >= 1, |
17656 | | "Must have enough reserved slots."); |
17657 | | |
17658 | | const JSClass* |
17659 | | GetJSClass() |
17660 | 0 | { |
17661 | 0 | return sClass.ToJSClass(); |
17662 | 0 | } |
17663 | | |
17664 | | bool |
17665 | | Wrap(JSContext* aCx, mozilla::webgpu::Texture* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
17666 | 0 | { |
17667 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::Texture>::value, |
17668 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
17669 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::Texture*>(aObject) == |
17670 | 0 | reinterpret_cast<mozilla::webgpu::Texture*>(aObject), |
17671 | 0 | "Multiple inheritance for mozilla::webgpu::Texture is broken."); |
17672 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
17673 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
17674 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
17675 | 0 | "You should probably not be using Wrap() directly; use " |
17676 | 0 | "GetOrCreateDOMReflector instead"); |
17677 | 0 |
|
17678 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
17679 | 0 | "nsISupports must be on our primary inheritance chain"); |
17680 | 0 |
|
17681 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
17682 | 0 | if (!global) { |
17683 | 0 | return false; |
17684 | 0 | } |
17685 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
17686 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
17687 | 0 |
|
17688 | 0 | // That might have ended up wrapping us already, due to the wonders |
17689 | 0 | // of XBL. Check for that, and bail out as needed. |
17690 | 0 | aReflector.set(aCache->GetWrapper()); |
17691 | 0 | if (aReflector) { |
17692 | | #ifdef DEBUG |
17693 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
17694 | | #endif // DEBUG |
17695 | | return true; |
17696 | 0 | } |
17697 | 0 |
|
17698 | 0 | JSAutoRealm ar(aCx, global); |
17699 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
17700 | 0 | if (!canonicalProto) { |
17701 | 0 | return false; |
17702 | 0 | } |
17703 | 0 | JS::Rooted<JSObject*> proto(aCx); |
17704 | 0 | if (aGivenProto) { |
17705 | 0 | proto = aGivenProto; |
17706 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
17707 | 0 | // coming in, we changed compartments to that of "parent" so may need |
17708 | 0 | // to wrap the proto here. |
17709 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
17710 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
17711 | 0 | return false; |
17712 | 0 | } |
17713 | 0 | } |
17714 | 0 | } else { |
17715 | 0 | proto = canonicalProto; |
17716 | 0 | } |
17717 | 0 |
|
17718 | 0 | BindingJSObjectCreator<mozilla::webgpu::Texture> creator(aCx); |
17719 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
17720 | 0 | if (!aReflector) { |
17721 | 0 | return false; |
17722 | 0 | } |
17723 | 0 | |
17724 | 0 | aCache->SetWrapper(aReflector); |
17725 | 0 | creator.InitializationSucceeded(); |
17726 | 0 |
|
17727 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
17728 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
17729 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
17730 | 0 | // otherwise we won't be able to properly recreate it later, since |
17731 | 0 | // we won't know what proto to use. Note that we don't check |
17732 | 0 | // aGivenProto here, since it's entirely possible (and even |
17733 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
17734 | 0 | // same as canonicalProto. |
17735 | 0 | if (proto != canonicalProto) { |
17736 | 0 | PreserveWrapper(aObject); |
17737 | 0 | } |
17738 | 0 |
|
17739 | 0 | return true; |
17740 | 0 | } |
17741 | | |
17742 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
17743 | | nullptr, |
17744 | | nullptr, |
17745 | | nullptr, |
17746 | | { sNativeProperties.Upcast(), nullptr }, |
17747 | | prototypes::id::WebGPUTexture, |
17748 | | constructors::id::WebGPUTexture, |
17749 | | nullptr, |
17750 | | &DefaultXrayExpandoObjectClass |
17751 | | } }; |
17752 | | |
17753 | | void |
17754 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
17755 | 0 | { |
17756 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
17757 | 0 | if (!parentProto) { |
17758 | 0 | return; |
17759 | 0 | } |
17760 | 0 | |
17761 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
17762 | 0 | if (!constructorProto) { |
17763 | 0 | return; |
17764 | 0 | } |
17765 | 0 | |
17766 | 0 | static bool sIdsInited = false; |
17767 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
17768 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
17769 | 0 | return; |
17770 | 0 | } |
17771 | 0 | sIdsInited = true; |
17772 | 0 | } |
17773 | 0 |
|
17774 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPUTexture); |
17775 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUTexture); |
17776 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
17777 | 0 | &sPrototypeClass.mBase, protoCache, |
17778 | 0 | nullptr, |
17779 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
17780 | 0 | interfaceCache, |
17781 | 0 | sNativeProperties.Upcast(), |
17782 | 0 | nullptr, |
17783 | 0 | "WebGPUTexture", aDefineOnGlobal, |
17784 | 0 | nullptr, |
17785 | 0 | false); |
17786 | 0 | } |
17787 | | |
17788 | | JSObject* |
17789 | | GetConstructorObject(JSContext* aCx) |
17790 | 0 | { |
17791 | 0 | return GetConstructorObjectHandle(aCx); |
17792 | 0 | } |
17793 | | |
17794 | | } // namespace WebGPUTexture_Binding |
17795 | | |
17796 | | |
17797 | | |
17798 | | namespace WebGPUTextureDimension_Binding { |
17799 | | |
17800 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
17801 | | #if defined(__clang__) |
17802 | | #pragma clang diagnostic push |
17803 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
17804 | | #endif |
17805 | | static const ConstantSpec sConstants_specs[] = { |
17806 | | { "e1D", JS::NumberValue(0U) }, |
17807 | | { "e2D", JS::NumberValue(1U) }, |
17808 | | { "e3D", JS::NumberValue(2U) }, |
17809 | | { 0, JS::UndefinedValue() } |
17810 | | }; |
17811 | | #if defined(__clang__) |
17812 | | #pragma clang diagnostic pop |
17813 | | #endif |
17814 | | |
17815 | | |
17816 | | static const Prefable<const ConstantSpec> sConstants[] = { |
17817 | | { nullptr, &sConstants_specs[0] }, |
17818 | | { nullptr, nullptr } |
17819 | | }; |
17820 | | |
17821 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
17822 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
17823 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
17824 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
17825 | | |
17826 | | |
17827 | | static uint16_t sNativeProperties_sortedPropertyIndices[3]; |
17828 | | static PropertyInfo sNativeProperties_propertyInfos[3]; |
17829 | | |
17830 | | static const NativePropertiesN<1> sNativeProperties = { |
17831 | | false, 0, |
17832 | | false, 0, |
17833 | | false, 0, |
17834 | | false, 0, |
17835 | | false, 0, |
17836 | | false, 0, |
17837 | | true, 0 /* sConstants */, |
17838 | | -1, |
17839 | | 3, |
17840 | | sNativeProperties_sortedPropertyIndices, |
17841 | | { |
17842 | | { sConstants, &sNativeProperties_propertyInfos[0] } |
17843 | | } |
17844 | | }; |
17845 | | static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
17846 | | "We have a property info count that is oversized"); |
17847 | | |
17848 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
17849 | | { |
17850 | | "Function", |
17851 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
17852 | | &sBoringInterfaceObjectClassClassOps, |
17853 | | JS_NULL_CLASS_SPEC, |
17854 | | JS_NULL_CLASS_EXT, |
17855 | | &sInterfaceObjectClassObjectOps |
17856 | | }, |
17857 | | eInterface, |
17858 | | false, |
17859 | | prototypes::id::_ID_Count, |
17860 | | 0, |
17861 | | sNativePropertyHooks, |
17862 | | "function WebGPUTextureDimension() {\n [native code]\n}", |
17863 | | JS::GetRealmFunctionPrototype |
17864 | | }; |
17865 | | |
17866 | | bool |
17867 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
17868 | 0 | { |
17869 | 0 | static bool sPrefValue; |
17870 | 0 | static bool sPrefCacheSetUp = false; |
17871 | 0 | if (!sPrefCacheSetUp) { |
17872 | 0 | sPrefCacheSetUp = true; |
17873 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
17874 | 0 | } |
17875 | 0 |
|
17876 | 0 | return sPrefValue; |
17877 | 0 | } |
17878 | | |
17879 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
17880 | | nullptr, |
17881 | | nullptr, |
17882 | | nullptr, |
17883 | | { sNativeProperties.Upcast(), nullptr }, |
17884 | | prototypes::id::_ID_Count, |
17885 | | constructors::id::WebGPUTextureDimension, |
17886 | | nullptr, |
17887 | | &DefaultXrayExpandoObjectClass |
17888 | | } }; |
17889 | | |
17890 | | void |
17891 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
17892 | 0 | { |
17893 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
17894 | 0 | if (!constructorProto) { |
17895 | 0 | return; |
17896 | 0 | } |
17897 | 0 | |
17898 | 0 | static bool sIdsInited = false; |
17899 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
17900 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
17901 | 0 | return; |
17902 | 0 | } |
17903 | 0 | sIdsInited = true; |
17904 | 0 | } |
17905 | 0 |
|
17906 | 0 | JS::Heap<JSObject*>* protoCache = nullptr; |
17907 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUTextureDimension); |
17908 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, nullptr, |
17909 | 0 | nullptr, protoCache, |
17910 | 0 | nullptr, |
17911 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
17912 | 0 | interfaceCache, |
17913 | 0 | sNativeProperties.Upcast(), |
17914 | 0 | nullptr, |
17915 | 0 | "WebGPUTextureDimension", aDefineOnGlobal, |
17916 | 0 | nullptr, |
17917 | 0 | false); |
17918 | 0 | } |
17919 | | |
17920 | | JSObject* |
17921 | | GetConstructorObject(JSContext* aCx) |
17922 | 0 | { |
17923 | 0 | return GetConstructorObjectHandle(aCx); |
17924 | 0 | } |
17925 | | |
17926 | | } // namespace WebGPUTextureDimension_Binding |
17927 | | |
17928 | | |
17929 | | |
17930 | | namespace WebGPUTextureFormat_Binding { |
17931 | | |
17932 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
17933 | | #if defined(__clang__) |
17934 | | #pragma clang diagnostic push |
17935 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
17936 | | #endif |
17937 | | static const ConstantSpec sConstants_specs[] = { |
17938 | | { "R8_G8_B8_A8_UNORM", JS::NumberValue(0U) }, |
17939 | | { "R8_G8_B8_A8_UINT", JS::NumberValue(1U) }, |
17940 | | { "B8_G8_R8_A8_UNORM", JS::NumberValue(2U) }, |
17941 | | { "D32_FLOAT_S8_UINT", JS::NumberValue(3U) }, |
17942 | | { 0, JS::UndefinedValue() } |
17943 | | }; |
17944 | | #if defined(__clang__) |
17945 | | #pragma clang diagnostic pop |
17946 | | #endif |
17947 | | |
17948 | | |
17949 | | static const Prefable<const ConstantSpec> sConstants[] = { |
17950 | | { nullptr, &sConstants_specs[0] }, |
17951 | | { nullptr, nullptr } |
17952 | | }; |
17953 | | |
17954 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
17955 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
17956 | | static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
17957 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
17958 | | |
17959 | | |
17960 | | static uint16_t sNativeProperties_sortedPropertyIndices[4]; |
17961 | | static PropertyInfo sNativeProperties_propertyInfos[4]; |
17962 | | |
17963 | | static const NativePropertiesN<1> sNativeProperties = { |
17964 | | false, 0, |
17965 | | false, 0, |
17966 | | false, 0, |
17967 | | false, 0, |
17968 | | false, 0, |
17969 | | false, 0, |
17970 | | true, 0 /* sConstants */, |
17971 | | -1, |
17972 | | 4, |
17973 | | sNativeProperties_sortedPropertyIndices, |
17974 | | { |
17975 | | { sConstants, &sNativeProperties_propertyInfos[0] } |
17976 | | } |
17977 | | }; |
17978 | | static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
17979 | | "We have a property info count that is oversized"); |
17980 | | |
17981 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
17982 | | { |
17983 | | "Function", |
17984 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
17985 | | &sBoringInterfaceObjectClassClassOps, |
17986 | | JS_NULL_CLASS_SPEC, |
17987 | | JS_NULL_CLASS_EXT, |
17988 | | &sInterfaceObjectClassObjectOps |
17989 | | }, |
17990 | | eInterface, |
17991 | | false, |
17992 | | prototypes::id::_ID_Count, |
17993 | | 0, |
17994 | | sNativePropertyHooks, |
17995 | | "function WebGPUTextureFormat() {\n [native code]\n}", |
17996 | | JS::GetRealmFunctionPrototype |
17997 | | }; |
17998 | | |
17999 | | bool |
18000 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
18001 | 0 | { |
18002 | 0 | static bool sPrefValue; |
18003 | 0 | static bool sPrefCacheSetUp = false; |
18004 | 0 | if (!sPrefCacheSetUp) { |
18005 | 0 | sPrefCacheSetUp = true; |
18006 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
18007 | 0 | } |
18008 | 0 |
|
18009 | 0 | return sPrefValue; |
18010 | 0 | } |
18011 | | |
18012 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
18013 | | nullptr, |
18014 | | nullptr, |
18015 | | nullptr, |
18016 | | { sNativeProperties.Upcast(), nullptr }, |
18017 | | prototypes::id::_ID_Count, |
18018 | | constructors::id::WebGPUTextureFormat, |
18019 | | nullptr, |
18020 | | &DefaultXrayExpandoObjectClass |
18021 | | } }; |
18022 | | |
18023 | | void |
18024 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
18025 | 0 | { |
18026 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
18027 | 0 | if (!constructorProto) { |
18028 | 0 | return; |
18029 | 0 | } |
18030 | 0 | |
18031 | 0 | static bool sIdsInited = false; |
18032 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
18033 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
18034 | 0 | return; |
18035 | 0 | } |
18036 | 0 | sIdsInited = true; |
18037 | 0 | } |
18038 | 0 |
|
18039 | 0 | JS::Heap<JSObject*>* protoCache = nullptr; |
18040 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUTextureFormat); |
18041 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, nullptr, |
18042 | 0 | nullptr, protoCache, |
18043 | 0 | nullptr, |
18044 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
18045 | 0 | interfaceCache, |
18046 | 0 | sNativeProperties.Upcast(), |
18047 | 0 | nullptr, |
18048 | 0 | "WebGPUTextureFormat", aDefineOnGlobal, |
18049 | 0 | nullptr, |
18050 | 0 | false); |
18051 | 0 | } |
18052 | | |
18053 | | JSObject* |
18054 | | GetConstructorObject(JSContext* aCx) |
18055 | 0 | { |
18056 | 0 | return GetConstructorObjectHandle(aCx); |
18057 | 0 | } |
18058 | | |
18059 | | } // namespace WebGPUTextureFormat_Binding |
18060 | | |
18061 | | |
18062 | | |
18063 | | namespace WebGPUTextureUsage_Binding { |
18064 | | |
18065 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
18066 | | #if defined(__clang__) |
18067 | | #pragma clang diagnostic push |
18068 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
18069 | | #endif |
18070 | | static const ConstantSpec sConstants_specs[] = { |
18071 | | { "NONE", JS::NumberValue(0U) }, |
18072 | | { "TRANSFER_SRC", JS::NumberValue(1U) }, |
18073 | | { "TRANSFER_DST", JS::NumberValue(2U) }, |
18074 | | { "SAMPLED", JS::NumberValue(4U) }, |
18075 | | { "STORAGE", JS::NumberValue(8U) }, |
18076 | | { "OUTPUT_ATTACHMENT", JS::NumberValue(16U) }, |
18077 | | { "PRESENT", JS::NumberValue(32U) }, |
18078 | | { 0, JS::UndefinedValue() } |
18079 | | }; |
18080 | | #if defined(__clang__) |
18081 | | #pragma clang diagnostic pop |
18082 | | #endif |
18083 | | |
18084 | | |
18085 | | static const Prefable<const ConstantSpec> sConstants[] = { |
18086 | | { nullptr, &sConstants_specs[0] }, |
18087 | | { nullptr, nullptr } |
18088 | | }; |
18089 | | |
18090 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
18091 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
18092 | | static_assert(7 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
18093 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
18094 | | |
18095 | | |
18096 | | static uint16_t sNativeProperties_sortedPropertyIndices[7]; |
18097 | | static PropertyInfo sNativeProperties_propertyInfos[7]; |
18098 | | |
18099 | | static const NativePropertiesN<1> sNativeProperties = { |
18100 | | false, 0, |
18101 | | false, 0, |
18102 | | false, 0, |
18103 | | false, 0, |
18104 | | false, 0, |
18105 | | false, 0, |
18106 | | true, 0 /* sConstants */, |
18107 | | -1, |
18108 | | 7, |
18109 | | sNativeProperties_sortedPropertyIndices, |
18110 | | { |
18111 | | { sConstants, &sNativeProperties_propertyInfos[0] } |
18112 | | } |
18113 | | }; |
18114 | | static_assert(7 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
18115 | | "We have a property info count that is oversized"); |
18116 | | |
18117 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
18118 | | { |
18119 | | "Function", |
18120 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
18121 | | &sBoringInterfaceObjectClassClassOps, |
18122 | | JS_NULL_CLASS_SPEC, |
18123 | | JS_NULL_CLASS_EXT, |
18124 | | &sInterfaceObjectClassObjectOps |
18125 | | }, |
18126 | | eInterface, |
18127 | | false, |
18128 | | prototypes::id::_ID_Count, |
18129 | | 0, |
18130 | | sNativePropertyHooks, |
18131 | | "function WebGPUTextureUsage() {\n [native code]\n}", |
18132 | | JS::GetRealmFunctionPrototype |
18133 | | }; |
18134 | | |
18135 | | bool |
18136 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
18137 | 0 | { |
18138 | 0 | static bool sPrefValue; |
18139 | 0 | static bool sPrefCacheSetUp = false; |
18140 | 0 | if (!sPrefCacheSetUp) { |
18141 | 0 | sPrefCacheSetUp = true; |
18142 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
18143 | 0 | } |
18144 | 0 |
|
18145 | 0 | return sPrefValue; |
18146 | 0 | } |
18147 | | |
18148 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
18149 | | nullptr, |
18150 | | nullptr, |
18151 | | nullptr, |
18152 | | { sNativeProperties.Upcast(), nullptr }, |
18153 | | prototypes::id::_ID_Count, |
18154 | | constructors::id::WebGPUTextureUsage, |
18155 | | nullptr, |
18156 | | &DefaultXrayExpandoObjectClass |
18157 | | } }; |
18158 | | |
18159 | | void |
18160 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
18161 | 0 | { |
18162 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
18163 | 0 | if (!constructorProto) { |
18164 | 0 | return; |
18165 | 0 | } |
18166 | 0 | |
18167 | 0 | static bool sIdsInited = false; |
18168 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
18169 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
18170 | 0 | return; |
18171 | 0 | } |
18172 | 0 | sIdsInited = true; |
18173 | 0 | } |
18174 | 0 |
|
18175 | 0 | JS::Heap<JSObject*>* protoCache = nullptr; |
18176 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUTextureUsage); |
18177 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, nullptr, |
18178 | 0 | nullptr, protoCache, |
18179 | 0 | nullptr, |
18180 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
18181 | 0 | interfaceCache, |
18182 | 0 | sNativeProperties.Upcast(), |
18183 | 0 | nullptr, |
18184 | 0 | "WebGPUTextureUsage", aDefineOnGlobal, |
18185 | 0 | nullptr, |
18186 | 0 | false); |
18187 | 0 | } |
18188 | | |
18189 | | JSObject* |
18190 | | GetConstructorObject(JSContext* aCx) |
18191 | 0 | { |
18192 | 0 | return GetConstructorObjectHandle(aCx); |
18193 | 0 | } |
18194 | | |
18195 | | } // namespace WebGPUTextureUsage_Binding |
18196 | | |
18197 | | |
18198 | | |
18199 | | namespace WebGPUTextureView_Binding { |
18200 | | |
18201 | | static bool |
18202 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
18203 | 0 | { |
18204 | 0 | mozilla::webgpu::TextureView* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::TextureView>(obj); |
18205 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
18206 | 0 | // obviously can't preserve if we're not initialized. |
18207 | 0 | if (self && self->GetWrapperPreserveColor()) { |
18208 | 0 | PreserveWrapper(self); |
18209 | 0 | } |
18210 | 0 | return true; |
18211 | 0 | } |
18212 | | |
18213 | | static void |
18214 | | _finalize(js::FreeOp* fop, JSObject* obj) |
18215 | 0 | { |
18216 | 0 | mozilla::webgpu::TextureView* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::TextureView>(obj); |
18217 | 0 | if (self) { |
18218 | 0 | ClearWrapper(self, self, obj); |
18219 | 0 | AddForDeferredFinalization<mozilla::webgpu::TextureView>(self); |
18220 | 0 | } |
18221 | 0 | } |
18222 | | |
18223 | | static size_t |
18224 | | _objectMoved(JSObject* obj, JSObject* old) |
18225 | 0 | { |
18226 | 0 | mozilla::webgpu::TextureView* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::webgpu::TextureView>(obj); |
18227 | 0 | if (self) { |
18228 | 0 | UpdateWrapper(self, self, obj, old); |
18229 | 0 | } |
18230 | 0 |
|
18231 | 0 | return 0; |
18232 | 0 | } |
18233 | | |
18234 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
18235 | | { |
18236 | | "Function", |
18237 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
18238 | | &sBoringInterfaceObjectClassClassOps, |
18239 | | JS_NULL_CLASS_SPEC, |
18240 | | JS_NULL_CLASS_EXT, |
18241 | | &sInterfaceObjectClassObjectOps |
18242 | | }, |
18243 | | eInterface, |
18244 | | true, |
18245 | | prototypes::id::WebGPUTextureView, |
18246 | | PrototypeTraits<prototypes::id::WebGPUTextureView>::Depth, |
18247 | | sNativePropertyHooks, |
18248 | | "function WebGPUTextureView() {\n [native code]\n}", |
18249 | | JS::GetRealmFunctionPrototype |
18250 | | }; |
18251 | | |
18252 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
18253 | | { |
18254 | | "WebGPUTextureViewPrototype", |
18255 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
18256 | | JS_NULL_CLASS_OPS, |
18257 | | JS_NULL_CLASS_SPEC, |
18258 | | JS_NULL_CLASS_EXT, |
18259 | | JS_NULL_OBJECT_OPS |
18260 | | }, |
18261 | | eInterfacePrototype, |
18262 | | false, |
18263 | | prototypes::id::WebGPUTextureView, |
18264 | | PrototypeTraits<prototypes::id::WebGPUTextureView>::Depth, |
18265 | | sNativePropertyHooks, |
18266 | | "[object WebGPUTextureViewPrototype]", |
18267 | | JS::GetRealmObjectPrototype |
18268 | | }; |
18269 | | |
18270 | | bool |
18271 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
18272 | 0 | { |
18273 | 0 | static bool sPrefValue; |
18274 | 0 | static bool sPrefCacheSetUp = false; |
18275 | 0 | if (!sPrefCacheSetUp) { |
18276 | 0 | sPrefCacheSetUp = true; |
18277 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
18278 | 0 | } |
18279 | 0 |
|
18280 | 0 | return sPrefValue; |
18281 | 0 | } |
18282 | | |
18283 | | static const js::ClassOps sClassOps = { |
18284 | | _addProperty, /* addProperty */ |
18285 | | nullptr, /* delProperty */ |
18286 | | nullptr, /* enumerate */ |
18287 | | nullptr, /* newEnumerate */ |
18288 | | nullptr, /* resolve */ |
18289 | | nullptr, /* mayResolve */ |
18290 | | _finalize, /* finalize */ |
18291 | | nullptr, /* call */ |
18292 | | nullptr, /* hasInstance */ |
18293 | | nullptr, /* construct */ |
18294 | | nullptr, /* trace */ |
18295 | | }; |
18296 | | |
18297 | | static const js::ClassExtension sClassExtension = { |
18298 | | nullptr, /* weakmapKeyDelegateOp */ |
18299 | | _objectMoved /* objectMovedOp */ |
18300 | | }; |
18301 | | |
18302 | | static const DOMJSClass sClass = { |
18303 | | { "WebGPUTextureView", |
18304 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
18305 | | &sClassOps, |
18306 | | JS_NULL_CLASS_SPEC, |
18307 | | &sClassExtension, |
18308 | | JS_NULL_OBJECT_OPS |
18309 | | }, |
18310 | | { prototypes::id::WebGPUTextureView, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
18311 | | IsBaseOf<nsISupports, mozilla::webgpu::TextureView >::value, |
18312 | | sNativePropertyHooks, |
18313 | | FindAssociatedGlobalForNative<mozilla::webgpu::TextureView>::Get, |
18314 | | GetProtoObjectHandle, |
18315 | | GetCCParticipant<mozilla::webgpu::TextureView>::Get() |
18316 | | }; |
18317 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
18318 | | "Must have the right minimal number of reserved slots."); |
18319 | | static_assert(1 >= 1, |
18320 | | "Must have enough reserved slots."); |
18321 | | |
18322 | | const JSClass* |
18323 | | GetJSClass() |
18324 | 0 | { |
18325 | 0 | return sClass.ToJSClass(); |
18326 | 0 | } |
18327 | | |
18328 | | bool |
18329 | | Wrap(JSContext* aCx, mozilla::webgpu::TextureView* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
18330 | 0 | { |
18331 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::webgpu::TextureView>::value, |
18332 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
18333 | 0 | MOZ_ASSERT(static_cast<mozilla::webgpu::TextureView*>(aObject) == |
18334 | 0 | reinterpret_cast<mozilla::webgpu::TextureView*>(aObject), |
18335 | 0 | "Multiple inheritance for mozilla::webgpu::TextureView is broken."); |
18336 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
18337 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
18338 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
18339 | 0 | "You should probably not be using Wrap() directly; use " |
18340 | 0 | "GetOrCreateDOMReflector instead"); |
18341 | 0 |
|
18342 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
18343 | 0 | "nsISupports must be on our primary inheritance chain"); |
18344 | 0 |
|
18345 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
18346 | 0 | if (!global) { |
18347 | 0 | return false; |
18348 | 0 | } |
18349 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
18350 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
18351 | 0 |
|
18352 | 0 | // That might have ended up wrapping us already, due to the wonders |
18353 | 0 | // of XBL. Check for that, and bail out as needed. |
18354 | 0 | aReflector.set(aCache->GetWrapper()); |
18355 | 0 | if (aReflector) { |
18356 | | #ifdef DEBUG |
18357 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
18358 | | #endif // DEBUG |
18359 | | return true; |
18360 | 0 | } |
18361 | 0 |
|
18362 | 0 | JSAutoRealm ar(aCx, global); |
18363 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
18364 | 0 | if (!canonicalProto) { |
18365 | 0 | return false; |
18366 | 0 | } |
18367 | 0 | JS::Rooted<JSObject*> proto(aCx); |
18368 | 0 | if (aGivenProto) { |
18369 | 0 | proto = aGivenProto; |
18370 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
18371 | 0 | // coming in, we changed compartments to that of "parent" so may need |
18372 | 0 | // to wrap the proto here. |
18373 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
18374 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
18375 | 0 | return false; |
18376 | 0 | } |
18377 | 0 | } |
18378 | 0 | } else { |
18379 | 0 | proto = canonicalProto; |
18380 | 0 | } |
18381 | 0 |
|
18382 | 0 | BindingJSObjectCreator<mozilla::webgpu::TextureView> creator(aCx); |
18383 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
18384 | 0 | if (!aReflector) { |
18385 | 0 | return false; |
18386 | 0 | } |
18387 | 0 | |
18388 | 0 | aCache->SetWrapper(aReflector); |
18389 | 0 | creator.InitializationSucceeded(); |
18390 | 0 |
|
18391 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
18392 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
18393 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
18394 | 0 | // otherwise we won't be able to properly recreate it later, since |
18395 | 0 | // we won't know what proto to use. Note that we don't check |
18396 | 0 | // aGivenProto here, since it's entirely possible (and even |
18397 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
18398 | 0 | // same as canonicalProto. |
18399 | 0 | if (proto != canonicalProto) { |
18400 | 0 | PreserveWrapper(aObject); |
18401 | 0 | } |
18402 | 0 |
|
18403 | 0 | return true; |
18404 | 0 | } |
18405 | | |
18406 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
18407 | | nullptr, |
18408 | | nullptr, |
18409 | | nullptr, |
18410 | | { nullptr, nullptr }, |
18411 | | prototypes::id::WebGPUTextureView, |
18412 | | constructors::id::WebGPUTextureView, |
18413 | | nullptr, |
18414 | | &DefaultXrayExpandoObjectClass |
18415 | | } }; |
18416 | | |
18417 | | void |
18418 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
18419 | 0 | { |
18420 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
18421 | 0 | if (!parentProto) { |
18422 | 0 | return; |
18423 | 0 | } |
18424 | 0 | |
18425 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
18426 | 0 | if (!constructorProto) { |
18427 | 0 | return; |
18428 | 0 | } |
18429 | 0 | |
18430 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGPUTextureView); |
18431 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUTextureView); |
18432 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
18433 | 0 | &sPrototypeClass.mBase, protoCache, |
18434 | 0 | nullptr, |
18435 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
18436 | 0 | interfaceCache, |
18437 | 0 | nullptr, |
18438 | 0 | nullptr, |
18439 | 0 | "WebGPUTextureView", aDefineOnGlobal, |
18440 | 0 | nullptr, |
18441 | 0 | false); |
18442 | 0 | } |
18443 | | |
18444 | | JSObject* |
18445 | | GetConstructorObject(JSContext* aCx) |
18446 | 0 | { |
18447 | 0 | return GetConstructorObjectHandle(aCx); |
18448 | 0 | } |
18449 | | |
18450 | | } // namespace WebGPUTextureView_Binding |
18451 | | |
18452 | | |
18453 | | |
18454 | | namespace WebGPUVertexFormat_Binding { |
18455 | | |
18456 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
18457 | | #if defined(__clang__) |
18458 | | #pragma clang diagnostic push |
18459 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
18460 | | #endif |
18461 | | static const ConstantSpec sConstants_specs[] = { |
18462 | | { "FLOAT_R32_G32_B32_A32", JS::NumberValue(0U) }, |
18463 | | { "FLOAT_R32_G32_B32", JS::NumberValue(1U) }, |
18464 | | { "FLOAT_R32_G32", JS::NumberValue(2U) }, |
18465 | | { "FLOAT_R32", JS::NumberValue(3U) }, |
18466 | | { 0, JS::UndefinedValue() } |
18467 | | }; |
18468 | | #if defined(__clang__) |
18469 | | #pragma clang diagnostic pop |
18470 | | #endif |
18471 | | |
18472 | | |
18473 | | static const Prefable<const ConstantSpec> sConstants[] = { |
18474 | | { nullptr, &sConstants_specs[0] }, |
18475 | | { nullptr, nullptr } |
18476 | | }; |
18477 | | |
18478 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
18479 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
18480 | | static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
18481 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
18482 | | |
18483 | | |
18484 | | static uint16_t sNativeProperties_sortedPropertyIndices[4]; |
18485 | | static PropertyInfo sNativeProperties_propertyInfos[4]; |
18486 | | |
18487 | | static const NativePropertiesN<1> sNativeProperties = { |
18488 | | false, 0, |
18489 | | false, 0, |
18490 | | false, 0, |
18491 | | false, 0, |
18492 | | false, 0, |
18493 | | false, 0, |
18494 | | true, 0 /* sConstants */, |
18495 | | -1, |
18496 | | 4, |
18497 | | sNativeProperties_sortedPropertyIndices, |
18498 | | { |
18499 | | { sConstants, &sNativeProperties_propertyInfos[0] } |
18500 | | } |
18501 | | }; |
18502 | | static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
18503 | | "We have a property info count that is oversized"); |
18504 | | |
18505 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
18506 | | { |
18507 | | "Function", |
18508 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
18509 | | &sBoringInterfaceObjectClassClassOps, |
18510 | | JS_NULL_CLASS_SPEC, |
18511 | | JS_NULL_CLASS_EXT, |
18512 | | &sInterfaceObjectClassObjectOps |
18513 | | }, |
18514 | | eInterface, |
18515 | | false, |
18516 | | prototypes::id::_ID_Count, |
18517 | | 0, |
18518 | | sNativePropertyHooks, |
18519 | | "function WebGPUVertexFormat() {\n [native code]\n}", |
18520 | | JS::GetRealmFunctionPrototype |
18521 | | }; |
18522 | | |
18523 | | bool |
18524 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
18525 | 0 | { |
18526 | 0 | static bool sPrefValue; |
18527 | 0 | static bool sPrefCacheSetUp = false; |
18528 | 0 | if (!sPrefCacheSetUp) { |
18529 | 0 | sPrefCacheSetUp = true; |
18530 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.webgpu.enable"); |
18531 | 0 | } |
18532 | 0 |
|
18533 | 0 | return sPrefValue; |
18534 | 0 | } |
18535 | | |
18536 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
18537 | | nullptr, |
18538 | | nullptr, |
18539 | | nullptr, |
18540 | | { sNativeProperties.Upcast(), nullptr }, |
18541 | | prototypes::id::_ID_Count, |
18542 | | constructors::id::WebGPUVertexFormat, |
18543 | | nullptr, |
18544 | | &DefaultXrayExpandoObjectClass |
18545 | | } }; |
18546 | | |
18547 | | void |
18548 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
18549 | 0 | { |
18550 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
18551 | 0 | if (!constructorProto) { |
18552 | 0 | return; |
18553 | 0 | } |
18554 | 0 | |
18555 | 0 | static bool sIdsInited = false; |
18556 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
18557 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
18558 | 0 | return; |
18559 | 0 | } |
18560 | 0 | sIdsInited = true; |
18561 | 0 | } |
18562 | 0 |
|
18563 | 0 | JS::Heap<JSObject*>* protoCache = nullptr; |
18564 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGPUVertexFormat); |
18565 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, nullptr, |
18566 | 0 | nullptr, protoCache, |
18567 | 0 | nullptr, |
18568 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
18569 | 0 | interfaceCache, |
18570 | 0 | sNativeProperties.Upcast(), |
18571 | 0 | nullptr, |
18572 | 0 | "WebGPUVertexFormat", aDefineOnGlobal, |
18573 | 0 | nullptr, |
18574 | 0 | false); |
18575 | 0 | } |
18576 | | |
18577 | | JSObject* |
18578 | | GetConstructorObject(JSContext* aCx) |
18579 | 0 | { |
18580 | 0 | return GetConstructorObjectHandle(aCx); |
18581 | 0 | } |
18582 | | |
18583 | | } // namespace WebGPUVertexFormat_Binding |
18584 | | |
18585 | | |
18586 | | |
18587 | | } // namespace dom |
18588 | | } // namespace mozilla |