/work/obj-fuzz/dom/bindings/PluginBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM Plugin.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "PluginBinding.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/NonRefcountedDOMObject.h" |
10 | | #include "mozilla/dom/Nullable.h" |
11 | | #include "mozilla/dom/PrimitiveConversions.h" |
12 | | #include "mozilla/dom/XrayExpandoClass.h" |
13 | | #include "nsMimeTypeArray.h" |
14 | | #include "nsPluginArray.h" |
15 | | |
16 | | namespace mozilla { |
17 | | namespace dom { |
18 | | |
19 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
20 | | using namespace mozilla::dom::binding_detail; |
21 | | |
22 | | |
23 | | namespace Plugin_Binding { |
24 | | |
25 | | MOZ_CAN_RUN_SCRIPT static bool |
26 | | get_description(JSContext* cx, JS::Handle<JSObject*> obj, nsPluginElement* self, JSJitGetterCallArgs args) |
27 | 0 | { |
28 | 0 | AUTO_PROFILER_LABEL_FAST("get Plugin.description", DOM, cx); |
29 | 0 |
|
30 | 0 | DOMString result; |
31 | 0 | self->GetDescription(result); |
32 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
33 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
34 | 0 | return false; |
35 | 0 | } |
36 | 0 | return true; |
37 | 0 | } |
38 | | |
39 | | static const JSJitInfo description_getterinfo = { |
40 | | { (JSJitGetterOp)get_description }, |
41 | | { prototypes::id::Plugin }, |
42 | | { PrototypeTraits<prototypes::id::Plugin>::Depth }, |
43 | | JSJitInfo::Getter, |
44 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
45 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
46 | | false, /* isInfallible. False in setters. */ |
47 | | false, /* isMovable. Not relevant for setters. */ |
48 | | false, /* isEliminatable. Not relevant for setters. */ |
49 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
50 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
51 | | false, /* isTypedMethod. Only relevant for methods. */ |
52 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
53 | | }; |
54 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
55 | | static_assert(0 < 1, "There is no slot for us"); |
56 | | |
57 | | MOZ_CAN_RUN_SCRIPT static bool |
58 | | get_filename(JSContext* cx, JS::Handle<JSObject*> obj, nsPluginElement* self, JSJitGetterCallArgs args) |
59 | 0 | { |
60 | 0 | AUTO_PROFILER_LABEL_FAST("get Plugin.filename", DOM, cx); |
61 | 0 |
|
62 | 0 | DOMString result; |
63 | 0 | self->GetFilename(result); |
64 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
65 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
66 | 0 | return false; |
67 | 0 | } |
68 | 0 | return true; |
69 | 0 | } |
70 | | |
71 | | static const JSJitInfo filename_getterinfo = { |
72 | | { (JSJitGetterOp)get_filename }, |
73 | | { prototypes::id::Plugin }, |
74 | | { PrototypeTraits<prototypes::id::Plugin>::Depth }, |
75 | | JSJitInfo::Getter, |
76 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
77 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
78 | | false, /* isInfallible. False in setters. */ |
79 | | false, /* isMovable. Not relevant for setters. */ |
80 | | false, /* isEliminatable. Not relevant for setters. */ |
81 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
82 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
83 | | false, /* isTypedMethod. Only relevant for methods. */ |
84 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
85 | | }; |
86 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
87 | | static_assert(0 < 1, "There is no slot for us"); |
88 | | |
89 | | MOZ_CAN_RUN_SCRIPT static bool |
90 | | get_version(JSContext* cx, JS::Handle<JSObject*> obj, nsPluginElement* self, JSJitGetterCallArgs args) |
91 | 0 | { |
92 | 0 | AUTO_PROFILER_LABEL_FAST("get Plugin.version", DOM, cx); |
93 | 0 |
|
94 | 0 | DOMString result; |
95 | 0 | self->GetVersion(result); |
96 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
97 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
98 | 0 | return false; |
99 | 0 | } |
100 | 0 | return true; |
101 | 0 | } |
102 | | |
103 | | static const JSJitInfo version_getterinfo = { |
104 | | { (JSJitGetterOp)get_version }, |
105 | | { prototypes::id::Plugin }, |
106 | | { PrototypeTraits<prototypes::id::Plugin>::Depth }, |
107 | | JSJitInfo::Getter, |
108 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
109 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
110 | | false, /* isInfallible. False in setters. */ |
111 | | false, /* isMovable. Not relevant for setters. */ |
112 | | false, /* isEliminatable. Not relevant for setters. */ |
113 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
114 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
115 | | false, /* isTypedMethod. Only relevant for methods. */ |
116 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
117 | | }; |
118 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
119 | | static_assert(0 < 1, "There is no slot for us"); |
120 | | |
121 | | MOZ_CAN_RUN_SCRIPT static bool |
122 | | get_name(JSContext* cx, JS::Handle<JSObject*> obj, nsPluginElement* self, JSJitGetterCallArgs args) |
123 | 0 | { |
124 | 0 | AUTO_PROFILER_LABEL_FAST("get Plugin.name", DOM, cx); |
125 | 0 |
|
126 | 0 | DOMString result; |
127 | 0 | self->GetName(result); |
128 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
129 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
130 | 0 | return false; |
131 | 0 | } |
132 | 0 | return true; |
133 | 0 | } |
134 | | |
135 | | static const JSJitInfo name_getterinfo = { |
136 | | { (JSJitGetterOp)get_name }, |
137 | | { prototypes::id::Plugin }, |
138 | | { PrototypeTraits<prototypes::id::Plugin>::Depth }, |
139 | | JSJitInfo::Getter, |
140 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
141 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
142 | | false, /* isInfallible. False in setters. */ |
143 | | false, /* isMovable. Not relevant for setters. */ |
144 | | false, /* isEliminatable. Not relevant for setters. */ |
145 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
146 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
147 | | false, /* isTypedMethod. Only relevant for methods. */ |
148 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
149 | | }; |
150 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
151 | | static_assert(0 < 1, "There is no slot for us"); |
152 | | |
153 | | MOZ_CAN_RUN_SCRIPT static bool |
154 | | get_length(JSContext* cx, JS::Handle<JSObject*> obj, nsPluginElement* self, JSJitGetterCallArgs args) |
155 | 0 | { |
156 | 0 | AUTO_PROFILER_LABEL_FAST("get Plugin.length", DOM, cx); |
157 | 0 |
|
158 | 0 | uint32_t result(self->Length()); |
159 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
160 | 0 | args.rval().setNumber(result); |
161 | 0 | return true; |
162 | 0 | } |
163 | | |
164 | | static const JSJitInfo length_getterinfo = { |
165 | | { (JSJitGetterOp)get_length }, |
166 | | { prototypes::id::Plugin }, |
167 | | { PrototypeTraits<prototypes::id::Plugin>::Depth }, |
168 | | JSJitInfo::Getter, |
169 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
170 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
171 | | true, /* isInfallible. False in setters. */ |
172 | | false, /* isMovable. Not relevant for setters. */ |
173 | | false, /* isEliminatable. Not relevant for setters. */ |
174 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
175 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
176 | | false, /* isTypedMethod. Only relevant for methods. */ |
177 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
178 | | }; |
179 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
180 | | static_assert(0 < 1, "There is no slot for us"); |
181 | | |
182 | | MOZ_CAN_RUN_SCRIPT static bool |
183 | | item(JSContext* cx, JS::Handle<JSObject*> obj, nsPluginElement* self, const JSJitMethodCallArgs& args) |
184 | 0 | { |
185 | 0 | AUTO_PROFILER_LABEL_FAST("Plugin.item", DOM, cx); |
186 | 0 |
|
187 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
188 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Plugin.item"); |
189 | 0 | } |
190 | 0 | uint32_t arg0; |
191 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) { |
192 | 0 | return false; |
193 | 0 | } |
194 | 0 | auto result(StrongOrRawPtr<nsMimeType>(self->Item(arg0))); |
195 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
196 | 0 | if (!result) { |
197 | 0 | args.rval().setNull(); |
198 | 0 | return true; |
199 | 0 | } |
200 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
201 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
202 | 0 | return false; |
203 | 0 | } |
204 | 0 | return true; |
205 | 0 | } |
206 | | |
207 | | static const JSJitInfo item_methodinfo = { |
208 | | { (JSJitGetterOp)item }, |
209 | | { prototypes::id::Plugin }, |
210 | | { PrototypeTraits<prototypes::id::Plugin>::Depth }, |
211 | | JSJitInfo::Method, |
212 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
213 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
214 | | false, /* isInfallible. False in setters. */ |
215 | | false, /* isMovable. Not relevant for setters. */ |
216 | | false, /* isEliminatable. Not relevant for setters. */ |
217 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
218 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
219 | | false, /* isTypedMethod. Only relevant for methods. */ |
220 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
221 | | }; |
222 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
223 | | static_assert(0 < 1, "There is no slot for us"); |
224 | | |
225 | | MOZ_CAN_RUN_SCRIPT static bool |
226 | | namedItem(JSContext* cx, JS::Handle<JSObject*> obj, nsPluginElement* self, const JSJitMethodCallArgs& args) |
227 | 0 | { |
228 | 0 | AUTO_PROFILER_LABEL_FAST("Plugin.namedItem", DOM, cx); |
229 | 0 |
|
230 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
231 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Plugin.namedItem"); |
232 | 0 | } |
233 | 0 | binding_detail::FakeString arg0; |
234 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
235 | 0 | return false; |
236 | 0 | } |
237 | 0 | auto result(StrongOrRawPtr<nsMimeType>(self->NamedItem(NonNullHelper(Constify(arg0))))); |
238 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
239 | 0 | if (!result) { |
240 | 0 | args.rval().setNull(); |
241 | 0 | return true; |
242 | 0 | } |
243 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
244 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
245 | 0 | return false; |
246 | 0 | } |
247 | 0 | return true; |
248 | 0 | } |
249 | | |
250 | | static const JSJitInfo namedItem_methodinfo = { |
251 | | { (JSJitGetterOp)namedItem }, |
252 | | { prototypes::id::Plugin }, |
253 | | { PrototypeTraits<prototypes::id::Plugin>::Depth }, |
254 | | JSJitInfo::Method, |
255 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
256 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
257 | | false, /* isInfallible. False in setters. */ |
258 | | false, /* isMovable. Not relevant for setters. */ |
259 | | false, /* isEliminatable. Not relevant for setters. */ |
260 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
261 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
262 | | false, /* isTypedMethod. Only relevant for methods. */ |
263 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
264 | | }; |
265 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
266 | | static_assert(0 < 1, "There is no slot for us"); |
267 | | |
268 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
269 | | #if defined(__clang__) |
270 | | #pragma clang diagnostic push |
271 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
272 | | #endif |
273 | | static const JSFunctionSpec sMethods_specs[] = { |
274 | | JS_FNSPEC("item", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&item_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
275 | | JS_FNSPEC("namedItem", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&namedItem_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
276 | | JS_SYM_FNSPEC(iterator, nullptr, nullptr, 0, 0, "ArrayValues"), |
277 | | JS_FS_END |
278 | | }; |
279 | | #if defined(__clang__) |
280 | | #pragma clang diagnostic pop |
281 | | #endif |
282 | | |
283 | | |
284 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
285 | | { nullptr, &sMethods_specs[0] }, |
286 | | { nullptr, nullptr } |
287 | | }; |
288 | | |
289 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
290 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
291 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
292 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
293 | | |
294 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
295 | | #if defined(__clang__) |
296 | | #pragma clang diagnostic push |
297 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
298 | | #endif |
299 | | static const JSPropertySpec sAttributes_specs[] = { |
300 | | { "description", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &description_getterinfo, nullptr, nullptr }, |
301 | | { "filename", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &filename_getterinfo, nullptr, nullptr }, |
302 | | { "version", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &version_getterinfo, nullptr, nullptr }, |
303 | | { "name", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &name_getterinfo, nullptr, nullptr }, |
304 | | { "length", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &length_getterinfo, nullptr, nullptr }, |
305 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
306 | | }; |
307 | | #if defined(__clang__) |
308 | | #pragma clang diagnostic pop |
309 | | #endif |
310 | | |
311 | | |
312 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
313 | | { nullptr, &sAttributes_specs[0] }, |
314 | | { nullptr, nullptr } |
315 | | }; |
316 | | |
317 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
318 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
319 | | static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
320 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
321 | | |
322 | | |
323 | | static uint16_t sNativeProperties_sortedPropertyIndices[8]; |
324 | | static PropertyInfo sNativeProperties_propertyInfos[8]; |
325 | | |
326 | | static const NativePropertiesN<2> sNativeProperties = { |
327 | | false, 0, |
328 | | false, 0, |
329 | | true, 0 /* sMethods */, |
330 | | true, 1 /* sAttributes */, |
331 | | false, 0, |
332 | | false, 0, |
333 | | false, 0, |
334 | | -1, |
335 | | 8, |
336 | | sNativeProperties_sortedPropertyIndices, |
337 | | { |
338 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
339 | | { sAttributes, &sNativeProperties_propertyInfos[3] } |
340 | | } |
341 | | }; |
342 | | static_assert(8 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
343 | | "We have a property info count that is oversized"); |
344 | | |
345 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
346 | | { |
347 | | "Function", |
348 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
349 | | &sBoringInterfaceObjectClassClassOps, |
350 | | JS_NULL_CLASS_SPEC, |
351 | | JS_NULL_CLASS_EXT, |
352 | | &sInterfaceObjectClassObjectOps |
353 | | }, |
354 | | eInterface, |
355 | | true, |
356 | | prototypes::id::Plugin, |
357 | | PrototypeTraits<prototypes::id::Plugin>::Depth, |
358 | | sNativePropertyHooks, |
359 | | "function Plugin() {\n [native code]\n}", |
360 | | JS::GetRealmFunctionPrototype |
361 | | }; |
362 | | |
363 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
364 | | { |
365 | | "PluginPrototype", |
366 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
367 | | JS_NULL_CLASS_OPS, |
368 | | JS_NULL_CLASS_SPEC, |
369 | | JS_NULL_CLASS_EXT, |
370 | | JS_NULL_OBJECT_OPS |
371 | | }, |
372 | | eInterfacePrototype, |
373 | | false, |
374 | | prototypes::id::Plugin, |
375 | | PrototypeTraits<prototypes::id::Plugin>::Depth, |
376 | | sNativePropertyHooks, |
377 | | "[object PluginPrototype]", |
378 | | JS::GetRealmObjectPrototype |
379 | | }; |
380 | | |
381 | | static_assert(IsBaseOf<nsISupports, nsPluginElement >::value, |
382 | | "We don't support non-nsISupports native classes for " |
383 | | "proxy-based bindings yet"); |
384 | | |
385 | | |
386 | | class DOMProxyHandler : public mozilla::dom::DOMProxyHandler |
387 | | { |
388 | | public: |
389 | | explicit constexpr DOMProxyHandler() |
390 | 0 | { |
391 | 0 | } |
392 | | |
393 | | virtual bool |
394 | | getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const override; |
395 | | |
396 | | virtual bool |
397 | | defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const override; |
398 | | |
399 | | using mozilla::dom::DOMProxyHandler::defineProperty; |
400 | | |
401 | | virtual bool |
402 | | ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const override; |
403 | | |
404 | | virtual bool |
405 | | hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const override; |
406 | | |
407 | | virtual bool |
408 | | get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const override; |
409 | | |
410 | | virtual const char* |
411 | | className(JSContext* cx, JS::Handle<JSObject*> proxy) const override; |
412 | | |
413 | | virtual bool |
414 | | finalizeInBackground(const JS::Value& priv) const override; |
415 | | |
416 | | virtual void |
417 | | finalize(JSFreeOp* fop, JSObject* proxy) const override; |
418 | | |
419 | | static const DOMProxyHandler* |
420 | | getInstance(); |
421 | | |
422 | | virtual bool |
423 | | delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const override; |
424 | | |
425 | | virtual bool |
426 | | getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const override; |
427 | | |
428 | | virtual size_t |
429 | | objectMoved(JSObject* obj, JSObject* old) const override; |
430 | | }; |
431 | | |
432 | | MOZ_ALWAYS_INLINE bool |
433 | | IsProxy(JSObject* obj) |
434 | 0 | { |
435 | 0 | return js::IsProxy(obj) && js::GetProxyHandler(obj) == DOMProxyHandler::getInstance(); |
436 | 0 | } |
437 | | |
438 | | MOZ_ALWAYS_INLINE nsPluginElement* |
439 | | UnwrapProxy(JSObject* obj) |
440 | 0 | { |
441 | 0 | MOZ_ASSERT(js::IsProxy(obj)); |
442 | 0 | if (js::GetProxyHandler(obj) != DOMProxyHandler::getInstance()) { |
443 | 0 | MOZ_ASSERT(xpc::WrapperFactory::IsXrayWrapper(obj)); |
444 | 0 | obj = js::UncheckedUnwrap(obj); |
445 | 0 | } |
446 | 0 | MOZ_ASSERT(IsProxy(obj)); |
447 | 0 | return static_cast<nsPluginElement*>(js::GetProxyReservedSlot(obj, DOM_OBJECT_SLOT).toPrivate()); |
448 | 0 | } |
449 | | |
450 | | bool |
451 | | DOMProxyHandler::getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const |
452 | 0 | { |
453 | 0 | bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy); |
454 | 0 | uint32_t index = GetArrayIndexFromId(cx, id); |
455 | 0 | if (IsArrayIndex(index)) { |
456 | 0 | nsPluginElement* self = UnwrapProxy(proxy); |
457 | 0 | bool found = false; |
458 | 0 | auto result(StrongOrRawPtr<nsMimeType>(self->IndexedGetter(index, found))); |
459 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
460 | 0 |
|
461 | 0 | if (found) { |
462 | 0 | if (!result) { |
463 | 0 | desc.value().setNull(); |
464 | 0 | FillPropertyDescriptor(desc, proxy, true); |
465 | 0 | return true; |
466 | 0 | } |
467 | 0 | if (!GetOrCreateDOMReflector(cx, result, desc.value())) { |
468 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
469 | 0 | return false; |
470 | 0 | } |
471 | 0 | FillPropertyDescriptor(desc, proxy, true); |
472 | 0 | return true; |
473 | 0 | } |
474 | 0 | } |
475 | 0 |
|
476 | 0 | JS::Rooted<JSObject*> expando(cx); |
477 | 0 | if (!isXray && (expando = GetExpandoObject(proxy))) { |
478 | 0 | if (!JS_GetOwnPropertyDescriptorById(cx, expando, id, desc)) { |
479 | 0 | return false; |
480 | 0 | } |
481 | 0 | if (desc.object()) { |
482 | 0 | // Pretend the property lives on the wrapper. |
483 | 0 | desc.object().set(proxy); |
484 | 0 | return true; |
485 | 0 | } |
486 | 0 | } |
487 | 0 | |
488 | 0 | bool callNamedGetter = false; |
489 | 0 | if (!IsArrayIndex(index) && !ignoreNamedProps) { |
490 | 0 | bool hasOnProto; |
491 | 0 | if (!HasPropertyOnPrototype(cx, proxy, id, &hasOnProto)) { |
492 | 0 | return false; |
493 | 0 | } |
494 | 0 | callNamedGetter = !hasOnProto; |
495 | 0 | } |
496 | 0 | if (callNamedGetter) { |
497 | 0 | FakeString name; |
498 | 0 | bool isSymbol; |
499 | 0 | if (!ConvertIdToString(cx, id, name, isSymbol)) { |
500 | 0 | return false; |
501 | 0 | } |
502 | 0 | if (!isSymbol) { |
503 | 0 | nsPluginElement* self = UnwrapProxy(proxy); |
504 | 0 | bool found = false; |
505 | 0 | auto result(StrongOrRawPtr<nsMimeType>(self->NamedGetter(NonNullHelper(Constify(name)), found))); |
506 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
507 | 0 |
|
508 | 0 | if (found) { |
509 | 0 | if (!result) { |
510 | 0 | desc.value().setNull(); |
511 | 0 | FillPropertyDescriptor(desc, proxy, true, false); |
512 | 0 | return true; |
513 | 0 | } |
514 | 0 | if (!GetOrCreateDOMReflector(cx, result, desc.value())) { |
515 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
516 | 0 | return false; |
517 | 0 | } |
518 | 0 | FillPropertyDescriptor(desc, proxy, true, false); |
519 | 0 | return true; |
520 | 0 | } |
521 | 0 | } |
522 | 0 | } |
523 | 0 |
|
524 | 0 | desc.object().set(nullptr); |
525 | 0 | return true; |
526 | 0 | } |
527 | | |
528 | | bool |
529 | | DOMProxyHandler::defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const |
530 | 0 | { |
531 | 0 | if (IsArrayIndex(GetArrayIndexFromId(cx, id))) { |
532 | 0 | *defined = true; |
533 | 0 | return opresult.failNoIndexedSetter(); |
534 | 0 | } |
535 | 0 | bool found = false; |
536 | 0 | FakeString name; |
537 | 0 | bool isSymbol; |
538 | 0 | if (!ConvertIdToString(cx, id, name, isSymbol)) { |
539 | 0 | return false; |
540 | 0 | } |
541 | 0 | if (!isSymbol) { |
542 | 0 | nsPluginElement* self = UnwrapProxy(proxy); |
543 | 0 | auto result(StrongOrRawPtr<nsMimeType>(self->NamedGetter(NonNullHelper(Constify(name)), found))); |
544 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
545 | 0 | (void)result; |
546 | 0 | } |
547 | 0 |
|
548 | 0 | if (found) { |
549 | 0 | *defined = true; |
550 | 0 | return opresult.failNoNamedSetter(); |
551 | 0 | } |
552 | 0 | return mozilla::dom::DOMProxyHandler::defineProperty(cx, proxy, id, desc, opresult, defined); |
553 | 0 | } |
554 | | |
555 | | |
556 | | bool |
557 | | DOMProxyHandler::ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const |
558 | 0 | { |
559 | 0 | bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy); |
560 | 0 |
|
561 | 0 | uint32_t length = UnwrapProxy(proxy)->Length(); |
562 | 0 | MOZ_ASSERT(int32_t(length) >= 0); |
563 | 0 | for (int32_t i = 0; i < int32_t(length); ++i) { |
564 | 0 | if (!props.append(INT_TO_JSID(i))) { |
565 | 0 | return false; |
566 | 0 | } |
567 | 0 | } |
568 | 0 |
|
569 | 0 | if (flags & JSITER_HIDDEN) { |
570 | 0 | nsTArray<nsString> names; |
571 | 0 | UnwrapProxy(proxy)->GetSupportedNames(names); |
572 | 0 | if (!AppendNamedPropertyIds(cx, proxy, names, false, props)) { |
573 | 0 | return false; |
574 | 0 | } |
575 | 0 | } |
576 | 0 | |
577 | 0 | JS::Rooted<JSObject*> expando(cx); |
578 | 0 | if (!isXray && (expando = DOMProxyHandler::GetExpandoObject(proxy)) && |
579 | 0 | !js::GetPropertyKeys(cx, expando, flags, &props)) { |
580 | 0 | return false; |
581 | 0 | } |
582 | 0 | |
583 | 0 | return true; |
584 | 0 | } |
585 | | |
586 | | bool |
587 | | DOMProxyHandler::hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const |
588 | 0 | { |
589 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
590 | 0 | "Should not have a XrayWrapper here"); |
591 | 0 |
|
592 | 0 | uint32_t index = GetArrayIndexFromId(cx, id); |
593 | 0 | if (IsArrayIndex(index)) { |
594 | 0 | bool found = false; |
595 | 0 | nsPluginElement* self = UnwrapProxy(proxy); |
596 | 0 | auto result(StrongOrRawPtr<nsMimeType>(self->IndexedGetter(index, found))); |
597 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
598 | 0 | (void)result; |
599 | 0 |
|
600 | 0 | *bp = found; |
601 | 0 | return true; |
602 | 0 | } |
603 | 0 |
|
604 | 0 |
|
605 | 0 | JS::Rooted<JSObject*> expando(cx, GetExpandoObject(proxy)); |
606 | 0 | if (expando) { |
607 | 0 | bool b = true; |
608 | 0 | bool ok = JS_HasPropertyById(cx, expando, id, &b); |
609 | 0 | *bp = !!b; |
610 | 0 | if (!ok || *bp) { |
611 | 0 | return ok; |
612 | 0 | } |
613 | 0 | } |
614 | 0 | |
615 | 0 | bool hasOnProto; |
616 | 0 | if (!HasPropertyOnPrototype(cx, proxy, id, &hasOnProto)) { |
617 | 0 | return false; |
618 | 0 | } |
619 | 0 | if (!hasOnProto) { |
620 | 0 | bool found = false; |
621 | 0 | FakeString name; |
622 | 0 | bool isSymbol; |
623 | 0 | if (!ConvertIdToString(cx, id, name, isSymbol)) { |
624 | 0 | return false; |
625 | 0 | } |
626 | 0 | if (!isSymbol) { |
627 | 0 | nsPluginElement* self = UnwrapProxy(proxy); |
628 | 0 | auto result(StrongOrRawPtr<nsMimeType>(self->NamedGetter(NonNullHelper(Constify(name)), found))); |
629 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
630 | 0 | (void)result; |
631 | 0 | } |
632 | 0 |
|
633 | 0 | *bp = found; |
634 | 0 | return true; |
635 | 0 | } |
636 | 0 | *bp = false; |
637 | 0 | return true; |
638 | 0 | } |
639 | | |
640 | | bool |
641 | | DOMProxyHandler::get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const |
642 | 0 | { |
643 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
644 | 0 | "Should not have a XrayWrapper here"); |
645 | 0 |
|
646 | 0 | uint32_t index = GetArrayIndexFromId(cx, id); |
647 | 0 | if (IsArrayIndex(index)) { |
648 | 0 | nsPluginElement* self = UnwrapProxy(proxy); |
649 | 0 | bool found = false; |
650 | 0 | auto result(StrongOrRawPtr<nsMimeType>(self->IndexedGetter(index, found))); |
651 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
652 | 0 |
|
653 | 0 | if (found) { |
654 | 0 | if (!result) { |
655 | 0 | vp.setNull(); |
656 | 0 | return true; |
657 | 0 | } |
658 | 0 | if (!GetOrCreateDOMReflector(cx, result, vp)) { |
659 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
660 | 0 | return false; |
661 | 0 | } |
662 | 0 | return true; |
663 | 0 | } |
664 | 0 | // Even if we don't have this index, we don't forward the |
665 | 0 | // get on to our expando object. |
666 | 0 | } else { |
667 | 0 | { // Scope for expando |
668 | 0 | JS::Rooted<JSObject*> expando(cx, DOMProxyHandler::GetExpandoObject(proxy)); |
669 | 0 | if (expando) { |
670 | 0 | bool hasProp; |
671 | 0 | if (!JS_HasPropertyById(cx, expando, id, &hasProp)) { |
672 | 0 | return false; |
673 | 0 | } |
674 | 0 | |
675 | 0 | if (hasProp) { |
676 | 0 | // Forward the get to the expando object, but our receiver is whatever our |
677 | 0 | // receiver is. |
678 | 0 | return JS_ForwardGetPropertyTo(cx, expando, id, receiver, vp); |
679 | 0 | } |
680 | 0 | } |
681 | 0 | } |
682 | 0 | } |
683 | 0 | |
684 | 0 | bool foundOnPrototype; |
685 | 0 | if (!GetPropertyOnPrototype(cx, proxy, receiver, id, &foundOnPrototype, vp)) { |
686 | 0 | return false; |
687 | 0 | } |
688 | 0 | |
689 | 0 | if (foundOnPrototype) { |
690 | 0 | return true; |
691 | 0 | } |
692 | 0 | |
693 | 0 | if (!IsArrayIndex(index)) { |
694 | 0 | FakeString name; |
695 | 0 | bool isSymbol; |
696 | 0 | if (!ConvertIdToString(cx, id, name, isSymbol)) { |
697 | 0 | return false; |
698 | 0 | } |
699 | 0 | if (!isSymbol) { |
700 | 0 | nsPluginElement* self = UnwrapProxy(proxy); |
701 | 0 | bool found = false; |
702 | 0 | auto result(StrongOrRawPtr<nsMimeType>(self->NamedGetter(NonNullHelper(Constify(name)), found))); |
703 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
704 | 0 |
|
705 | 0 | if (found) { |
706 | 0 | if (!result) { |
707 | 0 | vp.setNull(); |
708 | 0 | return true; |
709 | 0 | } |
710 | 0 | if (!GetOrCreateDOMReflector(cx, result, vp)) { |
711 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
712 | 0 | return false; |
713 | 0 | } |
714 | 0 | return true; |
715 | 0 | } |
716 | 0 | } |
717 | 0 | } |
718 | 0 |
|
719 | 0 | vp.setUndefined(); |
720 | 0 | return true; |
721 | 0 | } |
722 | | |
723 | | const char* |
724 | | DOMProxyHandler::className(JSContext* cx, JS::Handle<JSObject*> proxy) const |
725 | 0 | { |
726 | 0 | return "Plugin"; |
727 | 0 | } |
728 | | |
729 | | bool |
730 | | DOMProxyHandler::finalizeInBackground(const JS::Value& priv) const |
731 | 0 | { |
732 | 0 | return false; |
733 | 0 | } |
734 | | |
735 | | void |
736 | | DOMProxyHandler::finalize(JSFreeOp* fop, JSObject* proxy) const |
737 | 0 | { |
738 | 0 | nsPluginElement* self = UnwrapPossiblyNotInitializedDOMObject<nsPluginElement>(proxy); |
739 | 0 | if (self) { |
740 | 0 | ClearWrapper(self, self, proxy); |
741 | 0 | AddForDeferredFinalization<nsPluginElement>(self); |
742 | 0 | } |
743 | 0 | } |
744 | | |
745 | | const DOMProxyHandler* |
746 | | DOMProxyHandler::getInstance() |
747 | 0 | { |
748 | 0 | static const DOMProxyHandler instance; |
749 | 0 | return &instance; |
750 | 0 | } |
751 | | |
752 | | bool |
753 | | DOMProxyHandler::delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const |
754 | 0 | { |
755 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
756 | 0 | "Should not have a XrayWrapper here"); |
757 | 0 |
|
758 | 0 | uint32_t index = GetArrayIndexFromId(cx, id); |
759 | 0 | if (IsArrayIndex(index)) { |
760 | 0 | bool deleteSucceeded; |
761 | 0 | bool found = false; |
762 | 0 | nsPluginElement* self = UnwrapProxy(proxy); |
763 | 0 | auto result(StrongOrRawPtr<nsMimeType>(self->IndexedGetter(index, found))); |
764 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
765 | 0 | (void)result; |
766 | 0 | deleteSucceeded = !found; |
767 | 0 | return deleteSucceeded ? opresult.succeed() : opresult.failCantDelete(); |
768 | 0 | } |
769 | 0 | // Try named delete only if the named property visibility |
770 | 0 | // algorithm says the property is visible. |
771 | 0 | bool tryNamedDelete = true; |
772 | 0 | { // Scope for expando |
773 | 0 | JS::Rooted<JSObject*> expando(cx, DOMProxyHandler::GetExpandoObject(proxy)); |
774 | 0 | if (expando) { |
775 | 0 | bool hasProp; |
776 | 0 | if (!JS_HasPropertyById(cx, expando, id, &hasProp)) { |
777 | 0 | return false; |
778 | 0 | } |
779 | 0 | tryNamedDelete = !hasProp; |
780 | 0 | } |
781 | 0 | } |
782 | 0 | if (tryNamedDelete) { |
783 | 0 | bool hasOnProto; |
784 | 0 | if (!HasPropertyOnPrototype(cx, proxy, id, &hasOnProto)) { |
785 | 0 | return false; |
786 | 0 | } |
787 | 0 | tryNamedDelete = !hasOnProto; |
788 | 0 | } |
789 | 0 | if (tryNamedDelete) { |
790 | 0 | bool found = false; |
791 | 0 | bool deleteSucceeded; |
792 | 0 | FakeString name; |
793 | 0 | bool isSymbol; |
794 | 0 | if (!ConvertIdToString(cx, id, name, isSymbol)) { |
795 | 0 | return false; |
796 | 0 | } |
797 | 0 | if (!isSymbol) { |
798 | 0 | nsPluginElement* self = UnwrapProxy(proxy); |
799 | 0 | auto result(StrongOrRawPtr<nsMimeType>(self->NamedGetter(NonNullHelper(Constify(name)), found))); |
800 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
801 | 0 | (void)result; |
802 | 0 | } |
803 | 0 | deleteSucceeded = !found; |
804 | 0 | if (found) { |
805 | 0 | return deleteSucceeded ? opresult.succeed() : opresult.failCantDelete(); |
806 | 0 | } |
807 | 0 | } |
808 | 0 |
|
809 | 0 | return dom::DOMProxyHandler::delete_(cx, proxy, id, opresult); |
810 | 0 | } |
811 | | |
812 | | bool |
813 | | DOMProxyHandler::getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const |
814 | 0 | { |
815 | 0 | JS::Rooted<JS::Value> temp(cx); |
816 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
817 | 0 | "Should not have a XrayWrapper here"); |
818 | 0 |
|
819 | 0 | nsPluginElement* self = UnwrapProxy(proxy); |
820 | 0 | uint32_t length = self->Length(); |
821 | 0 | // Compute the end of the indices we'll get ourselves |
822 | 0 | uint32_t ourEnd = std::max(begin, std::min(end, length)); |
823 | 0 |
|
824 | 0 | for (uint32_t index = begin; index < ourEnd; ++index) { |
825 | 0 | bool found = false; |
826 | 0 | auto result(StrongOrRawPtr<nsMimeType>(self->IndexedGetter(index, found))); |
827 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
828 | 0 |
|
829 | 0 | MOZ_ASSERT(found); |
830 | 0 | if (!result) { |
831 | 0 | temp.setNull(); |
832 | 0 | if (!adder->append(cx, temp)) return false; |
833 | 0 | continue; |
834 | 0 | } |
835 | 0 | if (!GetOrCreateDOMReflector(cx, result, &temp)) { |
836 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
837 | 0 | return false; |
838 | 0 | } |
839 | 0 | if (!adder->append(cx, temp)) return false; |
840 | 0 | continue; |
841 | 0 | } |
842 | 0 |
|
843 | 0 | if (end > ourEnd) { |
844 | 0 | JS::Rooted<JSObject*> proto(cx); |
845 | 0 | if (!js::GetObjectProto(cx, proxy, &proto)) { |
846 | 0 | return false; |
847 | 0 | } |
848 | 0 | return js::GetElementsWithAdder(cx, proto, proxy, ourEnd, end, adder); |
849 | 0 | } |
850 | 0 | |
851 | 0 | return true; |
852 | 0 | } |
853 | | |
854 | | size_t |
855 | | DOMProxyHandler::objectMoved(JSObject* obj, JSObject* old) const |
856 | 0 | { |
857 | 0 | nsPluginElement* self = UnwrapPossiblyNotInitializedDOMObject<nsPluginElement>(obj); |
858 | 0 | if (self) { |
859 | 0 | UpdateWrapper(self, self, obj, old); |
860 | 0 | } |
861 | 0 |
|
862 | 0 | return 0; |
863 | 0 | } |
864 | | |
865 | | static const DOMJSClass sClass = { |
866 | | PROXY_CLASS_DEF("Plugin", |
867 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(1)), |
868 | | { prototypes::id::Plugin, 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 }, |
869 | | IsBaseOf<nsISupports, nsPluginElement >::value, |
870 | | sNativePropertyHooks, |
871 | | FindAssociatedGlobalForNative<nsPluginElement>::Get, |
872 | | GetProtoObjectHandle, |
873 | | GetCCParticipant<nsPluginElement>::Get() |
874 | | }; |
875 | | |
876 | | bool |
877 | | Wrap(JSContext* aCx, nsPluginElement* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
878 | 0 | { |
879 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, nsPluginElement>::value, |
880 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
881 | 0 | MOZ_ASSERT(static_cast<nsPluginElement*>(aObject) == |
882 | 0 | reinterpret_cast<nsPluginElement*>(aObject), |
883 | 0 | "Multiple inheritance for nsPluginElement is broken."); |
884 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
885 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
886 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
887 | 0 | "You should probably not be using Wrap() directly; use " |
888 | 0 | "GetOrCreateDOMReflector instead"); |
889 | 0 |
|
890 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
891 | 0 | "nsISupports must be on our primary inheritance chain"); |
892 | 0 |
|
893 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
894 | 0 | if (!global) { |
895 | 0 | return false; |
896 | 0 | } |
897 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
898 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
899 | 0 |
|
900 | 0 | // That might have ended up wrapping us already, due to the wonders |
901 | 0 | // of XBL. Check for that, and bail out as needed. |
902 | 0 | aReflector.set(aCache->GetWrapper()); |
903 | 0 | if (aReflector) { |
904 | | #ifdef DEBUG |
905 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
906 | | #endif // DEBUG |
907 | | return true; |
908 | 0 | } |
909 | 0 |
|
910 | 0 | JSAutoRealm ar(aCx, global); |
911 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
912 | 0 | if (!canonicalProto) { |
913 | 0 | return false; |
914 | 0 | } |
915 | 0 | JS::Rooted<JSObject*> proto(aCx); |
916 | 0 | if (aGivenProto) { |
917 | 0 | proto = aGivenProto; |
918 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
919 | 0 | // coming in, we changed compartments to that of "parent" so may need |
920 | 0 | // to wrap the proto here. |
921 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
922 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
923 | 0 | return false; |
924 | 0 | } |
925 | 0 | } |
926 | 0 | } else { |
927 | 0 | proto = canonicalProto; |
928 | 0 | } |
929 | 0 |
|
930 | 0 | BindingJSObjectCreator<nsPluginElement> creator(aCx); |
931 | 0 | creator.CreateProxyObject(aCx, &sClass.mBase, DOMProxyHandler::getInstance(), |
932 | 0 | proto, aObject, JS::UndefinedHandleValue, aReflector); |
933 | 0 | if (!aReflector) { |
934 | 0 | return false; |
935 | 0 | } |
936 | 0 | |
937 | 0 | aCache->SetWrapper(aReflector); |
938 | 0 | creator.InitializationSucceeded(); |
939 | 0 |
|
940 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
941 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
942 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
943 | 0 | // otherwise we won't be able to properly recreate it later, since |
944 | 0 | // we won't know what proto to use. Note that we don't check |
945 | 0 | // aGivenProto here, since it's entirely possible (and even |
946 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
947 | 0 | // same as canonicalProto. |
948 | 0 | if (proto != canonicalProto) { |
949 | 0 | PreserveWrapper(aObject); |
950 | 0 | } |
951 | 0 |
|
952 | 0 | return true; |
953 | 0 | } |
954 | | |
955 | | static bool |
956 | | ResolveOwnProperty(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::MutableHandle<JS::PropertyDescriptor> desc) |
957 | 0 | { |
958 | 0 | return js::GetProxyHandler(obj)->getOwnPropertyDescriptor(cx, wrapper, id, desc); |
959 | 0 | } |
960 | | |
961 | | static bool |
962 | | EnumerateOwnProperties(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::AutoIdVector& props) |
963 | 0 | { |
964 | 0 | return js::GetProxyHandler(obj)->ownPropertyKeys(cx, wrapper, props); |
965 | 0 | } |
966 | | |
967 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
968 | | ResolveOwnProperty, |
969 | | EnumerateOwnProperties, |
970 | | nullptr, |
971 | | { sNativeProperties.Upcast(), nullptr }, |
972 | | prototypes::id::Plugin, |
973 | | constructors::id::Plugin, |
974 | | nullptr, |
975 | | &DefaultXrayExpandoObjectClass |
976 | | } }; |
977 | | |
978 | | void |
979 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
980 | 0 | { |
981 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
982 | 0 | if (!parentProto) { |
983 | 0 | return; |
984 | 0 | } |
985 | 0 | |
986 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
987 | 0 | if (!constructorProto) { |
988 | 0 | return; |
989 | 0 | } |
990 | 0 | |
991 | 0 | static bool sIdsInited = false; |
992 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
993 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
994 | 0 | return; |
995 | 0 | } |
996 | 0 | sIdsInited = true; |
997 | 0 | } |
998 | 0 |
|
999 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::Plugin); |
1000 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::Plugin); |
1001 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
1002 | 0 | &sPrototypeClass.mBase, protoCache, |
1003 | 0 | nullptr, |
1004 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
1005 | 0 | interfaceCache, |
1006 | 0 | sNativeProperties.Upcast(), |
1007 | 0 | nullptr, |
1008 | 0 | "Plugin", aDefineOnGlobal, |
1009 | 0 | nullptr, |
1010 | 0 | false); |
1011 | 0 | } |
1012 | | |
1013 | | JSObject* |
1014 | | GetConstructorObject(JSContext* aCx) |
1015 | 0 | { |
1016 | 0 | return GetConstructorObjectHandle(aCx); |
1017 | 0 | } |
1018 | | |
1019 | | } // namespace Plugin_Binding |
1020 | | |
1021 | | |
1022 | | |
1023 | | } // namespace dom |
1024 | | } // namespace mozilla |