Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM ErrorEvent.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "ErrorEventBinding.h"
5 : #include "EventBinding.h"
6 : #include "WrapperFactory.h"
7 : #include "mozilla/OwningNonNull.h"
8 : #include "mozilla/dom/BindingUtils.h"
9 : #include "mozilla/dom/DOMJSClass.h"
10 : #include "mozilla/dom/ErrorEvent.h"
11 : #include "mozilla/dom/NonRefcountedDOMObject.h"
12 : #include "mozilla/dom/PrimitiveConversions.h"
13 : #include "mozilla/dom/ScriptSettings.h"
14 : #include "mozilla/dom/XrayExpandoClass.h"
15 :
16 : namespace mozilla {
17 : namespace dom {
18 :
19 :
20 0 : ErrorEventInit::ErrorEventInit()
21 0 : : EventInit(FastDictionaryInitializer()),
22 0 : mError(JS::UndefinedValue())
23 : {
24 : // Safe to pass a null context if we pass a null value
25 0 : Init(nullptr, JS::NullHandleValue);
26 0 : }
27 :
28 :
29 : bool
30 0 : ErrorEventInit::InitIds(JSContext* cx, ErrorEventInitAtoms* atomsCache)
31 : {
32 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
33 :
34 : // Initialize these in reverse order so that any failure leaves the first one
35 : // uninitialized.
36 0 : if (!atomsCache->message_id.init(cx, "message") ||
37 0 : !atomsCache->lineno_id.init(cx, "lineno") ||
38 0 : !atomsCache->filename_id.init(cx, "filename") ||
39 0 : !atomsCache->error_id.init(cx, "error") ||
40 0 : !atomsCache->colno_id.init(cx, "colno")) {
41 0 : return false;
42 : }
43 0 : return true;
44 : }
45 :
46 : bool
47 0 : ErrorEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
48 : {
49 : // Passing a null JSContext is OK only if we're initing from null,
50 : // Since in that case we will not have to do any property gets
51 : // Also evaluate isNullOrUndefined in order to avoid false-positive
52 : // checkers by static analysis tools
53 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
54 0 : ErrorEventInitAtoms* atomsCache = nullptr;
55 0 : if (cx) {
56 0 : atomsCache = GetAtomCache<ErrorEventInitAtoms>(cx);
57 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
58 0 : return false;
59 : }
60 : }
61 :
62 : // Per spec, we init the parent's members first
63 0 : if (!EventInit::Init(cx, val)) {
64 0 : return false;
65 : }
66 :
67 0 : bool isNull = val.isNullOrUndefined();
68 : // We only need these if !isNull, in which case we have |cx|.
69 0 : Maybe<JS::Rooted<JSObject *> > object;
70 0 : Maybe<JS::Rooted<JS::Value> > temp;
71 0 : if (!isNull) {
72 0 : MOZ_ASSERT(cx);
73 0 : object.emplace(cx, &val.toObject());
74 0 : temp.emplace(cx);
75 : }
76 0 : if (!isNull) {
77 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->colno_id, temp.ptr())) {
78 0 : return false;
79 : }
80 : }
81 0 : if (!isNull && !temp->isUndefined()) {
82 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &mColno)) {
83 0 : return false;
84 : }
85 : } else {
86 0 : mColno = 0U;
87 : }
88 0 : mIsAnyMemberPresent = true;
89 :
90 0 : if (!isNull) {
91 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->error_id, temp.ptr())) {
92 0 : return false;
93 : }
94 : }
95 0 : if (!isNull && !temp->isUndefined()) {
96 : #ifdef __clang__
97 : #pragma clang diagnostic push
98 : #pragma clang diagnostic ignored "-Wunreachable-code"
99 : #pragma clang diagnostic ignored "-Wunreachable-code-return"
100 : #endif // __clang__
101 0 : if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) {
102 0 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'error' member of ErrorEventInit");
103 0 : return false;
104 : }
105 : #ifdef __clang__
106 : #pragma clang diagnostic pop
107 : #endif // __clang__
108 0 : mError = temp.ref();
109 : } else {
110 0 : mError = JS::NullValue();
111 : }
112 0 : mIsAnyMemberPresent = true;
113 :
114 0 : if (!isNull) {
115 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->filename_id, temp.ptr())) {
116 0 : return false;
117 : }
118 : }
119 0 : if (!isNull && !temp->isUndefined()) {
120 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mFilename)) {
121 0 : return false;
122 : }
123 : } else {
124 : static const char16_t data[] = { 0 };
125 0 : mFilename.Rebind(data, ArrayLength(data) - 1);
126 : }
127 0 : mIsAnyMemberPresent = true;
128 :
129 0 : if (!isNull) {
130 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->lineno_id, temp.ptr())) {
131 0 : return false;
132 : }
133 : }
134 0 : if (!isNull && !temp->isUndefined()) {
135 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &mLineno)) {
136 0 : return false;
137 : }
138 : } else {
139 0 : mLineno = 0U;
140 : }
141 0 : mIsAnyMemberPresent = true;
142 :
143 0 : if (!isNull) {
144 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->message_id, temp.ptr())) {
145 0 : return false;
146 : }
147 : }
148 0 : if (!isNull && !temp->isUndefined()) {
149 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mMessage)) {
150 0 : return false;
151 : }
152 : } else {
153 : static const char16_t data[] = { 0 };
154 0 : mMessage.Rebind(data, ArrayLength(data) - 1);
155 : }
156 0 : mIsAnyMemberPresent = true;
157 0 : return true;
158 : }
159 :
160 : bool
161 0 : ErrorEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
162 : {
163 0 : ErrorEventInitAtoms* atomsCache = GetAtomCache<ErrorEventInitAtoms>(cx);
164 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
165 0 : return false;
166 : }
167 :
168 : // Per spec, we define the parent's members first
169 0 : if (!EventInit::ToObjectInternal(cx, rval)) {
170 0 : return false;
171 : }
172 0 : JS::Rooted<JSObject*> obj(cx, &rval.toObject());
173 :
174 : do {
175 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
176 0 : JS::Rooted<JS::Value> temp(cx);
177 0 : uint32_t const & currentValue = mColno;
178 0 : temp.setNumber(currentValue);
179 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->colno_id, temp, JSPROP_ENUMERATE)) {
180 0 : return false;
181 : }
182 0 : break;
183 : } while(0);
184 :
185 : do {
186 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
187 0 : JS::Rooted<JS::Value> temp(cx);
188 0 : JS::Value const & currentValue = mError;
189 0 : JS::ExposeValueToActiveJS(currentValue);
190 0 : temp.set(currentValue);
191 0 : if (!MaybeWrapValue(cx, &temp)) {
192 0 : return false;
193 : }
194 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->error_id, temp, JSPROP_ENUMERATE)) {
195 0 : return false;
196 : }
197 0 : break;
198 : } while(0);
199 :
200 : do {
201 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
202 0 : JS::Rooted<JS::Value> temp(cx);
203 0 : nsString const & currentValue = mFilename;
204 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
205 0 : return false;
206 : }
207 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->filename_id, temp, JSPROP_ENUMERATE)) {
208 0 : return false;
209 : }
210 0 : break;
211 : } while(0);
212 :
213 : do {
214 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
215 0 : JS::Rooted<JS::Value> temp(cx);
216 0 : uint32_t const & currentValue = mLineno;
217 0 : temp.setNumber(currentValue);
218 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->lineno_id, temp, JSPROP_ENUMERATE)) {
219 0 : return false;
220 : }
221 0 : break;
222 : } while(0);
223 :
224 : do {
225 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
226 0 : JS::Rooted<JS::Value> temp(cx);
227 0 : nsString const & currentValue = mMessage;
228 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
229 0 : return false;
230 : }
231 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->message_id, temp, JSPROP_ENUMERATE)) {
232 0 : return false;
233 : }
234 0 : break;
235 : } while(0);
236 :
237 0 : return true;
238 : }
239 :
240 : void
241 0 : ErrorEventInit::TraceDictionary(JSTracer* trc)
242 : {
243 0 : EventInit::TraceDictionary(trc);
244 0 : JS::UnsafeTraceRoot(trc, &mError, "ErrorEventInit.mError");
245 0 : }
246 :
247 : namespace binding_detail {
248 : } // namespace binding_detail
249 :
250 :
251 : namespace ErrorEventBinding {
252 :
253 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventBinding::NativeType>::value,
254 : "Can't inherit from an interface with a different ownership model.");
255 :
256 : static bool
257 0 : get_message(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ErrorEvent* self, JSJitGetterCallArgs args)
258 : {
259 0 : DOMString result;
260 0 : self->GetMessage(result);
261 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
262 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
263 0 : return false;
264 : }
265 0 : return true;
266 : }
267 :
268 : static const JSJitInfo message_getterinfo = {
269 : { (JSJitGetterOp)get_message },
270 : { prototypes::id::ErrorEvent },
271 : { PrototypeTraits<prototypes::id::ErrorEvent>::Depth },
272 : JSJitInfo::Getter,
273 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
274 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
275 : false, /* isInfallible. False in setters. */
276 : false, /* isMovable. Not relevant for setters. */
277 : false, /* isEliminatable. Not relevant for setters. */
278 : false, /* isAlwaysInSlot. Only relevant for getters. */
279 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
280 : false, /* isTypedMethod. Only relevant for methods. */
281 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
282 : };
283 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
284 : static_assert(0 < 1, "There is no slot for us");
285 :
286 : static bool
287 0 : get_filename(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ErrorEvent* self, JSJitGetterCallArgs args)
288 : {
289 0 : DOMString result;
290 0 : self->GetFilename(result);
291 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
292 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
293 0 : return false;
294 : }
295 0 : return true;
296 : }
297 :
298 : static const JSJitInfo filename_getterinfo = {
299 : { (JSJitGetterOp)get_filename },
300 : { prototypes::id::ErrorEvent },
301 : { PrototypeTraits<prototypes::id::ErrorEvent>::Depth },
302 : JSJitInfo::Getter,
303 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
304 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
305 : false, /* isInfallible. False in setters. */
306 : false, /* isMovable. Not relevant for setters. */
307 : false, /* isEliminatable. Not relevant for setters. */
308 : false, /* isAlwaysInSlot. Only relevant for getters. */
309 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
310 : false, /* isTypedMethod. Only relevant for methods. */
311 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
312 : };
313 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
314 : static_assert(0 < 1, "There is no slot for us");
315 :
316 : static bool
317 0 : get_lineno(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ErrorEvent* self, JSJitGetterCallArgs args)
318 : {
319 0 : uint32_t result(self->Lineno());
320 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
321 0 : args.rval().setNumber(result);
322 0 : return true;
323 : }
324 :
325 : static const JSJitInfo lineno_getterinfo = {
326 : { (JSJitGetterOp)get_lineno },
327 : { prototypes::id::ErrorEvent },
328 : { PrototypeTraits<prototypes::id::ErrorEvent>::Depth },
329 : JSJitInfo::Getter,
330 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
331 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
332 : true, /* isInfallible. False in setters. */
333 : false, /* isMovable. Not relevant for setters. */
334 : false, /* isEliminatable. Not relevant for setters. */
335 : false, /* isAlwaysInSlot. Only relevant for getters. */
336 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
337 : false, /* isTypedMethod. Only relevant for methods. */
338 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
339 : };
340 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
341 : static_assert(0 < 1, "There is no slot for us");
342 :
343 : static bool
344 0 : get_colno(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ErrorEvent* self, JSJitGetterCallArgs args)
345 : {
346 0 : uint32_t result(self->Colno());
347 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
348 0 : args.rval().setNumber(result);
349 0 : return true;
350 : }
351 :
352 : static const JSJitInfo colno_getterinfo = {
353 : { (JSJitGetterOp)get_colno },
354 : { prototypes::id::ErrorEvent },
355 : { PrototypeTraits<prototypes::id::ErrorEvent>::Depth },
356 : JSJitInfo::Getter,
357 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
358 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
359 : true, /* isInfallible. False in setters. */
360 : false, /* isMovable. Not relevant for setters. */
361 : false, /* isEliminatable. Not relevant for setters. */
362 : false, /* isAlwaysInSlot. Only relevant for getters. */
363 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
364 : false, /* isTypedMethod. Only relevant for methods. */
365 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
366 : };
367 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
368 : static_assert(0 < 1, "There is no slot for us");
369 :
370 : static bool
371 0 : get_error(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ErrorEvent* self, JSJitGetterCallArgs args)
372 : {
373 0 : JS::Rooted<JS::Value> result(cx);
374 0 : self->GetError(cx, &result);
375 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
376 0 : JS::ExposeValueToActiveJS(result);
377 0 : args.rval().set(result);
378 0 : if (!MaybeWrapValue(cx, args.rval())) {
379 0 : return false;
380 : }
381 0 : return true;
382 : }
383 :
384 : static const JSJitInfo error_getterinfo = {
385 : { (JSJitGetterOp)get_error },
386 : { prototypes::id::ErrorEvent },
387 : { PrototypeTraits<prototypes::id::ErrorEvent>::Depth },
388 : JSJitInfo::Getter,
389 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
390 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
391 : false, /* isInfallible. False in setters. */
392 : false, /* isMovable. Not relevant for setters. */
393 : false, /* isEliminatable. Not relevant for setters. */
394 : false, /* isAlwaysInSlot. Only relevant for getters. */
395 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
396 : false, /* isTypedMethod. Only relevant for methods. */
397 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
398 : };
399 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
400 : static_assert(0 < 1, "There is no slot for us");
401 :
402 : static bool
403 0 : get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ErrorEvent* self, JSJitGetterCallArgs args)
404 : {
405 0 : bool result(self->IsTrusted());
406 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
407 0 : args.rval().setBoolean(result);
408 0 : return true;
409 : }
410 :
411 : static const JSJitInfo isTrusted_getterinfo = {
412 : { (JSJitGetterOp)get_isTrusted },
413 : { prototypes::id::ErrorEvent },
414 : { PrototypeTraits<prototypes::id::ErrorEvent>::Depth },
415 : JSJitInfo::Getter,
416 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
417 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
418 : true, /* isInfallible. False in setters. */
419 : true, /* isMovable. Not relevant for setters. */
420 : true, /* isEliminatable. Not relevant for setters. */
421 : false, /* isAlwaysInSlot. Only relevant for getters. */
422 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
423 : false, /* isTypedMethod. Only relevant for methods. */
424 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
425 : };
426 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
427 : static_assert(0 < 1, "There is no slot for us");
428 :
429 : static bool
430 1 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
431 : {
432 1 : mozilla::dom::ErrorEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ErrorEvent>(obj);
433 : // We don't want to preserve if we don't have a wrapper, and we
434 : // obviously can't preserve if we're not initialized.
435 1 : if (self && self->GetWrapperPreserveColor()) {
436 0 : PreserveWrapper(self);
437 : }
438 1 : return true;
439 : }
440 :
441 : static void
442 0 : _finalize(js::FreeOp* fop, JSObject* obj)
443 : {
444 0 : mozilla::dom::ErrorEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ErrorEvent>(obj);
445 0 : if (self) {
446 0 : ClearWrapper(self, self, obj);
447 0 : AddForDeferredFinalization<mozilla::dom::ErrorEvent>(self);
448 : }
449 0 : }
450 :
451 : static void
452 0 : _objectMoved(JSObject* obj, const JSObject* old)
453 : {
454 0 : mozilla::dom::ErrorEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ErrorEvent>(obj);
455 0 : if (self) {
456 0 : UpdateWrapper(self, self, obj, old);
457 : }
458 0 : }
459 :
460 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
461 : #if defined(__clang__)
462 : #pragma clang diagnostic push
463 : #pragma clang diagnostic ignored "-Wmissing-braces"
464 : #endif
465 : static const JSPropertySpec sAttributes_specs[] = {
466 : { "message", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &message_getterinfo, nullptr, nullptr },
467 : { "filename", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &filename_getterinfo, nullptr, nullptr },
468 : { "lineno", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &lineno_getterinfo, nullptr, nullptr },
469 : { "colno", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &colno_getterinfo, nullptr, nullptr },
470 : { "error", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &error_getterinfo, nullptr, nullptr },
471 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
472 : };
473 : #if defined(__clang__)
474 : #pragma clang diagnostic pop
475 : #endif
476 :
477 :
478 : // Can't be const because the pref-enabled boolean needs to be writable
479 : static Prefable<const JSPropertySpec> sAttributes[] = {
480 : { nullptr, &sAttributes_specs[0] },
481 : { nullptr, nullptr }
482 : };
483 :
484 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
485 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
486 : static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
487 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
488 :
489 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
490 : #if defined(__clang__)
491 : #pragma clang diagnostic push
492 : #pragma clang diagnostic ignored "-Wmissing-braces"
493 : #endif
494 : static const JSPropertySpec sUnforgeableAttributes_specs[] = {
495 : { "isTrusted", JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericBindingGetter, &isTrusted_getterinfo, nullptr, nullptr },
496 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
497 : };
498 : #if defined(__clang__)
499 : #pragma clang diagnostic pop
500 : #endif
501 :
502 :
503 : // Can't be const because the pref-enabled boolean needs to be writable
504 : static Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
505 : { nullptr, &sUnforgeableAttributes_specs[0] },
506 : { nullptr, nullptr }
507 : };
508 :
509 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
510 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
511 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
512 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
513 :
514 :
515 : static uint16_t sNativeProperties_sortedPropertyIndices[6];
516 : static PropertyInfo sNativeProperties_propertyInfos[6];
517 :
518 : static const NativePropertiesN<2> sNativeProperties = {
519 : false, 0,
520 : false, 0,
521 : false, 0,
522 : true, 0 /* sAttributes */,
523 : false, 0,
524 : true, 1 /* sUnforgeableAttributes */,
525 : false, 0,
526 : -1,
527 : 6,
528 : sNativeProperties_sortedPropertyIndices,
529 : {
530 : { sAttributes, &sNativeProperties_propertyInfos[0] },
531 : { sUnforgeableAttributes, &sNativeProperties_propertyInfos[5] }
532 : }
533 : };
534 : static_assert(6 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
535 : "We have a property info count that is oversized");
536 :
537 : static bool
538 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
539 : {
540 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
541 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
542 0 : if (!args.isConstructing()) {
543 : // XXXbz wish I could get the name from the callee instead of
544 : // Adding more relocations
545 0 : return ThrowConstructorWithoutNew(cx, "ErrorEvent");
546 : }
547 :
548 0 : GlobalObject global(cx, obj);
549 0 : if (global.Failed()) {
550 0 : return false;
551 : }
552 :
553 0 : JS::Rooted<JSObject*> desiredProto(cx);
554 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
555 0 : return false;
556 : }
557 :
558 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
559 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ErrorEvent");
560 : }
561 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
562 0 : binding_detail::FakeString arg0;
563 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
564 0 : return false;
565 : }
566 0 : RootedDictionary<binding_detail::FastErrorEventInit> arg1(cx);
567 0 : if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of ErrorEvent.constructor", false)) {
568 0 : return false;
569 : }
570 0 : Maybe<JSAutoCompartment> ac;
571 0 : if (objIsXray) {
572 0 : obj = js::CheckedUnwrap(obj);
573 0 : if (!obj) {
574 0 : return false;
575 : }
576 0 : ac.emplace(cx, obj);
577 0 : if (!JS_WrapObject(cx, &desiredProto)) {
578 0 : return false;
579 : }
580 0 : if (!JS_WrapValue(cx, JS::MutableHandle<JS::Value>::fromMarkedLocation(&arg1.mError))) {
581 0 : return false;
582 : }
583 : }
584 0 : binding_detail::FastErrorResult rv;
585 0 : auto result(StrongOrRawPtr<mozilla::dom::ErrorEvent>(mozilla::dom::ErrorEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
586 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
587 0 : return false;
588 : }
589 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
590 : static_assert(!IsPointer<decltype(result)>::value,
591 : "NewObject implies that we need to keep the object alive with a strong reference.");
592 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
593 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
594 0 : return false;
595 : }
596 0 : return true;
597 : }
598 :
599 : static const js::ClassOps sInterfaceObjectClassOps = {
600 : nullptr, /* addProperty */
601 : nullptr, /* delProperty */
602 : nullptr, /* getProperty */
603 : nullptr, /* setProperty */
604 : nullptr, /* enumerate */
605 : nullptr, /* newEnumerate */
606 : nullptr, /* resolve */
607 : nullptr, /* mayResolve */
608 : nullptr, /* finalize */
609 : _constructor, /* call */
610 : nullptr, /* hasInstance */
611 : _constructor, /* construct */
612 : nullptr, /* trace */
613 : };
614 :
615 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
616 : {
617 : "Function",
618 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
619 : &sInterfaceObjectClassOps,
620 : JS_NULL_CLASS_SPEC,
621 : JS_NULL_CLASS_EXT,
622 : &sInterfaceObjectClassObjectOps
623 : },
624 : eInterface,
625 : true,
626 : prototypes::id::ErrorEvent,
627 : PrototypeTraits<prototypes::id::ErrorEvent>::Depth,
628 : sNativePropertyHooks,
629 : "function ErrorEvent() {\n [native code]\n}",
630 : EventBinding::GetConstructorObject
631 : };
632 :
633 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
634 : {
635 : "ErrorEventPrototype",
636 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
637 : JS_NULL_CLASS_OPS,
638 : JS_NULL_CLASS_SPEC,
639 : JS_NULL_CLASS_EXT,
640 : JS_NULL_OBJECT_OPS
641 : },
642 : eInterfacePrototype,
643 : false,
644 : prototypes::id::ErrorEvent,
645 : PrototypeTraits<prototypes::id::ErrorEvent>::Depth,
646 : sNativePropertyHooks,
647 : "[object ErrorEventPrototype]",
648 : EventBinding::GetProtoObject
649 : };
650 :
651 : JSObject*
652 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
653 : {
654 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
655 : }
656 :
657 : static const js::ClassOps sClassOps = {
658 : _addProperty, /* addProperty */
659 : nullptr, /* delProperty */
660 : nullptr, /* getProperty */
661 : nullptr, /* setProperty */
662 : nullptr, /* enumerate */
663 : nullptr, /* newEnumerate */
664 : nullptr, /* resolve */
665 : nullptr, /* mayResolve */
666 : _finalize, /* finalize */
667 : nullptr, /* call */
668 : nullptr, /* hasInstance */
669 : nullptr, /* construct */
670 : nullptr, /* trace */
671 : };
672 :
673 : static const js::ClassExtension sClassExtension = {
674 : nullptr, /* weakmapKeyDelegateOp */
675 : _objectMoved /* objectMovedOp */
676 : };
677 :
678 : static const DOMJSClass sClass = {
679 : { "ErrorEvent",
680 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
681 : &sClassOps,
682 : JS_NULL_CLASS_SPEC,
683 : &sClassExtension,
684 : JS_NULL_OBJECT_OPS
685 : },
686 : { prototypes::id::Event, prototypes::id::ErrorEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
687 : IsBaseOf<nsISupports, mozilla::dom::ErrorEvent >::value,
688 : sNativePropertyHooks,
689 : FindAssociatedGlobalForNative<mozilla::dom::ErrorEvent>::Get,
690 : GetProtoObjectHandle,
691 : GetCCParticipant<mozilla::dom::ErrorEvent>::Get()
692 : };
693 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
694 : "Must have the right minimal number of reserved slots.");
695 : static_assert(1 >= 1,
696 : "Must have enough reserved slots.");
697 :
698 : const JSClass*
699 0 : GetJSClass()
700 : {
701 0 : return sClass.ToJSClass();
702 : }
703 :
704 : bool
705 0 : Wrap(JSContext* aCx, mozilla::dom::ErrorEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
706 : {
707 : MOZ_ASSERT(static_cast<mozilla::dom::ErrorEvent*>(aObject) ==
708 : reinterpret_cast<mozilla::dom::ErrorEvent*>(aObject),
709 : "Multiple inheritance for mozilla::dom::ErrorEvent is broken.");
710 : MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
711 : reinterpret_cast<mozilla::dom::Event*>(aObject),
712 : "Multiple inheritance for mozilla::dom::Event is broken.");
713 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
714 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
715 0 : MOZ_ASSERT(!aCache->GetWrapper(),
716 : "You should probably not be using Wrap() directly; use "
717 : "GetOrCreateDOMReflector instead");
718 :
719 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
720 : "nsISupports must be on our primary inheritance chain");
721 :
722 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
723 0 : if (!global) {
724 0 : return false;
725 : }
726 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
727 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
728 :
729 : // That might have ended up wrapping us already, due to the wonders
730 : // of XBL. Check for that, and bail out as needed.
731 0 : aReflector.set(aCache->GetWrapper());
732 0 : if (aReflector) {
733 : #ifdef DEBUG
734 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
735 : #endif // DEBUG
736 0 : return true;
737 : }
738 :
739 0 : JSAutoCompartment ac(aCx, global);
740 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
741 0 : if (!canonicalProto) {
742 0 : return false;
743 : }
744 0 : JS::Rooted<JSObject*> proto(aCx);
745 0 : if (aGivenProto) {
746 0 : proto = aGivenProto;
747 : // Unfortunately, while aGivenProto was in the compartment of aCx
748 : // coming in, we changed compartments to that of "parent" so may need
749 : // to wrap the proto here.
750 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
751 0 : if (!JS_WrapObject(aCx, &proto)) {
752 0 : return false;
753 : }
754 : }
755 : } else {
756 0 : proto = canonicalProto;
757 : }
758 :
759 0 : BindingJSObjectCreator<mozilla::dom::ErrorEvent> creator(aCx);
760 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
761 0 : if (!aReflector) {
762 0 : return false;
763 : }
764 :
765 0 : aCache->SetWrapper(aReflector);
766 :
767 : // Important: do unforgeable property setup after we have handed
768 : // over ownership of the C++ object to obj as needed, so that if
769 : // we fail and it ends up GCed it won't have problems in the
770 : // finalizer trying to drop its ownership of the C++ object.
771 : JS::Rooted<JSObject*> unforgeableHolder(aCx,
772 0 : &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
773 0 : if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
774 0 : aCache->ReleaseWrapper(aObject);
775 0 : aCache->ClearWrapper();
776 0 : return false;
777 : }
778 0 : creator.InitializationSucceeded();
779 :
780 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
781 : aCache->GetWrapperPreserveColor() == aReflector);
782 : // If proto != canonicalProto, we have to preserve our wrapper;
783 : // otherwise we won't be able to properly recreate it later, since
784 : // we won't know what proto to use. Note that we don't check
785 : // aGivenProto here, since it's entirely possible (and even
786 : // somewhat common) to have a non-null aGivenProto which is the
787 : // same as canonicalProto.
788 0 : if (proto != canonicalProto) {
789 0 : PreserveWrapper(aObject);
790 : }
791 :
792 0 : return true;
793 : }
794 :
795 : const NativePropertyHooks sNativePropertyHooks[] = { {
796 : nullptr,
797 : nullptr,
798 : nullptr,
799 : { sNativeProperties.Upcast(), nullptr },
800 : prototypes::id::ErrorEvent,
801 : constructors::id::ErrorEvent,
802 : EventBinding::sNativePropertyHooks,
803 : &DefaultXrayExpandoObjectClass
804 : } };
805 :
806 : void
807 1 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
808 : {
809 1 : JS::Handle<JSObject*> parentProto(EventBinding::GetProtoObjectHandle(aCx));
810 1 : if (!parentProto) {
811 0 : return;
812 : }
813 :
814 1 : JS::Handle<JSObject*> constructorProto(EventBinding::GetConstructorObjectHandle(aCx));
815 1 : if (!constructorProto) {
816 0 : return;
817 : }
818 :
819 : static bool sIdsInited = false;
820 1 : if (!sIdsInited && NS_IsMainThread()) {
821 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
822 0 : return;
823 : }
824 0 : sIdsInited = true;
825 : }
826 :
827 1 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ErrorEvent);
828 1 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ErrorEvent);
829 1 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
830 : &sPrototypeClass.mBase, protoCache,
831 : constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
832 : interfaceCache,
833 : sNativeProperties.Upcast(),
834 : nullptr,
835 : "ErrorEvent", aDefineOnGlobal,
836 : nullptr,
837 1 : false);
838 :
839 2 : JS::Rooted<JSObject*> unforgeableHolder(aCx);
840 : {
841 2 : JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
842 1 : unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
843 1 : if (!unforgeableHolder) {
844 0 : *protoCache = nullptr;
845 0 : if (interfaceCache) {
846 0 : *interfaceCache = nullptr;
847 : }
848 0 : return;
849 : }
850 : }
851 :
852 1 : if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
853 0 : *protoCache = nullptr;
854 0 : if (interfaceCache) {
855 0 : *interfaceCache = nullptr;
856 : }
857 0 : return;
858 : }
859 :
860 1 : if (*protoCache) {
861 1 : js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
862 2 : JS::ObjectValue(*unforgeableHolder));
863 : }
864 : }
865 :
866 : JS::Handle<JSObject*>
867 0 : GetProtoObjectHandle(JSContext* aCx)
868 : {
869 : /* Get the interface prototype object for this class. This will create the
870 : object as needed. */
871 0 : bool aDefineOnGlobal = true;
872 :
873 : /* Make sure our global is sane. Hopefully we can remove this sometime */
874 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
875 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
876 0 : return nullptr;
877 : }
878 :
879 : /* Check to see whether the interface objects are already installed */
880 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
881 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::ErrorEvent)) {
882 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
883 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
884 : }
885 :
886 : /*
887 : * The object might _still_ be null, but that's OK.
888 : *
889 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
890 : * traced by TraceProtoAndIfaceCache() and its contents are never
891 : * changed after they have been set.
892 : *
893 : * Calling address() avoids the read read barrier that does gray
894 : * unmarking, but it's not possible for the object to be gray here.
895 : */
896 :
897 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::ErrorEvent);
898 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
899 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
900 : }
901 :
902 : JS::Handle<JSObject*>
903 1 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
904 : {
905 : /* Get the interface object for this class. This will create the object as
906 : needed. */
907 :
908 : /* Make sure our global is sane. Hopefully we can remove this sometime */
909 1 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
910 1 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
911 0 : return nullptr;
912 : }
913 :
914 : /* Check to see whether the interface objects are already installed */
915 1 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
916 1 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::ErrorEvent)) {
917 2 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
918 1 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
919 : }
920 :
921 : /*
922 : * The object might _still_ be null, but that's OK.
923 : *
924 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
925 : * traced by TraceProtoAndIfaceCache() and its contents are never
926 : * changed after they have been set.
927 : *
928 : * Calling address() avoids the read read barrier that does gray
929 : * unmarking, but it's not possible for the object to be gray here.
930 : */
931 :
932 1 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::ErrorEvent);
933 1 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
934 1 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
935 : }
936 :
937 : JSObject*
938 1 : GetConstructorObject(JSContext* aCx)
939 : {
940 1 : return GetConstructorObjectHandle(aCx);
941 : }
942 :
943 : } // namespace ErrorEventBinding
944 :
945 :
946 :
947 : } // namespace dom
948 : } // namespace mozilla
|