зеркало из https://github.com/mozilla/gecko-dev.git
Bug 332648 - Part g: Move AutoIdArray to jsapi.h; r=evilpie
This commit is contained in:
Родитель
5cbc546a54
Коммит
90d6724cfa
|
@ -501,9 +501,9 @@ nsHTMLCanvasElement::GetContext(const nsAString& aContextId,
|
|||
contextProps = do_CreateInstance("@mozilla.org/hash-property-bag;1");
|
||||
|
||||
JSObject *opts = JSVAL_TO_OBJECT(aContextOptions);
|
||||
JSIdArray *props = JS_Enumerate(cx, opts);
|
||||
for (int i = 0; props && i < JS_IdArrayLength(cx, props); ++i) {
|
||||
jsid propid = JS_IdArrayGet(cx, props, i);
|
||||
JS::AutoIdArray props(cx, JS_Enumerate(cx, opts));
|
||||
for (size_t i = 0; !!props && i < props.length(); ++i) {
|
||||
jsid propid = props[i];
|
||||
jsval propname, propval;
|
||||
if (!JS_IdToValue(cx, propid, &propname) ||
|
||||
!JS_GetPropertyById(cx, opts, propid, &propval)) {
|
||||
|
@ -513,13 +513,12 @@ nsHTMLCanvasElement::GetContext(const nsAString& aContextId,
|
|||
JSString *propnameString = JS_ValueToString(cx, propname);
|
||||
nsDependentJSString pstr;
|
||||
if (!propnameString || !pstr.init(cx, propnameString)) {
|
||||
JS_DestroyIdArray(cx, props);
|
||||
mCurrentContext = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (JSVAL_IS_BOOLEAN(propval)) {
|
||||
contextProps->SetPropertyAsBool(pstr, propval == JSVAL_TRUE ? true : false);
|
||||
contextProps->SetPropertyAsBool(pstr, JSVAL_TO_BOOLEAN(propval));
|
||||
} else if (JSVAL_IS_INT(propval)) {
|
||||
contextProps->SetPropertyAsInt32(pstr, JSVAL_TO_INT(propval));
|
||||
} else if (JSVAL_IS_DOUBLE(propval)) {
|
||||
|
@ -528,7 +527,6 @@ nsHTMLCanvasElement::GetContext(const nsAString& aContextId,
|
|||
JSString *propvalString = JS_ValueToString(cx, propval);
|
||||
nsDependentJSString vstr;
|
||||
if (!propvalString || !vstr.init(cx, propvalString)) {
|
||||
JS_DestroyIdArray(cx, props);
|
||||
mCurrentContext = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -536,7 +534,6 @@ nsHTMLCanvasElement::GetContext(const nsAString& aContextId,
|
|||
contextProps->SetPropertyAsAString(pstr, vstr);
|
||||
}
|
||||
}
|
||||
JS_DestroyIdArray(cx, props);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -966,25 +966,21 @@ nsJSObjWrapper::NP_Enumerate(NPObject *npobj, NPIdentifier **idarray,
|
|||
if (!ac.enter(cx, npjsobj->mJSObj))
|
||||
return false;
|
||||
|
||||
JSIdArray *ida = ::JS_Enumerate(cx, npjsobj->mJSObj);
|
||||
JS::AutoIdArray ida(cx, JS_Enumerate(cx, npjsobj->mJSObj));
|
||||
if (!ida) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*count = ida->length;
|
||||
*count = ida.length();
|
||||
*idarray = (NPIdentifier *)PR_Malloc(*count * sizeof(NPIdentifier));
|
||||
if (!*idarray) {
|
||||
ThrowJSException(cx, "Memory allocation failed for NPIdentifier!");
|
||||
|
||||
::JS_DestroyIdArray(cx, ida);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
for (PRUint32 i = 0; i < *count; i++) {
|
||||
jsval v;
|
||||
if (!::JS_IdToValue(cx, ida->vector[i], &v)) {
|
||||
::JS_DestroyIdArray(cx, ida);
|
||||
if (!JS_IdToValue(cx, ida[i], &v)) {
|
||||
PR_Free(*idarray);
|
||||
return false;
|
||||
}
|
||||
|
@ -993,10 +989,8 @@ nsJSObjWrapper::NP_Enumerate(NPObject *npobj, NPIdentifier **idarray,
|
|||
if (JSVAL_IS_STRING(v)) {
|
||||
JSString *str = JS_InternJSString(cx, JSVAL_TO_STRING(v));
|
||||
if (!str) {
|
||||
::JS_DestroyIdArray(cx, ida);
|
||||
PR_Free(*idarray);
|
||||
|
||||
return false;
|
||||
PR_Free(*idarray);
|
||||
return false;
|
||||
}
|
||||
id = StringToNPIdentifier(cx, str);
|
||||
} else {
|
||||
|
@ -1008,8 +1002,6 @@ nsJSObjWrapper::NP_Enumerate(NPObject *npobj, NPIdentifier **idarray,
|
|||
(*idarray)[i] = id;
|
||||
}
|
||||
|
||||
::JS_DestroyIdArray(cx, ida);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "jscntxt.h"
|
||||
|
||||
#include "mozilla/jsipc/ContextWrapperChild.h"
|
||||
#include "mozilla/jsipc/ObjectWrapperChild.h"
|
||||
|
|
|
@ -3471,6 +3471,57 @@ JS_IdArrayGet(JSContext *cx, JSIdArray *ida, jsint index);
|
|||
extern JS_PUBLIC_API(void)
|
||||
JS_DestroyIdArray(JSContext *cx, JSIdArray *ida);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace JS {
|
||||
|
||||
class AutoIdArray : private AutoGCRooter {
|
||||
public:
|
||||
AutoIdArray(JSContext *cx, JSIdArray *ida JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
||||
: AutoGCRooter(cx, IDARRAY), idArray(ida)
|
||||
{
|
||||
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
||||
}
|
||||
~AutoIdArray() {
|
||||
if (idArray)
|
||||
JS_DestroyIdArray(context, idArray);
|
||||
}
|
||||
bool operator!() {
|
||||
return !idArray;
|
||||
}
|
||||
jsid operator[](size_t i) const {
|
||||
JS_ASSERT(idArray);
|
||||
JS_ASSERT(i < length());
|
||||
return JS_IdArrayGet(context, idArray, i);
|
||||
}
|
||||
size_t length() const {
|
||||
return JS_IdArrayLength(context, idArray);
|
||||
}
|
||||
|
||||
friend void AutoGCRooter::trace(JSTracer *trc);
|
||||
|
||||
JSIdArray *steal() {
|
||||
JSIdArray *copy = idArray;
|
||||
idArray = NULL;
|
||||
return copy;
|
||||
}
|
||||
|
||||
protected:
|
||||
inline void trace(JSTracer *trc);
|
||||
|
||||
private:
|
||||
JSIdArray *idArray;
|
||||
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
|
||||
/* No copy or assignment semantics. */
|
||||
AutoIdArray(AutoIdArray &ida) MOZ_DELETE;
|
||||
void operator=(AutoIdArray &ida) MOZ_DELETE;
|
||||
};
|
||||
|
||||
} /* namespace JS */
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_ValueToId(JSContext *cx, jsval v, jsid *idp);
|
||||
|
||||
|
|
|
@ -1598,48 +1598,6 @@ typedef RootedVar<jsid> RootedVarId;
|
|||
typedef RootedVar<Value> RootedVarValue;
|
||||
|
||||
/* FIXME(bug 332648): Move this into a public header. */
|
||||
class AutoIdArray : private AutoGCRooter {
|
||||
public:
|
||||
AutoIdArray(JSContext *cx, JSIdArray *ida JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
||||
: AutoGCRooter(cx, IDARRAY), idArray(ida)
|
||||
{
|
||||
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
||||
}
|
||||
~AutoIdArray() {
|
||||
if (idArray)
|
||||
JS_DestroyIdArray(context, idArray);
|
||||
}
|
||||
bool operator!() {
|
||||
return idArray == NULL;
|
||||
}
|
||||
jsid operator[](size_t i) const {
|
||||
JS_ASSERT(idArray);
|
||||
JS_ASSERT(i < size_t(idArray->length));
|
||||
return idArray->vector[i];
|
||||
}
|
||||
size_t length() const {
|
||||
return idArray->length;
|
||||
}
|
||||
|
||||
friend void AutoGCRooter::trace(JSTracer *trc);
|
||||
|
||||
JSIdArray *steal() {
|
||||
JSIdArray *copy = idArray;
|
||||
idArray = NULL;
|
||||
return copy;
|
||||
}
|
||||
|
||||
protected:
|
||||
inline void trace(JSTracer *trc);
|
||||
|
||||
private:
|
||||
JSIdArray * idArray;
|
||||
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
|
||||
AutoIdArray(AutoIdArray &ida) MOZ_DELETE;
|
||||
void operator=(AutoIdArray &ida) MOZ_DELETE;
|
||||
};
|
||||
|
||||
/* The auto-root for enumeration object and its state. */
|
||||
class AutoEnumStateRooter : private AutoGCRooter
|
||||
{
|
||||
|
|
|
@ -1963,7 +1963,7 @@ AutoGCRooter::trace(JSTracer *trc)
|
|||
|
||||
case IDARRAY: {
|
||||
JSIdArray *ida = static_cast<AutoIdArray *>(this)->idArray;
|
||||
MarkIdRange(trc, ida->vector, ida->vector + ida->length, "js::AutoIdArray.idArray");
|
||||
MarkIdRange(trc, ida->vector, ida->vector + ida->length, "JS::AutoIdArray.idArray");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -61,8 +61,6 @@
|
|||
#include "jsgc.h"
|
||||
#include "jsfriendapi.h"
|
||||
|
||||
#include "jscntxt.h" // AutoIdArray
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace js;
|
||||
/***************************************************************************/
|
||||
|
@ -3758,7 +3756,7 @@ nsXPCComponents_Utils::MakeObjectPropsNormal(const jsval &vobj, JSContext *cx)
|
|||
if (!ac.enter(cx, obj))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
js::AutoIdArray ida(cx, JS_Enumerate(cx, obj));
|
||||
JS::AutoIdArray ida(cx, JS_Enumerate(cx, obj));
|
||||
if (!ida)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
#include "AccessCheck.h"
|
||||
#include "nsJSUtils.h"
|
||||
|
||||
#include "jscntxt.h" // mJSContext->errorReporter, JSIdArray, js::AutoValueVector
|
||||
#include "jscntxt.h" // mJSContext->errorReporter, js::AutoValueVector
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsXPCWrappedJSClass, nsIXPCWrappedJSClass)
|
||||
|
||||
|
@ -405,60 +405,49 @@ nsXPCWrappedJSClass::BuildPropertyEnumerator(XPCCallContext& ccx,
|
|||
nsISimpleEnumerator** aEnumerate)
|
||||
{
|
||||
JSContext* cx = ccx.GetJSContext();
|
||||
nsresult retval = NS_ERROR_FAILURE;
|
||||
JSIdArray* idArray = nsnull;
|
||||
int i;
|
||||
|
||||
// Saved state must be restored, all exits through 'out'...
|
||||
AutoScriptEvaluate scriptEval(cx);
|
||||
if (!scriptEval.StartEvaluating(aJSObj))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
idArray = JS_Enumerate(cx, aJSObj);
|
||||
JS::AutoIdArray idArray(cx, JS_Enumerate(cx, aJSObj));
|
||||
if (!idArray)
|
||||
return retval;
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMArray<nsIProperty> propertyArray(idArray.length());
|
||||
for (size_t i = 0; i < idArray.length(); i++) {
|
||||
jsid idName = idArray[i];
|
||||
|
||||
nsCOMArray<nsIProperty> propertyArray(idArray->length);
|
||||
for (i = 0; i < idArray->length; i++) {
|
||||
nsCOMPtr<nsIVariant> value;
|
||||
jsid idName = idArray->vector[i];
|
||||
nsresult rv;
|
||||
|
||||
if (!GetNamedPropertyAsVariantRaw(ccx, aJSObj, idName,
|
||||
getter_AddRefs(value), &rv)) {
|
||||
if (NS_FAILED(rv))
|
||||
retval = rv;
|
||||
goto out;
|
||||
return rv;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
jsval jsvalName;
|
||||
if (!JS_IdToValue(cx, idName, &jsvalName))
|
||||
goto out;
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
JSString* name = JS_ValueToString(cx, jsvalName);
|
||||
if (!name)
|
||||
goto out;
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
size_t length;
|
||||
const jschar *chars = JS_GetStringCharsAndLength(cx, name, &length);
|
||||
if (!chars)
|
||||
goto out;
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIProperty> property =
|
||||
new xpcProperty(chars, (PRUint32) length, value);
|
||||
if (!property)
|
||||
goto out;
|
||||
|
||||
if (!propertyArray.AppendObject(property))
|
||||
goto out;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
retval = NS_NewArrayEnumerator(aEnumerate, propertyArray);
|
||||
|
||||
out:
|
||||
JS_DestroyIdArray(cx, idArray);
|
||||
|
||||
return retval;
|
||||
return NS_NewArrayEnumerator(aEnumerate, propertyArray);
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
|
Загрузка…
Ссылка в новой задаче