Bug 714458 - Part a: Introduce JSAPI for JSContext's second private pointer; r=Waldo

JSContext currently has 2 private pointers, but the JSAPI only provides access
to one of them.
This commit is contained in:
Ms2ger 2012-01-11 09:23:07 +01:00
parent 0b7161afcb
commit 38fbde8026
4 changed files with 26 additions and 6 deletions

View File

@ -1194,6 +1194,18 @@ JS_SetContextPrivate(JSContext *cx, void *data)
cx->data = data;
}
JS_PUBLIC_API(void *)
JS_GetSecondContextPrivate(JSContext *cx)
{
return cx->data2;
}
JS_PUBLIC_API(void)
JS_SetSecondContextPrivate(JSContext *cx, void *data)
{
cx->data2 = data;
}
JS_PUBLIC_API(JSRuntime *)
JS_GetRuntime(JSContext *cx)
{

View File

@ -2085,6 +2085,12 @@ JS_GetContextPrivate(JSContext *cx);
extern JS_PUBLIC_API(void)
JS_SetContextPrivate(JSContext *cx, void *data);
extern JS_PUBLIC_API(void *)
JS_GetSecondContextPrivate(JSContext *cx);
extern JS_PUBLIC_API(void)
JS_SetSecondContextPrivate(JSContext *cx, void *data);
extern JS_PUBLIC_API(JSRuntime *)
JS_GetRuntime(JSContext *cx);

View File

@ -42,6 +42,8 @@
#include "xpcprivate.h"
#include "jsapi.h"
/***************************************************************************/
XPCContext::XPCContext(XPCJSRuntime* aRuntime,
@ -59,15 +61,15 @@ XPCContext::XPCContext(XPCJSRuntime* aRuntime,
PR_INIT_CLIST(&mScopes);
NS_ASSERTION(!mJSContext->data2, "Must be null");
mJSContext->data2 = this;
NS_ASSERTION(!JS_GetSecondContextPrivate(mJSContext), "Must be null");
JS_SetSecondContextPrivate(mJSContext, this);
}
XPCContext::~XPCContext()
{
MOZ_COUNT_DTOR(XPCContext);
NS_ASSERTION(mJSContext->data2 == this, "Must match this");
mJSContext->data2 = nsnull;
NS_ASSERTION(JS_GetSecondContextPrivate(mJSContext) == this, "Must match this");
JS_SetSecondContextPrivate(mJSContext, nsnull);
NS_IF_RELEASE(mException);
NS_IF_RELEASE(mSecurityManager);

View File

@ -859,8 +859,8 @@ class XPCContext
public:
static XPCContext* GetXPCContext(JSContext* aJSContext)
{
NS_ASSERTION(aJSContext->data2, "should already have XPCContext");
return static_cast<XPCContext *>(aJSContext->data2);
NS_ASSERTION(JS_GetSecondContextPrivate(aJSContext), "should already have XPCContext");
return static_cast<XPCContext *>(JS_GetSecondContextPrivate(aJSContext));
}
XPCJSRuntime* GetRuntime() const {return mRuntime;}