/work/obj-fuzz/dom/bindings/DOMExceptionBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM DOMException.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "DOMExceptionBinding.h" |
4 | | #include "WrapperFactory.h" |
5 | | #include "mozilla/OwningNonNull.h" |
6 | | #include "mozilla/dom/BindingUtils.h" |
7 | | #include "mozilla/dom/DOMException.h" |
8 | | #include "mozilla/dom/DOMJSClass.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 "nsContentUtils.h" |
14 | | #include "nsIException.h" |
15 | | #include "nsISupports.h" |
16 | | |
17 | | namespace mozilla { |
18 | | namespace dom { |
19 | | |
20 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
21 | | using namespace mozilla::dom::binding_detail; |
22 | | |
23 | | |
24 | | namespace DOMException_Binding { |
25 | | |
26 | | MOZ_CAN_RUN_SCRIPT static bool |
27 | | get_name(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMException* self, JSJitGetterCallArgs args) |
28 | 0 | { |
29 | 0 | AUTO_PROFILER_LABEL_FAST("get DOMException.name", DOM, cx); |
30 | 0 |
|
31 | 0 | DOMString result; |
32 | 0 | self->GetName(result); |
33 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
34 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
35 | 0 | return false; |
36 | 0 | } |
37 | 0 | return true; |
38 | 0 | } |
39 | | |
40 | | static const JSJitInfo name_getterinfo = { |
41 | | { (JSJitGetterOp)get_name }, |
42 | | { prototypes::id::DOMException }, |
43 | | { PrototypeTraits<prototypes::id::DOMException>::Depth }, |
44 | | JSJitInfo::Getter, |
45 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
46 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
47 | | false, /* isInfallible. False in setters. */ |
48 | | false, /* isMovable. Not relevant for setters. */ |
49 | | false, /* isEliminatable. Not relevant for setters. */ |
50 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
51 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
52 | | false, /* isTypedMethod. Only relevant for methods. */ |
53 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
54 | | }; |
55 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
56 | | static_assert(0 < 1, "There is no slot for us"); |
57 | | |
58 | | MOZ_CAN_RUN_SCRIPT static bool |
59 | | get_message(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMException* self, JSJitGetterCallArgs args) |
60 | 0 | { |
61 | 0 | AUTO_PROFILER_LABEL_FAST("get DOMException.message", DOM, cx); |
62 | 0 |
|
63 | 0 | DOMString result; |
64 | 0 | self->GetMessageMoz(result); |
65 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
66 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
67 | 0 | return false; |
68 | 0 | } |
69 | 0 | return true; |
70 | 0 | } |
71 | | |
72 | | static const JSJitInfo message_getterinfo = { |
73 | | { (JSJitGetterOp)get_message }, |
74 | | { prototypes::id::DOMException }, |
75 | | { PrototypeTraits<prototypes::id::DOMException>::Depth }, |
76 | | JSJitInfo::Getter, |
77 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
78 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
79 | | false, /* isInfallible. False in setters. */ |
80 | | false, /* isMovable. Not relevant for setters. */ |
81 | | false, /* isEliminatable. Not relevant for setters. */ |
82 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
83 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
84 | | false, /* isTypedMethod. Only relevant for methods. */ |
85 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
86 | | }; |
87 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
88 | | static_assert(0 < 1, "There is no slot for us"); |
89 | | |
90 | | MOZ_CAN_RUN_SCRIPT static bool |
91 | | get_code(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMException* self, JSJitGetterCallArgs args) |
92 | 0 | { |
93 | 0 | AUTO_PROFILER_LABEL_FAST("get DOMException.code", DOM, cx); |
94 | 0 |
|
95 | 0 | uint16_t result(self->Code()); |
96 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
97 | 0 | args.rval().setInt32(int32_t(result)); |
98 | 0 | return true; |
99 | 0 | } |
100 | | |
101 | | static const JSJitInfo code_getterinfo = { |
102 | | { (JSJitGetterOp)get_code }, |
103 | | { prototypes::id::DOMException }, |
104 | | { PrototypeTraits<prototypes::id::DOMException>::Depth }, |
105 | | JSJitInfo::Getter, |
106 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
107 | | JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */ |
108 | | true, /* isInfallible. False in setters. */ |
109 | | false, /* isMovable. Not relevant for setters. */ |
110 | | false, /* isEliminatable. Not relevant for setters. */ |
111 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
112 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
113 | | false, /* isTypedMethod. Only relevant for methods. */ |
114 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
115 | | }; |
116 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
117 | | static_assert(0 < 1, "There is no slot for us"); |
118 | | |
119 | | MOZ_CAN_RUN_SCRIPT static bool |
120 | | get_result(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMException* self, JSJitGetterCallArgs args) |
121 | 0 | { |
122 | 0 | AUTO_PROFILER_LABEL_FAST("get DOMException.result", DOM, cx); |
123 | 0 |
|
124 | 0 | uint32_t result(self->Result()); |
125 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
126 | 0 | args.rval().setNumber(result); |
127 | 0 | return true; |
128 | 0 | } |
129 | | |
130 | | static const JSJitInfo result_getterinfo = { |
131 | | { (JSJitGetterOp)get_result }, |
132 | | { prototypes::id::DOMException }, |
133 | | { PrototypeTraits<prototypes::id::DOMException>::Depth }, |
134 | | JSJitInfo::Getter, |
135 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
136 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
137 | | true, /* isInfallible. False in setters. */ |
138 | | false, /* isMovable. Not relevant for setters. */ |
139 | | false, /* isEliminatable. Not relevant for setters. */ |
140 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
141 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
142 | | false, /* isTypedMethod. Only relevant for methods. */ |
143 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
144 | | }; |
145 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
146 | | static_assert(0 < 1, "There is no slot for us"); |
147 | | |
148 | | MOZ_CAN_RUN_SCRIPT static bool |
149 | | get_filename(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMException* self, JSJitGetterCallArgs args) |
150 | 0 | { |
151 | 0 | AUTO_PROFILER_LABEL_FAST("get DOMException.filename", DOM, cx); |
152 | 0 |
|
153 | 0 | DOMString result; |
154 | 0 | self->GetFilename(cx, result); |
155 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
156 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
157 | 0 | return false; |
158 | 0 | } |
159 | 0 | return true; |
160 | 0 | } |
161 | | |
162 | | static const JSJitInfo filename_getterinfo = { |
163 | | { (JSJitGetterOp)get_filename }, |
164 | | { prototypes::id::DOMException }, |
165 | | { PrototypeTraits<prototypes::id::DOMException>::Depth }, |
166 | | JSJitInfo::Getter, |
167 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
168 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
169 | | false, /* isInfallible. False in setters. */ |
170 | | false, /* isMovable. Not relevant for setters. */ |
171 | | false, /* isEliminatable. Not relevant for setters. */ |
172 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
173 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
174 | | false, /* isTypedMethod. Only relevant for methods. */ |
175 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
176 | | }; |
177 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
178 | | static_assert(0 < 1, "There is no slot for us"); |
179 | | |
180 | | MOZ_CAN_RUN_SCRIPT static bool |
181 | | get_lineNumber(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMException* self, JSJitGetterCallArgs args) |
182 | 0 | { |
183 | 0 | AUTO_PROFILER_LABEL_FAST("get DOMException.lineNumber", DOM, cx); |
184 | 0 |
|
185 | 0 | uint32_t result(self->LineNumber(cx)); |
186 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
187 | 0 | args.rval().setNumber(result); |
188 | 0 | return true; |
189 | 0 | } |
190 | | |
191 | | static const JSJitInfo lineNumber_getterinfo = { |
192 | | { (JSJitGetterOp)get_lineNumber }, |
193 | | { prototypes::id::DOMException }, |
194 | | { PrototypeTraits<prototypes::id::DOMException>::Depth }, |
195 | | JSJitInfo::Getter, |
196 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
197 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
198 | | true, /* isInfallible. False in setters. */ |
199 | | false, /* isMovable. Not relevant for setters. */ |
200 | | false, /* isEliminatable. Not relevant for setters. */ |
201 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
202 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
203 | | false, /* isTypedMethod. Only relevant for methods. */ |
204 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
205 | | }; |
206 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
207 | | static_assert(0 < 1, "There is no slot for us"); |
208 | | |
209 | | MOZ_CAN_RUN_SCRIPT static bool |
210 | | get_columnNumber(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMException* self, JSJitGetterCallArgs args) |
211 | 0 | { |
212 | 0 | AUTO_PROFILER_LABEL_FAST("get DOMException.columnNumber", DOM, cx); |
213 | 0 |
|
214 | 0 | uint32_t result(self->ColumnNumber()); |
215 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
216 | 0 | args.rval().setNumber(result); |
217 | 0 | return true; |
218 | 0 | } |
219 | | |
220 | | static const JSJitInfo columnNumber_getterinfo = { |
221 | | { (JSJitGetterOp)get_columnNumber }, |
222 | | { prototypes::id::DOMException }, |
223 | | { PrototypeTraits<prototypes::id::DOMException>::Depth }, |
224 | | JSJitInfo::Getter, |
225 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
226 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
227 | | true, /* isInfallible. False in setters. */ |
228 | | false, /* isMovable. Not relevant for setters. */ |
229 | | false, /* isEliminatable. Not relevant for setters. */ |
230 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
231 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
232 | | false, /* isTypedMethod. Only relevant for methods. */ |
233 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
234 | | }; |
235 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
236 | | static_assert(0 < 1, "There is no slot for us"); |
237 | | |
238 | | MOZ_CAN_RUN_SCRIPT static bool |
239 | | get_location(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMException* self, JSJitGetterCallArgs args) |
240 | 0 | { |
241 | 0 | AUTO_PROFILER_LABEL_FAST("get DOMException.location", DOM, cx); |
242 | 0 |
|
243 | 0 | auto result(StrongOrRawPtr<nsIStackFrame>(self->GetLocation())); |
244 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
245 | 0 | if (!result) { |
246 | 0 | args.rval().setNull(); |
247 | 0 | return true; |
248 | 0 | } |
249 | 0 | if (!WrapObject(cx, result, &NS_GET_IID(nsIStackFrame), args.rval())) { |
250 | 0 | return false; |
251 | 0 | } |
252 | 0 | return true; |
253 | 0 | } |
254 | | |
255 | | static const JSJitInfo location_getterinfo = { |
256 | | { (JSJitGetterOp)get_location }, |
257 | | { prototypes::id::DOMException }, |
258 | | { PrototypeTraits<prototypes::id::DOMException>::Depth }, |
259 | | JSJitInfo::Getter, |
260 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
261 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
262 | | false, /* isInfallible. False in setters. */ |
263 | | false, /* isMovable. Not relevant for setters. */ |
264 | | false, /* isEliminatable. Not relevant for setters. */ |
265 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
266 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
267 | | false, /* isTypedMethod. Only relevant for methods. */ |
268 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
269 | | }; |
270 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
271 | | static_assert(0 < 1, "There is no slot for us"); |
272 | | |
273 | | MOZ_CAN_RUN_SCRIPT static bool |
274 | | get_data(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMException* self, JSJitGetterCallArgs args) |
275 | 0 | { |
276 | 0 | AUTO_PROFILER_LABEL_FAST("get DOMException.data", DOM, cx); |
277 | 0 |
|
278 | 0 | auto result(StrongOrRawPtr<nsISupports>(self->GetData())); |
279 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
280 | 0 | if (!result) { |
281 | 0 | args.rval().setNull(); |
282 | 0 | return true; |
283 | 0 | } |
284 | 0 | if (!WrapObject(cx, result, args.rval())) { |
285 | 0 | return false; |
286 | 0 | } |
287 | 0 | return true; |
288 | 0 | } |
289 | | |
290 | | static const JSJitInfo data_getterinfo = { |
291 | | { (JSJitGetterOp)get_data }, |
292 | | { prototypes::id::DOMException }, |
293 | | { PrototypeTraits<prototypes::id::DOMException>::Depth }, |
294 | | JSJitInfo::Getter, |
295 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
296 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
297 | | false, /* isInfallible. False in setters. */ |
298 | | false, /* isMovable. Not relevant for setters. */ |
299 | | false, /* isEliminatable. Not relevant for setters. */ |
300 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
301 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
302 | | false, /* isTypedMethod. Only relevant for methods. */ |
303 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
304 | | }; |
305 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
306 | | static_assert(0 < 1, "There is no slot for us"); |
307 | | |
308 | | MOZ_CAN_RUN_SCRIPT static bool |
309 | | get_stack(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMException* self, JSJitGetterCallArgs args) |
310 | 0 | { |
311 | 0 | AUTO_PROFILER_LABEL_FAST("get DOMException.stack", DOM, cx); |
312 | 0 |
|
313 | 0 | DOMString result; |
314 | 0 | self->GetStack(cx, result); |
315 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
316 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
317 | 0 | return false; |
318 | 0 | } |
319 | 0 | return true; |
320 | 0 | } |
321 | | |
322 | | MOZ_CAN_RUN_SCRIPT static bool |
323 | | set_stack(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMException* self, JSJitSetterCallArgs args) |
324 | 0 | { |
325 | 0 | AUTO_PROFILER_LABEL_FAST("set DOMException.stack", DOM, cx); |
326 | 0 |
|
327 | 0 | return JS_DefineProperty(cx, obj, "stack", args[0], JSPROP_ENUMERATE); |
328 | 0 | } |
329 | | |
330 | | static const JSJitInfo stack_getterinfo = { |
331 | | { (JSJitGetterOp)get_stack }, |
332 | | { prototypes::id::DOMException }, |
333 | | { PrototypeTraits<prototypes::id::DOMException>::Depth }, |
334 | | JSJitInfo::Getter, |
335 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
336 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
337 | | false, /* isInfallible. False in setters. */ |
338 | | false, /* isMovable. Not relevant for setters. */ |
339 | | false, /* isEliminatable. Not relevant for setters. */ |
340 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
341 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
342 | | false, /* isTypedMethod. Only relevant for methods. */ |
343 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
344 | | }; |
345 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
346 | | static_assert(0 < 1, "There is no slot for us"); |
347 | | static const JSJitInfo stack_setterinfo = { |
348 | | { (JSJitGetterOp)set_stack }, |
349 | | { prototypes::id::DOMException }, |
350 | | { PrototypeTraits<prototypes::id::DOMException>::Depth }, |
351 | | JSJitInfo::Setter, |
352 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
353 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
354 | | false, /* isInfallible. False in setters. */ |
355 | | false, /* isMovable. Not relevant for setters. */ |
356 | | false, /* isEliminatable. Not relevant for setters. */ |
357 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
358 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
359 | | false, /* isTypedMethod. Only relevant for methods. */ |
360 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
361 | | }; |
362 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
363 | | static_assert(0 < 1, "There is no slot for us"); |
364 | | |
365 | | static bool |
366 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
367 | 0 | { |
368 | 0 | mozilla::dom::DOMException* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DOMException>(obj); |
369 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
370 | 0 | // obviously can't preserve if we're not initialized. |
371 | 0 | if (self && self->GetWrapperPreserveColor()) { |
372 | 0 | PreserveWrapper(self); |
373 | 0 | } |
374 | 0 | return true; |
375 | 0 | } |
376 | | |
377 | | static void |
378 | | _finalize(js::FreeOp* fop, JSObject* obj) |
379 | 0 | { |
380 | 0 | mozilla::dom::DOMException* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DOMException>(obj); |
381 | 0 | if (self) { |
382 | 0 | ClearWrapper(self, self, obj); |
383 | 0 | AddForDeferredFinalization<mozilla::dom::DOMException>(self); |
384 | 0 | } |
385 | 0 | } |
386 | | |
387 | | static size_t |
388 | | _objectMoved(JSObject* obj, JSObject* old) |
389 | 0 | { |
390 | 0 | mozilla::dom::DOMException* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DOMException>(obj); |
391 | 0 | if (self) { |
392 | 0 | UpdateWrapper(self, self, obj, old); |
393 | 0 | } |
394 | 0 |
|
395 | 0 | return 0; |
396 | 0 | } |
397 | | |
398 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
399 | | #if defined(__clang__) |
400 | | #pragma clang diagnostic push |
401 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
402 | | #endif |
403 | | static const JSPropertySpec sAttributes_specs[] = { |
404 | | { "name", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &name_getterinfo, nullptr, nullptr }, |
405 | | { "message", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &message_getterinfo, nullptr, nullptr }, |
406 | | { "code", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &code_getterinfo, nullptr, nullptr }, |
407 | | { "result", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &result_getterinfo, nullptr, nullptr }, |
408 | | { "filename", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &filename_getterinfo, nullptr, nullptr }, |
409 | | { "lineNumber", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &lineNumber_getterinfo, nullptr, nullptr }, |
410 | | { "columnNumber", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &columnNumber_getterinfo, nullptr, nullptr }, |
411 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr }, |
412 | | { "data", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &data_getterinfo, nullptr, nullptr }, |
413 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr }, |
414 | | { "stack", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &stack_getterinfo, GenericSetter<NormalThisPolicy>, &stack_setterinfo }, |
415 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
416 | | }; |
417 | | #if defined(__clang__) |
418 | | #pragma clang diagnostic pop |
419 | | #endif |
420 | | |
421 | | // Can't be const because the pref-enabled boolean needs to be writable |
422 | | static PrefableDisablers sAttributes_disablers8 = { |
423 | | true, false, GlobalNames::BackstagePass | GlobalNames::DedicatedWorkerGlobalScope | GlobalNames::ServiceWorkerGlobalScope | GlobalNames::SharedWorkerGlobalScope, nullptr |
424 | | }; |
425 | | |
426 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
427 | | { nullptr, &sAttributes_specs[0] }, |
428 | | { &sAttributes_disablers8, &sAttributes_specs[8] }, |
429 | | { nullptr, &sAttributes_specs[10] }, |
430 | | { nullptr, nullptr } |
431 | | }; |
432 | | |
433 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
434 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
435 | | static_assert(7 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
436 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
437 | | |
438 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
439 | | #if defined(__clang__) |
440 | | #pragma clang diagnostic push |
441 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
442 | | #endif |
443 | | static const JSPropertySpec sChromeAttributes_specs[] = { |
444 | | { "location", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &location_getterinfo, nullptr, nullptr }, |
445 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
446 | | }; |
447 | | #if defined(__clang__) |
448 | | #pragma clang diagnostic pop |
449 | | #endif |
450 | | |
451 | | // Can't be const because the pref-enabled boolean needs to be writable |
452 | | static PrefableDisablers sChromeAttributes_disablers0 = { |
453 | | true, false, GlobalNames::BackstagePass | GlobalNames::DedicatedWorkerGlobalScope | GlobalNames::ServiceWorkerGlobalScope | GlobalNames::SharedWorkerGlobalScope, nullptr |
454 | | }; |
455 | | |
456 | | static const Prefable<const JSPropertySpec> sChromeAttributes[] = { |
457 | | { &sChromeAttributes_disablers0, &sChromeAttributes_specs[0] }, |
458 | | { nullptr, nullptr } |
459 | | }; |
460 | | |
461 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
462 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
463 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
464 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
465 | | |
466 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
467 | | #if defined(__clang__) |
468 | | #pragma clang diagnostic push |
469 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
470 | | #endif |
471 | | static const ConstantSpec sConstants_specs[] = { |
472 | | { "INDEX_SIZE_ERR", JS::Int32Value(1) }, |
473 | | { "DOMSTRING_SIZE_ERR", JS::Int32Value(2) }, |
474 | | { "HIERARCHY_REQUEST_ERR", JS::Int32Value(3) }, |
475 | | { "WRONG_DOCUMENT_ERR", JS::Int32Value(4) }, |
476 | | { "INVALID_CHARACTER_ERR", JS::Int32Value(5) }, |
477 | | { "NO_DATA_ALLOWED_ERR", JS::Int32Value(6) }, |
478 | | { "NO_MODIFICATION_ALLOWED_ERR", JS::Int32Value(7) }, |
479 | | { "NOT_FOUND_ERR", JS::Int32Value(8) }, |
480 | | { "NOT_SUPPORTED_ERR", JS::Int32Value(9) }, |
481 | | { "INUSE_ATTRIBUTE_ERR", JS::Int32Value(10) }, |
482 | | { "INVALID_STATE_ERR", JS::Int32Value(11) }, |
483 | | { "SYNTAX_ERR", JS::Int32Value(12) }, |
484 | | { "INVALID_MODIFICATION_ERR", JS::Int32Value(13) }, |
485 | | { "NAMESPACE_ERR", JS::Int32Value(14) }, |
486 | | { "INVALID_ACCESS_ERR", JS::Int32Value(15) }, |
487 | | { "VALIDATION_ERR", JS::Int32Value(16) }, |
488 | | { "TYPE_MISMATCH_ERR", JS::Int32Value(17) }, |
489 | | { "SECURITY_ERR", JS::Int32Value(18) }, |
490 | | { "NETWORK_ERR", JS::Int32Value(19) }, |
491 | | { "ABORT_ERR", JS::Int32Value(20) }, |
492 | | { "URL_MISMATCH_ERR", JS::Int32Value(21) }, |
493 | | { "QUOTA_EXCEEDED_ERR", JS::Int32Value(22) }, |
494 | | { "TIMEOUT_ERR", JS::Int32Value(23) }, |
495 | | { "INVALID_NODE_TYPE_ERR", JS::Int32Value(24) }, |
496 | | { "DATA_CLONE_ERR", JS::Int32Value(25) }, |
497 | | { 0, JS::UndefinedValue() } |
498 | | }; |
499 | | #if defined(__clang__) |
500 | | #pragma clang diagnostic pop |
501 | | #endif |
502 | | |
503 | | |
504 | | static const Prefable<const ConstantSpec> sConstants[] = { |
505 | | { nullptr, &sConstants_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(25 <= 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[34]; |
516 | | static PropertyInfo sNativeProperties_propertyInfos[34]; |
517 | | |
518 | | static const NativePropertiesN<2> sNativeProperties = { |
519 | | false, 0, |
520 | | false, 0, |
521 | | false, 0, |
522 | | true, 0 /* sAttributes */, |
523 | | false, 0, |
524 | | false, 0, |
525 | | true, 1 /* sConstants */, |
526 | | -1, |
527 | | 34, |
528 | | sNativeProperties_sortedPropertyIndices, |
529 | | { |
530 | | { sAttributes, &sNativeProperties_propertyInfos[0] }, |
531 | | { sConstants, &sNativeProperties_propertyInfos[9] } |
532 | | } |
533 | | }; |
534 | | static_assert(34 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
535 | | "We have a property info count that is oversized"); |
536 | | |
537 | | static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1]; |
538 | | static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1]; |
539 | | |
540 | | static const NativePropertiesN<1> sChromeOnlyNativeProperties = { |
541 | | false, 0, |
542 | | false, 0, |
543 | | false, 0, |
544 | | true, 0 /* sChromeAttributes */, |
545 | | false, 0, |
546 | | false, 0, |
547 | | false, 0, |
548 | | -1, |
549 | | 1, |
550 | | sChromeOnlyNativeProperties_sortedPropertyIndices, |
551 | | { |
552 | | { sChromeAttributes, &sChromeOnlyNativeProperties_propertyInfos[0] } |
553 | | } |
554 | | }; |
555 | | static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount), |
556 | | "We have a property info count that is oversized"); |
557 | | |
558 | | static bool |
559 | | _constructor(JSContext* cx, unsigned argc, JS::Value* vp) |
560 | 0 | { |
561 | 0 | AUTO_PROFILER_LABEL_FAST("DOMException constructor", DOM, cx); |
562 | 0 |
|
563 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
564 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
565 | 0 | if (!args.isConstructing()) { |
566 | 0 | // XXXbz wish I could get the name from the callee instead of |
567 | 0 | // Adding more relocations |
568 | 0 | return ThrowConstructorWithoutNew(cx, "DOMException"); |
569 | 0 | } |
570 | 0 | |
571 | 0 | JS::Rooted<JSObject*> desiredProto(cx); |
572 | 0 | if (!GetDesiredProto(cx, args, &desiredProto)) { |
573 | 0 | return false; |
574 | 0 | } |
575 | 0 | |
576 | 0 | GlobalObject global(cx, obj); |
577 | 0 | if (global.Failed()) { |
578 | 0 | return false; |
579 | 0 | } |
580 | 0 | |
581 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
582 | 0 | binding_detail::FakeString arg0; |
583 | 0 | if (args.hasDefined(0)) { |
584 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
585 | 0 | return false; |
586 | 0 | } |
587 | 0 | } else { |
588 | 0 | static const char16_t data[] = { 0 }; |
589 | 0 | arg0.Rebind(data, ArrayLength(data) - 1); |
590 | 0 | } |
591 | 0 | Optional<nsAString> arg1; |
592 | 0 | binding_detail::FakeString arg1_holder; |
593 | 0 | if (args.hasDefined(1)) { |
594 | 0 | if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1_holder)) { |
595 | 0 | return false; |
596 | 0 | } |
597 | 0 | arg1 = &arg1_holder; |
598 | 0 | } |
599 | 0 | Maybe<JSAutoRealm> ar; |
600 | 0 | if (objIsXray) { |
601 | 0 | obj = js::CheckedUnwrap(obj); |
602 | 0 | if (!obj) { |
603 | 0 | return false; |
604 | 0 | } |
605 | 0 | ar.emplace(cx, obj); |
606 | 0 | if (!JS_WrapObject(cx, &desiredProto)) { |
607 | 0 | return false; |
608 | 0 | } |
609 | 0 | } |
610 | 0 | FastErrorResult rv; |
611 | 0 | auto result(StrongOrRawPtr<mozilla::dom::DOMException>(mozilla::dom::DOMException::Constructor(global, NonNullHelper(Constify(arg0)), NonNullHelper(Constify(arg1)), rv))); |
612 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
613 | 0 | return false; |
614 | 0 | } |
615 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
616 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
617 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
618 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) { |
619 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
620 | 0 | return false; |
621 | 0 | } |
622 | 0 | return true; |
623 | 0 | } |
624 | | |
625 | | static const js::ClassOps sInterfaceObjectClassOps = { |
626 | | nullptr, /* addProperty */ |
627 | | nullptr, /* delProperty */ |
628 | | nullptr, /* enumerate */ |
629 | | nullptr, /* newEnumerate */ |
630 | | nullptr, /* resolve */ |
631 | | nullptr, /* mayResolve */ |
632 | | nullptr, /* finalize */ |
633 | | _constructor, /* call */ |
634 | | nullptr, /* hasInstance */ |
635 | | _constructor, /* construct */ |
636 | | nullptr, /* trace */ |
637 | | }; |
638 | | |
639 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
640 | | { |
641 | | "Function", |
642 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
643 | | &sInterfaceObjectClassOps, |
644 | | JS_NULL_CLASS_SPEC, |
645 | | JS_NULL_CLASS_EXT, |
646 | | &sInterfaceObjectClassObjectOps |
647 | | }, |
648 | | eInterface, |
649 | | true, |
650 | | prototypes::id::DOMException, |
651 | | PrototypeTraits<prototypes::id::DOMException>::Depth, |
652 | | sNativePropertyHooks, |
653 | | "function DOMException() {\n [native code]\n}", |
654 | | JS::GetRealmFunctionPrototype |
655 | | }; |
656 | | |
657 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
658 | | { |
659 | | "DOMExceptionPrototype", |
660 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
661 | | JS_NULL_CLASS_OPS, |
662 | | JS_NULL_CLASS_SPEC, |
663 | | JS_NULL_CLASS_EXT, |
664 | | JS_NULL_OBJECT_OPS |
665 | | }, |
666 | | eInterfacePrototype, |
667 | | false, |
668 | | prototypes::id::DOMException, |
669 | | PrototypeTraits<prototypes::id::DOMException>::Depth, |
670 | | sNativePropertyHooks, |
671 | | "[object DOMExceptionPrototype]", |
672 | | JS::GetRealmErrorPrototype |
673 | | }; |
674 | | |
675 | | static const js::ClassOps sClassOps = { |
676 | | _addProperty, /* addProperty */ |
677 | | nullptr, /* delProperty */ |
678 | | nullptr, /* enumerate */ |
679 | | nullptr, /* newEnumerate */ |
680 | | nullptr, /* resolve */ |
681 | | nullptr, /* mayResolve */ |
682 | | _finalize, /* finalize */ |
683 | | nullptr, /* call */ |
684 | | nullptr, /* hasInstance */ |
685 | | nullptr, /* construct */ |
686 | | nullptr, /* trace */ |
687 | | }; |
688 | | |
689 | | static const js::ClassExtension sClassExtension = { |
690 | | nullptr, /* weakmapKeyDelegateOp */ |
691 | | _objectMoved /* objectMovedOp */ |
692 | | }; |
693 | | |
694 | | static const DOMJSClass sClass = { |
695 | | { "DOMException", |
696 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
697 | | &sClassOps, |
698 | | JS_NULL_CLASS_SPEC, |
699 | | &sClassExtension, |
700 | | JS_NULL_OBJECT_OPS |
701 | | }, |
702 | | { prototypes::id::DOMException, 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 }, |
703 | | IsBaseOf<nsISupports, mozilla::dom::DOMException >::value, |
704 | | sNativePropertyHooks, |
705 | | FindAssociatedGlobalForNative<mozilla::dom::DOMException>::Get, |
706 | | GetProtoObjectHandle, |
707 | | GetCCParticipant<mozilla::dom::DOMException>::Get() |
708 | | }; |
709 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
710 | | "Must have the right minimal number of reserved slots."); |
711 | | static_assert(1 >= 1, |
712 | | "Must have enough reserved slots."); |
713 | | |
714 | | const JSClass* |
715 | | GetJSClass() |
716 | 0 | { |
717 | 0 | return sClass.ToJSClass(); |
718 | 0 | } |
719 | | |
720 | | bool |
721 | | Wrap(JSContext* aCx, mozilla::dom::DOMException* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
722 | 0 | { |
723 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::DOMException>::value, |
724 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
725 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::DOMException*>(aObject) == |
726 | 0 | reinterpret_cast<mozilla::dom::DOMException*>(aObject), |
727 | 0 | "Multiple inheritance for mozilla::dom::DOMException is broken."); |
728 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
729 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
730 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
731 | 0 | "You should probably not be using Wrap() directly; use " |
732 | 0 | "GetOrCreateDOMReflector instead"); |
733 | 0 |
|
734 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
735 | 0 | "nsISupports must be on our primary inheritance chain"); |
736 | 0 |
|
737 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
738 | 0 | if (!global) { |
739 | 0 | return false; |
740 | 0 | } |
741 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
742 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
743 | 0 |
|
744 | 0 | // That might have ended up wrapping us already, due to the wonders |
745 | 0 | // of XBL. Check for that, and bail out as needed. |
746 | 0 | aReflector.set(aCache->GetWrapper()); |
747 | 0 | if (aReflector) { |
748 | | #ifdef DEBUG |
749 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
750 | | #endif // DEBUG |
751 | | return true; |
752 | 0 | } |
753 | 0 |
|
754 | 0 | JSAutoRealm ar(aCx, global); |
755 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
756 | 0 | if (!canonicalProto) { |
757 | 0 | return false; |
758 | 0 | } |
759 | 0 | JS::Rooted<JSObject*> proto(aCx); |
760 | 0 | if (aGivenProto) { |
761 | 0 | proto = aGivenProto; |
762 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
763 | 0 | // coming in, we changed compartments to that of "parent" so may need |
764 | 0 | // to wrap the proto here. |
765 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
766 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
767 | 0 | return false; |
768 | 0 | } |
769 | 0 | } |
770 | 0 | } else { |
771 | 0 | proto = canonicalProto; |
772 | 0 | } |
773 | 0 |
|
774 | 0 | BindingJSObjectCreator<mozilla::dom::DOMException> creator(aCx); |
775 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
776 | 0 | if (!aReflector) { |
777 | 0 | return false; |
778 | 0 | } |
779 | 0 | |
780 | 0 | aCache->SetWrapper(aReflector); |
781 | 0 | creator.InitializationSucceeded(); |
782 | 0 |
|
783 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
784 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
785 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
786 | 0 | // otherwise we won't be able to properly recreate it later, since |
787 | 0 | // we won't know what proto to use. Note that we don't check |
788 | 0 | // aGivenProto here, since it's entirely possible (and even |
789 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
790 | 0 | // same as canonicalProto. |
791 | 0 | if (proto != canonicalProto) { |
792 | 0 | PreserveWrapper(aObject); |
793 | 0 | } |
794 | 0 |
|
795 | 0 | return true; |
796 | 0 | } |
797 | | |
798 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
799 | | nullptr, |
800 | | nullptr, |
801 | | nullptr, |
802 | | { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() }, |
803 | | prototypes::id::DOMException, |
804 | | constructors::id::DOMException, |
805 | | nullptr, |
806 | | &DefaultXrayExpandoObjectClass |
807 | | } }; |
808 | | |
809 | | void |
810 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
811 | 0 | { |
812 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmErrorPrototype(aCx)); |
813 | 0 | if (!parentProto) { |
814 | 0 | return; |
815 | 0 | } |
816 | 0 | |
817 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
818 | 0 | if (!constructorProto) { |
819 | 0 | return; |
820 | 0 | } |
821 | 0 | |
822 | 0 | static bool sIdsInited = false; |
823 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
824 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
825 | 0 | return; |
826 | 0 | } |
827 | 0 | if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) { |
828 | 0 | return; |
829 | 0 | } |
830 | 0 | sIdsInited = true; |
831 | 0 | } |
832 | 0 |
|
833 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::DOMException); |
834 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::DOMException); |
835 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
836 | 0 | &sPrototypeClass.mBase, protoCache, |
837 | 0 | nullptr, |
838 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
839 | 0 | interfaceCache, |
840 | 0 | sNativeProperties.Upcast(), |
841 | 0 | sChromeOnlyNativeProperties.Upcast(), |
842 | 0 | "DOMException", aDefineOnGlobal, |
843 | 0 | nullptr, |
844 | 0 | false); |
845 | 0 | } |
846 | | |
847 | | JSObject* |
848 | | GetConstructorObject(JSContext* aCx) |
849 | 0 | { |
850 | 0 | return GetConstructorObjectHandle(aCx); |
851 | 0 | } |
852 | | |
853 | | } // namespace DOMException_Binding |
854 | | |
855 | | |
856 | | |
857 | | namespace Exception_Binding { |
858 | | |
859 | | MOZ_CAN_RUN_SCRIPT static bool |
860 | | get_name(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Exception* self, JSJitGetterCallArgs args) |
861 | 0 | { |
862 | 0 | AUTO_PROFILER_LABEL_FAST("get Exception.name", DOM, cx); |
863 | 0 |
|
864 | 0 | DOMString result; |
865 | 0 | self->GetName(result); |
866 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
867 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
868 | 0 | return false; |
869 | 0 | } |
870 | 0 | return true; |
871 | 0 | } |
872 | | |
873 | | static const JSJitInfo name_getterinfo = { |
874 | | { (JSJitGetterOp)get_name }, |
875 | | { prototypes::id::Exception }, |
876 | | { PrototypeTraits<prototypes::id::Exception>::Depth }, |
877 | | JSJitInfo::Getter, |
878 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
879 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
880 | | false, /* isInfallible. False in setters. */ |
881 | | false, /* isMovable. Not relevant for setters. */ |
882 | | false, /* isEliminatable. Not relevant for setters. */ |
883 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
884 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
885 | | false, /* isTypedMethod. Only relevant for methods. */ |
886 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
887 | | }; |
888 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
889 | | static_assert(0 < 1, "There is no slot for us"); |
890 | | |
891 | | MOZ_CAN_RUN_SCRIPT static bool |
892 | | get_message(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Exception* self, JSJitGetterCallArgs args) |
893 | 0 | { |
894 | 0 | AUTO_PROFILER_LABEL_FAST("get Exception.message", DOM, cx); |
895 | 0 |
|
896 | 0 | DOMString result; |
897 | 0 | self->GetMessageMoz(result); |
898 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
899 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
900 | 0 | return false; |
901 | 0 | } |
902 | 0 | return true; |
903 | 0 | } |
904 | | |
905 | | static const JSJitInfo message_getterinfo = { |
906 | | { (JSJitGetterOp)get_message }, |
907 | | { prototypes::id::Exception }, |
908 | | { PrototypeTraits<prototypes::id::Exception>::Depth }, |
909 | | JSJitInfo::Getter, |
910 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
911 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
912 | | false, /* isInfallible. False in setters. */ |
913 | | false, /* isMovable. Not relevant for setters. */ |
914 | | false, /* isEliminatable. Not relevant for setters. */ |
915 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
916 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
917 | | false, /* isTypedMethod. Only relevant for methods. */ |
918 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
919 | | }; |
920 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
921 | | static_assert(0 < 1, "There is no slot for us"); |
922 | | |
923 | | MOZ_CAN_RUN_SCRIPT static bool |
924 | | __stringifier(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Exception* self, const JSJitMethodCallArgs& args) |
925 | 0 | { |
926 | 0 | AUTO_PROFILER_LABEL_FAST("Exception.__stringifier", DOM, cx); |
927 | 0 |
|
928 | 0 | DOMString result; |
929 | 0 | self->Stringify(cx, result); |
930 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
931 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
932 | 0 | return false; |
933 | 0 | } |
934 | 0 | return true; |
935 | 0 | } |
936 | | |
937 | | static const JSJitInfo __stringifier_methodinfo = { |
938 | | { (JSJitGetterOp)__stringifier }, |
939 | | { prototypes::id::Exception }, |
940 | | { PrototypeTraits<prototypes::id::Exception>::Depth }, |
941 | | JSJitInfo::Method, |
942 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
943 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
944 | | false, /* isInfallible. False in setters. */ |
945 | | false, /* isMovable. Not relevant for setters. */ |
946 | | false, /* isEliminatable. Not relevant for setters. */ |
947 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
948 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
949 | | false, /* isTypedMethod. Only relevant for methods. */ |
950 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
951 | | }; |
952 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
953 | | static_assert(0 < 1, "There is no slot for us"); |
954 | | |
955 | | MOZ_CAN_RUN_SCRIPT static bool |
956 | | get_result(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Exception* self, JSJitGetterCallArgs args) |
957 | 0 | { |
958 | 0 | AUTO_PROFILER_LABEL_FAST("get Exception.result", DOM, cx); |
959 | 0 |
|
960 | 0 | uint32_t result(self->Result()); |
961 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
962 | 0 | args.rval().setNumber(result); |
963 | 0 | return true; |
964 | 0 | } |
965 | | |
966 | | static const JSJitInfo result_getterinfo = { |
967 | | { (JSJitGetterOp)get_result }, |
968 | | { prototypes::id::Exception }, |
969 | | { PrototypeTraits<prototypes::id::Exception>::Depth }, |
970 | | JSJitInfo::Getter, |
971 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
972 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
973 | | true, /* isInfallible. False in setters. */ |
974 | | false, /* isMovable. Not relevant for setters. */ |
975 | | false, /* isEliminatable. Not relevant for setters. */ |
976 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
977 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
978 | | false, /* isTypedMethod. Only relevant for methods. */ |
979 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
980 | | }; |
981 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
982 | | static_assert(0 < 1, "There is no slot for us"); |
983 | | |
984 | | MOZ_CAN_RUN_SCRIPT static bool |
985 | | get_filename(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Exception* self, JSJitGetterCallArgs args) |
986 | 0 | { |
987 | 0 | AUTO_PROFILER_LABEL_FAST("get Exception.filename", DOM, cx); |
988 | 0 |
|
989 | 0 | DOMString result; |
990 | 0 | self->GetFilename(cx, result); |
991 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
992 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
993 | 0 | return false; |
994 | 0 | } |
995 | 0 | return true; |
996 | 0 | } |
997 | | |
998 | | static const JSJitInfo filename_getterinfo = { |
999 | | { (JSJitGetterOp)get_filename }, |
1000 | | { prototypes::id::Exception }, |
1001 | | { PrototypeTraits<prototypes::id::Exception>::Depth }, |
1002 | | JSJitInfo::Getter, |
1003 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1004 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
1005 | | false, /* isInfallible. False in setters. */ |
1006 | | false, /* isMovable. Not relevant for setters. */ |
1007 | | false, /* isEliminatable. Not relevant for setters. */ |
1008 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1009 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1010 | | false, /* isTypedMethod. Only relevant for methods. */ |
1011 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1012 | | }; |
1013 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1014 | | static_assert(0 < 1, "There is no slot for us"); |
1015 | | |
1016 | | MOZ_CAN_RUN_SCRIPT static bool |
1017 | | get_lineNumber(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Exception* self, JSJitGetterCallArgs args) |
1018 | 0 | { |
1019 | 0 | AUTO_PROFILER_LABEL_FAST("get Exception.lineNumber", DOM, cx); |
1020 | 0 |
|
1021 | 0 | uint32_t result(self->LineNumber(cx)); |
1022 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1023 | 0 | args.rval().setNumber(result); |
1024 | 0 | return true; |
1025 | 0 | } |
1026 | | |
1027 | | static const JSJitInfo lineNumber_getterinfo = { |
1028 | | { (JSJitGetterOp)get_lineNumber }, |
1029 | | { prototypes::id::Exception }, |
1030 | | { PrototypeTraits<prototypes::id::Exception>::Depth }, |
1031 | | JSJitInfo::Getter, |
1032 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1033 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
1034 | | true, /* isInfallible. False in setters. */ |
1035 | | false, /* isMovable. Not relevant for setters. */ |
1036 | | false, /* isEliminatable. Not relevant for setters. */ |
1037 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1038 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1039 | | false, /* isTypedMethod. Only relevant for methods. */ |
1040 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1041 | | }; |
1042 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1043 | | static_assert(0 < 1, "There is no slot for us"); |
1044 | | |
1045 | | MOZ_CAN_RUN_SCRIPT static bool |
1046 | | get_columnNumber(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Exception* self, JSJitGetterCallArgs args) |
1047 | 0 | { |
1048 | 0 | AUTO_PROFILER_LABEL_FAST("get Exception.columnNumber", DOM, cx); |
1049 | 0 |
|
1050 | 0 | uint32_t result(self->ColumnNumber()); |
1051 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1052 | 0 | args.rval().setNumber(result); |
1053 | 0 | return true; |
1054 | 0 | } |
1055 | | |
1056 | | static const JSJitInfo columnNumber_getterinfo = { |
1057 | | { (JSJitGetterOp)get_columnNumber }, |
1058 | | { prototypes::id::Exception }, |
1059 | | { PrototypeTraits<prototypes::id::Exception>::Depth }, |
1060 | | JSJitInfo::Getter, |
1061 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1062 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
1063 | | true, /* isInfallible. False in setters. */ |
1064 | | false, /* isMovable. Not relevant for setters. */ |
1065 | | false, /* isEliminatable. Not relevant for setters. */ |
1066 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1067 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1068 | | false, /* isTypedMethod. Only relevant for methods. */ |
1069 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1070 | | }; |
1071 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1072 | | static_assert(0 < 1, "There is no slot for us"); |
1073 | | |
1074 | | MOZ_CAN_RUN_SCRIPT static bool |
1075 | | get_location(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Exception* self, JSJitGetterCallArgs args) |
1076 | 0 | { |
1077 | 0 | AUTO_PROFILER_LABEL_FAST("get Exception.location", DOM, cx); |
1078 | 0 |
|
1079 | 0 | auto result(StrongOrRawPtr<nsIStackFrame>(self->GetLocation())); |
1080 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1081 | 0 | if (!result) { |
1082 | 0 | args.rval().setNull(); |
1083 | 0 | return true; |
1084 | 0 | } |
1085 | 0 | if (!WrapObject(cx, result, &NS_GET_IID(nsIStackFrame), args.rval())) { |
1086 | 0 | return false; |
1087 | 0 | } |
1088 | 0 | return true; |
1089 | 0 | } |
1090 | | |
1091 | | static const JSJitInfo location_getterinfo = { |
1092 | | { (JSJitGetterOp)get_location }, |
1093 | | { prototypes::id::Exception }, |
1094 | | { PrototypeTraits<prototypes::id::Exception>::Depth }, |
1095 | | JSJitInfo::Getter, |
1096 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1097 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
1098 | | false, /* isInfallible. False in setters. */ |
1099 | | false, /* isMovable. Not relevant for setters. */ |
1100 | | false, /* isEliminatable. Not relevant for setters. */ |
1101 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1102 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1103 | | false, /* isTypedMethod. Only relevant for methods. */ |
1104 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1105 | | }; |
1106 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1107 | | static_assert(0 < 1, "There is no slot for us"); |
1108 | | |
1109 | | MOZ_CAN_RUN_SCRIPT static bool |
1110 | | get_data(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Exception* self, JSJitGetterCallArgs args) |
1111 | 0 | { |
1112 | 0 | AUTO_PROFILER_LABEL_FAST("get Exception.data", DOM, cx); |
1113 | 0 |
|
1114 | 0 | auto result(StrongOrRawPtr<nsISupports>(self->GetData())); |
1115 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1116 | 0 | if (!result) { |
1117 | 0 | args.rval().setNull(); |
1118 | 0 | return true; |
1119 | 0 | } |
1120 | 0 | if (!WrapObject(cx, result, args.rval())) { |
1121 | 0 | return false; |
1122 | 0 | } |
1123 | 0 | return true; |
1124 | 0 | } |
1125 | | |
1126 | | static const JSJitInfo data_getterinfo = { |
1127 | | { (JSJitGetterOp)get_data }, |
1128 | | { prototypes::id::Exception }, |
1129 | | { PrototypeTraits<prototypes::id::Exception>::Depth }, |
1130 | | JSJitInfo::Getter, |
1131 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1132 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
1133 | | false, /* isInfallible. False in setters. */ |
1134 | | false, /* isMovable. Not relevant for setters. */ |
1135 | | false, /* isEliminatable. Not relevant for setters. */ |
1136 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1137 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1138 | | false, /* isTypedMethod. Only relevant for methods. */ |
1139 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1140 | | }; |
1141 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1142 | | static_assert(0 < 1, "There is no slot for us"); |
1143 | | |
1144 | | MOZ_CAN_RUN_SCRIPT static bool |
1145 | | get_stack(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Exception* self, JSJitGetterCallArgs args) |
1146 | 0 | { |
1147 | 0 | AUTO_PROFILER_LABEL_FAST("get Exception.stack", DOM, cx); |
1148 | 0 |
|
1149 | 0 | DOMString result; |
1150 | 0 | self->GetStack(cx, result); |
1151 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1152 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
1153 | 0 | return false; |
1154 | 0 | } |
1155 | 0 | return true; |
1156 | 0 | } |
1157 | | |
1158 | | MOZ_CAN_RUN_SCRIPT static bool |
1159 | | set_stack(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Exception* self, JSJitSetterCallArgs args) |
1160 | 0 | { |
1161 | 0 | AUTO_PROFILER_LABEL_FAST("set Exception.stack", DOM, cx); |
1162 | 0 |
|
1163 | 0 | return JS_DefineProperty(cx, obj, "stack", args[0], JSPROP_ENUMERATE); |
1164 | 0 | } |
1165 | | |
1166 | | static const JSJitInfo stack_getterinfo = { |
1167 | | { (JSJitGetterOp)get_stack }, |
1168 | | { prototypes::id::Exception }, |
1169 | | { PrototypeTraits<prototypes::id::Exception>::Depth }, |
1170 | | JSJitInfo::Getter, |
1171 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1172 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
1173 | | false, /* isInfallible. False in setters. */ |
1174 | | false, /* isMovable. Not relevant for setters. */ |
1175 | | false, /* isEliminatable. Not relevant for setters. */ |
1176 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1177 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1178 | | false, /* isTypedMethod. Only relevant for methods. */ |
1179 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1180 | | }; |
1181 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1182 | | static_assert(0 < 1, "There is no slot for us"); |
1183 | | static const JSJitInfo stack_setterinfo = { |
1184 | | { (JSJitGetterOp)set_stack }, |
1185 | | { prototypes::id::Exception }, |
1186 | | { PrototypeTraits<prototypes::id::Exception>::Depth }, |
1187 | | JSJitInfo::Setter, |
1188 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1189 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
1190 | | false, /* isInfallible. False in setters. */ |
1191 | | false, /* isMovable. Not relevant for setters. */ |
1192 | | false, /* isEliminatable. Not relevant for setters. */ |
1193 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1194 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1195 | | false, /* isTypedMethod. Only relevant for methods. */ |
1196 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1197 | | }; |
1198 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1199 | | static_assert(0 < 1, "There is no slot for us"); |
1200 | | |
1201 | | static bool |
1202 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
1203 | 0 | { |
1204 | 0 | mozilla::dom::Exception* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Exception>(obj); |
1205 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
1206 | 0 | // obviously can't preserve if we're not initialized. |
1207 | 0 | if (self && self->GetWrapperPreserveColor()) { |
1208 | 0 | PreserveWrapper(self); |
1209 | 0 | } |
1210 | 0 | return true; |
1211 | 0 | } |
1212 | | |
1213 | | static void |
1214 | | _finalize(js::FreeOp* fop, JSObject* obj) |
1215 | 0 | { |
1216 | 0 | mozilla::dom::Exception* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Exception>(obj); |
1217 | 0 | if (self) { |
1218 | 0 | ClearWrapper(self, self, obj); |
1219 | 0 | AddForDeferredFinalization<mozilla::dom::Exception>(self); |
1220 | 0 | } |
1221 | 0 | } |
1222 | | |
1223 | | static size_t |
1224 | | _objectMoved(JSObject* obj, JSObject* old) |
1225 | 0 | { |
1226 | 0 | mozilla::dom::Exception* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Exception>(obj); |
1227 | 0 | if (self) { |
1228 | 0 | UpdateWrapper(self, self, obj, old); |
1229 | 0 | } |
1230 | 0 |
|
1231 | 0 | return 0; |
1232 | 0 | } |
1233 | | |
1234 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
1235 | | #if defined(__clang__) |
1236 | | #pragma clang diagnostic push |
1237 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
1238 | | #endif |
1239 | | static const JSFunctionSpec sMethods_specs[] = { |
1240 | | JS_FNSPEC("toString", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&__stringifier_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
1241 | | JS_FS_END |
1242 | | }; |
1243 | | #if defined(__clang__) |
1244 | | #pragma clang diagnostic pop |
1245 | | #endif |
1246 | | |
1247 | | |
1248 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
1249 | | { nullptr, &sMethods_specs[0] }, |
1250 | | { nullptr, nullptr } |
1251 | | }; |
1252 | | |
1253 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
1254 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
1255 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
1256 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
1257 | | |
1258 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
1259 | | #if defined(__clang__) |
1260 | | #pragma clang diagnostic push |
1261 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
1262 | | #endif |
1263 | | static const JSPropertySpec sAttributes_specs[] = { |
1264 | | { "name", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &name_getterinfo, nullptr, nullptr }, |
1265 | | { "message", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &message_getterinfo, nullptr, nullptr }, |
1266 | | { "result", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &result_getterinfo, nullptr, nullptr }, |
1267 | | { "filename", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &filename_getterinfo, nullptr, nullptr }, |
1268 | | { "lineNumber", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &lineNumber_getterinfo, nullptr, nullptr }, |
1269 | | { "columnNumber", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &columnNumber_getterinfo, nullptr, nullptr }, |
1270 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr }, |
1271 | | { "data", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &data_getterinfo, nullptr, nullptr }, |
1272 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr }, |
1273 | | { "stack", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &stack_getterinfo, GenericSetter<NormalThisPolicy>, &stack_setterinfo }, |
1274 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
1275 | | }; |
1276 | | #if defined(__clang__) |
1277 | | #pragma clang diagnostic pop |
1278 | | #endif |
1279 | | |
1280 | | // Can't be const because the pref-enabled boolean needs to be writable |
1281 | | static PrefableDisablers sAttributes_disablers7 = { |
1282 | | true, false, GlobalNames::DedicatedWorkerGlobalScope | GlobalNames::ServiceWorkerGlobalScope | GlobalNames::SharedWorkerGlobalScope, nullptr |
1283 | | }; |
1284 | | |
1285 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
1286 | | { nullptr, &sAttributes_specs[0] }, |
1287 | | { &sAttributes_disablers7, &sAttributes_specs[7] }, |
1288 | | { nullptr, &sAttributes_specs[9] }, |
1289 | | { nullptr, nullptr } |
1290 | | }; |
1291 | | |
1292 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
1293 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
1294 | | static_assert(6 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
1295 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
1296 | | |
1297 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
1298 | | #if defined(__clang__) |
1299 | | #pragma clang diagnostic push |
1300 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
1301 | | #endif |
1302 | | static const JSPropertySpec sChromeAttributes_specs[] = { |
1303 | | { "location", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &location_getterinfo, nullptr, nullptr }, |
1304 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
1305 | | }; |
1306 | | #if defined(__clang__) |
1307 | | #pragma clang diagnostic pop |
1308 | | #endif |
1309 | | |
1310 | | // Can't be const because the pref-enabled boolean needs to be writable |
1311 | | static PrefableDisablers sChromeAttributes_disablers0 = { |
1312 | | true, false, GlobalNames::DedicatedWorkerGlobalScope | GlobalNames::ServiceWorkerGlobalScope | GlobalNames::SharedWorkerGlobalScope, nullptr |
1313 | | }; |
1314 | | |
1315 | | static const Prefable<const JSPropertySpec> sChromeAttributes[] = { |
1316 | | { &sChromeAttributes_disablers0, &sChromeAttributes_specs[0] }, |
1317 | | { nullptr, nullptr } |
1318 | | }; |
1319 | | |
1320 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
1321 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
1322 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
1323 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
1324 | | |
1325 | | |
1326 | | static uint16_t sNativeProperties_sortedPropertyIndices[9]; |
1327 | | static PropertyInfo sNativeProperties_propertyInfos[9]; |
1328 | | |
1329 | | static const NativePropertiesN<2> sNativeProperties = { |
1330 | | false, 0, |
1331 | | false, 0, |
1332 | | true, 0 /* sMethods */, |
1333 | | true, 1 /* sAttributes */, |
1334 | | false, 0, |
1335 | | false, 0, |
1336 | | false, 0, |
1337 | | -1, |
1338 | | 9, |
1339 | | sNativeProperties_sortedPropertyIndices, |
1340 | | { |
1341 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
1342 | | { sAttributes, &sNativeProperties_propertyInfos[1] } |
1343 | | } |
1344 | | }; |
1345 | | static_assert(9 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
1346 | | "We have a property info count that is oversized"); |
1347 | | |
1348 | | static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1]; |
1349 | | static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1]; |
1350 | | |
1351 | | static const NativePropertiesN<1> sChromeOnlyNativeProperties = { |
1352 | | false, 0, |
1353 | | false, 0, |
1354 | | false, 0, |
1355 | | true, 0 /* sChromeAttributes */, |
1356 | | false, 0, |
1357 | | false, 0, |
1358 | | false, 0, |
1359 | | -1, |
1360 | | 1, |
1361 | | sChromeOnlyNativeProperties_sortedPropertyIndices, |
1362 | | { |
1363 | | { sChromeAttributes, &sChromeOnlyNativeProperties_propertyInfos[0] } |
1364 | | } |
1365 | | }; |
1366 | | static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount), |
1367 | | "We have a property info count that is oversized"); |
1368 | | |
1369 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
1370 | | { |
1371 | | "ExceptionPrototype", |
1372 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
1373 | | JS_NULL_CLASS_OPS, |
1374 | | JS_NULL_CLASS_SPEC, |
1375 | | JS_NULL_CLASS_EXT, |
1376 | | JS_NULL_OBJECT_OPS |
1377 | | }, |
1378 | | eInterfacePrototype, |
1379 | | false, |
1380 | | prototypes::id::Exception, |
1381 | | PrototypeTraits<prototypes::id::Exception>::Depth, |
1382 | | sNativePropertyHooks, |
1383 | | "[object ExceptionPrototype]", |
1384 | | JS::GetRealmObjectPrototype |
1385 | | }; |
1386 | | |
1387 | | static const js::ClassOps sClassOps = { |
1388 | | _addProperty, /* addProperty */ |
1389 | | nullptr, /* delProperty */ |
1390 | | nullptr, /* enumerate */ |
1391 | | nullptr, /* newEnumerate */ |
1392 | | nullptr, /* resolve */ |
1393 | | nullptr, /* mayResolve */ |
1394 | | _finalize, /* finalize */ |
1395 | | nullptr, /* call */ |
1396 | | nullptr, /* hasInstance */ |
1397 | | nullptr, /* construct */ |
1398 | | nullptr, /* trace */ |
1399 | | }; |
1400 | | |
1401 | | static const js::ClassExtension sClassExtension = { |
1402 | | nullptr, /* weakmapKeyDelegateOp */ |
1403 | | _objectMoved /* objectMovedOp */ |
1404 | | }; |
1405 | | |
1406 | | static const DOMJSClass sClass = { |
1407 | | { "Exception", |
1408 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
1409 | | &sClassOps, |
1410 | | JS_NULL_CLASS_SPEC, |
1411 | | &sClassExtension, |
1412 | | JS_NULL_OBJECT_OPS |
1413 | | }, |
1414 | | { prototypes::id::Exception, 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 }, |
1415 | | IsBaseOf<nsISupports, mozilla::dom::Exception >::value, |
1416 | | sNativePropertyHooks, |
1417 | | FindAssociatedGlobalForNative<mozilla::dom::Exception>::Get, |
1418 | | GetProtoObjectHandle, |
1419 | | GetCCParticipant<mozilla::dom::Exception>::Get() |
1420 | | }; |
1421 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
1422 | | "Must have the right minimal number of reserved slots."); |
1423 | | static_assert(1 >= 1, |
1424 | | "Must have enough reserved slots."); |
1425 | | |
1426 | | const JSClass* |
1427 | | GetJSClass() |
1428 | 0 | { |
1429 | 0 | return sClass.ToJSClass(); |
1430 | 0 | } |
1431 | | |
1432 | | bool |
1433 | | Wrap(JSContext* aCx, mozilla::dom::Exception* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
1434 | 0 | { |
1435 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::Exception>::value, |
1436 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
1437 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::Exception*>(aObject) == |
1438 | 0 | reinterpret_cast<mozilla::dom::Exception*>(aObject), |
1439 | 0 | "Multiple inheritance for mozilla::dom::Exception is broken."); |
1440 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
1441 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
1442 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
1443 | 0 | "You should probably not be using Wrap() directly; use " |
1444 | 0 | "GetOrCreateDOMReflector instead"); |
1445 | 0 |
|
1446 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
1447 | 0 | "nsISupports must be on our primary inheritance chain"); |
1448 | 0 |
|
1449 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
1450 | 0 | if (!global) { |
1451 | 0 | return false; |
1452 | 0 | } |
1453 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
1454 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
1455 | 0 |
|
1456 | 0 | // That might have ended up wrapping us already, due to the wonders |
1457 | 0 | // of XBL. Check for that, and bail out as needed. |
1458 | 0 | aReflector.set(aCache->GetWrapper()); |
1459 | 0 | if (aReflector) { |
1460 | | #ifdef DEBUG |
1461 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
1462 | | #endif // DEBUG |
1463 | | return true; |
1464 | 0 | } |
1465 | 0 |
|
1466 | 0 | JSAutoRealm ar(aCx, global); |
1467 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
1468 | 0 | if (!canonicalProto) { |
1469 | 0 | return false; |
1470 | 0 | } |
1471 | 0 | JS::Rooted<JSObject*> proto(aCx); |
1472 | 0 | if (aGivenProto) { |
1473 | 0 | proto = aGivenProto; |
1474 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
1475 | 0 | // coming in, we changed compartments to that of "parent" so may need |
1476 | 0 | // to wrap the proto here. |
1477 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
1478 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
1479 | 0 | return false; |
1480 | 0 | } |
1481 | 0 | } |
1482 | 0 | } else { |
1483 | 0 | proto = canonicalProto; |
1484 | 0 | } |
1485 | 0 |
|
1486 | 0 | BindingJSObjectCreator<mozilla::dom::Exception> creator(aCx); |
1487 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
1488 | 0 | if (!aReflector) { |
1489 | 0 | return false; |
1490 | 0 | } |
1491 | 0 | |
1492 | 0 | aCache->SetWrapper(aReflector); |
1493 | 0 | creator.InitializationSucceeded(); |
1494 | 0 |
|
1495 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
1496 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
1497 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
1498 | 0 | // otherwise we won't be able to properly recreate it later, since |
1499 | 0 | // we won't know what proto to use. Note that we don't check |
1500 | 0 | // aGivenProto here, since it's entirely possible (and even |
1501 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
1502 | 0 | // same as canonicalProto. |
1503 | 0 | if (proto != canonicalProto) { |
1504 | 0 | PreserveWrapper(aObject); |
1505 | 0 | } |
1506 | 0 |
|
1507 | 0 | return true; |
1508 | 0 | } |
1509 | | |
1510 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
1511 | | nullptr, |
1512 | | nullptr, |
1513 | | nullptr, |
1514 | | { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() }, |
1515 | | prototypes::id::Exception, |
1516 | | constructors::id::_ID_Count, |
1517 | | nullptr, |
1518 | | &DefaultXrayExpandoObjectClass |
1519 | | } }; |
1520 | | |
1521 | | void |
1522 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
1523 | 0 | { |
1524 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
1525 | 0 | if (!parentProto) { |
1526 | 0 | return; |
1527 | 0 | } |
1528 | 0 | |
1529 | 0 | static bool sIdsInited = false; |
1530 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
1531 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
1532 | 0 | return; |
1533 | 0 | } |
1534 | 0 | if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) { |
1535 | 0 | return; |
1536 | 0 | } |
1537 | 0 | sIdsInited = true; |
1538 | 0 | } |
1539 | 0 |
|
1540 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::Exception); |
1541 | 0 | JS::Heap<JSObject*>* interfaceCache = nullptr; |
1542 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
1543 | 0 | &sPrototypeClass.mBase, protoCache, |
1544 | 0 | nullptr, |
1545 | 0 | nullptr, nullptr, 0, nullptr, |
1546 | 0 | interfaceCache, |
1547 | 0 | sNativeProperties.Upcast(), |
1548 | 0 | sChromeOnlyNativeProperties.Upcast(), |
1549 | 0 | nullptr, aDefineOnGlobal, |
1550 | 0 | nullptr, |
1551 | 0 | false); |
1552 | 0 | } |
1553 | | |
1554 | | } // namespace Exception_Binding |
1555 | | |
1556 | | |
1557 | | |
1558 | | } // namespace dom |
1559 | | } // namespace mozilla |