Bug 877762 - GC: Post-barrier cycle collector participants - 5 Convert JS::Value to use Heap<T> r=smaug

This commit is contained in:
Jon Coppeard 2013-06-18 11:00:37 +01:00
parent 82483ce6e9
commit 59d5490ab4
26 changed files with 100 additions and 57 deletions

View File

@ -782,12 +782,14 @@ nsXMLHttpRequest::CreateResponseParsedJSON(JSContext* aCx)
RootJSResultObjects();
// The Unicode converter has already zapped the BOM if there was one
JS::Rooted<JS::Value> value(aCx);
if (!JS_ParseJSON(aCx,
static_cast<const jschar*>(mResponseText.get()), mResponseText.Length(),
JS::MutableHandle<JS::Value>::fromMarkedLocation(&mResultJSON))) {
&value)) {
return NS_ERROR_FAILURE;
}
mResultJSON = value;
return NS_OK;
}

View File

@ -657,11 +657,11 @@ protected:
bool mFirstStartRequestSeen;
bool mInLoadProgressEvent;
nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback;
nsCOMPtr<nsIChannel> mNewRedirectChannel;
JS::Value mResultJSON;
JS::Heap<JS::Value> mResultJSON;
js::ArrayBufferBuilder mArrayBufferBuilder;
JSObject* mResultArrayBuffer;

View File

@ -65,7 +65,7 @@ public:
}
private:
JS::Value mData;
JS::Heap<JS::Value> mData;
nsString mOrigin;
nsString mLastEventId;
nsCOMPtr<nsIDOMWindow> mSource;

View File

