Checking in Ben Turner <bent.mozilla@gmail.com> and timeless's patch to make Gecko use the JS engine's request model to help multithreaded embedders avoid GC races and crashes. bug 176182, r=mrbkap assumed-rs=brendan

git-svn-id: svn://10.0.0.236/trunk@199768 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mrbkap%gmail.com 2006-06-12 22:39:55 +00:00
parent f4b68ea8d7
commit 0b7523274b
33 changed files with 392 additions and 123 deletions

View File

@ -100,6 +100,7 @@ JSRuntime *nsScriptSecurityManager::sRuntime = 0;
static inline const PRUnichar *
JSValIDToString(JSContext *cx, const jsval idval)
{
JSAutoRequest ar(cx);
JSString *str = JS_ValueToString(cx, idval);
if(!str)
return nsnull;
@ -114,6 +115,7 @@ GetScriptContext(JSContext *cx)
inline void SetPendingException(JSContext *cx, const char *aMsg)
{
JSAutoRequest ar(cx);
JSString *str = JS_NewStringCopyZ(cx, aMsg);
if (str)
JS_SetPendingException(cx, STRING_TO_JSVAL(str));
@ -121,6 +123,7 @@ inline void SetPendingException(JSContext *cx, const char *aMsg)
inline void SetPendingException(JSContext *cx, const PRUnichar *aMsg)
{
JSAutoRequest ar(cx);
JSString *str = JS_NewUCStringCopyZ(cx,
NS_REINTERPRET_CAST(const jschar*, aMsg));
if (str)
@ -520,6 +523,8 @@ nsScriptSecurityManager::CheckConnect(JSContext* cx,
nsresult rv = CheckLoadURIFromScript(cx, aTargetURI);
if (NS_FAILED(rv)) return rv;
JSAutoRequest ar(cx);
JSString* propertyName = ::JS_InternString(cx, aPropertyName);
if (!propertyName)
return NS_ERROR_OUT_OF_MEMORY;
@ -2769,6 +2774,7 @@ nsScriptSecurityManager::CheckComponentPermissions(JSContext *cx,
// Look up the policy for this class.
// while this isn't a property we'll treat it as such, using ACCESS_CALL_METHOD
JSAutoRequest ar(cx);
jsval cidVal = STRING_TO_JSVAL(::JS_InternString(cx, cid.get()));
ClassInfoData nameData(nsnull, "ClassID");
@ -3419,6 +3425,8 @@ nsScriptSecurityManager::InitDomainPolicy(JSContext* cx,
if (end)
*end = '\0';
JSAutoRequest ar(cx);
JSString* propertyKey = ::JS_InternString(cx, start);
if (!propertyKey)
return NS_ERROR_OUT_OF_MEMORY;

View File

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

View File

@ -758,6 +758,8 @@ nsScriptLoader::EvaluateScript(nsScriptLoadRequest* aRequest,
// Put the old script back in case it wants to do anything else.
mCurrentScript = oldCurrent;
JSAutoRequest ar(cx);
if (NS_FAILED(rv)) {
::JS_ReportPendingException(cx);
}

View File

@ -1104,6 +1104,7 @@ nsXMLHttpRequest::Open(const nsACString& method, const nsACString& url)
}
if (argc > 2) {
JSAutoRequest ar(cx);
JSBool asyncBool;
::JS_ValueToBoolean(cx, argv[2], &asyncBool);
async = (PRBool)asyncBool;

View File

@ -1423,6 +1423,7 @@ nsEventListenerManager::RegisterScriptEventListener(nsIScriptContext *aContext,
if (cx) {
if (sAddListenerID == JSVAL_VOID) {
JSAutoRequest ar(cx);
sAddListenerID =
STRING_TO_JSVAL(::JS_InternString(cx, "addEventListener"));
}

View File

@ -2381,6 +2381,8 @@ nsHTMLDocument::ScriptWriteCommon(PRBool aNewlineTerminate)
NS_ENSURE_TRUE(argv, NS_ERROR_UNEXPECTED);
if (argc == 1) {
JSAutoRequest ar(cx);
JSString *jsstr = JS_ValueToString(cx, argv[0]);
NS_ENSURE_TRUE(jsstr, NS_ERROR_OUT_OF_MEMORY);
@ -2395,6 +2397,8 @@ nsHTMLDocument::ScriptWriteCommon(PRBool aNewlineTerminate)
nsAutoString string_buffer;
for (i = 0; i < argc; ++i) {
JSAutoRequest ar(cx);
JSString *str = JS_ValueToString(cx, argv[i]);
NS_ENSURE_TRUE(str, NS_ERROR_OUT_OF_MEMORY);

View File

@ -995,6 +995,7 @@ nsXBLBinding::DoInitJSClass(JSContext *cx, JSObject *global, JSObject *obj,
nsCAutoString className(aClassName);
JSObject* parent_proto = nsnull; // If we have an "obj" we can set this
JSAutoRequest ar(cx);
if (obj) {
// Retrieve the current prototype of obj.
parent_proto = ::JS_GetPrototype(cx, obj);

View File

@ -254,6 +254,8 @@ nsXBLDocGlobalObject::GetContext()
JSContext *cx = (JSContext *)mScriptContext->GetNativeContext();
JSAutoRequest ar(cx);
JS_SetErrorReporter(cx, XBL_ProtoErrorReporter);
mJSObject = ::JS_NewObject(cx, &gSharedGlobalClass, nsnull, nsnull);
if (!mJSObject)

View File

@ -136,8 +136,9 @@ nsXBLProtoImplField::InstallMember(nsIScriptContext* aContext,
if (!undefined) {
// Define the evaluated result as a JS property
nsDependentString name(mName);
JSAutoRequest ar(cx);
if (!::JS_DefineUCProperty(cx, scriptObject, NS_REINTERPRET_CAST(const jschar*, mName),
name.Length(), result, nsnull, nsnull, mJSAttributes))
name.Length(), result, nsnull, nsnull, mJSAttributes))
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -155,6 +155,7 @@ nsXBLProtoImplMethod::InstallMember(nsIScriptContext* aContext,
// now we want to reevaluate our property using aContext and the script object for this window...
if (mJSMethodObject && targetClassObject) {
nsDependentString name(mName);
JSAutoRequest ar(cx);
JSObject * method = ::JS_CloneFunctionObject(cx, mJSMethodObject, globalObject);
if (!method) {
return NS_ERROR_OUT_OF_MEMORY;
@ -319,14 +320,14 @@ nsXBLProtoImplAnonymousMethod::Execute(nsIContent* aBoundElement)
rv = wrapper->GetJSObject(&thisObject);
NS_ENSURE_SUCCESS(rv, rv);
JSAutoRequest ar(cx);
// Clone the function object, using thisObject as the parent so "this" is in
// the scope chain of the resulting function (for backwards compat to the
// days when this was an event handler).
JSObject* method = ::JS_CloneFunctionObject(cx, mJSMethodObject,
thisObject);
if (!method) {
JSObject* method = ::JS_CloneFunctionObject(cx, mJSMethodObject, thisObject);
if (!method)
return NS_ERROR_OUT_OF_MEMORY;
}
// Now call the method

View File

@ -192,6 +192,7 @@ nsXBLProtoImplProperty::InstallMember(nsIScriptContext* aContext,
// now we want to reevaluate our property using aContext and the script object for this window...
if ((mJSGetterObject || mJSSetterObject) && targetClassObject) {
JSObject * getter = nsnull;
JSAutoRequest ar(cx);
if (mJSGetterObject)
if (!(getter = ::JS_CloneFunctionObject(cx, mJSGetterObject, globalObject)))
return NS_ERROR_OUT_OF_MEMORY;

View File

@ -2773,6 +2773,7 @@ nsXULPrototypeScript::Serialize(nsIObjectOutputStream* aStream,
JSScript *script = NS_REINTERPRET_CAST(JSScript*,
::JS_GetPrivate(cx, mJSObject));
JSAutoRequest ar(cx);
if (! ::JS_XDRScript(xdr, &script)) {
rv = NS_ERROR_FAILURE; // likely to be a principals serialization error
} else {
@ -2908,6 +2909,7 @@ nsXULPrototypeScript::Deserialize(nsIObjectInputStream* aStream,
rv = NS_ERROR_OUT_OF_MEMORY;
} else {
xdr->userdata = (void*) aStream;
JSAutoRequest ar(cx);
::JS_XDRMemSetData(xdr, data, size);
JSScript *script = nsnull;

View File

@ -816,6 +816,8 @@ nsXULPDGlobalObject::GetContext()
JSContext *cx = (JSContext *)mScriptContext->GetNativeContext();
JSAutoRequest ar(cx);
mJSObject = ::JS_NewObject(cx, &gSharedGlobalClass, nsnull, nsnull);
if (!mJSObject)
return nsnull;

View File

@ -1357,6 +1357,8 @@ nsDOMClassInfo::DefineStaticJSVals(JSContext *cx)
return NS_ERROR_OUT_OF_MEMORY; \
}
JSAutoRequest ar(cx);
SET_JSVAL_TO_STRING(sTop_id, cx, "top");
SET_JSVAL_TO_STRING(sParent_id, cx, "parent");
SET_JSVAL_TO_STRING(sScrollbars_id, cx, "scrollbars");
@ -1465,6 +1467,8 @@ nsDOMClassInfo::WrapNative(JSContext *cx, JSObject *scope, nsISupports *native,
nsresult
nsDOMClassInfo::ThrowJSException(JSContext *cx, nsresult aResult)
{
JSAutoRequest ar(cx);
do {
nsCOMPtr<nsIExceptionService> xs =
do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID);
@ -3118,6 +3122,8 @@ nsDOMClassInfo::GetArrayIndexFromId(JSContext *cx, jsval id, PRBool *aIsNumber)
*aIsNumber = PR_FALSE;
}
JSAutoRequest ar(cx);
if (!::JS_ValueToNumber(cx, id, &array_index)) {
return -1;
}
@ -3309,6 +3315,8 @@ nsDOMClassInfo::PostCreate(nsIXPConnectWrappedNative *wrapper,
wrapper->GetJSObjectPrototype(&proto);
JSAutoRequest ar(cx);
JSObject *proto_proto = ::JS_GetPrototype(cx, proto);
if (!proto_proto) {
// If our prototype doesn't have a proto, then we've probably already
@ -3444,6 +3452,7 @@ nsDOMClassInfo::ResolveConstructor(JSContext *cx, JSObject *obj,
JSObject *global = GetGlobalJSObject(cx, obj);
jsval val;
JSAutoRequest ar(cx);
if (!::JS_GetProperty(cx, global, mData->mName, &val)) {
return NS_ERROR_UNEXPECTED;
}
@ -3913,6 +3922,7 @@ nsWindowSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
if (!sObjectClass) {
JSObject *obj, *proto = globalObj;
JSAutoRequest ar(cx);
do {
obj = proto;
@ -4092,6 +4102,8 @@ nsWindowSH::InvalidateGlobalScopePolluter(JSContext *cx, JSObject *obj)
{
JSObject *proto;
JSAutoRequest ar(cx);
while ((proto = ::JS_GetPrototype(cx, obj))) {
if (JS_GET_CLASS(cx, proto) == &sGlobalScopePolluterClass) {
nsIHTMLDocument *doc = (nsIHTMLDocument *)::JS_GetPrivate(cx, proto);
@ -4122,6 +4134,8 @@ nsWindowSH::InstallGlobalScopePolluter(JSContext *cx, JSObject *obj,
return NS_OK;
}
JSAutoRequest ar(cx);
JSObject *gsp = ::JS_NewObject(cx, &sGlobalScopePolluterClass, nsnull, obj);
if (!gsp) {
return NS_ERROR_OUT_OF_MEMORY;
@ -4184,18 +4198,23 @@ nsWindowSH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
{
nsGlobalWindow *win = nsGlobalWindow::FromWrapper(wrapper);
JSAutoRequest ar(cx);
#ifdef DEBUG_SH_FORWARDING
{
nsDependentJSString str(::JS_ValueToString(cx, id));
jschar *jsstr = ::JS_ValueToString(cx, id);
if (jsstr) {
nsDependentJSString str(jsstr);
if (win->IsInnerWindow()) {
if (win->IsInnerWindow()) {
#ifdef DEBUG_PRINT_INNER
printf("Property '%s' get on inner window %p\n",
NS_ConvertUTF16toUTF8(str).get(), (void *)win);
printf("Property '%s' get on inner window %p\n",
NS_ConvertUTF16toUTF8(str).get(), (void *)win);
#endif
} else {
printf("Property '%s' get on outer window %p\n",
NS_ConvertUTF16toUTF8(str).get(), (void *)win);
} else {
printf("Property '%s' get on outer window %p\n",
NS_ConvertUTF16toUTF8(str).get(), (void *)win);
}
}
}
#endif
@ -4374,6 +4393,8 @@ nsWindowSH::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
}
if (id == sLocation_id) {
JSAutoRequest ar(cx);
JSString *val = ::JS_ValueToString(cx, *vp);
NS_ENSURE_TRUE(val, NS_ERROR_UNEXPECTED);
@ -5999,6 +6020,8 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
PRBool doSecurityCheckInAddProperty = sDoSecurityCheckInAddProperty;
sDoSecurityCheckInAddProperty = PR_FALSE;
JSAutoRequest ar(my_cx);
JSBool ok = ::JS_ResolveStandardClass(my_cx, obj, id, &did_resolve);
sDoSecurityCheckInAddProperty = doSecurityCheckInAddProperty;
@ -6102,9 +6125,10 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
PRBool doSecurityCheckInAddProperty = sDoSecurityCheckInAddProperty;
sDoSecurityCheckInAddProperty = PR_FALSE;
PRBool ok = ::JS_DefineUCProperty(cx, obj, chars,
::JS_GetStringLength(str), v, nsnull,
nsnull, 0);
JSAutoRequest ar(cx);
PRBool ok = ::JS_DefineUCProperty(cx, obj, chars, ::JS_GetStringLength(str),
v, nsnull, nsnull, 0);
sDoSecurityCheckInAddProperty = doSecurityCheckInAddProperty;
@ -6123,6 +6147,8 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
// for assignment, since only read-write properties get dealt
// with there.
if (!(flags & JSRESOLVE_ASSIGNING)) {
JSAutoRequest ar(cx);
// Call GlobalResolve() after we call FindChildWithName() so
// that named child frames will override external properties
// which have been registered with the script namespace manager.
@ -6146,6 +6172,8 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *windowObj = win->GetGlobalJSObject();
JSAutoRequest ar(cx);
JSFunction *fun = ::JS_NewFunction(cx, ContentWindowGetter, 0, 0,
windowObj, "_content");
if (!fun) {
@ -6204,9 +6232,11 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
PRBool doSecurityCheckInAddProperty = sDoSecurityCheckInAddProperty;
sDoSecurityCheckInAddProperty = PR_FALSE;
JSAutoRequest ar(cx);
JSBool ok = ::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(str),
::JS_GetStringLength(str), v, nsnull,
nsnull, JSPROP_ENUMERATE);
::JS_GetStringLength(str), v, nsnull,
nsnull, JSPROP_ENUMERATE);
sDoSecurityCheckInAddProperty = doSecurityCheckInAddProperty;
@ -6227,14 +6257,14 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
// fully qualified. Define the property on obj with the value
// undefined to override the predefined property. This is done
// for compatibility with other browsers.
JSAutoRequest ar(cx);
if (!::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(str),
::JS_GetStringLength(str),
JSVAL_VOID, nsnull, nsnull,
JSPROP_ENUMERATE)) {
::JS_GetStringLength(str),
JSVAL_VOID, nsnull, nsnull,
JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE;
}
*objp = obj;
return NS_OK;
@ -6251,12 +6281,13 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
getter_AddRefs(holder));
NS_ENSURE_SUCCESS(rv, rv);
JSAutoRequest ar(cx);
if (!::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(str),
::JS_GetStringLength(str), v, nsnull,
nsnull, JSPROP_ENUMERATE)) {
::JS_GetStringLength(str), v, nsnull,
nsnull, JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE;
}
*objp = obj;
return NS_OK;
@ -6285,14 +6316,15 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
win = win->GetOuterWindowInternal();
NS_ENSURE_TRUE(win, NS_ERROR_NOT_AVAILABLE);
JSAutoRequest ar(cx);
if (!::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(str),
::JS_GetStringLength(str),
OBJECT_TO_JSVAL(win->GetGlobalJSObject()),
nsnull, nsnull,
JSPROP_READONLY | JSPROP_ENUMERATE)) {
::JS_GetStringLength(str),
OBJECT_TO_JSVAL(win->GetGlobalJSObject()),
nsnull, nsnull,
JSPROP_READONLY | JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE;
}
*objp = obj;
return NS_OK;
@ -6958,6 +6990,8 @@ nsEventReceiverSH::SetProperty(nsIXPConnectWrappedNative *wrapper,
JSContext *cx, JSObject *obj, jsval id,
jsval *vp, PRBool *_retval)
{
JSAutoRequest ar(cx);
if ((::JS_TypeOfValue(cx, *vp) != JSTYPE_FUNCTION && !JSVAL_IS_NULL(*vp)) ||
!JSVAL_IS_STRING(id) || id == sAddEventListener_id) {
return NS_OK;
@ -7154,6 +7188,7 @@ nsGenericArraySH::Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
sCurrentlyEnumerating = PR_TRUE;
jsval len_val;
JSAutoRequest ar(cx);
JSBool ok = ::JS_GetProperty(cx, obj, "length", &len_val);
if (ok && JSVAL_IS_INT(len_val)) {
@ -7531,6 +7566,8 @@ nsDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
PRBool doSecurityCheckInAddProperty = sDoSecurityCheckInAddProperty;
sDoSecurityCheckInAddProperty = PR_FALSE;
JSAutoRequest ar(cx);
JSString *str = JSVAL_TO_STRING(id);
JSBool ok = ::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(str),
::JS_GetStringLength(str), v, nsnull,
@ -7627,6 +7664,8 @@ nsDocumentSH::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
NS_ENSURE_SUCCESS(rv, rv);
if (location) {
JSAutoRequest ar(cx);
JSString *val = ::JS_ValueToString(cx, *vp);
NS_ENSURE_TRUE(val, NS_ERROR_UNEXPECTED);
@ -8280,6 +8319,9 @@ nsHTMLDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
if (!(flags & JSRESOLVE_ASSIGNING)) {
// For native wrappers, do not resolve random names on document
JSAutoRequest ar(cx);
if (!ObjectIsNativeWrapper(cx, obj)) {
nsCOMPtr<nsISupports> result;
@ -8405,6 +8447,8 @@ nsHTMLDocumentSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
nsCOMPtr<nsISupports> result;
JSAutoRequest ar(cx);
rv = ResolveImpl(cx, wrapper, id, getter_AddRefs(result));
NS_ENSURE_SUCCESS(rv, rv);
@ -8460,6 +8504,7 @@ nsHTMLElementSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
{
if (id == sScrollIntoView_id && !(JSRESOLVE_ASSIGNING & flags)) {
JSString *str = JSVAL_TO_STRING(id);
JSAutoRequest ar(cx);
JSFunction *cfnc =
::JS_DefineFunction(cx, obj, ::JS_GetStringBytes(str), ScrollIntoView,
0, 0);
@ -8619,6 +8664,7 @@ nsHTMLFormElementSH::NewResolve(nsIXPConnectWrappedNative *wrapper,
FindNamedItem(form, str, getter_AddRefs(result));
if (result) {
JSAutoRequest ar(cx);
*_retval = ::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(str),
::JS_GetStringLength(str),
JSVAL_VOID, nsnull, nsnull, 0);
@ -8730,6 +8776,9 @@ nsHTMLFormElementSH::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
// If name is not there, use index instead
attr.AppendInt(index);
}
JSAutoRequest ar(cx);
JSString *jsname =
JS_NewUCStringCopyN(cx, NS_REINTERPRET_CAST(const jschar *,
attr.get()),
@ -8793,9 +8842,10 @@ nsresult
nsHTMLSelectElementSH::SetOption(JSContext *cx, jsval *vp, PRUint32 aIndex,
nsIDOMNSHTMLOptionCollection *aOptCollection)
{
JSAutoRequest ar(cx);
// vp must refer to an object
if (!JSVAL_IS_OBJECT(*vp) && !::JS_ConvertValue(cx, *vp, JSTYPE_OBJECT,
vp)) {
if (!JSVAL_IS_OBJECT(*vp) && !::JS_ConvertValue(cx, *vp, JSTYPE_OBJECT, vp)) {
return NS_ERROR_UNEXPECTED;
}
@ -8876,6 +8926,8 @@ IsObjInProtoChain(JSContext *cx, JSObject *obj, JSObject *proto)
{
JSObject *o = obj;
JSAutoRequest ar(cx);
while (o) {
JSObject *p = ::JS_GetPrototype(cx, o);
@ -8944,6 +8996,8 @@ nsHTMLExternalObjSH::PostCreate(nsIXPConnectWrappedNative *wrapper,
rv = wrapper->GetJSObjectPrototype(&my_proto);
NS_ENSURE_SUCCESS(rv, rv);
JSAutoRequest ar(cx);
// Set 'this.__proto__' to pi
if (!::JS_SetPrototype(cx, obj, pi_obj)) {
return NS_ERROR_UNEXPECTED;
@ -9022,6 +9076,8 @@ nsHTMLExternalObjSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
JSContext *cx, JSObject *obj, jsval id,
jsval *vp, PRBool *_retval)
{
JSAutoRequest ar(cx);
JSObject *pi_obj = ::JS_GetPrototype(cx, obj);
const jschar *id_chars = nsnull;
@ -9064,6 +9120,8 @@ nsHTMLExternalObjSH::SetProperty(nsIXPConnectWrappedNative *wrapper,
JSContext *cx, JSObject *obj, jsval id,
jsval *vp, PRBool *_retval)
{
JSAutoRequest ar(cx);
JSObject *pi_obj = ::JS_GetPrototype(cx, obj);
const jschar *id_chars = nsnull;
@ -9129,6 +9187,7 @@ nsHTMLExternalObjSH::Call(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
// XPConnect passes us the XPConnect wrapper JSObject as obj, and
// not the 'this' parameter that the JS engine passes in. Pass in
// the real this parameter from JS (argv[-1]) here.
JSAutoRequest ar(cx);
*_retval = ::JS_CallFunctionValue(cx, JSVAL_TO_OBJECT(argv[-1]),
OBJECT_TO_JSVAL(pi_obj), argc, argv, vp);
@ -9403,6 +9462,9 @@ nsHTMLOptionsCollectionSH::NewResolve(nsIXPConnectWrappedNative *wrapper,
{
if (id == sAdd_id) {
JSString *str = JSVAL_TO_STRING(id);
JSAutoRequest ar(cx);
JSFunction *fnc =
::JS_DefineFunction(cx, obj, ::JS_GetStringBytes(str),
Add, 0, JSPROP_ENUMERATE);
@ -9615,6 +9677,8 @@ nsStringArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
// XXX: Null strings?
JSAutoRequest ar(cx);
JSString *str =
::JS_NewUCStringCopyN(cx, NS_REINTERPRET_CAST(const jschar *, val.get()),
val.Length());

View File

@ -53,6 +53,7 @@
#include "nsXPIDLString.h"
#include "nsJSUtils.h"
#include "prmem.h"
#include "jsapi.h" // for JSAutoRequest
#include "jsdbgapi.h" // for JS_ClearWatchPointsForObject
#include "nsReadableUtils.h"
#include "nsDOMClassInfo.h"
@ -560,9 +561,9 @@ nsGlobalWindow::FreeInnerObjects(JSContext *cx)
mDoc = nsnull;
if (mJSObject && cx) {
JSAutoRequest ar(cx);
::JS_ClearScope(cx, mJSObject);
::JS_ClearWatchPointsForObject(cx, mJSObject);
nsWindowSH::InvalidateGlobalScopePolluter(cx, mJSObject);
}
}
@ -867,6 +868,8 @@ WindowStateHolder::~WindowStateHolder()
return;
}
JSAutoRequest ar(cx);
mInnerWindow->FreeInnerObjects(cx);
if (mLocation) {
@ -1066,6 +1069,8 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
PRUint32 flags = 0;
JSAutoRequest ar(cx);
// Make sure to clear scope on the outer window *before* we
// initialize the new inner window. If we don't, things
// (Object.prototype etc) could leak from the old outer to the new
@ -1178,6 +1183,9 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
// calling scope.
NS_ASSERTION(!currentInner->IsFrozen(),
"How does this opened window get into session history");
JSAutoRequest ar(cx);
callerScx->SetTerminationFunction(ClearWindowScope,
NS_STATIC_CAST(nsIDOMWindow *,
currentInner));
@ -1190,6 +1198,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
// held in the bfcache.
if (!currentInner->IsFrozen()) {
if (!termFuncSet) {
JSAutoRequest ar(cx);
::JS_ClearScope(cx, currentInner->mJSObject);
::JS_ClearWatchPointsForObject(cx, currentInner->mJSObject);
}
@ -1210,6 +1219,8 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
// Loading a new page and creating a new inner window, *not*
// restoring from session history.
JSAutoRequest ar(cx);
// InitClassesWithNewWrappedGlobal() for the new inner window
// sets the global object in cx to be the new wrapped global. We
// don't want that, but re-initializing the outer window will
@ -1313,6 +1324,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
// case we don't clear the inner window's scope, but we must
// make sure the cached document property gets updated.
JSAutoRequest ar(cx);
::JS_DeleteProperty(cx, currentInner->mJSObject, "document");
} else {
rv = newInnerWindow->SetNewDocument(aDocument, nsnull,
@ -1328,6 +1340,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
JSObject *nav;
navigatorHolder->GetJSObject(&nav);
JSAutoRequest ar(cx);
::JS_DefineProperty(cx, newInnerWindow->mJSObject, "navigator",
OBJECT_TO_JSVAL(nav), nsnull, nsnull,
JSPROP_ENUMERATE);
@ -1336,7 +1349,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
if (mArguments) {
jsval args = OBJECT_TO_JSVAL(mArguments);
JSAutoRequest ar(cx);
::JS_SetProperty(cx, newInnerWindow->mJSObject, "arguments",
&args);
@ -1383,6 +1396,7 @@ nsGlobalWindow::SetDocShell(nsIDocShell* aDocShell)
nsGlobalWindow *currentInner = GetCurrentInnerWindowInternal();
if (currentInner) {
JSAutoRequest ar(cx);
currentInner->FreeInnerObjects(cx);
NS_ASSERTION(mDoc, "Must have doc!");
@ -1687,6 +1701,8 @@ nsGlobalWindow::SetNewArguments(PRUint32 aArgc, void* aArgv)
(cx = (JSContext *)mContext->GetNativeContext()),
NS_ERROR_NOT_INITIALIZED);
JSAutoRequest ar(cx);
if (mArguments) {
::JS_UnlockGCThing(cx, mArguments);
mArguments = nsnull;
@ -3315,18 +3331,18 @@ nsGlobalWindow::Prompt(nsAString& aReturn)
PRUint32 savePassword = nsIAuthPrompt::SAVE_PASSWORD_NEVER;
if (argc > 0) {
nsJSUtils::ConvertJSValToString(message, cx, argv[0]);
if (argc > 1) {
nsJSUtils::ConvertJSValToString(initial, cx, argv[1]);
if (argc > 2) {
JSAutoRequest ar(cx);
switch (argc) {
default:
case 4:
nsJSUtils::ConvertJSValToUint32(&savePassword, cx, argv[3]);
case 3:
nsJSUtils::ConvertJSValToString(title, cx, argv[2]);
if (argc > 3) {
nsJSUtils::ConvertJSValToUint32(&savePassword, cx, argv[3]);
}
}
case 2:
nsJSUtils::ConvertJSValToString(initial, cx, argv[1]);
case 1:
nsJSUtils::ConvertJSValToString(message, cx, argv[0]);
break;
}
}
@ -4149,14 +4165,16 @@ nsGlobalWindow::Open(nsIDOMWindow **_retval)
ncc->GetArgvPtr(&argv);
if (argc > 0) {
nsJSUtils::ConvertJSValToString(url, cx, argv[0]);
if (argc > 1) {
nsJSUtils::ConvertJSValToString(name, cx, argv[1]);
if (argc > 2) {
JSAutoRequest ar(cx);
switch (argc) {
default:
case 3:
nsJSUtils::ConvertJSValToString(options, cx, argv[2]);
}
case 2:
nsJSUtils::ConvertJSValToString(name, cx, argv[1]);
case 1:
nsJSUtils::ConvertJSValToString(url, cx, argv[0]);
break;
}
}
@ -4212,14 +4230,16 @@ nsGlobalWindow::OpenDialog(nsIDOMWindow** _retval)
ncc->GetArgvPtr(&argv);
if (argc > 0) {
nsJSUtils::ConvertJSValToString(url, cx, argv[0]);
if (argc > 1) {
nsJSUtils::ConvertJSValToString(name, cx, argv[1]);
if (argc > 2) {
JSAutoRequest ar(cx);
switch (argc) {
default:
case 3:
nsJSUtils::ConvertJSValToString(options, cx, argv[2]);
}
case 2:
nsJSUtils::ConvertJSValToString(name, cx, argv[1]);
case 1:
nsJSUtils::ConvertJSValToString(url, cx, argv[0]);
break;
}
}
@ -4639,38 +4659,44 @@ nsGlobalWindow::Find(PRBool *aDidFind)
PRBool searchInFrames = PR_FALSE;
if (argc > 0) {
// First arg is the search pattern
nsJSUtils::ConvertJSValToString(searchStr, cx, argv[0]);
}
if (argc > 1 && !JS_ValueToBoolean(cx, argv[1], &caseSensitive)) {
// Second arg is the case sensitivity
caseSensitive = PR_FALSE;
}
if (argc > 2 && !JS_ValueToBoolean(cx, argv[2], &backwards)) {
// Third arg specifies whether to search backwards
backwards = PR_FALSE;
}
if (argc > 3 && !JS_ValueToBoolean(cx, argv[3], &wrapAround)) {
// Fourth arg specifies whether we should wrap the search
wrapAround = PR_FALSE;
}
if (argc > 4 && !JS_ValueToBoolean(cx, argv[4], &wholeWord)) {
// Fifth arg specifies whether we should show the Find dialog
wholeWord = PR_FALSE;
}
if (argc > 5 && !JS_ValueToBoolean(cx, argv[5], &searchInFrames)) {
// Sixth arg specifies whether we should search only for whole words
searchInFrames = PR_FALSE;
}
if (argc > 6 && !JS_ValueToBoolean(cx, argv[6], &showDialog)) {
// Seventh arg specifies whether we should search in all frames
showDialog = PR_FALSE;
JSAutoRequest ar(cx);
switch (argc) {
default:
case 7:
if (!JS_ValueToBoolean(cx, argv[6], &showDialog)) {
// Seventh arg specifies whether we should search in all frames
showDialog = PR_FALSE;
}
case 6:
if (!JS_ValueToBoolean(cx, argv[5], &searchInFrames)) {
// Sixth arg specifies whether we should search only for whole words
searchInFrames = PR_FALSE;
}
case 5:
if (!JS_ValueToBoolean(cx, argv[4], &wholeWord)) {
// Fifth arg specifies whether we should show the Find dialog
wholeWord = PR_FALSE;
}
case 4:
if (!JS_ValueToBoolean(cx, argv[3], &wrapAround)) {
// Fourth arg specifies whether we should wrap the search
wrapAround = PR_FALSE;
}
case 3:
if (!JS_ValueToBoolean(cx, argv[2], &backwards)) {
// Third arg specifies whether to search backwards
backwards = PR_FALSE;
}
case 2:
if (!JS_ValueToBoolean(cx, argv[1], &caseSensitive)) {
// Second arg is the case sensitivity
caseSensitive = PR_FALSE;
}
case 1:
// First arg is the search pattern
nsJSUtils::ConvertJSValToString(searchStr, cx, argv[0]);
break;
}
}
return FindInternal(searchStr, caseSensitive, backwards, wrapAround,
@ -5195,6 +5221,8 @@ nsGlobalWindow::GetObjectProperty(const PRUnichar *aProperty,
jsval propertyVal;
JSAutoRequest ar(cx);
if (!::JS_LookupUCProperty(cx, mJSObject,
NS_REINTERPRET_CAST(const jschar *, aProperty),
nsCRT::strlen(aProperty), &propertyVal)) {
@ -5921,6 +5949,8 @@ nsGlobalWindow::ClearWindowScope(nsISupports *aWindow)
JSContext *cx = (JSContext *)scx->GetNativeContext();
JSObject *global = sgo->GetGlobalJSObject();
JSAutoRequest ar(cx);
if (global) {
::JS_ClearScope(cx, global);
::JS_ClearWatchPointsForObject(cx, global);
@ -5976,6 +6006,8 @@ nsGlobalWindow::SetTimeoutOrInterval(PRBool aIsInterval, PRInt32 *aReturn)
nsTimeout *timeout;
int32 interval = 0;
JSAutoRequest ar(cx);
if (argc < 1) {
::JS_ReportError(cx, "Function %s requires at least 1 parameter",
aIsInterval ? kSetIntervalStr : kSetTimeoutStr);
@ -6049,7 +6081,7 @@ nsGlobalWindow::SetTimeoutOrInterval(PRBool aIsInterval, PRInt32 *aReturn)
timeout->mExpr = expr;
} else if (funobj) {
/* Leave an extra slot for a secret final argument that
indicates to the called function how "late" the timeout is. */
indicates to the called function how "late" the timeout is. */
timeout->mArgv = (jsval *) PR_MALLOC((argc - 1) * sizeof(jsval));
if (!timeout->mArgv) {
@ -6608,6 +6640,8 @@ nsGlobalWindow::ClearTimeoutOrInterval()
int32 timer_id;
JSAutoRequest ar(cx);
if (argv[0] == JSVAL_VOID || !::JS_ValueToInt32(cx, argv[0], &timer_id) ||
timer_id <= 0) {
// Undefined or non-positive number passed as argument, return
@ -7806,6 +7840,8 @@ nsNavigator::Preference()
rv = ncc->GetJSContext(&cx);
NS_ENSURE_SUCCESS(rv, rv);
JSAutoRequest ar(cx);
//--Check to see if the caller is allowed to access prefs
if (sPrefInternal_id == JSVAL_VOID) {
sPrefInternal_id =
@ -7814,9 +7850,9 @@ nsNavigator::Preference()
PRUint32 action;
if (argc == 1) {
action = nsIXPCSecurityManager::ACCESS_GET_PROPERTY;
action = nsIXPCSecurityManager::ACCESS_GET_PROPERTY;
} else {
action = nsIXPCSecurityManager::ACCESS_SET_PROPERTY;
action = nsIXPCSecurityManager::ACCESS_SET_PROPERTY;
}
rv = nsContentUtils::GetSecurityManager()->

View File

@ -880,8 +880,11 @@ nsJSContext::EvaluateStringWithValue(const nsAString& aScript,
if (ok) {
JSVersion oldVersion = JSVERSION_UNKNOWN;
JSAutoRequest ar(mContext);
if (aVersion)
oldVersion = ::JS_SetVersion(mContext, newVersion);
ok = ::JS_EvaluateUCScriptForPrincipals(mContext,
(JSObject *)aScopeObject,
jsprin,
@ -1064,8 +1067,11 @@ nsJSContext::EvaluateString(const nsAString& aScript,
if (ok) {
JSVersion oldVersion = JSVERSION_UNKNOWN;
JSAutoRequest ar(mContext);
if (aVersion)
oldVersion = ::JS_SetVersion(mContext, newVersion);
ok = ::JS_EvaluateUCScriptForPrincipals(mContext,
(JSObject *)aScopeObject,
jsprin,
@ -1094,6 +1100,7 @@ nsJSContext::EvaluateString(const nsAString& aScript,
// If all went well, convert val to a string (XXXbe unless undefined?).
if (ok) {
JSAutoRequest ar(mContext);
rv = JSValueToAString(mContext, val, aRetValue, aIsUndefined);
}
else {
@ -1156,6 +1163,9 @@ nsJSContext::CompileScript(const PRUnichar* aText,
if (!aVersion ||
(newVersion = ::JS_StringToVersion(aVersion)) != JSVERSION_UNKNOWN) {
JSVersion oldVersion = JSVERSION_UNKNOWN;
JSAutoRequest ar(mContext);
if (aVersion)
oldVersion = ::JS_SetVersion(mContext, newVersion);
@ -1173,8 +1183,7 @@ nsJSContext::CompileScript(const PRUnichar* aText,
::JS_DestroyScript(mContext, script);
script = nsnull;
}
}
if (!script)
} else
rv = NS_ERROR_OUT_OF_MEMORY;
if (aVersion)
@ -1228,6 +1237,7 @@ nsJSContext::ExecuteScript(void* aScriptObject,
JSBool ok;
nsJSContext::TerminationFuncHolder holder(this);
JSAutoRequest ar(mContext);
ok = ::JS_ExecuteScript(mContext,
(JSObject*) aScopeObject,
(JSScript*) ::JS_GetPrivate(mContext,
@ -1236,7 +1246,6 @@ nsJSContext::ExecuteScript(void* aScriptObject,
if (ok) {
// If all went well, convert val to a string (XXXbe unless undefined?).
rv = JSValueToAString(mContext, val, aRetValue, aIsUndefined);
} else {
if (aIsUndefined) {
@ -1325,6 +1334,8 @@ nsJSContext::CompileEventHandler(void *aTarget, nsIAtom *aName,
const char *argList[] = { aEventName };
JSAutoRequest ar(mContext);
JSFunction* fun =
::JS_CompileUCFunctionForPrincipals(mContext,
aShared ? nsnull : target, jsprin,
@ -1374,6 +1385,9 @@ nsJSContext::CompileFunction(void* aTarget,
}
JSObject *target = (JSObject*)aTarget;
JSAutoRequest ar(mContext);
JSFunction* fun =
::JS_CompileUCFunctionForPrincipals(mContext,
aShared ? nsnull : target, jsprin,
@ -1422,8 +1436,10 @@ nsJSContext::CallEventHandler(JSObject *aTarget, JSObject *aHandler,
if (NS_SUCCEEDED(rv)) {
jsval funval = OBJECT_TO_JSVAL(aHandler);
PRBool ok = ::JS_CallFunctionValue(mContext, aTarget, funval, argc, argv,
rval);
JSAutoRequest ar(mContext);
PRBool ok = ::JS_CallFunctionValue(mContext, aTarget, funval, argc, argv, rval);
if (!ok) {
// Tell XPConnect about any pending exceptions. This is needed
@ -1443,6 +1459,8 @@ nsJSContext::CallEventHandler(JSObject *aTarget, JSObject *aHandler,
if (NS_FAILED(stack->Pop(nsnull)))
return NS_ERROR_FAILURE;
JSAutoRequest ar(mContext);
// Need to lock, since ScriptEvaluated can GC.
PRBool locked = PR_FALSE;
if (NS_SUCCEEDED(rv) && JSVAL_IS_GCTHING(*rval)) {
@ -1483,6 +1501,8 @@ nsJSContext::BindCompiledEventHandler(void *aTarget, nsIAtom *aName,
return NS_ERROR_FAILURE;
}
JSAutoRequest ar(mContext);
// Make sure the handler function is parented by its event target object
if (funobj && ::JS_GetParent(mContext, funobj) != target) {
funobj = ::JS_CloneFunctionObject(mContext, funobj, target);
@ -1623,6 +1643,7 @@ nsJSContext::InitContext(nsIScriptGlobalObject *aGlobalObject)
// Now check whether we need to grab a pointer to the
// XPCNativeWrapper class
if (!NS_DOMClassInfo_GetXPCNativeWrapperClass()) {
JSAutoRequest ar(mContext);
rv = FindXPCNativeWrapperClass(holder);
NS_ENSURE_SUCCESS(rv, rv);
}
@ -1691,6 +1712,7 @@ nsJSContext::InitializeLiveConnectClasses(JSObject *aGlobalObj)
do_QueryInterface(jvmManager);
if (liveConnectManager) {
JSAutoRequest ar(mContext);
rv = liveConnectManager->InitLiveConnectClasses(mContext, aGlobalObj);
}
}
@ -1994,6 +2016,8 @@ nsJSContext::InitClasses(JSObject *aGlobalObj)
rv = InitializeLiveConnectClasses(aGlobalObj);
NS_ENSURE_SUCCESS(rv, rv);
JSAutoRequest ar(mContext);
// Initialize the options object and set default options in mContext
JSObject *optionsObj = ::JS_DefineObject(mContext, aGlobalObj, "_options",
&OptionsClass, nsnull, 0);

View File

@ -902,6 +902,7 @@ nsLocation::Reload()
rv = ncc->GetJSContext(&cx);
NS_ENSURE_SUCCESS(rv, rv);
JSAutoRequest ar(cx);
JS_ValueToBoolean(cx, argv[0], &force_get);
}

View File

@ -270,6 +270,7 @@ nsPluginArray::Refresh()
rv = ncc->GetJSContext(&cx);
NS_ENSURE_SUCCESS(rv, rv);
JSAutoRequest ar(cx);
JS_ValueToBoolean(cx, argv[0], &reload_doc);
}

View File

@ -60,6 +60,8 @@ nsJSEventListener::nsJSEventListener(nsIScriptContext *aContext,
if (aScopeObject && aContext) {
JSContext *cx = (JSContext *)aContext->GetNativeContext();
JSAutoRequest ar(cx);
::JS_LockGCThing(cx, aScopeObject);
}
}
@ -69,6 +71,8 @@ nsJSEventListener::~nsJSEventListener()
if (mScopeObject && mContext) {
JSContext *cx = (JSContext *)mContext->GetNativeContext();
JSAutoRequest ar(cx);
::JS_UnlockGCThing(cx, mScopeObject);
}
}
@ -138,6 +142,8 @@ nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent)
rv = wrapper->GetJSObject(&obj);
NS_ENSURE_SUCCESS(rv, rv);
JSAutoRequest ar(cx);
if (!JS_LookupUCProperty(cx, obj,
NS_REINTERPRET_CAST(const jschar *,
eventString.get()),
@ -170,7 +176,7 @@ nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent)
if (!handledScriptError) {
rv = xpc->WrapNative(cx, obj, aEvent, NS_GET_IID(nsIDOMEvent),
getter_AddRefs(wrapper));
getter_AddRefs(wrapper));
NS_ENSURE_SUCCESS(rv, rv);
JSObject *eventObj = nsnull;
@ -185,9 +191,8 @@ nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent)
rv = mContext->CallEventHandler(obj, JSVAL_TO_OBJECT(funval), argc, argv,
&rval);
if (argv != &arg) {
if (argv != &arg)
::JS_PopArguments(cx, stackPtr);
}
if (NS_SUCCEEDED(rv)) {
if (eventString.EqualsLiteral("onbeforeunload")) {
@ -218,9 +223,8 @@ nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent)
// the usual (false means cancel), then prevent default.
if (JSVAL_TO_BOOLEAN(rval) ==
(mReturnResult == nsReturnResult_eReverseReturnResult)) {
(mReturnResult == nsReturnResult_eReverseReturnResult))
aEvent->PreventDefault();
}
}
}

View File

@ -1979,7 +1979,8 @@ nsWindowWatcher::AddSupportsTojsvals(nsISupports *aArg,
p->GetData(data);
JSAutoRequest ar(cx);
JSString *str = ::JS_NewStringCopyN(cx, data.get(), data.Length());
NS_ENSURE_TRUE(str, NS_ERROR_OUT_OF_MEMORY);
@ -1995,6 +1996,8 @@ nsWindowWatcher::AddSupportsTojsvals(nsISupports *aArg,
p->GetData(data);
JSAutoRequest ar(cx);
// cast is probably safe since wchar_t and jschar are expected
// to be equivalent; both unsigned 16-bit entities
JSString *str =
@ -2062,6 +2065,8 @@ nsWindowWatcher::AddSupportsTojsvals(nsISupports *aArg,
p->GetData(&data);
JSAutoRequest ar(cx);
JSString *str = ::JS_NewStringCopyN(cx, &data, 1);
NS_ENSURE_TRUE(str, NS_ERROR_OUT_OF_MEMORY);
@ -2101,6 +2106,8 @@ nsWindowWatcher::AddSupportsTojsvals(nsISupports *aArg,
p->GetData(&data);
JSAutoRequest ar(cx);
jsdouble *d = ::JS_NewDouble(cx, data);
*aArgv = DOUBLE_TO_JSVAL(d);
@ -2115,6 +2122,8 @@ nsWindowWatcher::AddSupportsTojsvals(nsISupports *aArg,
p->GetData(&data);
JSAutoRequest ar(cx);
jsdouble *d = ::JS_NewDouble(cx, data);
*aArgv = DOUBLE_TO_JSVAL(d);

View File

@ -135,6 +135,8 @@ _newJSDContext(JSRuntime* jsrt,
if( ! jsdc->dumbContext )
goto label_newJSDContext_failure;
JS_BeginRequest(jsdc->dumbContext);
jsdc->glob = JS_NewObject(jsdc->dumbContext, &global_class, NULL, NULL);
if( ! jsdc->glob )
goto label_newJSDContext_failure;
@ -142,6 +144,8 @@ _newJSDContext(JSRuntime* jsrt,
if( ! JS_InitStandardClasses(jsdc->dumbContext, jsdc->glob) )
goto label_newJSDContext_failure;
JS_EndRequest(jsdc->dumbContext);
jsdc->data = NULL;
jsdc->inited = JS_TRUE;
@ -155,6 +159,7 @@ label_newJSDContext_failure:
if( jsdc ) {
jsd_DestroyObjectManager(jsdc);
jsd_DestroyAtomTable(jsdc);
JS_EndRequest(jsdc->dumbContext);
free(jsdc);
}
return NULL;

View File

@ -316,7 +316,9 @@ jsd_GetScopeChainForStackFrame(JSDContext* jsdc,
if( jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe) )
{
JS_BeginRequest(jsdthreadstate->context);
obj = JS_GetFrameScopeChain(jsdthreadstate->context, jsdframe->fp);
JS_EndRequest(jsdthreadstate->context);
if(obj)
jsdval = JSD_NewValue(jsdc, OBJECT_TO_JSVAL(obj));
}

View File

@ -153,15 +153,16 @@ jsd_IsValueNative(JSDContext* jsdc, JSDValue* jsdval)
if(jsd_IsValueFunction(jsdc, jsdval))
{
JSBool ok = JS_FALSE;
JS_BeginRequest(cx);
exceptionState = JS_SaveExceptionState(cx);
fun = JS_ValueToFunction(cx, val);
JS_RestoreExceptionState(cx, exceptionState);
if(!fun)
{
JS_ASSERT(0);
return JS_FALSE;
}
return JS_GetFunctionScript(cx, fun) ? JS_FALSE : JS_TRUE;
if(fun)
ok = JS_GetFunctionScript(cx, fun) ? JS_TRUE : JS_FALSE;
JS_EndRequest(cx);
JS_ASSERT(fun);
return ok;
}
return !JSVAL_IS_PRIMITIVE(val);
}
@ -208,6 +209,7 @@ jsd_GetValueString(JSDContext* jsdc, JSDValue* jsdval)
jsdval->string = JSVAL_TO_STRING(jsdval->val);
else
{
JS_BeginRequest(cx);
exceptionState = JS_SaveExceptionState(cx);
jsdval->string = JS_ValueToString(cx, jsdval->val);
JS_RestoreExceptionState(cx, exceptionState);
@ -216,6 +218,7 @@ jsd_GetValueString(JSDContext* jsdc, JSDValue* jsdval)
if(!JS_AddNamedRoot(cx, &jsdval->string, "ValueString"))
jsdval->string = NULL;
}
JS_EndRequest(cx);
}
}
return jsdval->string;
@ -230,9 +233,11 @@ jsd_GetValueFunctionName(JSDContext* jsdc, JSDValue* jsdval)
if(!jsdval->funName && jsd_IsValueFunction(jsdc, jsdval))
{
JS_BeginRequest(cx);
exceptionState = JS_SaveExceptionState(cx);
fun = JS_ValueToFunction(cx, jsdval->val);
JS_RestoreExceptionState(cx, exceptionState);
JS_EndRequest(cx);
if(!fun)
return NULL;
jsdval->funName = JS_GetFunctionName(fun);
@ -252,7 +257,11 @@ jsd_NewValue(JSDContext* jsdc, jsval val)
if(JSVAL_IS_GCTHING(val))
{
if(!JS_AddNamedRoot(jsdc->dumbContext, &jsdval->val, "JSDValue"))
JSBool ok = JS_FALSE;
JS_BeginRequest(jsdc->dumbContext);
ok = JS_AddNamedRoot(jsdc->dumbContext, &jsdval->val, "JSDValue");
JS_EndRequest(jsdc->dumbContext);
if(!ok)
{
free(jsdval);
return NULL;
@ -273,7 +282,11 @@ jsd_DropValue(JSDContext* jsdc, JSDValue* jsdval)
{
jsd_RefreshValue(jsdc, jsdval);
if(JSVAL_IS_GCTHING(jsdval->val))
{
JS_BeginRequest(jsdc->dumbContext);
JS_RemoveRoot(jsdc->dumbContext, &jsdval->val);
JS_EndRequest(jsdc->dumbContext);
}
free(jsdval);
}
}
@ -340,8 +353,12 @@ static JSBool _buildProps(JSDContext* jsdc, JSDValue* jsdval)
if(!JSVAL_IS_OBJECT(jsdval->val) || JSVAL_IS_NULL(jsdval->val))
return JS_FALSE;
JS_BeginRequest(cx);
if(!JS_GetPropertyDescArray(cx, JSVAL_TO_OBJECT(jsdval->val), &pda))
{
JS_EndRequest(cx);
return JS_FALSE;
}
for(i = 0; i < pda.length; i++)
{
@ -354,6 +371,7 @@ static JSBool _buildProps(JSDContext* jsdc, JSDValue* jsdval)
JS_APPEND_LINK(&prop->links, &jsdval->props);
}
JS_PutPropertyDescArray(cx, &pda);
JS_EndRequest(cx);
SET_BIT_FLAG(jsdval->flags, GOT_PROPS);
return !JS_CLIST_IS_EMPTY(&jsdval->props);
}
@ -370,7 +388,11 @@ jsd_RefreshValue(JSDContext* jsdc, JSDValue* jsdval)
{
/* if the jsval is a string, then we didn't need to root the string */
if(!JSVAL_IS_STRING(jsdval->val))
{
JS_BeginRequest(cx);
JS_RemoveRoot(cx, &jsdval->string);
JS_EndRequest(cx);
}
jsdval->string = NULL;
}
@ -459,9 +481,14 @@ jsd_GetValueProperty(JSDContext* jsdc, JSDValue* jsdval, JSString* name)
nameChars = JS_GetStringChars(name);
nameLen = JS_GetStringLength(name);
JS_BeginRequest(cx);
JS_GetUCPropertyAttributes(cx, obj, nameChars, nameLen, &attrs, &found);
if (!found)
{
JS_EndRequest(cx);
return NULL;
}
JS_ClearPendingException(cx);
@ -470,7 +497,10 @@ jsd_GetValueProperty(JSDContext* jsdc, JSDValue* jsdval, JSString* name)
if (JS_IsExceptionPending(cx))
{
if (!JS_GetPendingException(cx, &pd.value))
{
JS_EndRequest(cx);
return NULL;
}
pd.flags = JSPD_EXCEPTION;
}
else
@ -484,6 +514,8 @@ jsd_GetValueProperty(JSDContext* jsdc, JSDValue* jsdval, JSString* name)
pd.value = val;
}
JS_EndRequest(cx);
pd.id = STRING_TO_JSVAL(name);
pd.alias = pd.slot = pd.spare = 0;
pd.flags |= (attrs & JSPROP_ENUMERATE) ? JSPD_ENUMERATE : 0
@ -507,7 +539,10 @@ jsd_GetValuePrototype(JSDContext* jsdc, JSDValue* jsdval)
return NULL;
if(!(obj = JSVAL_TO_OBJECT(jsdval->val)))
return NULL;
if(!(proto = JS_GetPrototype(jsdc->dumbContext, obj)))
JS_BeginRequest(jsdc->dumbContext);
proto = JS_GetPrototype(jsdc->dumbContext, obj);
JS_EndRequest(jsdc->dumbContext);
if(!proto)
return NULL;
jsdval->proto = jsd_NewValue(jsdc, OBJECT_TO_JSVAL(proto));
}
@ -529,7 +564,10 @@ jsd_GetValueParent(JSDContext* jsdc, JSDValue* jsdval)
return NULL;
if(!(obj = JSVAL_TO_OBJECT(jsdval->val)))
return NULL;
if(!(parent = JS_GetParent(jsdc->dumbContext,obj)))
JS_BeginRequest(jsdc->dumbContext);
parent = JS_GetParent(jsdc->dumbContext,obj);
JS_EndRequest(jsdc->dumbContext);
if(!parent)
return NULL;
jsdval->parent = jsd_NewValue(jsdc, OBJECT_TO_JSVAL(parent));
}
@ -552,9 +590,16 @@ jsd_GetValueConstructor(JSDContext* jsdc, JSDValue* jsdval)
return NULL;
if(!(obj = JSVAL_TO_OBJECT(jsdval->val)))
return NULL;
if(!(proto = JS_GetPrototype(jsdc->dumbContext,obj)))
JS_BeginRequest(jsdc->dumbContext);
proto = JS_GetPrototype(jsdc->dumbContext,obj);
if(!proto)
{
JS_EndRequest(jsdc->dumbContext);
return NULL;
if(!(ctor = JS_GetConstructor(jsdc->dumbContext,proto)))
}
ctor = JS_GetConstructor(jsdc->dumbContext,proto);
JS_EndRequest(jsdc->dumbContext);
if(!ctor)
return NULL;
jsdval->ctor = jsd_NewValue(jsdc, OBJECT_TO_JSVAL(ctor));
}
@ -572,8 +617,10 @@ jsd_GetValueClassName(JSDContext* jsdc, JSDValue* jsdval)
JSObject* obj;
if(!(obj = JSVAL_TO_OBJECT(val)))
return NULL;
JS_BeginRequest(jsdc->dumbContext);
if(JS_GET_CLASS(jsdc->dumbContext, obj))
jsdval->className = JS_GET_CLASS(jsdc->dumbContext, obj)->name;
JS_EndRequest(jsdc->dumbContext);
}
return jsdval->className;
}

View File

@ -1017,6 +1017,7 @@ PCMapEntry *
jsdScript::CreatePPLineMap()
{
JSContext *cx = JSD_GetDefaultJSContext (mCx);
JSAutoRequest ar(cx);
JSObject *obj = JS_NewObject(cx, NULL, NULL, NULL);
JSFunction *fun = JSD_GetJSFunction (mCx, mScript);
JSScript *script;
@ -1262,18 +1263,19 @@ jsdScript::GetFunctionSource(nsAString & aFunctionSource)
return NS_ERROR_FAILURE;
}
JSFunction *fun = JSD_GetJSFunction (mCx, mScript);
JSAutoRequest ar(cx);
JSString *jsstr;
if (fun)
{
jsstr = JS_DecompileFunction (cx, fun, 4);
}
else
{
else {
JSScript *script = JSD_GetJSScript (mCx, mScript);
jsstr = JS_DecompileScript (cx, script, "ppscript", 4);
}
if (!jsstr)
return NS_ERROR_FAILURE;
aFunctionSource = NS_REINTERPRET_CAST(PRUnichar*, JS_GetStringChars(jsstr));
return NS_OK;
}
@ -1911,6 +1913,9 @@ jsdStackFrame::Eval (const nsAString &bytes, const char *fileName,
jsval jv;
JSContext *cx = JSD_GetJSContext (mCx, mThreadState);
JSAutoRequest ar(cx);
estate = JS_SaveExceptionState (cx);
JS_ClearPendingException (cx);
@ -1926,6 +1931,7 @@ jsdStackFrame::Eval (const nsAString &bytes, const char *fileName,
}
JS_RestoreExceptionState (cx, estate);
JSDValue *jsdv = JSD_NewValue (mCx, jv);
if (!jsdv)
return NS_ERROR_FAILURE;
@ -2231,8 +2237,13 @@ jsdValue::GetProperty (const char *name, jsdIProperty **_rval)
{
ASSERT_VALID_EPHEMERAL;
JSContext *cx = JSD_GetDefaultJSContext (mCx);
JSAutoRequest ar(cx);
/* not rooting this */
JSString *jstr_name = JS_NewStringCopyZ (cx, name);
if (!jstr_name)
return NS_ERROR_OUT_OF_MEMORY;
JSDProperty *prop = JSD_GetValueProperty (mCx, mValue, jstr_name);

View File

@ -143,6 +143,7 @@ class mozJSComponentLoader : public nsIModuleLoader,
module = nsnull;
if (global) {
JSAutoRequest ar(sSelf->mContext);
JS_ClearScope(sSelf->mContext, global);
JS_RemoveRoot(sSelf->mContext, &global);
}

View File

@ -137,6 +137,8 @@ mozJSSubScriptLoader::LoadSubScript (const PRUnichar * /*url*/
return rv;
}
JSAutoRequest ar(cx);
char *url;
JSObject *target_obj = nsnull;

View File

@ -1083,12 +1083,19 @@ main(int argc, char **argv, char **envp)
NS_ASSERTION(glob == nsnull, "bad GetJSObject?");
return 1;
}
if (!JS_DefineFunctions(cx, glob, glob_functions))
JS_BeginRequest(cx);
if (!JS_DefineFunctions(cx, glob, glob_functions)) {
JS_EndRequest(cx);
return 1;
}
envobj = JS_DefineObject(cx, glob, "environment", &env_class, NULL, 0);
if (!envobj || !JS_SetPrivate(cx, envobj, envp))
if (!envobj || !JS_SetPrivate(cx, envobj, envp)) {
JS_EndRequest(cx);
return 1;
}
argc--;
argv++;

View File

@ -681,6 +681,8 @@ XPC_NW_NewResolve(JSContext *cx, JSObject *obj, jsval id, uintN flags,
return JS_TRUE;
}
JSAutoRequest ar(cx);
jsid interned_id;
JSObject *pobj;
JSProperty *prop;
@ -865,8 +867,8 @@ XPC_NW_NewResolve(JSContext *cx, JSObject *obj, jsval id, uintN flags,
}
if (!::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(str),
::JS_GetStringLength(str), v, nsnull, nsnull,
attrs)) {
::JS_GetStringLength(str), v, nsnull, nsnull,
attrs)) {
return JS_FALSE;
}

View File

@ -48,6 +48,7 @@
static const char* JSVAL2String(JSContext* cx, jsval val, JSBool* isString)
{
JSAutoRequest ar(cx);
const char* value = nsnull;
JSString* value_str = JS_ValueToString(cx, val);
if(value_str)
@ -89,6 +90,9 @@ static char* FormatJSFrame(JSContext* cx, JSStackFrame* fp,
JSScript* script = JS_GetFrameScript(cx, fp);
jsbytecode* pc = JS_GetFramePC(cx, fp);
JSAutoRequest ar(cx);
if(script && pc)
{
filename = JS_GetScriptFilename(cx, script);
@ -337,6 +341,8 @@ xpc_DumpEvalInJSStackFrame(JSContext* cx, JSUint32 frameno, const char* text)
return JS_FALSE;
}
JSAutoRequest ar(cx);
JSExceptionState* exceptionState = JS_SaveExceptionState(cx);
JSErrorReporter older = JS_SetErrorReporter(cx, xpcDumpEvalErrorReporter);

View File

@ -915,7 +915,10 @@ XPCJSRuntime::SyncXPCContextList(JSContext* cx /* = nsnull */)
// if it is our first context then we need to generate our string ids
if(!mStrIDs[0])
{
JSAutoRequest ar(cur);
GenerateStringIDs(cur);
}
if(cx && cx == cur)
found = xpcc;

View File

@ -180,6 +180,8 @@ XPCNativeMember::Resolve(XPCCallContext& ccx, XPCNativeInterface* iface)
callback = XPC_WN_GetterSetter;
}
JSAutoRequest ar(cx);
JSFunction *fun = JS_NewFunction(cx, callback, argc, flags, nsnull,
iface->GetMemberName(ccx, this));
if(!fun)

View File

@ -1405,6 +1405,7 @@ _getstringidentifier(const NPUTF8* name)
if (!cx)
return NULL;
JSAutoRequest ar(cx);
return doGetIdentifier(cx, name);
}
@ -1422,6 +1423,8 @@ _getstringidentifiers(const NPUTF8** names, int32_t nameCount,
if (!cx)
return;
JSAutoRequest ar(cx);
for (int32_t i = 0; i < nameCount; ++i) {
identifiers[i] = doGetIdentifier(cx, names[i]);
}

View File

@ -514,6 +514,7 @@ nsJSObjWrapper::NP_HasMethod(NPObject *npobj, NPIdentifier identifier)
nsJSObjWrapper *npjsobj = (nsJSObjWrapper *)npobj;
jsval v;
JSAutoRequest ar(cx);
JSBool ok = GetProperty(cx, npjsobj->mJSObj, identifier, &v);
return ok && !JSVAL_IS_PRIMITIVE(v) &&
@ -538,6 +539,8 @@ doInvoke(NPObject *npobj, NPIdentifier method, const NPVariant *args,
return PR_FALSE;
}
JSAutoRequest ar(cx);
// Initialize *result
VOID_TO_NPVARIANT(*result);
@ -633,6 +636,8 @@ nsJSObjWrapper::NP_HasProperty(NPObject *npobj, NPIdentifier identifier)
jsval id = (jsval)identifier;
JSBool found, ok = JS_FALSE;
JSAutoRequest ar(cx);
if (JSVAL_IS_STRING(id)) {
JSString *str = JSVAL_TO_STRING(id);
@ -672,6 +677,7 @@ nsJSObjWrapper::NP_GetProperty(NPObject *npobj, NPIdentifier identifier,
AutoCXPusher pusher(cx);
jsval v;
JSAutoRequest ar(cx);
return (GetProperty(cx, npjsobj->mJSObj, identifier, &v) &&
JSValToNPVariant(npp, cx, v, result));
}
@ -701,6 +707,7 @@ nsJSObjWrapper::NP_SetProperty(NPObject *npobj, NPIdentifier identifier,
JSBool ok = JS_FALSE;
AutoCXPusher pusher(cx);
JSAutoRequest ar(cx);
jsval v = NPVariantToJSVal(npp, cx, value);
@ -744,6 +751,7 @@ nsJSObjWrapper::NP_RemoveProperty(NPObject *npobj, NPIdentifier identifier)
JSBool ok = JS_FALSE;
AutoCXPusher pusher(cx);
JSAutoRequest ar(cx);
if (JSVAL_IS_STRING(id)) {
JSString *str = JSVAL_TO_STRING(id);
@ -961,6 +969,8 @@ nsJSObjWrapper::GetNewOrUsed(NPP npp, JSContext *cx, JSObject *obj)
NS_ASSERTION(wrapper->mNpp == npp, "nsJSObjWrapper::mNpp not initialized!");
JSAutoRequest ar(cx);
// Root the JSObject, its lifetime is now tied to that of the
// NPObject.
if (!::JS_AddNamedRoot(cx, &wrapper->mJSObj, "nsJSObjWrapper::mJSObject")) {
@ -1473,6 +1483,8 @@ nsNPObjWrapper::GetNewOrUsed(NPP npp, JSContext *cx, NPObject *npobj)
entry->mNPObj = npobj;
entry->mNpp = npp;
JSAutoRequest ar(cx);
// No existing JSObject, create one.
JSObject *obj = ::JS_NewObject(cx, &sNPObjectJSWrapperClass, nsnull, nsnull);