/work/obj-fuzz/dom/bindings/StorageManagerBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM StorageManager.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "StorageManagerBinding.h" |
5 | | #include "WrapperFactory.h" |
6 | | #include "mozilla/OwningNonNull.h" |
7 | | #include "mozilla/dom/BindingUtils.h" |
8 | | #include "mozilla/dom/DOMJSClass.h" |
9 | | #include "mozilla/dom/DOMPrefs.h" |
10 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
11 | | #include "mozilla/dom/PrimitiveConversions.h" |
12 | | #include "mozilla/dom/Promise.h" |
13 | | #include "mozilla/dom/ScriptSettings.h" |
14 | | #include "mozilla/dom/SimpleGlobalObject.h" |
15 | | #include "mozilla/dom/StorageManager.h" |
16 | | #include "mozilla/dom/ToJSValue.h" |
17 | | #include "mozilla/dom/XrayExpandoClass.h" |
18 | | |
19 | | namespace mozilla { |
20 | | namespace dom { |
21 | | |
22 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
23 | | using namespace mozilla::dom::binding_detail; |
24 | | |
25 | | |
26 | | |
27 | | StorageEstimate::StorageEstimate() |
28 | 0 | { |
29 | 0 | // Safe to pass a null context if we pass a null value |
30 | 0 | Init(nullptr, JS::NullHandleValue); |
31 | 0 | } |
32 | | |
33 | | |
34 | | |
35 | | bool |
36 | | StorageEstimate::InitIds(JSContext* cx, StorageEstimateAtoms* atomsCache) |
37 | 0 | { |
38 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
39 | 0 |
|
40 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
41 | 0 | // uninitialized. |
42 | 0 | if (!atomsCache->usage_id.init(cx, "usage") || |
43 | 0 | !atomsCache->quota_id.init(cx, "quota")) { |
44 | 0 | return false; |
45 | 0 | } |
46 | 0 | return true; |
47 | 0 | } |
48 | | |
49 | | bool |
50 | | StorageEstimate::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
51 | 0 | { |
52 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
53 | 0 | // Since in that case we will not have to do any property gets |
54 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
55 | 0 | // checkers by static analysis tools |
56 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
57 | 0 | StorageEstimateAtoms* atomsCache = nullptr; |
58 | 0 | if (cx) { |
59 | 0 | atomsCache = GetAtomCache<StorageEstimateAtoms>(cx); |
60 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
61 | 0 | return false; |
62 | 0 | } |
63 | 0 | } |
64 | 0 | |
65 | 0 | if (!IsConvertibleToDictionary(val)) { |
66 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
67 | 0 | } |
68 | 0 | |
69 | 0 | bool isNull = val.isNullOrUndefined(); |
70 | 0 | // We only need these if !isNull, in which case we have |cx|. |
71 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
72 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
73 | 0 | if (!isNull) { |
74 | 0 | MOZ_ASSERT(cx); |
75 | 0 | object.emplace(cx, &val.toObject()); |
76 | 0 | temp.emplace(cx); |
77 | 0 | } |
78 | 0 | if (!isNull) { |
79 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->quota_id, temp.ptr())) { |
80 | 0 | return false; |
81 | 0 | } |
82 | 0 | } |
83 | 0 | if (!isNull && !temp->isUndefined()) { |
84 | 0 | mQuota.Construct(); |
85 | 0 | if (!ValueToPrimitive<uint64_t, eDefault>(cx, temp.ref(), &(mQuota.Value()))) { |
86 | 0 | return false; |
87 | 0 | } |
88 | 0 | mIsAnyMemberPresent = true; |
89 | 0 | } |
90 | 0 |
|
91 | 0 | if (!isNull) { |
92 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->usage_id, temp.ptr())) { |
93 | 0 | return false; |
94 | 0 | } |
95 | 0 | } |
96 | 0 | if (!isNull && !temp->isUndefined()) { |
97 | 0 | mUsage.Construct(); |
98 | 0 | if (!ValueToPrimitive<uint64_t, eDefault>(cx, temp.ref(), &(mUsage.Value()))) { |
99 | 0 | return false; |
100 | 0 | } |
101 | 0 | mIsAnyMemberPresent = true; |
102 | 0 | } |
103 | 0 | return true; |
104 | 0 | } |
105 | | |
106 | | bool |
107 | | StorageEstimate::Init(const nsAString& aJSON) |
108 | 0 | { |
109 | 0 | AutoJSAPI jsapi; |
110 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
111 | 0 | if (!cleanGlobal) { |
112 | 0 | return false; |
113 | 0 | } |
114 | 0 | if (!jsapi.Init(cleanGlobal)) { |
115 | 0 | return false; |
116 | 0 | } |
117 | 0 | JSContext* cx = jsapi.cx(); |
118 | 0 | JS::Rooted<JS::Value> json(cx); |
119 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
120 | 0 | NS_ENSURE_TRUE(ok, false); |
121 | 0 | return Init(cx, json); |
122 | 0 | } |
123 | | |
124 | | bool |
125 | | StorageEstimate::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
126 | 0 | { |
127 | 0 | StorageEstimateAtoms* atomsCache = GetAtomCache<StorageEstimateAtoms>(cx); |
128 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
129 | 0 | return false; |
130 | 0 | } |
131 | 0 | |
132 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
133 | 0 | if (!obj) { |
134 | 0 | return false; |
135 | 0 | } |
136 | 0 | rval.set(JS::ObjectValue(*obj)); |
137 | 0 |
|
138 | 0 | if (mQuota.WasPassed()) { |
139 | 0 | do { |
140 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
141 | 0 | JS::Rooted<JS::Value> temp(cx); |
142 | 0 | uint64_t const & currentValue = mQuota.InternalValue(); |
143 | 0 | temp.set(JS_NumberValue(double(currentValue))); |
144 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->quota_id, temp, JSPROP_ENUMERATE)) { |
145 | 0 | return false; |
146 | 0 | } |
147 | 0 | break; |
148 | 0 | } while(false); |
149 | 0 | } |
150 | 0 |
|
151 | 0 | if (mUsage.WasPassed()) { |
152 | 0 | do { |
153 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
154 | 0 | JS::Rooted<JS::Value> temp(cx); |
155 | 0 | uint64_t const & currentValue = mUsage.InternalValue(); |
156 | 0 | temp.set(JS_NumberValue(double(currentValue))); |
157 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->usage_id, temp, JSPROP_ENUMERATE)) { |
158 | 0 | return false; |
159 | 0 | } |
160 | 0 | break; |
161 | 0 | } while(false); |
162 | 0 | } |
163 | 0 |
|
164 | 0 | return true; |
165 | 0 | } |
166 | | |
167 | | bool |
168 | | StorageEstimate::ToJSON(nsAString& aJSON) const |
169 | 0 | { |
170 | 0 | AutoJSAPI jsapi; |
171 | 0 | jsapi.Init(); |
172 | 0 | JSContext *cx = jsapi.cx(); |
173 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
174 | 0 | // because we'll only be creating objects, in ways that have no |
175 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
176 | 0 | // which likewise guarantees no side-effects for the sorts of |
177 | 0 | // things we will pass it. |
178 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
179 | 0 | JS::Rooted<JS::Value> val(cx); |
180 | 0 | if (!ToObjectInternal(cx, &val)) { |
181 | 0 | return false; |
182 | 0 | } |
183 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
184 | 0 | return StringifyToJSON(cx, obj, aJSON); |
185 | 0 | } |
186 | | |
187 | | void |
188 | | StorageEstimate::TraceDictionary(JSTracer* trc) |
189 | 0 | { |
190 | 0 | } |
191 | | |
192 | | StorageEstimate& |
193 | | StorageEstimate::operator=(const StorageEstimate& aOther) |
194 | 0 | { |
195 | 0 | DictionaryBase::operator=(aOther); |
196 | 0 | mQuota.Reset(); |
197 | 0 | if (aOther.mQuota.WasPassed()) { |
198 | 0 | mQuota.Construct(aOther.mQuota.Value()); |
199 | 0 | } |
200 | 0 | mUsage.Reset(); |
201 | 0 | if (aOther.mUsage.WasPassed()) { |
202 | 0 | mUsage.Construct(aOther.mUsage.Value()); |
203 | 0 | } |
204 | 0 | return *this; |
205 | 0 | } |
206 | | |
207 | | namespace binding_detail { |
208 | | } // namespace binding_detail |
209 | | |
210 | | |
211 | | namespace StorageManager_Binding { |
212 | | |
213 | | MOZ_CAN_RUN_SCRIPT static bool |
214 | | persisted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::StorageManager* self, const JSJitMethodCallArgs& args) |
215 | 0 | { |
216 | 0 | AUTO_PROFILER_LABEL_FAST("StorageManager.persisted", DOM, cx); |
217 | 0 |
|
218 | 0 | FastErrorResult rv; |
219 | 0 | auto result(StrongOrRawPtr<Promise>(self->Persisted(rv))); |
220 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
221 | 0 | return false; |
222 | 0 | } |
223 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
224 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
225 | 0 | return false; |
226 | 0 | } |
227 | 0 | return true; |
228 | 0 | } |
229 | | |
230 | | MOZ_CAN_RUN_SCRIPT static bool |
231 | | persisted_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::StorageManager* self, const JSJitMethodCallArgs& args) |
232 | 0 | { |
233 | 0 | bool ok = persisted(cx, obj, self, args); |
234 | 0 | if (ok) { |
235 | 0 | return true; |
236 | 0 | } |
237 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
238 | 0 | } |
239 | | |
240 | | static const JSJitInfo persisted_methodinfo = { |
241 | | { (JSJitGetterOp)persisted_promiseWrapper }, |
242 | | { prototypes::id::StorageManager }, |
243 | | { PrototypeTraits<prototypes::id::StorageManager>::Depth }, |
244 | | JSJitInfo::Method, |
245 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
246 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
247 | | false, /* isInfallible. False in setters. */ |
248 | | false, /* isMovable. Not relevant for setters. */ |
249 | | false, /* isEliminatable. Not relevant for setters. */ |
250 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
251 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
252 | | false, /* isTypedMethod. Only relevant for methods. */ |
253 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
254 | | }; |
255 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
256 | | static_assert(0 < 1, "There is no slot for us"); |
257 | | |
258 | | MOZ_CAN_RUN_SCRIPT static bool |
259 | | persist(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::StorageManager* self, const JSJitMethodCallArgs& args) |
260 | 0 | { |
261 | 0 | AUTO_PROFILER_LABEL_FAST("StorageManager.persist", DOM, cx); |
262 | 0 |
|
263 | 0 | FastErrorResult rv; |
264 | 0 | auto result(StrongOrRawPtr<Promise>(self->Persist(rv))); |
265 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
266 | 0 | return false; |
267 | 0 | } |
268 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
269 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
270 | 0 | return false; |
271 | 0 | } |
272 | 0 | return true; |
273 | 0 | } |
274 | | |
275 | | MOZ_CAN_RUN_SCRIPT static bool |
276 | | persist_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::StorageManager* self, const JSJitMethodCallArgs& args) |
277 | 0 | { |
278 | 0 | bool ok = persist(cx, obj, self, args); |
279 | 0 | if (ok) { |
280 | 0 | return true; |
281 | 0 | } |
282 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
283 | 0 | } |
284 | | |
285 | | static const JSJitInfo persist_methodinfo = { |
286 | | { (JSJitGetterOp)persist_promiseWrapper }, |
287 | | { prototypes::id::StorageManager }, |
288 | | { PrototypeTraits<prototypes::id::StorageManager>::Depth }, |
289 | | JSJitInfo::Method, |
290 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
291 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
292 | | false, /* isInfallible. False in setters. */ |
293 | | false, /* isMovable. Not relevant for setters. */ |
294 | | false, /* isEliminatable. Not relevant for setters. */ |
295 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
296 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
297 | | false, /* isTypedMethod. Only relevant for methods. */ |
298 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
299 | | }; |
300 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
301 | | static_assert(0 < 1, "There is no slot for us"); |
302 | | |
303 | | MOZ_CAN_RUN_SCRIPT static bool |
304 | | estimate(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::StorageManager* self, const JSJitMethodCallArgs& args) |
305 | 0 | { |
306 | 0 | AUTO_PROFILER_LABEL_FAST("StorageManager.estimate", DOM, cx); |
307 | 0 |
|
308 | 0 | FastErrorResult rv; |
309 | 0 | auto result(StrongOrRawPtr<Promise>(self->Estimate(rv))); |
310 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
311 | 0 | return false; |
312 | 0 | } |
313 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
314 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
315 | 0 | return false; |
316 | 0 | } |
317 | 0 | return true; |
318 | 0 | } |
319 | | |
320 | | MOZ_CAN_RUN_SCRIPT static bool |
321 | | estimate_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::StorageManager* self, const JSJitMethodCallArgs& args) |
322 | 0 | { |
323 | 0 | bool ok = estimate(cx, obj, self, args); |
324 | 0 | if (ok) { |
325 | 0 | return true; |
326 | 0 | } |
327 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
328 | 0 | } |
329 | | |
330 | | static const JSJitInfo estimate_methodinfo = { |
331 | | { (JSJitGetterOp)estimate_promiseWrapper }, |
332 | | { prototypes::id::StorageManager }, |
333 | | { PrototypeTraits<prototypes::id::StorageManager>::Depth }, |
334 | | JSJitInfo::Method, |
335 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
336 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
337 | | false, /* isInfallible. False in setters. */ |
338 | | false, /* isMovable. Not relevant for setters. */ |
339 | | false, /* isEliminatable. Not relevant for setters. */ |
340 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
341 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
342 | | false, /* isTypedMethod. Only relevant for methods. */ |
343 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
344 | | }; |
345 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
346 | | static_assert(0 < 1, "There is no slot for us"); |
347 | | |
348 | | static bool |
349 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
350 | 0 | { |
351 | 0 | mozilla::dom::StorageManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::StorageManager>(obj); |
352 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
353 | 0 | // obviously can't preserve if we're not initialized. |
354 | 0 | if (self && self->GetWrapperPreserveColor()) { |
355 | 0 | PreserveWrapper(self); |
356 | 0 | } |
357 | 0 | return true; |
358 | 0 | } |
359 | | |
360 | | static void |
361 | | _finalize(js::FreeOp* fop, JSObject* obj) |
362 | 0 | { |
363 | 0 | mozilla::dom::StorageManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::StorageManager>(obj); |
364 | 0 | if (self) { |
365 | 0 | ClearWrapper(self, self, obj); |
366 | 0 | AddForDeferredFinalization<mozilla::dom::StorageManager>(self); |
367 | 0 | } |
368 | 0 | } |
369 | | |
370 | | static size_t |
371 | | _objectMoved(JSObject* obj, JSObject* old) |
372 | 0 | { |
373 | 0 | mozilla::dom::StorageManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::StorageManager>(obj); |
374 | 0 | if (self) { |
375 | 0 | UpdateWrapper(self, self, obj, old); |
376 | 0 | } |
377 | 0 |
|
378 | 0 | return 0; |
379 | 0 | } |
380 | | |
381 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
382 | | #if defined(__clang__) |
383 | | #pragma clang diagnostic push |
384 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
385 | | #endif |
386 | | static const JSFunctionSpec sMethods_specs[] = { |
387 | | JS_FNSPEC("persisted", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&persisted_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
388 | | JS_FS_END, |
389 | | JS_FNSPEC("persist", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&persist_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
390 | | JS_FS_END, |
391 | | JS_FNSPEC("estimate", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&estimate_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
392 | | JS_FS_END |
393 | | }; |
394 | | #if defined(__clang__) |
395 | | #pragma clang diagnostic pop |
396 | | #endif |
397 | | |
398 | | // Can't be const because the pref-enabled boolean needs to be writable |
399 | | static PrefableDisablers sMethods_disablers0 = { |
400 | | true, true, 0, nullptr |
401 | | }; |
402 | | |
403 | | // Can't be const because the pref-enabled boolean needs to be writable |
404 | | static PrefableDisablers sMethods_disablers2 = { |
405 | | true, true, GlobalNames::DedicatedWorkerGlobalScope | GlobalNames::ServiceWorkerGlobalScope | GlobalNames::SharedWorkerGlobalScope, nullptr |
406 | | }; |
407 | | |
408 | | // Can't be const because the pref-enabled boolean needs to be writable |
409 | | static PrefableDisablers sMethods_disablers4 = { |
410 | | true, true, 0, nullptr |
411 | | }; |
412 | | |
413 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
414 | | { &sMethods_disablers0, &sMethods_specs[0] }, |
415 | | { &sMethods_disablers2, &sMethods_specs[2] }, |
416 | | { &sMethods_disablers4, &sMethods_specs[4] }, |
417 | | { nullptr, nullptr } |
418 | | }; |
419 | | |
420 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
421 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
422 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
423 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
424 | | |
425 | | |
426 | | static uint16_t sNativeProperties_sortedPropertyIndices[3]; |
427 | | static PropertyInfo sNativeProperties_propertyInfos[3]; |
428 | | |
429 | | static const NativePropertiesN<1> sNativeProperties = { |
430 | | false, 0, |
431 | | false, 0, |
432 | | true, 0 /* sMethods */, |
433 | | false, 0, |
434 | | false, 0, |
435 | | false, 0, |
436 | | false, 0, |
437 | | -1, |
438 | | 3, |
439 | | sNativeProperties_sortedPropertyIndices, |
440 | | { |
441 | | { sMethods, &sNativeProperties_propertyInfos[0] } |
442 | | } |
443 | | }; |
444 | | static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
445 | | "We have a property info count that is oversized"); |
446 | | |
447 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
448 | | { |
449 | | "Function", |
450 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
451 | | &sBoringInterfaceObjectClassClassOps, |
452 | | JS_NULL_CLASS_SPEC, |
453 | | JS_NULL_CLASS_EXT, |
454 | | &sInterfaceObjectClassObjectOps |
455 | | }, |
456 | | eInterface, |
457 | | true, |
458 | | prototypes::id::StorageManager, |
459 | | PrototypeTraits<prototypes::id::StorageManager>::Depth, |
460 | | sNativePropertyHooks, |
461 | | "function StorageManager() {\n [native code]\n}", |
462 | | JS::GetRealmFunctionPrototype |
463 | | }; |
464 | | |
465 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
466 | | { |
467 | | "StorageManagerPrototype", |
468 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
469 | | JS_NULL_CLASS_OPS, |
470 | | JS_NULL_CLASS_SPEC, |
471 | | JS_NULL_CLASS_EXT, |
472 | | JS_NULL_OBJECT_OPS |
473 | | }, |
474 | | eInterfacePrototype, |
475 | | false, |
476 | | prototypes::id::StorageManager, |
477 | | PrototypeTraits<prototypes::id::StorageManager>::Depth, |
478 | | sNativePropertyHooks, |
479 | | "[object StorageManagerPrototype]", |
480 | | JS::GetRealmObjectPrototype |
481 | | }; |
482 | | |
483 | | bool |
484 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
485 | 0 | { |
486 | 0 | return mozilla::dom::DOMPrefs::dom_storageManager_enabled(aCx, aObj) && |
487 | 0 | mozilla::dom::IsSecureContextOrObjectIsFromSecureContext(aCx, aObj); |
488 | 0 | } |
489 | | |
490 | | static const js::ClassOps sClassOps = { |
491 | | _addProperty, /* addProperty */ |
492 | | nullptr, /* delProperty */ |
493 | | nullptr, /* enumerate */ |
494 | | nullptr, /* newEnumerate */ |
495 | | nullptr, /* resolve */ |
496 | | nullptr, /* mayResolve */ |
497 | | _finalize, /* finalize */ |
498 | | nullptr, /* call */ |
499 | | nullptr, /* hasInstance */ |
500 | | nullptr, /* construct */ |
501 | | nullptr, /* trace */ |
502 | | }; |
503 | | |
504 | | static const js::ClassExtension sClassExtension = { |
505 | | nullptr, /* weakmapKeyDelegateOp */ |
506 | | _objectMoved /* objectMovedOp */ |
507 | | }; |
508 | | |
509 | | static const DOMJSClass sClass = { |
510 | | { "StorageManager", |
511 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
512 | | &sClassOps, |
513 | | JS_NULL_CLASS_SPEC, |
514 | | &sClassExtension, |
515 | | JS_NULL_OBJECT_OPS |
516 | | }, |
517 | | { prototypes::id::StorageManager, 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 }, |
518 | | IsBaseOf<nsISupports, mozilla::dom::StorageManager >::value, |
519 | | sNativePropertyHooks, |
520 | | FindAssociatedGlobalForNative<mozilla::dom::StorageManager>::Get, |
521 | | GetProtoObjectHandle, |
522 | | GetCCParticipant<mozilla::dom::StorageManager>::Get() |
523 | | }; |
524 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
525 | | "Must have the right minimal number of reserved slots."); |
526 | | static_assert(1 >= 1, |
527 | | "Must have enough reserved slots."); |
528 | | |
529 | | const JSClass* |
530 | | GetJSClass() |
531 | 0 | { |
532 | 0 | return sClass.ToJSClass(); |
533 | 0 | } |
534 | | |
535 | | bool |
536 | | Wrap(JSContext* aCx, mozilla::dom::StorageManager* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
537 | 0 | { |
538 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::StorageManager>::value, |
539 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
540 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::StorageManager*>(aObject) == |
541 | 0 | reinterpret_cast<mozilla::dom::StorageManager*>(aObject), |
542 | 0 | "Multiple inheritance for mozilla::dom::StorageManager is broken."); |
543 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
544 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
545 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
546 | 0 | "You should probably not be using Wrap() directly; use " |
547 | 0 | "GetOrCreateDOMReflector instead"); |
548 | 0 |
|
549 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
550 | 0 | "nsISupports must be on our primary inheritance chain"); |
551 | 0 |
|
552 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
553 | 0 | if (!global) { |
554 | 0 | return false; |
555 | 0 | } |
556 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
557 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
558 | 0 |
|
559 | 0 | // That might have ended up wrapping us already, due to the wonders |
560 | 0 | // of XBL. Check for that, and bail out as needed. |
561 | 0 | aReflector.set(aCache->GetWrapper()); |
562 | 0 | if (aReflector) { |
563 | | #ifdef DEBUG |
564 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
565 | | #endif // DEBUG |
566 | | return true; |
567 | 0 | } |
568 | 0 |
|
569 | 0 | JSAutoRealm ar(aCx, global); |
570 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
571 | 0 | if (!canonicalProto) { |
572 | 0 | return false; |
573 | 0 | } |
574 | 0 | JS::Rooted<JSObject*> proto(aCx); |
575 | 0 | if (aGivenProto) { |
576 | 0 | proto = aGivenProto; |
577 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
578 | 0 | // coming in, we changed compartments to that of "parent" so may need |
579 | 0 | // to wrap the proto here. |
580 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
581 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
582 | 0 | return false; |
583 | 0 | } |
584 | 0 | } |
585 | 0 | } else { |
586 | 0 | proto = canonicalProto; |
587 | 0 | } |
588 | 0 |
|
589 | 0 | BindingJSObjectCreator<mozilla::dom::StorageManager> creator(aCx); |
590 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
591 | 0 | if (!aReflector) { |
592 | 0 | return false; |
593 | 0 | } |
594 | 0 | |
595 | 0 | aCache->SetWrapper(aReflector); |
596 | 0 | creator.InitializationSucceeded(); |
597 | 0 |
|
598 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
599 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
600 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
601 | 0 | // otherwise we won't be able to properly recreate it later, since |
602 | 0 | // we won't know what proto to use. Note that we don't check |
603 | 0 | // aGivenProto here, since it's entirely possible (and even |
604 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
605 | 0 | // same as canonicalProto. |
606 | 0 | if (proto != canonicalProto) { |
607 | 0 | PreserveWrapper(aObject); |
608 | 0 | } |
609 | 0 |
|
610 | 0 | return true; |
611 | 0 | } |
612 | | |
613 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
614 | | nullptr, |
615 | | nullptr, |
616 | | nullptr, |
617 | | { sNativeProperties.Upcast(), nullptr }, |
618 | | prototypes::id::StorageManager, |
619 | | constructors::id::StorageManager, |
620 | | nullptr, |
621 | | &DefaultXrayExpandoObjectClass |
622 | | } }; |
623 | | |
624 | | void |
625 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
626 | 0 | { |
627 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
628 | 0 | if (!parentProto) { |
629 | 0 | return; |
630 | 0 | } |
631 | 0 | |
632 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
633 | 0 | if (!constructorProto) { |
634 | 0 | return; |
635 | 0 | } |
636 | 0 | |
637 | 0 | static bool sIdsInited = false; |
638 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
639 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
640 | 0 | return; |
641 | 0 | } |
642 | 0 | sIdsInited = true; |
643 | 0 | } |
644 | 0 |
|
645 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::StorageManager); |
646 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::StorageManager); |
647 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
648 | 0 | &sPrototypeClass.mBase, protoCache, |
649 | 0 | nullptr, |
650 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
651 | 0 | interfaceCache, |
652 | 0 | sNativeProperties.Upcast(), |
653 | 0 | nullptr, |
654 | 0 | "StorageManager", aDefineOnGlobal, |
655 | 0 | nullptr, |
656 | 0 | false); |
657 | 0 | } |
658 | | |
659 | | JSObject* |
660 | | GetConstructorObject(JSContext* aCx) |
661 | 0 | { |
662 | 0 | return GetConstructorObjectHandle(aCx); |
663 | 0 | } |
664 | | |
665 | | } // namespace StorageManager_Binding |
666 | | |
667 | | |
668 | | |
669 | | } // namespace dom |
670 | | } // namespace mozilla |