Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM ImageData.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "ImageDataBinding.h"
4 : #include "WrapperFactory.h"
5 : #include "XrayWrapper.h"
6 : #include "jsfriendapi.h"
7 : #include "mozilla/OwningNonNull.h"
8 : #include "mozilla/dom/BindingUtils.h"
9 : #include "mozilla/dom/DOMJSClass.h"
10 : #include "mozilla/dom/ImageData.h"
11 : #include "mozilla/dom/NonRefcountedDOMObject.h"
12 : #include "mozilla/dom/PrimitiveConversions.h"
13 : #include "mozilla/dom/TypedArray.h"
14 : #include "mozilla/dom/XrayExpandoClass.h"
15 :
16 : namespace mozilla {
17 : namespace dom {
18 :
19 : namespace ImageDataBinding {
20 :
21 : static bool
22 0 : get_width(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ImageData* self, JSJitGetterCallArgs args)
23 : {
24 0 : uint32_t result(self->Width());
25 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
26 0 : args.rval().setNumber(result);
27 0 : return true;
28 : }
29 :
30 : static const JSJitInfo width_getterinfo = {
31 : { (JSJitGetterOp)get_width },
32 : { prototypes::id::ImageData },
33 : { PrototypeTraits<prototypes::id::ImageData>::Depth },
34 : JSJitInfo::Getter,
35 : JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */
36 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
37 : true, /* isInfallible. False in setters. */
38 : true, /* isMovable. Not relevant for setters. */
39 : true, /* isEliminatable. Not relevant for setters. */
40 : false, /* isAlwaysInSlot. Only relevant for getters. */
41 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
42 : false, /* isTypedMethod. Only relevant for methods. */
43 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
44 : };
45 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
46 : static_assert(0 < 2, "There is no slot for us");
47 :
48 : static bool
49 0 : get_height(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ImageData* self, JSJitGetterCallArgs args)
50 : {
51 0 : uint32_t result(self->Height());
52 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
53 0 : args.rval().setNumber(result);
54 0 : return true;
55 : }
56 :
57 : static const JSJitInfo height_getterinfo = {
58 : { (JSJitGetterOp)get_height },
59 : { prototypes::id::ImageData },
60 : { PrototypeTraits<prototypes::id::ImageData>::Depth },
61 : JSJitInfo::Getter,
62 : JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */
63 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
64 : true, /* isInfallible. False in setters. */
65 : true, /* isMovable. Not relevant for setters. */
66 : true, /* isEliminatable. Not relevant for setters. */
67 : false, /* isAlwaysInSlot. Only relevant for getters. */
68 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
69 : false, /* isTypedMethod. Only relevant for methods. */
70 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
71 : };
72 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
73 : static_assert(0 < 2, "There is no slot for us");
74 :
75 : static bool
76 0 : get_data(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ImageData* self, JSJitGetterCallArgs args)
77 : {
78 : // Have to either root across the getter call or reget after.
79 : bool isXray;
80 0 : JS::Rooted<JSObject*> slotStorage(cx, GetCachedSlotStorageObject(cx, obj, &isXray));
81 0 : if (!slotStorage) {
82 0 : return false;
83 : }
84 0 : const size_t slotIndex = isXray ? (xpc::JSSLOT_EXPANDO_COUNT + 0) : (DOM_INSTANCE_RESERVED_SLOTS + 0);
85 0 : MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex);
86 : {
87 : // Scope for cachedVal
88 0 : JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex);
89 0 : if (!cachedVal.isUndefined()) {
90 0 : args.rval().set(cachedVal);
91 : // The cached value is in the compartment of slotStorage,
92 : // so wrap into the caller compartment as needed.
93 0 : return MaybeWrapNonDOMObjectValue(cx, args.rval());
94 : }
95 : }
96 :
97 0 : JS::Rooted<JSObject*> result(cx);
98 0 : self->GetData(cx, &result);
99 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
100 : {
101 0 : JS::Rooted<JSObject*> conversionScope(cx, isXray ? obj : slotStorage);
102 0 : JSAutoCompartment ac(cx, conversionScope);
103 : do { // block we break out of when done wrapping
104 0 : JS::ExposeObjectToActiveJS(result);
105 0 : args.rval().setObject(*result);
106 0 : if (!MaybeWrapNonDOMObjectValue(cx, args.rval())) {
107 0 : return false;
108 : }
109 0 : break;
110 : } while (0);
111 : }
112 : { // And now store things in the compartment of our slotStorage.
113 0 : JSAutoCompartment ac(cx, slotStorage);
114 : // Make a copy so that we don't do unnecessary wrapping on args.rval().
115 0 : JS::Rooted<JS::Value> storedVal(cx, args.rval());
116 0 : if (!MaybeWrapNonDOMObjectValue(cx, &storedVal)) {
117 0 : return false;
118 : }
119 0 : js::SetReservedSlot(slotStorage, slotIndex, storedVal);
120 : }
121 : // And now make sure args.rval() is in the caller compartment
122 0 : return MaybeWrapNonDOMObjectValue(cx, args.rval());
123 : }
124 :
125 : static const JSJitInfo data_getterinfo = {
126 : { (JSJitGetterOp)get_data },
127 : { prototypes::id::ImageData },
128 : { PrototypeTraits<prototypes::id::ImageData>::Depth },
129 : JSJitInfo::Getter,
130 : JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */
131 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
132 : false, /* isInfallible. False in setters. */
133 : true, /* isMovable. Not relevant for setters. */
134 : true, /* isEliminatable. Not relevant for setters. */
135 : true, /* isAlwaysInSlot. Only relevant for getters. */
136 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
137 : false, /* isTypedMethod. Only relevant for methods. */
138 : (DOM_INSTANCE_RESERVED_SLOTS + 0) /* Reserved slot index, if we're stored in a slot, else 0. */
139 : };
140 : static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) <= JSJitInfo::maxSlotIndex, "We won't fit");
141 : static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) < 2, "There is no slot for us");
142 :
143 : static void
144 0 : _finalize(js::FreeOp* fop, JSObject* obj)
145 : {
146 0 : mozilla::dom::ImageData* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ImageData>(obj);
147 0 : if (self) {
148 0 : AddForDeferredFinalization<mozilla::dom::ImageData>(self);
149 : }
150 0 : }
151 :
152 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
153 : #if defined(__clang__)
154 : #pragma clang diagnostic push
155 : #pragma clang diagnostic ignored "-Wmissing-braces"
156 : #endif
157 : static const JSPropertySpec sAttributes_specs[] = {
158 : { "width", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &width_getterinfo, nullptr, nullptr },
159 : { "height", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &height_getterinfo, nullptr, nullptr },
160 : { "data", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &data_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(3 <= 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[3];
181 : static PropertyInfo sNativeProperties_propertyInfos[3];
182 :
183 : static const NativePropertiesN<1> sNativeProperties = {
184 : false, 0,
185 : false, 0,
186 : false, 0,
187 : true, 0 /* sAttributes */,
188 : false, 0,
189 : false, 0,
190 : false, 0,
191 : -1,
192 : 3,
193 : sNativeProperties_sortedPropertyIndices,
194 : {
195 : { sAttributes, &sNativeProperties_propertyInfos[0] }
196 : }
197 : };
198 : static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
199 : "We have a property info count that is oversized");
200 :
201 : static bool
202 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
203 : {
204 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
205 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
206 0 : if (!args.isConstructing()) {
207 : // XXXbz wish I could get the name from the callee instead of
208 : // Adding more relocations
209 0 : return ThrowConstructorWithoutNew(cx, "ImageData");
210 : }
211 :
212 0 : GlobalObject global(cx, obj);
213 0 : if (global.Failed()) {
214 0 : return false;
215 : }
216 :
217 0 : JS::Rooted<JSObject*> desiredProto(cx);
218 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
219 0 : return false;
220 : }
221 :
222 0 : unsigned argcount = std::min(args.length(), 3u);
223 0 : switch (argcount) {
224 : case 2: {
225 0 : if (args[0].isObject()) {
226 : do {
227 0 : RootedTypedArray<Uint8ClampedArray> arg0(cx);
228 0 : if (!arg0.Init(&args[0].toObject())) {
229 0 : break;
230 : }
231 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
232 : uint32_t arg1;
233 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) {
234 0 : return false;
235 : }
236 0 : Optional<uint32_t> arg2;
237 0 : if (args.hasDefined(2)) {
238 0 : arg2.Construct();
239 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[2], &arg2.Value())) {
240 0 : return false;
241 : }
242 : }
243 0 : Maybe<JSAutoCompartment> ac;
244 0 : if (objIsXray) {
245 0 : obj = js::CheckedUnwrap(obj);
246 0 : if (!obj) {
247 0 : return false;
248 : }
249 0 : ac.emplace(cx, obj);
250 0 : if (!JS_WrapObject(cx, &desiredProto)) {
251 0 : return false;
252 : }
253 0 : if (!arg0.WrapIntoNewCompartment(cx)) {
254 0 : return false;
255 : }
256 : }
257 0 : binding_detail::FastErrorResult rv;
258 0 : auto result(StrongOrRawPtr<mozilla::dom::ImageData>(mozilla::dom::ImageData::Constructor(global, Constify(arg0), arg1, Constify(arg2), rv)));
259 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
260 0 : return false;
261 : }
262 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
263 : static_assert(!IsPointer<decltype(result)>::value,
264 : "NewObject implies that we need to keep the object alive with a strong reference.");
265 0 : if (!WrapNewBindingNonWrapperCachedObject(cx, obj, result, args.rval(), desiredProto)) {
266 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
267 0 : return false;
268 : }
269 0 : return true;
270 : } while (0);
271 : }
272 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
273 : uint32_t arg0;
274 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
275 0 : return false;
276 : }
277 : uint32_t arg1;
278 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) {
279 0 : return false;
280 : }
281 0 : Maybe<JSAutoCompartment> ac;
282 0 : if (objIsXray) {
283 0 : obj = js::CheckedUnwrap(obj);
284 0 : if (!obj) {
285 0 : return false;
286 : }
287 0 : ac.emplace(cx, obj);
288 0 : if (!JS_WrapObject(cx, &desiredProto)) {
289 0 : return false;
290 : }
291 : }
292 0 : binding_detail::FastErrorResult rv;
293 0 : auto result(StrongOrRawPtr<mozilla::dom::ImageData>(mozilla::dom::ImageData::Constructor(global, arg0, arg1, rv)));
294 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
295 0 : return false;
296 : }
297 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
298 : static_assert(!IsPointer<decltype(result)>::value,
299 : "NewObject implies that we need to keep the object alive with a strong reference.");
300 0 : if (!WrapNewBindingNonWrapperCachedObject(cx, obj, result, args.rval(), desiredProto)) {
301 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
302 0 : return false;
303 : }
304 0 : return true;
305 : break;
306 : }
307 : case 3: {
308 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
309 0 : RootedTypedArray<Uint8ClampedArray> arg0(cx);
310 0 : if (args[0].isObject()) {
311 0 : if (!arg0.Init(&args[0].toObject())) {
312 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of ImageData.constructor", "Uint8ClampedArray");
313 0 : return false;
314 : }
315 : } else {
316 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of ImageData.constructor");
317 0 : return false;
318 : }
319 : uint32_t arg1;
320 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) {
321 0 : return false;
322 : }
323 0 : Optional<uint32_t> arg2;
324 0 : if (args.hasDefined(2)) {
325 0 : arg2.Construct();
326 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[2], &arg2.Value())) {
327 0 : return false;
328 : }
329 : }
330 0 : Maybe<JSAutoCompartment> ac;
331 0 : if (objIsXray) {
332 0 : obj = js::CheckedUnwrap(obj);
333 0 : if (!obj) {
334 0 : return false;
335 : }
336 0 : ac.emplace(cx, obj);
337 0 : if (!JS_WrapObject(cx, &desiredProto)) {
338 0 : return false;
339 : }
340 0 : if (!arg0.WrapIntoNewCompartment(cx)) {
341 0 : return false;
342 : }
343 : }
344 0 : binding_detail::FastErrorResult rv;
345 0 : auto result(StrongOrRawPtr<mozilla::dom::ImageData>(mozilla::dom::ImageData::Constructor(global, Constify(arg0), arg1, Constify(arg2), rv)));
346 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
347 0 : return false;
348 : }
349 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
350 : static_assert(!IsPointer<decltype(result)>::value,
351 : "NewObject implies that we need to keep the object alive with a strong reference.");
352 0 : if (!WrapNewBindingNonWrapperCachedObject(cx, obj, result, args.rval(), desiredProto)) {
353 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
354 0 : return false;
355 : }
356 0 : return true;
357 : break;
358 : }
359 : default: {
360 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ImageData");
361 : break;
362 : }
363 : }
364 : MOZ_CRASH("We have an always-returning default case");
365 : return false;
366 : }
367 :
368 : static const js::ClassOps sInterfaceObjectClassOps = {
369 : nullptr, /* addProperty */
370 : nullptr, /* delProperty */
371 : nullptr, /* getProperty */
372 : nullptr, /* setProperty */
373 : nullptr, /* enumerate */
374 : nullptr, /* newEnumerate */
375 : nullptr, /* resolve */
376 : nullptr, /* mayResolve */
377 : nullptr, /* finalize */
378 : _constructor, /* call */
379 : nullptr, /* hasInstance */
380 : _constructor, /* construct */
381 : nullptr, /* trace */
382 : };
383 :
384 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
385 : {
386 : "Function",
387 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
388 : &sInterfaceObjectClassOps,
389 : JS_NULL_CLASS_SPEC,
390 : JS_NULL_CLASS_EXT,
391 : &sInterfaceObjectClassObjectOps
392 : },
393 : eInterface,
394 : true,
395 : prototypes::id::ImageData,
396 : PrototypeTraits<prototypes::id::ImageData>::Depth,
397 : sNativePropertyHooks,
398 : "function ImageData() {\n [native code]\n}",
399 : JS::GetRealmFunctionPrototype
400 : };
401 :
402 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
403 : {
404 : "ImageDataPrototype",
405 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
406 : JS_NULL_CLASS_OPS,
407 : JS_NULL_CLASS_SPEC,
408 : JS_NULL_CLASS_EXT,
409 : JS_NULL_OBJECT_OPS
410 : },
411 : eInterfacePrototype,
412 : false,
413 : prototypes::id::ImageData,
414 : PrototypeTraits<prototypes::id::ImageData>::Depth,
415 : sNativePropertyHooks,
416 : "[object ImageDataPrototype]",
417 : JS::GetRealmObjectPrototype
418 : };
419 :
420 : JSObject*
421 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
422 : {
423 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
424 : }
425 :
426 : static const js::ClassOps sClassOps = {
427 : nullptr, /* addProperty */
428 : nullptr, /* delProperty */
429 : nullptr, /* getProperty */
430 : nullptr, /* setProperty */
431 : nullptr, /* enumerate */
432 : nullptr, /* newEnumerate */
433 : nullptr, /* resolve */
434 : nullptr, /* mayResolve */
435 : _finalize, /* finalize */
436 : nullptr, /* call */
437 : nullptr, /* hasInstance */
438 : nullptr, /* construct */
439 : nullptr, /* trace */
440 : };
441 :
442 : static const js::ClassExtension sClassExtension = {
443 : nullptr, /* weakmapKeyDelegateOp */
444 : nullptr /* objectMovedOp */
445 : };
446 :
447 : static const DOMJSClass sClass = {
448 : { "ImageData",
449 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(2),
450 : &sClassOps,
451 : JS_NULL_CLASS_SPEC,
452 : &sClassExtension,
453 : JS_NULL_OBJECT_OPS
454 : },
455 : { prototypes::id::ImageData, 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 },
456 : IsBaseOf<nsISupports, mozilla::dom::ImageData >::value,
457 : sNativePropertyHooks,
458 : FindAssociatedGlobalForNative<mozilla::dom::ImageData>::Get,
459 : GetProtoObjectHandle,
460 : GetCCParticipant<mozilla::dom::ImageData>::Get()
461 : };
462 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
463 : "Must have the right minimal number of reserved slots.");
464 : static_assert(2 >= 2,
465 : "Must have enough reserved slots.");
466 :
467 : const JSClass*
468 0 : GetJSClass()
469 : {
470 0 : return sClass.ToJSClass();
471 : }
472 :
473 : static bool
474 0 : UpdateMemberSlots(JSContext* aCx, JS::Handle<JSObject*> aWrapper, mozilla::dom::ImageData* aObject)
475 : {
476 0 : JS::Rooted<JS::Value> temp(aCx);
477 0 : JSJitGetterCallArgs args(&temp);
478 :
479 : static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) < js::shadow::Object::MAX_FIXED_SLOTS,
480 : "Not enough fixed slots to fit 'ImageData.data. Ion's visitGetDOMMemberV/visitGetDOMMemberT assume StoreInSlot things are all in fixed slots.");
481 0 : if (!get_data(aCx, aWrapper, aObject, args)) {
482 0 : return false;
483 : }
484 : // Getter handled setting our reserved slots
485 :
486 0 : return true;
487 : }
488 :
489 : bool
490 0 : Wrap(JSContext* aCx, mozilla::dom::ImageData* aObject, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
491 : {
492 : MOZ_ASSERT(static_cast<mozilla::dom::ImageData*>(aObject) ==
493 : reinterpret_cast<mozilla::dom::ImageData*>(aObject),
494 : "Multiple inheritance for mozilla::dom::ImageData is broken.");
495 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
496 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
497 :
498 0 : JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
499 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
500 0 : if (!canonicalProto) {
501 0 : return false;
502 : }
503 0 : JS::Rooted<JSObject*> proto(aCx);
504 0 : if (aGivenProto) {
505 0 : proto = aGivenProto;
506 : // Unfortunately, while aGivenProto was in the compartment of aCx
507 : // coming in, we changed compartments to that of "parent" so may need
508 : // to wrap the proto here.
509 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
510 0 : if (!JS_WrapObject(aCx, &proto)) {
511 0 : return false;
512 : }
513 : }
514 : } else {
515 0 : proto = canonicalProto;
516 : }
517 :
518 0 : BindingJSObjectCreator<mozilla::dom::ImageData> creator(aCx);
519 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
520 0 : if (!aReflector) {
521 0 : return false;
522 : }
523 :
524 :
525 0 : if (!UpdateMemberSlots(aCx, aReflector, aObject)) {
526 0 : return false;
527 : }
528 :
529 0 : creator.InitializationSucceeded();
530 0 : return true;
531 : }
532 :
533 : // This may allocate too many slots, because we only really need
534 : // slots for our non-interface-typed members that we cache. But
535 : // allocating slots only for those would make the slot index
536 : // computations much more complicated, so let's do this the simple
537 : // way for now.
538 : DEFINE_XRAY_EXPANDO_CLASS(static, sXrayExpandoObjectClass, 1);
539 :
540 : const NativePropertyHooks sNativePropertyHooks[] = { {
541 : nullptr,
542 : nullptr,
543 : nullptr,
544 : { sNativeProperties.Upcast(), nullptr },
545 : prototypes::id::ImageData,
546 : constructors::id::ImageData,
547 : nullptr,
548 : &sXrayExpandoObjectClass
549 : } };
550 :
551 : void
552 1 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
553 : {
554 2 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
555 1 : if (!parentProto) {
556 0 : return;
557 : }
558 :
559 2 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
560 1 : if (!constructorProto) {
561 0 : return;
562 : }
563 :
564 : static bool sIdsInited = false;
565 1 : if (!sIdsInited && NS_IsMainThread()) {
566 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
567 0 : return;
568 : }
569 0 : sIdsInited = true;
570 : }
571 :
572 1 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ImageData);
573 1 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ImageData);
574 2 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
575 : &sPrototypeClass.mBase, protoCache,
576 : constructorProto, &sInterfaceObjectClass.mBase, 2, nullptr,
577 : interfaceCache,
578 : sNativeProperties.Upcast(),
579 : nullptr,
580 : "ImageData", aDefineOnGlobal,
581 : nullptr,
582 1 : false);
583 : }
584 :
585 : JS::Handle<JSObject*>
586 0 : GetProtoObjectHandle(JSContext* aCx)
587 : {
588 : /* Get the interface prototype object for this class. This will create the
589 : object as needed. */
590 0 : bool aDefineOnGlobal = true;
591 :
592 : /* Make sure our global is sane. Hopefully we can remove this sometime */
593 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
594 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
595 0 : return nullptr;
596 : }
597 :
598 : /* Check to see whether the interface objects are already installed */
599 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
600 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::ImageData)) {
601 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
602 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
603 : }
604 :
605 : /*
606 : * The object might _still_ be null, but that's OK.
607 : *
608 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
609 : * traced by TraceProtoAndIfaceCache() and its contents are never
610 : * changed after they have been set.
611 : *
612 : * Calling address() avoids the read read barrier that does gray
613 : * unmarking, but it's not possible for the object to be gray here.
614 : */
615 :
616 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::ImageData);
617 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
618 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
619 : }
620 :
621 : JS::Handle<JSObject*>
622 1 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
623 : {
624 : /* Get the interface object for this class. This will create the object as
625 : needed. */
626 :
627 : /* Make sure our global is sane. Hopefully we can remove this sometime */
628 1 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
629 1 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
630 0 : return nullptr;
631 : }
632 :
633 : /* Check to see whether the interface objects are already installed */
634 1 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
635 1 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::ImageData)) {
636 2 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
637 1 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
638 : }
639 :
640 : /*
641 : * The object might _still_ be null, but that's OK.
642 : *
643 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
644 : * traced by TraceProtoAndIfaceCache() and its contents are never
645 : * changed after they have been set.
646 : *
647 : * Calling address() avoids the read read barrier that does gray
648 : * unmarking, but it's not possible for the object to be gray here.
649 : */
650 :
651 1 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::ImageData);
652 1 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
653 1 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
654 : }
655 :
656 : JSObject*
657 1 : GetConstructorObject(JSContext* aCx)
658 : {
659 1 : return GetConstructorObjectHandle(aCx);
660 : }
661 :
662 : } // namespace ImageDataBinding
663 :
664 :
665 :
666 : } // namespace dom
667 : } // namespace mozilla
|