bug 723517 - drop cx argument from JSObject field and fixed slots infallible API. r=:Waldo

--HG--
extra : rebase_source : c461dfc0e0e0462ab262cc01c2a771d3bb0971cc
This commit is contained in:
Igor Bukanov 2012-02-05 21:07:23 +01:00
Родитель d6ed2294cf
Коммит ca990d2064
64 изменённых файлов: 1000 добавлений и 1310 удалений

Просмотреть файл

@ -337,7 +337,7 @@ nsSecurityNameSet::InitializeNameSet(nsIScriptContext* aScriptContext)
JSObject *obj = global;
JSObject *proto;
JSAutoRequest ar(cx);
while ((proto = JS_GetPrototype(cx, obj)) != nsnull)
while ((proto = JS_GetPrototype(obj)) != nsnull)
obj = proto;
JSClass *objectClass = JS_GetClass(obj);

Просмотреть файл

@ -108,7 +108,7 @@ static void
XBLFinalize(JSContext *cx, JSObject *obj)
{
nsXBLDocumentInfo* docInfo =
static_cast<nsXBLDocumentInfo*>(::JS_GetPrivate(cx, obj));
static_cast<nsXBLDocumentInfo*>(::JS_GetPrivate(obj));
NS_RELEASE(docInfo);
nsXBLJSClass* c = static_cast<nsXBLJSClass*>(::JS_GetClass(obj));
@ -135,8 +135,7 @@ XBLResolve(JSContext *cx, JSObject *obj, jsid id, uintN flags,
nsDependentJSString fieldName(id);
jsval slotVal;
::JS_GetReservedSlot(cx, obj, 0, &slotVal);
jsval slotVal = ::JS_GetReservedSlot(obj, 0);
NS_ASSERTION(!JSVAL_IS_VOID(slotVal), "How did that happen?");
nsXBLPrototypeBinding* protoBinding =
@ -161,7 +160,7 @@ XBLResolve(JSContext *cx, JSObject *obj, jsid id, uintN flags,
}
nsCOMPtr<nsIXPConnectWrappedNative> xpcWrapper =
do_QueryInterface(static_cast<nsISupports*>(::JS_GetPrivate(cx, origObj)));
do_QueryInterface(static_cast<nsISupports*>(::JS_GetPrivate(origObj)));
if (!xpcWrapper) {
// Looks like whatever |origObj| is it's not our nsIContent. It might well
// be the proto our binding installed, however, where the private is the
@ -1088,7 +1087,7 @@ nsXBLBinding::ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocumen
}
for ( ; true; base = proto) { // Will break out on null proto
proto = ::JS_GetPrototype(cx, base);
proto = ::JS_GetPrototype(base);
if (!proto) {
break;
}
@ -1105,17 +1104,13 @@ nsXBLBinding::ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocumen
}
nsRefPtr<nsXBLDocumentInfo> docInfo =
static_cast<nsXBLDocumentInfo*>(::JS_GetPrivate(cx, proto));
static_cast<nsXBLDocumentInfo*>(::JS_GetPrivate(proto));
if (!docInfo) {
// Not the proto we seek
continue;
}
jsval protoBinding;
if (!::JS_GetReservedSlot(cx, proto, 0, &protoBinding)) {
NS_ERROR("Really shouldn't happen");
continue;
}
jsval protoBinding = ::JS_GetReservedSlot(proto, 0);
if (JSVAL_TO_PRIVATE(protoBinding) != mPrototypeBinding) {
// Not the right binding
@ -1124,7 +1119,7 @@ nsXBLBinding::ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocumen
// Alright! This is the right prototype. Pull it out of the
// proto chain.
JSObject* grandProto = ::JS_GetPrototype(cx, proto);
JSObject* grandProto = ::JS_GetPrototype(proto);
::JS_SetPrototype(cx, base, grandProto);
break;
}
@ -1224,7 +1219,7 @@ nsXBLBinding::DoInitJSClass(JSContext *cx, JSObject *global, JSObject *obj,
if (obj) {
// Retrieve the current prototype of obj.
parent_proto = ::JS_GetPrototype(cx, obj);
parent_proto = ::JS_GetPrototype(obj);
if (parent_proto) {
// We need to create a unique classname based on aClassName and
// parent_proto. Append a space (an invalid URI character) to ensure that
@ -1327,16 +1322,10 @@ nsXBLBinding::DoInitJSClass(JSContext *cx, JSObject *global, JSObject *obj,
// collection doesn't seem to work right if the private is not an
// nsISupports.
nsXBLDocumentInfo* docInfo = aProtoBinding->XBLDocumentInfo();
::JS_SetPrivate(cx, proto, docInfo);
::JS_SetPrivate(proto, docInfo);
NS_ADDREF(docInfo);
if (!::JS_SetReservedSlot(cx, proto, 0, PRIVATE_TO_JSVAL(aProtoBinding))) {
(nsXBLService::gClassTable)->Remove(&key);
// |c| will get dropped when |proto| is finalized
return NS_ERROR_OUT_OF_MEMORY;
}
::JS_SetReservedSlot(proto, 0, PRIVATE_TO_JSVAL(aProtoBinding));
*aClassObject = proto;
}

Просмотреть файл

@ -122,7 +122,7 @@ nsXBLDocGlobalObject::doCheckAccess(JSContext *cx, JSObject *obj, jsid id, PRUin
// Make sure to actually operate on our object, and not some object further
// down on the proto chain.
while (JS_GetClass(obj) != &nsXBLDocGlobalObject::gSharedGlobalClass) {
obj = ::JS_GetPrototype(cx, obj);
obj = ::JS_GetPrototype(obj);
if (!obj) {
::JS_ReportError(cx, "Invalid access to a global object property.");
return JS_FALSE;
@ -168,7 +168,7 @@ nsXBLDocGlobalObject_checkAccess(JSContext *cx, JSObject *obj, jsid id,
static void
nsXBLDocGlobalObject_finalize(JSContext *cx, JSObject *obj)
{
nsISupports *nativeThis = (nsISupports*)JS_GetPrivate(cx, obj);
nsISupports *nativeThis = (nsISupports*)JS_GetPrivate(obj);
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(nativeThis));
@ -334,7 +334,7 @@ nsXBLDocGlobalObject::EnsureScriptEnvironment(PRUint32 aLangID)
// Add an owning reference from JS back to us. This'll be
// released when the JSObject is finalized.
::JS_SetPrivate(cx, mJSObject, this);
::JS_SetPrivate(mJSObject, this);
NS_ADDREF(this);
return NS_OK;
}

Просмотреть файл

@ -119,7 +119,7 @@ PRUint32 nsXULPrototypeDocument::gRefCnt;
void
nsXULPDGlobalObject_finalize(JSContext *cx, JSObject *obj)
{
nsISupports *nativeThis = (nsISupports*)JS_GetPrivate(cx, obj);
nsISupports *nativeThis = (nsISupports*)JS_GetPrivate(obj);
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(nativeThis));
@ -747,7 +747,7 @@ nsXULPDGlobalObject::EnsureScriptEnvironment(PRUint32 lang_id)
// Add an owning reference from JS back to us. This'll be
// released when the JSObject is finalized.
::JS_SetPrivate(cx, newGlob, this);
::JS_SetPrivate(newGlob, this);
NS_ADDREF(this);
}

Просмотреть файл

@ -4896,8 +4896,8 @@ nsDOMClassInfo::PostCreatePrototype(JSContext * cx, JSObject * proto)
"Incorrect object class!");
}
NS_ASSERTION(::JS_GetPrototype(cx, proto) &&
JS_GetClass(::JS_GetPrototype(cx, proto)) == sObjectClass,
NS_ASSERTION(::JS_GetPrototype(proto) &&
JS_GetClass(::JS_GetPrototype(proto)) == sObjectClass,
"Hmm, somebody did something evil?");
#ifdef DEBUG
@ -5204,10 +5204,10 @@ nsWindowSH::SecurityCheckOnSetProp(JSContext *cx, JSObject *obj, jsid id, JSBool
}
static nsHTMLDocument*
GetDocument(JSContext *cx, JSObject *obj)
GetDocument(JSObject *obj)
{
return static_cast<nsHTMLDocument*>(
static_cast<nsIHTMLDocument*>(::JS_GetPrivate(cx, obj)));
static_cast<nsIHTMLDocument*>(::JS_GetPrivate(obj)));
}
// static
@ -5226,7 +5226,7 @@ nsWindowSH::GlobalScopePolluterNewResolve(JSContext *cx, JSObject *obj,
return JS_TRUE;
}
nsHTMLDocument *document = GetDocument(cx, obj);
nsHTMLDocument *document = GetDocument(obj);
if (!document ||
document->GetCompatibilityMode() != eCompatibility_NavQuirks) {
@ -5236,7 +5236,7 @@ nsWindowSH::GlobalScopePolluterNewResolve(JSContext *cx, JSObject *obj,
return JS_TRUE;
}
JSObject *proto = ::JS_GetPrototype(cx, obj);
JSObject *proto = ::JS_GetPrototype(obj);
JSBool hasProp;
if (!proto || !::JS_HasPropertyById(cx, proto, id, &hasProp) ||
@ -5286,17 +5286,17 @@ nsWindowSH::InvalidateGlobalScopePolluter(JSContext *cx, JSObject *obj)
JSAutoRequest ar(cx);
while ((proto = ::JS_GetPrototype(cx, obj))) {
while ((proto = ::JS_GetPrototype(obj))) {
if (JS_GetClass(proto) == &sGlobalScopePolluterClass) {
nsIHTMLDocument *doc = (nsIHTMLDocument *)::JS_GetPrivate(cx, proto);
nsIHTMLDocument *doc = (nsIHTMLDocument *)::JS_GetPrivate(proto);
NS_IF_RELEASE(doc);
::JS_SetPrivate(cx, proto, nsnull);
::JS_SetPrivate(proto, nsnull);
// Pull the global scope polluter out of the prototype chain so
// that it can be freed.
::JS_SplicePrototype(cx, obj, ::JS_GetPrototype(cx, proto));
::JS_SplicePrototype(cx, obj, ::JS_GetPrototype(proto));
break;
}
@ -5328,7 +5328,7 @@ nsWindowSH::InstallGlobalScopePolluter(JSContext *cx, JSObject *obj,
// Find the place in the prototype chain where we want this global
// scope polluter (right before Object.prototype).
while ((proto = ::JS_GetPrototype(cx, o))) {
while ((proto = ::JS_GetPrototype(o))) {
if (JS_GetClass(proto) == sObjectClass) {
// Set the global scope polluters prototype to Object.prototype
::JS_SplicePrototype(cx, gsp, proto);
@ -5343,9 +5343,7 @@ nsWindowSH::InstallGlobalScopePolluter(JSContext *cx, JSObject *obj,
// Object.prototype to be the global scope polluter.
::JS_SplicePrototype(cx, o, gsp);
if (!::JS_SetPrivate(cx, gsp, doc)) {
return NS_ERROR_UNEXPECTED;
}
::JS_SetPrivate(gsp, doc);
// The global scope polluter will release doc on destruction (or
// invalidation).
@ -5928,8 +5926,8 @@ nsDOMConstructor::HasInstance(nsIXPConnectWrappedNative *wrapper,
JS_ASSERT(!JSVAL_IS_PRIMITIVE(val));
JSObject *dot_prototype = JSVAL_TO_OBJECT(val);
JSObject *proto = JS_GetPrototype(cx, dom_obj);
for ( ; proto; proto = JS_GetPrototype(cx, proto)) {
JSObject *proto = JS_GetPrototype(dom_obj);
for ( ; proto; proto = JS_GetPrototype(proto)) {
if (proto == dot_prototype) {
*bp = true;
break;
@ -6300,7 +6298,7 @@ ResolvePrototype(nsIXPConnect *aXPConnect, nsGlobalWindow *aWin, JSContext *cx,
return NS_ERROR_UNEXPECTED;
}
JSObject *xpc_proto_proto = ::JS_GetPrototype(cx, dot_prototype);
JSObject *xpc_proto_proto = ::JS_GetPrototype(dot_prototype);
if (proto &&
(!xpc_proto_proto ||
@ -8150,7 +8148,7 @@ nsNamedArraySH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
return NS_ERROR_FAILURE;
}
JSObject *proto = ::JS_GetPrototype(cx, realObj);
JSObject *proto = ::JS_GetPrototype(realObj);
if (proto) {
JSBool hasProp;
@ -8727,12 +8725,9 @@ nsHTMLDocumentSH::GetDocumentAllNodeList(JSContext *cx, JSObject *obj,
// node list part (i.e. access to elements by index) not walk the
// document each time, we create a nsContentList and hold on to it
// in a reserved slot (0) on the document.all JSObject.
jsval collection;
nsresult rv = NS_OK;
if (!JS_GetReservedSlot(cx, obj, 0, &collection)) {
return JS_FALSE;
}
jsval collection = JS_GetReservedSlot(obj, 0);
if (!JSVAL_IS_PRIMITIVE(collection)) {
// We already have a node list in our reserved slot, use it.
@ -8768,9 +8763,7 @@ nsHTMLDocumentSH::GetDocumentAllNodeList(JSContext *cx, JSObject *obj,
list.forget(nodeList);
// ... and store it in our reserved slot.
if (!JS_SetReservedSlot(cx, obj, 0, collection)) {
return JS_FALSE;
}
JS_SetReservedSlot(obj, 0, collection);
}
if (NS_FAILED(rv)) {
@ -8804,7 +8797,7 @@ nsHTMLDocumentSH::DocumentAllGetProperty(JSContext *cx, JSObject *obj,
}
}
nsHTMLDocument *doc = GetDocument(cx, obj);
nsHTMLDocument *doc = GetDocument(obj);
nsISupports *result;
nsWrapperCache *cache;
nsresult rv = NS_OK;
@ -8909,7 +8902,7 @@ nsHTMLDocumentSH::DocumentAllNewResolve(JSContext *cx, JSObject *obj, jsid id,
v = JSVAL_ONE;
} else if (id == sTags_id) {
nsHTMLDocument *doc = GetDocument(cx, obj);
nsHTMLDocument *doc = GetDocument(obj);
JSObject *tags = ::JS_NewObject(cx, &sHTMLDocumentAllTagsClass, nsnull,
::JS_GetGlobalForObject(cx, obj));
@ -8917,9 +8910,7 @@ nsHTMLDocumentSH::DocumentAllNewResolve(JSContext *cx, JSObject *obj, jsid id,
return JS_FALSE;
}
if (!::JS_SetPrivate(cx, tags, doc)) {
return JS_FALSE;
}
::JS_SetPrivate(tags, doc);
// The "tags" JSObject now also owns doc.
NS_ADDREF(doc);
@ -8947,7 +8938,7 @@ nsHTMLDocumentSH::DocumentAllNewResolve(JSContext *cx, JSObject *obj, jsid id,
void
nsHTMLDocumentSH::ReleaseDocument(JSContext *cx, JSObject *obj)
{
nsIHTMLDocument *doc = (nsIHTMLDocument *)::JS_GetPrivate(cx, obj);
nsIHTMLDocument *doc = (nsIHTMLDocument *)::JS_GetPrivate(obj);
NS_IF_RELEASE(doc);
}
@ -8995,10 +8986,10 @@ nsHTMLDocumentSH::CallToGetPropMapper(JSContext *cx, uintN argc, jsval *vp)
static inline JSObject *
GetDocumentAllHelper(JSContext *cx, JSObject *obj)
GetDocumentAllHelper(JSObject *obj)
{
while (obj && JS_GetClass(obj) != &sHTMLDocumentAllHelperClass) {
obj = ::JS_GetPrototype(cx, obj);
obj = ::JS_GetPrototype(obj);
}
return obj;
@ -9026,7 +9017,7 @@ nsHTMLDocumentSH::DocumentAllHelperGetProperty(JSContext *cx, JSObject *obj,
return JS_TRUE;
}
JSObject *helper = GetDocumentAllHelper(cx, obj);
JSObject *helper = GetDocumentAllHelper(obj);
if (!helper) {
NS_ERROR("Uh, how'd we get here?");
@ -9036,7 +9027,7 @@ nsHTMLDocumentSH::DocumentAllHelperGetProperty(JSContext *cx, JSObject *obj,
return JS_TRUE;
}
PRUint32 flags = PrivateToFlags(::JS_GetPrivate(cx, helper));
PRUint32 flags = PrivateToFlags(::JS_GetPrivate(helper));
if (flags & JSRESOLVE_DETECTING || !(flags & JSRESOLVE_QUALIFIED)) {
// document.all is either being detected, e.g. if (document.all),
@ -9066,9 +9057,7 @@ nsHTMLDocumentSH::DocumentAllHelperGetProperty(JSContext *cx, JSObject *obj,
}
// Let the JSObject take over ownership of doc.
if (!::JS_SetPrivate(cx, all, doc)) {
return JS_FALSE;
}
::JS_SetPrivate(all, doc);
doc.forget();
@ -9086,7 +9075,7 @@ nsHTMLDocumentSH::DocumentAllHelperNewResolve(JSContext *cx, JSObject *obj,
{
if (id == nsDOMClassInfo::sAll_id) {
// document.all is resolved for the first time. Define it.
JSObject *helper = GetDocumentAllHelper(cx, obj);
JSObject *helper = GetDocumentAllHelper(obj);
if (helper) {
if (!::JS_DefineProperty(cx, helper, "all", JSVAL_VOID, nsnull, nsnull,
@ -9108,9 +9097,9 @@ nsHTMLDocumentSH::DocumentAllTagsNewResolve(JSContext *cx, JSObject *obj,
JSObject **objp)
{
if (JSID_IS_STRING(id)) {
nsDocument *doc = GetDocument(cx, obj);
nsDocument *doc = GetDocument(obj);
JSObject *proto = ::JS_GetPrototype(cx, obj);
JSObject *proto = ::JS_GetPrototype(obj);
if (NS_UNLIKELY(!proto)) {
return JS_TRUE;
}
@ -9188,10 +9177,9 @@ nsHTMLDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
nsIDocument *doc = static_cast<nsIDocument*>(wrapper->Native());
if (doc->GetCompatibilityMode() == eCompatibility_NavQuirks) {
JSObject *helper =
GetDocumentAllHelper(cx, ::JS_GetPrototype(cx, obj));
JSObject *helper = GetDocumentAllHelper(::JS_GetPrototype(obj));
JSObject *proto = ::JS_GetPrototype(cx, helper ? helper : obj);
JSObject *proto = ::JS_GetPrototype(helper ? helper : obj);
// Check if the property all is defined on obj's (or helper's
// if obj doesn't exist) prototype, if it is, don't expose our
@ -9208,7 +9196,7 @@ nsHTMLDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
// shadowing of the now defined "all" property.
JSObject *tmp = obj, *tmpProto;
while ((tmpProto = ::JS_GetPrototype(cx, tmp)) != helper) {
while ((tmpProto = ::JS_GetPrototype(tmp)) != helper) {
tmp = tmpProto;
}
@ -9225,7 +9213,7 @@ nsHTMLDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
PrintWarningOnConsole(cx, "DocumentAllUsed");
helper = ::JS_NewObject(cx, &sHTMLDocumentAllHelperClass,
::JS_GetPrototype(cx, obj),
::JS_GetPrototype(obj),
::JS_GetGlobalForObject(cx, obj));
if (!helper) {
@ -9243,10 +9231,8 @@ nsHTMLDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
// If we have (or just created) a helper, pass the resolve flags
// to the helper as its private data.
if (helper && !::JS_SetPrivate(cx, helper, FlagsToPrivate(flags))) {
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_UNEXPECTED);
return NS_ERROR_UNEXPECTED;
if (helper) {
::JS_SetPrivate(helper, FlagsToPrivate(flags));
}
}
@ -9791,7 +9777,7 @@ nsHTMLPluginObjElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
{
JSAutoRequest ar(cx);
JSObject *pi_obj = ::JS_GetPrototype(cx, obj);
JSObject *pi_obj = ::JS_GetPrototype(obj);
if (NS_UNLIKELY(!pi_obj)) {
return NS_OK;
}
@ -9820,7 +9806,7 @@ nsHTMLPluginObjElementSH::SetProperty(nsIXPConnectWrappedNative *wrapper,
{
JSAutoRequest ar(cx);
JSObject *pi_obj = ::JS_GetPrototype(cx, obj);
JSObject *pi_obj = ::JS_GetPrototype(obj);
if (NS_UNLIKELY(!pi_obj)) {
return NS_OK;
}
@ -9899,7 +9885,7 @@ nsHTMLPluginObjElementSH::GetPluginJSObject(JSContext *cx, JSObject *obj,
if (plugin_inst) {
plugin_inst->GetJSObject(cx, plugin_obj);
if (*plugin_obj) {
*plugin_proto = ::JS_GetPrototype(cx, *plugin_obj);
*plugin_proto = ::JS_GetPrototype(*plugin_obj);
}
}
@ -10298,7 +10284,7 @@ nsStorageSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
// First check to see if the property is defined on our prototype.
JSObject *proto = ::JS_GetPrototype(cx, realObj);
JSObject *proto = ::JS_GetPrototype(realObj);
JSBool hasProp;
if (proto &&
@ -10484,7 +10470,7 @@ nsStorage2SH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
return JS_FALSE;
}
JSObject *proto = ::JS_GetPrototype(cx, realObj);
JSObject *proto = ::JS_GetPrototype(realObj);
JSBool hasProp;
if (proto &&

Просмотреть файл

@ -1606,7 +1606,7 @@ nsDOMWindowUtils::GetParent(const JS::Value& aObject,
return NS_ERROR_XPC_BAD_CONVERT_JS;
}
JSObject* parent = JS_GetParent(aCx, JSVAL_TO_OBJECT(aObject));
JSObject* parent = JS_GetParent(JSVAL_TO_OBJECT(aObject));
*aParent = OBJECT_TO_JSVAL(parent);
// Outerize if necessary.

Просмотреть файл

@ -1870,7 +1870,7 @@ ReparentWaiverWrappers(JSDHashTable *table, JSDHashEntryHdr *hdr,
// We reparent wrappers that have as their parent an inner window whose
// outer has the new inner window as its current inner.
JSObject *parent = JS_GetParent(closure->mCx, value);
JSObject *parent = JS_GetParent(value);
JSObject *outer = JS_ObjectToOuterObject(closure->mCx, parent);
if (outer) {
JSObject *inner = JS_ObjectToInnerObject(closure->mCx, outer);
@ -9975,7 +9975,7 @@ nsGlobalWindow::SaveWindowState(nsISupports **aState)
getter_AddRefs(proto));
NS_ENSURE_SUCCESS(rv, rv);
JSObject *realProto = JS_GetPrototype(cx, mJSObject);
JSObject *realProto = JS_GetPrototype(mJSObject);
nsCOMPtr<nsIXPConnectJSObjectHolder> realProtoHolder;
if (realProto) {
rv = xpc->HoldObject(cx, realProto, getter_AddRefs(realProtoHolder));

Просмотреть файл

@ -1901,7 +1901,7 @@ nsJSContext::CallEventHandler(nsISupports* aTarget, JSObject* aScope,
JSObject *obj = aHandler;
if (js::IsFunctionProxy(obj))
obj = js::UnwrapObject(obj);
JSString *id = JS_GetFunctionId(static_cast<JSFunction *>(JS_GetPrivate(mContext, obj)));
JSString *id = JS_GetFunctionId(static_cast<JSFunction *>(JS_GetPrivate(obj)));
JSAutoByteString bytes;
const char *name = !id ? "anonymous" : bytes.encode(mContext, id) ? bytes.ptr() : "<error>";
NS_TIME_FUNCTION_FMT(1.0, "%s (line %d) (function: %s)", MOZ_FUNCTION_NAME, __LINE__, name);
@ -2272,8 +2272,8 @@ nsJSContext::ConnectToInner(nsIScriptGlobalObject *aNewInner, JSObject *aOuterGl
// the global object's compartment as its default compartment,
// so update that now since it might have changed.
JS_SetGlobalObject(mContext, aOuterGlobal);
NS_ASSERTION(JS_GetPrototype(mContext, aOuterGlobal) ==
JS_GetPrototype(mContext, newInnerJSObject),
NS_ASSERTION(JS_GetPrototype(aOuterGlobal) ==
JS_GetPrototype(newInnerJSObject),
"outer and inner globals should have the same prototype");
return NS_OK;
@ -2334,7 +2334,7 @@ nsJSContext::SetOuterObject(JSObject* aOuterObject)
JS_SetGlobalObject(mContext, aOuterObject);
// NB: JS_SetGlobalObject sets mContext->compartment.
JSObject *inner = JS_GetParent(mContext, aOuterObject);
JSObject *inner = JS_GetParent(aOuterObject);
nsIXPConnect *xpc = nsContentUtils::XPConnect();
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
@ -2344,7 +2344,7 @@ nsJSContext::SetOuterObject(JSObject* aOuterObject)
NS_ABORT_IF_FALSE(wrapper, "bad wrapper");
wrapper->RefreshPrototype();
JS_SetPrototype(mContext, aOuterObject, JS_GetPrototype(mContext, inner));
JS_SetPrototype(mContext, aOuterObject, JS_GetPrototype(inner));
return NS_OK;
}
@ -3099,8 +3099,8 @@ nsJSContext::ClearScope(void *aGlobalObj, bool aClearFromProtoChain)
nsWindowSH::InvalidateGlobalScopePolluter(mContext, obj);
// Clear up obj's prototype chain, but not Object.prototype.
for (JSObject *o = ::JS_GetPrototype(mContext, obj), *next;
o && (next = ::JS_GetPrototype(mContext, o)); o = next)
for (JSObject *o = ::JS_GetPrototype(obj), *next;
o && (next = ::JS_GetPrototype(o)); o = next)
::JS_ClearScope(mContext, o);
}
}

Просмотреть файл

@ -114,7 +114,7 @@ nsJSUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj)
if (!clazz ||
!(clazz->flags & JSCLASS_HAS_PRIVATE) ||
!(clazz->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS) ||
!(supports = (nsISupports*)::JS_GetPrivate(aContext, glob))) {
!(supports = (nsISupports*)::JS_GetPrivate(glob))) {
return nsnull;
}

Просмотреть файл

@ -1073,7 +1073,7 @@ nsJSObjWrapper::GetNewOrUsed(NPP npp, JSContext *cx, JSObject *obj)
// obj is one of our own, its private data is the NPObject we're
// looking for.
NPObject *npobj = (NPObject *)::JS_GetPrivate(cx, obj);
NPObject *npobj = (NPObject *)::JS_GetPrivate(obj);
if (LookupNPP(npobj) == npp)
return _retainobject(npobj);
@ -1154,17 +1154,17 @@ nsJSObjWrapper::GetNewOrUsed(NPP npp, JSContext *cx, JSObject *obj)
}
static NPObject *
GetNPObject(JSContext *cx, JSObject *obj)
GetNPObject(JSObject *obj)
{
while (obj && JS_GetClass(obj) != &sNPObjectJSWrapperClass) {
obj = ::JS_GetPrototype(cx, obj);
obj = ::JS_GetPrototype(obj);
}
if (!obj) {
return nsnull;
}
return (NPObject *)::JS_GetPrivate(cx, obj);
return (NPObject *)::JS_GetPrivate(obj);
}
@ -1173,7 +1173,7 @@ GetNPObject(JSContext *cx, JSObject *obj)
static JSBool
NPObjWrapper_AddProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
{
NPObject *npobj = GetNPObject(cx, obj);
NPObject *npobj = GetNPObject(obj);
if (!npobj || !npobj->_class || !npobj->_class->hasProperty ||
!npobj->_class->hasMethod) {
@ -1214,7 +1214,7 @@ NPObjWrapper_AddProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
static JSBool
NPObjWrapper_DelProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
{
NPObject *npobj = GetNPObject(cx, obj);
NPObject *npobj = GetNPObject(obj);
if (!npobj || !npobj->_class || !npobj->_class->hasProperty ||
!npobj->_class->removeProperty) {
@ -1245,7 +1245,7 @@ NPObjWrapper_DelProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
static JSBool
NPObjWrapper_SetProperty(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
{
NPObject *npobj = GetNPObject(cx, obj);
NPObject *npobj = GetNPObject(obj);
if (!npobj || !npobj->_class || !npobj->_class->hasProperty ||
!npobj->_class->setProperty) {
@ -1304,7 +1304,7 @@ NPObjWrapper_SetProperty(JSContext *cx, JSObject *obj, jsid id, JSBool strict, j
static JSBool
NPObjWrapper_GetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
{
NPObject *npobj = GetNPObject(cx, obj);
NPObject *npobj = GetNPObject(obj);
if (!npobj || !npobj->_class || !npobj->_class->hasProperty ||
!npobj->_class->hasMethod || !npobj->_class->getProperty) {
@ -1393,7 +1393,7 @@ CallNPMethodInternal(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval, bool ctorCall)
{
while (obj && JS_GetClass(obj) != &sNPObjectJSWrapperClass) {
obj = ::JS_GetPrototype(cx, obj);
obj = ::JS_GetPrototype(obj);
}
if (!obj) {
@ -1402,7 +1402,7 @@ CallNPMethodInternal(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
return JS_FALSE;
}
NPObject *npobj = (NPObject *)::JS_GetPrivate(cx, obj);
NPObject *npobj = (NPObject *)::JS_GetPrivate(obj);
if (!npobj || !npobj->_class) {
ThrowJSException(cx, "Bad NPObject as private data!");
@ -1545,7 +1545,7 @@ static JSBool
NPObjWrapper_newEnumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
jsval *statep, jsid *idp)
{
NPObject *npobj = GetNPObject(cx, obj);
NPObject *npobj = GetNPObject(obj);
NPIdentifier *enum_value;
uint32_t length;
NPObjectEnumerateState *state;
@ -1625,7 +1625,7 @@ static JSBool
NPObjWrapper_NewResolve(JSContext *cx, JSObject *obj, jsid id, uintN flags,
JSObject **objp)
{
NPObject *npobj = GetNPObject(cx, obj);
NPObject *npobj = GetNPObject(obj);
if (!npobj || !npobj->_class || !npobj->_class->hasProperty ||
!npobj->_class->hasMethod) {
@ -1714,7 +1714,7 @@ NPObjWrapper_Convert(JSContext *cx, JSObject *obj, JSType hint, jsval *vp)
static void
NPObjWrapper_Finalize(JSContext *cx, JSObject *obj)
{
NPObject *npobj = (NPObject *)::JS_GetPrivate(cx, obj);
NPObject *npobj = (NPObject *)::JS_GetPrivate(obj);
if (npobj) {
if (sNPObjWrappers.ops) {
PL_DHashTableOperate(&sNPObjWrappers, npobj, PL_DHASH_REMOVE);
@ -1780,11 +1780,7 @@ nsNPObjWrapper::OnDestroy(NPObject *npobj)
// Found a live NPObject wrapper, null out its JSObjects' private
// data.
JSContext *cx = GetJSContext(entry->mNpp);
if (cx) {
::JS_SetPrivate(cx, entry->mJSObj, nsnull);
}
::JS_SetPrivate(entry->mJSObj, nsnull);
// Remove the npobj from the hash now that it went away.
PL_DHashTableRawRemove(&sNPObjWrappers, entry);
@ -1876,8 +1872,7 @@ nsNPObjWrapper::GetNewOrUsed(NPP npp, JSContext *cx, NPObject *npobj)
entry->mJSObj = obj;
// JS_SetPrivate() never fails.
::JS_SetPrivate(cx, obj, npobj);
::JS_SetPrivate(obj, npobj);
// The new JSObject now holds on to npobj
_retainobject(npobj);
@ -1960,10 +1955,7 @@ NPObjWrapperPluginDestroyedCallback(PLDHashTable *table, PLDHashEntryHdr *hdr,
PR_Free(npobj);
}
JSAutoEnterCompartment ac;
if (ac.enter(nppcx->cx, entry->mJSObj)) {
::JS_SetPrivate(nppcx->cx, entry->mJSObj, nsnull);
}
::JS_SetPrivate(entry->mJSObj, nsnull);
table->ops = ops;
@ -2074,10 +2066,10 @@ nsJSNPRuntime::OnPluginDestroy(NPP npp)
// be only one, but remove all instances found in case the page put
// more than one of the plugin's scriptable objects on the prototype
// chain).
while (obj && (proto = ::JS_GetPrototype(cx, obj))) {
while (obj && (proto = ::JS_GetPrototype(obj))) {
if (JS_GetClass(proto) == &sNPObjectJSWrapperClass) {
// We found an NPObject on the proto chain, get its prototype...
proto = ::JS_GetPrototype(cx, proto);
proto = ::JS_GetPrototype(proto);
// ... and pull it out of the chain.
::JS_SetPrototype(cx, obj, proto);
@ -2140,7 +2132,7 @@ CreateNPObjectMember(NPP npp, JSContext *cx, JSObject *obj, NPObject* npobj,
*vp = OBJECT_TO_JSVAL(memobj);
::JS_AddValueRoot(cx, vp);
::JS_SetPrivate(cx, memobj, (void *)memberPrivate);
::JS_SetPrivate(memobj, (void *)memberPrivate);
NPIdentifier identifier = JSIdToNPIdentifier(id);
@ -2173,7 +2165,7 @@ CreateNPObjectMember(NPP npp, JSContext *cx, JSObject *obj, NPObject* npobj,
// outlive the underlying NPObject, so make sure it points to the
// real JSObject wrapper for the NPObject.
while (JS_GetClass(obj) != &sNPObjectJSWrapperClass) {
obj = ::JS_GetPrototype(cx, obj);
obj = ::JS_GetPrototype(obj);
}
memberPrivate->npobjWrapper = obj;
@ -2226,7 +2218,7 @@ NPObjectMember_Finalize(JSContext *cx, JSObject *obj)
{
NPObjectMemberPrivate *memberPrivate;
memberPrivate = (NPObjectMemberPrivate *)::JS_GetPrivate(cx, obj);
memberPrivate = (NPObjectMemberPrivate *)::JS_GetPrivate(obj);
if (!memberPrivate)
return;
@ -2246,7 +2238,7 @@ NPObjectMember_Call(JSContext *cx, uintN argc, jsval *vp)
if (!memberPrivate || !memberPrivate->npobjWrapper)
return JS_FALSE;
NPObject *npobj = GetNPObject(cx, memberPrivate->npobjWrapper);
NPObject *npobj = GetNPObject(memberPrivate->npobjWrapper);
if (!npobj) {
ThrowJSException(cx, "Call on invalid member object");
@ -2319,7 +2311,7 @@ static void
NPObjectMember_Trace(JSTracer *trc, JSObject *obj)
{
NPObjectMemberPrivate *memberPrivate =
(NPObjectMemberPrivate *)::JS_GetPrivate(trc->context, obj);
(NPObjectMemberPrivate *)::JS_GetPrivate(obj);
if (!memberPrivate)
return;

Просмотреть файл

@ -94,12 +94,13 @@ CTypesLazyGetter(JSContext* aCx, JSObject* aObj, jsid aId, jsval* aVp)
}
jsval ctypes;
return JS_DeletePropertyById(aCx, aObj, aId) &&
JS_InitCTypesClass(aCx, aObj) &&
JS_GetPropertyById(aCx, aObj, aId, &ctypes) &&
JS_SetCTypesCallbacks(aCx, JSVAL_TO_OBJECT(ctypes),
&gCTypesCallbacks) &&
JS_GetPropertyById(aCx, aObj, aId, aVp);
if (!JS_DeletePropertyById(aCx, aObj, aId) ||
!JS_InitCTypesClass(aCx, aObj) ||
!JS_GetPropertyById(aCx, aObj, aId, &ctypes)) {
return false;
}
JS_SetCTypesCallbacks(JSVAL_TO_OBJECT(ctypes), &gCTypesCallbacks);
return JS_GetPropertyById(aCx, aObj, aId, aVp);
}
#endif

Просмотреть файл

@ -85,9 +85,9 @@ EnsureObjectIsEventTarget(JSContext* aCx, JSObject* aObj, char* aFunctionName)
inline
EventTarget*
GetPrivate(JSContext* aCx, JSObject* aObj)
GetPrivate(JSObject* aObj)
{
return GetJSPrivateSafeish<EventTarget>(aCx, aObj);
return GetJSPrivateSafeish<EventTarget>(aObj);
}
JSBool
@ -149,9 +149,9 @@ EventTarget::SetEventListenerOnEventTarget(JSContext* aCx, const char* aType,
// static
EventTarget*
EventTarget::FromJSObject(JSContext* aCx, JSObject* aObj)
EventTarget::FromJSObject(JSObject* aObj)
{
return GetPrivate(aCx, aObj);
return GetPrivate(aObj);
}
// static
@ -167,7 +167,7 @@ EventTarget::AddEventListener(JSContext* aCx, uintN aArgc, jsval* aVp)
return false;
}
EventTarget* self = GetPrivate(aCx, obj);
EventTarget* self = GetPrivate(obj);
if (!self) {
return true;
}
@ -202,7 +202,7 @@ EventTarget::RemoveEventListener(JSContext* aCx, uintN aArgc, jsval* aVp)
return false;
}
EventTarget* self = GetPrivate(aCx, obj);
EventTarget* self = GetPrivate(obj);
if (!self) {
return true;
}
@ -237,7 +237,7 @@ EventTarget::DispatchEvent(JSContext* aCx, uintN aArgc, jsval* aVp)
return false;
}
EventTarget* self = GetPrivate(aCx, obj);
EventTarget* self = GetPrivate(obj);
if (!self) {
return true;
}

Просмотреть файл

@ -77,7 +77,7 @@ protected:
public:
static EventTarget*
FromJSObject(JSContext* aCx, JSObject* aObj);
FromJSObject(JSObject* aObj);
static JSBool
AddEventListener(JSContext* aCx, uintN aArgc, jsval* aVp);

Просмотреть файл

@ -128,50 +128,41 @@ public:
JSObject* obj = JS_NewObject(aCx, clasp, NULL, aParent);
if (obj) {
Event* priv = new Event();
if (!SetJSPrivateSafeish(aCx, obj, priv) ||
!InitEventCommon(aCx, obj, priv, aType, aBubbles, aCancelable,
true)) {
SetJSPrivateSafeish(aCx, obj, NULL);
delete priv;
return NULL;
}
SetJSPrivateSafeish(obj, priv);
InitEventCommon(obj, priv, aType, aBubbles, aCancelable, true);
}
return obj;
}
static bool
IsSupportedClass(JSContext* aCx, JSObject* aEvent)
IsSupportedClass(JSObject* aEvent)
{
return !!GetPrivate(aCx, aEvent);
return !!GetPrivate(aEvent);
}
static bool
SetTarget(JSContext* aCx, JSObject* aEvent, JSObject* aTarget)
static void
SetTarget(JSObject* aEvent, JSObject* aTarget)
{
JS_ASSERT(IsSupportedClass(aCx, aEvent));
JS_ASSERT(IsSupportedClass(aEvent));
jsval target = OBJECT_TO_JSVAL(aTarget);
return JS_SetReservedSlot(aCx, aEvent, SLOT_target, target) &&
JS_SetReservedSlot(aCx, aEvent, SLOT_currentTarget, target);
JS_SetReservedSlot(aEvent, SLOT_target, target);
JS_SetReservedSlot(aEvent, SLOT_currentTarget, target);
}
static bool
WasCanceled(JSContext* aCx, JSObject* aEvent)
WasCanceled(JSObject* aEvent)
{
JS_ASSERT(IsSupportedClass(aCx, aEvent));
jsval canceled;
if (!GetPropertyCommon(aCx, aEvent, SLOT_defaultPrevented, &canceled)) {
return false;
}
JS_ASSERT(IsSupportedClass(aEvent));
jsval canceled = JS_GetReservedSlot(aEvent, SLOT_defaultPrevented);
return JSVAL_TO_BOOLEAN(canceled);
}
static bool
ImmediatePropagationStopped(JSContext* aCx, JSObject* aEvent)
ImmediatePropagationStopped(JSObject* aEvent)
{
Event* event = GetPrivate(aCx, aEvent);
Event* event = GetPrivate(aEvent);
return event ? event->mStopImmediatePropagationCalled : false;
}
@ -209,12 +200,12 @@ protected:
};
static Event*
GetPrivate(JSContext* aCx, JSObject* aEvent);
GetPrivate(JSObject* aEvent);
static Event*
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName)
{
Event* priv = GetPrivate(aCx, aObj);
Event* priv = GetPrivate(aObj);
if (priv) {
return priv;
}
@ -224,43 +215,25 @@ protected:
return NULL;
}
static JSBool
InitEventCommon(JSContext* aCx, JSObject* aObj, Event* aEvent,
JSString* aType, JSBool aBubbles, JSBool aCancelable,
bool aIsTrusted)
static void
InitEventCommon(JSObject* aObj, Event* aEvent, JSString* aType,
JSBool aBubbles, JSBool aCancelable, bool aIsTrusted)
{
aEvent->mStopPropagationCalled = false;
aEvent->mStopImmediatePropagationCalled = false;
jsval now;
if (!JS_NewNumberValue(aCx, JS_Now(), &now)) {
return false;
}
if (!JS_SetReservedSlot(aCx, aObj, SLOT_type, STRING_TO_JSVAL(aType)) ||
!JS_SetReservedSlot(aCx, aObj, SLOT_target, JSVAL_NULL) ||
!JS_SetReservedSlot(aCx, aObj, SLOT_currentTarget, JSVAL_NULL) ||
!JS_SetReservedSlot(aCx, aObj, SLOT_eventPhase,
INT_TO_JSVAL(CAPTURING_PHASE)) ||
!JS_SetReservedSlot(aCx, aObj, SLOT_bubbles,
aBubbles ? JSVAL_TRUE : JSVAL_FALSE) ||
!JS_SetReservedSlot(aCx, aObj, SLOT_cancelable,
aCancelable ? JSVAL_TRUE : JSVAL_FALSE) ||
!JS_SetReservedSlot(aCx, aObj, SLOT_timeStamp, now) ||
!JS_SetReservedSlot(aCx, aObj, SLOT_defaultPrevented, JSVAL_FALSE) ||
!JS_SetReservedSlot(aCx, aObj, SLOT_isTrusted,
aIsTrusted ? JSVAL_TRUE : JSVAL_FALSE)) {
return false;
}
return true;
}
static JSBool
GetPropertyCommon(JSContext* aCx, JSObject* aObj, int32 aSlot, jsval* aVp)
{
JS_ASSERT(aSlot >= 0 && aSlot < SLOT_COUNT);
return JS_GetReservedSlot(aCx, aObj, aSlot, aVp);
JS_SetReservedSlot(aObj, SLOT_type, STRING_TO_JSVAL(aType));
JS_SetReservedSlot(aObj, SLOT_target, JSVAL_NULL);
JS_SetReservedSlot(aObj, SLOT_currentTarget, JSVAL_NULL);
JS_SetReservedSlot(aObj, SLOT_eventPhase, INT_TO_JSVAL(CAPTURING_PHASE));
JS_SetReservedSlot(aObj, SLOT_bubbles,
aBubbles ? JSVAL_TRUE : JSVAL_FALSE);
JS_SetReservedSlot(aObj, SLOT_cancelable,
aCancelable ? JSVAL_TRUE : JSVAL_FALSE);
JS_SetReservedSlot(aObj, SLOT_timeStamp, JS::NumberValue(double(JS_Now())));
JS_SetReservedSlot(aObj, SLOT_defaultPrevented, JSVAL_FALSE);
JS_SetReservedSlot(aObj, SLOT_isTrusted,
aIsTrusted ? JSVAL_TRUE : JSVAL_FALSE);
}
private:
@ -276,7 +249,7 @@ private:
Finalize(JSContext* aCx, JSObject* aObj)
{
JS_ASSERT(IsThisClass(JS_GetClass(aObj)));
delete GetJSPrivateSafeish<Event>(aCx, aObj);
delete GetJSPrivateSafeish<Event>(aObj);
}
static JSBool
@ -291,7 +264,8 @@ private:
return false;
}
return GetPropertyCommon(aCx, aObj, slot, aVp);
*aVp = JS_GetReservedSlot(aObj, slot);
return true;
}
static JSBool
@ -354,14 +328,11 @@ private:
return false;
}
jsval cancelableVal;
if (!GetPropertyCommon(aCx, obj, SLOT_cancelable, &cancelableVal)) {
return false;
}
jsval cancelableVal = JS_GetReservedSlot(obj, SLOT_cancelable);
return JSVAL_TO_BOOLEAN(cancelableVal) ?
JS_SetReservedSlot(aCx, obj, SLOT_defaultPrevented, cancelableVal) :
true;
if (JSVAL_TO_BOOLEAN(cancelableVal))
JS_SetReservedSlot(obj, SLOT_defaultPrevented, cancelableVal);
return true;
}
static JSBool
@ -384,7 +355,8 @@ private:
return false;
}
return InitEventCommon(aCx, obj, event, type, bubbles, cancelable, false);
InitEventCommon(obj, event, type, bubbles, cancelable, false);
return true;
}
};
@ -486,14 +458,9 @@ public:
}
MessageEvent* priv = new MessageEvent(aMainRuntime);
if (!SetJSPrivateSafeish(aCx, obj, priv) ||
!InitMessageEventCommon(aCx, obj, priv, type, false, false, NULL, NULL,
NULL, true)) {
SetJSPrivateSafeish(aCx, obj, NULL);
delete priv;
return NULL;
}
SetJSPrivateSafeish(obj, priv);
InitMessageEventCommon(aCx, obj, priv, type, false, false, NULL, NULL, NULL,
true);
aData.steal(&priv->mData, &priv->mDataByteCount);
priv->mClonedObjects.SwapElements(aClonedObjects);
@ -528,7 +495,7 @@ private:
{
JSClass* classPtr = JS_GetClass(aObj);
if (IsThisClass(classPtr)) {
return GetJSPrivateSafeish<MessageEvent>(aCx, aObj);
return GetJSPrivateSafeish<MessageEvent>(aObj);
}
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
@ -537,7 +504,7 @@ private:
return NULL;
}
static JSBool
static void
InitMessageEventCommon(JSContext* aCx, JSObject* aObj, Event* aEvent,
JSString* aType, JSBool aBubbles, JSBool aCancelable,
JSString* aData, JSString* aOrigin, JSObject* aSource,
@ -545,16 +512,13 @@ private:
{
jsval emptyString = JS_GetEmptyStringValue(aCx);
if (!Event::InitEventCommon(aCx, aObj, aEvent, aType, aBubbles,
aCancelable, aIsTrusted) ||
!JS_SetReservedSlot(aCx, aObj, SLOT_data,
aData ? STRING_TO_JSVAL(aData) : emptyString) ||
!JS_SetReservedSlot(aCx, aObj, SLOT_origin,
aOrigin ? STRING_TO_JSVAL(aOrigin) : emptyString) ||
!JS_SetReservedSlot(aCx, aObj, SLOT_source, OBJECT_TO_JSVAL(aSource))) {
return false;
}
return true;
Event::InitEventCommon(aObj, aEvent, aType, aBubbles, aCancelable,
aIsTrusted);
JS_SetReservedSlot(aObj, SLOT_data,
aData ? STRING_TO_JSVAL(aData) : emptyString);
JS_SetReservedSlot(aObj, SLOT_origin,
aOrigin ? STRING_TO_JSVAL(aOrigin) : emptyString);
JS_SetReservedSlot(aObj, SLOT_source, OBJECT_TO_JSVAL(aSource));
}
static JSBool
@ -569,7 +533,7 @@ private:
Finalize(JSContext* aCx, JSObject* aObj)
{
JS_ASSERT(IsThisClass(JS_GetClass(aObj)));
MessageEvent* priv = GetJSPrivateSafeish<MessageEvent>(aCx, aObj);
MessageEvent* priv = GetJSPrivateSafeish<MessageEvent>(aObj);
if (priv) {
JS_free(aCx, priv->mData);
#ifdef DEBUG
@ -609,16 +573,17 @@ private:
jsval data;
if (!buffer.read(aCx, &data,
WorkerStructuredCloneCallbacks(event->mMainRuntime)) ||
!JS_SetReservedSlot(aCx, aObj, slot, data)) {
WorkerStructuredCloneCallbacks(event->mMainRuntime))) {
return false;
}
JS_SetReservedSlot(aObj, slot, data);
*aVp = data;
return true;
}
return JS_GetReservedSlot(aCx, aObj, slot, aVp);
*aVp = JS_GetReservedSlot(aObj, slot);
return true;
}
static JSBool
@ -642,8 +607,9 @@ private:
return false;
}
return InitMessageEventCommon(aCx, obj, event, type, bubbles, cancelable,
data, origin, source, false);
InitMessageEventCommon(aCx, obj, event, type, bubbles, cancelable,
data, origin, source, false);
return true;
}
};
@ -717,13 +683,9 @@ public:
}
ErrorEvent* priv = new ErrorEvent();
if (!SetJSPrivateSafeish(aCx, obj, priv) ||
!InitErrorEventCommon(aCx, obj, priv, type, false, true, aMessage,
aFilename, aLineNumber, true)) {
SetJSPrivateSafeish(aCx, obj, NULL);
delete priv;
return NULL;
}
SetJSPrivateSafeish(obj, priv);
InitErrorEventCommon(obj, priv, type, false, true, aMessage, aFilename,
aLineNumber, true);
return obj;
}
@ -753,7 +715,7 @@ private:
{
JSClass* classPtr = JS_GetClass(aObj);
if (IsThisClass(classPtr)) {
return GetJSPrivateSafeish<ErrorEvent>(aCx, aObj);
return GetJSPrivateSafeish<ErrorEvent>(aObj);
}
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
@ -762,23 +724,17 @@ private:
return NULL;
}
static JSBool
InitErrorEventCommon(JSContext* aCx, JSObject* aObj, Event* aEvent,
JSString* aType, JSBool aBubbles, JSBool aCancelable,
static void
InitErrorEventCommon(JSObject* aObj, Event* aEvent, JSString* aType,
JSBool aBubbles, JSBool aCancelable,
JSString* aMessage, JSString* aFilename,
uint32 aLineNumber, bool aIsTrusted)
{
if (!Event::InitEventCommon(aCx, aObj, aEvent, aType, aBubbles,
aCancelable, aIsTrusted) ||
!JS_SetReservedSlot(aCx, aObj, SLOT_message,
STRING_TO_JSVAL(aMessage)) ||
!JS_SetReservedSlot(aCx, aObj, SLOT_filename,
STRING_TO_JSVAL(aFilename)) ||
!JS_SetReservedSlot(aCx, aObj, SLOT_lineno,
INT_TO_JSVAL(aLineNumber))) {
return false;
}
return true;
Event::InitEventCommon(aObj, aEvent, aType, aBubbles, aCancelable,
aIsTrusted);
JS_SetReservedSlot(aObj, SLOT_message, STRING_TO_JSVAL(aMessage));
JS_SetReservedSlot(aObj, SLOT_filename, STRING_TO_JSVAL(aFilename));
JS_SetReservedSlot(aObj, SLOT_lineno, INT_TO_JSVAL(aLineNumber));
}
static JSBool
@ -793,7 +749,7 @@ private:
Finalize(JSContext* aCx, JSObject* aObj)
{
JS_ASSERT(IsThisClass(JS_GetClass(aObj)));
delete GetJSPrivateSafeish<ErrorEvent>(aCx, aObj);
delete GetJSPrivateSafeish<ErrorEvent>(aObj);
}
static JSBool
@ -811,7 +767,8 @@ private:
return false;
}
return JS_GetReservedSlot(aCx, aObj, slot, aVp);
*aVp = JS_GetReservedSlot(aObj, slot);
return true;
}
static JSBool
@ -836,8 +793,9 @@ private:
return false;
}
return InitErrorEventCommon(aCx, obj, event, type, bubbles, cancelable,
message, filename, lineNumber, false);
InitErrorEventCommon(obj, event, type, bubbles, cancelable, message,
filename, lineNumber, false);
return true;
}
};
@ -905,13 +863,9 @@ public:
}
ProgressEvent* priv = new ProgressEvent();
if (!SetJSPrivateSafeish(aCx, obj, priv) ||
!InitProgressEventCommon(aCx, obj, priv, type, false, false,
aLengthComputable, aLoaded, aTotal, true)) {
SetJSPrivateSafeish(aCx, obj, NULL);
delete priv;
return NULL;
}
SetJSPrivateSafeish(obj, priv);
InitProgressEventCommon(obj, priv, type, false, false, aLengthComputable,
aLoaded, aTotal, true);
return obj;
}
@ -941,7 +895,7 @@ private:
{
JSClass* classPtr = JS_GetClass(aObj);
if (classPtr == &sClass) {
return GetJSPrivateSafeish<ProgressEvent>(aCx, aObj);
return GetJSPrivateSafeish<ProgressEvent>(aObj);
}
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
@ -950,21 +904,18 @@ private:
return NULL;
}
static JSBool
InitProgressEventCommon(JSContext* aCx, JSObject* aObj, Event* aEvent,
JSString* aType, JSBool aBubbles, JSBool aCancelable,
static void
InitProgressEventCommon(JSObject* aObj, Event* aEvent, JSString* aType,
JSBool aBubbles, JSBool aCancelable,
JSBool aLengthComputable, jsdouble aLoaded,
jsdouble aTotal, bool aIsTrusted)
{
if (!Event::InitEventCommon(aCx, aObj, aEvent, aType, aBubbles,
aCancelable, aIsTrusted) ||
!JS_SetReservedSlot(aCx, aObj, SLOT_lengthComputable,
aLengthComputable ? JSVAL_TRUE : JSVAL_FALSE) ||
!JS_SetReservedSlot(aCx, aObj, SLOT_loaded, DOUBLE_TO_JSVAL(aLoaded)) ||
!JS_SetReservedSlot(aCx, aObj, SLOT_total, DOUBLE_TO_JSVAL(aTotal))) {
return false;
}
return true;
Event::InitEventCommon(aObj, aEvent, aType, aBubbles, aCancelable,
aIsTrusted);
JS_SetReservedSlot(aObj, SLOT_lengthComputable,
aLengthComputable ? JSVAL_TRUE : JSVAL_FALSE);
JS_SetReservedSlot(aObj, SLOT_loaded, DOUBLE_TO_JSVAL(aLoaded));
JS_SetReservedSlot(aObj, SLOT_total, DOUBLE_TO_JSVAL(aTotal));
}
static JSBool
@ -979,7 +930,7 @@ private:
Finalize(JSContext* aCx, JSObject* aObj)
{
JS_ASSERT(JS_GetClass(aObj) == &sClass);
delete GetJSPrivateSafeish<ProgressEvent>(aCx, aObj);
delete GetJSPrivateSafeish<ProgressEvent>(aObj);
}
static JSBool
@ -997,7 +948,8 @@ private:
return false;
}
return JS_GetReservedSlot(aCx, aObj, slot, aVp);
*aVp = JS_GetReservedSlot(aObj, slot);
return true;
}
static JSBool
@ -1022,8 +974,9 @@ private:
return false;
}
return InitProgressEventCommon(aCx, obj, event, type, bubbles, cancelable,
lengthComputable, loaded, total, false);
InitProgressEventCommon(obj, event, type, bubbles, cancelable,
lengthComputable, loaded, total, false);
return true;
}
};
@ -1051,7 +1004,7 @@ JSFunctionSpec ProgressEvent::sFunctions[] = {
};
Event*
Event::GetPrivate(JSContext* aCx, JSObject* aObj)
Event::GetPrivate(JSObject* aObj)
{
if (aObj) {
JSClass* classPtr = JS_GetClass(aObj);
@ -1059,7 +1012,7 @@ Event::GetPrivate(JSContext* aCx, JSObject* aObj)
MessageEvent::IsThisClass(classPtr) ||
ErrorEvent::IsThisClass(classPtr) ||
classPtr == ProgressEvent::Class()) {
return GetJSPrivateSafeish<Event>(aCx, aObj);
return GetJSPrivateSafeish<Event>(aObj);
}
}
return NULL;
@ -1120,27 +1073,27 @@ CreateProgressEvent(JSContext* aCx, JSString* aType, bool aLengthComputable,
}
bool
IsSupportedEventClass(JSContext* aCx, JSObject* aEvent)
IsSupportedEventClass(JSObject* aEvent)
{
return Event::IsSupportedClass(aCx, aEvent);
return Event::IsSupportedClass(aEvent);
}
void
SetEventTarget(JSObject* aEvent, JSObject* aTarget)
{
Event::SetTarget(aEvent, aTarget);
}
bool
SetEventTarget(JSContext* aCx, JSObject* aEvent, JSObject* aTarget)
EventWasCanceled(JSObject* aEvent)
{
return Event::SetTarget(aCx, aEvent, aTarget);
return Event::WasCanceled(aEvent);
}
bool
EventWasCanceled(JSContext* aCx, JSObject* aEvent)
EventImmediatePropagationStopped(JSObject* aEvent)
{
return Event::WasCanceled(aCx, aEvent);
}
bool
EventImmediatePropagationStopped(JSContext* aCx, JSObject* aEvent)
{
return Event::ImmediatePropagationStopped(aCx, aEvent);
return Event::ImmediatePropagationStopped(aEvent);
}
bool

Просмотреть файл

@ -72,16 +72,16 @@ CreateProgressEvent(JSContext* aCx, JSString* aType, bool aLengthComputable,
jsdouble aLoaded, jsdouble aTotal);
bool
IsSupportedEventClass(JSContext* aCx, JSObject* aEvent);
IsSupportedEventClass(JSObject* aEvent);
void
SetEventTarget(JSObject* aEvent, JSObject* aTarget);
bool
SetEventTarget(JSContext* aCx, JSObject* aEvent, JSObject* aTarget);
EventWasCanceled(JSObject* aEvent);
bool
EventWasCanceled(JSContext* aCx, JSObject* aEvent);
bool
EventImmediatePropagationStopped(JSContext* aCx, JSObject* aEvent);
EventImmediatePropagationStopped(JSObject* aEvent);
bool
DispatchEventToTarget(JSContext* aCx, JSObject* aTarget, JSObject* aEvent,

Просмотреть файл

@ -114,7 +114,7 @@ private:
Finalize(JSContext* aCx, JSObject* aObj)
{
JS_ASSERT(JS_GetClass(aObj) == &sClass);
delete GetJSPrivateSafeish<DOMException>(aCx, aObj);
delete GetJSPrivateSafeish<DOMException>(aObj);
}
static JSBool
@ -141,11 +141,7 @@ private:
return false;
}
jsval name;
if (!JS_GetReservedSlot(aCx, obj, SLOT_name, &name)) {
return false;
}
jsval name = JS_GetReservedSlot(obj, SLOT_name);
JS_ASSERT(JSVAL_IS_STRING(name));
JSString* out = JS_ConcatStrings(aCx, classString, JSVAL_TO_STRING(name));
@ -166,14 +162,15 @@ private:
JSClass* classPtr = JS_GetClass(aObj);
if (classPtr != &sClass || !GetJSPrivateSafeish<DOMException>(aCx, aObj)) {
if (classPtr != &sClass || !GetJSPrivateSafeish<DOMException>(aObj)) {
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO, sClass.name,
sProperties[slot].name, classPtr->name);
return false;
}
return JS_GetReservedSlot(aCx, aObj, slot, aVp);
*aVp = JS_GetReservedSlot(aObj, slot);
return true;
}
static JSBool
@ -269,16 +266,11 @@ DOMException::Create(JSContext* aCx, intN aCode)
return NULL;
}
if (!JS_SetReservedSlot(aCx, obj, SLOT_code, INT_TO_JSVAL(aCode)) ||
!JS_SetReservedSlot(aCx, obj, SLOT_name, STRING_TO_JSVAL(name))) {
return NULL;
}
JS_SetReservedSlot(obj, SLOT_code, INT_TO_JSVAL(aCode));
JS_SetReservedSlot(obj, SLOT_name, STRING_TO_JSVAL(name));
DOMException* priv = new DOMException();
if (!SetJSPrivateSafeish(aCx, obj, priv)) {
delete priv;
return NULL;
}
SetJSPrivateSafeish(obj, priv);
return obj;
}
@ -330,7 +322,7 @@ private:
Finalize(JSContext* aCx, JSObject* aObj)
{
JS_ASSERT(JS_GetClass(aObj) == &sClass);
delete GetJSPrivateSafeish<FileException>(aCx, aObj);
delete GetJSPrivateSafeish<FileException>(aObj);
}
static JSBool
@ -342,14 +334,15 @@ private:
JSClass* classPtr = JS_GetClass(aObj);
if (classPtr != &sClass || !GetJSPrivateSafeish<FileException>(aCx, aObj)) {
if (classPtr != &sClass || !GetJSPrivateSafeish<FileException>(aObj)) {
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO, sClass.name,
sProperties[slot].name, classPtr->name);
return false;
}
return JS_GetReservedSlot(aCx, aObj, slot, aVp);
*aVp = JS_GetReservedSlot(aObj, slot);
return true;
}
static JSBool
@ -415,16 +408,11 @@ FileException::Create(JSContext* aCx, intN aCode)
return NULL;
}
if (!JS_SetReservedSlot(aCx, obj, SLOT_code, INT_TO_JSVAL(aCode)) ||
!JS_SetReservedSlot(aCx, obj, SLOT_name, STRING_TO_JSVAL(name))) {
return NULL;
}
JS_SetReservedSlot(obj, SLOT_code, INT_TO_JSVAL(aCode));
JS_SetReservedSlot(obj, SLOT_name, STRING_TO_JSVAL(name));
FileException* priv = new FileException();
if (!SetJSPrivateSafeish(aCx, obj, priv)) {
delete priv;
return NULL;
}
SetJSPrivateSafeish(obj, priv);
return obj;
}

Просмотреть файл

@ -86,22 +86,20 @@ public:
JSObject* obj = JS_NewObject(aCx, &sClass, NULL, NULL);
if (obj) {
if (!JS_SetPrivate(aCx, obj, aBlob)) {
return NULL;
}
JS_SetPrivate(obj, aBlob);
NS_ADDREF(aBlob);
}
return obj;
}
static nsIDOMBlob*
GetPrivate(JSContext* aCx, JSObject* aObj);
GetPrivate(JSObject* aObj);
private:
static nsIDOMBlob*
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName)
{
nsIDOMBlob* blob = GetPrivate(aCx, aObj);
nsIDOMBlob* blob = GetPrivate(aObj);
if (blob) {
return blob;
}
@ -125,7 +123,7 @@ private:
{
JS_ASSERT(JS_GetClass(aObj) == &sClass);
nsIDOMBlob* blob = GetPrivate(aCx, aObj);
nsIDOMBlob* blob = GetPrivate(aObj);
NS_IF_RELEASE(blob);
}
@ -260,21 +258,19 @@ public:
JSObject* obj = JS_NewObject(aCx, &sClass, NULL, NULL);
if (obj) {
if (!JS_SetPrivate(aCx, obj, aFile)) {
return NULL;
}
JS_SetPrivate(obj, aFile);
NS_ADDREF(aFile);
}
return obj;
}
static nsIDOMFile*
GetPrivate(JSContext* aCx, JSObject* aObj)
GetPrivate(JSObject* aObj)
{
if (aObj) {
JSClass* classPtr = JS_GetClass(aObj);
if (classPtr == &sClass) {
nsISupports* priv = static_cast<nsISupports*>(JS_GetPrivate(aCx, aObj));
nsISupports* priv = static_cast<nsISupports*>(JS_GetPrivate(aObj));
nsCOMPtr<nsIDOMFile> file = do_QueryInterface(priv);
JS_ASSERT_IF(priv, file);
return file;
@ -293,7 +289,7 @@ private:
static nsIDOMFile*
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName)
{
nsIDOMFile* file = GetPrivate(aCx, aObj);
nsIDOMFile* file = GetPrivate(aObj);
if (file) {
return file;
}
@ -317,7 +313,7 @@ private:
{
JS_ASSERT(JS_GetClass(aObj) == &sClass);
nsIDOMFile* file = GetPrivate(aCx, aObj);
nsIDOMFile* file = GetPrivate(aObj);
NS_IF_RELEASE(file);
}
@ -386,12 +382,12 @@ JSPropertySpec File::sProperties[] = {
};
nsIDOMBlob*
Blob::GetPrivate(JSContext* aCx, JSObject* aObj)
Blob::GetPrivate(JSObject* aObj)
{
if (aObj) {
JSClass* classPtr = JS_GetClass(aObj);
if (classPtr == &sClass || classPtr == File::Class()) {
nsISupports* priv = static_cast<nsISupports*>(JS_GetPrivate(aCx, aObj));
nsISupports* priv = static_cast<nsISupports*>(JS_GetPrivate(aObj));
nsCOMPtr<nsIDOMBlob> blob = do_QueryInterface(priv);
JS_ASSERT_IF(priv, blob);
return blob;
@ -420,9 +416,9 @@ InitClasses(JSContext* aCx, JSObject* aGlobal)
}
nsIDOMBlob*
GetDOMBlobFromJSObject(JSContext* aCx, JSObject* aObj)
GetDOMBlobFromJSObject(JSObject* aObj)
{
return Blob::GetPrivate(aCx, aObj);
return Blob::GetPrivate(aObj);
}
JSObject*
@ -432,9 +428,9 @@ CreateFile(JSContext* aCx, nsIDOMFile* aFile)
}
nsIDOMFile*
GetDOMFileFromJSObject(JSContext* aCx, JSObject* aObj)
GetDOMFileFromJSObject(JSObject* aObj)
{
return File::GetPrivate(aCx, aObj);
return File::GetPrivate(aObj);
}
} // namespace file

Просмотреть файл

@ -58,13 +58,13 @@ JSObject*
CreateBlob(JSContext* aCx, nsIDOMBlob* aBlob);
nsIDOMBlob*
GetDOMBlobFromJSObject(JSContext* aCx, JSObject* aObj);
GetDOMBlobFromJSObject(JSObject* aObj);
JSObject*
CreateFile(JSContext* aCx, nsIDOMFile* aFile);
nsIDOMFile*
GetDOMFileFromJSObject(JSContext* aCx, JSObject* aObj);
GetDOMFileFromJSObject(JSObject* aObj);
} // namespace file

Просмотреть файл

@ -81,7 +81,7 @@ GetDOMBlobFromJSObject(JSContext* aCx, JSObject* aObj) {
// aObj can be null as JS_ConvertArguments("o") successfully converts JS
// null to a null pointer to JSObject
if (aObj) {
nsIDOMBlob* blob = file::GetDOMBlobFromJSObject(aCx, aObj);
nsIDOMBlob* blob = file::GetDOMBlobFromJSObject(aObj);
if (blob) {
return blob;
}
@ -110,13 +110,13 @@ public:
}
static FileReaderSyncPrivate*
GetPrivate(JSContext* aCx, JSObject* aObj)
GetPrivate(JSObject* aObj)
{
if (aObj) {
JSClass* classPtr = JS_GetClass(aObj);
if (classPtr == &sClass) {
FileReaderSyncPrivate* fileReader =
GetJSPrivateSafeish<FileReaderSyncPrivate>(aCx, aObj);
GetJSPrivateSafeish<FileReaderSyncPrivate>(aObj);
return fileReader;
}
}
@ -127,7 +127,7 @@ private:
static FileReaderSyncPrivate*
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName)
{
FileReaderSyncPrivate* fileReader = GetPrivate(aCx, aObj);
FileReaderSyncPrivate* fileReader = GetPrivate(aObj);
if (fileReader) {
return fileReader;
}
@ -149,10 +149,7 @@ private:
FileReaderSyncPrivate* fileReader = new FileReaderSyncPrivate();
NS_ADDREF(fileReader);
if (!SetJSPrivateSafeish(aCx, obj, fileReader)) {
NS_RELEASE(fileReader);
return false;
}
SetJSPrivateSafeish(obj, fileReader);
JS_SET_RVAL(aCx, aVp, OBJECT_TO_JSVAL(obj));
return true;
@ -163,7 +160,7 @@ private:
{
JS_ASSERT(JS_GetClass(aObj) == &sClass);
FileReaderSyncPrivate* fileReader =
GetJSPrivateSafeish<FileReaderSyncPrivate>(aCx, aObj);
GetJSPrivateSafeish<FileReaderSyncPrivate>(aObj);
NS_IF_RELEASE(fileReader);
}

Просмотреть файл

@ -340,7 +340,7 @@ bool
ListenerManager::DispatchEvent(JSContext* aCx, JSObject* aTarget,
JSObject* aEvent, bool* aPreventDefaultCalled)
{
if (!events::IsSupportedEventClass(aCx, aEvent)) {
if (!events::IsSupportedEventClass(aEvent)) {
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_METHOD,
"EventTarget", "dispatchEvent", "Event object");
@ -407,12 +407,10 @@ ListenerManager::DispatchEvent(JSContext* aCx, JSObject* aTarget,
return true;
}
if (!events::SetEventTarget(aCx, aEvent, aTarget)) {
return false;
}
events::SetEventTarget(aEvent, aTarget);
for (size_t index = 0; index < listeners.length(); index++) {
if (events::EventImmediatePropagationStopped(aCx, aEvent)) {
if (events::EventImmediatePropagationStopped(aEvent)) {
break;
}
@ -462,11 +460,9 @@ ListenerManager::DispatchEvent(JSContext* aCx, JSObject* aTarget,
}
}
if (!events::SetEventTarget(aCx, aEvent, NULL)) {
return false;
}
events::SetEventTarget(aEvent, NULL);
*aPreventDefaultCalled = events::EventWasCanceled(aCx, aEvent);
*aPreventDefaultCalled = events::EventWasCanceled(aEvent);
return true;
}

Просмотреть файл

@ -89,31 +89,25 @@ public:
jsval empty = JS_GetEmptyStringValue(aCx);
if (!JS_SetReservedSlot(aCx, obj, SLOT_href,
aHref ? STRING_TO_JSVAL(aHref) : empty) ||
!JS_SetReservedSlot(aCx, obj, SLOT_protocol,
aProtocol ? STRING_TO_JSVAL(aProtocol) : empty) ||
!JS_SetReservedSlot(aCx, obj, SLOT_host,
aHost ? STRING_TO_JSVAL(aHost) : empty) ||
!JS_SetReservedSlot(aCx, obj, SLOT_hostname,
aHostname ? STRING_TO_JSVAL(aHostname) : empty) ||
!JS_SetReservedSlot(aCx, obj, SLOT_port,
aPort ? STRING_TO_JSVAL(aPort) : empty) ||
!JS_SetReservedSlot(aCx, obj, SLOT_pathname,
aPathname ? STRING_TO_JSVAL(aPathname) : empty) ||
!JS_SetReservedSlot(aCx, obj, SLOT_search,
aSearch ? STRING_TO_JSVAL(aSearch) : empty) ||
!JS_SetReservedSlot(aCx, obj, SLOT_hash,
aHash ? STRING_TO_JSVAL(aHash) : empty)) {
return NULL;
}
JS_SetReservedSlot(obj, SLOT_href,
aHref ? STRING_TO_JSVAL(aHref) : empty);
JS_SetReservedSlot(obj, SLOT_protocol,
aProtocol ? STRING_TO_JSVAL(aProtocol) : empty);
JS_SetReservedSlot(obj, SLOT_host,
aHost ? STRING_TO_JSVAL(aHost) : empty);
JS_SetReservedSlot(obj, SLOT_hostname,
aHostname ? STRING_TO_JSVAL(aHostname) : empty);
JS_SetReservedSlot(obj, SLOT_port,
aPort ? STRING_TO_JSVAL(aPort) : empty);
JS_SetReservedSlot(obj, SLOT_pathname,
aPathname ? STRING_TO_JSVAL(aPathname) : empty);
JS_SetReservedSlot(obj, SLOT_search,
aSearch ? STRING_TO_JSVAL(aSearch) : empty);
JS_SetReservedSlot(obj, SLOT_hash,
aHash ? STRING_TO_JSVAL(aHash) : empty);
Location* priv = new Location();
if (!JS_SetPrivate(aCx, obj, priv)) {
delete priv;
return NULL;
}
JS_SetPrivate(obj, priv);
return obj;
}
@ -141,7 +135,7 @@ private:
Finalize(JSContext* aCx, JSObject* aObj)
{
JS_ASSERT(JS_GetClass(aObj) == &sClass);
delete static_cast<Location*>(JS_GetPrivate(aCx, aObj));
delete static_cast<Location*>(JS_GetPrivate(aObj));
}
static JSBool
@ -160,11 +154,7 @@ private:
return false;
}
jsval href;
if (!JS_GetReservedSlot(aCx, obj, SLOT_href, &href)) {
return false;
}
jsval href = JS_GetReservedSlot(obj, SLOT_href);
JS_SET_RVAL(aCx, aVp, href);
return true;
@ -184,7 +174,8 @@ private:
JS_ASSERT(JSID_IS_INT(aIdval));
JS_ASSERT(JSID_TO_INT(aIdval) >= 0 && JSID_TO_INT(aIdval) < SLOT_COUNT);
return JS_GetReservedSlot(aCx, aObj, JSID_TO_INT(aIdval), aVp);
*aVp = JS_GetReservedSlot(aObj, JSID_TO_INT(aIdval));
return true;
}
};

Просмотреть файл

@ -108,23 +108,17 @@ public:
jsval empty = JS_GetEmptyStringValue(aCx);
if (!JS_SetReservedSlot(aCx, obj, SLOT_appName,
appName ? STRING_TO_JSVAL(appName) : empty) ||
!JS_SetReservedSlot(aCx, obj, SLOT_appVersion,
version ? STRING_TO_JSVAL(version) : empty) ||
!JS_SetReservedSlot(aCx, obj, SLOT_platform,
platform ? STRING_TO_JSVAL(platform) : empty) ||
!JS_SetReservedSlot(aCx, obj, SLOT_userAgent,
userAgent ? STRING_TO_JSVAL(userAgent) : empty)) {
return NULL;
}
JS_SetReservedSlot(obj, SLOT_appName,
appName ? STRING_TO_JSVAL(appName) : empty);
JS_SetReservedSlot(obj, SLOT_appVersion,
version ? STRING_TO_JSVAL(version) : empty);
JS_SetReservedSlot(obj, SLOT_platform,
platform ? STRING_TO_JSVAL(platform) : empty);
JS_SetReservedSlot(obj, SLOT_userAgent,
userAgent ? STRING_TO_JSVAL(userAgent) : empty);
Navigator* priv = new Navigator();
if (!JS_SetPrivate(aCx, obj, priv)) {
delete priv;
return NULL;
}
JS_SetPrivate(obj, priv);
return obj;
}
@ -152,7 +146,7 @@ private:
Finalize(JSContext* aCx, JSObject* aObj)
{
JS_ASSERT(JS_GetClass(aObj) == &sClass);
delete static_cast<Navigator*>(JS_GetPrivate(aCx, aObj));
delete static_cast<Navigator*>(JS_GetPrivate(aObj));
}
static JSBool
@ -169,7 +163,8 @@ private:
JS_ASSERT(JSID_IS_INT(aIdval));
JS_ASSERT(JSID_TO_INT(aIdval) >= 0 && JSID_TO_INT(aIdval) < SLOT_COUNT);
return JS_GetReservedSlot(aCx, aObj, JSID_TO_INT(aIdval), aVp);
*aVp = JS_GetReservedSlot(aObj, JSID_TO_INT(aIdval));
return true;
}
};

Просмотреть файл

@ -116,7 +116,7 @@ public:
{
JS_ASSERT(!JS_IsExceptionPending(aCx));
WorkerPrivate* worker = GetJSPrivateSafeish<WorkerPrivate>(aCx, aObj);
WorkerPrivate* worker = GetJSPrivateSafeish<WorkerPrivate>(aObj);
JS_ASSERT(worker);
if (aSaveEventHandlers) {
@ -131,7 +131,7 @@ public:
}
}
SetJSPrivateSafeish(aCx, aObj, NULL);
SetJSPrivateSafeish(aObj, NULL);
}
static WorkerPrivate*
@ -184,7 +184,7 @@ protected:
}
// Worker now owned by the JS object.
SetJSPrivateSafeish(aCx, obj, worker);
SetJSPrivateSafeish(obj, worker);
if (!runtimeService->RegisterWorker(aCx, worker)) {
return false;
@ -242,7 +242,7 @@ private:
Finalize(JSContext* aCx, JSObject* aObj)
{
JS_ASSERT(JS_GetClass(aObj) == &sClass);
WorkerPrivate* worker = GetJSPrivateSafeish<WorkerPrivate>(aCx, aObj);
WorkerPrivate* worker = GetJSPrivateSafeish<WorkerPrivate>(aObj);
if (worker) {
worker->FinalizeInstance(aCx, true);
}
@ -252,8 +252,7 @@ private:
Trace(JSTracer* aTrc, JSObject* aObj)
{
JS_ASSERT(JS_GetClass(aObj) == &sClass);
WorkerPrivate* worker =
GetJSPrivateSafeish<WorkerPrivate>(aTrc->context, aObj);
WorkerPrivate* worker = GetJSPrivateSafeish<WorkerPrivate>(aObj);
if (worker) {
worker->TraceInstance(aTrc);
}
@ -380,7 +379,7 @@ private:
if (aObj) {
JSClass* classPtr = JS_GetClass(aObj);
if (classPtr == &sClass) {
return GetJSPrivateSafeish<WorkerPrivate>(aCx, aObj);
return GetJSPrivateSafeish<WorkerPrivate>(aObj);
}
}
@ -397,7 +396,7 @@ private:
Finalize(JSContext* aCx, JSObject* aObj)
{
JS_ASSERT(JS_GetClass(aObj) == &sClass);
WorkerPrivate* worker = GetJSPrivateSafeish<WorkerPrivate>(aCx, aObj);
WorkerPrivate* worker = GetJSPrivateSafeish<WorkerPrivate>(aObj);
if (worker) {
worker->FinalizeInstance(aCx, true);
}
@ -407,8 +406,7 @@ private:
Trace(JSTracer* aTrc, JSObject* aObj)
{
JS_ASSERT(JS_GetClass(aObj) == &sClass);
WorkerPrivate* worker =
GetJSPrivateSafeish<WorkerPrivate>(aTrc->context, aObj);
WorkerPrivate* worker = GetJSPrivateSafeish<WorkerPrivate>(aObj);
if (worker) {
worker->TraceInstance(aTrc);
}
@ -429,7 +427,7 @@ Worker::GetInstancePrivate(JSContext* aCx, JSObject* aObj,
{
JSClass* classPtr = JS_GetClass(aObj);
if (classPtr == &sClass || classPtr == ChromeWorker::Class()) {
return GetJSPrivateSafeish<WorkerPrivate>(aCx, aObj);
return GetJSPrivateSafeish<WorkerPrivate>(aObj);
}
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JSMSG_INCOMPATIBLE_PROTO,

Просмотреть файл

@ -39,19 +39,19 @@
BEGIN_WORKERS_NAMESPACE
inline
JSBool
SetJSPrivateSafeish(JSContext* aCx, JSObject* aObj, PrivatizableBase* aBase)
void
SetJSPrivateSafeish(JSObject* aObj, PrivatizableBase* aBase)
{
return JS_SetPrivate(aCx, aObj, aBase);
JS_SetPrivate(aObj, aBase);
}
template <class Derived>
inline
Derived*
GetJSPrivateSafeish(JSContext* aCx, JSObject* aObj)
GetJSPrivateSafeish(JSObject* aObj)
{
return static_cast<Derived*>(
static_cast<PrivatizableBase*>(JS_GetPrivate(aCx, aObj)));
static_cast<PrivatizableBase*>(JS_GetPrivate(aObj)));
}
END_WORKERS_NAMESPACE

Просмотреть файл

@ -338,7 +338,7 @@ struct WorkerStructuredCloneCallbacks
// See if this is a File object.
{
nsIDOMFile* file = file::GetDOMFileFromJSObject(aCx, aObj);
nsIDOMFile* file = file::GetDOMFileFromJSObject(aObj);
if (file) {
if (JS_WriteUint32Pair(aWriter, DOMWORKER_SCTAG_FILE, 0) &&
JS_WriteBytes(aWriter, &file, sizeof(file))) {
@ -350,7 +350,7 @@ struct WorkerStructuredCloneCallbacks
// See if this is a Blob object.
{
nsIDOMBlob* blob = file::GetDOMBlobFromJSObject(aCx, aObj);
nsIDOMBlob* blob = file::GetDOMBlobFromJSObject(aObj);
if (blob) {
nsCOMPtr<nsIMutable> mutableBlob = do_QueryInterface(blob);
if (mutableBlob && NS_SUCCEEDED(mutableBlob->SetMutable(false)) &&

Просмотреть файл

@ -660,14 +660,11 @@ public:
InitPrivate(JSContext* aCx, JSObject* aObj, WorkerPrivate* aWorkerPrivate)
{
JS_ASSERT(JS_GetClass(aObj) == &sClass);
JS_ASSERT(!GetJSPrivateSafeish<DedicatedWorkerGlobalScope>(aCx, aObj));
JS_ASSERT(!GetJSPrivateSafeish<DedicatedWorkerGlobalScope>(aObj));
DedicatedWorkerGlobalScope* priv =
new DedicatedWorkerGlobalScope(aWorkerPrivate);
if (!SetJSPrivateSafeish(aCx, aObj, priv)) {
delete priv;
return false;
}
SetJSPrivateSafeish(aObj, priv);
return true;
}
@ -724,7 +721,7 @@ private:
{
JSClass* classPtr = JS_GetClass(aObj);
if (classPtr == &sClass) {
return GetJSPrivateSafeish<DedicatedWorkerGlobalScope>(aCx, aObj);
return GetJSPrivateSafeish<DedicatedWorkerGlobalScope>(aObj);
}
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
@ -759,7 +756,7 @@ private:
{
JS_ASSERT(JS_GetClass(aObj) == &sClass);
DedicatedWorkerGlobalScope* scope =
GetJSPrivateSafeish<DedicatedWorkerGlobalScope>(aCx, aObj);
GetJSPrivateSafeish<DedicatedWorkerGlobalScope>(aObj);
if (scope) {
scope->FinalizeInstance(aCx);
delete scope;
@ -771,7 +768,7 @@ private:
{
JS_ASSERT(JS_GetClass(aObj) == &sClass);
DedicatedWorkerGlobalScope* scope =
GetJSPrivateSafeish<DedicatedWorkerGlobalScope>(aTrc->context, aObj);
GetJSPrivateSafeish<DedicatedWorkerGlobalScope>(aObj);
if (scope) {
scope->TraceInstance(aTrc);
}
@ -829,7 +826,7 @@ WorkerGlobalScope::GetInstancePrivate(JSContext* aCx, JSObject* aObj,
{
JSClass* classPtr = JS_GetClass(aObj);
if (classPtr == &sClass || classPtr == DedicatedWorkerGlobalScope::Class()) {
return GetJSPrivateSafeish<WorkerGlobalScope>(aCx, aObj);
return GetJSPrivateSafeish<WorkerGlobalScope>(aObj);
}
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JSMSG_INCOMPATIBLE_PROTO,

Просмотреть файл

@ -108,13 +108,9 @@ public:
JSObject* obj = JS_NewObject(aCx, &sClass, NULL, NULL);
if (obj) {
JS_SetReservedSlot(obj, SLOT_xhrParent, OBJECT_TO_JSVAL(aParentObj));
XMLHttpRequestUpload* priv = new XMLHttpRequestUpload();
if (!JS_SetReservedSlot(aCx, obj, SLOT_xhrParent,
OBJECT_TO_JSVAL(aParentObj)) ||
!SetJSPrivateSafeish(aCx, obj, priv)) {
delete priv;
return NULL;
}
SetJSPrivateSafeish(obj, priv);
}
return obj;
}
@ -134,12 +130,12 @@ private:
}
static XMLHttpRequestUpload*
GetPrivate(JSContext* aCx, JSObject* aObj)
GetPrivate(JSObject* aObj)
{
if (aObj) {
JSClass* classPtr = JS_GetClass(aObj);
if (classPtr == &sClass) {
return GetJSPrivateSafeish<XMLHttpRequestUpload>(aCx, aObj);
return GetJSPrivateSafeish<XMLHttpRequestUpload>(aObj);
}
}
return NULL;
@ -148,7 +144,7 @@ private:
static XMLHttpRequestUpload*
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName)
{
XMLHttpRequestUpload* priv = GetPrivate(aCx, aObj);
XMLHttpRequestUpload* priv = GetPrivate(aObj);
if (priv) {
return priv;
}
@ -171,7 +167,7 @@ private:
Finalize(JSContext* aCx, JSObject* aObj)
{
JS_ASSERT(JS_GetClass(aObj) == &sClass);
XMLHttpRequestUpload* priv = GetPrivate(aCx, aObj);
XMLHttpRequestUpload* priv = GetPrivate(aObj);
if (priv) {
priv->FinalizeInstance(aCx);
delete priv;
@ -182,7 +178,7 @@ private:
Trace(JSTracer* aTrc, JSObject* aObj)
{
JS_ASSERT(JS_GetClass(aObj) == &sClass);
XMLHttpRequestUpload* priv = GetPrivate(aTrc->context, aObj);
XMLHttpRequestUpload* priv = GetPrivate(aObj);
if (priv) {
priv->TraceInstance(aTrc);
}
@ -325,13 +321,11 @@ public:
static bool
UpdateState(JSContext* aCx, JSObject* aObj, const xhr::StateData& aNewState)
{
JS_ASSERT(GetPrivate(aCx, aObj));
JS_ASSERT(GetPrivate(aObj));
#define HANDLE_STATE_VALUE(_member, _slot) \
if (aNewState. _member##Exception || !JSVAL_IS_VOID(aNewState. _member)) { \
if (!JS_SetReservedSlot(aCx, aObj, _slot, aNewState. _member)) { \
return false; \
} \
JS_SetReservedSlot(aObj, _slot, aNewState. _member); \
}
HANDLE_STATE_VALUE(mResponseText, SLOT_responseText)
@ -353,12 +347,12 @@ private:
~XMLHttpRequest();
static XMLHttpRequestPrivate*
GetPrivate(JSContext* aCx, JSObject* aObj)
GetPrivate(JSObject* aObj)
{
if (aObj) {
JSClass* classPtr = JS_GetClass(aObj);
if (classPtr == &sClass) {
return GetJSPrivateSafeish<XMLHttpRequestPrivate>(aCx, aObj);
return GetJSPrivateSafeish<XMLHttpRequestPrivate>(aObj);
}
}
return NULL;
@ -367,7 +361,7 @@ private:
static XMLHttpRequestPrivate*
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName)
{
XMLHttpRequestPrivate* priv = GetPrivate(aCx, aObj);
XMLHttpRequestPrivate* priv = GetPrivate(aObj);
if (priv) {
return priv;
}
@ -394,27 +388,21 @@ private:
jsval emptyString = JS_GetEmptyStringValue(aCx);
jsval zero = INT_TO_JSVAL(0);
if (!JS_SetReservedSlot(aCx, obj, SLOT_channel, JSVAL_NULL) ||
!JS_SetReservedSlot(aCx, obj, SLOT_responseXML, JSVAL_NULL) ||
!JS_SetReservedSlot(aCx, obj, SLOT_responseText, emptyString) ||
!JS_SetReservedSlot(aCx, obj, SLOT_status, zero) ||
!JS_SetReservedSlot(aCx, obj, SLOT_statusText, emptyString) ||
!JS_SetReservedSlot(aCx, obj, SLOT_readyState, zero) ||
!JS_SetReservedSlot(aCx, obj, SLOT_multipart, JSVAL_FALSE) ||
!JS_SetReservedSlot(aCx, obj, SLOT_mozBackgroundRequest, JSVAL_FALSE) ||
!JS_SetReservedSlot(aCx, obj, SLOT_withCredentials, JSVAL_FALSE) ||
!JS_SetReservedSlot(aCx, obj, SLOT_upload, JSVAL_NULL) ||
!JS_SetReservedSlot(aCx, obj, SLOT_responseType,
STRING_TO_JSVAL(textStr))) {
return false;
}
JS_SetReservedSlot(obj, SLOT_channel, JSVAL_NULL);
JS_SetReservedSlot(obj, SLOT_responseXML, JSVAL_NULL);
JS_SetReservedSlot(obj, SLOT_responseText, emptyString);
JS_SetReservedSlot(obj, SLOT_status, zero);
JS_SetReservedSlot(obj, SLOT_statusText, emptyString);
JS_SetReservedSlot(obj, SLOT_readyState, zero);
JS_SetReservedSlot(obj, SLOT_multipart, JSVAL_FALSE);
JS_SetReservedSlot(obj, SLOT_mozBackgroundRequest, JSVAL_FALSE);
JS_SetReservedSlot(obj, SLOT_withCredentials, JSVAL_FALSE);
JS_SetReservedSlot(obj, SLOT_upload, JSVAL_NULL);
JS_SetReservedSlot(obj, SLOT_responseType, STRING_TO_JSVAL(textStr));
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
XMLHttpRequestPrivate* priv = new XMLHttpRequestPrivate(obj, workerPrivate);
if (!SetJSPrivateSafeish(aCx, obj, priv)) {
delete priv;
return false;
}
SetJSPrivateSafeish(obj, priv);
JS_SET_RVAL(aCx, aVp, OBJECT_TO_JSVAL(obj));
return true;
@ -424,7 +412,7 @@ private:
Finalize(JSContext* aCx, JSObject* aObj)
{
JS_ASSERT(JS_GetClass(aObj) == &sClass);
XMLHttpRequestPrivate* priv = GetPrivate(aCx, aObj);
XMLHttpRequestPrivate* priv = GetPrivate(aObj);
if (priv) {
priv->FinalizeInstance(aCx);
delete priv;
@ -435,7 +423,7 @@ private:
Trace(JSTracer* aTrc, JSObject* aObj)
{
JS_ASSERT(JS_GetClass(aObj) == &sClass);
XMLHttpRequestPrivate* priv = GetPrivate(aTrc->context, aObj);
XMLHttpRequestPrivate* priv = GetPrivate(aObj);
if (priv) {
priv->TraceInstance(aTrc);
}
@ -453,10 +441,7 @@ private:
return false;
}
jsval rval;
if (!JS_GetReservedSlot(aCx, aObj, slot, &rval)) {
return false;
}
jsval rval = JS_GetReservedSlot(aObj, slot);
if (JSVAL_IS_VOID(rval)) {
// Throw an exception.
@ -492,10 +477,7 @@ private:
return false;
}
jsval uploadVal;
if (!JS_GetReservedSlot(aCx, aObj, slot, &uploadVal)) {
return false;
}
jsval uploadVal = JS_GetReservedSlot(aObj, slot);
if (JSVAL_IS_NULL(uploadVal)) {
JSObject* uploadObj = XMLHttpRequestUpload::Create(aCx, aObj);
@ -505,9 +487,7 @@ private:
uploadVal = OBJECT_TO_JSVAL(uploadObj);
if (!JS_SetReservedSlot(aCx, aObj, slot, uploadVal)) {
return false;
}
JS_SetReservedSlot(aObj, slot, uploadVal);
priv->SetUploadObject(uploadObj);
}
@ -533,16 +513,12 @@ private:
return false; \
} \
\
jsval oldVal; \
if (!JS_GetReservedSlot(aCx, aObj, slot, &oldVal)) { \
return false; \
} \
jsval oldVal = JS_GetReservedSlot(aObj, slot); \
\
jsval rval = *aVp; \
if (!priv->Set##_name (aCx, oldVal, &rval) || \
!JS_SetReservedSlot(aCx, aObj, slot, rval)) { \
if (!priv->Set##_name (aCx, oldVal, &rval)) \
return false; \
} \
JS_SetReservedSlot(aObj, slot, rval); \
\
*aVp = rval; \
return true; \
@ -880,10 +856,7 @@ XMLHttpRequestUpload::UpdateState(JSContext* aCx, JSObject* aObj,
{
JS_ASSERT(JS_GetClass(aObj) == &sClass);
jsval parentVal;
if (!JS_GetReservedSlot(aCx, aObj, SLOT_xhrParent, &parentVal)) {
return false;
}
jsval parentVal = JS_GetReservedSlot(aObj, SLOT_xhrParent);
if (!JSVAL_IS_PRIMITIVE(parentVal)) {
return XMLHttpRequest::UpdateState(aCx, JSVAL_TO_OBJECT(parentVal),

Просмотреть файл

@ -1694,7 +1694,7 @@ XMLHttpRequestPrivate::Send(JSContext* aCx, bool aHasBody, jsval aBody)
bool hasUploadListeners = false;
if (mUploadJSObject) {
events::EventTarget* target =
events::EventTarget::FromJSObject(aCx, mUploadJSObject);
events::EventTarget::FromJSObject(mUploadJSObject);
NS_ASSERTION(target, "This should never be null!");
hasUploadListeners = target->HasListeners();
}
@ -1754,7 +1754,7 @@ XMLHttpRequestPrivate::SendAsBinary(JSContext* aCx, JSString* aBody)
bool hasUploadListeners = false;
if (mUploadJSObject) {
events::EventTarget* target =
events::EventTarget::FromJSObject(aCx, mUploadJSObject);
events::EventTarget::FromJSObject(mUploadJSObject);
NS_ASSERTION(target, "This should never be null!");
hasUploadListeners = target->HasListeners();
}

Просмотреть файл

@ -414,11 +414,11 @@ static void
CPOW_NewEnumerateState_Finalize(JSContext* cx, JSObject* state)
{
nsTArray<nsString>* strIds =
static_cast<nsTArray<nsString>*>(JS_GetPrivate(cx, state));
static_cast<nsTArray<nsString>*>(JS_GetPrivate(state));
if (strIds) {
delete strIds;
JS_SetPrivate(cx, state, NULL);
JS_SetPrivate(state, NULL);
}
}
@ -452,7 +452,7 @@ ObjectWrapperChild::AnswerNewEnumerateInit(/* no in-parameters */
for (JSObject* proto = mObj;
proto;
proto = JS_GetPrototype(cx, proto))
proto = JS_GetPrototype(proto))
{
AutoIdArray ids(cx, JS_Enumerate(cx, proto));
for (size_t i = 0; i < ids.length(); ++i)
@ -474,10 +474,10 @@ ObjectWrapperChild::AnswerNewEnumerateInit(/* no in-parameters */
}
*idp = strIds->Length();
*status = (JS_SetPrivate(cx, state, strIds) &&
JS_SetReservedSlot(cx, state, sNextIdIndexSlot,
JSVAL_ZERO) &&
JSObject_to_JSVariant(cx, state, statep));
JS_SetPrivate(state, strIds);
JS_SetReservedSlot(state, sNextIdIndexSlot, JSVAL_ZERO);
*status = JSObject_to_JSVariant(cx, state, statep);
return true;
}
@ -487,7 +487,6 @@ ObjectWrapperChild::AnswerNewEnumerateNext(const JSVariant& in_state,
OperationStatus* status, JSVariant* statep, nsString* idp)
{
JSObject* state;
jsval v;
*statep = in_state;
idp->Truncate();
@ -500,11 +499,13 @@ ObjectWrapperChild::AnswerNewEnumerateNext(const JSVariant& in_state,
return false;
InfallibleTArray<nsString>* strIds =
static_cast<InfallibleTArray<nsString>*>(JS_GetPrivate(cx, state));
static_cast<InfallibleTArray<nsString>*>(JS_GetPrivate(state));
if (!strIds || !JS_GetReservedSlot(cx, state, sNextIdIndexSlot, &v))
if (!strIds)
return false;
jsval v = JS_GetReservedSlot(state, sNextIdIndexSlot);
jsuint i = JSVAL_TO_INT(v);
NS_ASSERTION(i >= 0, "Index of next jsid negative?");
NS_ASSERTION(i <= strIds->Length(), "Index of next jsid too large?");
@ -515,8 +516,8 @@ ObjectWrapperChild::AnswerNewEnumerateNext(const JSVariant& in_state,
}
*idp = strIds->ElementAt(i);
*status = JS_SetReservedSlot(cx, state, sNextIdIndexSlot,
INT_TO_JSVAL(i + 1));
JS_SetReservedSlot(state, sNextIdIndexSlot, INT_TO_JSVAL(i + 1));
*status = JS_TRUE;
return true;
}

Просмотреть файл

@ -59,47 +59,38 @@ namespace {
class AutoResolveFlag
{
JSContext* mContext;
JSObject* mObj;
uintN mOldFlags;
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
static uintN GetFlags(JSContext* cx, JSObject* obj) {
jsval v;
#ifdef DEBUG
JSBool ok =
#endif
JS_GetReservedSlot(cx, obj, sFlagsSlot, &v);
NS_ASSERTION(ok, "Failed to get CPOW flags");
static uintN GetFlags(JSObject* obj) {
jsval v = JS_GetReservedSlot(obj, sFlagsSlot);
return JSVAL_TO_INT(v);
}
static uintN SetFlags(JSContext* cx, JSObject* obj, uintN flags) {
uintN oldFlags = GetFlags(cx, obj);
static uintN SetFlags(JSObject* obj, uintN flags) {
uintN oldFlags = GetFlags(obj);
if (oldFlags != flags)
JS_SetReservedSlot(cx, obj, sFlagsSlot, INT_TO_JSVAL(flags));
JS_SetReservedSlot(obj, sFlagsSlot, INT_TO_JSVAL(flags));
return oldFlags;
}
public:
AutoResolveFlag(JSContext* cx,
JSObject* obj
AutoResolveFlag(JSObject* obj
JS_GUARD_OBJECT_NOTIFIER_PARAM)
: mContext(cx)
, mObj(obj)
, mOldFlags(SetFlags(cx, obj,
GetFlags(cx, obj) | CPOW_FLAG_RESOLVING))
: mObj(obj)
, mOldFlags(SetFlags(obj, GetFlags(obj) | CPOW_FLAG_RESOLVING))
{
JS_GUARD_OBJECT_NOTIFIER_INIT;
}
~AutoResolveFlag() {
SetFlags(mContext, mObj, mOldFlags);
SetFlags(mObj, mOldFlags);
}
static JSBool IsSet(JSContext* cx, JSObject* obj) {
return GetFlags(cx, obj) & CPOW_FLAG_RESOLVING;
static JSBool IsSet(JSObject* obj) {
return GetFlags(obj) & CPOW_FLAG_RESOLVING;
}
};
@ -201,7 +192,7 @@ void
ObjectWrapperParent::ActorDestroy(ActorDestroyReason)
{
if (mObj) {
JS_SetPrivate(NULL, mObj, NULL);
JS_SetPrivate(mObj, NULL);
mObj = NULL;
}
}
@ -216,25 +207,28 @@ ObjectWrapperParent::Manager()
JSObject*
ObjectWrapperParent::GetJSObject(JSContext* cx) const
{
js::Class *clasp = const_cast<js::Class *>(&ObjectWrapperParent::sCPOW_JSClass);
if (!mObj && (mObj = JS_NewObject(cx, js::Jsvalify(clasp), NULL, NULL))) {
JS_SetPrivate(cx, mObj, (void*)this);
JS_SetReservedSlot(cx, mObj, sFlagsSlot, JSVAL_ZERO);
if (!mObj) {
js::Class *clasp = const_cast<js::Class *>(&ObjectWrapperParent::sCPOW_JSClass);
mObj = JS_NewObject(cx, js::Jsvalify(clasp), NULL, NULL);
if (mObj) {
JS_SetPrivate(mObj, (void*)this);
JS_SetReservedSlot(mObj, sFlagsSlot, JSVAL_ZERO);
}
}
return mObj;
}
static ObjectWrapperParent*
Unwrap(JSContext* cx, JSObject* obj)
Unwrap(JSObject* obj)
{
while (js::GetObjectClass(obj) != &ObjectWrapperParent::sCPOW_JSClass)
if (!(obj = js::GetObjectProto(obj)))
return NULL;
ObjectWrapperParent* self =
static_cast<ObjectWrapperParent*>(JS_GetPrivate(cx, obj));
static_cast<ObjectWrapperParent*>(JS_GetPrivate(obj));
NS_ASSERTION(!self || self->GetJSObject(cx) == obj,
NS_ASSERTION(!self || self->GetJSObjectOrNull() == obj,
"Wrapper and wrapped object disagree?");
return self;
@ -259,7 +253,7 @@ ObjectWrapperParent::jsval_to_JSVariant(JSContext* cx, jsval from,
case JSTYPE_OBJECT:
{
PObjectWrapperParent* powp;
if (!JSObject_to_PObjectWrapperParent(cx, JSVAL_TO_OBJECT(from), &powp))
if (!JSObject_to_PObjectWrapperParent(JSVAL_TO_OBJECT(from), &powp))
return with_error(cx, false, "Cannot pass parent-created object to child");
*to = powp;
}
@ -322,14 +316,13 @@ ObjectWrapperParent::jsval_from_JSVariant(JSContext* cx, const JSVariant& from,
/*static*/ bool
ObjectWrapperParent::
JSObject_to_PObjectWrapperParent(JSContext* cx, JSObject* from,
PObjectWrapperParent** to)
JSObject_to_PObjectWrapperParent(JSObject* from, PObjectWrapperParent** to)
{
if (!from) {
*to = NULL;
return true;
}
ObjectWrapperParent* owp = Unwrap(cx, from);
ObjectWrapperParent* owp = Unwrap(from);
if (!owp)
return false;
*to = owp;
@ -401,11 +394,11 @@ ObjectWrapperParent::CPOW_AddProperty(JSContext *cx, JSObject *obj, jsid id,
CPOW_LOG(("Calling CPOW_AddProperty (%s)...",
JSVAL_TO_CSTR(cx, id)));
ObjectWrapperParent* self = Unwrap(cx, obj);
ObjectWrapperParent* self = Unwrap(obj);
if (!self)
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_AddProperty");
if (AutoResolveFlag::IsSet(cx, obj))
if (AutoResolveFlag::IsSet(obj))
return JS_TRUE;
AutoCheckOperation aco(cx, self);
@ -428,7 +421,7 @@ ObjectWrapperParent::CPOW_GetProperty(JSContext *cx, JSObject *obj, jsid id,
CPOW_LOG(("Calling CPOW_GetProperty (%s)...",
JSVAL_TO_CSTR(cx, id)));
ObjectWrapperParent* self = Unwrap(cx, obj);
ObjectWrapperParent* self = Unwrap(obj);
if (!self)
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_GetProperty");
@ -455,7 +448,7 @@ ObjectWrapperParent::CPOW_SetProperty(JSContext *cx, JSObject *obj, jsid id,
CPOW_LOG(("Calling CPOW_SetProperty (%s)...",
JSVAL_TO_CSTR(cx, id)));
ObjectWrapperParent* self = Unwrap(cx, obj);
ObjectWrapperParent* self = Unwrap(obj);
if (!self)
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_SetProperty");
@ -484,7 +477,7 @@ ObjectWrapperParent::CPOW_DelProperty(JSContext *cx, JSObject *obj, jsid id,
CPOW_LOG(("Calling CPOW_DelProperty (%s)...",
JSVAL_TO_CSTR(cx, id)));
ObjectWrapperParent* self = Unwrap(cx, obj);
ObjectWrapperParent* self = Unwrap(obj);
if (!self)
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_DelProperty");
@ -538,7 +531,7 @@ ObjectWrapperParent::NewEnumerateNext(JSContext* cx, jsval* statep, jsid* idp)
jsid_from_nsString(cx, out_id, idp))
{
JSObject* obj = GetJSObject(cx);
AutoResolveFlag arf(cx, obj);
AutoResolveFlag arf(obj);
return JS_DefinePropertyById(cx, obj, *idp, JSVAL_VOID, NULL, NULL,
JSPROP_ENUMERATE);
}
@ -565,7 +558,7 @@ ObjectWrapperParent::CPOW_NewEnumerate(JSContext *cx, JSObject *obj,
{
CPOW_LOG(("Calling CPOW_NewEnumerate..."));
ObjectWrapperParent* self = Unwrap(cx, obj);
ObjectWrapperParent* self = Unwrap(obj);
if (!self)
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_NewEnumerate");
@ -591,7 +584,7 @@ ObjectWrapperParent::CPOW_NewResolve(JSContext *cx, JSObject *obj, jsid id,
CPOW_LOG(("Calling CPOW_NewResolve (%s)...",
JSVAL_TO_CSTR(cx, id)));
ObjectWrapperParent* self = Unwrap(cx, obj);
ObjectWrapperParent* self = Unwrap(obj);
if (!self)
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_NewResolve");
@ -612,7 +605,7 @@ ObjectWrapperParent::CPOW_NewResolve(JSContext *cx, JSObject *obj, jsid id,
return JS_FALSE;
if (*objp) {
AutoResolveFlag arf(cx, *objp);
AutoResolveFlag arf(*objp);
JS_DefinePropertyById(cx, *objp, id, JSVAL_VOID, NULL, NULL,
JSPROP_ENUMERATE);
}
@ -626,7 +619,7 @@ ObjectWrapperParent::CPOW_Convert(JSContext *cx, JSObject *obj, JSType type,
CPOW_LOG(("Calling CPOW_Convert (to %s)...",
JS_GetTypeName(cx, type)));
ObjectWrapperParent* self = Unwrap(cx, obj);
ObjectWrapperParent* self = Unwrap(obj);
if (!self)
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_Convert");
@ -640,7 +633,7 @@ ObjectWrapperParent::CPOW_Finalize(JSContext* cx, JSObject* obj)
{
CPOW_LOG(("Calling CPOW_Finalize..."));
ObjectWrapperParent* self = Unwrap(cx, obj);
ObjectWrapperParent* self = Unwrap(obj);
if (self) {
self->mObj = NULL;
unused << ObjectWrapperParent::Send__delete__(self);
@ -657,13 +650,13 @@ ObjectWrapperParent::CPOW_Call(JSContext* cx, uintN argc, jsval* vp)
return JS_FALSE;
ObjectWrapperParent* function =
Unwrap(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)));
Unwrap(JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)));
if (!function)
return with_error(cx, JS_FALSE, "Could not unwrap CPOW function");
AutoCheckOperation aco(cx, function);
ObjectWrapperParent* receiver = Unwrap(cx, thisobj);
ObjectWrapperParent* receiver = Unwrap(thisobj);
if (!receiver) {
// Substitute child global for parent global object.
// TODO First make sure we're really replacing the global object?
@ -692,7 +685,7 @@ ObjectWrapperParent::CPOW_Construct(JSContext* cx, uintN argc, jsval* vp)
{
CPOW_LOG(("Calling CPOW_Construct..."));
ObjectWrapperParent* constructor = Unwrap(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)));
ObjectWrapperParent* constructor = Unwrap(JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)));
if (!constructor)
return with_error(cx, JS_FALSE, "Could not unwrap CPOW constructor function");
@ -720,7 +713,7 @@ ObjectWrapperParent::CPOW_HasInstance(JSContext *cx, JSObject *obj, const jsval
*bp = JS_FALSE;
ObjectWrapperParent* self = Unwrap(cx, obj);
ObjectWrapperParent* self = Unwrap(obj);
if (!self)
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_HasInstance");
@ -745,14 +738,14 @@ ObjectWrapperParent::CPOW_Equality(JSContext *cx, JSObject *obj, const jsval *v,
*bp = JS_FALSE;
ObjectWrapperParent* self = Unwrap(cx, obj);
ObjectWrapperParent* self = Unwrap(obj);
if (!self)
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_Equality");
if (JSVAL_IS_PRIMITIVE(*v))
return JS_TRUE;
ObjectWrapperParent* other = Unwrap(cx, JSVAL_TO_OBJECT(*v));
ObjectWrapperParent* other = Unwrap(JSVAL_TO_OBJECT(*v));
if (!other)
return JS_TRUE;

Просмотреть файл

@ -69,6 +69,10 @@ public:
JSObject* GetJSObject(JSContext* cx) const;
JSObject* GetJSObjectOrNull() const {
return mObj;
}
jsval GetJSVal(JSContext* cx) const {
return OBJECT_TO_JSVAL(GetJSObject(cx));
}
@ -133,8 +137,7 @@ private:
static bool jsval_from_JSVariant(JSContext* cx, const JSVariant& from,
jsval* to);
static bool
JSObject_to_PObjectWrapperParent(JSContext* cx, JSObject* from,
PObjectWrapperParent** to);
JSObject_to_PObjectWrapperParent(JSObject* from, PObjectWrapperParent** to);
static bool
JSObject_from_PObjectWrapperParent(JSContext* cx,
const PObjectWrapperParent* from,

Просмотреть файл

@ -706,16 +706,7 @@ jsd_GetValuePrototype(JSDContext* jsdc, JSDValue* jsdval)
return NULL;
if(!(obj = JSVAL_TO_OBJECT(jsdval->val)))
return NULL;
JS_BeginRequest(jsdc->dumbContext);
call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, obj);
if(!call) {
JS_EndRequest(jsdc->dumbContext);
return NULL;
}
proto = JS_GetPrototype(jsdc->dumbContext, obj);
JS_LeaveCrossCompartmentCall(call);
JS_EndRequest(jsdc->dumbContext);
proto = JS_GetPrototype(obj);
if(!proto)
return NULL;
jsdval->proto = jsd_NewValue(jsdc, OBJECT_TO_JSVAL(proto));
@ -775,6 +766,9 @@ jsd_GetValueConstructor(JSDContext* jsdc, JSDValue* jsdval)
return NULL;
if(!(obj = JSVAL_TO_OBJECT(jsdval->val)))
return NULL;
proto = JS_GetPrototype(obj);
if(!proto)
return NULL;
JS_BeginRequest(jsdc->dumbContext);
call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, obj);
if(!call) {
@ -782,13 +776,6 @@ jsd_GetValueConstructor(JSDContext* jsdc, JSDValue* jsdval)
return NULL;
}
proto = JS_GetPrototype(jsdc->dumbContext,obj);
if(!proto)
{
JS_LeaveCrossCompartmentCall(call);
JS_EndRequest(jsdc->dumbContext);
return NULL;
}
ctor = JS_GetConstructor(jsdc->dumbContext,proto);
JS_LeaveCrossCompartmentCall(call);
JS_EndRequest(jsdc->dumbContext);

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -350,7 +350,7 @@ struct ClosureInfo
bool IsCTypesGlobal(JSObject* obj);
JSCTypesCallbacks* GetCallbacks(JSContext* cx, JSObject* obj);
JSCTypesCallbacks* GetCallbacks(JSObject* obj);
JSBool InitTypeClasses(JSContext* cx, JSObject* parent);
@ -456,39 +456,39 @@ namespace CType {
bool IsCType(JSObject* obj);
bool IsCTypeProto(JSObject* obj);
TypeCode GetTypeCode(JSContext* cx, JSObject* typeObj);
bool TypesEqual(JSContext* cx, JSObject* t1, JSObject* t2);
size_t GetSize(JSContext* cx, JSObject* obj);
bool GetSafeSize(JSContext* cx, JSObject* obj, size_t* result);
bool IsSizeDefined(JSContext* cx, JSObject* obj);
size_t GetAlignment(JSContext* cx, JSObject* obj);
TypeCode GetTypeCode(JSObject* typeObj);
bool TypesEqual(JSObject* t1, JSObject* t2);
size_t GetSize(JSObject* obj);
bool GetSafeSize(JSObject* obj, size_t* result);
bool IsSizeDefined(JSObject* obj);
size_t GetAlignment(JSObject* obj);
ffi_type* GetFFIType(JSContext* cx, JSObject* obj);
JSString* GetName(JSContext* cx, JSObject* obj);
JSObject* GetProtoFromCtor(JSContext* cx, JSObject* obj, CTypeProtoSlot slot);
JSObject* GetProtoFromType(JSContext* cx, JSObject* obj, CTypeProtoSlot slot);
JSCTypesCallbacks* GetCallbacksFromType(JSContext* cx, JSObject* obj);
JSObject* GetProtoFromCtor(JSObject* obj, CTypeProtoSlot slot);
JSObject* GetProtoFromType(JSObject* obj, CTypeProtoSlot slot);
JSCTypesCallbacks* GetCallbacksFromType(JSObject* obj);
}
namespace PointerType {
JSObject* CreateInternal(JSContext* cx, JSObject* baseType);
JSObject* GetBaseType(JSContext* cx, JSObject* obj);
JSObject* GetBaseType(JSObject* obj);
}
namespace ArrayType {
JSObject* CreateInternal(JSContext* cx, JSObject* baseType, size_t length,
bool lengthDefined);
JSObject* GetBaseType(JSContext* cx, JSObject* obj);
size_t GetLength(JSContext* cx, JSObject* obj);
bool GetSafeLength(JSContext* cx, JSObject* obj, size_t* result);
JSObject* GetBaseType(JSObject* obj);
size_t GetLength(JSObject* obj);
bool GetSafeLength(JSObject* obj, size_t* result);
ffi_type* BuildFFIType(JSContext* cx, JSObject* obj);
}
namespace StructType {
JSBool DefineInternal(JSContext* cx, JSObject* typeObj, JSObject* fieldsObj);
const FieldInfoHash* GetFieldInfo(JSContext* cx, JSObject* obj);
const FieldInfoHash* GetFieldInfo(JSObject* obj);
const FieldInfo* LookupField(JSContext* cx, JSObject* obj, JSFlatString *name);
JSObject* BuildFieldsArray(JSContext* cx, JSObject* obj);
ffi_type* BuildFFIType(JSContext* cx, JSObject* obj);
@ -501,9 +501,8 @@ namespace FunctionType {
JSObject* ConstructWithObject(JSContext* cx, JSObject* typeObj,
JSObject* refObj, PRFuncPtr fnptr, JSObject* result);
FunctionInfo* GetFunctionInfo(JSContext* cx, JSObject* obj);
JSObject* GetLibrary(JSContext* cx, JSObject* obj);
void BuildSymbolName(JSContext* cx, JSString* name, JSObject* typeObj,
FunctionInfo* GetFunctionInfo(JSObject* obj);
void BuildSymbolName(JSString* name, JSObject* typeObj,
AutoCString& result);
}
@ -516,8 +515,8 @@ namespace CData {
JSObject* Create(JSContext* cx, JSObject* typeObj, JSObject* refObj,
void* data, bool ownResult);
JSObject* GetCType(JSContext* cx, JSObject* dataObj);
void* GetData(JSContext* cx, JSObject* dataObj);
JSObject* GetCType(JSObject* dataObj);
void* GetData(JSObject* dataObj);
bool IsCData(JSObject* obj);
bool IsCDataProto(JSObject* obj);

Просмотреть файл

@ -121,8 +121,7 @@ Library::Create(JSContext* cx, jsval path, JSCTypesCallbacks* callbacks)
js::AutoObjectRooter root(cx, libraryObj);
// initialize the library
if (!JS_SetReservedSlot(cx, libraryObj, SLOT_LIBRARY, PRIVATE_TO_JSVAL(NULL)))
return NULL;
JS_SetReservedSlot(libraryObj, SLOT_LIBRARY, PRIVATE_TO_JSVAL(NULL));
// attach API functions
if (!JS_DefineFunctions(cx, libraryObj, sLibraryFunctions))
@ -187,9 +186,7 @@ Library::Create(JSContext* cx, jsval path, JSCTypesCallbacks* callbacks)
}
// stash the library
if (!JS_SetReservedSlot(cx, libraryObj, SLOT_LIBRARY,
PRIVATE_TO_JSVAL(library)))
return NULL;
JS_SetReservedSlot(libraryObj, SLOT_LIBRARY, PRIVATE_TO_JSVAL(library));
return libraryObj;
}
@ -201,12 +198,11 @@ Library::IsLibrary(JSObject* obj)
}
PRLibrary*
Library::GetLibrary(JSContext* cx, JSObject* obj)
Library::GetLibrary(JSObject* obj)
{
JS_ASSERT(IsLibrary(obj));
jsval slot;
JS_GetReservedSlot(cx, obj, SLOT_LIBRARY, &slot);
jsval slot = JS_GetReservedSlot(obj, SLOT_LIBRARY);
return static_cast<PRLibrary*>(JSVAL_TO_PRIVATE(slot));
}
@ -214,7 +210,7 @@ void
Library::Finalize(JSContext* cx, JSObject* obj)
{
// unload the library
PRLibrary* library = GetLibrary(cx, obj);
PRLibrary* library = GetLibrary(obj);
if (library)
PR_UnloadLibrary(library);
}
@ -233,7 +229,7 @@ Library::Open(JSContext* cx, uintN argc, jsval *vp)
return JS_FALSE;
}
JSObject* library = Create(cx, JS_ARGV(cx, vp)[0], GetCallbacks(cx, ctypesObj));
JSObject* library = Create(cx, JS_ARGV(cx, vp)[0], GetCallbacks(ctypesObj));
if (!library)
return JS_FALSE;
@ -257,7 +253,7 @@ Library::Close(JSContext* cx, uintN argc, jsval* vp)
// delete our internal objects
Finalize(cx, obj);
JS_SetReservedSlot(cx, obj, SLOT_LIBRARY, PRIVATE_TO_JSVAL(NULL));
JS_SetReservedSlot(obj, SLOT_LIBRARY, PRIVATE_TO_JSVAL(NULL));
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
@ -272,7 +268,7 @@ Library::Declare(JSContext* cx, uintN argc, jsval* vp)
return JS_FALSE;
}
PRLibrary* library = GetLibrary(cx, obj);
PRLibrary* library = GetLibrary(obj);
if (!library) {
JS_ReportError(cx, "library not open");
return JS_FALSE;
@ -322,15 +318,15 @@ Library::Declare(JSContext* cx, uintN argc, jsval* vp)
// Case 2).
if (JSVAL_IS_PRIMITIVE(argv[1]) ||
!CType::IsCType(JSVAL_TO_OBJECT(argv[1])) ||
!CType::IsSizeDefined(cx, JSVAL_TO_OBJECT(argv[1]))) {
!CType::IsSizeDefined(JSVAL_TO_OBJECT(argv[1]))) {
JS_ReportError(cx, "second argument must be a type of defined size");
return JS_FALSE;
}
typeObj = JSVAL_TO_OBJECT(argv[1]);
if (CType::GetTypeCode(cx, typeObj) == TYPE_pointer) {
fnObj = PointerType::GetBaseType(cx, typeObj);
isFunction = fnObj && CType::GetTypeCode(cx, fnObj) == TYPE_function;
if (CType::GetTypeCode(typeObj) == TYPE_pointer) {
fnObj = PointerType::GetBaseType(typeObj);
isFunction = fnObj && CType::GetTypeCode(fnObj) == TYPE_function;
}
}
@ -340,7 +336,7 @@ Library::Declare(JSContext* cx, uintN argc, jsval* vp)
AutoCString symbol;
if (isFunction) {
// Build the symbol, with mangling if necessary.
FunctionType::BuildSymbolName(cx, nameStr, fnObj, symbol);
FunctionType::BuildSymbolName(nameStr, fnObj, symbol);
AppendString(symbol, "\0");
// Look up the function symbol.

Просмотреть файл

@ -59,7 +59,7 @@ namespace Library
JSObject* Create(JSContext* cx, jsval path, JSCTypesCallbacks* callbacks);
bool IsLibrary(JSObject* obj);
PRLibrary* GetLibrary(JSContext* cx, JSObject* obj);
PRLibrary* GetLibrary(JSObject* obj);
JSBool Open(JSContext* cx, uintN argc, jsval* vp);
}

Просмотреть файл

@ -18,7 +18,7 @@ END_TEST(selfTest_NaNsAreSame)
BEGIN_TEST(selfTest_globalHasNoParent)
{
CHECK(JS_GetParent(cx, global) == NULL);
CHECK(JS_GetParent(global) == NULL);
return true;
}
END_TEST(selfTest_globalHasNoParent)

Просмотреть файл

@ -30,8 +30,8 @@ BEGIN_TEST(testResolveRecursion)
CHECK(obj1);
obj2 = JS_NewObject(cx, &my_resolve_class, NULL, NULL);
CHECK(obj2);
CHECK(JS_SetPrivate(cx, obj1, this));
CHECK(JS_SetPrivate(cx, obj2, this));
JS_SetPrivate(obj1, this);
JS_SetPrivate(obj2, this);
CHECK(JS_DefineProperty(cx, global, "obj1", OBJECT_TO_JSVAL(obj1), NULL, NULL, 0));
CHECK(JS_DefineProperty(cx, global, "obj2", OBJECT_TO_JSVAL(obj2), NULL, NULL, 0));
@ -127,7 +127,7 @@ doResolve(JSObject *obj, jsid id, uintN flags, JSObject **objp)
static JSBool
my_resolve(JSContext *cx, JSObject *obj, jsid id, uintN flags, JSObject **objp)
{
return static_cast<cls_testResolveRecursion *>(JS_GetPrivate(cx, obj))->
return static_cast<cls_testResolveRecursion *>(JS_GetPrivate(obj))->
doResolve(obj, id, flags, objp);
}

Просмотреть файл

@ -3156,18 +3156,17 @@ JS_HasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp)
}
JS_PUBLIC_API(void *)
JS_GetPrivate(JSContext *cx, JSObject *obj)
JS_GetPrivate(JSObject *obj)
{
/* This function can be called by a finalizer. */
return obj->getPrivate();
}
JS_PUBLIC_API(JSBool)
JS_SetPrivate(JSContext *cx, JSObject *obj, void *data)
JS_PUBLIC_API(void)
JS_SetPrivate(JSObject *obj, void *data)
{
/* This function can be called by a finalizer. */
obj->setPrivate(data);
return true;
}
JS_PUBLIC_API(void *)
@ -3179,10 +3178,8 @@ JS_GetInstancePrivate(JSContext *cx, JSObject *obj, JSClass *clasp, jsval *argv)
}
JS_PUBLIC_API(JSObject *)
JS_GetPrototype(JSContext *cx, JSObject *obj)
JS_GetPrototype(JSObject *obj)
{
CHECK_REQUEST(cx);
assertSameCompartment(cx, obj);
return obj->getProto();
}
@ -3196,10 +3193,9 @@ JS_SetPrototype(JSContext *cx, JSObject *obj, JSObject *proto)
}
JS_PUBLIC_API(JSObject *)
JS_GetParent(JSContext *cx, JSObject *obj)
JS_GetParent(JSObject *obj)
{
JS_ASSERT(!obj->isScope());
assertSameCompartment(cx, obj);
return obj->getParent();
}
@ -4405,22 +4401,23 @@ JS_ElementIteratorStub(JSContext *cx, JSObject *obj, JSBool keysonly)
return JS_NewElementIterator(cx, obj);
}
JS_PUBLIC_API(JSBool)
JS_GetReservedSlot(JSContext *cx, JSObject *obj, uint32_t index, jsval *vp)
JS_PUBLIC_API(jsval)
JS_GetReservedSlot(JSObject *obj, uint32_t index)
{
/* This function can be called by a finalizer. */
CHECK_REQUEST(cx);
assertSameCompartment(cx, obj);
return js_GetReservedSlot(cx, obj, index, vp);
if (!obj->isNative())
return UndefinedValue();
return GetReservedSlot(obj, index);
}
JS_PUBLIC_API(JSBool)
JS_SetReservedSlot(JSContext *cx, JSObject *obj, uint32_t index, jsval v)
JS_PUBLIC_API(void)
JS_SetReservedSlot(JSObject *obj, uint32_t index, jsval v)
{
AssertNoGC(cx);
CHECK_REQUEST(cx);
assertSameCompartment(cx, obj, v);
return js_SetReservedSlot(cx, obj, index, v);
if (!obj->isNative())
return;
SetReservedSlot(obj, index, v);
GCPoke(obj->compartment()->rt, NullValue());
}
JS_PUBLIC_API(JSObject *)

Просмотреть файл

@ -2773,8 +2773,8 @@ typedef struct JSCTypesCallbacks JSCTypesCallbacks;
* may safely be altered after calling this function and without having
* to call this function again.
*/
extern JS_PUBLIC_API(JSBool)
JS_SetCTypesCallbacks(JSContext *cx, JSObject *ctypesObj, JSCTypesCallbacks *callbacks);
extern JS_PUBLIC_API(void)
JS_SetCTypesCallbacks(JSObject *ctypesObj, JSCTypesCallbacks *callbacks);
#endif
typedef JSBool
@ -3620,23 +3620,23 @@ extern JS_PUBLIC_API(JSBool)
JS_HasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp);
extern JS_PUBLIC_API(void *)
JS_GetPrivate(JSContext *cx, JSObject *obj);
JS_GetPrivate(JSObject *obj);
extern JS_PUBLIC_API(JSBool)
JS_SetPrivate(JSContext *cx, JSObject *obj, void *data);
extern JS_PUBLIC_API(void)
JS_SetPrivate(JSObject *obj, void *data);
extern JS_PUBLIC_API(void *)
JS_GetInstancePrivate(JSContext *cx, JSObject *obj, JSClass *clasp,
jsval *argv);
extern JS_PUBLIC_API(JSObject *)
JS_GetPrototype(JSContext *cx, JSObject *obj);
JS_GetPrototype(JSObject *obj);
extern JS_PUBLIC_API(JSBool)
JS_SetPrototype(JSContext *cx, JSObject *obj, JSObject *proto);
extern JS_PUBLIC_API(JSObject *)
JS_GetParent(JSContext *cx, JSObject *obj);
JS_GetParent(JSObject *obj);
extern JS_PUBLIC_API(JSBool)
JS_SetParent(JSContext *cx, JSObject *obj, JSObject *parent);
@ -4025,11 +4025,11 @@ extern JS_PUBLIC_API(JSBool)
JS_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode,
jsval *vp, uintN *attrsp);
extern JS_PUBLIC_API(JSBool)
JS_GetReservedSlot(JSContext *cx, JSObject *obj, uint32_t index, jsval *vp);
extern JS_PUBLIC_API(jsval)
JS_GetReservedSlot(JSObject *obj, uint32_t index);
extern JS_PUBLIC_API(JSBool)
JS_SetReservedSlot(JSContext *cx, JSObject *obj, uint32_t index, jsval v);
extern JS_PUBLIC_API(void)
JS_SetReservedSlot(JSObject *obj, uint32_t index, jsval v);
/************************************************************************/

Просмотреть файл

@ -195,7 +195,7 @@ GetGCKindSlots(AllocKind thingKind, Class *clasp)
}
static inline void
GCPoke(JSContext *cx, Value oldval)
GCPoke(JSRuntime *rt, Value oldval)
{
/*
* Since we're forcing a GC from JS_GC anyway, don't bother wasting cycles
@ -203,15 +203,15 @@ GCPoke(JSContext *cx, Value oldval)
* ignored", etc.
*/
#if 1
cx->runtime->gcPoke = JS_TRUE;
rt->gcPoke = true;
#else
cx->runtime->gcPoke = oldval.isGCThing();
rt->gcPoke = oldval.isGCThing();
#endif
#ifdef JS_GC_ZEAL
/* Schedule a GC to happen "soon" after a GC poke. */
if (cx->runtime->gcZeal() >= js::gc::ZealPokeThreshold)
cx->runtime->gcNextScheduled = 1;
if (rt->gcZeal() >= js::gc::ZealPokeThreshold)
rt->gcNextScheduled = 1;
#endif
}

Просмотреть файл

@ -3595,8 +3595,7 @@ DefineStandardSlot(JSContext *cx, JSObject *obj, JSProtoKey key, JSAtom *atom,
const Shape *shape = obj->nativeLookup(cx, id);
if (!shape) {
uint32_t slot = 2 * JSProto_LIMIT + key;
if (!js_SetReservedSlot(cx, obj, slot, v))
return false;
SetReservedSlot(obj, slot, v);
if (!obj->addProperty(cx, id, JS_PropertyStub, JS_StrictPropertyStub, slot, attrs, 0, 0))
return false;
AddTypePropertyId(cx, obj, id, v);
@ -3612,15 +3611,15 @@ DefineStandardSlot(JSContext *cx, JSObject *obj, JSProtoKey key, JSAtom *atom,
namespace js {
static bool
SetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key, JSObject *cobj, JSObject *proto)
static void
SetClassObject(JSObject *obj, JSProtoKey key, JSObject *cobj, JSObject *proto)
{
JS_ASSERT(!obj->getParent());
if (!obj->isGlobal())
return true;
return;
return js_SetReservedSlot(cx, obj, key, ObjectOrNullValue(cobj)) &&
js_SetReservedSlot(cx, obj, JSProto_LIMIT + key, ObjectOrNullValue(proto));
SetReservedSlot(obj, key, ObjectOrNullValue(cobj));
SetReservedSlot(obj, JSProto_LIMIT + key, ObjectOrNullValue(proto));
}
static void
@ -3722,8 +3721,7 @@ DefineConstructorAndPrototype(JSContext *cx, HandleObject obj, JSProtoKey key, H
* fail if it tries to do a reentrant reconstruction of the class.
*/
if (key != JSProto_Null) {
if (!SetClassObject(cx, obj, key, fun, proto))
goto bad;
SetClassObject(obj, key, fun, proto);
cached = true;
}
@ -3761,8 +3759,8 @@ DefineConstructorAndPrototype(JSContext *cx, HandleObject obj, JSProtoKey key, H
}
/* If this is a standard class, cache its prototype. */
if (!cached && key != JSProto_Null && !SetClassObject(cx, obj, key, ctor, proto))
goto bad;
if (!cached && key != JSProto_Null)
SetClassObject(obj, key, ctor, proto);
if (ctorp)
*ctorp = ctor;
@ -5779,7 +5777,7 @@ js_DeleteGeneric(JSContext *cx, JSObject *obj, jsid id, Value *rval, JSBool stri
if (shape->hasSlot()) {
const Value &v = obj->nativeGetSlot(shape->slot());
GCPoke(cx, v);
GCPoke(cx->runtime, v);
/*
* Delete is rare enough that we can take the hit of checking for an
@ -6355,31 +6353,6 @@ js_ClearNative(JSContext *cx, JSObject *obj)
return true;
}
bool
js_GetReservedSlot(JSContext *cx, JSObject *obj, uint32_t slot, Value *vp)
{
if (!obj->isNative()) {
vp->setUndefined();
return true;
}
JS_ASSERT(slot < JSSLOT_FREE(obj->getClass()));
*vp = obj->getSlot(slot);
return true;
}
bool
js_SetReservedSlot(JSContext *cx, JSObject *obj, uint32_t slot, const Value &v)
{
if (!obj->isNative())
return true;
JS_ASSERT(slot < JSSLOT_FREE(obj->getClass()));
obj->setSlot(slot, v);
GCPoke(cx, NullValue());
return true;
}
static ObjectElements emptyObjectHeader(0, 0);
HeapValue *js::emptyObjectElements =
(HeapValue *) (uintptr_t(&emptyObjectHeader) + sizeof(ObjectElements));

Просмотреть файл

@ -1990,12 +1990,6 @@ js_PrintObjectSlotName(JSTracer *trc, char *buf, size_t bufsize);
extern bool
js_ClearNative(JSContext *cx, JSObject *obj);
extern bool
js_GetReservedSlot(JSContext *cx, JSObject *obj, uint32_t index, js::Value *vp);
extern bool
js_SetReservedSlot(JSContext *cx, JSObject *obj, uint32_t index, const js::Value &v);
extern JSBool
js_ReportGetterOnlyAssignment(JSContext *cx);

Просмотреть файл

@ -7718,8 +7718,7 @@ js_GetAnyName(JSContext *cx, jsid *idp)
return false;
v.setObject(*obj);
if (!js_SetReservedSlot(cx, global, JSProto_AnyName, v))
return false;
SetReservedSlot(global, JSProto_AnyName, v);
}
*idp = OBJECT_TO_JSID(&v.toObject());
return true;

Просмотреть файл

@ -71,7 +71,7 @@ pm_construct(JSContext* cx, uintN argc, jsval* vp)
return JS_FALSE;
}
JS_SetPrivate(cx, obj, p);
JS_SetPrivate(obj, p);
*vp = OBJECT_TO_JSVAL(obj);
return JS_TRUE;
}
@ -79,7 +79,7 @@ pm_construct(JSContext* cx, uintN argc, jsval* vp)
static void
pm_finalize(JSContext* cx, JSObject* obj)
{
cx->delete_((PerfMeasurement*) JS_GetPrivate(cx, obj));
cx->delete_((PerfMeasurement*) JS_GetPrivate(obj));
}
// Property access

Просмотреть файл

@ -1630,7 +1630,7 @@ ValueToScript(JSContext *cx, jsval v, JSFunction **funp = NULL)
JSClass *clasp = JS_GetClass(obj);
if (clasp == Jsvalify(&GeneratorClass)) {
if (JSGenerator *gen = (JSGenerator *) JS_GetPrivate(cx, obj)) {
if (JSGenerator *gen = (JSGenerator *) JS_GetPrivate(obj)) {
fun = gen->floatingFrame()->fun();
script = fun->script();
}
@ -2787,7 +2787,7 @@ Clone(JSContext *cx, uintN argc, jsval *vp)
if (!JS_ValueToObject(cx, argv[1], &parent))
return JS_FALSE;
} else {
parent = JS_GetParent(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)));
parent = JS_GetParent(JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)));
}
clone = JS_CloneFunctionObject(cx, funobj, parent);
@ -3214,16 +3214,14 @@ CopyProperty(JSContext *cx, JSObject *obj, JSObject *referent, jsid id,
static JSBool
resolver_resolve(JSContext *cx, JSObject *obj, jsid id, uintN flags, JSObject **objp)
{
jsval v;
JS_ALWAYS_TRUE(JS_GetReservedSlot(cx, obj, 0, &v));
jsval v = JS_GetReservedSlot(obj, 0);
return CopyProperty(cx, obj, JSVAL_TO_OBJECT(v), id, flags, objp);
}
static JSBool
resolver_enumerate(JSContext *cx, JSObject *obj)
{
jsval v;
JS_ALWAYS_TRUE(JS_GetReservedSlot(cx, obj, 0, &v));
jsval v = JS_GetReservedSlot(obj, 0);
JSObject *referent = JSVAL_TO_OBJECT(v);
AutoIdArray ida(cx, JS_Enumerate(cx, referent));
@ -3254,11 +3252,11 @@ Resolver(JSContext *cx, uintN argc, jsval *vp)
JSObject *result = (argc > 1
? JS_NewObjectWithGivenProto
: JS_NewObject)(cx, &resolver_class, proto, JS_GetParent(cx, referent));
: JS_NewObject)(cx, &resolver_class, proto, JS_GetParent(referent));
if (!result)
return false;
JS_ALWAYS_TRUE(JS_SetReservedSlot(cx, result, 0, OBJECT_TO_JSVAL(referent)));
JS_SetReservedSlot(result, 0, OBJECT_TO_JSVAL(referent));
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(result));
return true;
}
@ -3581,7 +3579,7 @@ Parent(JSContext *cx, uintN argc, jsval *vp)
return JS_FALSE;
}
JSObject *parent = JS_GetParent(cx, JSVAL_TO_OBJECT(v));
JSObject *parent = JS_GetParent(JSVAL_TO_OBJECT(v));
*vp = OBJECT_TO_JSVAL(parent);
/* Outerize if necessary. Embrace the ugliness! */
@ -4526,10 +4524,10 @@ its_finalize(JSContext *cx, JSObject *obj)
jsval *rootedVal;
if (its_noisy)
fprintf(gOutFile, "finalizing it\n");
rootedVal = (jsval *) JS_GetPrivate(cx, obj);
rootedVal = (jsval *) JS_GetPrivate(obj);
if (rootedVal) {
JS_RemoveValueRoot(cx, rootedVal);
JS_SetPrivate(cx, obj, NULL);
JS_SetPrivate(obj, NULL);
delete rootedVal;
}
}
@ -4546,7 +4544,7 @@ static JSBool
its_getter(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
{
if (JS_GetClass(obj) == &its_class) {
jsval *val = (jsval *) JS_GetPrivate(cx, obj);
jsval *val = (jsval *) JS_GetPrivate(obj);
*vp = val ? *val : JSVAL_VOID;
} else {
*vp = JSVAL_VOID;
@ -4561,7 +4559,7 @@ its_setter(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
if (JS_GetClass(obj) != &its_class)
return JS_TRUE;
jsval *val = (jsval *) JS_GetPrivate(cx, obj);
jsval *val = (jsval *) JS_GetPrivate(obj);
if (val) {
*val = *vp;
return JS_TRUE;
@ -4578,11 +4576,7 @@ its_setter(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
return JS_FALSE;
}
if (!JS_SetPrivate(cx, obj, (void*)val)) {
JS_RemoveValueRoot(cx, val);
delete val;
return JS_FALSE;
}
JS_SetPrivate(obj, (void*)val);
*val = *vp;
return JS_TRUE;
@ -4895,7 +4889,7 @@ env_enumerate(JSContext *cx, JSObject *obj)
if (reflected)
return JS_TRUE;
for (evp = (char **)JS_GetPrivate(cx, obj); (name = *evp) != NULL; evp++) {
for (evp = (char **)JS_GetPrivate(obj); (name = *evp) != NULL; evp++) {
value = strchr(name, '=');
if (!value)
continue;
@ -5198,8 +5192,9 @@ Shell(JSContext *cx, OptionParser *op, char **envp)
JS_SetGlobalObject(cx, glob);
JSObject *envobj = JS_DefineObject(cx, glob, "environment", &env_class, NULL, 0);
if (!envobj || !JS_SetPrivate(cx, envobj, envp))
if (!envobj)
return 1;
JS_SetPrivate(envobj, envp);
#ifdef JSDEBUGGER
/*

Просмотреть файл

@ -489,10 +489,11 @@ class ThreadPool
}
JSObject *obj = JS_NewObject(cx, &jsClass, NULL, NULL);
if (!obj || !JS_SetPrivate(cx, obj, tp)) {
if (!obj) {
delete tp;
return NULL;
}
JS_SetPrivate(obj, tp);
tp->obj = obj;
return tp;
}
@ -566,7 +567,7 @@ class ThreadPool
private:
static void jsTraceThreadPool(JSTracer *trc, JSObject *obj) {
ThreadPool *tp = unwrap(trc->context, obj);
ThreadPool *tp = unwrap(obj);
if (tp->mq) {
tp->mq->traceChildren(trc);
tp->wq->trace(trc);
@ -575,14 +576,14 @@ class ThreadPool
static void jsFinalize(JSContext *cx, JSObject *obj) {
if (ThreadPool *tp = unwrap(cx, obj))
if (ThreadPool *tp = unwrap(obj))
delete tp;
}
public:
static ThreadPool *unwrap(JSContext *cx, JSObject *obj) {
static ThreadPool *unwrap(JSObject *obj) {
JS_ASSERT(JS_GetClass(obj) == &jsClass);
return (ThreadPool *) JS_GetPrivate(cx, obj);
return (ThreadPool *) JS_GetPrivate(obj);
}
};
@ -626,10 +627,10 @@ class Worker MOZ_FINAL : public WorkerParent
this->parent = parent;
this->object = obj;
lock = PR_NewLock();
return lock &&
createRuntime(parentcx) &&
createContext(parentcx, parent) &&
JS_SetPrivate(parentcx, obj, this);
if (!lock || !createRuntime(parentcx) || !createContext(parentcx, parent))
return false;
JS_SetPrivate(obj, this);
return true;
}
bool createRuntime(JSContext *parentcx) {
@ -701,7 +702,7 @@ class Worker MOZ_FINAL : public WorkerParent
static void jsTraceWorker(JSTracer *trc, JSObject *obj) {
JS_ASSERT(JS_GetClass(obj) == &jsWorkerClass);
if (Worker *w = (Worker *) JS_GetPrivate(trc->context, obj)) {
if (Worker *w = (Worker *) JS_GetPrivate(obj)) {
w->parent->trace(trc);
w->events.trace(trc);
if (w->current)
@ -712,7 +713,7 @@ class Worker MOZ_FINAL : public WorkerParent
static void jsFinalize(JSContext *cx, JSObject *obj) {
JS_ASSERT(JS_GetClass(obj) == &jsWorkerClass);
if (Worker *w = (Worker *) JS_GetPrivate(cx, obj))
if (Worker *w = (Worker *) JS_GetPrivate(obj))
delete w;
}

Просмотреть файл

@ -2637,11 +2637,9 @@ DebuggerFrame_getArguments(JSContext *cx, uintN argc, Value *vp)
if (!js_GetClassPrototype(cx, global, JSProto_Array, &proto))
return false;
argsobj = NewObjectWithGivenProto(cx, &DebuggerArguments_class, proto, global);
if (!argsobj ||
!js_SetReservedSlot(cx, argsobj, JSSLOT_DEBUGARGUMENTS_FRAME, ObjectValue(*thisobj)))
{
if (!argsobj)
return false;
}
SetReservedSlot(argsobj, JSSLOT_DEBUGARGUMENTS_FRAME, ObjectValue(*thisobj));
JS_ASSERT(fp->numActualArgs() <= 0x7fffffff);
int32_t fargc = int32_t(fp->numActualArgs());

Просмотреть файл

@ -825,7 +825,7 @@ Parent(JSContext *cx, uintN argc, jsval *vp)
return false;
}
*vp = OBJECT_TO_JSVAL(JS_GetParent(cx, JSVAL_TO_OBJECT(v)));
*vp = OBJECT_TO_JSVAL(JS_GetParent(JSVAL_TO_OBJECT(v)));
return true;
}
@ -923,7 +923,7 @@ env_enumerate(JSContext *cx, JSObject *obj)
if (reflected)
return true;
for (evp = (char **)JS_GetPrivate(cx, obj); (name = *evp) != NULL; evp++) {
for (evp = (char **)JS_GetPrivate(obj); (name = *evp) != NULL; evp++) {
value = strchr(name, '=');
if (!value)
continue;
@ -1234,7 +1234,7 @@ ProcessArgs(JSContext *cx, JSObject *obj, char **argv, int argc)
xpc_ActivateDebugMode();
break;
case 'P':
if (JS_GetClass(JS_GetPrototype(cx, obj)) != &global_class) {
if (JS_GetClass(JS_GetPrototype(obj)) != &global_class) {
JSObject *gobj;
if (!JS_DeepFreezeObject(cx, obj))
@ -1977,11 +1977,13 @@ main(int argc, char **argv, char **envp)
}
envobj = JS_DefineObject(cx, glob, "environment", &env_class, NULL, 0);
if (!envobj || !JS_SetPrivate(cx, envobj, envp)) {
if (!envobj) {
JS_EndRequest(cx);
return 1;
}
JS_SetPrivate(envobj, envp);
nsAutoString workingDirectory;
if (GetCurrentWorkingDirectory(workingDirectory))
gWorkingDirectory = &workingDirectory;

Просмотреть файл

@ -2625,7 +2625,7 @@ nsXPCComponents_Utils::LookupMethod(const JS::Value& object,
JSObject* obj = JSVAL_TO_OBJECT(object);
while (obj && !js::IsWrapper(obj) && !IS_WRAPPER_CLASS(js::GetObjectClass(obj)))
obj = JS_GetPrototype(cx, obj);
obj = JS_GetPrototype(obj);
if (!obj)
return NS_ERROR_XPC_BAD_CONVERT_JS;
@ -3034,9 +3034,7 @@ xpc_CreateSandboxObject(JSContext * cx, jsval * vp, nsISupports *prinOrSop, JSOb
}
// Pass on ownership of sop to |sandbox|.
if (!JS_SetPrivate(cx, sandbox, sop.forget().get())) {
return NS_ERROR_XPC_UNEXPECTED;
}
JS_SetPrivate(sandbox, sop.forget().get());
rv = xpc->InitClasses(cx, sandbox);
if (NS_SUCCEEDED(rv) &&

Просмотреть файл

@ -999,17 +999,17 @@ DetachedWrappedNativeProtoShutdownMarker(JSDHashTable *table, JSDHashEntryHdr *h
XPCWrappedNativeProto* proto =
(XPCWrappedNativeProto*)((JSDHashEntryStub*)hdr)->key;
proto->SystemIsBeingShutDown((JSContext*)arg);
proto->SystemIsBeingShutDown();
return JS_DHASH_NEXT;
}
void XPCJSRuntime::SystemIsBeingShutDown(JSContext* cx)
void XPCJSRuntime::SystemIsBeingShutDown()
{
DOM_ClearInterfaces();
if (mDetachedWrappedNativeProtoMap)
mDetachedWrappedNativeProtoMap->
Enumerate(DetachedWrappedNativeProtoShutdownMarker, cx);
Enumerate(DetachedWrappedNativeProtoShutdownMarker, nsnull);
}
JSContext *

Просмотреть файл

@ -152,7 +152,7 @@ PropertyOpForwarder(JSContext *cx, uintN argc, jsval *vp)
jsval v = js::GetFunctionNativeReserved(callee, 0);
JSObject *ptrobj = JSVAL_TO_OBJECT(v);
Op *popp = static_cast<Op *>(JS_GetPrivate(cx, ptrobj));
Op *popp = static_cast<Op *>(JS_GetPrivate(ptrobj));
v = js::GetFunctionNativeReserved(callee, 1);
@ -167,7 +167,7 @@ PropertyOpForwarder(JSContext *cx, uintN argc, jsval *vp)
static void
PointerFinalize(JSContext *cx, JSObject *obj)
{
JSPropertyOp *popp = static_cast<JSPropertyOp *>(JS_GetPrivate(cx, obj));
JSPropertyOp *popp = static_cast<JSPropertyOp *>(JS_GetPrivate(obj));
delete popp;
}
@ -203,7 +203,7 @@ GeneratePropertyOp(JSContext *cx, JSObject *obj, jsid id, uintN argc, Op pop)
if (!popp)
return nsnull;
*popp = pop;
JS_SetPrivate(cx, ptrobj, popp);
JS_SetPrivate(ptrobj, popp);
js::SetFunctionNativeReserved(funobj, 0, OBJECT_TO_JSVAL(ptrobj));
js::SetFunctionNativeReserved(funobj, 1, js::IdToJsval(id));

Просмотреть файл

@ -239,11 +239,7 @@ XPCJSContextStack::GetSafeJSContext()
// InitClasses
nsIScriptObjectPrincipal* priv = nsnull;
sop.swap(priv);
if (!JS_SetPrivate(mSafeJSContext, glob, priv)) {
// Drop the whole thing
NS_RELEASE(priv);
glob = nsnull;
}
JS_SetPrivate(glob, priv);
}
// After this point either glob is null and the

Просмотреть файл

@ -707,7 +707,7 @@ XPCWrappedNative::Morph(XPCCallContext& ccx,
// https://bugzilla.mozilla.org/show_bug.cgi?id=343141 is fixed.
#if 0
if (proto->GetScriptableInfo()->GetFlags().WantPreCreate()) {
JSObject* parent = JS_GetParent(ccx, existingJSObject);
JSObject* parent = JS_GetParent(existingJSObject);
JSObject* plannedParent = parent;
nsresult rv =
proto->GetScriptableInfo()->GetCallback()->PreCreate(identity, ccx,
@ -1127,14 +1127,7 @@ XPCWrappedNative::Init(XPCCallContext& ccx,
if (!mFlatJSObject)
return false;
// In the current JS engine JS_SetPrivate can't fail. But if it *did*
// fail then we would not receive our finalizer call and would not be
// able to properly cleanup. So, if it fails we null out mFlatJSObject
// to indicate the invalid state of this object and return false.
if (!JS_SetPrivate(ccx, mFlatJSObject, this)) {
mFlatJSObject = nsnull;
return false;
}
JS_SetPrivate(mFlatJSObject, this);
return FinishInit(ccx);
}
@ -1142,18 +1135,10 @@ XPCWrappedNative::Init(XPCCallContext& ccx,
JSBool
XPCWrappedNative::Init(XPCCallContext &ccx, JSObject *existingJSObject)
{
// In the current JS engine JS_SetPrivate can't fail. But if it *did*
// fail then we would not receive our finalizer call and would not be
// able to properly cleanup. So, if it fails we null out mFlatJSObject
// to indicate the invalid state of this object and return false.
if (!JS_SetPrivate(ccx, existingJSObject, this)) {
mFlatJSObject = nsnull;
return false;
}
JS_SetPrivate(existingJSObject, this);
// Morph the existing object.
if (!JS_SetReservedSlot(ccx, existingJSObject, 0, JSVAL_VOID))
return false;
JS_SetReservedSlot(existingJSObject, 0, JSVAL_VOID);
mScriptableInfo = GetProto()->GetScriptableInfo();
mFlatJSObject = existingJSObject;
@ -1260,7 +1245,7 @@ NS_IMPL_THREADSAFE_RELEASE(XPCWrappedNative)
*/
void
XPCWrappedNative::FlatJSObjectFinalized(JSContext *cx)
XPCWrappedNative::FlatJSObjectFinalized()
{
if (!IsValid())
return;
@ -1277,7 +1262,7 @@ XPCWrappedNative::FlatJSObjectFinalized(JSContext *cx)
JSObject* jso = to->GetJSObject();
if (jso) {
NS_ASSERTION(JS_IsAboutToBeFinalized(jso), "bad!");
JS_SetPrivate(cx, jso, nsnull);
JS_SetPrivate(jso, nsnull);
to->JSObjectFinalized();
}
@ -1332,7 +1317,7 @@ XPCWrappedNative::FlatJSObjectFinalized(JSContext *cx)
}
void
XPCWrappedNative::SystemIsBeingShutDown(JSContext* cx)
XPCWrappedNative::SystemIsBeingShutDown()
{
#ifdef DEBUG_xpc_hacker
{
@ -1358,13 +1343,13 @@ XPCWrappedNative::SystemIsBeingShutDown(JSContext* cx)
// We leak mIdentity (see above).
// short circuit future finalization
JS_SetPrivate(cx, mFlatJSObject, nsnull);
JS_SetPrivate(mFlatJSObject, nsnull);
mFlatJSObject = nsnull; // This makes 'IsValid()' return false.
XPCWrappedNativeProto* proto = GetProto();
if (HasProto())
proto->SystemIsBeingShutDown(cx);
proto->SystemIsBeingShutDown();
if (mScriptableInfo &&
(!HasProto() ||
@ -1379,7 +1364,7 @@ XPCWrappedNative::SystemIsBeingShutDown(JSContext* cx)
XPCWrappedNativeTearOff* to = chunk->mTearOffs;
for (int i = XPC_WRAPPED_NATIVE_TEAROFFS_PER_CHUNK-1; i >= 0; i--, to++) {
if (to->GetJSObject()) {
JS_SetPrivate(cx, to->GetJSObject(), nsnull);
JS_SetPrivate(to->GetJSObject(), nsnull);
to->SetJSObject(nsnull);
}
// We leak the tearoff mNative
@ -1533,7 +1518,7 @@ XPCWrappedNative::ReparentWrapperIfFound(XPCCallContext& ccx,
if (!newobj)
return NS_ERROR_FAILURE;
JS_SetPrivate(ccx, flat, nsnull);
JS_SetPrivate(flat, nsnull);
JSObject *propertyHolder =
JS_NewObjectWithGivenProto(ccx, NULL, NULL, aNewParent);
@ -1585,11 +1570,11 @@ XPCWrappedNative::ReparentWrapperIfFound(XPCCallContext& ccx,
}
}
} else {
if (!JS_SetReservedSlot(ccx, flat, 0,
PRIVATE_TO_JSVAL(newProto.get())) ||
!JS_SetPrototype(ccx, flat, newProto->GetJSProtoObject())) {
JS_SetReservedSlot(flat, 0,
PRIVATE_TO_JSVAL(newProto.get()));
if (!JS_SetPrototype(ccx, flat, newProto->GetJSProtoObject())) {
// this is bad, very bad
JS_SetReservedSlot(ccx, flat, 0, JSVAL_NULL);
JS_SetReservedSlot(flat, 0, JSVAL_NULL);
NS_ERROR("JS_SetPrototype failed");
return NS_ERROR_FAILURE;
}
@ -2029,9 +2014,10 @@ XPCWrappedNative::InitTearOffJSObject(XPCCallContext& ccx,
GetScope()->GetPrototypeJSObject(),
false, mFlatJSObject);
if (!obj || !JS_SetPrivate(ccx, obj, to))
if (!obj)
return false;
JS_SetPrivate(obj, to);
to->SetJSObject(obj);
return true;
}
@ -3713,11 +3699,12 @@ ConstructSlimWrapper(XPCCallContext &ccx,
wrapper = xpc_NewSystemInheritingJSObject(ccx, jsclazz,
xpcproto->GetJSProtoObject(),
false, parent);
if (!wrapper ||
!JS_SetPrivate(ccx, wrapper, identityObj) ||
!JS_SetReservedSlot(ccx, wrapper, 0, PRIVATE_TO_JSVAL(xpcproto.get())))
if (!wrapper)
return false;
JS_SetPrivate(wrapper, identityObj);
JS_SetReservedSlot(wrapper, 0, PRIVATE_TO_JSVAL(xpcproto.get()));
// Transfer ownership to the wrapper's private.
aHelper.forgetCanonical();

Просмотреть файл

@ -637,7 +637,7 @@ XPC_WN_NoHelper_Finalize(JSContext *cx, JSObject *obj)
return;
}
static_cast<XPCWrappedNative*>(p)->FlatJSObjectFinalized(cx);
static_cast<XPCWrappedNative*>(p)->FlatJSObjectFinalized();
}
static void
@ -1058,7 +1058,7 @@ XPC_WN_Helper_Finalize(JSContext *cx, JSObject *obj)
if (!wrapper)
return;
wrapper->GetScriptableCallback()->Finalize(wrapper, cx, obj);
wrapper->FlatJSObjectFinalized(cx);
wrapper->FlatJSObjectFinalized();
}
static JSBool

Просмотреть файл

@ -128,15 +128,18 @@ XPCWrappedNativeProto::Init(XPCCallContext& ccx,
mScope->GetPrototypeJSObject(),
true, parent);
JSBool ok = mJSProtoObject && JS_SetPrivate(ccx, mJSProtoObject, this);
JSBool ok = !!mJSProtoObject;
if (ok && callback) {
nsresult rv = callback->PostCreatePrototype(ccx, mJSProtoObject);
if (NS_FAILED(rv)) {
JS_SetPrivate(ccx, mJSProtoObject, nsnull);
mJSProtoObject = nsnull;
XPCThrower::Throw(rv, ccx);
return false;
if (ok) {
JS_SetPrivate(mJSProtoObject, this);
if (callback) {
nsresult rv = callback->PostCreatePrototype(ccx, mJSProtoObject);
if (NS_FAILED(rv)) {
JS_SetPrivate(mJSProtoObject, nsnull);
mJSProtoObject = nsnull;
XPCThrower::Throw(rv, ccx);
return false;
}
}
}
@ -165,7 +168,7 @@ XPCWrappedNativeProto::JSProtoObjectFinalized(JSContext *cx, JSObject *obj)
}
void
XPCWrappedNativeProto::SystemIsBeingShutDown(JSContext* cx)
XPCWrappedNativeProto::SystemIsBeingShutDown()
{
// Note that the instance might receive this call multiple times
// as we walk to here from various places.
@ -181,7 +184,7 @@ XPCWrappedNativeProto::SystemIsBeingShutDown(JSContext* cx)
if (mJSProtoObject) {
// short circuit future finalization
JS_SetPrivate(cx, mJSProtoObject, nsnull);
JS_SetPrivate(mJSProtoObject, nsnull);
mJSProtoObject = nsnull;
}
}

Просмотреть файл

@ -127,9 +127,9 @@ XPCWrappedNativeScope::GetNewOrUsed(XPCCallContext& ccx, JSObject* aGlobal)
scope->SetGlobal(ccx, aGlobal);
}
if (js::GetObjectClass(aGlobal)->flags & JSCLASS_XPCONNECT_GLOBAL)
JS_ALWAYS_TRUE(JS_SetReservedSlot(ccx, aGlobal,
JSCLASS_GLOBAL_SLOT_COUNT,
PRIVATE_TO_JSVAL(scope)));
JS_SetReservedSlot(aGlobal,
JSCLASS_GLOBAL_SLOT_COUNT,
PRIVATE_TO_JSVAL(scope));
return scope;
}
@ -555,10 +555,9 @@ XPCWrappedNativeScope::KillDyingScopes()
struct ShutdownData
{
ShutdownData(JSContext* acx)
: cx(acx), wrapperCount(0),
ShutdownData()
: wrapperCount(0),
protoCount(0) {}
JSContext* cx;
int wrapperCount;
int protoCount;
};
@ -571,7 +570,7 @@ WrappedNativeShutdownEnumerator(JSDHashTable *table, JSDHashEntryHdr *hdr,
XPCWrappedNative* wrapper = ((Native2WrappedNativeMap::Entry*)hdr)->value;
if (wrapper->IsValid()) {
wrapper->SystemIsBeingShutDown(data->cx);
wrapper->SystemIsBeingShutDown();
data->wrapperCount++;
}
return JS_DHASH_REMOVE;
@ -583,21 +582,21 @@ WrappedNativeProtoShutdownEnumerator(JSDHashTable *table, JSDHashEntryHdr *hdr,
{
ShutdownData* data = (ShutdownData*) arg;
((ClassInfo2WrappedNativeProtoMap::Entry*)hdr)->value->
SystemIsBeingShutDown(data->cx);
SystemIsBeingShutDown();
data->protoCount++;
return JS_DHASH_REMOVE;
}
//static
void
XPCWrappedNativeScope::SystemIsBeingShutDown(JSContext* cx)
XPCWrappedNativeScope::SystemIsBeingShutDown()
{
DEBUG_TrackScopeTraversal();
DEBUG_TrackScopeShutdown();
int liveScopeCount = 0;
ShutdownData data(cx);
ShutdownData data;
XPCWrappedNativeScope* cur;
@ -620,12 +619,6 @@ XPCWrappedNativeScope::SystemIsBeingShutDown(JSContext* cx)
if (cur->mComponents)
cur->mComponents->SystemIsBeingShutDown();
JSAutoEnterCompartment ac;
// XXX: What if we have no global in the scope???
if (cur->mGlobalJSObject)
ac.enter(cx, cur->mGlobalJSObject);
// Walk the protos first. Wrapper shutdown can leave dangling
// proto pointers in the proto map.
cur->mWrappedNativeProtoMap->

Просмотреть файл

@ -414,7 +414,7 @@ interface_hasInstance(JSContext *cx, JSObject *obj, const JS::Value *vp, JSBool
} else {
JSObject *protoObj = JSVAL_TO_OBJECT(prototype);
JSObject *proto = other;
while ((proto = JS_GetPrototype(cx, proto))) {
while ((proto = JS_GetPrototype(proto))) {
if (proto == protoObj) {
*bp = true;
return true;
@ -759,7 +759,7 @@ ListBase<LC>::ensureExpandoObject(JSContext *cx, JSObject *obj)
return NULL;
js::SetProxyExtra(obj, JSPROXYSLOT_EXPANDO, ObjectValue(*expando));
JS_SetPrivate(cx, expando, js::GetProxyPrivate(obj).toPrivate());
JS_SetPrivate(expando, js::GetProxyPrivate(obj).toPrivate());
}
return expando;
}

Просмотреть файл

@ -138,14 +138,10 @@ nsXPConnect::~nsXPConnect()
XPCPerThreadData::CleanupAllThreads();
mShuttingDown = true;
if (cx) {
JS_BeginRequest(cx);
// XXX Call even if |mRuntime| null?
XPCWrappedNativeScope::SystemIsBeingShutDown(cx);
XPCWrappedNativeScope::SystemIsBeingShutDown();
mRuntime->SystemIsBeingShutDown(cx);
JS_EndRequest(cx);
mRuntime->SystemIsBeingShutDown();
JS_DestroyContext(cx);
}

Просмотреть файл

@ -762,7 +762,7 @@ public:
void DebugDump(PRInt16 depth);
void SystemIsBeingShutDown(JSContext* cx);
void SystemIsBeingShutDown();
PRThread* GetThreadRunningGC() const {return mThreadRunningGC;}
@ -1545,7 +1545,7 @@ public:
}
static void
SystemIsBeingShutDown(JSContext* cx);
SystemIsBeingShutDown();
static void
TraceJS(JSTracer* trc, XPCJSRuntime* rt);
@ -2281,7 +2281,7 @@ public:
void JSProtoObjectFinalized(JSContext *cx, JSObject *obj);
void SystemIsBeingShutDown(JSContext* cx);
void SystemIsBeingShutDown();
void DebugDump(PRInt16 depth);
@ -2632,9 +2632,9 @@ public:
nsISupports* aCOMObj,
XPCWrappedNative** aWrapper);
void FlatJSObjectFinalized(JSContext *cx);
void FlatJSObjectFinalized();
void SystemIsBeingShutDown(JSContext* cx);
void SystemIsBeingShutDown();
enum CallMode {CALL_METHOD, CALL_GETTER, CALL_SETTER};

Просмотреть файл

@ -456,7 +456,7 @@ JSObject *
WrapperFactory::WrapSOWObject(JSContext *cx, JSObject *obj)
{
JSObject *wrapperObj =
Wrapper::New(cx, obj, JS_GetPrototype(cx, obj), JS_GetGlobalForObject(cx, obj),
Wrapper::New(cx, obj, JS_GetPrototype(obj), JS_GetGlobalForObject(cx, obj),
&FilteringWrapper<SameCompartmentSecurityWrapper,
OnlyIfSubjectIsSystem>::singleton);
return wrapperObj;

Просмотреть файл

@ -2022,7 +2022,7 @@ nsCrypto::GenerateCRMFRequest(nsIDOMCRMFObject** aReturn)
args->m_cx = cx;
args->m_kungFuDeathGrip = GetISupportsFromContext(cx);
args->m_scope = JS_GetParent(cx, script_obj);
args->m_scope = JS_GetParent(script_obj);
args->m_jsCallback.Adopt(!!jsCallback ? nsCRT::strdup(jsCallback.ptr()) : 0);
args->m_principals = principals;

Просмотреть файл

@ -119,10 +119,11 @@ InitAndSealCTypesClass(JSContext* cx, JSObject* global)
// Set callbacks for charset conversion and such.
jsval ctypes;
if (!JS_GetProperty(cx, global, "ctypes", &ctypes) ||
!JS_SetCTypesCallbacks(cx, JSVAL_TO_OBJECT(ctypes), &sCallbacks))
if (!JS_GetProperty(cx, global, "ctypes", &ctypes))
return false;
JS_SetCTypesCallbacks(JSVAL_TO_OBJECT(ctypes), &sCallbacks);
// Seal up Object, Function, Array and Error and their prototypes. (This
// single object instance is shared amongst everyone who imports the ctypes
// module.)

Просмотреть файл

@ -286,7 +286,7 @@ JSHistogram_Add(JSContext *cx, uintN argc, jsval *vp)
return JS_FALSE;
}
Histogram *h = static_cast<Histogram*>(JS_GetPrivate(cx, obj));
Histogram *h = static_cast<Histogram*>(JS_GetPrivate(obj));
if (h->histogram_type() == Histogram::BOOLEAN_HISTOGRAM)
h->Add(!!value);
else
@ -303,7 +303,7 @@ JSHistogram_Snapshot(JSContext *cx, uintN argc, jsval *vp)
return JS_FALSE;
}
Histogram *h = static_cast<Histogram*>(JS_GetPrivate(cx, obj));
Histogram *h = static_cast<Histogram*>(JS_GetPrivate(obj));
JSObject *snapshot = JS_NewObject(cx, NULL, NULL, NULL);
if (!snapshot)
return JS_FALSE;
@ -338,8 +338,8 @@ WrapAndReturnHistogram(Histogram *h, JSContext *cx, jsval *ret)
if (!obj)
return NS_ERROR_FAILURE;
*ret = OBJECT_TO_JSVAL(obj);
return (JS_SetPrivate(cx, obj, h)
&& JS_DefineFunction (cx, obj, "add", JSHistogram_Add, 1, 0)
JS_SetPrivate(obj, h);
return (JS_DefineFunction (cx, obj, "add", JSHistogram_Add, 1, 0)
&& JS_DefineFunction (cx, obj, "snapshot", JSHistogram_Snapshot, 1, 0)) ? NS_OK : NS_ERROR_FAILURE;
}