/work/obj-fuzz/dom/bindings/KeyAlgorithmBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM KeyAlgorithm.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "KeyAlgorithmBinding.h" |
5 | | #include "jsfriendapi.h" |
6 | | #include "mozilla/OwningNonNull.h" |
7 | | #include "mozilla/dom/BindingUtils.h" |
8 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
9 | | #include "mozilla/dom/PrimitiveConversions.h" |
10 | | #include "mozilla/dom/ScriptSettings.h" |
11 | | #include "mozilla/dom/SimpleGlobalObject.h" |
12 | | |
13 | | namespace mozilla { |
14 | | namespace dom { |
15 | | |
16 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
17 | | using namespace mozilla::dom::binding_detail; |
18 | | |
19 | | |
20 | | |
21 | | KeyAlgorithm::KeyAlgorithm() |
22 | 0 | { |
23 | 0 | // Safe to pass a null context if we pass a null value |
24 | 0 | Init(nullptr, JS::NullHandleValue); |
25 | 0 | } |
26 | | |
27 | | |
28 | | |
29 | | bool |
30 | | KeyAlgorithm::InitIds(JSContext* cx, KeyAlgorithmAtoms* atomsCache) |
31 | 0 | { |
32 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
33 | 0 |
|
34 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
35 | 0 | // uninitialized. |
36 | 0 | if (!atomsCache->name_id.init(cx, "name")) { |
37 | 0 | return false; |
38 | 0 | } |
39 | 0 | return true; |
40 | 0 | } |
41 | | |
42 | | bool |
43 | | KeyAlgorithm::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
44 | 0 | { |
45 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
46 | 0 | // Since in that case we will not have to do any property gets |
47 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
48 | 0 | // checkers by static analysis tools |
49 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
50 | 0 | KeyAlgorithmAtoms* atomsCache = nullptr; |
51 | 0 | if (cx) { |
52 | 0 | atomsCache = GetAtomCache<KeyAlgorithmAtoms>(cx); |
53 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
54 | 0 | return false; |
55 | 0 | } |
56 | 0 | } |
57 | 0 | |
58 | 0 | if (!IsConvertibleToDictionary(val)) { |
59 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
60 | 0 | } |
61 | 0 | |
62 | 0 | bool isNull = val.isNullOrUndefined(); |
63 | 0 | // We only need these if !isNull, in which case we have |cx|. |
64 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
65 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
66 | 0 | if (!isNull) { |
67 | 0 | MOZ_ASSERT(cx); |
68 | 0 | object.emplace(cx, &val.toObject()); |
69 | 0 | temp.emplace(cx); |
70 | 0 | } |
71 | 0 | if (!isNull) { |
72 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->name_id, temp.ptr())) { |
73 | 0 | return false; |
74 | 0 | } |
75 | 0 | } |
76 | 0 | if (!isNull && !temp->isUndefined()) { |
77 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mName)) { |
78 | 0 | return false; |
79 | 0 | } |
80 | 0 | mIsAnyMemberPresent = true; |
81 | 0 | } else if (cx) { |
82 | 0 | // Don't error out if we have no cx. In that |
83 | 0 | // situation the caller is default-constructing us and we'll |
84 | 0 | // just assume they know what they're doing. |
85 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
86 | 0 | "'name' member of KeyAlgorithm"); |
87 | 0 | } |
88 | 0 | return true; |
89 | 0 | } |
90 | | |
91 | | bool |
92 | | KeyAlgorithm::Init(const nsAString& aJSON) |
93 | 0 | { |
94 | 0 | AutoJSAPI jsapi; |
95 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
96 | 0 | if (!cleanGlobal) { |
97 | 0 | return false; |
98 | 0 | } |
99 | 0 | if (!jsapi.Init(cleanGlobal)) { |
100 | 0 | return false; |
101 | 0 | } |
102 | 0 | JSContext* cx = jsapi.cx(); |
103 | 0 | JS::Rooted<JS::Value> json(cx); |
104 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
105 | 0 | NS_ENSURE_TRUE(ok, false); |
106 | 0 | return Init(cx, json); |
107 | 0 | } |
108 | | |
109 | | bool |
110 | | KeyAlgorithm::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
111 | 0 | { |
112 | 0 | KeyAlgorithmAtoms* atomsCache = GetAtomCache<KeyAlgorithmAtoms>(cx); |
113 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
114 | 0 | return false; |
115 | 0 | } |
116 | 0 | |
117 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
118 | 0 | if (!obj) { |
119 | 0 | return false; |
120 | 0 | } |
121 | 0 | rval.set(JS::ObjectValue(*obj)); |
122 | 0 |
|
123 | 0 | do { |
124 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
125 | 0 | JS::Rooted<JS::Value> temp(cx); |
126 | 0 | nsString const & currentValue = mName; |
127 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
128 | 0 | return false; |
129 | 0 | } |
130 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->name_id, temp, JSPROP_ENUMERATE)) { |
131 | 0 | return false; |
132 | 0 | } |
133 | 0 | break; |
134 | 0 | } while(false); |
135 | 0 |
|
136 | 0 | return true; |
137 | 0 | } |
138 | | |
139 | | bool |
140 | | KeyAlgorithm::ToJSON(nsAString& aJSON) const |
141 | 0 | { |
142 | 0 | AutoJSAPI jsapi; |
143 | 0 | jsapi.Init(); |
144 | 0 | JSContext *cx = jsapi.cx(); |
145 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
146 | 0 | // because we'll only be creating objects, in ways that have no |
147 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
148 | 0 | // which likewise guarantees no side-effects for the sorts of |
149 | 0 | // things we will pass it. |
150 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
151 | 0 | JS::Rooted<JS::Value> val(cx); |
152 | 0 | if (!ToObjectInternal(cx, &val)) { |
153 | 0 | return false; |
154 | 0 | } |
155 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
156 | 0 | return StringifyToJSON(cx, obj, aJSON); |
157 | 0 | } |
158 | | |
159 | | void |
160 | | KeyAlgorithm::TraceDictionary(JSTracer* trc) |
161 | 0 | { |
162 | 0 | } |
163 | | |
164 | | KeyAlgorithm& |
165 | | KeyAlgorithm::operator=(const KeyAlgorithm& aOther) |
166 | 0 | { |
167 | 0 | DictionaryBase::operator=(aOther); |
168 | 0 | mName = aOther.mName; |
169 | 0 | return *this; |
170 | 0 | } |
171 | | |
172 | | namespace binding_detail { |
173 | | } // namespace binding_detail |
174 | | |
175 | | |
176 | | |
177 | | AesKeyAlgorithm::AesKeyAlgorithm() |
178 | | : KeyAlgorithm(FastDictionaryInitializer()) |
179 | 0 | { |
180 | 0 | // Safe to pass a null context if we pass a null value |
181 | 0 | Init(nullptr, JS::NullHandleValue); |
182 | 0 | } |
183 | | |
184 | | |
185 | | |
186 | | bool |
187 | | AesKeyAlgorithm::InitIds(JSContext* cx, AesKeyAlgorithmAtoms* atomsCache) |
188 | 0 | { |
189 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
190 | 0 |
|
191 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
192 | 0 | // uninitialized. |
193 | 0 | if (!atomsCache->length_id.init(cx, "length")) { |
194 | 0 | return false; |
195 | 0 | } |
196 | 0 | return true; |
197 | 0 | } |
198 | | |
199 | | bool |
200 | | AesKeyAlgorithm::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
201 | 0 | { |
202 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
203 | 0 | // Since in that case we will not have to do any property gets |
204 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
205 | 0 | // checkers by static analysis tools |
206 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
207 | 0 | AesKeyAlgorithmAtoms* atomsCache = nullptr; |
208 | 0 | if (cx) { |
209 | 0 | atomsCache = GetAtomCache<AesKeyAlgorithmAtoms>(cx); |
210 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
211 | 0 | return false; |
212 | 0 | } |
213 | 0 | } |
214 | 0 | |
215 | 0 | // Per spec, we init the parent's members first |
216 | 0 | if (!KeyAlgorithm::Init(cx, val)) { |
217 | 0 | return false; |
218 | 0 | } |
219 | 0 | |
220 | 0 | bool isNull = val.isNullOrUndefined(); |
221 | 0 | // We only need these if !isNull, in which case we have |cx|. |
222 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
223 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
224 | 0 | if (!isNull) { |
225 | 0 | MOZ_ASSERT(cx); |
226 | 0 | object.emplace(cx, &val.toObject()); |
227 | 0 | temp.emplace(cx); |
228 | 0 | } |
229 | 0 | if (!isNull) { |
230 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->length_id, temp.ptr())) { |
231 | 0 | return false; |
232 | 0 | } |
233 | 0 | } |
234 | 0 | if (!isNull && !temp->isUndefined()) { |
235 | 0 | if (!ValueToPrimitive<uint16_t, eDefault>(cx, temp.ref(), &mLength)) { |
236 | 0 | return false; |
237 | 0 | } |
238 | 0 | mIsAnyMemberPresent = true; |
239 | 0 | } else if (cx) { |
240 | 0 | // Don't error out if we have no cx. In that |
241 | 0 | // situation the caller is default-constructing us and we'll |
242 | 0 | // just assume they know what they're doing. |
243 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
244 | 0 | "'length' member of AesKeyAlgorithm"); |
245 | 0 | } |
246 | 0 | return true; |
247 | 0 | } |
248 | | |
249 | | bool |
250 | | AesKeyAlgorithm::Init(const nsAString& aJSON) |
251 | 0 | { |
252 | 0 | AutoJSAPI jsapi; |
253 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
254 | 0 | if (!cleanGlobal) { |
255 | 0 | return false; |
256 | 0 | } |
257 | 0 | if (!jsapi.Init(cleanGlobal)) { |
258 | 0 | return false; |
259 | 0 | } |
260 | 0 | JSContext* cx = jsapi.cx(); |
261 | 0 | JS::Rooted<JS::Value> json(cx); |
262 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
263 | 0 | NS_ENSURE_TRUE(ok, false); |
264 | 0 | return Init(cx, json); |
265 | 0 | } |
266 | | |
267 | | bool |
268 | | AesKeyAlgorithm::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
269 | 0 | { |
270 | 0 | AesKeyAlgorithmAtoms* atomsCache = GetAtomCache<AesKeyAlgorithmAtoms>(cx); |
271 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
272 | 0 | return false; |
273 | 0 | } |
274 | 0 | |
275 | 0 | // Per spec, we define the parent's members first |
276 | 0 | if (!KeyAlgorithm::ToObjectInternal(cx, rval)) { |
277 | 0 | return false; |
278 | 0 | } |
279 | 0 | JS::Rooted<JSObject*> obj(cx, &rval.toObject()); |
280 | 0 |
|
281 | 0 | do { |
282 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
283 | 0 | JS::Rooted<JS::Value> temp(cx); |
284 | 0 | uint16_t const & currentValue = mLength; |
285 | 0 | temp.setInt32(int32_t(currentValue)); |
286 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->length_id, temp, JSPROP_ENUMERATE)) { |
287 | 0 | return false; |
288 | 0 | } |
289 | 0 | break; |
290 | 0 | } while(false); |
291 | 0 |
|
292 | 0 | return true; |
293 | 0 | } |
294 | | |
295 | | bool |
296 | | AesKeyAlgorithm::ToJSON(nsAString& aJSON) const |
297 | 0 | { |
298 | 0 | AutoJSAPI jsapi; |
299 | 0 | jsapi.Init(); |
300 | 0 | JSContext *cx = jsapi.cx(); |
301 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
302 | 0 | // because we'll only be creating objects, in ways that have no |
303 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
304 | 0 | // which likewise guarantees no side-effects for the sorts of |
305 | 0 | // things we will pass it. |
306 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
307 | 0 | JS::Rooted<JS::Value> val(cx); |
308 | 0 | if (!ToObjectInternal(cx, &val)) { |
309 | 0 | return false; |
310 | 0 | } |
311 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
312 | 0 | return StringifyToJSON(cx, obj, aJSON); |
313 | 0 | } |
314 | | |
315 | | void |
316 | | AesKeyAlgorithm::TraceDictionary(JSTracer* trc) |
317 | 0 | { |
318 | 0 | KeyAlgorithm::TraceDictionary(trc); |
319 | 0 | } |
320 | | |
321 | | AesKeyAlgorithm& |
322 | | AesKeyAlgorithm::operator=(const AesKeyAlgorithm& aOther) |
323 | 0 | { |
324 | 0 | KeyAlgorithm::operator=(aOther); |
325 | 0 | mLength = aOther.mLength; |
326 | 0 | return *this; |
327 | 0 | } |
328 | | |
329 | | namespace binding_detail { |
330 | | } // namespace binding_detail |
331 | | |
332 | | |
333 | | |
334 | | DhKeyAlgorithm::DhKeyAlgorithm() |
335 | | : KeyAlgorithm(FastDictionaryInitializer()) |
336 | 0 | { |
337 | 0 | // Safe to pass a null context if we pass a null value |
338 | 0 | Init(nullptr, JS::NullHandleValue); |
339 | 0 | } |
340 | | |
341 | | |
342 | | bool |
343 | | DhKeyAlgorithm::InitIds(JSContext* cx, DhKeyAlgorithmAtoms* atomsCache) |
344 | 0 | { |
345 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
346 | 0 |
|
347 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
348 | 0 | // uninitialized. |
349 | 0 | if (!atomsCache->prime_id.init(cx, "prime") || |
350 | 0 | !atomsCache->generator_id.init(cx, "generator")) { |
351 | 0 | return false; |
352 | 0 | } |
353 | 0 | return true; |
354 | 0 | } |
355 | | |
356 | | bool |
357 | | DhKeyAlgorithm::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
358 | 0 | { |
359 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
360 | 0 | // Since in that case we will not have to do any property gets |
361 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
362 | 0 | // checkers by static analysis tools |
363 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
364 | 0 | DhKeyAlgorithmAtoms* atomsCache = nullptr; |
365 | 0 | if (cx) { |
366 | 0 | atomsCache = GetAtomCache<DhKeyAlgorithmAtoms>(cx); |
367 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
368 | 0 | return false; |
369 | 0 | } |
370 | 0 | } |
371 | 0 | |
372 | 0 | // Per spec, we init the parent's members first |
373 | 0 | if (!KeyAlgorithm::Init(cx, val)) { |
374 | 0 | return false; |
375 | 0 | } |
376 | 0 | |
377 | 0 | bool isNull = val.isNullOrUndefined(); |
378 | 0 | // We only need these if !isNull, in which case we have |cx|. |
379 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
380 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
381 | 0 | if (!isNull) { |
382 | 0 | MOZ_ASSERT(cx); |
383 | 0 | object.emplace(cx, &val.toObject()); |
384 | 0 | temp.emplace(cx); |
385 | 0 | } |
386 | 0 | if (!isNull) { |
387 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->generator_id, temp.ptr())) { |
388 | 0 | return false; |
389 | 0 | } |
390 | 0 | } |
391 | 0 | if (!isNull && !temp->isUndefined()) { |
392 | 0 | if (temp.ref().isObject()) { |
393 | 0 | if (!mGenerator.Init(&temp.ref().toObject())) { |
394 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'generator' member of DhKeyAlgorithm", "Uint8Array"); |
395 | 0 | return false; |
396 | 0 | } |
397 | 0 | } else { |
398 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'generator' member of DhKeyAlgorithm"); |
399 | 0 | return false; |
400 | 0 | } |
401 | 0 | mIsAnyMemberPresent = true; |
402 | 0 | } else if (cx) { |
403 | 0 | // Don't error out if we have no cx. In that |
404 | 0 | // situation the caller is default-constructing us and we'll |
405 | 0 | // just assume they know what they're doing. |
406 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
407 | 0 | "'generator' member of DhKeyAlgorithm"); |
408 | 0 | } |
409 | 0 | |
410 | 0 | if (!isNull) { |
411 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->prime_id, temp.ptr())) { |
412 | 0 | return false; |
413 | 0 | } |
414 | 0 | } |
415 | 0 | if (!isNull && !temp->isUndefined()) { |
416 | 0 | if (temp.ref().isObject()) { |
417 | 0 | if (!mPrime.Init(&temp.ref().toObject())) { |
418 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'prime' member of DhKeyAlgorithm", "Uint8Array"); |
419 | 0 | return false; |
420 | 0 | } |
421 | 0 | } else { |
422 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'prime' member of DhKeyAlgorithm"); |
423 | 0 | return false; |
424 | 0 | } |
425 | 0 | mIsAnyMemberPresent = true; |
426 | 0 | } else if (cx) { |
427 | 0 | // Don't error out if we have no cx. In that |
428 | 0 | // situation the caller is default-constructing us and we'll |
429 | 0 | // just assume they know what they're doing. |
430 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
431 | 0 | "'prime' member of DhKeyAlgorithm"); |
432 | 0 | } |
433 | 0 | return true; |
434 | 0 | } |
435 | | |
436 | | bool |
437 | | DhKeyAlgorithm::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
438 | 0 | { |
439 | 0 | DhKeyAlgorithmAtoms* atomsCache = GetAtomCache<DhKeyAlgorithmAtoms>(cx); |
440 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
441 | 0 | return false; |
442 | 0 | } |
443 | 0 | |
444 | 0 | // Per spec, we define the parent's members first |
445 | 0 | if (!KeyAlgorithm::ToObjectInternal(cx, rval)) { |
446 | 0 | return false; |
447 | 0 | } |
448 | 0 | JS::Rooted<JSObject*> obj(cx, &rval.toObject()); |
449 | 0 |
|
450 | 0 | do { |
451 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
452 | 0 | JS::Rooted<JS::Value> temp(cx); |
453 | 0 | Uint8Array const & currentValue = mGenerator; |
454 | 0 | temp.setObject(*currentValue.Obj()); |
455 | 0 | if (!MaybeWrapNonDOMObjectValue(cx, &temp)) { |
456 | 0 | return false; |
457 | 0 | } |
458 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->generator_id, temp, JSPROP_ENUMERATE)) { |
459 | 0 | return false; |
460 | 0 | } |
461 | 0 | break; |
462 | 0 | } while(false); |
463 | 0 |
|
464 | 0 | do { |
465 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
466 | 0 | JS::Rooted<JS::Value> temp(cx); |
467 | 0 | Uint8Array const & currentValue = mPrime; |
468 | 0 | temp.setObject(*currentValue.Obj()); |
469 | 0 | if (!MaybeWrapNonDOMObjectValue(cx, &temp)) { |
470 | 0 | return false; |
471 | 0 | } |
472 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->prime_id, temp, JSPROP_ENUMERATE)) { |
473 | 0 | return false; |
474 | 0 | } |
475 | 0 | break; |
476 | 0 | } while(false); |
477 | 0 |
|
478 | 0 | return true; |
479 | 0 | } |
480 | | |
481 | | void |
482 | | DhKeyAlgorithm::TraceDictionary(JSTracer* trc) |
483 | 0 | { |
484 | 0 | KeyAlgorithm::TraceDictionary(trc); |
485 | 0 | mGenerator.TraceSelf(trc); |
486 | 0 |
|
487 | 0 | mPrime.TraceSelf(trc); |
488 | 0 | } |
489 | | |
490 | | namespace binding_detail { |
491 | | } // namespace binding_detail |
492 | | |
493 | | |
494 | | |
495 | | EcKeyAlgorithm::EcKeyAlgorithm() |
496 | | : KeyAlgorithm(FastDictionaryInitializer()) |
497 | 0 | { |
498 | 0 | // Safe to pass a null context if we pass a null value |
499 | 0 | Init(nullptr, JS::NullHandleValue); |
500 | 0 | } |
501 | | |
502 | | |
503 | | |
504 | | bool |
505 | | EcKeyAlgorithm::InitIds(JSContext* cx, EcKeyAlgorithmAtoms* atomsCache) |
506 | 0 | { |
507 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
508 | 0 |
|
509 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
510 | 0 | // uninitialized. |
511 | 0 | if (!atomsCache->namedCurve_id.init(cx, "namedCurve")) { |
512 | 0 | return false; |
513 | 0 | } |
514 | 0 | return true; |
515 | 0 | } |
516 | | |
517 | | bool |
518 | | EcKeyAlgorithm::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
519 | 0 | { |
520 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
521 | 0 | // Since in that case we will not have to do any property gets |
522 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
523 | 0 | // checkers by static analysis tools |
524 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
525 | 0 | EcKeyAlgorithmAtoms* atomsCache = nullptr; |
526 | 0 | if (cx) { |
527 | 0 | atomsCache = GetAtomCache<EcKeyAlgorithmAtoms>(cx); |
528 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
529 | 0 | return false; |
530 | 0 | } |
531 | 0 | } |
532 | 0 | |
533 | 0 | // Per spec, we init the parent's members first |
534 | 0 | if (!KeyAlgorithm::Init(cx, val)) { |
535 | 0 | return false; |
536 | 0 | } |
537 | 0 | |
538 | 0 | bool isNull = val.isNullOrUndefined(); |
539 | 0 | // We only need these if !isNull, in which case we have |cx|. |
540 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
541 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
542 | 0 | if (!isNull) { |
543 | 0 | MOZ_ASSERT(cx); |
544 | 0 | object.emplace(cx, &val.toObject()); |
545 | 0 | temp.emplace(cx); |
546 | 0 | } |
547 | 0 | if (!isNull) { |
548 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->namedCurve_id, temp.ptr())) { |
549 | 0 | return false; |
550 | 0 | } |
551 | 0 | } |
552 | 0 | if (!isNull && !temp->isUndefined()) { |
553 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mNamedCurve)) { |
554 | 0 | return false; |
555 | 0 | } |
556 | 0 | mIsAnyMemberPresent = true; |
557 | 0 | } else if (cx) { |
558 | 0 | // Don't error out if we have no cx. In that |
559 | 0 | // situation the caller is default-constructing us and we'll |
560 | 0 | // just assume they know what they're doing. |
561 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
562 | 0 | "'namedCurve' member of EcKeyAlgorithm"); |
563 | 0 | } |
564 | 0 | return true; |
565 | 0 | } |
566 | | |
567 | | bool |
568 | | EcKeyAlgorithm::Init(const nsAString& aJSON) |
569 | 0 | { |
570 | 0 | AutoJSAPI jsapi; |
571 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
572 | 0 | if (!cleanGlobal) { |
573 | 0 | return false; |
574 | 0 | } |
575 | 0 | if (!jsapi.Init(cleanGlobal)) { |
576 | 0 | return false; |
577 | 0 | } |
578 | 0 | JSContext* cx = jsapi.cx(); |
579 | 0 | JS::Rooted<JS::Value> json(cx); |
580 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
581 | 0 | NS_ENSURE_TRUE(ok, false); |
582 | 0 | return Init(cx, json); |
583 | 0 | } |
584 | | |
585 | | bool |
586 | | EcKeyAlgorithm::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
587 | 0 | { |
588 | 0 | EcKeyAlgorithmAtoms* atomsCache = GetAtomCache<EcKeyAlgorithmAtoms>(cx); |
589 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
590 | 0 | return false; |
591 | 0 | } |
592 | 0 | |
593 | 0 | // Per spec, we define the parent's members first |
594 | 0 | if (!KeyAlgorithm::ToObjectInternal(cx, rval)) { |
595 | 0 | return false; |
596 | 0 | } |
597 | 0 | JS::Rooted<JSObject*> obj(cx, &rval.toObject()); |
598 | 0 |
|
599 | 0 | do { |
600 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
601 | 0 | JS::Rooted<JS::Value> temp(cx); |
602 | 0 | nsString const & currentValue = mNamedCurve; |
603 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
604 | 0 | return false; |
605 | 0 | } |
606 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->namedCurve_id, temp, JSPROP_ENUMERATE)) { |
607 | 0 | return false; |
608 | 0 | } |
609 | 0 | break; |
610 | 0 | } while(false); |
611 | 0 |
|
612 | 0 | return true; |
613 | 0 | } |
614 | | |
615 | | bool |
616 | | EcKeyAlgorithm::ToJSON(nsAString& aJSON) const |
617 | 0 | { |
618 | 0 | AutoJSAPI jsapi; |
619 | 0 | jsapi.Init(); |
620 | 0 | JSContext *cx = jsapi.cx(); |
621 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
622 | 0 | // because we'll only be creating objects, in ways that have no |
623 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
624 | 0 | // which likewise guarantees no side-effects for the sorts of |
625 | 0 | // things we will pass it. |
626 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
627 | 0 | JS::Rooted<JS::Value> val(cx); |
628 | 0 | if (!ToObjectInternal(cx, &val)) { |
629 | 0 | return false; |
630 | 0 | } |
631 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
632 | 0 | return StringifyToJSON(cx, obj, aJSON); |
633 | 0 | } |
634 | | |
635 | | void |
636 | | EcKeyAlgorithm::TraceDictionary(JSTracer* trc) |
637 | 0 | { |
638 | 0 | KeyAlgorithm::TraceDictionary(trc); |
639 | 0 | } |
640 | | |
641 | | EcKeyAlgorithm& |
642 | | EcKeyAlgorithm::operator=(const EcKeyAlgorithm& aOther) |
643 | 0 | { |
644 | 0 | KeyAlgorithm::operator=(aOther); |
645 | 0 | mNamedCurve = aOther.mNamedCurve; |
646 | 0 | return *this; |
647 | 0 | } |
648 | | |
649 | | namespace binding_detail { |
650 | | } // namespace binding_detail |
651 | | |
652 | | |
653 | | |
654 | | HmacKeyAlgorithm::HmacKeyAlgorithm() |
655 | | : KeyAlgorithm(FastDictionaryInitializer()), |
656 | | mHash(FastDictionaryInitializer()) |
657 | 0 | { |
658 | 0 | // Safe to pass a null context if we pass a null value |
659 | 0 | Init(nullptr, JS::NullHandleValue); |
660 | 0 | } |
661 | | |
662 | | |
663 | | |
664 | | bool |
665 | | HmacKeyAlgorithm::InitIds(JSContext* cx, HmacKeyAlgorithmAtoms* atomsCache) |
666 | 0 | { |
667 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
668 | 0 |
|
669 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
670 | 0 | // uninitialized. |
671 | 0 | if (!atomsCache->length_id.init(cx, "length") || |
672 | 0 | !atomsCache->hash_id.init(cx, "hash")) { |
673 | 0 | return false; |
674 | 0 | } |
675 | 0 | return true; |
676 | 0 | } |
677 | | |
678 | | bool |
679 | | HmacKeyAlgorithm::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
680 | 0 | { |
681 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
682 | 0 | // Since in that case we will not have to do any property gets |
683 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
684 | 0 | // checkers by static analysis tools |
685 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
686 | 0 | HmacKeyAlgorithmAtoms* atomsCache = nullptr; |
687 | 0 | if (cx) { |
688 | 0 | atomsCache = GetAtomCache<HmacKeyAlgorithmAtoms>(cx); |
689 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
690 | 0 | return false; |
691 | 0 | } |
692 | 0 | } |
693 | 0 | |
694 | 0 | // Per spec, we init the parent's members first |
695 | 0 | if (!KeyAlgorithm::Init(cx, val)) { |
696 | 0 | return false; |
697 | 0 | } |
698 | 0 | |
699 | 0 | bool isNull = val.isNullOrUndefined(); |
700 | 0 | // We only need these if !isNull, in which case we have |cx|. |
701 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
702 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
703 | 0 | if (!isNull) { |
704 | 0 | MOZ_ASSERT(cx); |
705 | 0 | object.emplace(cx, &val.toObject()); |
706 | 0 | temp.emplace(cx); |
707 | 0 | } |
708 | 0 | if (!isNull) { |
709 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->hash_id, temp.ptr())) { |
710 | 0 | return false; |
711 | 0 | } |
712 | 0 | } |
713 | 0 | if (!isNull && !temp->isUndefined()) { |
714 | 0 | if (!mHash.Init(cx, temp.ref(), "'hash' member of HmacKeyAlgorithm", passedToJSImpl)) { |
715 | 0 | return false; |
716 | 0 | } |
717 | 0 | mIsAnyMemberPresent = true; |
718 | 0 | } else if (cx) { |
719 | 0 | // Don't error out if we have no cx. In that |
720 | 0 | // situation the caller is default-constructing us and we'll |
721 | 0 | // just assume they know what they're doing. |
722 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
723 | 0 | "'hash' member of HmacKeyAlgorithm"); |
724 | 0 | } |
725 | 0 | |
726 | 0 | if (!isNull) { |
727 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->length_id, temp.ptr())) { |
728 | 0 | return false; |
729 | 0 | } |
730 | 0 | } |
731 | 0 | if (!isNull && !temp->isUndefined()) { |
732 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &mLength)) { |
733 | 0 | return false; |
734 | 0 | } |
735 | 0 | mIsAnyMemberPresent = true; |
736 | 0 | } else if (cx) { |
737 | 0 | // Don't error out if we have no cx. In that |
738 | 0 | // situation the caller is default-constructing us and we'll |
739 | 0 | // just assume they know what they're doing. |
740 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
741 | 0 | "'length' member of HmacKeyAlgorithm"); |
742 | 0 | } |
743 | 0 | return true; |
744 | 0 | } |
745 | | |
746 | | bool |
747 | | HmacKeyAlgorithm::Init(const nsAString& aJSON) |
748 | 0 | { |
749 | 0 | AutoJSAPI jsapi; |
750 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
751 | 0 | if (!cleanGlobal) { |
752 | 0 | return false; |
753 | 0 | } |
754 | 0 | if (!jsapi.Init(cleanGlobal)) { |
755 | 0 | return false; |
756 | 0 | } |
757 | 0 | JSContext* cx = jsapi.cx(); |
758 | 0 | JS::Rooted<JS::Value> json(cx); |
759 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
760 | 0 | NS_ENSURE_TRUE(ok, false); |
761 | 0 | return Init(cx, json); |
762 | 0 | } |
763 | | |
764 | | bool |
765 | | HmacKeyAlgorithm::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
766 | 0 | { |
767 | 0 | HmacKeyAlgorithmAtoms* atomsCache = GetAtomCache<HmacKeyAlgorithmAtoms>(cx); |
768 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
769 | 0 | return false; |
770 | 0 | } |
771 | 0 | |
772 | 0 | // Per spec, we define the parent's members first |
773 | 0 | if (!KeyAlgorithm::ToObjectInternal(cx, rval)) { |
774 | 0 | return false; |
775 | 0 | } |
776 | 0 | JS::Rooted<JSObject*> obj(cx, &rval.toObject()); |
777 | 0 |
|
778 | 0 | do { |
779 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
780 | 0 | JS::Rooted<JS::Value> temp(cx); |
781 | 0 | KeyAlgorithm const & currentValue = mHash; |
782 | 0 | if (!currentValue.ToObjectInternal(cx, &temp)) { |
783 | 0 | return false; |
784 | 0 | } |
785 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->hash_id, temp, JSPROP_ENUMERATE)) { |
786 | 0 | return false; |
787 | 0 | } |
788 | 0 | break; |
789 | 0 | } while(false); |
790 | 0 |
|
791 | 0 | do { |
792 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
793 | 0 | JS::Rooted<JS::Value> temp(cx); |
794 | 0 | uint32_t const & currentValue = mLength; |
795 | 0 | temp.setNumber(currentValue); |
796 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->length_id, temp, JSPROP_ENUMERATE)) { |
797 | 0 | return false; |
798 | 0 | } |
799 | 0 | break; |
800 | 0 | } while(false); |
801 | 0 |
|
802 | 0 | return true; |
803 | 0 | } |
804 | | |
805 | | bool |
806 | | HmacKeyAlgorithm::ToJSON(nsAString& aJSON) const |
807 | 0 | { |
808 | 0 | AutoJSAPI jsapi; |
809 | 0 | jsapi.Init(); |
810 | 0 | JSContext *cx = jsapi.cx(); |
811 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
812 | 0 | // because we'll only be creating objects, in ways that have no |
813 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
814 | 0 | // which likewise guarantees no side-effects for the sorts of |
815 | 0 | // things we will pass it. |
816 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
817 | 0 | JS::Rooted<JS::Value> val(cx); |
818 | 0 | if (!ToObjectInternal(cx, &val)) { |
819 | 0 | return false; |
820 | 0 | } |
821 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
822 | 0 | return StringifyToJSON(cx, obj, aJSON); |
823 | 0 | } |
824 | | |
825 | | void |
826 | | HmacKeyAlgorithm::TraceDictionary(JSTracer* trc) |
827 | 0 | { |
828 | 0 | KeyAlgorithm::TraceDictionary(trc); |
829 | 0 | } |
830 | | |
831 | | HmacKeyAlgorithm& |
832 | | HmacKeyAlgorithm::operator=(const HmacKeyAlgorithm& aOther) |
833 | 0 | { |
834 | 0 | KeyAlgorithm::operator=(aOther); |
835 | 0 | mHash = aOther.mHash; |
836 | 0 | mLength = aOther.mLength; |
837 | 0 | return *this; |
838 | 0 | } |
839 | | |
840 | | namespace binding_detail { |
841 | | } // namespace binding_detail |
842 | | |
843 | | |
844 | | |
845 | | RsaHashedKeyAlgorithm::RsaHashedKeyAlgorithm() |
846 | | : KeyAlgorithm(FastDictionaryInitializer()), |
847 | | mHash(FastDictionaryInitializer()) |
848 | 0 | { |
849 | 0 | // Safe to pass a null context if we pass a null value |
850 | 0 | Init(nullptr, JS::NullHandleValue); |
851 | 0 | } |
852 | | |
853 | | |
854 | | bool |
855 | | RsaHashedKeyAlgorithm::InitIds(JSContext* cx, RsaHashedKeyAlgorithmAtoms* atomsCache) |
856 | 0 | { |
857 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
858 | 0 |
|
859 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
860 | 0 | // uninitialized. |
861 | 0 | if (!atomsCache->publicExponent_id.init(cx, "publicExponent") || |
862 | 0 | !atomsCache->modulusLength_id.init(cx, "modulusLength") || |
863 | 0 | !atomsCache->hash_id.init(cx, "hash")) { |
864 | 0 | return false; |
865 | 0 | } |
866 | 0 | return true; |
867 | 0 | } |
868 | | |
869 | | bool |
870 | | RsaHashedKeyAlgorithm::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
871 | 0 | { |
872 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
873 | 0 | // Since in that case we will not have to do any property gets |
874 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
875 | 0 | // checkers by static analysis tools |
876 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
877 | 0 | RsaHashedKeyAlgorithmAtoms* atomsCache = nullptr; |
878 | 0 | if (cx) { |
879 | 0 | atomsCache = GetAtomCache<RsaHashedKeyAlgorithmAtoms>(cx); |
880 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
881 | 0 | return false; |
882 | 0 | } |
883 | 0 | } |
884 | 0 | |
885 | 0 | // Per spec, we init the parent's members first |
886 | 0 | if (!KeyAlgorithm::Init(cx, val)) { |
887 | 0 | return false; |
888 | 0 | } |
889 | 0 | |
890 | 0 | bool isNull = val.isNullOrUndefined(); |
891 | 0 | // We only need these if !isNull, in which case we have |cx|. |
892 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
893 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
894 | 0 | if (!isNull) { |
895 | 0 | MOZ_ASSERT(cx); |
896 | 0 | object.emplace(cx, &val.toObject()); |
897 | 0 | temp.emplace(cx); |
898 | 0 | } |
899 | 0 | if (!isNull) { |
900 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->hash_id, temp.ptr())) { |
901 | 0 | return false; |
902 | 0 | } |
903 | 0 | } |
904 | 0 | if (!isNull && !temp->isUndefined()) { |
905 | 0 | if (!mHash.Init(cx, temp.ref(), "'hash' member of RsaHashedKeyAlgorithm", passedToJSImpl)) { |
906 | 0 | return false; |
907 | 0 | } |
908 | 0 | mIsAnyMemberPresent = true; |
909 | 0 | } else if (cx) { |
910 | 0 | // Don't error out if we have no cx. In that |
911 | 0 | // situation the caller is default-constructing us and we'll |
912 | 0 | // just assume they know what they're doing. |
913 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
914 | 0 | "'hash' member of RsaHashedKeyAlgorithm"); |
915 | 0 | } |
916 | 0 | |
917 | 0 | if (!isNull) { |
918 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->modulusLength_id, temp.ptr())) { |
919 | 0 | return false; |
920 | 0 | } |
921 | 0 | } |
922 | 0 | if (!isNull && !temp->isUndefined()) { |
923 | 0 | if (!ValueToPrimitive<uint16_t, eDefault>(cx, temp.ref(), &mModulusLength)) { |
924 | 0 | return false; |
925 | 0 | } |
926 | 0 | mIsAnyMemberPresent = true; |
927 | 0 | } else if (cx) { |
928 | 0 | // Don't error out if we have no cx. In that |
929 | 0 | // situation the caller is default-constructing us and we'll |
930 | 0 | // just assume they know what they're doing. |
931 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
932 | 0 | "'modulusLength' member of RsaHashedKeyAlgorithm"); |
933 | 0 | } |
934 | 0 | |
935 | 0 | if (!isNull) { |
936 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->publicExponent_id, temp.ptr())) { |
937 | 0 | return false; |
938 | 0 | } |
939 | 0 | } |
940 | 0 | if (!isNull && !temp->isUndefined()) { |
941 | 0 | if (temp.ref().isObject()) { |
942 | 0 | if (!mPublicExponent.Init(&temp.ref().toObject())) { |
943 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'publicExponent' member of RsaHashedKeyAlgorithm", "Uint8Array"); |
944 | 0 | return false; |
945 | 0 | } |
946 | 0 | } else { |
947 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'publicExponent' member of RsaHashedKeyAlgorithm"); |
948 | 0 | return false; |
949 | 0 | } |
950 | 0 | mIsAnyMemberPresent = true; |
951 | 0 | } else if (cx) { |
952 | 0 | // Don't error out if we have no cx. In that |
953 | 0 | // situation the caller is default-constructing us and we'll |
954 | 0 | // just assume they know what they're doing. |
955 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
956 | 0 | "'publicExponent' member of RsaHashedKeyAlgorithm"); |
957 | 0 | } |
958 | 0 | return true; |
959 | 0 | } |
960 | | |
961 | | bool |
962 | | RsaHashedKeyAlgorithm::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
963 | 0 | { |
964 | 0 | RsaHashedKeyAlgorithmAtoms* atomsCache = GetAtomCache<RsaHashedKeyAlgorithmAtoms>(cx); |
965 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
966 | 0 | return false; |
967 | 0 | } |
968 | 0 | |
969 | 0 | // Per spec, we define the parent's members first |
970 | 0 | if (!KeyAlgorithm::ToObjectInternal(cx, rval)) { |
971 | 0 | return false; |
972 | 0 | } |
973 | 0 | JS::Rooted<JSObject*> obj(cx, &rval.toObject()); |
974 | 0 |
|
975 | 0 | do { |
976 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
977 | 0 | JS::Rooted<JS::Value> temp(cx); |
978 | 0 | KeyAlgorithm const & currentValue = mHash; |
979 | 0 | if (!currentValue.ToObjectInternal(cx, &temp)) { |
980 | 0 | return false; |
981 | 0 | } |
982 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->hash_id, temp, JSPROP_ENUMERATE)) { |
983 | 0 | return false; |
984 | 0 | } |
985 | 0 | break; |
986 | 0 | } while(false); |
987 | 0 |
|
988 | 0 | do { |
989 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
990 | 0 | JS::Rooted<JS::Value> temp(cx); |
991 | 0 | uint16_t const & currentValue = mModulusLength; |
992 | 0 | temp.setInt32(int32_t(currentValue)); |
993 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->modulusLength_id, temp, JSPROP_ENUMERATE)) { |
994 | 0 | return false; |
995 | 0 | } |
996 | 0 | break; |
997 | 0 | } while(false); |
998 | 0 |
|
999 | 0 | do { |
1000 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
1001 | 0 | JS::Rooted<JS::Value> temp(cx); |
1002 | 0 | Uint8Array const & currentValue = mPublicExponent; |
1003 | 0 | temp.setObject(*currentValue.Obj()); |
1004 | 0 | if (!MaybeWrapNonDOMObjectValue(cx, &temp)) { |
1005 | 0 | return false; |
1006 | 0 | } |
1007 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->publicExponent_id, temp, JSPROP_ENUMERATE)) { |
1008 | 0 | return false; |
1009 | 0 | } |
1010 | 0 | break; |
1011 | 0 | } while(false); |
1012 | 0 |
|
1013 | 0 | return true; |
1014 | 0 | } |
1015 | | |
1016 | | void |
1017 | | RsaHashedKeyAlgorithm::TraceDictionary(JSTracer* trc) |
1018 | 0 | { |
1019 | 0 | KeyAlgorithm::TraceDictionary(trc); |
1020 | 0 | mPublicExponent.TraceSelf(trc); |
1021 | 0 | } |
1022 | | |
1023 | | namespace binding_detail { |
1024 | | } // namespace binding_detail |
1025 | | |
1026 | | |
1027 | | } // namespace dom |
1028 | | } // namespace mozilla |