Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM StructuredCloneHolder.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "StructuredCloneHolderBinding.h"
4 : #include "WrapperFactory.h"
5 : #include "mozilla/OwningNonNull.h"
6 : #include "mozilla/dom/BindingUtils.h"
7 : #include "mozilla/dom/DOMJSClass.h"
8 : #include "mozilla/dom/NonRefcountedDOMObject.h"
9 : #include "mozilla/dom/Nullable.h"
10 : #include "mozilla/dom/StructuredCloneBlob.h"
11 : #include "mozilla/dom/XrayExpandoClass.h"
12 : #include "nsContentUtils.h"
13 :
14 : namespace mozilla {
15 : namespace dom {
16 :
17 : namespace StructuredCloneHolderBinding {
18 :
19 : static bool
20 0 : deserialize(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::StructuredCloneBlob* self, const JSJitMethodCallArgs& args)
21 : {
22 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
23 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "StructuredCloneHolder.deserialize");
24 : }
25 0 : JS::Rooted<JSObject*> arg0(cx);
26 0 : if (args[0].isObject()) {
27 0 : arg0 = &args[0].toObject();
28 : } else {
29 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of StructuredCloneHolder.deserialize");
30 0 : return false;
31 : }
32 0 : binding_detail::FastErrorResult rv;
33 0 : JS::Rooted<JS::Value> result(cx);
34 0 : self->Deserialize(cx, arg0, &result, rv);
35 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
36 0 : return false;
37 : }
38 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
39 0 : JS::ExposeValueToActiveJS(result);
40 0 : args.rval().set(result);
41 0 : if (!MaybeWrapValue(cx, args.rval())) {
42 0 : return false;
43 : }
44 0 : return true;
45 : }
46 :
47 : static const JSJitInfo deserialize_methodinfo = {
48 : { (JSJitGetterOp)deserialize },
49 : { prototypes::id::StructuredCloneHolder },
50 : { PrototypeTraits<prototypes::id::StructuredCloneHolder>::Depth },
51 : JSJitInfo::Method,
52 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
53 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
54 : false, /* isInfallible. False in setters. */
55 : false, /* isMovable. Not relevant for setters. */
56 : false, /* isEliminatable. Not relevant for setters. */
57 : false, /* isAlwaysInSlot. Only relevant for getters. */
58 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
59 : false, /* isTypedMethod. Only relevant for methods. */
60 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
61 : };
62 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
63 : static_assert(0 < 1, "There is no slot for us");
64 :
65 : static void
66 0 : _finalize(js::FreeOp* fop, JSObject* obj)
67 : {
68 0 : mozilla::dom::StructuredCloneBlob* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::StructuredCloneBlob>(obj);
69 0 : if (self) {
70 0 : AddForDeferredFinalization<mozilla::dom::StructuredCloneBlob>(self);
71 : }
72 0 : }
73 :
74 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
75 : #if defined(__clang__)
76 : #pragma clang diagnostic push
77 : #pragma clang diagnostic ignored "-Wmissing-braces"
78 : #endif
79 : static const JSFunctionSpec sMethods_specs[] = {
80 : JS_FNSPEC("deserialize", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&deserialize_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
81 : JS_FS_END
82 : };
83 : #if defined(__clang__)
84 : #pragma clang diagnostic pop
85 : #endif
86 :
87 :
88 : // Can't be const because the pref-enabled boolean needs to be writable
89 : static Prefable<const JSFunctionSpec> sMethods[] = {
90 : { nullptr, &sMethods_specs[0] },
91 : { nullptr, nullptr }
92 : };
93 :
94 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
95 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
96 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
97 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
98 :
99 :
100 : static uint16_t sNativeProperties_sortedPropertyIndices[1];
101 : static PropertyInfo sNativeProperties_propertyInfos[1];
102 :
103 : static const NativePropertiesN<1> sNativeProperties = {
104 : false, 0,
105 : false, 0,
106 : true, 0 /* sMethods */,
107 : false, 0,
108 : false, 0,
109 : false, 0,
110 : false, 0,
111 : -1,
112 : 1,
113 : sNativeProperties_sortedPropertyIndices,
114 : {
115 : { sMethods, &sNativeProperties_propertyInfos[0] }
116 : }
117 : };
118 : static_assert(1 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
119 : "We have a property info count that is oversized");
120 :
121 : static bool
122 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
123 : {
124 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
125 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
126 0 : if (!args.isConstructing()) {
127 : // XXXbz wish I could get the name from the callee instead of
128 : // Adding more relocations
129 0 : return ThrowConstructorWithoutNew(cx, "StructuredCloneHolder");
130 : }
131 :
132 0 : GlobalObject global(cx, obj);
133 0 : if (global.Failed()) {
134 0 : return false;
135 : }
136 :
137 0 : JS::Rooted<JSObject*> desiredProto(cx);
138 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
139 0 : return false;
140 : }
141 :
142 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
143 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "StructuredCloneHolder");
144 : }
145 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
146 0 : JS::Rooted<JS::Value> arg0(cx);
147 0 : arg0 = args[0];
148 0 : JS::Rooted<JSObject*> arg1(cx);
149 0 : if (args.hasDefined(1)) {
150 0 : if (args[1].isObject()) {
151 0 : arg1 = &args[1].toObject();
152 0 : } else if (args[1].isNullOrUndefined()) {
153 0 : arg1 = nullptr;
154 : } else {
155 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of StructuredCloneHolder.constructor");
156 0 : return false;
157 : }
158 : } else {
159 0 : arg1 = nullptr;
160 : }
161 0 : Maybe<JSAutoCompartment> ac;
162 0 : if (objIsXray) {
163 0 : obj = js::CheckedUnwrap(obj);
164 0 : if (!obj) {
165 0 : return false;
166 : }
167 0 : ac.emplace(cx, obj);
168 0 : if (!JS_WrapObject(cx, &desiredProto)) {
169 0 : return false;
170 : }
171 0 : if (!JS_WrapValue(cx, &arg0)) {
172 0 : return false;
173 : }
174 0 : if (!JS_WrapObject(cx, &arg1)) {
175 0 : return false;
176 : }
177 : }
178 0 : binding_detail::FastErrorResult rv;
179 0 : auto result(StrongOrRawPtr<mozilla::dom::StructuredCloneBlob>(mozilla::dom::StructuredCloneBlob::Constructor(global, arg0, arg1, rv)));
180 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
181 0 : return false;
182 : }
183 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
184 : static_assert(!IsPointer<decltype(result)>::value,
185 : "NewObject implies that we need to keep the object alive with a strong reference.");
186 0 : if (!WrapNewBindingNonWrapperCachedObject(cx, obj, result, args.rval(), desiredProto)) {
187 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
188 0 : return false;
189 : }
190 0 : return true;
191 : }
192 :
193 : static const js::ClassOps sInterfaceObjectClassOps = {
194 : nullptr, /* addProperty */
195 : nullptr, /* delProperty */
196 : nullptr, /* getProperty */
197 : nullptr, /* setProperty */
198 : nullptr, /* enumerate */
199 : nullptr, /* newEnumerate */
200 : nullptr, /* resolve */
201 : nullptr, /* mayResolve */
202 : nullptr, /* finalize */
203 : _constructor, /* call */
204 : nullptr, /* hasInstance */
205 : _constructor, /* construct */
206 : nullptr, /* trace */
207 : };
208 :
209 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
210 : {
211 : "Function",
212 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
213 : &sInterfaceObjectClassOps,
214 : JS_NULL_CLASS_SPEC,
215 : JS_NULL_CLASS_EXT,
216 : &sInterfaceObjectClassObjectOps
217 : },
218 : eInterface,
219 : true,
220 : prototypes::id::StructuredCloneHolder,
221 : PrototypeTraits<prototypes::id::StructuredCloneHolder>::Depth,
222 : sNativePropertyHooks,
223 : "function StructuredCloneHolder() {\n [native code]\n}",
224 : JS::GetRealmFunctionPrototype
225 : };
226 :
227 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
228 : {
229 : "StructuredCloneHolderPrototype",
230 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
231 : JS_NULL_CLASS_OPS,
232 : JS_NULL_CLASS_SPEC,
233 : JS_NULL_CLASS_EXT,
234 : JS_NULL_OBJECT_OPS
235 : },
236 : eInterfacePrototype,
237 : false,
238 : prototypes::id::StructuredCloneHolder,
239 : PrototypeTraits<prototypes::id::StructuredCloneHolder>::Depth,
240 : sNativePropertyHooks,
241 : "[object StructuredCloneHolderPrototype]",
242 : JS::GetRealmObjectPrototype
243 : };
244 :
245 : bool
246 1 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
247 : {
248 1 : return nsContentUtils::ThreadsafeIsSystemCaller(aCx);
249 : }
250 :
251 : JSObject*
252 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
253 : {
254 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
255 : }
256 :
257 : static const js::ClassOps sClassOps = {
258 : nullptr, /* addProperty */
259 : nullptr, /* delProperty */
260 : nullptr, /* getProperty */
261 : nullptr, /* setProperty */
262 : nullptr, /* enumerate */
263 : nullptr, /* newEnumerate */
264 : nullptr, /* resolve */
265 : nullptr, /* mayResolve */
266 : _finalize, /* finalize */
267 : nullptr, /* call */
268 : nullptr, /* hasInstance */
269 : nullptr, /* construct */
270 : nullptr, /* trace */
271 : };
272 :
273 : static const js::ClassExtension sClassExtension = {
274 : nullptr, /* weakmapKeyDelegateOp */
275 : nullptr /* objectMovedOp */
276 : };
277 :
278 : static const DOMJSClass sClass = {
279 : { "StructuredCloneHolder",
280 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
281 : &sClassOps,
282 : JS_NULL_CLASS_SPEC,
283 : &sClassExtension,
284 : JS_NULL_OBJECT_OPS
285 : },
286 : { prototypes::id::StructuredCloneHolder, 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 },
287 : IsBaseOf<nsISupports, mozilla::dom::StructuredCloneBlob >::value,
288 : sNativePropertyHooks,
289 : FindAssociatedGlobalForNative<mozilla::dom::StructuredCloneBlob>::Get,
290 : GetProtoObjectHandle,
291 : GetCCParticipant<mozilla::dom::StructuredCloneBlob>::Get()
292 : };
293 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
294 : "Must have the right minimal number of reserved slots.");
295 : static_assert(1 >= 1,
296 : "Must have enough reserved slots.");
297 :
298 : const JSClass*
299 0 : GetJSClass()
300 : {
301 0 : return sClass.ToJSClass();
302 : }
303 :
304 : bool
305 0 : Wrap(JSContext* aCx, mozilla::dom::StructuredCloneBlob* aObject, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
306 : {
307 : MOZ_ASSERT(static_cast<mozilla::dom::StructuredCloneBlob*>(aObject) ==
308 : reinterpret_cast<mozilla::dom::StructuredCloneBlob*>(aObject),
309 : "Multiple inheritance for mozilla::dom::StructuredCloneBlob is broken.");
310 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
311 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
312 :
313 0 : JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
314 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
315 0 : if (!canonicalProto) {
316 0 : return false;
317 : }
318 0 : JS::Rooted<JSObject*> proto(aCx);
319 0 : if (aGivenProto) {
320 0 : proto = aGivenProto;
321 : // Unfortunately, while aGivenProto was in the compartment of aCx
322 : // coming in, we changed compartments to that of "parent" so may need
323 : // to wrap the proto here.
324 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
325 0 : if (!JS_WrapObject(aCx, &proto)) {
326 0 : return false;
327 : }
328 : }
329 : } else {
330 0 : proto = canonicalProto;
331 : }
332 :
333 0 : BindingJSObjectCreator<mozilla::dom::StructuredCloneBlob> creator(aCx);
334 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
335 0 : if (!aReflector) {
336 0 : return false;
337 : }
338 :
339 :
340 :
341 0 : creator.InitializationSucceeded();
342 0 : return true;
343 : }
344 :
345 : const NativePropertyHooks sNativePropertyHooks[] = { {
346 : nullptr,
347 : nullptr,
348 : nullptr,
349 : { sNativeProperties.Upcast(), nullptr },
350 : prototypes::id::StructuredCloneHolder,
351 : constructors::id::StructuredCloneHolder,
352 : nullptr,
353 : &DefaultXrayExpandoObjectClass
354 : } };
355 :
356 : void
357 1 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
358 : {
359 2 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
360 1 : if (!parentProto) {
361 0 : return;
362 : }
363 :
364 2 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
365 1 : if (!constructorProto) {
366 0 : return;
367 : }
368 :
369 : static bool sIdsInited = false;
370 1 : if (!sIdsInited && NS_IsMainThread()) {
371 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
372 0 : return;
373 : }
374 0 : sIdsInited = true;
375 : }
376 :
377 1 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::StructuredCloneHolder);
378 1 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::StructuredCloneHolder);
379 2 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
380 : &sPrototypeClass.mBase, protoCache,
381 : constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
382 : interfaceCache,
383 : sNativeProperties.Upcast(),
384 : nullptr,
385 : "StructuredCloneHolder", aDefineOnGlobal,
386 : nullptr,
387 1 : false);
388 : }
389 :
390 : JS::Handle<JSObject*>
391 0 : GetProtoObjectHandle(JSContext* aCx)
392 : {
393 : /* Get the interface prototype object for this class. This will create the
394 : object as needed. */
395 0 : bool aDefineOnGlobal = true;
396 :
397 : /* Make sure our global is sane. Hopefully we can remove this sometime */
398 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
399 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
400 0 : return nullptr;
401 : }
402 :
403 : /* Check to see whether the interface objects are already installed */
404 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
405 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::StructuredCloneHolder)) {
406 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
407 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
408 : }
409 :
410 : /*
411 : * The object might _still_ be null, but that's OK.
412 : *
413 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
414 : * traced by TraceProtoAndIfaceCache() and its contents are never
415 : * changed after they have been set.
416 : *
417 : * Calling address() avoids the read read barrier that does gray
418 : * unmarking, but it's not possible for the object to be gray here.
419 : */
420 :
421 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::StructuredCloneHolder);
422 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
423 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
424 : }
425 :
426 : JS::Handle<JSObject*>
427 1 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
428 : {
429 : /* Get the interface object for this class. This will create the object as
430 : needed. */
431 :
432 : /* Make sure our global is sane. Hopefully we can remove this sometime */
433 1 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
434 1 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
435 0 : return nullptr;
436 : }
437 :
438 : /* Check to see whether the interface objects are already installed */
439 1 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
440 1 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::StructuredCloneHolder)) {
441 2 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
442 1 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
443 : }
444 :
445 : /*
446 : * The object might _still_ be null, but that's OK.
447 : *
448 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
449 : * traced by TraceProtoAndIfaceCache() and its contents are never
450 : * changed after they have been set.
451 : *
452 : * Calling address() avoids the read read barrier that does gray
453 : * unmarking, but it's not possible for the object to be gray here.
454 : */
455 :
456 1 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::StructuredCloneHolder);
457 1 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
458 1 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
459 : }
460 :
461 : JSObject*
462 1 : GetConstructorObject(JSContext* aCx)
463 : {
464 1 : return GetConstructorObjectHandle(aCx);
465 : }
466 :
467 : } // namespace StructuredCloneHolderBinding
468 :
469 :
470 :
471 : } // namespace dom
472 : } // namespace mozilla
|