@ -2383,8 +2383,7 @@ nsXULPrototypeScript::Serialize(nsIObjectOutputStream* aStream,
rv = aStream->Write32(mLangVersion);
if (NS_FAILED(rv)) return rv;
// And delegate the writing to the nsIScriptContext
rv = context->Serialize(aStream,
JS::Handle<JSScript*>::fromMarkedLocation(&mScriptObject));
rv = context->Serialize(aStream, mScriptObject);
if (NS_FAILED(rv)) return rv;
return NS_OK;

View File

@ -22,7 +22,7 @@ class DOMRequest : public nsDOMEventTargetHelper,
public nsIDOMDOMRequest
{
protected:
JS::Value mResult;
JS::Heap<JS::Value> mResult;
nsRefPtr<DOMError> mError;
bool mDone;
bool mRooted;

View File

@ -3523,7 +3523,7 @@ public:
protected:
JSContext *mContext;
JS::Value *mArgv;
JS::Heap<JS::Value> *mArgv;
uint32_t mArgc;
};
@ -3534,9 +3534,10 @@ nsJSArgArray::nsJSArgArray(JSContext *aContext, uint32_t argc, JS::Value *argv,
mArgc(argc)
{
// copy the array - we don't know its lifetime, and ours is tied to xpcom
// refcounting. Alloc zero'd array so cleanup etc is safe.
// refcounting.
if (argc) {
mArgv = (JS::Value *) PR_CALLOC(argc * sizeof(JS::Value));
static const fallible_t fallible = fallible_t();
mArgv = new (fallible) JS::Heap<JS::Value>[argc];
if (!mArgv) {
*prv = NS_ERROR_OUT_OF_MEMORY;
return;
@ -3566,7 +3567,7 @@ void
nsJSArgArray::ReleaseJSObjects()
{
if (mArgv) {
PR_DELETE(mArgv);
delete [] mArgv;
}
if (mArgc > 0) {
mArgc = 0;

View File

@ -67,7 +67,7 @@ private:
// caller of setTimeout()
nsCString mFileName;
uint32_t mLineNo;
nsTArray<JS::Value> mArgs;
nsTArray<JS::Heap<JS::Value> > mArgs;
// The JS expression to evaluate or function to call, if !mExpr
JSFlatString *mExpr;
@ -299,7 +299,8 @@ nsJSScriptTimeoutHandler::Init(nsGlobalWindow *aWindow, bool *aIsInterval,
// array.
// std::max(argc - 2, 0) wouldn't work right because argc is unsigned.
uint32_t argCount = std::max(argc, 2u) - 2;
FallibleTArray<JS::Value> args;
FallibleTArray<JS::Heap<JS::Value> > args;
if (!args.SetCapacity(argCount)) {
// No need to drop here, since we already have a non-null mFunction
return NS_ERROR_OUT_OF_MEMORY;

View File

@ -107,7 +107,7 @@ private:
nsTArray<nsRefPtr<FutureCallback> > mResolveCallbacks;
nsTArray<nsRefPtr<FutureCallback> > mRejectCallbacks;
JS::Value mResult;
JS::Heap<JS::Value> mResult;
FutureState mState;
bool mTaskPending;
};

View File

@ -544,7 +544,7 @@ IDBCursor::GetKey(JSContext* aCx,
mRooted = true;
}
nsresult rv = mKey.ToJSVal(aCx, &mCachedKey);
nsresult rv = mKey.ToJSVal(aCx, mCachedKey);
NS_ENSURE_SUCCESS(rv, rv);
mHaveCachedKey = true;
@ -578,7 +578,7 @@ IDBCursor::GetPrimaryKey(JSContext* aCx,
const Key& key = mType == OBJECTSTORE ? mKey : mObjectKey;
nsresult rv = key.ToJSVal(aCx, &mCachedPrimaryKey);
nsresult rv = key.ToJSVal(aCx, mCachedPrimaryKey);
NS_ENSURE_SUCCESS(rv, rv);
mHaveCachedPrimaryKey = true;
@ -739,7 +739,7 @@ IDBCursor::Update(const jsval& aValue,
}
else {
JS::Rooted<JS::Value> keyVal(aCx);
rv = objectKey.ToJSVal(aCx, keyVal.address());
rv = objectKey.ToJSVal(aCx, &keyVal);
NS_ENSURE_SUCCESS(rv, rv);
rv = mObjectStore->Put(aValue, keyVal, aCx, 1, getter_AddRefs(request));
@ -810,7 +810,7 @@ IDBCursor::Delete(JSContext* aCx,
Key& objectKey = (mType == OBJECTSTORE) ? mKey : mObjectKey;
JS::Rooted<JS::Value> key(aCx);
nsresult rv = objectKey.ToJSVal(aCx, key.address());
nsresult rv = objectKey.ToJSVal(aCx, &key);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIIDBRequest> request;

View File

@ -176,9 +176,9 @@ protected:
nsCString mContinueToQuery;
// These are cycle-collected!
jsval mCachedKey;
jsval mCachedPrimaryKey;
jsval mCachedValue;
JS::Heap<JS::Value> mCachedKey;
JS::Heap<JS::Value> mCachedPrimaryKey;
JS::Heap<JS::Value> mCachedValue;
Key mRangeKey;

View File

@ -810,7 +810,7 @@ IDBIndex::GetKeyPath(JSContext* aCx,
return NS_OK;
}
nsresult rv = GetKeyPath().ToJSVal(aCx, &mCachedKeyPath);
nsresult rv = GetKeyPath().ToJSVal(aCx, mCachedKeyPath);
NS_ENSURE_SUCCESS(rv, rv);
if (JSVAL_IS_GCTHING(mCachedKeyPath)) {
@ -1180,7 +1180,12 @@ nsresult
GetKeyHelper::GetSuccessResult(JSContext* aCx,
jsval* aVal)
{
return mKey.ToJSVal(aCx, aVal);
JS::Rooted<JS::Value> value(aCx);
nsresult rv = mKey.ToJSVal(aCx, &value);
if (NS_SUCCEEDED(rv)) {
*aVal = value;
}
return rv;
}
void
@ -1508,7 +1513,7 @@ GetAllKeysHelper::GetSuccessResult(JSContext* aCx,
NS_ASSERTION(!key.IsUnset(), "Bad key!");
JS::Rooted<JS::Value> value(aCx);
nsresult rv = key.ToJSVal(aCx, value.address());
nsresult rv = key.ToJSVal(aCx, &value);
if (NS_FAILED(rv)) {
NS_WARNING("Failed to get jsval for key!");
return rv;

View File

@ -157,7 +157,7 @@ private:
int64_t mId;
nsString mName;
KeyPath mKeyPath;
JS::Value mCachedKeyPath;
JS::Heap<JS::Value> mCachedKeyPath;
IndexedDBIndexChild* mActorChild;
IndexedDBIndexParent* mActorParent;

View File

@ -363,7 +363,7 @@ IDBKeyRange::GetLower(JSContext* aCx,
mRooted = true;
}
nsresult rv = Lower().ToJSVal(aCx, &mCachedLowerVal);
nsresult rv = Lower().ToJSVal(aCx, mCachedLowerVal);
NS_ENSURE_SUCCESS(rv, rv);
mHaveCachedLowerVal = true;
@ -385,7 +385,7 @@ IDBKeyRange::GetUpper(JSContext* aCx,
mRooted = true;
}
nsresult rv = Upper().ToJSVal(aCx, &mCachedUpperVal);
nsresult rv = Upper().ToJSVal(aCx, mCachedUpperVal);
NS_ENSURE_SUCCESS(rv, rv);
mHaveCachedUpperVal = true;

View File

@ -157,8 +157,8 @@ private:
Key mLower;
Key mUpper;
jsval mCachedLowerVal;
jsval mCachedUpperVal;
JS::Heap<JS::Value> mCachedLowerVal;
JS::Heap<JS::Value> mCachedUpperVal;
bool mLowerOpen;
bool mUpperOpen;
bool mIsOnly;

View File

@ -2387,7 +2387,7 @@ IDBObjectStore::GetKeyPath(JSContext* aCx,
return NS_OK;
}
nsresult rv = GetKeyPath().ToJSVal(aCx, &mCachedKeyPath);
nsresult rv = GetKeyPath().ToJSVal(aCx, mCachedKeyPath);
NS_ENSURE_SUCCESS(rv, rv);
if (JSVAL_IS_GCTHING(mCachedKeyPath)) {
@ -3134,7 +3134,12 @@ AddHelper::GetSuccessResult(JSContext* aCx,
mCloneWriteInfo.mCloneBuffer.clear();
return mKey.ToJSVal(aCx, aVal);
JS::Rooted<JS::Value> value(aCx);
nsresult rv = mKey.ToJSVal(aCx, &value);
if (NS_SUCCEEDED(rv)) {
*aVal = value;
}
return rv;
}
void

View File

@ -287,7 +287,7 @@ private:
int64_t mId;
nsString mName;
KeyPath mKeyPath;
JS::Value mCachedKeyPath;
JS::Heap<JS::Value> mCachedKeyPath;
bool mRooted;
bool mAutoIncrement;
nsCOMPtr<nsIAtom> mDatabaseId;

View File

@ -120,13 +120,15 @@ IDBRequest::NotifyHelperCompleted(HelperBase* aHelper)
JSAutoCompartment ac(cx, global);
AssertIsRooted();
rv = aHelper->GetSuccessResult(cx, &mResultVal);
JS::Rooted<JS::Value> value(cx);
rv = aHelper->GetSuccessResult(cx, value.address());
if (NS_FAILED(rv)) {
NS_WARNING("GetSuccessResult failed!");
}
if (NS_SUCCEEDED(rv)) {
mError = nullptr;
mResultVal = value;
}
else {
SetError(rv);

View File

@ -109,7 +109,7 @@ protected:
nsCOMPtr<nsISupports> mSource;
nsRefPtr<IDBTransaction> mTransaction;
jsval mResultVal;
JS::Heap<JS::Value> mResultVal;
nsRefPtr<mozilla::dom::DOMError> mError;
IndexedDBRequestParentBase* mActorParent;
nsString mFilename;

View File

@ -185,7 +185,7 @@ Key::EncodeJSValInternal(JSContext* aCx, const jsval aVal,
// static
nsresult
Key::DecodeJSValInternal(const unsigned char*& aPos, const unsigned char* aEnd,
JSContext* aCx, uint8_t aTypeOffset, jsval* aVal,
JSContext* aCx, uint8_t aTypeOffset, JS::MutableHandle<JS::Value> aVal,
uint16_t aRecursionDepth)
{
NS_ENSURE_TRUE(aRecursionDepth < MaxRecursionDepth, NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
@ -208,7 +208,7 @@ Key::DecodeJSValInternal(const unsigned char*& aPos, const unsigned char* aEnd,
while (aPos < aEnd && *aPos - aTypeOffset != eTerminator) {
JS::Rooted<JS::Value> val(aCx);
nsresult rv = DecodeJSValInternal(aPos, aEnd, aCx, aTypeOffset,
val.address(), aRecursionDepth + 1);
&val, aRecursionDepth + 1);
NS_ENSURE_SUCCESS(rv, rv);
aTypeOffset = 0;
@ -223,12 +223,12 @@ Key::DecodeJSValInternal(const unsigned char*& aPos, const unsigned char* aEnd,
"Should have found end-of-array marker");
++aPos;
*aVal = OBJECT_TO_JSVAL(array);
aVal.setObject(*array);
}
else if (*aPos - aTypeOffset == eString) {
nsString key;
DecodeString(aPos, aEnd, key);
if (!xpc::StringToJsval(aCx, key, aVal)) {
if (!xpc::StringToJsval(aCx, key, aVal.address())) {
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
}
@ -240,10 +240,10 @@ Key::DecodeJSValInternal(const unsigned char*& aPos, const unsigned char* aEnd,
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
*aVal = OBJECT_TO_JSVAL(date);
aVal.setObject(*date);
}
else if (*aPos - aTypeOffset == eFloat) {
*aVal = DOUBLE_TO_JSVAL(DecodeNumber(aPos, aEnd));
aVal.setDouble(DecodeNumber(aPos, aEnd));
}
else {
NS_NOTREACHED("Unknown key type!");

View File

@ -179,10 +179,10 @@ public:
}
nsresult ToJSVal(JSContext* aCx,
jsval* aVal) const
JS::MutableHandle<JS::Value> aVal) const
{
if (IsUnset()) {
*aVal = JSVAL_VOID;
aVal.set(JSVAL_VOID);
return NS_OK;
}
@ -196,6 +196,17 @@ public:
return NS_OK;
}
nsresult ToJSVal(JSContext* aCx,
JS::Heap<JS::Value>& aVal) const
{
JS::Rooted<JS::Value> value(aCx);
nsresult rv = ToJSVal(aCx, &value);
if (NS_SUCCEEDED(rv)) {
aVal = value;
}
return rv;
}
nsresult AppendItem(JSContext* aCx,
bool aFirstOfArray,
const jsval aVal)
@ -304,7 +315,7 @@ private:
// past the consumed value.
static inline nsresult DecodeJSVal(const unsigned char*& aPos,
const unsigned char* aEnd, JSContext* aCx,
uint8_t aTypeOffset, jsval* aVal)
uint8_t aTypeOffset, JS::MutableHandle<JS::Value> aVal)
{
return DecodeJSValInternal(aPos, aEnd, aCx, aTypeOffset, aVal, 0);
}
@ -324,7 +335,7 @@ private:
static nsresult DecodeJSValInternal(const unsigned char*& aPos,
const unsigned char* aEnd,
JSContext* aCx, uint8_t aTypeOffset,
jsval* aVal, uint16_t aRecursionDepth);
JS::MutableHandle<JS::Value> aVal, uint16_t aRecursionDepth);
};
END_INDEXEDDB_NAMESPACE

View File

@ -457,7 +457,7 @@ KeyPath::DeserializeFromString(const nsAString& aString)
}
nsresult
KeyPath::ToJSVal(JSContext* aCx, JS::Value* aValue) const
KeyPath::ToJSVal(JSContext* aCx, JS::MutableHandle<JS::Value> aValue) const
{
if (IsArray()) {
uint32_t len = mStrings.Length();
@ -479,22 +479,33 @@ KeyPath::ToJSVal(JSContext* aCx, JS::Value* aValue) const
}
}
*aValue = OBJECT_TO_JSVAL(array);
aValue.setObject(*array);
return NS_OK;
}
if (IsString()) {
nsString tmp(mStrings[0]);
if (!xpc::StringToJsval(aCx, tmp, aValue)) {
if (!xpc::StringToJsval(aCx, tmp, aValue.address())) {
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
return NS_OK;
}
*aValue = JSVAL_NULL;
aValue.setNull();
return NS_OK;
}
nsresult
KeyPath::ToJSVal(JSContext* aCx, JS::Heap<JS::Value>& aValue) const
{
JS::Rooted<JS::Value> value(aCx);
nsresult rv = ToJSVal(aCx, &value);
if (NS_SUCCEEDED(rv)) {
aValue = value;
}
return rv;
}
bool
KeyPath::IsAllowedForObjectStore(bool aAutoIncrement) const
{

View File

@ -87,7 +87,8 @@ public:
void SerializeToString(nsAString& aString) const;
static KeyPath DeserializeFromString(const nsAString& aString);
nsresult ToJSVal(JSContext* aCx, JS::Value* aValue) const;
nsresult ToJSVal(JSContext* aCx, JS::MutableHandle<JS::Value> aValue) const;
nsresult ToJSVal(JSContext* aCx, JS::Heap<JS::Value>& aValue) const;
bool IsAllowedForObjectStore(bool aAutoIncrement) const;

View File

@ -31,6 +31,11 @@
#define JS_CHECK_STACK_SIZE(limit, lval) JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, lval, 0)
namespace JS {
template <class T>
class Heap;
} /* namespace JS */
extern JS_FRIEND_API(void)
JS_SetGrayGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data);
@ -890,7 +895,7 @@ struct ExpandoAndGeneration {
generation(0)
{}
Value expando;
JS::Heap<JS::Value> expando;
uint32_t generation;
};

View File

@ -503,8 +503,8 @@ void XPCJSRuntime::TraceGrayJS(JSTracer* trc, void* data)
struct JsGcTracer : public TraceCallbacks
{
virtual void Trace(JS::Value *p, const char *name, void *closure) const MOZ_OVERRIDE {
JS_CallValueTracer(static_cast<JSTracer*>(closure), p, name);
virtual void Trace(JS::Heap<JS::Value> *p, const char *name, void *closure) const MOZ_OVERRIDE {
JS_CallHeapValueTracer(static_cast<JSTracer*>(closure), p, name);
}
virtual void Trace(jsid *p, const char *name, void *closure) const MOZ_OVERRIDE {
JS_CallIdTracer(static_cast<JSTracer*>(closure), p, name);

View File

@ -69,9 +69,9 @@ CycleCollectionNoteEdgeNameImpl(nsCycleCollectionTraversalCallback& aCallback,
}
void
TraceCallbackFunc::Trace(JS::Value* p, const char* name, void* closure) const
TraceCallbackFunc::Trace(JS::Heap<JS::Value>* p, const char* name, void* closure) const
{
mCallback(JSVAL_TO_TRACEABLE(*p), name, closure);
mCallback(JSVAL_TO_TRACEABLE(p->get()), name, closure);
}
void

View File

@ -62,7 +62,7 @@ template <class T> class Heap;
*/
struct TraceCallbacks
{
virtual void Trace(JS::Value* p, const char* name, void* closure) const = 0;
virtual void Trace(JS::Heap<JS::Value>* p, const char* name, void* closure) const = 0;
virtual void Trace(jsid* p, const char* name, void* closure) const = 0;
virtual void Trace(JSObject** p, const char* name, void* closure) const = 0;
virtual void Trace(JSString** p, const char* name, void* closure) const = 0;
@ -83,7 +83,7 @@ struct TraceCallbackFunc : public TraceCallbacks
explicit TraceCallbackFunc(Func cb) : mCallback(cb) {}
virtual void Trace(JS::Value* p, const char* name, void* closure) const MOZ_OVERRIDE;
virtual void Trace(JS::Heap<JS::Value>* p, const char* name, void* closure) const MOZ_OVERRIDE;
virtual void Trace(jsid* p, const char* name, void* closure) const MOZ_OVERRIDE;
virtual void Trace(JSObject** p, const char* name, void* closure) const MOZ_OVERRIDE;
virtual void Trace(JSString** p, const char* name, void* closure) const MOZ_OVERRIDE;