/work/obj-fuzz/dom/bindings/SourceBufferListBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM SourceBufferList.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "EventHandlerBinding.h" |
4 | | #include "EventTargetBinding.h" |
5 | | #include "SourceBufferListBinding.h" |
6 | | #include "WrapperFactory.h" |
7 | | #include "mozilla/OwningNonNull.h" |
8 | | #include "mozilla/dom/BindingUtils.h" |
9 | | #include "mozilla/dom/DOMJSClass.h" |
10 | | #include "mozilla/dom/DOMJSProxyHandler.h" |
11 | | #include "mozilla/dom/MediaSource.h" |
12 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
13 | | #include "mozilla/dom/Nullable.h" |
14 | | #include "mozilla/dom/PrimitiveConversions.h" |
15 | | #include "mozilla/dom/SourceBuffer.h" |
16 | | #include "mozilla/dom/SourceBufferList.h" |
17 | | #include "mozilla/dom/XrayExpandoClass.h" |
18 | | |
19 | | namespace mozilla { |
20 | | namespace dom { |
21 | | |
22 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
23 | | using namespace mozilla::dom::binding_detail; |
24 | | |
25 | | |
26 | | namespace SourceBufferList_Binding { |
27 | | |
28 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value, |
29 | | "Can't inherit from an interface with a different ownership model."); |
30 | | |
31 | | MOZ_CAN_RUN_SCRIPT static bool |
32 | | get_length(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SourceBufferList* self, JSJitGetterCallArgs args) |
33 | 0 | { |
34 | 0 | AUTO_PROFILER_LABEL_FAST("get SourceBufferList.length", DOM, cx); |
35 | 0 |
|
36 | 0 | uint32_t result(self->Length()); |
37 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
38 | 0 | args.rval().setNumber(result); |
39 | 0 | return true; |
40 | 0 | } |
41 | | |
42 | | static const JSJitInfo length_getterinfo = { |
43 | | { (JSJitGetterOp)get_length }, |
44 | | { prototypes::id::SourceBufferList }, |
45 | | { PrototypeTraits<prototypes::id::SourceBufferList>::Depth }, |
46 | | JSJitInfo::Getter, |
47 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
48 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
49 | | true, /* isInfallible. False in setters. */ |
50 | | false, /* isMovable. Not relevant for setters. */ |
51 | | false, /* isEliminatable. Not relevant for setters. */ |
52 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
53 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
54 | | false, /* isTypedMethod. Only relevant for methods. */ |
55 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
56 | | }; |
57 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
58 | | static_assert(0 < 1, "There is no slot for us"); |
59 | | |
60 | | MOZ_CAN_RUN_SCRIPT static bool |
61 | | get_onaddsourcebuffer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SourceBufferList* self, JSJitGetterCallArgs args) |
62 | 0 | { |
63 | 0 | AUTO_PROFILER_LABEL_FAST("get SourceBufferList.onaddsourcebuffer", DOM, cx); |
64 | 0 |
|
65 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnaddsourcebuffer()); |
66 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
67 | 0 | if (result) { |
68 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
69 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
70 | 0 | return false; |
71 | 0 | } |
72 | 0 | return true; |
73 | 0 | } else { |
74 | 0 | args.rval().setNull(); |
75 | 0 | return true; |
76 | 0 | } |
77 | 0 | } |
78 | | |
79 | | MOZ_CAN_RUN_SCRIPT static bool |
80 | | set_onaddsourcebuffer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SourceBufferList* self, JSJitSetterCallArgs args) |
81 | 0 | { |
82 | 0 | AUTO_PROFILER_LABEL_FAST("set SourceBufferList.onaddsourcebuffer", DOM, cx); |
83 | 0 |
|
84 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
85 | 0 | if (args[0].isObject()) { |
86 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
87 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
88 | 0 | } |
89 | 0 | } else { |
90 | 0 | arg0 = nullptr; |
91 | 0 | } |
92 | 0 | self->SetOnaddsourcebuffer(Constify(arg0)); |
93 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
94 | 0 |
|
95 | 0 | return true; |
96 | 0 | } |
97 | | |
98 | | static const JSJitInfo onaddsourcebuffer_getterinfo = { |
99 | | { (JSJitGetterOp)get_onaddsourcebuffer }, |
100 | | { prototypes::id::SourceBufferList }, |
101 | | { PrototypeTraits<prototypes::id::SourceBufferList>::Depth }, |
102 | | JSJitInfo::Getter, |
103 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
104 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
105 | | false, /* isInfallible. False in setters. */ |
106 | | false, /* isMovable. Not relevant for setters. */ |
107 | | false, /* isEliminatable. Not relevant for setters. */ |
108 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
109 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
110 | | false, /* isTypedMethod. Only relevant for methods. */ |
111 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
112 | | }; |
113 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
114 | | static_assert(0 < 1, "There is no slot for us"); |
115 | | static const JSJitInfo onaddsourcebuffer_setterinfo = { |
116 | | { (JSJitGetterOp)set_onaddsourcebuffer }, |
117 | | { prototypes::id::SourceBufferList }, |
118 | | { PrototypeTraits<prototypes::id::SourceBufferList>::Depth }, |
119 | | JSJitInfo::Setter, |
120 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
121 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
122 | | false, /* isInfallible. False in setters. */ |
123 | | false, /* isMovable. Not relevant for setters. */ |
124 | | false, /* isEliminatable. Not relevant for setters. */ |
125 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
126 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
127 | | false, /* isTypedMethod. Only relevant for methods. */ |
128 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
129 | | }; |
130 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
131 | | static_assert(0 < 1, "There is no slot for us"); |
132 | | |
133 | | MOZ_CAN_RUN_SCRIPT static bool |
134 | | get_onremovesourcebuffer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SourceBufferList* self, JSJitGetterCallArgs args) |
135 | 0 | { |
136 | 0 | AUTO_PROFILER_LABEL_FAST("get SourceBufferList.onremovesourcebuffer", DOM, cx); |
137 | 0 |
|
138 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnremovesourcebuffer()); |
139 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
140 | 0 | if (result) { |
141 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
142 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
143 | 0 | return false; |
144 | 0 | } |
145 | 0 | return true; |
146 | 0 | } else { |
147 | 0 | args.rval().setNull(); |
148 | 0 | return true; |
149 | 0 | } |
150 | 0 | } |
151 | | |
152 | | MOZ_CAN_RUN_SCRIPT static bool |
153 | | set_onremovesourcebuffer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SourceBufferList* self, JSJitSetterCallArgs args) |
154 | 0 | { |
155 | 0 | AUTO_PROFILER_LABEL_FAST("set SourceBufferList.onremovesourcebuffer", DOM, cx); |
156 | 0 |
|
157 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
158 | 0 | if (args[0].isObject()) { |
159 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
160 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
161 | 0 | } |
162 | 0 | } else { |
163 | 0 | arg0 = nullptr; |
164 | 0 | } |
165 | 0 | self->SetOnremovesourcebuffer(Constify(arg0)); |
166 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
167 | 0 |
|
168 | 0 | return true; |
169 | 0 | } |
170 | | |
171 | | static const JSJitInfo onremovesourcebuffer_getterinfo = { |
172 | | { (JSJitGetterOp)get_onremovesourcebuffer }, |
173 | | { prototypes::id::SourceBufferList }, |
174 | | { PrototypeTraits<prototypes::id::SourceBufferList>::Depth }, |
175 | | JSJitInfo::Getter, |
176 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
177 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
178 | | false, /* isInfallible. False in setters. */ |
179 | | false, /* isMovable. Not relevant for setters. */ |
180 | | false, /* isEliminatable. Not relevant for setters. */ |
181 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
182 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
183 | | false, /* isTypedMethod. Only relevant for methods. */ |
184 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
185 | | }; |
186 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
187 | | static_assert(0 < 1, "There is no slot for us"); |
188 | | static const JSJitInfo onremovesourcebuffer_setterinfo = { |
189 | | { (JSJitGetterOp)set_onremovesourcebuffer }, |
190 | | { prototypes::id::SourceBufferList }, |
191 | | { PrototypeTraits<prototypes::id::SourceBufferList>::Depth }, |
192 | | JSJitInfo::Setter, |
193 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
194 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
195 | | false, /* isInfallible. False in setters. */ |
196 | | false, /* isMovable. Not relevant for setters. */ |
197 | | false, /* isEliminatable. Not relevant for setters. */ |
198 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
199 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
200 | | false, /* isTypedMethod. Only relevant for methods. */ |
201 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
202 | | }; |
203 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
204 | | static_assert(0 < 1, "There is no slot for us"); |
205 | | |
206 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
207 | | #if defined(__clang__) |
208 | | #pragma clang diagnostic push |
209 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
210 | | #endif |
211 | | static const JSFunctionSpec sMethods_specs[] = { |
212 | | JS_SYM_FNSPEC(iterator, nullptr, nullptr, 0, 0, "ArrayValues"), |
213 | | JS_FS_END |
214 | | }; |
215 | | #if defined(__clang__) |
216 | | #pragma clang diagnostic pop |
217 | | #endif |
218 | | |
219 | | |
220 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
221 | | { nullptr, &sMethods_specs[0] }, |
222 | | { nullptr, nullptr } |
223 | | }; |
224 | | |
225 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
226 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
227 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
228 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
229 | | |
230 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
231 | | #if defined(__clang__) |
232 | | #pragma clang diagnostic push |
233 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
234 | | #endif |
235 | | static const JSPropertySpec sAttributes_specs[] = { |
236 | | { "length", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &length_getterinfo, nullptr, nullptr }, |
237 | | { "onaddsourcebuffer", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onaddsourcebuffer_getterinfo, GenericSetter<NormalThisPolicy>, &onaddsourcebuffer_setterinfo }, |
238 | | { "onremovesourcebuffer", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onremovesourcebuffer_getterinfo, GenericSetter<NormalThisPolicy>, &onremovesourcebuffer_setterinfo }, |
239 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
240 | | }; |
241 | | #if defined(__clang__) |
242 | | #pragma clang diagnostic pop |
243 | | #endif |
244 | | |
245 | | |
246 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
247 | | { nullptr, &sAttributes_specs[0] }, |
248 | | { nullptr, nullptr } |
249 | | }; |
250 | | |
251 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
252 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
253 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
254 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
255 | | |
256 | | |
257 | | static uint16_t sNativeProperties_sortedPropertyIndices[4]; |
258 | | static PropertyInfo sNativeProperties_propertyInfos[4]; |
259 | | |
260 | | static const NativePropertiesN<2> sNativeProperties = { |
261 | | false, 0, |
262 | | false, 0, |
263 | | true, 0 /* sMethods */, |
264 | | true, 1 /* sAttributes */, |
265 | | false, 0, |
266 | | false, 0, |
267 | | false, 0, |
268 | | -1, |
269 | | 4, |
270 | | sNativeProperties_sortedPropertyIndices, |
271 | | { |
272 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
273 | | { sAttributes, &sNativeProperties_propertyInfos[1] } |
274 | | } |
275 | | }; |
276 | | static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
277 | | "We have a property info count that is oversized"); |
278 | | |
279 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
280 | | { |
281 | | "Function", |
282 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
283 | | &sBoringInterfaceObjectClassClassOps, |
284 | | JS_NULL_CLASS_SPEC, |
285 | | JS_NULL_CLASS_EXT, |
286 | | &sInterfaceObjectClassObjectOps |
287 | | }, |
288 | | eInterface, |
289 | | true, |
290 | | prototypes::id::SourceBufferList, |
291 | | PrototypeTraits<prototypes::id::SourceBufferList>::Depth, |
292 | | sNativePropertyHooks, |
293 | | "function SourceBufferList() {\n [native code]\n}", |
294 | | EventTarget_Binding::GetConstructorObject |
295 | | }; |
296 | | |
297 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
298 | | { |
299 | | "SourceBufferListPrototype", |
300 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
301 | | JS_NULL_CLASS_OPS, |
302 | | JS_NULL_CLASS_SPEC, |
303 | | JS_NULL_CLASS_EXT, |
304 | | JS_NULL_OBJECT_OPS |
305 | | }, |
306 | | eInterfacePrototype, |
307 | | false, |
308 | | prototypes::id::SourceBufferList, |
309 | | PrototypeTraits<prototypes::id::SourceBufferList>::Depth, |
310 | | sNativePropertyHooks, |
311 | | "[object SourceBufferListPrototype]", |
312 | | EventTarget_Binding::GetProtoObject |
313 | | }; |
314 | | |
315 | | bool |
316 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
317 | 0 | { |
318 | 0 | return mozilla::dom::MediaSource::Enabled(aCx, aObj); |
319 | 0 | } |
320 | | |
321 | | static_assert(IsBaseOf<nsISupports, mozilla::dom::SourceBufferList >::value, |
322 | | "We don't support non-nsISupports native classes for " |
323 | | "proxy-based bindings yet"); |
324 | | |
325 | | |
326 | | class DOMProxyHandler : public mozilla::dom::DOMProxyHandler |
327 | | { |
328 | | public: |
329 | | explicit constexpr DOMProxyHandler() |
330 | 0 | { |
331 | 0 | } |
332 | | |
333 | | virtual bool |
334 | | getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const override; |
335 | | |
336 | | virtual bool |
337 | | defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const override; |
338 | | |
339 | | using mozilla::dom::DOMProxyHandler::defineProperty; |
340 | | |
341 | | virtual bool |
342 | | ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const override; |
343 | | |
344 | | virtual bool |
345 | | hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const override; |
346 | | |
347 | | virtual bool |
348 | | get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const override; |
349 | | |
350 | | virtual const char* |
351 | | className(JSContext* cx, JS::Handle<JSObject*> proxy) const override; |
352 | | |
353 | | virtual bool |
354 | | finalizeInBackground(const JS::Value& priv) const override; |
355 | | |
356 | | virtual void |
357 | | finalize(JSFreeOp* fop, JSObject* proxy) const override; |
358 | | |
359 | | static const DOMProxyHandler* |
360 | | getInstance(); |
361 | | |
362 | | virtual bool |
363 | | delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const override; |
364 | | |
365 | | virtual bool |
366 | | getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const override; |
367 | | |
368 | | virtual size_t |
369 | | objectMoved(JSObject* obj, JSObject* old) const override; |
370 | | }; |
371 | | |
372 | | MOZ_ALWAYS_INLINE bool |
373 | | IsProxy(JSObject* obj) |
374 | 0 | { |
375 | 0 | return js::IsProxy(obj) && js::GetProxyHandler(obj) == DOMProxyHandler::getInstance(); |
376 | 0 | } |
377 | | |
378 | | MOZ_ALWAYS_INLINE mozilla::dom::SourceBufferList* |
379 | | UnwrapProxy(JSObject* obj) |
380 | 0 | { |
381 | 0 | MOZ_ASSERT(js::IsProxy(obj)); |
382 | 0 | if (js::GetProxyHandler(obj) != DOMProxyHandler::getInstance()) { |
383 | 0 | MOZ_ASSERT(xpc::WrapperFactory::IsXrayWrapper(obj)); |
384 | 0 | obj = js::UncheckedUnwrap(obj); |
385 | 0 | } |
386 | 0 | MOZ_ASSERT(IsProxy(obj)); |
387 | 0 | return static_cast<mozilla::dom::SourceBufferList*>(js::GetProxyReservedSlot(obj, DOM_OBJECT_SLOT).toPrivate()); |
388 | 0 | } |
389 | | |
390 | | bool |
391 | | DOMProxyHandler::getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const |
392 | 0 | { |
393 | 0 | bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy); |
394 | 0 | uint32_t index = GetArrayIndexFromId(cx, id); |
395 | 0 | if (IsArrayIndex(index)) { |
396 | 0 | mozilla::dom::SourceBufferList* self = UnwrapProxy(proxy); |
397 | 0 | bool found = false; |
398 | 0 | auto result(StrongOrRawPtr<mozilla::dom::SourceBuffer>(self->IndexedGetter(index, found))); |
399 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
400 | 0 |
|
401 | 0 | if (found) { |
402 | 0 | if (!GetOrCreateDOMReflector(cx, result, desc.value())) { |
403 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
404 | 0 | return false; |
405 | 0 | } |
406 | 0 | FillPropertyDescriptor(desc, proxy, true); |
407 | 0 | return true; |
408 | 0 | } |
409 | 0 | } |
410 | 0 |
|
411 | 0 | JS::Rooted<JSObject*> expando(cx); |
412 | 0 | if (!isXray && (expando = GetExpandoObject(proxy))) { |
413 | 0 | if (!JS_GetOwnPropertyDescriptorById(cx, expando, id, desc)) { |
414 | 0 | return false; |
415 | 0 | } |
416 | 0 | if (desc.object()) { |
417 | 0 | // Pretend the property lives on the wrapper. |
418 | 0 | desc.object().set(proxy); |
419 | 0 | return true; |
420 | 0 | } |
421 | 0 | } |
422 | 0 | |
423 | 0 | desc.object().set(nullptr); |
424 | 0 | return true; |
425 | 0 | } |
426 | | |
427 | | bool |
428 | | DOMProxyHandler::defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const |
429 | 0 | { |
430 | 0 | if (IsArrayIndex(GetArrayIndexFromId(cx, id))) { |
431 | 0 | *defined = true; |
432 | 0 | return opresult.failNoIndexedSetter(); |
433 | 0 | } |
434 | 0 | return mozilla::dom::DOMProxyHandler::defineProperty(cx, proxy, id, desc, opresult, defined); |
435 | 0 | } |
436 | | |
437 | | |
438 | | bool |
439 | | DOMProxyHandler::ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const |
440 | 0 | { |
441 | 0 | bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy); |
442 | 0 |
|
443 | 0 | uint32_t length = UnwrapProxy(proxy)->Length(); |
444 | 0 | MOZ_ASSERT(int32_t(length) >= 0); |
445 | 0 | for (int32_t i = 0; i < int32_t(length); ++i) { |
446 | 0 | if (!props.append(INT_TO_JSID(i))) { |
447 | 0 | return false; |
448 | 0 | } |
449 | 0 | } |
450 | 0 |
|
451 | 0 | JS::Rooted<JSObject*> expando(cx); |
452 | 0 | if (!isXray && (expando = DOMProxyHandler::GetExpandoObject(proxy)) && |
453 | 0 | !js::GetPropertyKeys(cx, expando, flags, &props)) { |
454 | 0 | return false; |
455 | 0 | } |
456 | 0 | |
457 | 0 | return true; |
458 | 0 | } |
459 | | |
460 | | bool |
461 | | DOMProxyHandler::hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const |
462 | 0 | { |
463 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
464 | 0 | "Should not have a XrayWrapper here"); |
465 | 0 |
|
466 | 0 | uint32_t index = GetArrayIndexFromId(cx, id); |
467 | 0 | if (IsArrayIndex(index)) { |
468 | 0 | bool found = false; |
469 | 0 | mozilla::dom::SourceBufferList* self = UnwrapProxy(proxy); |
470 | 0 | auto result(StrongOrRawPtr<mozilla::dom::SourceBuffer>(self->IndexedGetter(index, found))); |
471 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
472 | 0 | (void)result; |
473 | 0 |
|
474 | 0 | *bp = found; |
475 | 0 | return true; |
476 | 0 | } |
477 | 0 |
|
478 | 0 |
|
479 | 0 | JS::Rooted<JSObject*> expando(cx, GetExpandoObject(proxy)); |
480 | 0 | if (expando) { |
481 | 0 | bool b = true; |
482 | 0 | bool ok = JS_HasPropertyById(cx, expando, id, &b); |
483 | 0 | *bp = !!b; |
484 | 0 | if (!ok || *bp) { |
485 | 0 | return ok; |
486 | 0 | } |
487 | 0 | } |
488 | 0 | |
489 | 0 | *bp = false; |
490 | 0 | return true; |
491 | 0 | } |
492 | | |
493 | | bool |
494 | | DOMProxyHandler::get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const |
495 | 0 | { |
496 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
497 | 0 | "Should not have a XrayWrapper here"); |
498 | 0 |
|
499 | 0 | uint32_t index = GetArrayIndexFromId(cx, id); |
500 | 0 | if (IsArrayIndex(index)) { |
501 | 0 | mozilla::dom::SourceBufferList* self = UnwrapProxy(proxy); |
502 | 0 | bool found = false; |
503 | 0 | auto result(StrongOrRawPtr<mozilla::dom::SourceBuffer>(self->IndexedGetter(index, found))); |
504 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
505 | 0 |
|
506 | 0 | if (found) { |
507 | 0 | if (!GetOrCreateDOMReflector(cx, result, vp)) { |
508 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
509 | 0 | return false; |
510 | 0 | } |
511 | 0 | return true; |
512 | 0 | } |
513 | 0 | // Even if we don't have this index, we don't forward the |
514 | 0 | // get on to our expando object. |
515 | 0 | } else { |
516 | 0 | { // Scope for expando |
517 | 0 | JS::Rooted<JSObject*> expando(cx, DOMProxyHandler::GetExpandoObject(proxy)); |
518 | 0 | if (expando) { |
519 | 0 | bool hasProp; |
520 | 0 | if (!JS_HasPropertyById(cx, expando, id, &hasProp)) { |
521 | 0 | return false; |
522 | 0 | } |
523 | 0 | |
524 | 0 | if (hasProp) { |
525 | 0 | // Forward the get to the expando object, but our receiver is whatever our |
526 | 0 | // receiver is. |
527 | 0 | return JS_ForwardGetPropertyTo(cx, expando, id, receiver, vp); |
528 | 0 | } |
529 | 0 | } |
530 | 0 | } |
531 | 0 | } |
532 | 0 | |
533 | 0 | bool foundOnPrototype; |
534 | 0 | if (!GetPropertyOnPrototype(cx, proxy, receiver, id, &foundOnPrototype, vp)) { |
535 | 0 | return false; |
536 | 0 | } |
537 | 0 | |
538 | 0 | if (foundOnPrototype) { |
539 | 0 | return true; |
540 | 0 | } |
541 | 0 | |
542 | 0 | vp.setUndefined(); |
543 | 0 | return true; |
544 | 0 | } |
545 | | |
546 | | const char* |
547 | | DOMProxyHandler::className(JSContext* cx, JS::Handle<JSObject*> proxy) const |
548 | 0 | { |
549 | 0 | return "SourceBufferList"; |
550 | 0 | } |
551 | | |
552 | | bool |
553 | | DOMProxyHandler::finalizeInBackground(const JS::Value& priv) const |
554 | 0 | { |
555 | 0 | return false; |
556 | 0 | } |
557 | | |
558 | | void |
559 | | DOMProxyHandler::finalize(JSFreeOp* fop, JSObject* proxy) const |
560 | 0 | { |
561 | 0 | mozilla::dom::SourceBufferList* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SourceBufferList>(proxy); |
562 | 0 | if (self) { |
563 | 0 | ClearWrapper(self, self, proxy); |
564 | 0 | AddForDeferredFinalization<mozilla::dom::SourceBufferList>(self); |
565 | 0 | } |
566 | 0 | } |
567 | | |
568 | | const DOMProxyHandler* |
569 | | DOMProxyHandler::getInstance() |
570 | 0 | { |
571 | 0 | static const DOMProxyHandler instance; |
572 | 0 | return &instance; |
573 | 0 | } |
574 | | |
575 | | bool |
576 | | DOMProxyHandler::delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const |
577 | 0 | { |
578 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
579 | 0 | "Should not have a XrayWrapper here"); |
580 | 0 |
|
581 | 0 | uint32_t index = GetArrayIndexFromId(cx, id); |
582 | 0 | if (IsArrayIndex(index)) { |
583 | 0 | bool deleteSucceeded; |
584 | 0 | bool found = false; |
585 | 0 | mozilla::dom::SourceBufferList* self = UnwrapProxy(proxy); |
586 | 0 | auto result(StrongOrRawPtr<mozilla::dom::SourceBuffer>(self->IndexedGetter(index, found))); |
587 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
588 | 0 | (void)result; |
589 | 0 | deleteSucceeded = !found; |
590 | 0 | return deleteSucceeded ? opresult.succeed() : opresult.failCantDelete(); |
591 | 0 | } |
592 | 0 |
|
593 | 0 | return dom::DOMProxyHandler::delete_(cx, proxy, id, opresult); |
594 | 0 | } |
595 | | |
596 | | bool |
597 | | DOMProxyHandler::getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const |
598 | 0 | { |
599 | 0 | JS::Rooted<JS::Value> temp(cx); |
600 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
601 | 0 | "Should not have a XrayWrapper here"); |
602 | 0 |
|
603 | 0 | mozilla::dom::SourceBufferList* self = UnwrapProxy(proxy); |
604 | 0 | uint32_t length = self->Length(); |
605 | 0 | // Compute the end of the indices we'll get ourselves |
606 | 0 | uint32_t ourEnd = std::max(begin, std::min(end, length)); |
607 | 0 |
|
608 | 0 | for (uint32_t index = begin; index < ourEnd; ++index) { |
609 | 0 | bool found = false; |
610 | 0 | auto result(StrongOrRawPtr<mozilla::dom::SourceBuffer>(self->IndexedGetter(index, found))); |
611 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
612 | 0 |
|
613 | 0 | MOZ_ASSERT(found); |
614 | 0 | if (!GetOrCreateDOMReflector(cx, result, &temp)) { |
615 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
616 | 0 | return false; |
617 | 0 | } |
618 | 0 | if (!adder->append(cx, temp)) return false; |
619 | 0 | continue; |
620 | 0 | } |
621 | 0 |
|
622 | 0 | if (end > ourEnd) { |
623 | 0 | JS::Rooted<JSObject*> proto(cx); |
624 | 0 | if (!js::GetObjectProto(cx, proxy, &proto)) { |
625 | 0 | return false; |
626 | 0 | } |
627 | 0 | return js::GetElementsWithAdder(cx, proto, proxy, ourEnd, end, adder); |
628 | 0 | } |
629 | 0 | |
630 | 0 | return true; |
631 | 0 | } |
632 | | |
633 | | size_t |
634 | | DOMProxyHandler::objectMoved(JSObject* obj, JSObject* old) const |
635 | 0 | { |
636 | 0 | mozilla::dom::SourceBufferList* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SourceBufferList>(obj); |
637 | 0 | if (self) { |
638 | 0 | UpdateWrapper(self, self, obj, old); |
639 | 0 | } |
640 | 0 |
|
641 | 0 | return 0; |
642 | 0 | } |
643 | | |
644 | | static const DOMJSClass sClass = { |
645 | | PROXY_CLASS_DEF("SourceBufferList", |
646 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(1)), |
647 | | { prototypes::id::EventTarget, prototypes::id::SourceBufferList, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
648 | | IsBaseOf<nsISupports, mozilla::dom::SourceBufferList >::value, |
649 | | sNativePropertyHooks, |
650 | | FindAssociatedGlobalForNative<mozilla::dom::SourceBufferList>::Get, |
651 | | GetProtoObjectHandle, |
652 | | GetCCParticipant<mozilla::dom::SourceBufferList>::Get() |
653 | | }; |
654 | | |
655 | | bool |
656 | | Wrap(JSContext* aCx, mozilla::dom::SourceBufferList* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
657 | 0 | { |
658 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::SourceBufferList>::value, |
659 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
660 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::SourceBufferList*>(aObject) == |
661 | 0 | reinterpret_cast<mozilla::dom::SourceBufferList*>(aObject), |
662 | 0 | "Multiple inheritance for mozilla::dom::SourceBufferList is broken."); |
663 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) == |
664 | 0 | reinterpret_cast<mozilla::dom::EventTarget*>(aObject), |
665 | 0 | "Multiple inheritance for mozilla::dom::EventTarget is broken."); |
666 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
667 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
668 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
669 | 0 | "You should probably not be using Wrap() directly; use " |
670 | 0 | "GetOrCreateDOMReflector instead"); |
671 | 0 |
|
672 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
673 | 0 | "nsISupports must be on our primary inheritance chain"); |
674 | 0 |
|
675 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
676 | 0 | if (!global) { |
677 | 0 | return false; |
678 | 0 | } |
679 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
680 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
681 | 0 |
|
682 | 0 | // That might have ended up wrapping us already, due to the wonders |
683 | 0 | // of XBL. Check for that, and bail out as needed. |
684 | 0 | aReflector.set(aCache->GetWrapper()); |
685 | 0 | if (aReflector) { |
686 | | #ifdef DEBUG |
687 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
688 | | #endif // DEBUG |
689 | | return true; |
690 | 0 | } |
691 | 0 |
|
692 | 0 | JSAutoRealm ar(aCx, global); |
693 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
694 | 0 | if (!canonicalProto) { |
695 | 0 | return false; |
696 | 0 | } |
697 | 0 | JS::Rooted<JSObject*> proto(aCx); |
698 | 0 | if (aGivenProto) { |
699 | 0 | proto = aGivenProto; |
700 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
701 | 0 | // coming in, we changed compartments to that of "parent" so may need |
702 | 0 | // to wrap the proto here. |
703 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
704 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
705 | 0 | return false; |
706 | 0 | } |
707 | 0 | } |
708 | 0 | } else { |
709 | 0 | proto = canonicalProto; |
710 | 0 | } |
711 | 0 |
|
712 | 0 | BindingJSObjectCreator<mozilla::dom::SourceBufferList> creator(aCx); |
713 | 0 | creator.CreateProxyObject(aCx, &sClass.mBase, DOMProxyHandler::getInstance(), |
714 | 0 | proto, aObject, JS::UndefinedHandleValue, aReflector); |
715 | 0 | if (!aReflector) { |
716 | 0 | return false; |
717 | 0 | } |
718 | 0 | |
719 | 0 | aCache->SetWrapper(aReflector); |
720 | 0 | creator.InitializationSucceeded(); |
721 | 0 |
|
722 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
723 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
724 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
725 | 0 | // otherwise we won't be able to properly recreate it later, since |
726 | 0 | // we won't know what proto to use. Note that we don't check |
727 | 0 | // aGivenProto here, since it's entirely possible (and even |
728 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
729 | 0 | // same as canonicalProto. |
730 | 0 | if (proto != canonicalProto) { |
731 | 0 | PreserveWrapper(aObject); |
732 | 0 | } |
733 | 0 |
|
734 | 0 | return true; |
735 | 0 | } |
736 | | |
737 | | static bool |
738 | | ResolveOwnProperty(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::MutableHandle<JS::PropertyDescriptor> desc) |
739 | 0 | { |
740 | 0 | return js::GetProxyHandler(obj)->getOwnPropertyDescriptor(cx, wrapper, id, desc); |
741 | 0 | } |
742 | | |
743 | | static bool |
744 | | EnumerateOwnProperties(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::AutoIdVector& props) |
745 | 0 | { |
746 | 0 | return js::GetProxyHandler(obj)->ownPropertyKeys(cx, wrapper, props); |
747 | 0 | } |
748 | | |
749 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
750 | | ResolveOwnProperty, |
751 | | EnumerateOwnProperties, |
752 | | nullptr, |
753 | | { sNativeProperties.Upcast(), nullptr }, |
754 | | prototypes::id::SourceBufferList, |
755 | | constructors::id::SourceBufferList, |
756 | | EventTarget_Binding::sNativePropertyHooks, |
757 | | &DefaultXrayExpandoObjectClass |
758 | | } }; |
759 | | |
760 | | void |
761 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
762 | 0 | { |
763 | 0 | JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx)); |
764 | 0 | if (!parentProto) { |
765 | 0 | return; |
766 | 0 | } |
767 | 0 | |
768 | 0 | JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx)); |
769 | 0 | if (!constructorProto) { |
770 | 0 | return; |
771 | 0 | } |
772 | 0 | |
773 | 0 | static bool sIdsInited = false; |
774 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
775 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
776 | 0 | return; |
777 | 0 | } |
778 | 0 | sIdsInited = true; |
779 | 0 | } |
780 | 0 |
|
781 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::SourceBufferList); |
782 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::SourceBufferList); |
783 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
784 | 0 | &sPrototypeClass.mBase, protoCache, |
785 | 0 | nullptr, |
786 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
787 | 0 | interfaceCache, |
788 | 0 | sNativeProperties.Upcast(), |
789 | 0 | nullptr, |
790 | 0 | "SourceBufferList", aDefineOnGlobal, |
791 | 0 | nullptr, |
792 | 0 | false); |
793 | 0 | } |
794 | | |
795 | | JSObject* |
796 | | GetConstructorObject(JSContext* aCx) |
797 | 0 | { |
798 | 0 | return GetConstructorObjectHandle(aCx); |
799 | 0 | } |
800 | | |
801 | | } // namespace SourceBufferList_Binding |
802 | | |
803 | | |
804 | | |
805 | | } // namespace dom |
806 | | } // namespace mozilla |