/work/obj-fuzz/dom/bindings/CryptoBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM Crypto.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "Crypto.h" |
4 | | #include "CryptoBinding.h" |
5 | | #include "WrapperFactory.h" |
6 | | #include "jsfriendapi.h" |
7 | | #include "mozilla/OwningNonNull.h" |
8 | | #include "mozilla/dom/BindingUtils.h" |
9 | | #include "mozilla/dom/DOMJSClass.h" |
10 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
11 | | #include "mozilla/dom/SubtleCrypto.h" |
12 | | #include "mozilla/dom/TypedArray.h" |
13 | | #include "mozilla/dom/XrayExpandoClass.h" |
14 | | |
15 | | namespace mozilla { |
16 | | namespace dom { |
17 | | |
18 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
19 | | using namespace mozilla::dom::binding_detail; |
20 | | |
21 | | |
22 | | namespace Crypto_Binding { |
23 | | |
24 | | MOZ_CAN_RUN_SCRIPT static bool |
25 | | get_subtle(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Crypto* self, JSJitGetterCallArgs args) |
26 | 0 | { |
27 | 0 | AUTO_PROFILER_LABEL_FAST("get Crypto.subtle", DOM, cx); |
28 | 0 |
|
29 | 0 | auto result(StrongOrRawPtr<mozilla::dom::SubtleCrypto>(self->Subtle())); |
30 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
31 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
32 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
33 | 0 | return false; |
34 | 0 | } |
35 | 0 | return true; |
36 | 0 | } |
37 | | |
38 | | static const JSJitInfo subtle_getterinfo = { |
39 | | { (JSJitGetterOp)get_subtle }, |
40 | | { prototypes::id::Crypto }, |
41 | | { PrototypeTraits<prototypes::id::Crypto>::Depth }, |
42 | | JSJitInfo::Getter, |
43 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
44 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
45 | | false, /* isInfallible. False in setters. */ |
46 | | false, /* isMovable. Not relevant for setters. */ |
47 | | false, /* isEliminatable. Not relevant for setters. */ |
48 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
49 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
50 | | false, /* isTypedMethod. Only relevant for methods. */ |
51 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
52 | | }; |
53 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
54 | | static_assert(0 < 1, "There is no slot for us"); |
55 | | |
56 | | MOZ_CAN_RUN_SCRIPT static bool |
57 | | getRandomValues(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Crypto* self, const JSJitMethodCallArgs& args) |
58 | 0 | { |
59 | 0 | AUTO_PROFILER_LABEL_FAST("Crypto.getRandomValues", DOM, cx); |
60 | 0 |
|
61 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
62 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Crypto.getRandomValues"); |
63 | 0 | } |
64 | 0 | RootedSpiderMonkeyInterface<ArrayBufferView> arg0(cx); |
65 | 0 | if (args[0].isObject()) { |
66 | 0 | if (!arg0.Init(&args[0].toObject())) { |
67 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of Crypto.getRandomValues", "ArrayBufferView"); |
68 | 0 | return false; |
69 | 0 | } |
70 | 0 | } else { |
71 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of Crypto.getRandomValues"); |
72 | 0 | return false; |
73 | 0 | } |
74 | 0 | FastErrorResult rv; |
75 | 0 | JS::Rooted<JSObject*> result(cx); |
76 | 0 | self->GetRandomValues(cx, Constify(arg0), &result, rv); |
77 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
78 | 0 | return false; |
79 | 0 | } |
80 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
81 | 0 | JS::ExposeObjectToActiveJS(result); |
82 | 0 | args.rval().setObject(*result); |
83 | 0 | if (!MaybeWrapNonDOMObjectValue(cx, args.rval())) { |
84 | 0 | return false; |
85 | 0 | } |
86 | 0 | return true; |
87 | 0 | } |
88 | | |
89 | | static const JSJitInfo getRandomValues_methodinfo = { |
90 | | { (JSJitGetterOp)getRandomValues }, |
91 | | { prototypes::id::Crypto }, |
92 | | { PrototypeTraits<prototypes::id::Crypto>::Depth }, |
93 | | JSJitInfo::Method, |
94 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
95 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
96 | | false, /* isInfallible. False in setters. */ |
97 | | false, /* isMovable. Not relevant for setters. */ |
98 | | false, /* isEliminatable. Not relevant for setters. */ |
99 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
100 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
101 | | false, /* isTypedMethod. Only relevant for methods. */ |
102 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
103 | | }; |
104 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
105 | | static_assert(0 < 1, "There is no slot for us"); |
106 | | |
107 | | static bool |
108 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
109 | 0 | { |
110 | 0 | mozilla::dom::Crypto* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Crypto>(obj); |
111 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
112 | 0 | // obviously can't preserve if we're not initialized. |
113 | 0 | if (self && self->GetWrapperPreserveColor()) { |
114 | 0 | PreserveWrapper(self); |
115 | 0 | } |
116 | 0 | return true; |
117 | 0 | } |
118 | | |
119 | | static void |
120 | | _finalize(js::FreeOp* fop, JSObject* obj) |
121 | 0 | { |
122 | 0 | mozilla::dom::Crypto* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Crypto>(obj); |
123 | 0 | if (self) { |
124 | 0 | ClearWrapper(self, self, obj); |
125 | 0 | AddForDeferredFinalization<mozilla::dom::Crypto>(self); |
126 | 0 | } |
127 | 0 | } |
128 | | |
129 | | static size_t |
130 | | _objectMoved(JSObject* obj, JSObject* old) |
131 | 0 | { |
132 | 0 | mozilla::dom::Crypto* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Crypto>(obj); |
133 | 0 | if (self) { |
134 | 0 | UpdateWrapper(self, self, obj, old); |
135 | 0 | } |
136 | 0 |
|
137 | 0 | return 0; |
138 | 0 | } |
139 | | |
140 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
141 | | #if defined(__clang__) |
142 | | #pragma clang diagnostic push |
143 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
144 | | #endif |
145 | | static const JSFunctionSpec sMethods_specs[] = { |
146 | | JS_FNSPEC("getRandomValues", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getRandomValues_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
147 | | JS_FS_END |
148 | | }; |
149 | | #if defined(__clang__) |
150 | | #pragma clang diagnostic pop |
151 | | #endif |
152 | | |
153 | | |
154 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
155 | | { nullptr, &sMethods_specs[0] }, |
156 | | { nullptr, nullptr } |
157 | | }; |
158 | | |
159 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
160 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
161 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
162 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
163 | | |
164 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
165 | | #if defined(__clang__) |
166 | | #pragma clang diagnostic push |
167 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
168 | | #endif |
169 | | static const JSPropertySpec sAttributes_specs[] = { |
170 | | { "subtle", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &subtle_getterinfo, nullptr, nullptr }, |
171 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
172 | | }; |
173 | | #if defined(__clang__) |
174 | | #pragma clang diagnostic pop |
175 | | #endif |
176 | | |
177 | | |
178 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
179 | | { nullptr, &sAttributes_specs[0] }, |
180 | | { nullptr, nullptr } |
181 | | }; |
182 | | |
183 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
184 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
185 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
186 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
187 | | |
188 | | |
189 | | static uint16_t sNativeProperties_sortedPropertyIndices[2]; |
190 | | static PropertyInfo sNativeProperties_propertyInfos[2]; |
191 | | |
192 | | static const NativePropertiesN<2> sNativeProperties = { |
193 | | false, 0, |
194 | | false, 0, |
195 | | true, 0 /* sMethods */, |
196 | | true, 1 /* sAttributes */, |
197 | | false, 0, |
198 | | false, 0, |
199 | | false, 0, |
200 | | -1, |
201 | | 2, |
202 | | sNativeProperties_sortedPropertyIndices, |
203 | | { |
204 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
205 | | { sAttributes, &sNativeProperties_propertyInfos[1] } |
206 | | } |
207 | | }; |
208 | | static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
209 | | "We have a property info count that is oversized"); |
210 | | |
211 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
212 | | { |
213 | | "Function", |
214 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
215 | | &sBoringInterfaceObjectClassClassOps, |
216 | | JS_NULL_CLASS_SPEC, |
217 | | JS_NULL_CLASS_EXT, |
218 | | &sInterfaceObjectClassObjectOps |
219 | | }, |
220 | | eInterface, |
221 | | true, |
222 | | prototypes::id::Crypto, |
223 | | PrototypeTraits<prototypes::id::Crypto>::Depth, |
224 | | sNativePropertyHooks, |
225 | | "function Crypto() {\n [native code]\n}", |
226 | | JS::GetRealmFunctionPrototype |
227 | | }; |
228 | | |
229 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
230 | | { |
231 | | "CryptoPrototype", |
232 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
233 | | JS_NULL_CLASS_OPS, |
234 | | JS_NULL_CLASS_SPEC, |
235 | | JS_NULL_CLASS_EXT, |
236 | | JS_NULL_OBJECT_OPS |
237 | | }, |
238 | | eInterfacePrototype, |
239 | | false, |
240 | | prototypes::id::Crypto, |
241 | | PrototypeTraits<prototypes::id::Crypto>::Depth, |
242 | | sNativePropertyHooks, |
243 | | "[object CryptoPrototype]", |
244 | | JS::GetRealmObjectPrototype |
245 | | }; |
246 | | |
247 | | static const js::ClassOps sClassOps = { |
248 | | _addProperty, /* addProperty */ |
249 | | nullptr, /* delProperty */ |
250 | | nullptr, /* enumerate */ |
251 | | nullptr, /* newEnumerate */ |
252 | | nullptr, /* resolve */ |
253 | | nullptr, /* mayResolve */ |
254 | | _finalize, /* finalize */ |
255 | | nullptr, /* call */ |
256 | | nullptr, /* hasInstance */ |
257 | | nullptr, /* construct */ |
258 | | nullptr, /* trace */ |
259 | | }; |
260 | | |
261 | | static const js::ClassExtension sClassExtension = { |
262 | | nullptr, /* weakmapKeyDelegateOp */ |
263 | | _objectMoved /* objectMovedOp */ |
264 | | }; |
265 | | |
266 | | static const DOMJSClass sClass = { |
267 | | { "Crypto", |
268 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
269 | | &sClassOps, |
270 | | JS_NULL_CLASS_SPEC, |
271 | | &sClassExtension, |
272 | | JS_NULL_OBJECT_OPS |
273 | | }, |
274 | | { prototypes::id::Crypto, 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 }, |
275 | | IsBaseOf<nsISupports, mozilla::dom::Crypto >::value, |
276 | | sNativePropertyHooks, |
277 | | FindAssociatedGlobalForNative<mozilla::dom::Crypto>::Get, |
278 | | GetProtoObjectHandle, |
279 | | GetCCParticipant<mozilla::dom::Crypto>::Get() |
280 | | }; |
281 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
282 | | "Must have the right minimal number of reserved slots."); |
283 | | static_assert(1 >= 1, |
284 | | "Must have enough reserved slots."); |
285 | | |
286 | | const JSClass* |
287 | | GetJSClass() |
288 | 0 | { |
289 | 0 | return sClass.ToJSClass(); |
290 | 0 | } |
291 | | |
292 | | bool |
293 | | Wrap(JSContext* aCx, mozilla::dom::Crypto* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
294 | 0 | { |
295 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::Crypto>::value, |
296 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
297 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::Crypto*>(aObject) == |
298 | 0 | reinterpret_cast<mozilla::dom::Crypto*>(aObject), |
299 | 0 | "Multiple inheritance for mozilla::dom::Crypto is broken."); |
300 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
301 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
302 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
303 | 0 | "You should probably not be using Wrap() directly; use " |
304 | 0 | "GetOrCreateDOMReflector instead"); |
305 | 0 |
|
306 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
307 | 0 | "nsISupports must be on our primary inheritance chain"); |
308 | 0 |
|
309 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
310 | 0 | if (!global) { |
311 | 0 | return false; |
312 | 0 | } |
313 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
314 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
315 | 0 |
|
316 | 0 | // That might have ended up wrapping us already, due to the wonders |
317 | 0 | // of XBL. Check for that, and bail out as needed. |
318 | 0 | aReflector.set(aCache->GetWrapper()); |
319 | 0 | if (aReflector) { |
320 | | #ifdef DEBUG |
321 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
322 | | #endif // DEBUG |
323 | | return true; |
324 | 0 | } |
325 | 0 |
|
326 | 0 | JSAutoRealm ar(aCx, global); |
327 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
328 | 0 | if (!canonicalProto) { |
329 | 0 | return false; |
330 | 0 | } |
331 | 0 | JS::Rooted<JSObject*> proto(aCx); |
332 | 0 | if (aGivenProto) { |
333 | 0 | proto = aGivenProto; |
334 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
335 | 0 | // coming in, we changed compartments to that of "parent" so may need |
336 | 0 | // to wrap the proto here. |
337 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
338 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
339 | 0 | return false; |
340 | 0 | } |
341 | 0 | } |
342 | 0 | } else { |
343 | 0 | proto = canonicalProto; |
344 | 0 | } |
345 | 0 |
|
346 | 0 | BindingJSObjectCreator<mozilla::dom::Crypto> creator(aCx); |
347 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
348 | 0 | if (!aReflector) { |
349 | 0 | return false; |
350 | 0 | } |
351 | 0 | |
352 | 0 | aCache->SetWrapper(aReflector); |
353 | 0 | creator.InitializationSucceeded(); |
354 | 0 |
|
355 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
356 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
357 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
358 | 0 | // otherwise we won't be able to properly recreate it later, since |
359 | 0 | // we won't know what proto to use. Note that we don't check |
360 | 0 | // aGivenProto here, since it's entirely possible (and even |
361 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
362 | 0 | // same as canonicalProto. |
363 | 0 | if (proto != canonicalProto) { |
364 | 0 | PreserveWrapper(aObject); |
365 | 0 | } |
366 | 0 |
|
367 | 0 | return true; |
368 | 0 | } |
369 | | |
370 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
371 | | nullptr, |
372 | | nullptr, |
373 | | nullptr, |
374 | | { sNativeProperties.Upcast(), nullptr }, |
375 | | prototypes::id::Crypto, |
376 | | constructors::id::Crypto, |
377 | | nullptr, |
378 | | &DefaultXrayExpandoObjectClass |
379 | | } }; |
380 | | |
381 | | void |
382 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
383 | 0 | { |
384 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
385 | 0 | if (!parentProto) { |
386 | 0 | return; |
387 | 0 | } |
388 | 0 | |
389 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
390 | 0 | if (!constructorProto) { |
391 | 0 | return; |
392 | 0 | } |
393 | 0 | |
394 | 0 | static bool sIdsInited = false; |
395 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
396 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
397 | 0 | return; |
398 | 0 | } |
399 | 0 | sIdsInited = true; |
400 | 0 | } |
401 | 0 |
|
402 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::Crypto); |
403 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::Crypto); |
404 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
405 | 0 | &sPrototypeClass.mBase, protoCache, |
406 | 0 | nullptr, |
407 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
408 | 0 | interfaceCache, |
409 | 0 | sNativeProperties.Upcast(), |
410 | 0 | nullptr, |
411 | 0 | "Crypto", aDefineOnGlobal, |
412 | 0 | nullptr, |
413 | 0 | false); |
414 | 0 | } |
415 | | |
416 | | JSObject* |
417 | | GetConstructorObject(JSContext* aCx) |
418 | 0 | { |
419 | 0 | return GetConstructorObjectHandle(aCx); |
420 | 0 | } |
421 | | |
422 | | } // namespace Crypto_Binding |
423 | | |
424 | | |
425 | | |
426 | | } // namespace dom |
427 | | } // namespace mozilla |