1 : /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 : * vim: set ts=4 sw=4 et tw=79:
3 : *
4 : * ***** BEGIN LICENSE BLOCK *****
5 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 : *
7 : * The contents of this file are subject to the Mozilla Public License Version
8 : * 1.1 (the "License"); you may not use this file except in compliance with
9 : * the License. You may obtain a copy of the License at
10 : * http://www.mozilla.org/MPL/
11 : *
12 : * Software distributed under the License is distributed on an "AS IS" basis,
13 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 : * for the specific language governing rights and limitations under the
15 : * License.
16 : *
17 : * The Original Code is Mozilla Communicator client code, released
18 : * March 31, 1998.
19 : *
20 : * The Initial Developer of the Original Code is
21 : * Netscape Communications Corporation.
22 : * Portions created by the Initial Developer are Copyright (C) 1998
23 : * the Initial Developer. All Rights Reserved.
24 : *
25 : * Contributor(s):
26 : * John Bandhauer <jband@netscape.com> (original author)
27 : *
28 : * Alternatively, the contents of this file may be used under the terms of
29 : * either of the GNU General Public License Version 2 or later (the "GPL"),
30 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 : * in which case the provisions of the GPL or the LGPL are applicable instead
32 : * of those above. If you wish to allow use of your version of this file only
33 : * under the terms of either the GPL or the LGPL, and not to allow others to
34 : * use your version of this file under the terms of the MPL, indicate your
35 : * decision by deleting the provisions above and replace them with the notice
36 : * and other provisions required by the GPL or the LGPL. If you do not delete
37 : * the provisions above, a recipient may use your version of this file under
38 : * the terms of any one of the MPL, the GPL or the LGPL.
39 : *
40 : * ***** END LICENSE BLOCK ***** */
41 :
42 : /* private inline methods (#include'd by xpcprivate.h). */
43 :
44 : #ifndef xpcinlines_h___
45 : #define xpcinlines_h___
46 :
47 : #include "jsfriendapi.h"
48 :
49 : /***************************************************************************/
50 : bool
51 18435 : xpc::PtrAndPrincipalHashKey::KeyEquals(const PtrAndPrincipalHashKey* aKey) const
52 : {
53 18435 : if (aKey->mPtr != mPtr)
54 24 : return false;
55 18411 : if (aKey->mPrincipal == mPrincipal)
56 18411 : return true;
57 :
58 : bool equals;
59 0 : if (NS_FAILED(mPrincipal->EqualsIgnoringDomain(aKey->mPrincipal, &equals))) {
60 0 : NS_ERROR("we failed, guessing!");
61 0 : return false;
62 : }
63 :
64 0 : return equals;
65 : }
66 :
67 : inline void
68 3464 : XPCJSRuntime::AddVariantRoot(XPCTraceableVariant* variant)
69 : {
70 3464 : variant->AddToRootSet(GetMapLock(), &mVariantRoots);
71 3464 : }
72 :
73 : inline void
74 131266 : XPCJSRuntime::AddWrappedJSRoot(nsXPCWrappedJS* wrappedJS)
75 : {
76 131266 : wrappedJS->AddToRootSet(GetMapLock(), &mWrappedJSRoots);
77 131266 : }
78 :
79 : inline void
80 0 : XPCJSRuntime::AddObjectHolderRoot(XPCJSObjectHolder* holder)
81 : {
82 0 : holder->AddToRootSet(GetMapLock(), &mObjectHolderRoots);
83 0 : }
84 :
85 : /***************************************************************************/
86 :
87 : inline JSBool
88 9860952 : XPCCallContext::IsValid() const
89 : {
90 9860952 : return mState != INIT_FAILED;
91 : }
92 :
93 : inline nsXPConnect*
94 355782 : XPCCallContext::GetXPConnect() const
95 : {
96 355782 : CHECK_STATE(HAVE_CONTEXT);
97 355782 : return mXPC;
98 : }
99 :
100 : inline XPCJSRuntime*
101 14873409 : XPCCallContext::GetRuntime() const
102 : {
103 14873409 : CHECK_STATE(HAVE_CONTEXT);
104 14873409 : return mXPCContext->GetRuntime();
105 : }
106 :
107 : inline XPCPerThreadData*
108 34791921 : XPCCallContext::GetThreadData() const
109 : {
110 34791921 : CHECK_STATE(HAVE_CONTEXT);
111 34791921 : return mThreadData;
112 : }
113 :
114 : inline XPCContext*
115 24864907 : XPCCallContext::GetXPCContext() const
116 : {
117 24864907 : CHECK_STATE(HAVE_CONTEXT);
118 24864907 : return mXPCContext;
119 : }
120 :
121 : inline JSContext*
122 81746949 : XPCCallContext::GetJSContext() const
123 : {
124 81746949 : CHECK_STATE(HAVE_CONTEXT);
125 81746949 : return mJSContext;
126 : }
127 :
128 : inline JSBool
129 : XPCCallContext::GetContextPopRequired() const
130 : {
131 : CHECK_STATE(HAVE_CONTEXT);
132 : return mContextPopRequired;
133 : }
134 :
135 : inline XPCContext::LangType
136 399 : XPCCallContext::GetCallerLanguage() const
137 : {
138 399 : CHECK_STATE(HAVE_CONTEXT);
139 399 : return mCallerLanguage;
140 : }
141 :
142 : inline XPCContext::LangType
143 : XPCCallContext::GetPrevCallerLanguage() const
144 : {
145 : CHECK_STATE(HAVE_CONTEXT);
146 : return mPrevCallerLanguage;
147 : }
148 :
149 : inline XPCCallContext*
150 19994 : XPCCallContext::GetPrevCallContext() const
151 : {
152 19994 : CHECK_STATE(HAVE_CONTEXT);
153 19994 : return mPrevCallContext;
154 : }
155 :
156 : inline JSObject*
157 8775215 : XPCCallContext::GetScopeForNewJSObjects() const
158 : {
159 8775215 : CHECK_STATE(HAVE_SCOPE);
160 8775215 : return mScopeForNewJSObjects;
161 : }
162 :
163 : inline void
164 3065717 : XPCCallContext::SetScopeForNewJSObjects(JSObject *scope)
165 : {
166 3065717 : NS_ABORT_IF_FALSE(mState == HAVE_CONTEXT, "wrong call context state");
167 3065717 : NS_ABORT_IF_FALSE(js::IsObjectInContextCompartment(scope, mJSContext), "wrong compartment");
168 3065717 : mScopeForNewJSObjects = scope;
169 3065717 : mState = HAVE_SCOPE;
170 3065717 : }
171 :
172 : inline JSObject*
173 7438384 : XPCCallContext::GetFlattenedJSObject() const
174 : {
175 7438384 : CHECK_STATE(HAVE_OBJECT);
176 7438384 : return mFlattenedJSObject;
177 : }
178 :
179 : inline nsISupports*
180 596 : XPCCallContext::GetIdentityObject() const
181 : {
182 596 : CHECK_STATE(HAVE_OBJECT);
183 596 : if (mWrapper)
184 596 : return mWrapper->GetIdentityObject();
185 : return mFlattenedJSObject ?
186 0 : static_cast<nsISupports*>(xpc_GetJSPrivate(mFlattenedJSObject)) :
187 0 : nsnull;
188 : }
189 :
190 : inline XPCWrappedNative*
191 41893327 : XPCCallContext::GetWrapper() const
192 : {
193 41893327 : if (mState == INIT_FAILED)
194 0 : return nsnull;
195 :
196 41893327 : CHECK_STATE(HAVE_OBJECT);
197 41893327 : return mWrapper;
198 : }
199 :
200 : inline XPCWrappedNativeProto*
201 596 : XPCCallContext::GetProto() const
202 : {
203 596 : CHECK_STATE(HAVE_OBJECT);
204 596 : if (mWrapper)
205 596 : return mWrapper->GetProto();
206 0 : return mFlattenedJSObject ? GetSlimWrapperProto(mFlattenedJSObject) : nsnull;
207 : }
208 :
209 : inline JSBool
210 9780 : XPCCallContext::CanGetTearOff() const
211 : {
212 9780 : return mState >= HAVE_OBJECT;
213 : }
214 :
215 : inline XPCWrappedNativeTearOff*
216 7394610 : XPCCallContext::GetTearOff() const
217 : {
218 7394610 : CHECK_STATE(HAVE_OBJECT);
219 7394610 : return mTearOff;
220 : }
221 :
222 : inline XPCNativeScriptableInfo*
223 326 : XPCCallContext::GetScriptableInfo() const
224 : {
225 326 : CHECK_STATE(HAVE_OBJECT);
226 326 : return mScriptableInfo;
227 : }
228 :
229 : inline JSBool
230 9780 : XPCCallContext::CanGetSet() const
231 : {
232 9780 : return mState >= HAVE_NAME;
233 : }
234 :
235 : inline XPCNativeSet*
236 1670940 : XPCCallContext::GetSet() const
237 : {
238 1670940 : CHECK_STATE(HAVE_NAME);
239 1670940 : return mSet;
240 : }
241 :
242 : inline JSBool
243 9780 : XPCCallContext::CanGetInterface() const
244 : {
245 9780 : return mState >= HAVE_NAME;
246 : }
247 :
248 : inline XPCNativeInterface*
249 9061311 : XPCCallContext::GetInterface() const
250 : {
251 9061311 : CHECK_STATE(HAVE_NAME);
252 9061311 : return mInterface;
253 : }
254 :
255 : inline XPCNativeMember*
256 7439363 : XPCCallContext::GetMember() const
257 : {
258 7439363 : CHECK_STATE(HAVE_NAME);
259 7439363 : return mMember;
260 : }
261 :
262 : inline JSBool
263 7390371 : XPCCallContext::HasInterfaceAndMember() const
264 : {
265 7390371 : return mState >= HAVE_NAME && mInterface && mMember;
266 : }
267 :
268 : inline jsid
269 : XPCCallContext::GetName() const
270 : {
271 : CHECK_STATE(HAVE_NAME);
272 : return mName;
273 : }
274 :
275 : inline JSBool
276 1656231 : XPCCallContext::GetStaticMemberIsLocal() const
277 : {
278 1656231 : CHECK_STATE(HAVE_NAME);
279 1656231 : return mStaticMemberIsLocal;
280 : }
281 :
282 : inline unsigned
283 7371823 : XPCCallContext::GetArgc() const
284 : {
285 7371823 : CHECK_STATE(READY_TO_CALL);
286 7371823 : return mArgc;
287 : }
288 :
289 : inline jsval*
290 7371823 : XPCCallContext::GetArgv() const
291 : {
292 7371823 : CHECK_STATE(READY_TO_CALL);
293 7371823 : return mArgv;
294 : }
295 :
296 : inline jsval*
297 : XPCCallContext::GetRetVal() const
298 : {
299 : CHECK_STATE(READY_TO_CALL);
300 : return mRetVal;
301 : }
302 :
303 : inline void
304 14085306 : XPCCallContext::SetRetVal(jsval val)
305 : {
306 14085306 : CHECK_STATE(HAVE_ARGS);
307 14085306 : if (mRetVal)
308 14085306 : *mRetVal = val;
309 14085306 : }
310 :
311 : inline jsid
312 1670908 : XPCCallContext::GetResolveName() const
313 : {
314 1670908 : CHECK_STATE(HAVE_CONTEXT);
315 1670908 : return mThreadData->GetResolveName();
316 : }
317 :
318 : inline jsid
319 3139734 : XPCCallContext::SetResolveName(jsid name)
320 : {
321 3139734 : CHECK_STATE(HAVE_CONTEXT);
322 3139734 : return mThreadData->SetResolveName(name);
323 : }
324 :
325 : inline XPCWrappedNative*
326 223550 : XPCCallContext::GetResolvingWrapper() const
327 : {
328 223550 : CHECK_STATE(HAVE_OBJECT);
329 223550 : return mThreadData->GetResolvingWrapper();
330 : }
331 :
332 : inline XPCWrappedNative*
333 1030760 : XPCCallContext::SetResolvingWrapper(XPCWrappedNative* w)
334 : {
335 1030760 : CHECK_STATE(HAVE_OBJECT);
336 1030760 : return mThreadData->SetResolvingWrapper(w);
337 : }
338 :
339 : inline PRUint16
340 7371823 : XPCCallContext::GetMethodIndex() const
341 : {
342 7371823 : CHECK_STATE(HAVE_OBJECT);
343 7371823 : return mMethodIndex;
344 : }
345 :
346 : inline void
347 : XPCCallContext::SetMethodIndex(PRUint16 index)
348 : {
349 : CHECK_STATE(HAVE_OBJECT);
350 : mMethodIndex = index;
351 : }
352 :
353 : inline JSBool
354 : XPCCallContext::GetDestroyJSContextInDestructor() const
355 : {
356 : CHECK_STATE(HAVE_CONTEXT);
357 : return mDestroyJSContextInDestructor;
358 : }
359 :
360 : inline void
361 0 : XPCCallContext::SetDestroyJSContextInDestructor(JSBool b)
362 : {
363 0 : CHECK_STATE(HAVE_CONTEXT);
364 0 : mDestroyJSContextInDestructor = b;
365 0 : }
366 :
367 : /***************************************************************************/
368 :
369 : inline const nsIID*
370 3591907 : XPCNativeInterface::GetIID() const
371 : {
372 : const nsIID* iid;
373 3591907 : return NS_SUCCEEDED(mInfo->GetIIDShared(&iid)) ? iid : nsnull;
374 : }
375 :
376 : inline const char*
377 87377 : XPCNativeInterface::GetNameString() const
378 : {
379 : const char* name;
380 87377 : return NS_SUCCEEDED(mInfo->GetNameShared(&name)) ? name : nsnull;
381 : }
382 :
383 : inline XPCNativeMember*
384 11572510 : XPCNativeInterface::FindMember(jsid name) const
385 : {
386 11572510 : const XPCNativeMember* member = mMembers;
387 62324084 : for (int i = (int) mMemberCount; i > 0; i--, member++)
388 55673073 : if (member->GetName() == name)
389 4921499 : return const_cast<XPCNativeMember*>(member);
390 6651011 : return nsnull;
391 : }
392 :
393 : inline JSBool
394 23858 : XPCNativeInterface::HasAncestor(const nsIID* iid) const
395 : {
396 23858 : bool found = false;
397 23858 : mInfo->HasAncestor(iid, &found);
398 23858 : return found;
399 : }
400 :
401 : /***************************************************************************/
402 :
403 : inline JSBool
404 6052579 : XPCNativeSet::FindMember(jsid name, XPCNativeMember** pMember,
405 : PRUint16* pInterfaceIndex) const
406 : {
407 : XPCNativeInterface* const * iface;
408 6052579 : int count = (int) mInterfaceCount;
409 : int i;
410 :
411 : // look for interface names first
412 :
413 18384816 : for (i = 0, iface = mInterfaces; i < count; i++, iface++) {
414 12332354 : if (name == (*iface)->GetName()) {
415 117 : if (pMember)
416 117 : *pMember = nsnull;
417 117 : if (pInterfaceIndex)
418 117 : *pInterfaceIndex = (PRUint16) i;
419 117 : return true;
420 : }
421 : }
422 :
423 : // look for method names
424 12698566 : for (i = 0, iface = mInterfaces; i < count; i++, iface++) {
425 11553197 : XPCNativeMember* member = (*iface)->FindMember(name);
426 11553197 : if (member) {
427 4907093 : if (pMember)
428 4907093 : *pMember = member;
429 4907093 : if (pInterfaceIndex)
430 4907093 : *pInterfaceIndex = (PRUint16) i;
431 4907093 : return true;
432 : }
433 : }
434 1145369 : return false;
435 : }
436 :
437 : inline JSBool
438 5966102 : XPCNativeSet::FindMember(jsid name, XPCNativeMember** pMember,
439 : XPCNativeInterface** pInterface) const
440 : {
441 : PRUint16 index;
442 5966102 : if (!FindMember(name, pMember, &index))
443 1058892 : return false;
444 4907210 : *pInterface = mInterfaces[index];
445 4907210 : return true;
446 : }
447 :
448 : inline JSBool
449 3268479 : XPCNativeSet::FindMember(jsid name,
450 : XPCNativeMember** pMember,
451 : XPCNativeInterface** pInterface,
452 : XPCNativeSet* protoSet,
453 : JSBool* pIsLocal) const
454 : {
455 : XPCNativeMember* Member;
456 : XPCNativeInterface* Interface;
457 : XPCNativeMember* protoMember;
458 :
459 3268479 : if (!FindMember(name, &Member, &Interface))
460 31421 : return false;
461 :
462 3237058 : *pMember = Member;
463 3237058 : *pInterface = Interface;
464 :
465 : *pIsLocal =
466 3237058 : !Member ||
467 : !protoSet ||
468 : (protoSet != this &&
469 95629 : !protoSet->MatchesSetUpToInterface(this, Interface) &&
470 86477 : (!protoSet->FindMember(name, &protoMember, (PRUint16*)nsnull) ||
471 3419164 : protoMember != Member));
472 :
473 3237058 : return true;
474 : }
475 :
476 : inline XPCNativeInterface*
477 0 : XPCNativeSet::FindNamedInterface(jsid name) const
478 : {
479 0 : XPCNativeInterface* const * pp = mInterfaces;
480 :
481 0 : for (int i = (int) mInterfaceCount; i > 0; i--, pp++) {
482 0 : XPCNativeInterface* iface = *pp;
483 :
484 0 : if (name == iface->GetName())
485 0 : return iface;
486 : }
487 0 : return nsnull;
488 : }
489 :
490 : inline XPCNativeInterface*
491 355438 : XPCNativeSet::FindInterfaceWithIID(const nsIID& iid) const
492 : {
493 355438 : XPCNativeInterface* const * pp = mInterfaces;
494 :
495 749412 : for (int i = (int) mInterfaceCount; i > 0; i--, pp++) {
496 727377 : XPCNativeInterface* iface = *pp;
497 :
498 727377 : if (iface->GetIID()->Equals(iid))
499 333403 : return iface;
500 : }
501 22035 : return nsnull;
502 : }
503 :
504 : inline JSBool
505 1665356 : XPCNativeSet::HasInterface(XPCNativeInterface* aInterface) const
506 : {
507 1665356 : XPCNativeInterface* const * pp = mInterfaces;
508 :
509 3618981 : for (int i = (int) mInterfaceCount; i > 0; i--, pp++) {
510 3331787 : if (aInterface == *pp)
511 1378162 : return true;
512 : }
513 287194 : return false;
514 : }
515 :
516 : inline JSBool
517 5076 : XPCNativeSet::HasInterfaceWithAncestor(XPCNativeInterface* aInterface) const
518 : {
519 5076 : return HasInterfaceWithAncestor(aInterface->GetIID());
520 : }
521 :
522 : inline JSBool
523 13852 : XPCNativeSet::HasInterfaceWithAncestor(const nsIID* iid) const
524 : {
525 : // We can safely skip the first interface which is *always* nsISupports.
526 13852 : XPCNativeInterface* const * pp = mInterfaces+1;
527 33858 : for (int i = (int) mInterfaceCount; i > 1; i--, pp++)
528 23858 : if ((*pp)->HasAncestor(iid))
529 3852 : return true;
530 :
531 : // This is rare, so check last.
532 10000 : if (iid == &NS_GET_IID(nsISupports))
533 0 : return true;
534 :
535 10000 : return false;
536 : }
537 :
538 : inline JSBool
539 95629 : XPCNativeSet::MatchesSetUpToInterface(const XPCNativeSet* other,
540 : XPCNativeInterface* iface) const
541 : {
542 95629 : int count = JS_MIN((int)mInterfaceCount, (int)other->mInterfaceCount);
543 :
544 95629 : XPCNativeInterface* const * pp1 = mInterfaces;
545 95629 : XPCNativeInterface* const * pp2 = other->mInterfaces;
546 :
547 190161 : for (int i = (int) count; i > 0; i--, pp1++, pp2++) {
548 103684 : XPCNativeInterface* cur = (*pp1);
549 103684 : if (cur != (*pp2))
550 0 : return false;
551 103684 : if (cur == iface)
552 9152 : return true;
553 : }
554 86477 : return false;
555 : }
556 :
557 4971868 : inline void XPCNativeSet::Mark()
558 : {
559 4971868 : if (IsMarked())
560 4749874 : return;
561 :
562 221994 : XPCNativeInterface* const * pp = mInterfaces;
563 :
564 762199 : for (int i = (int) mInterfaceCount; i > 0; i--, pp++)
565 540205 : (*pp)->Mark();
566 :
567 221994 : MarkSelfOnly();
568 : }
569 :
570 : #ifdef DEBUG
571 4967962 : inline void XPCNativeSet::ASSERT_NotMarked()
572 : {
573 4967962 : NS_ASSERTION(!IsMarked(), "bad");
574 :
575 4967962 : XPCNativeInterface* const * pp = mInterfaces;
576 :
577 18111863 : for (int i = (int) mInterfaceCount; i > 0; i--, pp++)
578 13143901 : NS_ASSERTION(!(*pp)->IsMarked(), "bad");
579 4967962 : }
580 : #endif
581 :
582 : /***************************************************************************/
583 :
584 : inline
585 5405651 : JSObject* XPCWrappedNativeTearOff::GetJSObjectPreserveColor() const
586 : {
587 5405651 : return mJSObject;
588 : }
589 :
590 : inline
591 60 : JSObject* XPCWrappedNativeTearOff::GetJSObject()
592 : {
593 60 : JSObject *obj = GetJSObjectPreserveColor();
594 60 : xpc_UnmarkGrayObject(obj);
595 60 : return obj;
596 : }
597 :
598 : inline
599 120 : void XPCWrappedNativeTearOff::SetJSObject(JSObject* JSObj)
600 : {
601 120 : mJSObject = JSObj;
602 120 : }
603 :
604 : inline
605 1423222 : XPCWrappedNativeTearOff::~XPCWrappedNativeTearOff()
606 : {
607 1423222 : NS_ASSERTION(!(GetInterface()||GetNative()||GetJSObjectPreserveColor()),
608 : "tearoff not empty in dtor");
609 1423222 : }
610 :
611 : /***************************************************************************/
612 :
613 : inline JSBool
614 355438 : XPCWrappedNative::HasInterfaceNoQI(const nsIID& iid)
615 : {
616 355438 : return nsnull != GetSet()->FindInterfaceWithIID(iid);
617 : }
618 :
619 : inline void
620 2232933 : XPCWrappedNative::SweepTearOffs()
621 : {
622 : XPCWrappedNativeTearOffChunk* chunk;
623 4794590 : for (chunk = &mFirstChunk; chunk; chunk = chunk->mNextChunk) {
624 2561657 : XPCWrappedNativeTearOff* to = chunk->mTearOffs;
625 5123314 : for (int i = XPC_WRAPPED_NATIVE_TEAROFFS_PER_CHUNK; i > 0; i--, to++) {
626 2561657 : JSBool marked = to->IsMarked();
627 2561657 : to->Unmark();
628 2561657 : if (marked)
629 3782 : continue;
630 :
631 : // If this tearoff does not have a live dedicated JSObject,
632 : // then let's recycle it.
633 2557875 : if (!to->GetJSObjectPreserveColor()) {
634 2557698 : nsISupports* obj = to->GetNative();
635 2557698 : if (obj) {
636 377484 : obj->Release();
637 377484 : to->SetNative(nsnull);
638 : }
639 2557698 : to->SetInterface(nsnull);
640 : }
641 : }
642 : }
643 2232933 : }
644 :
645 : /***************************************************************************/
646 :
647 : inline JSBool
648 302 : xpc_ForcePropertyResolve(JSContext* cx, JSObject* obj, jsid id)
649 : {
650 : jsval prop;
651 :
652 302 : if (!JS_LookupPropertyById(cx, obj, id, &prop))
653 0 : return false;
654 302 : return true;
655 : }
656 :
657 : inline JSObject*
658 1437603 : xpc_NewSystemInheritingJSObject(JSContext *cx, JSClass *clasp, JSObject *proto,
659 : bool uniqueType, JSObject *parent)
660 : {
661 : // Global creation should go through XPCWrappedNative::WrapNewGlobal().
662 1437603 : MOZ_ASSERT(!(clasp->flags & JSCLASS_IS_GLOBAL));
663 :
664 : JSObject *obj;
665 1437603 : if (uniqueType) {
666 186009 : obj = JS_NewObjectWithUniqueType(cx, clasp, proto, parent);
667 : } else {
668 1251594 : obj = JS_NewObject(cx, clasp, proto, parent);
669 : }
670 1437603 : if (obj && JS_IsSystemObject(cx, parent) && !JS_MakeSystemObject(cx, obj))
671 0 : obj = NULL;
672 1437603 : return obj;
673 : }
674 :
675 : inline jsid
676 0 : GetRTIdByIndex(JSContext *cx, unsigned index)
677 : {
678 0 : XPCJSRuntime *rt = nsXPConnect::FastGetXPConnect()->GetRuntime();
679 0 : return rt->GetStringID(index);
680 : }
681 :
682 : inline
683 25 : JSBool ThrowBadParam(nsresult rv, unsigned paramNum, XPCCallContext& ccx)
684 : {
685 25 : XPCThrower::ThrowBadParam(rv, paramNum, ccx);
686 25 : return false;
687 : }
688 :
689 : inline
690 18766 : void ThrowBadResult(nsresult result, XPCCallContext& ccx)
691 : {
692 : XPCThrower::ThrowBadResult(NS_ERROR_XPC_NATIVE_RETURNED_FAILURE,
693 18766 : result, ccx);
694 18766 : }
695 :
696 : inline void
697 18138 : XPCLazyCallContext::SetWrapper(XPCWrappedNative* wrapper,
698 : XPCWrappedNativeTearOff* tearoff)
699 : {
700 18138 : mWrapper = wrapper;
701 18138 : mTearOff = tearoff;
702 18138 : if (mTearOff)
703 0 : mFlattenedJSObject = mTearOff->GetJSObject();
704 : else
705 18138 : mFlattenedJSObject = mWrapper->GetFlatJSObject();
706 18138 : }
707 : inline void
708 10970 : XPCLazyCallContext::SetWrapper(JSObject* flattenedJSObject)
709 : {
710 10970 : NS_ASSERTION(IS_SLIM_WRAPPER_OBJECT(flattenedJSObject),
711 : "What kind of object is this?");
712 10970 : mWrapper = nsnull;
713 10970 : mTearOff = nsnull;
714 10970 : mFlattenedJSObject = flattenedJSObject;
715 10970 : }
716 :
717 : /***************************************************************************/
718 :
719 : #endif /* xpcinlines_h___ */
|