Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM CharacterData.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "CharacterDataBinding.h"
4 : #include "NodeBinding.h"
5 : #include "WrapperFactory.h"
6 : #include "mozilla/OwningNonNull.h"
7 : #include "mozilla/dom/BindingUtils.h"
8 : #include "mozilla/dom/CustomElementRegistry.h"
9 : #include "mozilla/dom/DOMJSClass.h"
10 : #include "mozilla/dom/Element.h"
11 : #include "mozilla/dom/NonRefcountedDOMObject.h"
12 : #include "mozilla/dom/Nullable.h"
13 : #include "mozilla/dom/PrimitiveConversions.h"
14 : #include "mozilla/dom/UnionConversions.h"
15 : #include "mozilla/dom/UnionTypes.h"
16 : #include "mozilla/dom/XrayExpandoClass.h"
17 : #include "nsGenericDOMDataNode.h"
18 :
19 : namespace mozilla {
20 : namespace dom {
21 :
22 : namespace CharacterDataBinding {
23 :
24 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<NodeBinding::NativeType>::value,
25 : "Can't inherit from an interface with a different ownership model.");
26 :
27 : static bool
28 0 : get_data(JSContext* cx, JS::Handle<JSObject*> obj, nsGenericDOMDataNode* self, JSJitGetterCallArgs args)
29 : {
30 0 : DOMString result;
31 0 : self->GetData(result);
32 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
33 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
34 0 : return false;
35 : }
36 0 : return true;
37 : }
38 :
39 : static bool
40 0 : set_data(JSContext* cx, JS::Handle<JSObject*> obj, nsGenericDOMDataNode* self, JSJitSetterCallArgs args)
41 : {
42 0 : binding_detail::FakeString arg0;
43 0 : if (!ConvertJSValueToString(cx, args[0], eEmpty, eStringify, arg0)) {
44 0 : return false;
45 : }
46 0 : binding_detail::FastErrorResult rv;
47 0 : self->SetData(NonNullHelper(Constify(arg0)), rv);
48 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
49 0 : return false;
50 : }
51 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
52 :
53 0 : return true;
54 : }
55 :
56 : static const JSJitInfo data_getterinfo = {
57 : { (JSJitGetterOp)get_data },
58 : { prototypes::id::CharacterData },
59 : { PrototypeTraits<prototypes::id::CharacterData>::Depth },
60 : JSJitInfo::Getter,
61 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
62 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
63 : false, /* isInfallible. False in setters. */
64 : true, /* isMovable. Not relevant for setters. */
65 : true, /* isEliminatable. Not relevant for setters. */
66 : false, /* isAlwaysInSlot. Only relevant for getters. */
67 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
68 : false, /* isTypedMethod. Only relevant for methods. */
69 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
70 : };
71 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
72 : static_assert(0 < 1, "There is no slot for us");
73 : static const JSJitInfo data_setterinfo = {
74 : { (JSJitGetterOp)set_data },
75 : { prototypes::id::CharacterData },
76 : { PrototypeTraits<prototypes::id::CharacterData>::Depth },
77 : JSJitInfo::Setter,
78 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
79 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
80 : false, /* isInfallible. False in setters. */
81 : false, /* isMovable. Not relevant for setters. */
82 : false, /* isEliminatable. Not relevant for setters. */
83 : false, /* isAlwaysInSlot. Only relevant for getters. */
84 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
85 : false, /* isTypedMethod. Only relevant for methods. */
86 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
87 : };
88 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
89 : static_assert(0 < 1, "There is no slot for us");
90 :
91 : static bool
92 0 : get_length(JSContext* cx, JS::Handle<JSObject*> obj, nsGenericDOMDataNode* self, JSJitGetterCallArgs args)
93 : {
94 0 : uint32_t result(self->Length());
95 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
96 0 : args.rval().setNumber(result);
97 0 : return true;
98 : }
99 :
100 : static const JSJitInfo length_getterinfo = {
101 : { (JSJitGetterOp)get_length },
102 : { prototypes::id::CharacterData },
103 : { PrototypeTraits<prototypes::id::CharacterData>::Depth },
104 : JSJitInfo::Getter,
105 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
106 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
107 : true, /* isInfallible. False in setters. */
108 : true, /* isMovable. Not relevant for setters. */
109 : true, /* isEliminatable. Not relevant for setters. */
110 : false, /* isAlwaysInSlot. Only relevant for getters. */
111 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
112 : false, /* isTypedMethod. Only relevant for methods. */
113 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
114 : };
115 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
116 : static_assert(0 < 1, "There is no slot for us");
117 :
118 : static bool
119 0 : substringData(JSContext* cx, JS::Handle<JSObject*> obj, nsGenericDOMDataNode* self, const JSJitMethodCallArgs& args)
120 : {
121 0 : if (MOZ_UNLIKELY(args.length() < 2)) {
122 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CharacterData.substringData");
123 : }
124 : uint32_t arg0;
125 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
126 0 : return false;
127 : }
128 : uint32_t arg1;
129 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) {
130 0 : return false;
131 : }
132 0 : binding_detail::FastErrorResult rv;
133 0 : DOMString result;
134 0 : self->SubstringData(arg0, arg1, result, rv);
135 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
136 0 : return false;
137 : }
138 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
139 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
140 0 : return false;
141 : }
142 0 : return true;
143 : }
144 :
145 : static const JSJitInfo substringData_methodinfo = {
146 : { (JSJitGetterOp)substringData },
147 : { prototypes::id::CharacterData },
148 : { PrototypeTraits<prototypes::id::CharacterData>::Depth },
149 : JSJitInfo::Method,
150 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
151 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
152 : false, /* isInfallible. False in setters. */
153 : false, /* isMovable. Not relevant for setters. */
154 : false, /* isEliminatable. Not relevant for setters. */
155 : false, /* isAlwaysInSlot. Only relevant for getters. */
156 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
157 : false, /* isTypedMethod. Only relevant for methods. */
158 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
159 : };
160 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
161 : static_assert(0 < 1, "There is no slot for us");
162 :
163 : static bool
164 0 : appendData(JSContext* cx, JS::Handle<JSObject*> obj, nsGenericDOMDataNode* self, const JSJitMethodCallArgs& args)
165 : {
166 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
167 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CharacterData.appendData");
168 : }
169 0 : binding_detail::FakeString arg0;
170 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
171 0 : return false;
172 : }
173 0 : binding_detail::FastErrorResult rv;
174 0 : self->AppendData(NonNullHelper(Constify(arg0)), rv);
175 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
176 0 : return false;
177 : }
178 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
179 0 : args.rval().setUndefined();
180 0 : return true;
181 : }
182 :
183 : static const JSJitInfo appendData_methodinfo = {
184 : { (JSJitGetterOp)appendData },
185 : { prototypes::id::CharacterData },
186 : { PrototypeTraits<prototypes::id::CharacterData>::Depth },
187 : JSJitInfo::Method,
188 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
189 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
190 : false, /* isInfallible. False in setters. */
191 : false, /* isMovable. Not relevant for setters. */
192 : false, /* isEliminatable. Not relevant for setters. */
193 : false, /* isAlwaysInSlot. Only relevant for getters. */
194 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
195 : false, /* isTypedMethod. Only relevant for methods. */
196 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
197 : };
198 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
199 : static_assert(0 < 1, "There is no slot for us");
200 :
201 : static bool
202 0 : insertData(JSContext* cx, JS::Handle<JSObject*> obj, nsGenericDOMDataNode* self, const JSJitMethodCallArgs& args)
203 : {
204 0 : if (MOZ_UNLIKELY(args.length() < 2)) {
205 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CharacterData.insertData");
206 : }
207 : uint32_t arg0;
208 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
209 0 : return false;
210 : }
211 0 : binding_detail::FakeString arg1;
212 0 : if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) {
213 0 : return false;
214 : }
215 0 : binding_detail::FastErrorResult rv;
216 0 : self->InsertData(arg0, NonNullHelper(Constify(arg1)), rv);
217 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
218 0 : return false;
219 : }
220 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
221 0 : args.rval().setUndefined();
222 0 : return true;
223 : }
224 :
225 : static const JSJitInfo insertData_methodinfo = {
226 : { (JSJitGetterOp)insertData },
227 : { prototypes::id::CharacterData },
228 : { PrototypeTraits<prototypes::id::CharacterData>::Depth },
229 : JSJitInfo::Method,
230 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
231 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
232 : false, /* isInfallible. False in setters. */
233 : false, /* isMovable. Not relevant for setters. */
234 : false, /* isEliminatable. Not relevant for setters. */
235 : false, /* isAlwaysInSlot. Only relevant for getters. */
236 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
237 : false, /* isTypedMethod. Only relevant for methods. */
238 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
239 : };
240 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
241 : static_assert(0 < 1, "There is no slot for us");
242 :
243 : static bool
244 0 : deleteData(JSContext* cx, JS::Handle<JSObject*> obj, nsGenericDOMDataNode* self, const JSJitMethodCallArgs& args)
245 : {
246 0 : if (MOZ_UNLIKELY(args.length() < 2)) {
247 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CharacterData.deleteData");
248 : }
249 : uint32_t arg0;
250 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
251 0 : return false;
252 : }
253 : uint32_t arg1;
254 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) {
255 0 : return false;
256 : }
257 0 : binding_detail::FastErrorResult rv;
258 0 : self->DeleteData(arg0, arg1, rv);
259 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
260 0 : return false;
261 : }
262 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
263 0 : args.rval().setUndefined();
264 0 : return true;
265 : }
266 :
267 : static const JSJitInfo deleteData_methodinfo = {
268 : { (JSJitGetterOp)deleteData },
269 : { prototypes::id::CharacterData },
270 : { PrototypeTraits<prototypes::id::CharacterData>::Depth },
271 : JSJitInfo::Method,
272 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
273 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
274 : false, /* isInfallible. False in setters. */
275 : false, /* isMovable. Not relevant for setters. */
276 : false, /* isEliminatable. Not relevant for setters. */
277 : false, /* isAlwaysInSlot. Only relevant for getters. */
278 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
279 : false, /* isTypedMethod. Only relevant for methods. */
280 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
281 : };
282 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
283 : static_assert(0 < 1, "There is no slot for us");
284 :
285 : static bool
286 0 : replaceData(JSContext* cx, JS::Handle<JSObject*> obj, nsGenericDOMDataNode* self, const JSJitMethodCallArgs& args)
287 : {
288 0 : if (MOZ_UNLIKELY(args.length() < 3)) {
289 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CharacterData.replaceData");
290 : }
291 : uint32_t arg0;
292 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
293 0 : return false;
294 : }
295 : uint32_t arg1;
296 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) {
297 0 : return false;
298 : }
299 0 : binding_detail::FakeString arg2;
300 0 : if (!ConvertJSValueToString(cx, args[2], eStringify, eStringify, arg2)) {
301 0 : return false;
302 : }
303 0 : binding_detail::FastErrorResult rv;
304 0 : self->ReplaceData(arg0, arg1, NonNullHelper(Constify(arg2)), rv);
305 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
306 0 : return false;
307 : }
308 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
309 0 : args.rval().setUndefined();
310 0 : return true;
311 : }
312 :
313 : static const JSJitInfo replaceData_methodinfo = {
314 : { (JSJitGetterOp)replaceData },
315 : { prototypes::id::CharacterData },
316 : { PrototypeTraits<prototypes::id::CharacterData>::Depth },
317 : JSJitInfo::Method,
318 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
319 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
320 : false, /* isInfallible. False in setters. */
321 : false, /* isMovable. Not relevant for setters. */
322 : false, /* isEliminatable. Not relevant for setters. */
323 : false, /* isAlwaysInSlot. Only relevant for getters. */
324 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
325 : false, /* isTypedMethod. Only relevant for methods. */
326 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
327 : };
328 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
329 : static_assert(0 < 1, "There is no slot for us");
330 :
331 : static bool
332 0 : before(JSContext* cx, JS::Handle<JSObject*> obj, nsGenericDOMDataNode* self, const JSJitMethodCallArgs& args)
333 : {
334 0 : binding_detail::AutoSequence<OwningNodeOrString> arg0;
335 0 : if (args.length() > 0) {
336 0 : if (!arg0.SetCapacity(args.length() - 0, mozilla::fallible)) {
337 0 : JS_ReportOutOfMemory(cx);
338 0 : return false;
339 : }
340 0 : for (uint32_t variadicArg = 0; variadicArg < args.length(); ++variadicArg) {
341 0 : OwningNodeOrString& slot = *arg0.AppendElement(mozilla::fallible);
342 : {
343 0 : bool done = false, failed = false, tryNext;
344 0 : if (args[variadicArg].isObject()) {
345 0 : done = (failed = !slot.TrySetToNode(cx, args[variadicArg], tryNext, false)) || !tryNext;
346 :
347 : }
348 0 : if (!done) {
349 : do {
350 0 : done = (failed = !slot.TrySetToString(cx, args[variadicArg], tryNext)) || !tryNext;
351 0 : break;
352 : } while (0);
353 : }
354 0 : if (failed) {
355 0 : return false;
356 : }
357 0 : if (!done) {
358 0 : ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of CharacterData.before", "Node");
359 0 : return false;
360 : }
361 : }
362 : }
363 : }
364 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
365 0 : Maybe<AutoCEReaction> ceReaction;
366 0 : if (reactionsStack) {
367 0 : ceReaction.emplace(reactionsStack);
368 : }
369 0 : binding_detail::FastErrorResult rv;
370 0 : self->Before(Constify(arg0), rv);
371 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
372 0 : return false;
373 : }
374 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
375 0 : args.rval().setUndefined();
376 0 : return true;
377 : }
378 :
379 : static const JSJitInfo before_methodinfo = {
380 : { (JSJitGetterOp)before },
381 : { prototypes::id::CharacterData },
382 : { PrototypeTraits<prototypes::id::CharacterData>::Depth },
383 : JSJitInfo::Method,
384 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
385 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
386 : false, /* isInfallible. False in setters. */
387 : false, /* isMovable. Not relevant for setters. */
388 : false, /* isEliminatable. Not relevant for setters. */
389 : false, /* isAlwaysInSlot. Only relevant for getters. */
390 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
391 : false, /* isTypedMethod. Only relevant for methods. */
392 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
393 : };
394 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
395 : static_assert(0 < 1, "There is no slot for us");
396 :
397 : static bool
398 0 : after(JSContext* cx, JS::Handle<JSObject*> obj, nsGenericDOMDataNode* self, const JSJitMethodCallArgs& args)
399 : {
400 0 : binding_detail::AutoSequence<OwningNodeOrString> arg0;
401 0 : if (args.length() > 0) {
402 0 : if (!arg0.SetCapacity(args.length() - 0, mozilla::fallible)) {
403 0 : JS_ReportOutOfMemory(cx);
404 0 : return false;
405 : }
406 0 : for (uint32_t variadicArg = 0; variadicArg < args.length(); ++variadicArg) {
407 0 : OwningNodeOrString& slot = *arg0.AppendElement(mozilla::fallible);
408 : {
409 0 : bool done = false, failed = false, tryNext;
410 0 : if (args[variadicArg].isObject()) {
411 0 : done = (failed = !slot.TrySetToNode(cx, args[variadicArg], tryNext, false)) || !tryNext;
412 :
413 : }
414 0 : if (!done) {
415 : do {
416 0 : done = (failed = !slot.TrySetToString(cx, args[variadicArg], tryNext)) || !tryNext;
417 0 : break;
418 : } while (0);
419 : }
420 0 : if (failed) {
421 0 : return false;
422 : }
423 0 : if (!done) {
424 0 : ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of CharacterData.after", "Node");
425 0 : return false;
426 : }
427 : }
428 : }
429 : }
430 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
431 0 : Maybe<AutoCEReaction> ceReaction;
432 0 : if (reactionsStack) {
433 0 : ceReaction.emplace(reactionsStack);
434 : }
435 0 : binding_detail::FastErrorResult rv;
436 0 : self->After(Constify(arg0), rv);
437 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
438 0 : return false;
439 : }
440 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
441 0 : args.rval().setUndefined();
442 0 : return true;
443 : }
444 :
445 : static const JSJitInfo after_methodinfo = {
446 : { (JSJitGetterOp)after },
447 : { prototypes::id::CharacterData },
448 : { PrototypeTraits<prototypes::id::CharacterData>::Depth },
449 : JSJitInfo::Method,
450 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
451 : JSVAL_TYPE_UNDEFINED, /* 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 0 : replaceWith(JSContext* cx, JS::Handle<JSObject*> obj, nsGenericDOMDataNode* self, const JSJitMethodCallArgs& args)
465 : {
466 0 : binding_detail::AutoSequence<OwningNodeOrString> arg0;
467 0 : if (args.length() > 0) {
468 0 : if (!arg0.SetCapacity(args.length() - 0, mozilla::fallible)) {
469 0 : JS_ReportOutOfMemory(cx);
470 0 : return false;
471 : }
472 0 : for (uint32_t variadicArg = 0; variadicArg < args.length(); ++variadicArg) {
473 0 : OwningNodeOrString& slot = *arg0.AppendElement(mozilla::fallible);
474 : {
475 0 : bool done = false, failed = false, tryNext;
476 0 : if (args[variadicArg].isObject()) {
477 0 : done = (failed = !slot.TrySetToNode(cx, args[variadicArg], tryNext, false)) || !tryNext;
478 :
479 : }
480 0 : if (!done) {
481 : do {
482 0 : done = (failed = !slot.TrySetToString(cx, args[variadicArg], tryNext)) || !tryNext;
483 0 : break;
484 : } while (0);
485 : }
486 0 : if (failed) {
487 0 : return false;
488 : }
489 0 : if (!done) {
490 0 : ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of CharacterData.replaceWith", "Node");
491 0 : return false;
492 : }
493 : }
494 : }
495 : }
496 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
497 0 : Maybe<AutoCEReaction> ceReaction;
498 0 : if (reactionsStack) {
499 0 : ceReaction.emplace(reactionsStack);
500 : }
501 0 : binding_detail::FastErrorResult rv;
502 0 : self->ReplaceWith(Constify(arg0), rv);
503 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
504 0 : return false;
505 : }
506 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
507 0 : args.rval().setUndefined();
508 0 : return true;
509 : }
510 :
511 : static const JSJitInfo replaceWith_methodinfo = {
512 : { (JSJitGetterOp)replaceWith },
513 : { prototypes::id::CharacterData },
514 : { PrototypeTraits<prototypes::id::CharacterData>::Depth },
515 : JSJitInfo::Method,
516 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
517 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
518 : false, /* isInfallible. False in setters. */
519 : false, /* isMovable. Not relevant for setters. */
520 : false, /* isEliminatable. Not relevant for setters. */
521 : false, /* isAlwaysInSlot. Only relevant for getters. */
522 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
523 : false, /* isTypedMethod. Only relevant for methods. */
524 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
525 : };
526 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
527 : static_assert(0 < 1, "There is no slot for us");
528 :
529 : static bool
530 0 : remove(JSContext* cx, JS::Handle<JSObject*> obj, nsGenericDOMDataNode* self, const JSJitMethodCallArgs& args)
531 : {
532 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
533 0 : Maybe<AutoCEReaction> ceReaction;
534 0 : if (reactionsStack) {
535 0 : ceReaction.emplace(reactionsStack);
536 : }
537 0 : self->Remove();
538 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
539 0 : args.rval().setUndefined();
540 0 : return true;
541 : }
542 :
543 : static const JSJitInfo remove_methodinfo = {
544 : { (JSJitGetterOp)remove },
545 : { prototypes::id::CharacterData },
546 : { PrototypeTraits<prototypes::id::CharacterData>::Depth },
547 : JSJitInfo::Method,
548 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
549 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
550 : true, /* isInfallible. False in setters. */
551 : false, /* isMovable. Not relevant for setters. */
552 : false, /* isEliminatable. Not relevant for setters. */
553 : false, /* isAlwaysInSlot. Only relevant for getters. */
554 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
555 : false, /* isTypedMethod. Only relevant for methods. */
556 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
557 : };
558 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
559 : static_assert(0 < 1, "There is no slot for us");
560 :
561 : static bool
562 0 : get_previousElementSibling(JSContext* cx, JS::Handle<JSObject*> obj, nsGenericDOMDataNode* self, JSJitGetterCallArgs args)
563 : {
564 0 : auto result(StrongOrRawPtr<mozilla::dom::Element>(self->GetPreviousElementSibling()));
565 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
566 0 : if (!result) {
567 0 : args.rval().setNull();
568 0 : return true;
569 : }
570 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
571 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
572 0 : return false;
573 : }
574 0 : return true;
575 : }
576 :
577 : static const JSJitInfo previousElementSibling_getterinfo = {
578 : { (JSJitGetterOp)get_previousElementSibling },
579 : { prototypes::id::CharacterData },
580 : { PrototypeTraits<prototypes::id::CharacterData>::Depth },
581 : JSJitInfo::Getter,
582 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
583 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
584 : false, /* isInfallible. False in setters. */
585 : true, /* isMovable. Not relevant for setters. */
586 : true, /* isEliminatable. Not relevant for setters. */
587 : false, /* isAlwaysInSlot. Only relevant for getters. */
588 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
589 : false, /* isTypedMethod. Only relevant for methods. */
590 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
591 : };
592 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
593 : static_assert(0 < 1, "There is no slot for us");
594 :
595 : static bool
596 0 : get_nextElementSibling(JSContext* cx, JS::Handle<JSObject*> obj, nsGenericDOMDataNode* self, JSJitGetterCallArgs args)
597 : {
598 0 : auto result(StrongOrRawPtr<mozilla::dom::Element>(self->GetNextElementSibling()));
599 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
600 0 : if (!result) {
601 0 : args.rval().setNull();
602 0 : return true;
603 : }
604 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
605 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
606 0 : return false;
607 : }
608 0 : return true;
609 : }
610 :
611 : static const JSJitInfo nextElementSibling_getterinfo = {
612 : { (JSJitGetterOp)get_nextElementSibling },
613 : { prototypes::id::CharacterData },
614 : { PrototypeTraits<prototypes::id::CharacterData>::Depth },
615 : JSJitInfo::Getter,
616 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
617 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
618 : false, /* isInfallible. False in setters. */
619 : true, /* isMovable. Not relevant for setters. */
620 : true, /* isEliminatable. Not relevant for setters. */
621 : false, /* isAlwaysInSlot. Only relevant for getters. */
622 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
623 : false, /* isTypedMethod. Only relevant for methods. */
624 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
625 : };
626 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
627 : static_assert(0 < 1, "There is no slot for us");
628 :
629 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
630 : #if defined(__clang__)
631 : #pragma clang diagnostic push
632 : #pragma clang diagnostic ignored "-Wmissing-braces"
633 : #endif
634 : static const JSFunctionSpec sMethods_specs[] = {
635 : JS_FNSPEC("substringData", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&substringData_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
636 : JS_FNSPEC("appendData", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&appendData_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
637 : JS_FNSPEC("insertData", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&insertData_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
638 : JS_FNSPEC("deleteData", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&deleteData_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
639 : JS_FNSPEC("replaceData", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&replaceData_methodinfo), 3, JSPROP_ENUMERATE, nullptr),
640 : JS_FNSPEC("before", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&before_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
641 : JS_FNSPEC("after", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&after_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
642 : JS_FNSPEC("replaceWith", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&replaceWith_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
643 : JS_FNSPEC("remove", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&remove_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
644 : JS_FS_END
645 : };
646 : #if defined(__clang__)
647 : #pragma clang diagnostic pop
648 : #endif
649 :
650 :
651 : // Can't be const because the pref-enabled boolean needs to be writable
652 : static Prefable<const JSFunctionSpec> sMethods[] = {
653 : { nullptr, &sMethods_specs[0] },
654 : { nullptr, nullptr }
655 : };
656 :
657 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
658 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
659 : static_assert(9 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
660 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
661 :
662 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
663 : #if defined(__clang__)
664 : #pragma clang diagnostic push
665 : #pragma clang diagnostic ignored "-Wmissing-braces"
666 : #endif
667 : static const JSPropertySpec sAttributes_specs[] = {
668 : { "data", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &data_getterinfo, GenericBindingSetter, &data_setterinfo },
669 : { "length", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &length_getterinfo, nullptr, nullptr },
670 : { "previousElementSibling", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &previousElementSibling_getterinfo, nullptr, nullptr },
671 : { "nextElementSibling", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &nextElementSibling_getterinfo, nullptr, nullptr },
672 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
673 : };
674 : #if defined(__clang__)
675 : #pragma clang diagnostic pop
676 : #endif
677 :
678 :
679 : // Can't be const because the pref-enabled boolean needs to be writable
680 : static Prefable<const JSPropertySpec> sAttributes[] = {
681 : { nullptr, &sAttributes_specs[0] },
682 : { nullptr, nullptr }
683 : };
684 :
685 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
686 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
687 : static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
688 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
689 :
690 :
691 : static uint16_t sNativeProperties_sortedPropertyIndices[13];
692 : static PropertyInfo sNativeProperties_propertyInfos[13];
693 :
694 : static const NativePropertiesN<2> sNativeProperties = {
695 : false, 0,
696 : false, 0,
697 : true, 0 /* sMethods */,
698 : true, 1 /* sAttributes */,
699 : false, 0,
700 : false, 0,
701 : false, 0,
702 : -1,
703 : 13,
704 : sNativeProperties_sortedPropertyIndices,
705 : {
706 : { sMethods, &sNativeProperties_propertyInfos[0] },
707 : { sAttributes, &sNativeProperties_propertyInfos[9] }
708 : }
709 : };
710 : static_assert(13 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
711 : "We have a property info count that is oversized");
712 :
713 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
714 : {
715 : "Function",
716 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
717 : &sBoringInterfaceObjectClassClassOps,
718 : JS_NULL_CLASS_SPEC,
719 : JS_NULL_CLASS_EXT,
720 : &sInterfaceObjectClassObjectOps
721 : },
722 : eInterface,
723 : true,
724 : prototypes::id::CharacterData,
725 : PrototypeTraits<prototypes::id::CharacterData>::Depth,
726 : sNativePropertyHooks,
727 : "function CharacterData() {\n [native code]\n}",
728 : NodeBinding::GetConstructorObject
729 : };
730 :
731 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
732 : {
733 : "CharacterDataPrototype",
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::CharacterData,
743 : PrototypeTraits<prototypes::id::CharacterData>::Depth,
744 : sNativePropertyHooks,
745 : "[object CharacterDataPrototype]",
746 : NodeBinding::GetProtoObject
747 : };
748 :
749 : JSObject*
750 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
751 : {
752 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
753 : }
754 :
755 : const NativePropertyHooks sNativePropertyHooks[] = { {
756 : nullptr,
757 : nullptr,
758 : nullptr,
759 : { sNativeProperties.Upcast(), nullptr },
760 : prototypes::id::CharacterData,
761 : constructors::id::CharacterData,
762 : NodeBinding::sNativePropertyHooks,
763 : &DefaultXrayExpandoObjectClass
764 : } };
765 :
766 : static const char* const unscopableNames[] = {
767 : "before",
768 : "after",
769 : "replaceWith",
770 : "remove",
771 : nullptr
772 : };
773 :
774 : void
775 1 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
776 : {
777 1 : JS::Handle<JSObject*> parentProto(NodeBinding::GetProtoObjectHandle(aCx));
778 1 : if (!parentProto) {
779 0 : return;
780 : }
781 :
782 1 : JS::Handle<JSObject*> constructorProto(NodeBinding::GetConstructorObjectHandle(aCx));
783 1 : if (!constructorProto) {
784 0 : return;
785 : }
786 :
787 : static bool sIdsInited = false;
788 1 : if (!sIdsInited && NS_IsMainThread()) {
789 1 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
790 0 : return;
791 : }
792 1 : sIdsInited = true;
793 : }
794 :
795 1 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::CharacterData);
796 1 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::CharacterData);
797 1 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
798 : &sPrototypeClass.mBase, protoCache,
799 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
800 : interfaceCache,
801 : sNativeProperties.Upcast(),
802 : nullptr,
803 : "CharacterData", aDefineOnGlobal,
804 : unscopableNames,
805 1 : false);
806 : }
807 :
808 : JS::Handle<JSObject*>
809 1 : GetProtoObjectHandle(JSContext* aCx)
810 : {
811 : /* Get the interface prototype object for this class. This will create the
812 : object as needed. */
813 1 : bool aDefineOnGlobal = true;
814 :
815 : /* Make sure our global is sane. Hopefully we can remove this sometime */
816 1 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
817 1 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
818 0 : return nullptr;
819 : }
820 :
821 : /* Check to see whether the interface objects are already installed */
822 1 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
823 1 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::CharacterData)) {
824 2 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
825 1 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
826 : }
827 :
828 : /*
829 : * The object might _still_ be null, but that's OK.
830 : *
831 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
832 : * traced by TraceProtoAndIfaceCache() and its contents are never
833 : * changed after they have been set.
834 : *
835 : * Calling address() avoids the read read barrier that does gray
836 : * unmarking, but it's not possible for the object to be gray here.
837 : */
838 :
839 1 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::CharacterData);
840 1 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
841 1 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
842 : }
843 :
844 : JSObject*
845 0 : GetProtoObject(JSContext* aCx)
846 : {
847 0 : return GetProtoObjectHandle(aCx);
848 : }
849 :
850 : JS::Handle<JSObject*>
851 1 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
852 : {
853 : /* Get the interface object for this class. This will create the object as
854 : needed. */
855 :
856 : /* Make sure our global is sane. Hopefully we can remove this sometime */
857 1 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
858 1 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
859 0 : return nullptr;
860 : }
861 :
862 : /* Check to see whether the interface objects are already installed */
863 1 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
864 1 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::CharacterData)) {
865 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
866 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
867 : }
868 :
869 : /*
870 : * The object might _still_ be null, but that's OK.
871 : *
872 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
873 : * traced by TraceProtoAndIfaceCache() and its contents are never
874 : * changed after they have been set.
875 : *
876 : * Calling address() avoids the read read barrier that does gray
877 : * unmarking, but it's not possible for the object to be gray here.
878 : */
879 :
880 1 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::CharacterData);
881 1 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
882 1 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
883 : }
884 :
885 : JSObject*
886 0 : GetConstructorObject(JSContext* aCx)
887 : {
888 0 : return GetConstructorObjectHandle(aCx);
889 : }
890 :
891 : } // namespace CharacterDataBinding
892 :
893 :
894 :
895 : } // namespace dom
896 : } // namespace mozilla
|