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