/work/obj-fuzz/dom/bindings/IDBFactoryBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM IDBFactory.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "IDBFactoryBinding.h" |
5 | | #include "IDBRequest.h" |
6 | | #include "WrapperFactory.h" |
7 | | #include "mozilla/OwningNonNull.h" |
8 | | #include "mozilla/dom/BindingUtils.h" |
9 | | #include "mozilla/dom/DOMJSClass.h" |
10 | | #include "mozilla/dom/IDBFactory.h" |
11 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
12 | | #include "mozilla/dom/PrimitiveConversions.h" |
13 | | #include "mozilla/dom/ScriptSettings.h" |
14 | | #include "mozilla/dom/SimpleGlobalObject.h" |
15 | | #include "mozilla/dom/XrayExpandoClass.h" |
16 | | #include "nsContentUtils.h" |
17 | | #include "nsIPrincipal.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 | | IDBOpenDBOptions::IDBOpenDBOptions() |
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 | | IDBOpenDBOptions::InitIds(JSContext* cx, IDBOpenDBOptionsAtoms* 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->version_id.init(cx, "version") || |
43 | 0 | !atomsCache->storage_id.init(cx, "storage")) { |
44 | 0 | return false; |
45 | 0 | } |
46 | 0 | return true; |
47 | 0 | } |
48 | | |
49 | | bool |
50 | | IDBOpenDBOptions::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 | IDBOpenDBOptionsAtoms* atomsCache = nullptr; |
58 | 0 | if (cx) { |
59 | 0 | atomsCache = GetAtomCache<IDBOpenDBOptionsAtoms>(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->storage_id, temp.ptr())) { |
80 | 0 | return false; |
81 | 0 | } |
82 | 0 | } |
83 | 0 | if (!isNull && !temp->isUndefined()) { |
84 | 0 | mStorage.Construct(); |
85 | 0 | { |
86 | 0 | int index; |
87 | 0 | if (!FindEnumStringIndex<true>(cx, temp.ref(), StorageTypeValues::strings, "StorageType", "'storage' member of IDBOpenDBOptions", &index)) { |
88 | 0 | return false; |
89 | 0 | } |
90 | 0 | MOZ_ASSERT(index >= 0); |
91 | 0 | (mStorage.Value()) = static_cast<StorageType>(index); |
92 | 0 | } |
93 | 0 | mIsAnyMemberPresent = true; |
94 | 0 | } |
95 | 0 |
|
96 | 0 | if (!isNull) { |
97 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->version_id, temp.ptr())) { |
98 | 0 | return false; |
99 | 0 | } |
100 | 0 | } |
101 | 0 | if (!isNull && !temp->isUndefined()) { |
102 | 0 | mVersion.Construct(); |
103 | 0 | if (!ValueToPrimitive<uint64_t, eEnforceRange>(cx, temp.ref(), &(mVersion.Value()))) { |
104 | 0 | return false; |
105 | 0 | } |
106 | 0 | mIsAnyMemberPresent = true; |
107 | 0 | } |
108 | 0 | return true; |
109 | 0 | } |
110 | | |
111 | | bool |
112 | | IDBOpenDBOptions::Init(const nsAString& aJSON) |
113 | 0 | { |
114 | 0 | AutoJSAPI jsapi; |
115 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
116 | 0 | if (!cleanGlobal) { |
117 | 0 | return false; |
118 | 0 | } |
119 | 0 | if (!jsapi.Init(cleanGlobal)) { |
120 | 0 | return false; |
121 | 0 | } |
122 | 0 | JSContext* cx = jsapi.cx(); |
123 | 0 | JS::Rooted<JS::Value> json(cx); |
124 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
125 | 0 | NS_ENSURE_TRUE(ok, false); |
126 | 0 | return Init(cx, json); |
127 | 0 | } |
128 | | |
129 | | bool |
130 | | IDBOpenDBOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
131 | 0 | { |
132 | 0 | IDBOpenDBOptionsAtoms* atomsCache = GetAtomCache<IDBOpenDBOptionsAtoms>(cx); |
133 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
134 | 0 | return false; |
135 | 0 | } |
136 | 0 | |
137 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
138 | 0 | if (!obj) { |
139 | 0 | return false; |
140 | 0 | } |
141 | 0 | rval.set(JS::ObjectValue(*obj)); |
142 | 0 |
|
143 | 0 | if (mStorage.WasPassed()) { |
144 | 0 | do { |
145 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
146 | 0 | JS::Rooted<JS::Value> temp(cx); |
147 | 0 | StorageType const & currentValue = mStorage.InternalValue(); |
148 | 0 | if (!ToJSValue(cx, currentValue, &temp)) { |
149 | 0 | return false; |
150 | 0 | } |
151 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->storage_id, temp, JSPROP_ENUMERATE)) { |
152 | 0 | return false; |
153 | 0 | } |
154 | 0 | break; |
155 | 0 | } while(false); |
156 | 0 | } |
157 | 0 |
|
158 | 0 | if (mVersion.WasPassed()) { |
159 | 0 | do { |
160 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
161 | 0 | JS::Rooted<JS::Value> temp(cx); |
162 | 0 | uint64_t const & currentValue = mVersion.InternalValue(); |
163 | 0 | temp.set(JS_NumberValue(double(currentValue))); |
164 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->version_id, temp, JSPROP_ENUMERATE)) { |
165 | 0 | return false; |
166 | 0 | } |
167 | 0 | break; |
168 | 0 | } while(false); |
169 | 0 | } |
170 | 0 |
|
171 | 0 | return true; |
172 | 0 | } |
173 | | |
174 | | bool |
175 | | IDBOpenDBOptions::ToJSON(nsAString& aJSON) const |
176 | 0 | { |
177 | 0 | AutoJSAPI jsapi; |
178 | 0 | jsapi.Init(); |
179 | 0 | JSContext *cx = jsapi.cx(); |
180 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
181 | 0 | // because we'll only be creating objects, in ways that have no |
182 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
183 | 0 | // which likewise guarantees no side-effects for the sorts of |
184 | 0 | // things we will pass it. |
185 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
186 | 0 | JS::Rooted<JS::Value> val(cx); |
187 | 0 | if (!ToObjectInternal(cx, &val)) { |
188 | 0 | return false; |
189 | 0 | } |
190 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
191 | 0 | return StringifyToJSON(cx, obj, aJSON); |
192 | 0 | } |
193 | | |
194 | | void |
195 | | IDBOpenDBOptions::TraceDictionary(JSTracer* trc) |
196 | 0 | { |
197 | 0 | } |
198 | | |
199 | | IDBOpenDBOptions& |
200 | | IDBOpenDBOptions::operator=(const IDBOpenDBOptions& aOther) |
201 | 0 | { |
202 | 0 | DictionaryBase::operator=(aOther); |
203 | 0 | mStorage.Reset(); |
204 | 0 | if (aOther.mStorage.WasPassed()) { |
205 | 0 | mStorage.Construct(aOther.mStorage.Value()); |
206 | 0 | } |
207 | 0 | mVersion.Reset(); |
208 | 0 | if (aOther.mVersion.WasPassed()) { |
209 | 0 | mVersion.Construct(aOther.mVersion.Value()); |
210 | 0 | } |
211 | 0 | return *this; |
212 | 0 | } |
213 | | |
214 | | namespace binding_detail { |
215 | | } // namespace binding_detail |
216 | | |
217 | | |
218 | | namespace IDBFactory_Binding { |
219 | | |
220 | | MOZ_CAN_RUN_SCRIPT static bool |
221 | | open(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBFactory* self, const JSJitMethodCallArgs& args) |
222 | 0 | { |
223 | 0 | AUTO_PROFILER_LABEL_FAST("IDBFactory.open", DOM, cx); |
224 | 0 |
|
225 | 0 | unsigned argcount = std::min(args.length(), 2u); |
226 | 0 | switch (argcount) { |
227 | 0 | case 1: { |
228 | 0 | binding_detail::FakeString arg0; |
229 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
230 | 0 | return false; |
231 | 0 | } |
232 | 0 | binding_detail::FastIDBOpenDBOptions arg1; |
233 | 0 | if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of IDBFactory.open", false)) { |
234 | 0 | return false; |
235 | 0 | } |
236 | 0 | FastErrorResult rv; |
237 | 0 | auto result(StrongOrRawPtr<mozilla::dom::IDBOpenDBRequest>(self->Open(cx, NonNullHelper(Constify(arg0)), Constify(arg1), nsContentUtils::ThreadsafeIsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem, rv))); |
238 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
239 | 0 | return false; |
240 | 0 | } |
241 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
242 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
243 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
244 | 0 | return false; |
245 | 0 | } |
246 | 0 | return true; |
247 | 0 | break; |
248 | 0 | } |
249 | 0 | case 2: { |
250 | 0 | binding_detail::FakeString arg0; |
251 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
252 | 0 | return false; |
253 | 0 | } |
254 | 0 | if (args[1].isNullOrUndefined()) { |
255 | 0 | binding_detail::FastIDBOpenDBOptions arg1; |
256 | 0 | if (!arg1.Init(cx, args[1], "Argument 2 of IDBFactory.open", false)) { |
257 | 0 | return false; |
258 | 0 | } |
259 | 0 | FastErrorResult rv; |
260 | 0 | auto result(StrongOrRawPtr<mozilla::dom::IDBOpenDBRequest>(self->Open(cx, NonNullHelper(Constify(arg0)), Constify(arg1), nsContentUtils::ThreadsafeIsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem, rv))); |
261 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
262 | 0 | return false; |
263 | 0 | } |
264 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
265 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
266 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
267 | 0 | return false; |
268 | 0 | } |
269 | 0 | return true; |
270 | 0 | } |
271 | 0 | if (args[1].isObject()) { |
272 | 0 | do { |
273 | 0 | binding_detail::FastIDBOpenDBOptions arg1; |
274 | 0 | if (!arg1.Init(cx, args[1], "Argument 2 of IDBFactory.open", false)) { |
275 | 0 | return false; |
276 | 0 | } |
277 | 0 | FastErrorResult rv; |
278 | 0 | auto result(StrongOrRawPtr<mozilla::dom::IDBOpenDBRequest>(self->Open(cx, NonNullHelper(Constify(arg0)), Constify(arg1), nsContentUtils::ThreadsafeIsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem, rv))); |
279 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
280 | 0 | return false; |
281 | 0 | } |
282 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
283 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
284 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
285 | 0 | return false; |
286 | 0 | } |
287 | 0 | return true; |
288 | 0 | } while (false); |
289 | 0 | } |
290 | 0 | uint64_t arg1; |
291 | 0 | if (!ValueToPrimitive<uint64_t, eEnforceRange>(cx, args[1], &arg1)) { |
292 | 0 | return false; |
293 | 0 | } |
294 | 0 | FastErrorResult rv; |
295 | 0 | auto result(StrongOrRawPtr<mozilla::dom::IDBOpenDBRequest>(self->Open(cx, NonNullHelper(Constify(arg0)), arg1, nsContentUtils::ThreadsafeIsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem, rv))); |
296 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
297 | 0 | return false; |
298 | 0 | } |
299 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
300 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
301 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
302 | 0 | return false; |
303 | 0 | } |
304 | 0 | return true; |
305 | 0 | break; |
306 | 0 | } |
307 | 0 | default: { |
308 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "IDBFactory.open"); |
309 | 0 | break; |
310 | 0 | } |
311 | 0 | } |
312 | 0 | MOZ_CRASH("We have an always-returning default case"); |
313 | 0 | return false; |
314 | 0 | } |
315 | | |
316 | | static const JSJitInfo open_methodinfo = { |
317 | | { (JSJitGetterOp)open }, |
318 | | { prototypes::id::IDBFactory }, |
319 | | { PrototypeTraits<prototypes::id::IDBFactory>::Depth }, |
320 | | JSJitInfo::Method, |
321 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
322 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
323 | | false, /* isInfallible. False in setters. */ |
324 | | false, /* isMovable. Not relevant for setters. */ |
325 | | false, /* isEliminatable. Not relevant for setters. */ |
326 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
327 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
328 | | false, /* isTypedMethod. Only relevant for methods. */ |
329 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
330 | | }; |
331 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
332 | | static_assert(0 < 1, "There is no slot for us"); |
333 | | |
334 | | MOZ_CAN_RUN_SCRIPT static bool |
335 | | deleteDatabase(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBFactory* self, const JSJitMethodCallArgs& args) |
336 | 0 | { |
337 | 0 | AUTO_PROFILER_LABEL_FAST("IDBFactory.deleteDatabase", DOM, cx); |
338 | 0 |
|
339 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
340 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "IDBFactory.deleteDatabase"); |
341 | 0 | } |
342 | 0 | binding_detail::FakeString arg0; |
343 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
344 | 0 | return false; |
345 | 0 | } |
346 | 0 | binding_detail::FastIDBOpenDBOptions arg1; |
347 | 0 | if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of IDBFactory.deleteDatabase", false)) { |
348 | 0 | return false; |
349 | 0 | } |
350 | 0 | FastErrorResult rv; |
351 | 0 | auto result(StrongOrRawPtr<mozilla::dom::IDBOpenDBRequest>(self->DeleteDatabase(cx, NonNullHelper(Constify(arg0)), Constify(arg1), nsContentUtils::ThreadsafeIsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem, rv))); |
352 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
353 | 0 | return false; |
354 | 0 | } |
355 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
356 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
357 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
358 | 0 | return false; |
359 | 0 | } |
360 | 0 | return true; |
361 | 0 | } |
362 | | |
363 | | static const JSJitInfo deleteDatabase_methodinfo = { |
364 | | { (JSJitGetterOp)deleteDatabase }, |
365 | | { prototypes::id::IDBFactory }, |
366 | | { PrototypeTraits<prototypes::id::IDBFactory>::Depth }, |
367 | | JSJitInfo::Method, |
368 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
369 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
370 | | false, /* isInfallible. False in setters. */ |
371 | | false, /* isMovable. Not relevant for setters. */ |
372 | | false, /* isEliminatable. Not relevant for setters. */ |
373 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
374 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
375 | | false, /* isTypedMethod. Only relevant for methods. */ |
376 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
377 | | }; |
378 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
379 | | static_assert(0 < 1, "There is no slot for us"); |
380 | | |
381 | | MOZ_CAN_RUN_SCRIPT static bool |
382 | | cmp(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBFactory* self, const JSJitMethodCallArgs& args) |
383 | 0 | { |
384 | 0 | AUTO_PROFILER_LABEL_FAST("IDBFactory.cmp", DOM, cx); |
385 | 0 |
|
386 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
387 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "IDBFactory.cmp"); |
388 | 0 | } |
389 | 0 | JS::Rooted<JS::Value> arg0(cx); |
390 | 0 | arg0 = args[0]; |
391 | 0 | JS::Rooted<JS::Value> arg1(cx); |
392 | 0 | arg1 = args[1]; |
393 | 0 | FastErrorResult rv; |
394 | 0 | int16_t result(self->Cmp(cx, arg0, arg1, rv)); |
395 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
396 | 0 | return false; |
397 | 0 | } |
398 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
399 | 0 | args.rval().setInt32(int32_t(result)); |
400 | 0 | return true; |
401 | 0 | } |
402 | | |
403 | | static const JSJitInfo cmp_methodinfo = { |
404 | | { (JSJitGetterOp)cmp }, |
405 | | { prototypes::id::IDBFactory }, |
406 | | { PrototypeTraits<prototypes::id::IDBFactory>::Depth }, |
407 | | JSJitInfo::Method, |
408 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
409 | | JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */ |
410 | | false, /* isInfallible. False in setters. */ |
411 | | false, /* isMovable. Not relevant for setters. */ |
412 | | false, /* isEliminatable. Not relevant for setters. */ |
413 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
414 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
415 | | false, /* isTypedMethod. Only relevant for methods. */ |
416 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
417 | | }; |
418 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
419 | | static_assert(0 < 1, "There is no slot for us"); |
420 | | |
421 | | MOZ_CAN_RUN_SCRIPT static bool |
422 | | openForPrincipal(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBFactory* self, const JSJitMethodCallArgs& args) |
423 | 0 | { |
424 | 0 | AUTO_PROFILER_LABEL_FAST("IDBFactory.openForPrincipal", DOM, cx); |
425 | 0 |
|
426 | 0 | unsigned argcount = std::min(args.length(), 3u); |
427 | 0 | switch (argcount) { |
428 | 0 | case 2: { |
429 | 0 | nsIPrincipal* arg0; |
430 | 0 | RefPtr<nsIPrincipal> arg0_holder; |
431 | 0 | if (args[0].isObject()) { |
432 | 0 | JS::Rooted<JSObject*> source(cx, &args[0].toObject()); |
433 | 0 | if (NS_FAILED(UnwrapArg<nsIPrincipal>(cx, source, getter_AddRefs(arg0_holder)))) { |
434 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of IDBFactory.openForPrincipal", "Principal"); |
435 | 0 | return false; |
436 | 0 | } |
437 | 0 | MOZ_ASSERT(arg0_holder); |
438 | 0 | arg0 = arg0_holder; |
439 | 0 | } else { |
440 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of IDBFactory.openForPrincipal"); |
441 | 0 | return false; |
442 | 0 | } |
443 | 0 | binding_detail::FakeString arg1; |
444 | 0 | if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) { |
445 | 0 | return false; |
446 | 0 | } |
447 | 0 | binding_detail::FastIDBOpenDBOptions arg2; |
448 | 0 | if (!arg2.Init(cx, (args.hasDefined(2)) ? args[2] : JS::NullHandleValue, "Argument 3 of IDBFactory.openForPrincipal", false)) { |
449 | 0 | return false; |
450 | 0 | } |
451 | 0 | FastErrorResult rv; |
452 | 0 | auto result(StrongOrRawPtr<mozilla::dom::IDBOpenDBRequest>(self->OpenForPrincipal(cx, MOZ_KnownLive(NonNullHelper(arg0)), NonNullHelper(Constify(arg1)), Constify(arg2), SystemCallerGuarantee(), rv))); |
453 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
454 | 0 | return false; |
455 | 0 | } |
456 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
457 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
458 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
459 | 0 | return false; |
460 | 0 | } |
461 | 0 | return true; |
462 | 0 | break; |
463 | 0 | } |
464 | 0 | case 3: { |
465 | 0 | nsIPrincipal* arg0; |
466 | 0 | RefPtr<nsIPrincipal> arg0_holder; |
467 | 0 | if (args[0].isObject()) { |
468 | 0 | JS::Rooted<JSObject*> source(cx, &args[0].toObject()); |
469 | 0 | if (NS_FAILED(UnwrapArg<nsIPrincipal>(cx, source, getter_AddRefs(arg0_holder)))) { |
470 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of IDBFactory.openForPrincipal", "Principal"); |
471 | 0 | return false; |
472 | 0 | } |
473 | 0 | MOZ_ASSERT(arg0_holder); |
474 | 0 | arg0 = arg0_holder; |
475 | 0 | } else { |
476 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of IDBFactory.openForPrincipal"); |
477 | 0 | return false; |
478 | 0 | } |
479 | 0 | binding_detail::FakeString arg1; |
480 | 0 | if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) { |
481 | 0 | return false; |
482 | 0 | } |
483 | 0 | if (args[2].isNullOrUndefined()) { |
484 | 0 | binding_detail::FastIDBOpenDBOptions arg2; |
485 | 0 | if (!arg2.Init(cx, args[2], "Argument 3 of IDBFactory.openForPrincipal", false)) { |
486 | 0 | return false; |
487 | 0 | } |
488 | 0 | FastErrorResult rv; |
489 | 0 | auto result(StrongOrRawPtr<mozilla::dom::IDBOpenDBRequest>(self->OpenForPrincipal(cx, MOZ_KnownLive(NonNullHelper(arg0)), NonNullHelper(Constify(arg1)), Constify(arg2), SystemCallerGuarantee(), rv))); |
490 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
491 | 0 | return false; |
492 | 0 | } |
493 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
494 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
495 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
496 | 0 | return false; |
497 | 0 | } |
498 | 0 | return true; |
499 | 0 | } |
500 | 0 | if (args[2].isObject()) { |
501 | 0 | do { |
502 | 0 | binding_detail::FastIDBOpenDBOptions arg2; |
503 | 0 | if (!arg2.Init(cx, args[2], "Argument 3 of IDBFactory.openForPrincipal", false)) { |
504 | 0 | return false; |
505 | 0 | } |
506 | 0 | FastErrorResult rv; |
507 | 0 | auto result(StrongOrRawPtr<mozilla::dom::IDBOpenDBRequest>(self->OpenForPrincipal(cx, MOZ_KnownLive(NonNullHelper(arg0)), NonNullHelper(Constify(arg1)), Constify(arg2), SystemCallerGuarantee(), rv))); |
508 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
509 | 0 | return false; |
510 | 0 | } |
511 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
512 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
513 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
514 | 0 | return false; |
515 | 0 | } |
516 | 0 | return true; |
517 | 0 | } while (false); |
518 | 0 | } |
519 | 0 | uint64_t arg2; |
520 | 0 | if (!ValueToPrimitive<uint64_t, eEnforceRange>(cx, args[2], &arg2)) { |
521 | 0 | return false; |
522 | 0 | } |
523 | 0 | FastErrorResult rv; |
524 | 0 | auto result(StrongOrRawPtr<mozilla::dom::IDBOpenDBRequest>(self->OpenForPrincipal(cx, MOZ_KnownLive(NonNullHelper(arg0)), NonNullHelper(Constify(arg1)), arg2, SystemCallerGuarantee(), rv))); |
525 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
526 | 0 | return false; |
527 | 0 | } |
528 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
529 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
530 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
531 | 0 | return false; |
532 | 0 | } |
533 | 0 | return true; |
534 | 0 | break; |
535 | 0 | } |
536 | 0 | default: { |
537 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "IDBFactory.openForPrincipal"); |
538 | 0 | break; |
539 | 0 | } |
540 | 0 | } |
541 | 0 | MOZ_CRASH("We have an always-returning default case"); |
542 | 0 | return false; |
543 | 0 | } |
544 | | |
545 | | static const JSJitInfo openForPrincipal_methodinfo = { |
546 | | { (JSJitGetterOp)openForPrincipal }, |
547 | | { prototypes::id::IDBFactory }, |
548 | | { PrototypeTraits<prototypes::id::IDBFactory>::Depth }, |
549 | | JSJitInfo::Method, |
550 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
551 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
552 | | false, /* isInfallible. False in setters. */ |
553 | | false, /* isMovable. Not relevant for setters. */ |
554 | | false, /* isEliminatable. Not relevant for setters. */ |
555 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
556 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
557 | | false, /* isTypedMethod. Only relevant for methods. */ |
558 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
559 | | }; |
560 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
561 | | static_assert(0 < 1, "There is no slot for us"); |
562 | | |
563 | | MOZ_CAN_RUN_SCRIPT static bool |
564 | | deleteForPrincipal(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBFactory* self, const JSJitMethodCallArgs& args) |
565 | 0 | { |
566 | 0 | AUTO_PROFILER_LABEL_FAST("IDBFactory.deleteForPrincipal", DOM, cx); |
567 | 0 |
|
568 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
569 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "IDBFactory.deleteForPrincipal"); |
570 | 0 | } |
571 | 0 | nsIPrincipal* arg0; |
572 | 0 | RefPtr<nsIPrincipal> arg0_holder; |
573 | 0 | if (args[0].isObject()) { |
574 | 0 | JS::Rooted<JSObject*> source(cx, &args[0].toObject()); |
575 | 0 | if (NS_FAILED(UnwrapArg<nsIPrincipal>(cx, source, getter_AddRefs(arg0_holder)))) { |
576 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of IDBFactory.deleteForPrincipal", "Principal"); |
577 | 0 | return false; |
578 | 0 | } |
579 | 0 | MOZ_ASSERT(arg0_holder); |
580 | 0 | arg0 = arg0_holder; |
581 | 0 | } else { |
582 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of IDBFactory.deleteForPrincipal"); |
583 | 0 | return false; |
584 | 0 | } |
585 | 0 | binding_detail::FakeString arg1; |
586 | 0 | if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) { |
587 | 0 | return false; |
588 | 0 | } |
589 | 0 | binding_detail::FastIDBOpenDBOptions arg2; |
590 | 0 | if (!arg2.Init(cx, (args.hasDefined(2)) ? args[2] : JS::NullHandleValue, "Argument 3 of IDBFactory.deleteForPrincipal", false)) { |
591 | 0 | return false; |
592 | 0 | } |
593 | 0 | FastErrorResult rv; |
594 | 0 | auto result(StrongOrRawPtr<mozilla::dom::IDBOpenDBRequest>(self->DeleteForPrincipal(cx, MOZ_KnownLive(NonNullHelper(arg0)), NonNullHelper(Constify(arg1)), Constify(arg2), SystemCallerGuarantee(), rv))); |
595 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
596 | 0 | return false; |
597 | 0 | } |
598 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
599 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
600 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
601 | 0 | return false; |
602 | 0 | } |
603 | 0 | return true; |
604 | 0 | } |
605 | | |
606 | | static const JSJitInfo deleteForPrincipal_methodinfo = { |
607 | | { (JSJitGetterOp)deleteForPrincipal }, |
608 | | { prototypes::id::IDBFactory }, |
609 | | { PrototypeTraits<prototypes::id::IDBFactory>::Depth }, |
610 | | JSJitInfo::Method, |
611 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
612 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
613 | | false, /* isInfallible. False in setters. */ |
614 | | false, /* isMovable. Not relevant for setters. */ |
615 | | false, /* isEliminatable. Not relevant for setters. */ |
616 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
617 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
618 | | false, /* isTypedMethod. Only relevant for methods. */ |
619 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
620 | | }; |
621 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
622 | | static_assert(0 < 1, "There is no slot for us"); |
623 | | |
624 | | static bool |
625 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
626 | 0 | { |
627 | 0 | mozilla::dom::IDBFactory* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::IDBFactory>(obj); |
628 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
629 | 0 | // obviously can't preserve if we're not initialized. |
630 | 0 | if (self && self->GetWrapperPreserveColor()) { |
631 | 0 | PreserveWrapper(self); |
632 | 0 | } |
633 | 0 | return true; |
634 | 0 | } |
635 | | |
636 | | static void |
637 | | _finalize(js::FreeOp* fop, JSObject* obj) |
638 | 0 | { |
639 | 0 | mozilla::dom::IDBFactory* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::IDBFactory>(obj); |
640 | 0 | if (self) { |
641 | 0 | ClearWrapper(self, self, obj); |
642 | 0 | AddForDeferredFinalization<mozilla::dom::IDBFactory>(self); |
643 | 0 | } |
644 | 0 | } |
645 | | |
646 | | static size_t |
647 | | _objectMoved(JSObject* obj, JSObject* old) |
648 | 0 | { |
649 | 0 | mozilla::dom::IDBFactory* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::IDBFactory>(obj); |
650 | 0 | if (self) { |
651 | 0 | UpdateWrapper(self, self, obj, old); |
652 | 0 | } |
653 | 0 |
|
654 | 0 | return 0; |
655 | 0 | } |
656 | | |
657 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
658 | | #if defined(__clang__) |
659 | | #pragma clang diagnostic push |
660 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
661 | | #endif |
662 | | static const JSFunctionSpec sMethods_specs[] = { |
663 | | JS_FNSPEC("open", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&open_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
664 | | JS_FNSPEC("deleteDatabase", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&deleteDatabase_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
665 | | JS_FNSPEC("cmp", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&cmp_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
666 | | JS_FS_END |
667 | | }; |
668 | | #if defined(__clang__) |
669 | | #pragma clang diagnostic pop |
670 | | #endif |
671 | | |
672 | | |
673 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
674 | | { nullptr, &sMethods_specs[0] }, |
675 | | { nullptr, nullptr } |
676 | | }; |
677 | | |
678 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
679 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
680 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
681 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
682 | | |
683 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
684 | | #if defined(__clang__) |
685 | | #pragma clang diagnostic push |
686 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
687 | | #endif |
688 | | static const JSFunctionSpec sChromeMethods_specs[] = { |
689 | | JS_FNSPEC("openForPrincipal", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&openForPrincipal_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
690 | | JS_FNSPEC("deleteForPrincipal", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&deleteForPrincipal_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
691 | | JS_FS_END |
692 | | }; |
693 | | #if defined(__clang__) |
694 | | #pragma clang diagnostic pop |
695 | | #endif |
696 | | |
697 | | |
698 | | static const Prefable<const JSFunctionSpec> sChromeMethods[] = { |
699 | | { nullptr, &sChromeMethods_specs[0] }, |
700 | | { nullptr, nullptr } |
701 | | }; |
702 | | |
703 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
704 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
705 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
706 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
707 | | |
708 | | |
709 | | static uint16_t sNativeProperties_sortedPropertyIndices[3]; |
710 | | static PropertyInfo sNativeProperties_propertyInfos[3]; |
711 | | |
712 | | static const NativePropertiesN<1> sNativeProperties = { |
713 | | false, 0, |
714 | | false, 0, |
715 | | true, 0 /* sMethods */, |
716 | | false, 0, |
717 | | false, 0, |
718 | | false, 0, |
719 | | false, 0, |
720 | | -1, |
721 | | 3, |
722 | | sNativeProperties_sortedPropertyIndices, |
723 | | { |
724 | | { sMethods, &sNativeProperties_propertyInfos[0] } |
725 | | } |
726 | | }; |
727 | | static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
728 | | "We have a property info count that is oversized"); |
729 | | |
730 | | static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[2]; |
731 | | static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[2]; |
732 | | |
733 | | static const NativePropertiesN<1> sChromeOnlyNativeProperties = { |
734 | | false, 0, |
735 | | false, 0, |
736 | | true, 0 /* sChromeMethods */, |
737 | | false, 0, |
738 | | false, 0, |
739 | | false, 0, |
740 | | false, 0, |
741 | | -1, |
742 | | 2, |
743 | | sChromeOnlyNativeProperties_sortedPropertyIndices, |
744 | | { |
745 | | { sChromeMethods, &sChromeOnlyNativeProperties_propertyInfos[0] } |
746 | | } |
747 | | }; |
748 | | static_assert(2 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount), |
749 | | "We have a property info count that is oversized"); |
750 | | |
751 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
752 | | { |
753 | | "Function", |
754 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
755 | | &sBoringInterfaceObjectClassClassOps, |
756 | | JS_NULL_CLASS_SPEC, |
757 | | JS_NULL_CLASS_EXT, |
758 | | &sInterfaceObjectClassObjectOps |
759 | | }, |
760 | | eInterface, |
761 | | true, |
762 | | prototypes::id::IDBFactory, |
763 | | PrototypeTraits<prototypes::id::IDBFactory>::Depth, |
764 | | sNativePropertyHooks, |
765 | | "function IDBFactory() {\n [native code]\n}", |
766 | | JS::GetRealmFunctionPrototype |
767 | | }; |
768 | | |
769 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
770 | | { |
771 | | "IDBFactoryPrototype", |
772 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
773 | | JS_NULL_CLASS_OPS, |
774 | | JS_NULL_CLASS_SPEC, |
775 | | JS_NULL_CLASS_EXT, |
776 | | JS_NULL_OBJECT_OPS |
777 | | }, |
778 | | eInterfacePrototype, |
779 | | false, |
780 | | prototypes::id::IDBFactory, |
781 | | PrototypeTraits<prototypes::id::IDBFactory>::Depth, |
782 | | sNativePropertyHooks, |
783 | | "[object IDBFactoryPrototype]", |
784 | | JS::GetRealmObjectPrototype |
785 | | }; |
786 | | |
787 | | static const js::ClassOps sClassOps = { |
788 | | _addProperty, /* addProperty */ |
789 | | nullptr, /* delProperty */ |
790 | | nullptr, /* enumerate */ |
791 | | nullptr, /* newEnumerate */ |
792 | | nullptr, /* resolve */ |
793 | | nullptr, /* mayResolve */ |
794 | | _finalize, /* finalize */ |
795 | | nullptr, /* call */ |
796 | | nullptr, /* hasInstance */ |
797 | | nullptr, /* construct */ |
798 | | nullptr, /* trace */ |
799 | | }; |
800 | | |
801 | | static const js::ClassExtension sClassExtension = { |
802 | | nullptr, /* weakmapKeyDelegateOp */ |
803 | | _objectMoved /* objectMovedOp */ |
804 | | }; |
805 | | |
806 | | static const DOMJSClass sClass = { |
807 | | { "IDBFactory", |
808 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
809 | | &sClassOps, |
810 | | JS_NULL_CLASS_SPEC, |
811 | | &sClassExtension, |
812 | | JS_NULL_OBJECT_OPS |
813 | | }, |
814 | | { prototypes::id::IDBFactory, 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 }, |
815 | | IsBaseOf<nsISupports, mozilla::dom::IDBFactory >::value, |
816 | | sNativePropertyHooks, |
817 | | FindAssociatedGlobalForNative<mozilla::dom::IDBFactory>::Get, |
818 | | GetProtoObjectHandle, |
819 | | GetCCParticipant<mozilla::dom::IDBFactory>::Get() |
820 | | }; |
821 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
822 | | "Must have the right minimal number of reserved slots."); |
823 | | static_assert(1 >= 1, |
824 | | "Must have enough reserved slots."); |
825 | | |
826 | | const JSClass* |
827 | | GetJSClass() |
828 | 0 | { |
829 | 0 | return sClass.ToJSClass(); |
830 | 0 | } |
831 | | |
832 | | bool |
833 | | Wrap(JSContext* aCx, mozilla::dom::IDBFactory* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
834 | 0 | { |
835 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::IDBFactory>::value, |
836 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
837 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::IDBFactory*>(aObject) == |
838 | 0 | reinterpret_cast<mozilla::dom::IDBFactory*>(aObject), |
839 | 0 | "Multiple inheritance for mozilla::dom::IDBFactory is broken."); |
840 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
841 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
842 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
843 | 0 | "You should probably not be using Wrap() directly; use " |
844 | 0 | "GetOrCreateDOMReflector instead"); |
845 | 0 |
|
846 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
847 | 0 | "nsISupports must be on our primary inheritance chain"); |
848 | 0 |
|
849 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
850 | 0 | if (!global) { |
851 | 0 | return false; |
852 | 0 | } |
853 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
854 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
855 | 0 |
|
856 | 0 | // That might have ended up wrapping us already, due to the wonders |
857 | 0 | // of XBL. Check for that, and bail out as needed. |
858 | 0 | aReflector.set(aCache->GetWrapper()); |
859 | 0 | if (aReflector) { |
860 | | #ifdef DEBUG |
861 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
862 | | #endif // DEBUG |
863 | | return true; |
864 | 0 | } |
865 | 0 |
|
866 | 0 | JSAutoRealm ar(aCx, global); |
867 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
868 | 0 | if (!canonicalProto) { |
869 | 0 | return false; |
870 | 0 | } |
871 | 0 | JS::Rooted<JSObject*> proto(aCx); |
872 | 0 | if (aGivenProto) { |
873 | 0 | proto = aGivenProto; |
874 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
875 | 0 | // coming in, we changed compartments to that of "parent" so may need |
876 | 0 | // to wrap the proto here. |
877 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
878 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
879 | 0 | return false; |
880 | 0 | } |
881 | 0 | } |
882 | 0 | } else { |
883 | 0 | proto = canonicalProto; |
884 | 0 | } |
885 | 0 |
|
886 | 0 | BindingJSObjectCreator<mozilla::dom::IDBFactory> creator(aCx); |
887 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
888 | 0 | if (!aReflector) { |
889 | 0 | return false; |
890 | 0 | } |
891 | 0 | |
892 | 0 | aCache->SetWrapper(aReflector); |
893 | 0 | creator.InitializationSucceeded(); |
894 | 0 |
|
895 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
896 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
897 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
898 | 0 | // otherwise we won't be able to properly recreate it later, since |
899 | 0 | // we won't know what proto to use. Note that we don't check |
900 | 0 | // aGivenProto here, since it's entirely possible (and even |
901 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
902 | 0 | // same as canonicalProto. |
903 | 0 | if (proto != canonicalProto) { |
904 | 0 | PreserveWrapper(aObject); |
905 | 0 | } |
906 | 0 |
|
907 | 0 | return true; |
908 | 0 | } |
909 | | |
910 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
911 | | nullptr, |
912 | | nullptr, |
913 | | nullptr, |
914 | | { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() }, |
915 | | prototypes::id::IDBFactory, |
916 | | constructors::id::IDBFactory, |
917 | | nullptr, |
918 | | &DefaultXrayExpandoObjectClass |
919 | | } }; |
920 | | |
921 | | void |
922 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
923 | 0 | { |
924 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
925 | 0 | if (!parentProto) { |
926 | 0 | return; |
927 | 0 | } |
928 | 0 | |
929 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
930 | 0 | if (!constructorProto) { |
931 | 0 | return; |
932 | 0 | } |
933 | 0 | |
934 | 0 | static bool sIdsInited = false; |
935 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
936 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
937 | 0 | return; |
938 | 0 | } |
939 | 0 | if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) { |
940 | 0 | return; |
941 | 0 | } |
942 | 0 | sIdsInited = true; |
943 | 0 | } |
944 | 0 |
|
945 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::IDBFactory); |
946 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::IDBFactory); |
947 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
948 | 0 | &sPrototypeClass.mBase, protoCache, |
949 | 0 | nullptr, |
950 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
951 | 0 | interfaceCache, |
952 | 0 | sNativeProperties.Upcast(), |
953 | 0 | sChromeOnlyNativeProperties.Upcast(), |
954 | 0 | "IDBFactory", aDefineOnGlobal, |
955 | 0 | nullptr, |
956 | 0 | false); |
957 | 0 | } |
958 | | |
959 | | JSObject* |
960 | | GetConstructorObject(JSContext* aCx) |
961 | 0 | { |
962 | 0 | return GetConstructorObjectHandle(aCx); |
963 | 0 | } |
964 | | |
965 | | } // namespace IDBFactory_Binding |
966 | | |
967 | | |
968 | | |
969 | | } // namespace dom |
970 | | } // namespace mozilla |