/work/obj-fuzz/dom/bindings/DOMStringMapBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM DOMStringMap.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "DOMStringMapBinding.h" |
4 | | #include "WrapperFactory.h" |
5 | | #include "mozilla/OwningNonNull.h" |
6 | | #include "mozilla/dom/BindingUtils.h" |
7 | | #include "mozilla/dom/CustomElementRegistry.h" |
8 | | #include "mozilla/dom/DOMJSClass.h" |
9 | | #include "mozilla/dom/DOMJSProxyHandler.h" |
10 | | #include "mozilla/dom/DocGroup.h" |
11 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
12 | | #include "mozilla/dom/XrayExpandoClass.h" |
13 | | #include "nsDOMStringMap.h" |
14 | | |
15 | | namespace mozilla { |
16 | | namespace dom { |
17 | | |
18 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
19 | | using namespace mozilla::dom::binding_detail; |
20 | | |
21 | | |
22 | | namespace DOMStringMap_Binding { |
23 | | |
24 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
25 | | { |
26 | | "Function", |
27 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
28 | | &sBoringInterfaceObjectClassClassOps, |
29 | | JS_NULL_CLASS_SPEC, |
30 | | JS_NULL_CLASS_EXT, |
31 | | &sInterfaceObjectClassObjectOps |
32 | | }, |
33 | | eInterface, |
34 | | true, |
35 | | prototypes::id::DOMStringMap, |
36 | | PrototypeTraits<prototypes::id::DOMStringMap>::Depth, |
37 | | sNativePropertyHooks, |
38 | | "function DOMStringMap() {\n [native code]\n}", |
39 | | JS::GetRealmFunctionPrototype |
40 | | }; |
41 | | |
42 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
43 | | { |
44 | | "DOMStringMapPrototype", |
45 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
46 | | JS_NULL_CLASS_OPS, |
47 | | JS_NULL_CLASS_SPEC, |
48 | | JS_NULL_CLASS_EXT, |
49 | | JS_NULL_OBJECT_OPS |
50 | | }, |
51 | | eInterfacePrototype, |
52 | | false, |
53 | | prototypes::id::DOMStringMap, |
54 | | PrototypeTraits<prototypes::id::DOMStringMap>::Depth, |
55 | | sNativePropertyHooks, |
56 | | "[object DOMStringMapPrototype]", |
57 | | JS::GetRealmObjectPrototype |
58 | | }; |
59 | | |
60 | | static_assert(IsBaseOf<nsISupports, nsDOMStringMap >::value, |
61 | | "We don't support non-nsISupports native classes for " |
62 | | "proxy-based bindings yet"); |
63 | | |
64 | | |
65 | | class DOMProxyHandler : public ShadowingDOMProxyHandler |
66 | | { |
67 | | public: |
68 | | explicit constexpr DOMProxyHandler() |
69 | 0 | { |
70 | 0 | } |
71 | | |
72 | | virtual bool |
73 | | getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const override; |
74 | | |
75 | | virtual bool |
76 | | defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const override; |
77 | | |
78 | | using mozilla::dom::DOMProxyHandler::defineProperty; |
79 | | |
80 | | virtual bool |
81 | | ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const override; |
82 | | |
83 | | virtual bool |
84 | | hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const override; |
85 | | |
86 | | virtual bool |
87 | | get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const override; |
88 | | |
89 | | virtual const char* |
90 | | className(JSContext* cx, JS::Handle<JSObject*> proxy) const override; |
91 | | |
92 | | virtual bool |
93 | | finalizeInBackground(const JS::Value& priv) const override; |
94 | | |
95 | | virtual void |
96 | | finalize(JSFreeOp* fop, JSObject* proxy) const override; |
97 | | |
98 | | static const DOMProxyHandler* |
99 | | getInstance(); |
100 | | |
101 | | virtual bool |
102 | | delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const override; |
103 | | |
104 | | virtual bool |
105 | | setCustom(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::Value> v, bool* done) const override; |
106 | | |
107 | | virtual size_t |
108 | | objectMoved(JSObject* obj, JSObject* old) const override; |
109 | | }; |
110 | | |
111 | | MOZ_ALWAYS_INLINE bool |
112 | | IsProxy(JSObject* obj) |
113 | 0 | { |
114 | 0 | return js::IsProxy(obj) && js::GetProxyHandler(obj) == DOMProxyHandler::getInstance(); |
115 | 0 | } |
116 | | |
117 | | MOZ_ALWAYS_INLINE nsDOMStringMap* |
118 | | UnwrapProxy(JSObject* obj) |
119 | 0 | { |
120 | 0 | MOZ_ASSERT(js::IsProxy(obj)); |
121 | 0 | if (js::GetProxyHandler(obj) != DOMProxyHandler::getInstance()) { |
122 | 0 | MOZ_ASSERT(xpc::WrapperFactory::IsXrayWrapper(obj)); |
123 | 0 | obj = js::UncheckedUnwrap(obj); |
124 | 0 | } |
125 | 0 | MOZ_ASSERT(IsProxy(obj)); |
126 | 0 | return static_cast<nsDOMStringMap*>(js::GetProxyReservedSlot(obj, DOM_OBJECT_SLOT).toPrivate()); |
127 | 0 | } |
128 | | |
129 | | bool |
130 | | DOMProxyHandler::getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const |
131 | 0 | { |
132 | 0 | bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy); |
133 | 0 | JS::Rooted<JSObject*> expando(cx); |
134 | 0 | if (!isXray && (expando = GetExpandoObject(proxy))) { |
135 | 0 | if (!JS_GetOwnPropertyDescriptorById(cx, expando, id, desc)) { |
136 | 0 | return false; |
137 | 0 | } |
138 | 0 | if (desc.object()) { |
139 | 0 | // Pretend the property lives on the wrapper. |
140 | 0 | desc.object().set(proxy); |
141 | 0 | return true; |
142 | 0 | } |
143 | 0 | } |
144 | 0 | |
145 | 0 | bool callNamedGetter = false; |
146 | 0 | if (!ignoreNamedProps) { |
147 | 0 | if (!isXray) { |
148 | 0 | callNamedGetter = true; |
149 | 0 | } else { |
150 | 0 | bool hasOnProto; |
151 | 0 | if (!HasPropertyOnPrototype(cx, proxy, id, &hasOnProto)) { |
152 | 0 | return false; |
153 | 0 | } |
154 | 0 | callNamedGetter = !hasOnProto; |
155 | 0 | } |
156 | 0 | } |
157 | 0 | if (callNamedGetter) { |
158 | 0 | FakeString name; |
159 | 0 | bool isSymbol; |
160 | 0 | if (!ConvertIdToString(cx, id, name, isSymbol)) { |
161 | 0 | return false; |
162 | 0 | } |
163 | 0 | if (!isSymbol) { |
164 | 0 | nsDOMStringMap* self = UnwrapProxy(proxy); |
165 | 0 | bool found = false; |
166 | 0 | DOMString result; |
167 | 0 | self->NamedGetter(NonNullHelper(Constify(name)), found, result); |
168 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
169 | 0 |
|
170 | 0 | if (found) { |
171 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, desc.value())) { |
172 | 0 | return false; |
173 | 0 | } |
174 | 0 | FillPropertyDescriptor(desc, proxy, false, true); |
175 | 0 | return true; |
176 | 0 | } |
177 | 0 | } |
178 | 0 | } |
179 | 0 |
|
180 | 0 | desc.object().set(nullptr); |
181 | 0 | return true; |
182 | 0 | } |
183 | | |
184 | | bool |
185 | | DOMProxyHandler::defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const |
186 | 0 | { |
187 | 0 | *defined = true; |
188 | 0 | FakeString name; |
189 | 0 | bool isSymbol; |
190 | 0 | if (!ConvertIdToString(cx, id, name, isSymbol)) { |
191 | 0 | return false; |
192 | 0 | } |
193 | 0 | if (!isSymbol) { |
194 | 0 | nsDOMStringMap* self = UnwrapProxy(proxy); |
195 | 0 | JS::Rooted<JS::Value> rootedValue(cx, desc.value()); |
196 | 0 | binding_detail::FakeString value; |
197 | 0 | if (!ConvertJSValueToString(cx, desc.value(), eStringify, eStringify, value)) { |
198 | 0 | return false; |
199 | 0 | } |
200 | 0 | Maybe<AutoCEReaction> ceReaction; |
201 | 0 | if (CustomElementRegistry::IsCustomElementEnabled(cx, proxy)) { |
202 | 0 | DocGroup* docGroup = self->GetDocGroup(); |
203 | 0 | if (docGroup) { |
204 | 0 | ceReaction.emplace(docGroup->CustomElementReactionsStack(), cx); |
205 | 0 | } |
206 | 0 | } |
207 | 0 | FastErrorResult rv; |
208 | 0 | self->NamedSetter(NonNullHelper(Constify(name)), NonNullHelper(Constify(value)), rv); |
209 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
210 | 0 | return false; |
211 | 0 | } |
212 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
213 | 0 | } |
214 | 0 |
|
215 | 0 | return opresult.succeed(); |
216 | 0 | } |
217 | | |
218 | | |
219 | | bool |
220 | | DOMProxyHandler::ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const |
221 | 0 | { |
222 | 0 | bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy); |
223 | 0 |
|
224 | 0 | nsTArray<nsString> names; |
225 | 0 | UnwrapProxy(proxy)->GetSupportedNames(names); |
226 | 0 | if (!AppendNamedPropertyIds(cx, proxy, names, !isXray, props)) { |
227 | 0 | return false; |
228 | 0 | } |
229 | 0 | |
230 | 0 | JS::Rooted<JSObject*> expando(cx); |
231 | 0 | if (!isXray && (expando = DOMProxyHandler::GetExpandoObject(proxy)) && |
232 | 0 | !js::GetPropertyKeys(cx, expando, flags, &props)) { |
233 | 0 | return false; |
234 | 0 | } |
235 | 0 | |
236 | 0 | return true; |
237 | 0 | } |
238 | | |
239 | | bool |
240 | | DOMProxyHandler::hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const |
241 | 0 | { |
242 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
243 | 0 | "Should not have a XrayWrapper here"); |
244 | 0 |
|
245 | 0 |
|
246 | 0 | JS::Rooted<JSObject*> expando(cx, GetExpandoObject(proxy)); |
247 | 0 | if (expando) { |
248 | 0 | bool b = true; |
249 | 0 | bool ok = JS_HasPropertyById(cx, expando, id, &b); |
250 | 0 | *bp = !!b; |
251 | 0 | if (!ok || *bp) { |
252 | 0 | return ok; |
253 | 0 | } |
254 | 0 | } |
255 | 0 | |
256 | 0 | bool found = false; |
257 | 0 | FakeString name; |
258 | 0 | bool isSymbol; |
259 | 0 | if (!ConvertIdToString(cx, id, name, isSymbol)) { |
260 | 0 | return false; |
261 | 0 | } |
262 | 0 | if (!isSymbol) { |
263 | 0 | nsDOMStringMap* self = UnwrapProxy(proxy); |
264 | 0 | DOMString result; |
265 | 0 | self->NamedGetter(NonNullHelper(Constify(name)), found, result); |
266 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
267 | 0 | (void)result; |
268 | 0 | } |
269 | 0 |
|
270 | 0 | *bp = found; |
271 | 0 |
|
272 | 0 | return true; |
273 | 0 | } |
274 | | |
275 | | bool |
276 | | DOMProxyHandler::get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const |
277 | 0 | { |
278 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
279 | 0 | "Should not have a XrayWrapper here"); |
280 | 0 |
|
281 | 0 | { // Scope for expando |
282 | 0 | JS::Rooted<JSObject*> expando(cx, DOMProxyHandler::GetExpandoObject(proxy)); |
283 | 0 | if (expando) { |
284 | 0 | bool hasProp; |
285 | 0 | if (!JS_HasPropertyById(cx, expando, id, &hasProp)) { |
286 | 0 | return false; |
287 | 0 | } |
288 | 0 | |
289 | 0 | if (hasProp) { |
290 | 0 | // Forward the get to the expando object, but our receiver is whatever our |
291 | 0 | // receiver is. |
292 | 0 | return JS_ForwardGetPropertyTo(cx, expando, id, receiver, vp); |
293 | 0 | } |
294 | 0 | } |
295 | 0 | } |
296 | 0 | |
297 | 0 | FakeString name; |
298 | 0 | bool isSymbol; |
299 | 0 | if (!ConvertIdToString(cx, id, name, isSymbol)) { |
300 | 0 | return false; |
301 | 0 | } |
302 | 0 | if (!isSymbol) { |
303 | 0 | nsDOMStringMap* self = UnwrapProxy(proxy); |
304 | 0 | bool found = false; |
305 | 0 | DOMString result; |
306 | 0 | self->NamedGetter(NonNullHelper(Constify(name)), found, result); |
307 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
308 | 0 |
|
309 | 0 | if (found) { |
310 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, vp)) { |
311 | 0 | return false; |
312 | 0 | } |
313 | 0 | return true; |
314 | 0 | } |
315 | 0 | } |
316 | 0 |
|
317 | 0 | bool foundOnPrototype; |
318 | 0 | if (!GetPropertyOnPrototype(cx, proxy, receiver, id, &foundOnPrototype, vp)) { |
319 | 0 | return false; |
320 | 0 | } |
321 | 0 | |
322 | 0 | if (foundOnPrototype) { |
323 | 0 | return true; |
324 | 0 | } |
325 | 0 | |
326 | 0 | vp.setUndefined(); |
327 | 0 | return true; |
328 | 0 | } |
329 | | |
330 | | const char* |
331 | | DOMProxyHandler::className(JSContext* cx, JS::Handle<JSObject*> proxy) const |
332 | 0 | { |
333 | 0 | return "DOMStringMap"; |
334 | 0 | } |
335 | | |
336 | | bool |
337 | | DOMProxyHandler::finalizeInBackground(const JS::Value& priv) const |
338 | 0 | { |
339 | 0 | return false; |
340 | 0 | } |
341 | | |
342 | | void |
343 | | DOMProxyHandler::finalize(JSFreeOp* fop, JSObject* proxy) const |
344 | 0 | { |
345 | 0 | nsDOMStringMap* self = UnwrapPossiblyNotInitializedDOMObject<nsDOMStringMap>(proxy); |
346 | 0 | if (self) { |
347 | 0 | // Either our proxy created an expando object or not. If it did, |
348 | 0 | // then we would have preserved ourselves, and hence if we're going |
349 | 0 | // away so is our C++ object and we should reset its expando value. |
350 | 0 | // It's possible that in this situation the C++ object's reflector |
351 | 0 | // pointer has been nulled out, but if not it's pointing to us. If |
352 | 0 | // our proxy did _not_ create an expando object then it's possible |
353 | 0 | // that we're no longer the reflector for our C++ object (and |
354 | 0 | // incremental finalization is finally getting to us), and that in |
355 | 0 | // the meantime the new reflector has created an expando object. |
356 | 0 | // In that case we do NOT want to clear the expando pointer in the |
357 | 0 | // C++ object. |
358 | 0 | // |
359 | 0 | // It's important to do this before we ClearWrapper, of course. |
360 | 0 | JSObject* reflector = self->GetWrapperMaybeDead(); |
361 | 0 | if (!reflector || reflector == proxy) { |
362 | 0 | self->mExpandoAndGeneration.expando = JS::UndefinedValue(); |
363 | 0 | } |
364 | 0 | ClearWrapper(self, self, proxy); |
365 | 0 | AddForDeferredFinalization<nsDOMStringMap>(self); |
366 | 0 | } |
367 | 0 | } |
368 | | |
369 | | const DOMProxyHandler* |
370 | | DOMProxyHandler::getInstance() |
371 | 0 | { |
372 | 0 | static const DOMProxyHandler instance; |
373 | 0 | return &instance; |
374 | 0 | } |
375 | | |
376 | | bool |
377 | | DOMProxyHandler::delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const |
378 | 0 | { |
379 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
380 | 0 | "Should not have a XrayWrapper here"); |
381 | 0 |
|
382 | 0 | // Try named delete only if the named property visibility |
383 | 0 | // algorithm says the property is visible. |
384 | 0 | bool tryNamedDelete = true; |
385 | 0 | { // Scope for expando |
386 | 0 | JS::Rooted<JSObject*> expando(cx, DOMProxyHandler::GetExpandoObject(proxy)); |
387 | 0 | if (expando) { |
388 | 0 | bool hasProp; |
389 | 0 | if (!JS_HasPropertyById(cx, expando, id, &hasProp)) { |
390 | 0 | return false; |
391 | 0 | } |
392 | 0 | tryNamedDelete = !hasProp; |
393 | 0 | } |
394 | 0 | } |
395 | 0 | if (tryNamedDelete) { |
396 | 0 | bool found = false; |
397 | 0 | bool deleteSucceeded; |
398 | 0 | FakeString name; |
399 | 0 | bool isSymbol; |
400 | 0 | if (!ConvertIdToString(cx, id, name, isSymbol)) { |
401 | 0 | return false; |
402 | 0 | } |
403 | 0 | if (!isSymbol) { |
404 | 0 | nsDOMStringMap* self = UnwrapProxy(proxy); |
405 | 0 | Maybe<AutoCEReaction> ceReaction; |
406 | 0 | if (CustomElementRegistry::IsCustomElementEnabled(cx, proxy)) { |
407 | 0 | DocGroup* docGroup = self->GetDocGroup(); |
408 | 0 | if (docGroup) { |
409 | 0 | ceReaction.emplace(docGroup->CustomElementReactionsStack(), cx); |
410 | 0 | } |
411 | 0 | } |
412 | 0 | self->NamedDeleter(NonNullHelper(Constify(name)), found); |
413 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
414 | 0 | } |
415 | 0 | deleteSucceeded = true; |
416 | 0 | if (found) { |
417 | 0 | return deleteSucceeded ? opresult.succeed() : opresult.failCantDelete(); |
418 | 0 | } |
419 | 0 | } |
420 | 0 |
|
421 | 0 | return dom::DOMProxyHandler::delete_(cx, proxy, id, opresult); |
422 | 0 | } |
423 | | |
424 | | bool |
425 | | DOMProxyHandler::setCustom(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::Value> v, bool* done) const |
426 | 0 | { |
427 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
428 | 0 | "Should not have a XrayWrapper here"); |
429 | 0 | FakeString name; |
430 | 0 | bool isSymbol; |
431 | 0 | if (!ConvertIdToString(cx, id, name, isSymbol)) { |
432 | 0 | return false; |
433 | 0 | } |
434 | 0 | if (!isSymbol) { |
435 | 0 | nsDOMStringMap* self = UnwrapProxy(proxy); |
436 | 0 | JS::Rooted<JS::Value> rootedValue(cx, v); |
437 | 0 | binding_detail::FakeString value; |
438 | 0 | if (!ConvertJSValueToString(cx, v, eStringify, eStringify, value)) { |
439 | 0 | return false; |
440 | 0 | } |
441 | 0 | Maybe<AutoCEReaction> ceReaction; |
442 | 0 | if (CustomElementRegistry::IsCustomElementEnabled(cx, proxy)) { |
443 | 0 | DocGroup* docGroup = self->GetDocGroup(); |
444 | 0 | if (docGroup) { |
445 | 0 | ceReaction.emplace(docGroup->CustomElementReactionsStack(), cx); |
446 | 0 | } |
447 | 0 | } |
448 | 0 | FastErrorResult rv; |
449 | 0 | self->NamedSetter(NonNullHelper(Constify(name)), NonNullHelper(Constify(value)), rv); |
450 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
451 | 0 | return false; |
452 | 0 | } |
453 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
454 | 0 | } |
455 | 0 | *done = true; |
456 | 0 | return true; |
457 | 0 | } |
458 | | |
459 | | size_t |
460 | | DOMProxyHandler::objectMoved(JSObject* obj, JSObject* old) const |
461 | 0 | { |
462 | 0 | nsDOMStringMap* self = UnwrapPossiblyNotInitializedDOMObject<nsDOMStringMap>(obj); |
463 | 0 | if (self) { |
464 | 0 | UpdateWrapper(self, self, obj, old); |
465 | 0 | } |
466 | 0 |
|
467 | 0 | return 0; |
468 | 0 | } |
469 | | |
470 | | static const DOMJSClass sClass = { |
471 | | PROXY_CLASS_DEF("DOMStringMap", |
472 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(1)), |
473 | | { prototypes::id::DOMStringMap, 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 }, |
474 | | IsBaseOf<nsISupports, nsDOMStringMap >::value, |
475 | | sNativePropertyHooks, |
476 | | FindAssociatedGlobalForNative<nsDOMStringMap>::Get, |
477 | | GetProtoObjectHandle, |
478 | | GetCCParticipant<nsDOMStringMap>::Get() |
479 | | }; |
480 | | |
481 | | bool |
482 | | Wrap(JSContext* aCx, nsDOMStringMap* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
483 | 0 | { |
484 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, nsDOMStringMap>::value, |
485 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
486 | 0 | MOZ_ASSERT(static_cast<nsDOMStringMap*>(aObject) == |
487 | 0 | reinterpret_cast<nsDOMStringMap*>(aObject), |
488 | 0 | "Multiple inheritance for nsDOMStringMap is broken."); |
489 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
490 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
491 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
492 | 0 | "You should probably not be using Wrap() directly; use " |
493 | 0 | "GetOrCreateDOMReflector instead"); |
494 | 0 |
|
495 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
496 | 0 | "nsISupports must be on our primary inheritance chain"); |
497 | 0 |
|
498 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
499 | 0 | if (!global) { |
500 | 0 | return false; |
501 | 0 | } |
502 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
503 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
504 | 0 |
|
505 | 0 | // That might have ended up wrapping us already, due to the wonders |
506 | 0 | // of XBL. Check for that, and bail out as needed. |
507 | 0 | aReflector.set(aCache->GetWrapper()); |
508 | 0 | if (aReflector) { |
509 | | #ifdef DEBUG |
510 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
511 | | #endif // DEBUG |
512 | | return true; |
513 | 0 | } |
514 | 0 |
|
515 | 0 | JSAutoRealm ar(aCx, global); |
516 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
517 | 0 | if (!canonicalProto) { |
518 | 0 | return false; |
519 | 0 | } |
520 | 0 | JS::Rooted<JSObject*> proto(aCx); |
521 | 0 | if (aGivenProto) { |
522 | 0 | proto = aGivenProto; |
523 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
524 | 0 | // coming in, we changed compartments to that of "parent" so may need |
525 | 0 | // to wrap the proto here. |
526 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
527 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
528 | 0 | return false; |
529 | 0 | } |
530 | 0 | } |
531 | 0 | } else { |
532 | 0 | proto = canonicalProto; |
533 | 0 | } |
534 | 0 |
|
535 | 0 | BindingJSObjectCreator<nsDOMStringMap> creator(aCx); |
536 | 0 | aObject->mExpandoAndGeneration.expando.setUndefined(); |
537 | 0 | JS::Rooted<JS::Value> expandoValue(aCx, JS::PrivateValue(&aObject->mExpandoAndGeneration)); |
538 | 0 | creator.CreateProxyObject(aCx, &sClass.mBase, DOMProxyHandler::getInstance(), |
539 | 0 | proto, aObject, expandoValue, aReflector); |
540 | 0 | if (!aReflector) { |
541 | 0 | return false; |
542 | 0 | } |
543 | 0 | |
544 | 0 | aCache->SetWrapper(aReflector); |
545 | 0 | creator.InitializationSucceeded(); |
546 | 0 |
|
547 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
548 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
549 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
550 | 0 | // otherwise we won't be able to properly recreate it later, since |
551 | 0 | // we won't know what proto to use. Note that we don't check |
552 | 0 | // aGivenProto here, since it's entirely possible (and even |
553 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
554 | 0 | // same as canonicalProto. |
555 | 0 | if (proto != canonicalProto) { |
556 | 0 | PreserveWrapper(aObject); |
557 | 0 | } |
558 | 0 |
|
559 | 0 | return true; |
560 | 0 | } |
561 | | |
562 | | static bool |
563 | | ResolveOwnProperty(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::MutableHandle<JS::PropertyDescriptor> desc) |
564 | 0 | { |
565 | 0 | return js::GetProxyHandler(obj)->getOwnPropertyDescriptor(cx, wrapper, id, desc); |
566 | 0 | } |
567 | | |
568 | | static bool |
569 | | EnumerateOwnProperties(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::AutoIdVector& props) |
570 | 0 | { |
571 | 0 | return js::GetProxyHandler(obj)->ownPropertyKeys(cx, wrapper, props); |
572 | 0 | } |
573 | | |
574 | | static bool |
575 | | DeleteNamedProperty(JSContext* cx, JS::Handle<JSObject*> xray, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) |
576 | 0 | { |
577 | 0 | MOZ_ASSERT(xpc::WrapperFactory::IsXrayWrapper(xray)); |
578 | 0 | MOZ_ASSERT(js::IsProxy(proxy)); |
579 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy)); |
580 | 0 | JSAutoRealm ar(cx, proxy); |
581 | 0 | bool deleteSucceeded = false; |
582 | 0 | bool found = false; |
583 | 0 | FakeString name; |
584 | 0 | bool isSymbol; |
585 | 0 | if (!ConvertIdToString(cx, id, name, isSymbol)) { |
586 | 0 | return false; |
587 | 0 | } |
588 | 0 | if (!isSymbol) { |
589 | 0 | nsDOMStringMap* self = UnwrapProxy(proxy); |
590 | 0 | Maybe<AutoCEReaction> ceReaction; |
591 | 0 | if (CustomElementRegistry::IsCustomElementEnabled(cx, proxy)) { |
592 | 0 | DocGroup* docGroup = self->GetDocGroup(); |
593 | 0 | if (docGroup) { |
594 | 0 | ceReaction.emplace(docGroup->CustomElementReactionsStack(), cx); |
595 | 0 | } |
596 | 0 | } |
597 | 0 | self->NamedDeleter(NonNullHelper(Constify(name)), found); |
598 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
599 | 0 | } |
600 | 0 | deleteSucceeded = true; |
601 | 0 | if (!found || deleteSucceeded) { |
602 | 0 | return opresult.succeed(); |
603 | 0 | } |
604 | 0 | return opresult.failCantDelete(); |
605 | 0 | } |
606 | | |
607 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
608 | | ResolveOwnProperty, |
609 | | EnumerateOwnProperties, |
610 | | DeleteNamedProperty, |
611 | | { nullptr, nullptr }, |
612 | | prototypes::id::DOMStringMap, |
613 | | constructors::id::DOMStringMap, |
614 | | nullptr, |
615 | | &DefaultXrayExpandoObjectClass |
616 | | } }; |
617 | | |
618 | | void |
619 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
620 | 0 | { |
621 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
622 | 0 | if (!parentProto) { |
623 | 0 | return; |
624 | 0 | } |
625 | 0 | |
626 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
627 | 0 | if (!constructorProto) { |
628 | 0 | return; |
629 | 0 | } |
630 | 0 | |
631 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::DOMStringMap); |
632 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::DOMStringMap); |
633 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
634 | 0 | &sPrototypeClass.mBase, protoCache, |
635 | 0 | nullptr, |
636 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
637 | 0 | interfaceCache, |
638 | 0 | nullptr, |
639 | 0 | nullptr, |
640 | 0 | "DOMStringMap", aDefineOnGlobal, |
641 | 0 | nullptr, |
642 | 0 | false); |
643 | 0 | } |
644 | | |
645 | | JSObject* |
646 | | GetConstructorObject(JSContext* aCx) |
647 | 0 | { |
648 | 0 | return GetConstructorObjectHandle(aCx); |
649 | 0 | } |
650 | | |
651 | | } // namespace DOMStringMap_Binding |
652 | | |
653 | | |
654 | | |
655 | | } // namespace dom |
656 | | } // namespace mozilla |