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