/work/obj-fuzz/dom/bindings/HTMLBaseElementBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM HTMLBaseElement.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "HTMLBaseElementBinding.h" |
4 | | #include "HTMLElementBinding.h" |
5 | | #include "WrapperFactory.h" |
6 | | #include "mozilla/OwningNonNull.h" |
7 | | #include "mozilla/dom/BindingUtils.h" |
8 | | #include "mozilla/dom/CustomElementRegistry.h" |
9 | | #include "mozilla/dom/DOMJSClass.h" |
10 | | #include "mozilla/dom/DocGroup.h" |
11 | | #include "mozilla/dom/HTMLSharedElement.h" |
12 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
13 | | #include "mozilla/dom/XrayExpandoClass.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 HTMLBaseElement_Binding { |
23 | | |
24 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<HTMLElement_Binding::NativeType>::value, |
25 | | "Can't inherit from an interface with a different ownership model."); |
26 | | |
27 | | MOZ_CAN_RUN_SCRIPT static bool |
28 | | get_href(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLSharedElement* self, JSJitGetterCallArgs args) |
29 | 0 | { |
30 | 0 | AUTO_PROFILER_LABEL_FAST("get HTMLBaseElement.href", DOM, cx); |
31 | 0 |
|
32 | 0 | DOMString result; |
33 | 0 | self->GetHref(result); |
34 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
35 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
36 | 0 | return false; |
37 | 0 | } |
38 | 0 | return true; |
39 | 0 | } |
40 | | |
41 | | MOZ_CAN_RUN_SCRIPT static bool |
42 | | set_href(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLSharedElement* self, JSJitSetterCallArgs args) |
43 | 0 | { |
44 | 0 | AUTO_PROFILER_LABEL_FAST("set HTMLBaseElement.href", DOM, cx); |
45 | 0 |
|
46 | 0 | binding_detail::FakeString arg0; |
47 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
48 | 0 | return false; |
49 | 0 | } |
50 | 0 | Maybe<AutoCEReaction> ceReaction; |
51 | 0 | if (CustomElementRegistry::IsCustomElementEnabled(cx, obj)) { |
52 | 0 | DocGroup* docGroup = self->GetDocGroup(); |
53 | 0 | if (docGroup) { |
54 | 0 | ceReaction.emplace(docGroup->CustomElementReactionsStack(), cx); |
55 | 0 | } |
56 | 0 | } |
57 | 0 | FastErrorResult rv; |
58 | 0 | self->SetHref(NonNullHelper(Constify(arg0)), rv); |
59 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
60 | 0 | return false; |
61 | 0 | } |
62 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
63 | 0 |
|
64 | 0 | return true; |
65 | 0 | } |
66 | | |
67 | | static const JSJitInfo href_getterinfo = { |
68 | | { (JSJitGetterOp)get_href }, |
69 | | { prototypes::id::HTMLBaseElement }, |
70 | | { PrototypeTraits<prototypes::id::HTMLBaseElement>::Depth }, |
71 | | JSJitInfo::Getter, |
72 | | JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */ |
73 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
74 | | false, /* isInfallible. False in setters. */ |
75 | | true, /* isMovable. Not relevant for setters. */ |
76 | | true, /* isEliminatable. Not relevant for setters. */ |
77 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
78 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
79 | | false, /* isTypedMethod. Only relevant for methods. */ |
80 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
81 | | }; |
82 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
83 | | static_assert(0 < 1, "There is no slot for us"); |
84 | | static const JSJitInfo href_setterinfo = { |
85 | | { (JSJitGetterOp)set_href }, |
86 | | { prototypes::id::HTMLBaseElement }, |
87 | | { PrototypeTraits<prototypes::id::HTMLBaseElement>::Depth }, |
88 | | JSJitInfo::Setter, |
89 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
90 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
91 | | false, /* isInfallible. False in setters. */ |
92 | | false, /* isMovable. Not relevant for setters. */ |
93 | | false, /* isEliminatable. Not relevant for setters. */ |
94 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
95 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
96 | | false, /* isTypedMethod. Only relevant for methods. */ |
97 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
98 | | }; |
99 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
100 | | static_assert(0 < 1, "There is no slot for us"); |
101 | | |
102 | | MOZ_CAN_RUN_SCRIPT static bool |
103 | | get_target(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLSharedElement* self, JSJitGetterCallArgs args) |
104 | 0 | { |
105 | 0 | AUTO_PROFILER_LABEL_FAST("get HTMLBaseElement.target", DOM, cx); |
106 | 0 |
|
107 | 0 | DOMString result; |
108 | 0 | self->GetTarget(result); |
109 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
110 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
111 | 0 | return false; |
112 | 0 | } |
113 | 0 | return true; |
114 | 0 | } |
115 | | |
116 | | MOZ_CAN_RUN_SCRIPT static bool |
117 | | set_target(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLSharedElement* self, JSJitSetterCallArgs args) |
118 | 0 | { |
119 | 0 | AUTO_PROFILER_LABEL_FAST("set HTMLBaseElement.target", DOM, cx); |
120 | 0 |
|
121 | 0 | binding_detail::FakeString arg0; |
122 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
123 | 0 | return false; |
124 | 0 | } |
125 | 0 | Maybe<AutoCEReaction> ceReaction; |
126 | 0 | if (CustomElementRegistry::IsCustomElementEnabled(cx, obj)) { |
127 | 0 | DocGroup* docGroup = self->GetDocGroup(); |
128 | 0 | if (docGroup) { |
129 | 0 | ceReaction.emplace(docGroup->CustomElementReactionsStack(), cx); |
130 | 0 | } |
131 | 0 | } |
132 | 0 | FastErrorResult rv; |
133 | 0 | self->SetTarget(NonNullHelper(Constify(arg0)), rv); |
134 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
135 | 0 | return false; |
136 | 0 | } |
137 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
138 | 0 |
|
139 | 0 | return true; |
140 | 0 | } |
141 | | |
142 | | static const JSJitInfo target_getterinfo = { |
143 | | { (JSJitGetterOp)get_target }, |
144 | | { prototypes::id::HTMLBaseElement }, |
145 | | { PrototypeTraits<prototypes::id::HTMLBaseElement>::Depth }, |
146 | | JSJitInfo::Getter, |
147 | | JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */ |
148 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
149 | | false, /* isInfallible. False in setters. */ |
150 | | true, /* isMovable. Not relevant for setters. */ |
151 | | true, /* isEliminatable. Not relevant for setters. */ |
152 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
153 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
154 | | false, /* isTypedMethod. Only relevant for methods. */ |
155 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
156 | | }; |
157 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
158 | | static_assert(0 < 1, "There is no slot for us"); |
159 | | static const JSJitInfo target_setterinfo = { |
160 | | { (JSJitGetterOp)set_target }, |
161 | | { prototypes::id::HTMLBaseElement }, |
162 | | { PrototypeTraits<prototypes::id::HTMLBaseElement>::Depth }, |
163 | | JSJitInfo::Setter, |
164 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
165 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
166 | | false, /* isInfallible. False in setters. */ |
167 | | false, /* isMovable. Not relevant for setters. */ |
168 | | false, /* isEliminatable. Not relevant for setters. */ |
169 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
170 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
171 | | false, /* isTypedMethod. Only relevant for methods. */ |
172 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
173 | | }; |
174 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
175 | | static_assert(0 < 1, "There is no slot for us"); |
176 | | |
177 | | static bool |
178 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
179 | 0 | { |
180 | 0 | mozilla::dom::HTMLSharedElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLSharedElement>(obj); |
181 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
182 | 0 | // obviously can't preserve if we're not initialized. |
183 | 0 | if (self && self->GetWrapperPreserveColor()) { |
184 | 0 | PreserveWrapper(self); |
185 | 0 | } |
186 | 0 | return true; |
187 | 0 | } |
188 | | |
189 | | static void |
190 | | _finalize(js::FreeOp* fop, JSObject* obj) |
191 | 0 | { |
192 | 0 | mozilla::dom::HTMLSharedElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLSharedElement>(obj); |
193 | 0 | if (self) { |
194 | 0 | ClearWrapper(self, self, obj); |
195 | 0 | AddForDeferredFinalization<mozilla::dom::HTMLSharedElement>(self); |
196 | 0 | } |
197 | 0 | } |
198 | | |
199 | | static size_t |
200 | | _objectMoved(JSObject* obj, JSObject* old) |
201 | 0 | { |
202 | 0 | mozilla::dom::HTMLSharedElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLSharedElement>(obj); |
203 | 0 | if (self) { |
204 | 0 | UpdateWrapper(self, self, obj, old); |
205 | 0 | } |
206 | 0 |
|
207 | 0 | return 0; |
208 | 0 | } |
209 | | |
210 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
211 | | #if defined(__clang__) |
212 | | #pragma clang diagnostic push |
213 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
214 | | #endif |
215 | | static const JSPropertySpec sAttributes_specs[] = { |
216 | | { "href", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &href_getterinfo, GenericSetter<NormalThisPolicy>, &href_setterinfo }, |
217 | | { "target", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &target_getterinfo, GenericSetter<NormalThisPolicy>, &target_setterinfo }, |
218 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
219 | | }; |
220 | | #if defined(__clang__) |
221 | | #pragma clang diagnostic pop |
222 | | #endif |
223 | | |
224 | | |
225 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
226 | | { nullptr, &sAttributes_specs[0] }, |
227 | | { nullptr, nullptr } |
228 | | }; |
229 | | |
230 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
231 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
232 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
233 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
234 | | |
235 | | |
236 | | static uint16_t sNativeProperties_sortedPropertyIndices[2]; |
237 | | static PropertyInfo sNativeProperties_propertyInfos[2]; |
238 | | |
239 | | static const NativePropertiesN<1> sNativeProperties = { |
240 | | false, 0, |
241 | | false, 0, |
242 | | false, 0, |
243 | | true, 0 /* sAttributes */, |
244 | | false, 0, |
245 | | false, 0, |
246 | | false, 0, |
247 | | -1, |
248 | | 2, |
249 | | sNativeProperties_sortedPropertyIndices, |
250 | | { |
251 | | { sAttributes, &sNativeProperties_propertyInfos[0] } |
252 | | } |
253 | | }; |
254 | | static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
255 | | "We have a property info count that is oversized"); |
256 | | |
257 | | static bool |
258 | | _constructor(JSContext* cx, unsigned argc, JS::Value* vp) |
259 | 0 | { |
260 | 0 | AUTO_PROFILER_LABEL_FAST("HTMLBaseElement constructor", DOM, cx); |
261 | 0 |
|
262 | 0 | return HTMLConstructor(cx, argc, vp, |
263 | 0 | constructors::id::HTMLBaseElement, |
264 | 0 | prototypes::id::HTMLBaseElement, |
265 | 0 | CreateInterfaceObjects); |
266 | 0 | } |
267 | | |
268 | | static const js::ClassOps sInterfaceObjectClassOps = { |
269 | | nullptr, /* addProperty */ |
270 | | nullptr, /* delProperty */ |
271 | | nullptr, /* enumerate */ |
272 | | nullptr, /* newEnumerate */ |
273 | | nullptr, /* resolve */ |
274 | | nullptr, /* mayResolve */ |
275 | | nullptr, /* finalize */ |
276 | | _constructor, /* call */ |
277 | | nullptr, /* hasInstance */ |
278 | | _constructor, /* construct */ |
279 | | nullptr, /* trace */ |
280 | | }; |
281 | | |
282 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
283 | | { |
284 | | "Function", |
285 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
286 | | &sInterfaceObjectClassOps, |
287 | | JS_NULL_CLASS_SPEC, |
288 | | JS_NULL_CLASS_EXT, |
289 | | &sInterfaceObjectClassObjectOps |
290 | | }, |
291 | | eInterface, |
292 | | true, |
293 | | prototypes::id::HTMLBaseElement, |
294 | | PrototypeTraits<prototypes::id::HTMLBaseElement>::Depth, |
295 | | sNativePropertyHooks, |
296 | | "function HTMLBaseElement() {\n [native code]\n}", |
297 | | HTMLElement_Binding::GetConstructorObject |
298 | | }; |
299 | | |
300 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
301 | | { |
302 | | "HTMLBaseElementPrototype", |
303 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
304 | | JS_NULL_CLASS_OPS, |
305 | | JS_NULL_CLASS_SPEC, |
306 | | JS_NULL_CLASS_EXT, |
307 | | JS_NULL_OBJECT_OPS |
308 | | }, |
309 | | eInterfacePrototype, |
310 | | false, |
311 | | prototypes::id::HTMLBaseElement, |
312 | | PrototypeTraits<prototypes::id::HTMLBaseElement>::Depth, |
313 | | sNativePropertyHooks, |
314 | | "[object HTMLBaseElementPrototype]", |
315 | | HTMLElement_Binding::GetProtoObject |
316 | | }; |
317 | | |
318 | | static const js::ClassOps sClassOps = { |
319 | | _addProperty, /* addProperty */ |
320 | | nullptr, /* delProperty */ |
321 | | nullptr, /* enumerate */ |
322 | | nullptr, /* newEnumerate */ |
323 | | nullptr, /* resolve */ |
324 | | nullptr, /* mayResolve */ |
325 | | _finalize, /* finalize */ |
326 | | nullptr, /* call */ |
327 | | nullptr, /* hasInstance */ |
328 | | nullptr, /* construct */ |
329 | | nullptr, /* trace */ |
330 | | }; |
331 | | |
332 | | static const js::ClassExtension sClassExtension = { |
333 | | nullptr, /* weakmapKeyDelegateOp */ |
334 | | _objectMoved /* objectMovedOp */ |
335 | | }; |
336 | | |
337 | | static const DOMJSClass sClass = { |
338 | | { "HTMLBaseElement", |
339 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
340 | | &sClassOps, |
341 | | JS_NULL_CLASS_SPEC, |
342 | | &sClassExtension, |
343 | | JS_NULL_OBJECT_OPS |
344 | | }, |
345 | | { prototypes::id::EventTarget, prototypes::id::Node, prototypes::id::Element, prototypes::id::HTMLElement, prototypes::id::HTMLBaseElement, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
346 | | IsBaseOf<nsISupports, mozilla::dom::HTMLSharedElement >::value, |
347 | | sNativePropertyHooks, |
348 | | FindAssociatedGlobalForNative<mozilla::dom::HTMLSharedElement>::Get, |
349 | | GetProtoObjectHandle, |
350 | | GetCCParticipant<mozilla::dom::HTMLSharedElement>::Get() |
351 | | }; |
352 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
353 | | "Must have the right minimal number of reserved slots."); |
354 | | static_assert(1 >= 1, |
355 | | "Must have enough reserved slots."); |
356 | | |
357 | | const JSClass* |
358 | | GetJSClass() |
359 | 0 | { |
360 | 0 | return sClass.ToJSClass(); |
361 | 0 | } |
362 | | |
363 | | bool |
364 | | Wrap(JSContext* aCx, mozilla::dom::HTMLSharedElement* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
365 | 0 | { |
366 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::HTMLSharedElement>::value, |
367 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
368 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::HTMLSharedElement*>(aObject) == |
369 | 0 | reinterpret_cast<mozilla::dom::HTMLSharedElement*>(aObject), |
370 | 0 | "Multiple inheritance for mozilla::dom::HTMLSharedElement is broken."); |
371 | 0 | MOZ_ASSERT(static_cast<nsGenericHTMLElement*>(aObject) == |
372 | 0 | reinterpret_cast<nsGenericHTMLElement*>(aObject), |
373 | 0 | "Multiple inheritance for nsGenericHTMLElement is broken."); |
374 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::Element*>(aObject) == |
375 | 0 | reinterpret_cast<mozilla::dom::Element*>(aObject), |
376 | 0 | "Multiple inheritance for mozilla::dom::Element is broken."); |
377 | 0 | MOZ_ASSERT(static_cast<nsINode*>(aObject) == |
378 | 0 | reinterpret_cast<nsINode*>(aObject), |
379 | 0 | "Multiple inheritance for nsINode is broken."); |
380 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) == |
381 | 0 | reinterpret_cast<mozilla::dom::EventTarget*>(aObject), |
382 | 0 | "Multiple inheritance for mozilla::dom::EventTarget is broken."); |
383 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
384 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
385 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
386 | 0 | "You should probably not be using Wrap() directly; use " |
387 | 0 | "GetOrCreateDOMReflector instead"); |
388 | 0 |
|
389 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
390 | 0 | "nsISupports must be on our primary inheritance chain"); |
391 | 0 |
|
392 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
393 | 0 | if (!global) { |
394 | 0 | return false; |
395 | 0 | } |
396 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
397 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
398 | 0 |
|
399 | 0 | // That might have ended up wrapping us already, due to the wonders |
400 | 0 | // of XBL. Check for that, and bail out as needed. |
401 | 0 | aReflector.set(aCache->GetWrapper()); |
402 | 0 | if (aReflector) { |
403 | | #ifdef DEBUG |
404 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
405 | | #endif // DEBUG |
406 | | return true; |
407 | 0 | } |
408 | 0 |
|
409 | 0 | JSAutoRealm ar(aCx, global); |
410 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
411 | 0 | if (!canonicalProto) { |
412 | 0 | return false; |
413 | 0 | } |
414 | 0 | JS::Rooted<JSObject*> proto(aCx); |
415 | 0 | if (aGivenProto) { |
416 | 0 | proto = aGivenProto; |
417 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
418 | 0 | // coming in, we changed compartments to that of "parent" so may need |
419 | 0 | // to wrap the proto here. |
420 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
421 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
422 | 0 | return false; |
423 | 0 | } |
424 | 0 | } |
425 | 0 | } else { |
426 | 0 | proto = canonicalProto; |
427 | 0 | } |
428 | 0 |
|
429 | 0 | BindingJSObjectCreator<mozilla::dom::HTMLSharedElement> creator(aCx); |
430 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
431 | 0 | if (!aReflector) { |
432 | 0 | return false; |
433 | 0 | } |
434 | 0 | |
435 | 0 | aCache->SetWrapper(aReflector); |
436 | 0 | creator.InitializationSucceeded(); |
437 | 0 |
|
438 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
439 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
440 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
441 | 0 | // otherwise we won't be able to properly recreate it later, since |
442 | 0 | // we won't know what proto to use. Note that we don't check |
443 | 0 | // aGivenProto here, since it's entirely possible (and even |
444 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
445 | 0 | // same as canonicalProto. |
446 | 0 | if (proto != canonicalProto) { |
447 | 0 | PreserveWrapper(aObject); |
448 | 0 | } |
449 | 0 |
|
450 | 0 | return true; |
451 | 0 | } |
452 | | |
453 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
454 | | nullptr, |
455 | | nullptr, |
456 | | nullptr, |
457 | | { sNativeProperties.Upcast(), nullptr }, |
458 | | prototypes::id::HTMLBaseElement, |
459 | | constructors::id::HTMLBaseElement, |
460 | | HTMLElement_Binding::sNativePropertyHooks, |
461 | | &DefaultXrayExpandoObjectClass |
462 | | } }; |
463 | | |
464 | | void |
465 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
466 | 0 | { |
467 | 0 | JS::Handle<JSObject*> parentProto(HTMLElement_Binding::GetProtoObjectHandle(aCx)); |
468 | 0 | if (!parentProto) { |
469 | 0 | return; |
470 | 0 | } |
471 | 0 | |
472 | 0 | JS::Handle<JSObject*> constructorProto(HTMLElement_Binding::GetConstructorObjectHandle(aCx)); |
473 | 0 | if (!constructorProto) { |
474 | 0 | return; |
475 | 0 | } |
476 | 0 | |
477 | 0 | static bool sIdsInited = false; |
478 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
479 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
480 | 0 | return; |
481 | 0 | } |
482 | 0 | sIdsInited = true; |
483 | 0 | } |
484 | 0 |
|
485 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::HTMLBaseElement); |
486 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::HTMLBaseElement); |
487 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
488 | 0 | &sPrototypeClass.mBase, protoCache, |
489 | 0 | nullptr, |
490 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
491 | 0 | interfaceCache, |
492 | 0 | sNativeProperties.Upcast(), |
493 | 0 | nullptr, |
494 | 0 | "HTMLBaseElement", aDefineOnGlobal, |
495 | 0 | nullptr, |
496 | 0 | false); |
497 | 0 | } |
498 | | |
499 | | JSObject* |
500 | | GetConstructorObject(JSContext* aCx) |
501 | 0 | { |
502 | 0 | return GetConstructorObjectHandle(aCx); |
503 | 0 | } |
504 | | |
505 | | } // namespace HTMLBaseElement_Binding |
506 | | |
507 | | |
508 | | |
509 | | } // namespace dom |
510 | | } // namespace mozilla |