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