Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM HTMLScriptElement.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "HTMLElementBinding.h"
4 : #include "HTMLScriptElementBinding.h"
5 : #include "WrapperFactory.h"
6 : #include "mozilla/OwningNonNull.h"
7 : #include "mozilla/Preferences.h"
8 : #include "mozilla/dom/BindingUtils.h"
9 : #include "mozilla/dom/CustomElementRegistry.h"
10 : #include "mozilla/dom/DOMJSClass.h"
11 : #include "mozilla/dom/HTMLScriptElement.h"
12 : #include "mozilla/dom/NonRefcountedDOMObject.h"
13 : #include "mozilla/dom/Nullable.h"
14 : #include "mozilla/dom/PrimitiveConversions.h"
15 : #include "mozilla/dom/XrayExpandoClass.h"
16 :
17 : namespace mozilla {
18 : namespace dom {
19 :
20 : namespace HTMLScriptElementBinding {
21 :
22 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<HTMLElementBinding::NativeType>::value,
23 : "Can't inherit from an interface with a different ownership model.");
24 :
25 : static bool
26 0 : get_src(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLScriptElement* self, JSJitGetterCallArgs args)
27 : {
28 0 : DOMString result;
29 0 : self->GetSrc(result);
30 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
31 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
32 0 : return false;
33 : }
34 0 : return true;
35 : }
36 :
37 : static bool
38 0 : set_src(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLScriptElement* self, JSJitSetterCallArgs args)
39 : {
40 0 : binding_detail::FakeString arg0;
41 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
42 0 : return false;
43 : }
44 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
45 0 : Maybe<AutoCEReaction> ceReaction;
46 0 : if (reactionsStack) {
47 0 : ceReaction.emplace(reactionsStack);
48 : }
49 0 : binding_detail::FastErrorResult rv;
50 0 : self->SetSrc(NonNullHelper(Constify(arg0)), rv);
51 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
52 0 : return false;
53 : }
54 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
55 :
56 0 : return true;
57 : }
58 :
59 : static const JSJitInfo src_getterinfo = {
60 : { (JSJitGetterOp)get_src },
61 : { prototypes::id::HTMLScriptElement },
62 : { PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth },
63 : JSJitInfo::Getter,
64 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
65 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
66 : false, /* isInfallible. False in setters. */
67 : false, /* isMovable. Not relevant for setters. */
68 : false, /* isEliminatable. Not relevant for setters. */
69 : false, /* isAlwaysInSlot. Only relevant for getters. */
70 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
71 : false, /* isTypedMethod. Only relevant for methods. */
72 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
73 : };
74 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
75 : static_assert(0 < 1, "There is no slot for us");
76 : static const JSJitInfo src_setterinfo = {
77 : { (JSJitGetterOp)set_src },
78 : { prototypes::id::HTMLScriptElement },
79 : { PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth },
80 : JSJitInfo::Setter,
81 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
82 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
83 : false, /* isInfallible. False in setters. */
84 : false, /* isMovable. Not relevant for setters. */
85 : false, /* isEliminatable. Not relevant for setters. */
86 : false, /* isAlwaysInSlot. Only relevant for getters. */
87 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
88 : false, /* isTypedMethod. Only relevant for methods. */
89 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
90 : };
91 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
92 : static_assert(0 < 1, "There is no slot for us");
93 :
94 : static bool
95 0 : get_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLScriptElement* self, JSJitGetterCallArgs args)
96 : {
97 0 : DOMString result;
98 0 : self->GetType(result);
99 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
100 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
101 0 : return false;
102 : }
103 0 : return true;
104 : }
105 :
106 : static bool
107 0 : set_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLScriptElement* self, JSJitSetterCallArgs args)
108 : {
109 0 : binding_detail::FakeString arg0;
110 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
111 0 : return false;
112 : }
113 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
114 0 : Maybe<AutoCEReaction> ceReaction;
115 0 : if (reactionsStack) {
116 0 : ceReaction.emplace(reactionsStack);
117 : }
118 0 : binding_detail::FastErrorResult rv;
119 0 : self->SetType(NonNullHelper(Constify(arg0)), rv);
120 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
121 0 : return false;
122 : }
123 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
124 :
125 0 : return true;
126 : }
127 :
128 : static const JSJitInfo type_getterinfo = {
129 : { (JSJitGetterOp)get_type },
130 : { prototypes::id::HTMLScriptElement },
131 : { PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth },
132 : JSJitInfo::Getter,
133 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
134 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
135 : false, /* isInfallible. False in setters. */
136 : false, /* isMovable. Not relevant for setters. */
137 : false, /* isEliminatable. Not relevant for setters. */
138 : false, /* isAlwaysInSlot. Only relevant for getters. */
139 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
140 : false, /* isTypedMethod. Only relevant for methods. */
141 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
142 : };
143 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
144 : static_assert(0 < 1, "There is no slot for us");
145 : static const JSJitInfo type_setterinfo = {
146 : { (JSJitGetterOp)set_type },
147 : { prototypes::id::HTMLScriptElement },
148 : { PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth },
149 : JSJitInfo::Setter,
150 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
151 : JSVAL_TYPE_UNDEFINED, /* 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 : get_noModule(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLScriptElement* self, JSJitGetterCallArgs args)
165 : {
166 0 : bool result(self->NoModule());
167 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
168 0 : args.rval().setBoolean(result);
169 0 : return true;
170 : }
171 :
172 : static bool
173 0 : set_noModule(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLScriptElement* self, JSJitSetterCallArgs args)
174 : {
175 : bool arg0;
176 0 : if (!ValueToPrimitive<bool, eDefault>(cx, args[0], &arg0)) {
177 0 : return false;
178 : }
179 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
180 0 : Maybe<AutoCEReaction> ceReaction;
181 0 : if (reactionsStack) {
182 0 : ceReaction.emplace(reactionsStack);
183 : }
184 0 : binding_detail::FastErrorResult rv;
185 0 : self->SetNoModule(arg0, rv);
186 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
187 0 : return false;
188 : }
189 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
190 :
191 0 : return true;
192 : }
193 :
194 : static const JSJitInfo noModule_getterinfo = {
195 : { (JSJitGetterOp)get_noModule },
196 : { prototypes::id::HTMLScriptElement },
197 : { PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth },
198 : JSJitInfo::Getter,
199 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
200 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
201 : true, /* isInfallible. False in setters. */
202 : false, /* isMovable. Not relevant for setters. */
203 : false, /* isEliminatable. Not relevant for setters. */
204 : false, /* isAlwaysInSlot. Only relevant for getters. */
205 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
206 : false, /* isTypedMethod. Only relevant for methods. */
207 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
208 : };
209 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
210 : static_assert(0 < 1, "There is no slot for us");
211 : static const JSJitInfo noModule_setterinfo = {
212 : { (JSJitGetterOp)set_noModule },
213 : { prototypes::id::HTMLScriptElement },
214 : { PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth },
215 : JSJitInfo::Setter,
216 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
217 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
218 : false, /* isInfallible. False in setters. */
219 : false, /* isMovable. Not relevant for setters. */
220 : false, /* isEliminatable. Not relevant for setters. */
221 : false, /* isAlwaysInSlot. Only relevant for getters. */
222 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
223 : false, /* isTypedMethod. Only relevant for methods. */
224 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
225 : };
226 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
227 : static_assert(0 < 1, "There is no slot for us");
228 :
229 : static bool
230 0 : get_charset(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLScriptElement* self, JSJitGetterCallArgs args)
231 : {
232 0 : DOMString result;
233 0 : self->GetCharset(result);
234 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
235 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
236 0 : return false;
237 : }
238 0 : return true;
239 : }
240 :
241 : static bool
242 0 : set_charset(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLScriptElement* self, JSJitSetterCallArgs args)
243 : {
244 0 : binding_detail::FakeString arg0;
245 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
246 0 : return false;
247 : }
248 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
249 0 : Maybe<AutoCEReaction> ceReaction;
250 0 : if (reactionsStack) {
251 0 : ceReaction.emplace(reactionsStack);
252 : }
253 0 : binding_detail::FastErrorResult rv;
254 0 : self->SetCharset(NonNullHelper(Constify(arg0)), rv);
255 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
256 0 : return false;
257 : }
258 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
259 :
260 0 : return true;
261 : }
262 :
263 : static const JSJitInfo charset_getterinfo = {
264 : { (JSJitGetterOp)get_charset },
265 : { prototypes::id::HTMLScriptElement },
266 : { PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth },
267 : JSJitInfo::Getter,
268 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
269 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
270 : false, /* isInfallible. False in setters. */
271 : false, /* isMovable. Not relevant for setters. */
272 : false, /* isEliminatable. Not relevant for setters. */
273 : false, /* isAlwaysInSlot. Only relevant for getters. */
274 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
275 : false, /* isTypedMethod. Only relevant for methods. */
276 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
277 : };
278 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
279 : static_assert(0 < 1, "There is no slot for us");
280 : static const JSJitInfo charset_setterinfo = {
281 : { (JSJitGetterOp)set_charset },
282 : { prototypes::id::HTMLScriptElement },
283 : { PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth },
284 : JSJitInfo::Setter,
285 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
286 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
287 : false, /* isInfallible. False in setters. */
288 : false, /* isMovable. Not relevant for setters. */
289 : false, /* isEliminatable. Not relevant for setters. */
290 : false, /* isAlwaysInSlot. Only relevant for getters. */
291 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
292 : false, /* isTypedMethod. Only relevant for methods. */
293 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
294 : };
295 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
296 : static_assert(0 < 1, "There is no slot for us");
297 :
298 : static bool
299 0 : get_async(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLScriptElement* self, JSJitGetterCallArgs args)
300 : {
301 0 : bool result(self->Async());
302 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
303 0 : args.rval().setBoolean(result);
304 0 : return true;
305 : }
306 :
307 : static bool
308 0 : set_async(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLScriptElement* self, JSJitSetterCallArgs args)
309 : {
310 : bool arg0;
311 0 : if (!ValueToPrimitive<bool, eDefault>(cx, args[0], &arg0)) {
312 0 : return false;
313 : }
314 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
315 0 : Maybe<AutoCEReaction> ceReaction;
316 0 : if (reactionsStack) {
317 0 : ceReaction.emplace(reactionsStack);
318 : }
319 0 : binding_detail::FastErrorResult rv;
320 0 : self->SetAsync(arg0, rv);
321 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
322 0 : return false;
323 : }
324 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
325 :
326 0 : return true;
327 : }
328 :
329 : static const JSJitInfo async_getterinfo = {
330 : { (JSJitGetterOp)get_async },
331 : { prototypes::id::HTMLScriptElement },
332 : { PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth },
333 : JSJitInfo::Getter,
334 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
335 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
336 : true, /* isInfallible. False in setters. */
337 : false, /* isMovable. Not relevant for setters. */
338 : false, /* isEliminatable. Not relevant for setters. */
339 : false, /* isAlwaysInSlot. Only relevant for getters. */
340 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
341 : false, /* isTypedMethod. Only relevant for methods. */
342 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
343 : };
344 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
345 : static_assert(0 < 1, "There is no slot for us");
346 : static const JSJitInfo async_setterinfo = {
347 : { (JSJitGetterOp)set_async },
348 : { prototypes::id::HTMLScriptElement },
349 : { PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth },
350 : JSJitInfo::Setter,
351 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
352 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
353 : false, /* isInfallible. False in setters. */
354 : false, /* isMovable. Not relevant for setters. */
355 : false, /* isEliminatable. Not relevant for setters. */
356 : false, /* isAlwaysInSlot. Only relevant for getters. */
357 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
358 : false, /* isTypedMethod. Only relevant for methods. */
359 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
360 : };
361 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
362 : static_assert(0 < 1, "There is no slot for us");
363 :
364 : static bool
365 0 : get_defer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLScriptElement* self, JSJitGetterCallArgs args)
366 : {
367 0 : bool result(self->Defer());
368 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
369 0 : args.rval().setBoolean(result);
370 0 : return true;
371 : }
372 :
373 : static bool
374 0 : set_defer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLScriptElement* self, JSJitSetterCallArgs args)
375 : {
376 : bool arg0;
377 0 : if (!ValueToPrimitive<bool, eDefault>(cx, args[0], &arg0)) {
378 0 : return false;
379 : }
380 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
381 0 : Maybe<AutoCEReaction> ceReaction;
382 0 : if (reactionsStack) {
383 0 : ceReaction.emplace(reactionsStack);
384 : }
385 0 : binding_detail::FastErrorResult rv;
386 0 : self->SetDefer(arg0, rv);
387 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
388 0 : return false;
389 : }
390 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
391 :
392 0 : return true;
393 : }
394 :
395 : static const JSJitInfo defer_getterinfo = {
396 : { (JSJitGetterOp)get_defer },
397 : { prototypes::id::HTMLScriptElement },
398 : { PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth },
399 : JSJitInfo::Getter,
400 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
401 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
402 : true, /* isInfallible. False in setters. */
403 : false, /* isMovable. Not relevant for setters. */
404 : false, /* isEliminatable. Not relevant for setters. */
405 : false, /* isAlwaysInSlot. Only relevant for getters. */
406 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
407 : false, /* isTypedMethod. Only relevant for methods. */
408 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
409 : };
410 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
411 : static_assert(0 < 1, "There is no slot for us");
412 : static const JSJitInfo defer_setterinfo = {
413 : { (JSJitGetterOp)set_defer },
414 : { prototypes::id::HTMLScriptElement },
415 : { PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth },
416 : JSJitInfo::Setter,
417 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
418 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
419 : false, /* isInfallible. False in setters. */
420 : false, /* isMovable. Not relevant for setters. */
421 : false, /* isEliminatable. Not relevant for setters. */
422 : false, /* isAlwaysInSlot. Only relevant for getters. */
423 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
424 : false, /* isTypedMethod. Only relevant for methods. */
425 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
426 : };
427 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
428 : static_assert(0 < 1, "There is no slot for us");
429 :
430 : static bool
431 0 : get_crossOrigin(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLScriptElement* self, JSJitGetterCallArgs args)
432 : {
433 0 : DOMString result;
434 0 : self->GetCrossOrigin(result);
435 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
436 0 : if (!xpc::StringToJsval(cx, result, args.rval())) {
437 0 : return false;
438 : }
439 0 : return true;
440 : }
441 :
442 : static bool
443 0 : set_crossOrigin(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLScriptElement* self, JSJitSetterCallArgs args)
444 : {
445 0 : binding_detail::FakeString arg0;
446 0 : if (!ConvertJSValueToString(cx, args[0], eNull, eNull, arg0)) {
447 0 : return false;
448 : }
449 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
450 0 : Maybe<AutoCEReaction> ceReaction;
451 0 : if (reactionsStack) {
452 0 : ceReaction.emplace(reactionsStack);
453 : }
454 0 : binding_detail::FastErrorResult rv;
455 0 : self->SetCrossOrigin(NonNullHelper(Constify(arg0)), rv);
456 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
457 0 : return false;
458 : }
459 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
460 :
461 0 : return true;
462 : }
463 :
464 : static const JSJitInfo crossOrigin_getterinfo = {
465 : { (JSJitGetterOp)get_crossOrigin },
466 : { prototypes::id::HTMLScriptElement },
467 : { PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth },
468 : JSJitInfo::Getter,
469 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
470 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
471 : false, /* isInfallible. False in setters. */
472 : false, /* isMovable. Not relevant for setters. */
473 : false, /* isEliminatable. Not relevant for setters. */
474 : false, /* isAlwaysInSlot. Only relevant for getters. */
475 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
476 : false, /* isTypedMethod. Only relevant for methods. */
477 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
478 : };
479 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
480 : static_assert(0 < 1, "There is no slot for us");
481 : static const JSJitInfo crossOrigin_setterinfo = {
482 : { (JSJitGetterOp)set_crossOrigin },
483 : { prototypes::id::HTMLScriptElement },
484 : { PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth },
485 : JSJitInfo::Setter,
486 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
487 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
488 : false, /* isInfallible. False in setters. */
489 : false, /* isMovable. Not relevant for setters. */
490 : false, /* isEliminatable. Not relevant for setters. */
491 : false, /* isAlwaysInSlot. Only relevant for getters. */
492 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
493 : false, /* isTypedMethod. Only relevant for methods. */
494 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
495 : };
496 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
497 : static_assert(0 < 1, "There is no slot for us");
498 :
499 : static bool
500 0 : get_text(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLScriptElement* self, JSJitGetterCallArgs args)
501 : {
502 0 : DOMString result;
503 0 : self->GetText(result);
504 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
505 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
506 0 : return false;
507 : }
508 0 : return true;
509 : }
510 :
511 : static bool
512 0 : set_text(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLScriptElement* self, JSJitSetterCallArgs args)
513 : {
514 0 : binding_detail::FakeString arg0;
515 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
516 0 : return false;
517 : }
518 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
519 0 : Maybe<AutoCEReaction> ceReaction;
520 0 : if (reactionsStack) {
521 0 : ceReaction.emplace(reactionsStack);
522 : }
523 0 : binding_detail::FastErrorResult rv;
524 0 : self->SetText(NonNullHelper(Constify(arg0)), rv);
525 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
526 0 : return false;
527 : }
528 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
529 :
530 0 : return true;
531 : }
532 :
533 : static const JSJitInfo text_getterinfo = {
534 : { (JSJitGetterOp)get_text },
535 : { prototypes::id::HTMLScriptElement },
536 : { PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth },
537 : JSJitInfo::Getter,
538 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
539 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
540 : false, /* isInfallible. False in setters. */
541 : false, /* isMovable. Not relevant for setters. */
542 : false, /* isEliminatable. Not relevant for setters. */
543 : false, /* isAlwaysInSlot. Only relevant for getters. */
544 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
545 : false, /* isTypedMethod. Only relevant for methods. */
546 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
547 : };
548 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
549 : static_assert(0 < 1, "There is no slot for us");
550 : static const JSJitInfo text_setterinfo = {
551 : { (JSJitGetterOp)set_text },
552 : { prototypes::id::HTMLScriptElement },
553 : { PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth },
554 : JSJitInfo::Setter,
555 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
556 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
557 : false, /* isInfallible. False in setters. */
558 : false, /* isMovable. Not relevant for setters. */
559 : false, /* isEliminatable. Not relevant for setters. */
560 : false, /* isAlwaysInSlot. Only relevant for getters. */
561 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
562 : false, /* isTypedMethod. Only relevant for methods. */
563 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
564 : };
565 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
566 : static_assert(0 < 1, "There is no slot for us");
567 :
568 : static bool
569 0 : get_event(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLScriptElement* self, JSJitGetterCallArgs args)
570 : {
571 0 : DOMString result;
572 0 : self->GetEvent(result);
573 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
574 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
575 0 : return false;
576 : }
577 0 : return true;
578 : }
579 :
580 : static bool
581 0 : set_event(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLScriptElement* self, JSJitSetterCallArgs args)
582 : {
583 0 : binding_detail::FakeString arg0;
584 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
585 0 : return false;
586 : }
587 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
588 0 : Maybe<AutoCEReaction> ceReaction;
589 0 : if (reactionsStack) {
590 0 : ceReaction.emplace(reactionsStack);
591 : }
592 0 : binding_detail::FastErrorResult rv;
593 0 : self->SetEvent(NonNullHelper(Constify(arg0)), rv);
594 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
595 0 : return false;
596 : }
597 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
598 :
599 0 : return true;
600 : }
601 :
602 : static const JSJitInfo event_getterinfo = {
603 : { (JSJitGetterOp)get_event },
604 : { prototypes::id::HTMLScriptElement },
605 : { PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth },
606 : JSJitInfo::Getter,
607 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
608 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
609 : false, /* isInfallible. False in setters. */
610 : false, /* isMovable. Not relevant for setters. */
611 : false, /* isEliminatable. Not relevant for setters. */
612 : false, /* isAlwaysInSlot. Only relevant for getters. */
613 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
614 : false, /* isTypedMethod. Only relevant for methods. */
615 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
616 : };
617 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
618 : static_assert(0 < 1, "There is no slot for us");
619 : static const JSJitInfo event_setterinfo = {
620 : { (JSJitGetterOp)set_event },
621 : { prototypes::id::HTMLScriptElement },
622 : { PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth },
623 : JSJitInfo::Setter,
624 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
625 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
626 : false, /* isInfallible. False in setters. */
627 : false, /* isMovable. Not relevant for setters. */
628 : false, /* isEliminatable. Not relevant for setters. */
629 : false, /* isAlwaysInSlot. Only relevant for getters. */
630 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
631 : false, /* isTypedMethod. Only relevant for methods. */
632 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
633 : };
634 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
635 : static_assert(0 < 1, "There is no slot for us");
636 :
637 : static bool
638 0 : get_htmlFor(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLScriptElement* self, JSJitGetterCallArgs args)
639 : {
640 0 : DOMString result;
641 0 : self->GetHtmlFor(result);
642 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
643 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
644 0 : return false;
645 : }
646 0 : return true;
647 : }
648 :
649 : static bool
650 0 : set_htmlFor(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLScriptElement* self, JSJitSetterCallArgs args)
651 : {
652 0 : binding_detail::FakeString arg0;
653 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
654 0 : return false;
655 : }
656 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
657 0 : Maybe<AutoCEReaction> ceReaction;
658 0 : if (reactionsStack) {
659 0 : ceReaction.emplace(reactionsStack);
660 : }
661 0 : binding_detail::FastErrorResult rv;
662 0 : self->SetHtmlFor(NonNullHelper(Constify(arg0)), rv);
663 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
664 0 : return false;
665 : }
666 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
667 :
668 0 : return true;
669 : }
670 :
671 : static const JSJitInfo htmlFor_getterinfo = {
672 : { (JSJitGetterOp)get_htmlFor },
673 : { prototypes::id::HTMLScriptElement },
674 : { PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth },
675 : JSJitInfo::Getter,
676 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
677 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
678 : false, /* isInfallible. False in setters. */
679 : false, /* isMovable. Not relevant for setters. */
680 : false, /* isEliminatable. Not relevant for setters. */
681 : false, /* isAlwaysInSlot. Only relevant for getters. */
682 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
683 : false, /* isTypedMethod. Only relevant for methods. */
684 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
685 : };
686 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
687 : static_assert(0 < 1, "There is no slot for us");
688 : static const JSJitInfo htmlFor_setterinfo = {
689 : { (JSJitGetterOp)set_htmlFor },
690 : { prototypes::id::HTMLScriptElement },
691 : { PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth },
692 : JSJitInfo::Setter,
693 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
694 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
695 : false, /* isInfallible. False in setters. */
696 : false, /* isMovable. Not relevant for setters. */
697 : false, /* isEliminatable. Not relevant for setters. */
698 : false, /* isAlwaysInSlot. Only relevant for getters. */
699 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
700 : false, /* isTypedMethod. Only relevant for methods. */
701 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
702 : };
703 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
704 : static_assert(0 < 1, "There is no slot for us");
705 :
706 : static bool
707 0 : get_integrity(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLScriptElement* self, JSJitGetterCallArgs args)
708 : {
709 0 : DOMString result;
710 0 : self->GetIntegrity(result);
711 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
712 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
713 0 : return false;
714 : }
715 0 : return true;
716 : }
717 :
718 : static bool
719 0 : set_integrity(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLScriptElement* self, JSJitSetterCallArgs args)
720 : {
721 0 : binding_detail::FakeString arg0;
722 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
723 0 : return false;
724 : }
725 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
726 0 : Maybe<AutoCEReaction> ceReaction;
727 0 : if (reactionsStack) {
728 0 : ceReaction.emplace(reactionsStack);
729 : }
730 0 : binding_detail::FastErrorResult rv;
731 0 : self->SetIntegrity(NonNullHelper(Constify(arg0)), rv);
732 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
733 0 : return false;
734 : }
735 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
736 :
737 0 : return true;
738 : }
739 :
740 : static const JSJitInfo integrity_getterinfo = {
741 : { (JSJitGetterOp)get_integrity },
742 : { prototypes::id::HTMLScriptElement },
743 : { PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth },
744 : JSJitInfo::Getter,
745 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
746 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
747 : false, /* isInfallible. False in setters. */
748 : false, /* isMovable. Not relevant for setters. */
749 : false, /* isEliminatable. Not relevant for setters. */
750 : false, /* isAlwaysInSlot. Only relevant for getters. */
751 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
752 : false, /* isTypedMethod. Only relevant for methods. */
753 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
754 : };
755 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
756 : static_assert(0 < 1, "There is no slot for us");
757 : static const JSJitInfo integrity_setterinfo = {
758 : { (JSJitGetterOp)set_integrity },
759 : { prototypes::id::HTMLScriptElement },
760 : { PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth },
761 : JSJitInfo::Setter,
762 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
763 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
764 : false, /* isInfallible. False in setters. */
765 : false, /* isMovable. Not relevant for setters. */
766 : false, /* isEliminatable. Not relevant for setters. */
767 : false, /* isAlwaysInSlot. Only relevant for getters. */
768 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
769 : false, /* isTypedMethod. Only relevant for methods. */
770 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
771 : };
772 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
773 : static_assert(0 < 1, "There is no slot for us");
774 :
775 : static bool
776 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
777 : {
778 0 : mozilla::dom::HTMLScriptElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLScriptElement>(obj);
779 : // We don't want to preserve if we don't have a wrapper, and we
780 : // obviously can't preserve if we're not initialized.
781 0 : if (self && self->GetWrapperPreserveColor()) {
782 0 : PreserveWrapper(self);
783 : }
784 0 : return true;
785 : }
786 :
787 : static void
788 0 : _finalize(js::FreeOp* fop, JSObject* obj)
789 : {
790 0 : mozilla::dom::HTMLScriptElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLScriptElement>(obj);
791 0 : if (self) {
792 0 : ClearWrapper(self, self, obj);
793 0 : AddForDeferredFinalization<mozilla::dom::HTMLScriptElement>(self);
794 : }
795 0 : }
796 :
797 : static void
798 0 : _objectMoved(JSObject* obj, const JSObject* old)
799 : {
800 0 : mozilla::dom::HTMLScriptElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLScriptElement>(obj);
801 0 : if (self) {
802 0 : UpdateWrapper(self, self, obj, old);
803 : }
804 0 : }
805 :
806 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
807 : #if defined(__clang__)
808 : #pragma clang diagnostic push
809 : #pragma clang diagnostic ignored "-Wmissing-braces"
810 : #endif
811 : static const JSPropertySpec sAttributes_specs[] = {
812 : { "src", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &src_getterinfo, GenericBindingSetter, &src_setterinfo },
813 : { "type", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &type_getterinfo, GenericBindingSetter, &type_setterinfo },
814 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr },
815 : { "noModule", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &noModule_getterinfo, GenericBindingSetter, &noModule_setterinfo },
816 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr },
817 : { "charset", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &charset_getterinfo, GenericBindingSetter, &charset_setterinfo },
818 : { "async", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &async_getterinfo, GenericBindingSetter, &async_setterinfo },
819 : { "defer", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &defer_getterinfo, GenericBindingSetter, &defer_setterinfo },
820 : { "crossOrigin", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &crossOrigin_getterinfo, GenericBindingSetter, &crossOrigin_setterinfo },
821 : { "text", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &text_getterinfo, GenericBindingSetter, &text_setterinfo },
822 : { "event", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &event_getterinfo, GenericBindingSetter, &event_setterinfo },
823 : { "htmlFor", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &htmlFor_getterinfo, GenericBindingSetter, &htmlFor_setterinfo },
824 : { "integrity", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &integrity_getterinfo, GenericBindingSetter, &integrity_setterinfo },
825 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
826 : };
827 : #if defined(__clang__)
828 : #pragma clang diagnostic pop
829 : #endif
830 :
831 : static PrefableDisablers sAttributes_disablers3 = {
832 : true, false, 0, nullptr
833 : };
834 :
835 : // Can't be const because the pref-enabled boolean needs to be writable
836 : static Prefable<const JSPropertySpec> sAttributes[] = {
837 : { nullptr, &sAttributes_specs[0] },
838 : { &sAttributes_disablers3, &sAttributes_specs[3] },
839 : { nullptr, &sAttributes_specs[5] },
840 : { nullptr, nullptr }
841 : };
842 :
843 : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
844 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
845 : static_assert(8 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
846 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
847 :
848 :
849 : static uint16_t sNativeProperties_sortedPropertyIndices[11];
850 : static PropertyInfo sNativeProperties_propertyInfos[11];
851 :
852 : static const NativePropertiesN<1> sNativeProperties = {
853 : false, 0,
854 : false, 0,
855 : false, 0,
856 : true, 0 /* sAttributes */,
857 : false, 0,
858 : false, 0,
859 : false, 0,
860 : -1,
861 : 11,
862 : sNativeProperties_sortedPropertyIndices,
863 : {
864 : { sAttributes, &sNativeProperties_propertyInfos[0] }
865 : }
866 : };
867 : static_assert(11 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
868 : "We have a property info count that is oversized");
869 :
870 : static bool
871 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
872 : {
873 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
874 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
875 0 : if (!args.isConstructing()) {
876 : // XXXbz wish I could get the name from the callee instead of
877 : // Adding more relocations
878 0 : return ThrowConstructorWithoutNew(cx, "HTMLScriptElement");
879 : }
880 :
881 0 : GlobalObject global(cx, obj);
882 0 : if (global.Failed()) {
883 0 : return false;
884 : }
885 :
886 : // The newTarget might be a cross-compartment wrapper. Get the underlying object
887 : // so we can do the spec's object-identity checks.
888 0 : JS::Rooted<JSObject*> newTarget(cx, js::CheckedUnwrap(&args.newTarget().toObject()));
889 0 : if (!newTarget) {
890 0 : return ThrowErrorMessage(cx, MSG_ILLEGAL_CONSTRUCTOR);
891 : }
892 :
893 : // Step 2 of https://html.spec.whatwg.org/multipage/dom.html#htmlconstructor.
894 : // Enter the compartment of our underlying newTarget object, so we end
895 : // up comparing to the constructor object for our interface from that global.
896 : {
897 0 : JSAutoCompartment ac(cx, newTarget);
898 0 : JS::Handle<JSObject*> constructor(GetConstructorObjectHandle(cx));
899 0 : if (!constructor) {
900 0 : return false;
901 : }
902 0 : if (newTarget == constructor) {
903 0 : return ThrowErrorMessage(cx, MSG_ILLEGAL_CONSTRUCTOR);
904 : }
905 : }
906 :
907 0 : JS::Rooted<JSObject*> desiredProto(cx);
908 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
909 0 : return false;
910 : }
911 0 : if (!desiredProto) {
912 : // Step 7 of https://html.spec.whatwg.org/multipage/dom.html#htmlconstructor.
913 : // This fallback behavior is designed to match analogous behavior for the
914 : // JavaScript built-ins. So we enter the compartment of our underlying
915 : // newTarget object and fall back to the prototype object from that global.
916 : // XXX The spec says to use GetFunctionRealm(), which is not actually
917 : // the same thing as what we have here (e.g. in the case of scripted callable proxies
918 : // whose target is not same-compartment with the proxy, or bound functions, etc).
919 : // https://bugzilla.mozilla.org/show_bug.cgi?id=1317658
920 : {
921 0 : JSAutoCompartment ac(cx, newTarget);
922 0 : desiredProto = GetProtoObjectHandle(cx);
923 0 : if (!desiredProto) {
924 0 : return false;
925 : }
926 : }
927 :
928 : // desiredProto is in the compartment of the underlying newTarget object.
929 : // Wrap it into the context compartment.
930 0 : if (!JS_WrapObject(cx, &desiredProto)) {
931 0 : return false;
932 : }
933 : }
934 :
935 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
936 0 : Maybe<JSAutoCompartment> ac;
937 0 : if (objIsXray) {
938 0 : obj = js::CheckedUnwrap(obj);
939 0 : if (!obj) {
940 0 : return false;
941 : }
942 0 : ac.emplace(cx, obj);
943 0 : if (!JS_WrapObject(cx, &desiredProto)) {
944 0 : return false;
945 : }
946 : }
947 0 : binding_detail::FastErrorResult rv;
948 0 : auto result(StrongOrRawPtr<mozilla::dom::HTMLScriptElement>(CreateHTMLElement(global, args, rv)));
949 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
950 0 : return false;
951 : }
952 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
953 : static_assert(!IsPointer<decltype(result)>::value,
954 : "NewObject implies that we need to keep the object alive with a strong reference.");
955 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
956 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
957 0 : return false;
958 : }
959 0 : return true;
960 : }
961 :
962 : static const js::ClassOps sInterfaceObjectClassOps = {
963 : nullptr, /* addProperty */
964 : nullptr, /* delProperty */
965 : nullptr, /* getProperty */
966 : nullptr, /* setProperty */
967 : nullptr, /* enumerate */
968 : nullptr, /* newEnumerate */
969 : nullptr, /* resolve */
970 : nullptr, /* mayResolve */
971 : nullptr, /* finalize */
972 : _constructor, /* call */
973 : nullptr, /* hasInstance */
974 : _constructor, /* construct */
975 : nullptr, /* trace */
976 : };
977 :
978 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
979 : {
980 : "Function",
981 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
982 : &sInterfaceObjectClassOps,
983 : JS_NULL_CLASS_SPEC,
984 : JS_NULL_CLASS_EXT,
985 : &sInterfaceObjectClassObjectOps
986 : },
987 : eInterface,
988 : true,
989 : prototypes::id::HTMLScriptElement,
990 : PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth,
991 : sNativePropertyHooks,
992 : "function HTMLScriptElement() {\n [native code]\n}",
993 : HTMLElementBinding::GetConstructorObject
994 : };
995 :
996 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
997 : {
998 : "HTMLScriptElementPrototype",
999 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
1000 : JS_NULL_CLASS_OPS,
1001 : JS_NULL_CLASS_SPEC,
1002 : JS_NULL_CLASS_EXT,
1003 : JS_NULL_OBJECT_OPS
1004 : },
1005 : eInterfacePrototype,
1006 : false,
1007 : prototypes::id::HTMLScriptElement,
1008 : PrototypeTraits<prototypes::id::HTMLScriptElement>::Depth,
1009 : sNativePropertyHooks,
1010 : "[object HTMLScriptElementPrototype]",
1011 : HTMLElementBinding::GetProtoObject
1012 : };
1013 :
1014 : JSObject*
1015 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
1016 : {
1017 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
1018 : }
1019 :
1020 : static const js::ClassOps sClassOps = {
1021 : _addProperty, /* addProperty */
1022 : nullptr, /* delProperty */
1023 : nullptr, /* getProperty */
1024 : nullptr, /* setProperty */
1025 : nullptr, /* enumerate */
1026 : nullptr, /* newEnumerate */
1027 : nullptr, /* resolve */
1028 : nullptr, /* mayResolve */
1029 : _finalize, /* finalize */
1030 : nullptr, /* call */
1031 : nullptr, /* hasInstance */
1032 : nullptr, /* construct */
1033 : nullptr, /* trace */
1034 : };
1035 :
1036 : static const js::ClassExtension sClassExtension = {
1037 : nullptr, /* weakmapKeyDelegateOp */
1038 : _objectMoved /* objectMovedOp */
1039 : };
1040 :
1041 : static const DOMJSClass sClass = {
1042 : { "HTMLScriptElement",
1043 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
1044 : &sClassOps,
1045 : JS_NULL_CLASS_SPEC,
1046 : &sClassExtension,
1047 : JS_NULL_OBJECT_OPS
1048 : },
1049 : { prototypes::id::EventTarget, prototypes::id::Node, prototypes::id::Element, prototypes::id::HTMLElement, prototypes::id::HTMLScriptElement, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
1050 : IsBaseOf<nsISupports, mozilla::dom::HTMLScriptElement >::value,
1051 : sNativePropertyHooks,
1052 : FindAssociatedGlobalForNative<mozilla::dom::HTMLScriptElement>::Get,
1053 : GetProtoObjectHandle,
1054 : GetCCParticipant<mozilla::dom::HTMLScriptElement>::Get()
1055 : };
1056 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1057 : "Must have the right minimal number of reserved slots.");
1058 : static_assert(1 >= 1,
1059 : "Must have enough reserved slots.");
1060 :
1061 : const JSClass*
1062 0 : GetJSClass()
1063 : {
1064 0 : return sClass.ToJSClass();
1065 : }
1066 :
1067 : bool
1068 5 : Wrap(JSContext* aCx, mozilla::dom::HTMLScriptElement* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1069 : {
1070 : MOZ_ASSERT(static_cast<mozilla::dom::HTMLScriptElement*>(aObject) ==
1071 : reinterpret_cast<mozilla::dom::HTMLScriptElement*>(aObject),
1072 : "Multiple inheritance for mozilla::dom::HTMLScriptElement is broken.");
1073 : MOZ_ASSERT(static_cast<nsGenericHTMLElement*>(aObject) ==
1074 : reinterpret_cast<nsGenericHTMLElement*>(aObject),
1075 : "Multiple inheritance for nsGenericHTMLElement is broken.");
1076 : MOZ_ASSERT(static_cast<mozilla::dom::Element*>(aObject) ==
1077 : reinterpret_cast<mozilla::dom::Element*>(aObject),
1078 : "Multiple inheritance for mozilla::dom::Element is broken.");
1079 : MOZ_ASSERT(static_cast<nsINode*>(aObject) ==
1080 : reinterpret_cast<nsINode*>(aObject),
1081 : "Multiple inheritance for nsINode is broken.");
1082 : MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
1083 : reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
1084 : "Multiple inheritance for mozilla::dom::EventTarget is broken.");
1085 5 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1086 5 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1087 5 : MOZ_ASSERT(!aCache->GetWrapper(),
1088 : "You should probably not be using Wrap() directly; use "
1089 : "GetOrCreateDOMReflector instead");
1090 :
1091 5 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
1092 : "nsISupports must be on our primary inheritance chain");
1093 :
1094 10 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
1095 5 : if (!global) {
1096 0 : return false;
1097 : }
1098 5 : MOZ_ASSERT(JS_IsGlobalObject(global));
1099 5 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
1100 :
1101 : // That might have ended up wrapping us already, due to the wonders
1102 : // of XBL. Check for that, and bail out as needed.
1103 5 : aReflector.set(aCache->GetWrapper());
1104 5 : if (aReflector) {
1105 : #ifdef DEBUG
1106 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
1107 : #endif // DEBUG
1108 0 : return true;
1109 : }
1110 :
1111 10 : JSAutoCompartment ac(aCx, global);
1112 5 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1113 5 : if (!canonicalProto) {
1114 0 : return false;
1115 : }
1116 10 : JS::Rooted<JSObject*> proto(aCx);
1117 5 : if (aGivenProto) {
1118 0 : proto = aGivenProto;
1119 : // Unfortunately, while aGivenProto was in the compartment of aCx
1120 : // coming in, we changed compartments to that of "parent" so may need
1121 : // to wrap the proto here.
1122 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1123 0 : if (!JS_WrapObject(aCx, &proto)) {
1124 0 : return false;
1125 : }
1126 : }
1127 : } else {
1128 5 : proto = canonicalProto;
1129 : }
1130 :
1131 10 : BindingJSObjectCreator<mozilla::dom::HTMLScriptElement> creator(aCx);
1132 5 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1133 5 : if (!aReflector) {
1134 0 : return false;
1135 : }
1136 :
1137 5 : aCache->SetWrapper(aReflector);
1138 5 : creator.InitializationSucceeded();
1139 :
1140 5 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1141 : aCache->GetWrapperPreserveColor() == aReflector);
1142 : // If proto != canonicalProto, we have to preserve our wrapper;
1143 : // otherwise we won't be able to properly recreate it later, since
1144 : // we won't know what proto to use. Note that we don't check
1145 : // aGivenProto here, since it's entirely possible (and even
1146 : // somewhat common) to have a non-null aGivenProto which is the
1147 : // same as canonicalProto.
1148 5 : if (proto != canonicalProto) {
1149 0 : PreserveWrapper(aObject);
1150 : }
1151 :
1152 5 : return true;
1153 : }
1154 :
1155 : const NativePropertyHooks sNativePropertyHooks[] = { {
1156 : nullptr,
1157 : nullptr,
1158 : nullptr,
1159 : { sNativeProperties.Upcast(), nullptr },
1160 : prototypes::id::HTMLScriptElement,
1161 : constructors::id::HTMLScriptElement,
1162 : HTMLElementBinding::sNativePropertyHooks,
1163 : &DefaultXrayExpandoObjectClass
1164 : } };
1165 :
1166 : void
1167 1 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1168 : {
1169 1 : JS::Handle<JSObject*> parentProto(HTMLElementBinding::GetProtoObjectHandle(aCx));
1170 1 : if (!parentProto) {
1171 0 : return;
1172 : }
1173 :
1174 1 : JS::Handle<JSObject*> constructorProto(HTMLElementBinding::GetConstructorObjectHandle(aCx));
1175 1 : if (!constructorProto) {
1176 0 : return;
1177 : }
1178 :
1179 : static bool sIdsInited = false;
1180 1 : if (!sIdsInited && NS_IsMainThread()) {
1181 1 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
1182 0 : return;
1183 : }
1184 1 : sIdsInited = true;
1185 : }
1186 :
1187 : static bool sPrefCachesInited = false;
1188 1 : if (!sPrefCachesInited && NS_IsMainThread()) {
1189 1 : sPrefCachesInited = true;
1190 1 : Preferences::AddBoolVarCache(&sAttributes[1].disablers->enabled, "dom.moduleScripts.enabled");
1191 : }
1192 :
1193 1 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::HTMLScriptElement);
1194 1 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::HTMLScriptElement);
1195 1 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1196 : &sPrototypeClass.mBase, protoCache,
1197 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
1198 : interfaceCache,
1199 : sNativeProperties.Upcast(),
1200 : nullptr,
1201 : "HTMLScriptElement", aDefineOnGlobal,
1202 : nullptr,
1203 1 : false);
1204 : }
1205 :
1206 : JS::Handle<JSObject*>
1207 5 : GetProtoObjectHandle(JSContext* aCx)
1208 : {
1209 : /* Get the interface prototype object for this class. This will create the
1210 : object as needed. */
1211 5 : bool aDefineOnGlobal = true;
1212 :
1213 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1214 5 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1215 5 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1216 0 : return nullptr;
1217 : }
1218 :
1219 : /* Check to see whether the interface objects are already installed */
1220 5 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1221 5 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::HTMLScriptElement)) {
1222 2 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1223 1 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1224 : }
1225 :
1226 : /*
1227 : * The object might _still_ be null, but that's OK.
1228 : *
1229 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1230 : * traced by TraceProtoAndIfaceCache() and its contents are never
1231 : * changed after they have been set.
1232 : *
1233 : * Calling address() avoids the read read barrier that does gray
1234 : * unmarking, but it's not possible for the object to be gray here.
1235 : */
1236 :
1237 5 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::HTMLScriptElement);
1238 5 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1239 5 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1240 : }
1241 :
1242 : JS::Handle<JSObject*>
1243 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
1244 : {
1245 : /* Get the interface object for this class. This will create the object as
1246 : needed. */
1247 :
1248 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1249 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1250 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1251 0 : return nullptr;
1252 : }
1253 :
1254 : /* Check to see whether the interface objects are already installed */
1255 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1256 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::HTMLScriptElement)) {
1257 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1258 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1259 : }
1260 :
1261 : /*
1262 : * The object might _still_ be null, but that's OK.
1263 : *
1264 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1265 : * traced by TraceProtoAndIfaceCache() and its contents are never
1266 : * changed after they have been set.
1267 : *
1268 : * Calling address() avoids the read read barrier that does gray
1269 : * unmarking, but it's not possible for the object to be gray here.
1270 : */
1271 :
1272 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::HTMLScriptElement);
1273 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1274 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1275 : }
1276 :
1277 : JSObject*
1278 0 : GetConstructorObject(JSContext* aCx)
1279 : {
1280 0 : return GetConstructorObjectHandle(aCx);
1281 : }
1282 :
1283 : } // namespace HTMLScriptElementBinding
1284 :
1285 :
1286 :
1287 : } // namespace dom
1288 : } // namespace mozilla
|