mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-14 13:55:43 +00:00
Backed out changeset 110e44b996f8 (bug 1034627) for Valgrind Testfailures on a CLOSED TREE
This commit is contained in:
parent
dcc8c1b538
commit
eb71d8cf86
@ -6,8 +6,6 @@
|
||||
|
||||
/* nsIVariant implementation for xpconnect. */
|
||||
|
||||
#include "mozilla/Range.h"
|
||||
|
||||
#include "xpcprivate.h"
|
||||
#include "nsCxPusher.h"
|
||||
|
||||
@ -98,6 +96,10 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(XPCVariant)
|
||||
JS::Value val = tmp->GetJSValPreserveColor();
|
||||
|
||||
// We're sharing val's buffer, clear the pointer to it so Cleanup() won't
|
||||
// try to delete it
|
||||
if (val.isString())
|
||||
tmp->mData.u.wstr.mWStringValue = nullptr;
|
||||
nsVariant::Cleanup(&tmp->mData);
|
||||
|
||||
if (val.isMarkable()) {
|
||||
@ -286,18 +288,25 @@ bool XPCVariant::InitializeData(JSContext* cx)
|
||||
if (!str)
|
||||
return false;
|
||||
|
||||
// Don't use nsVariant::SetFromWStringWithSize, because that will copy
|
||||
// the data. Just handle this ourselves. Note that it's ok to not
|
||||
// copy because we added mJSVal as a GC root.
|
||||
MOZ_ASSERT(mData.mType == nsIDataType::VTYPE_EMPTY,
|
||||
"Why do we already have data?");
|
||||
|
||||
size_t length = JS_GetStringLength(str);
|
||||
if (!NS_SUCCEEDED(nsVariant::AllocateWStringWithSize(&mData, length)))
|
||||
// Despite the fact that the variant holds the length, there are
|
||||
// implicit assumptions that mWStringValue[mWStringLength] == 0
|
||||
size_t length;
|
||||
const jschar *chars = JS_GetStringCharsZAndLength(cx, str, &length);
|
||||
if (!chars)
|
||||
return false;
|
||||
|
||||
mozilla::Range<jschar> destChars(mData.u.wstr.mWStringValue, length);
|
||||
if (!JS_CopyStringChars(cx, destChars, str))
|
||||
return false;
|
||||
mData.u.wstr.mWStringValue = const_cast<jschar *>(chars);
|
||||
// Use C-style cast, because reinterpret cast from size_t to
|
||||
// uint32_t is not valid on some platforms.
|
||||
mData.u.wstr.mWStringLength = (uint32_t)length;
|
||||
mData.mType = nsIDataType::VTYPE_WSTRING_SIZE_IS;
|
||||
|
||||
MOZ_ASSERT(mData.u.wstr.mWStringValue[length] == '\0');
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1557,18 +1557,6 @@ nsVariant::SetFromWStringWithSize(nsDiscriminatedUnion* aData, uint32_t aSize,
|
||||
DATA_SETTER_EPILOGUE(aData, VTYPE_WSTRING_SIZE_IS);
|
||||
}
|
||||
/* static */ nsresult
|
||||
nsVariant::AllocateWStringWithSize(nsDiscriminatedUnion* aData, uint32_t aSize)
|
||||
{
|
||||
DATA_SETTER_PROLOGUE(aData);
|
||||
if (!(aData->u.wstr.mWStringValue =
|
||||
(char16_t*)NS_Alloc((aSize + 1) * sizeof(char16_t)))) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
aData->u.wstr.mWStringValue[aSize] = '\0';
|
||||
aData->u.wstr.mWStringLength = aSize;
|
||||
DATA_SETTER_EPILOGUE(aData, VTYPE_WSTRING_SIZE_IS);
|
||||
}
|
||||
/* static */ nsresult
|
||||
nsVariant::SetToVoid(nsDiscriminatedUnion* aData)
|
||||
{
|
||||
DATA_SETTER_PROLOGUE(aData);
|
||||
|
@ -190,11 +190,6 @@ public:
|
||||
uint32_t aSize,
|
||||
const char16_t* aValue);
|
||||
|
||||
// Like SetFromWStringWithSize, but leaves the string uninitialized. It does
|
||||
// does write the null-terminator.
|
||||
static nsresult AllocateWStringWithSize(nsDiscriminatedUnion* aData,
|
||||
uint32_t aSize);
|
||||
|
||||
static nsresult SetToVoid(nsDiscriminatedUnion* aData);
|
||||
static nsresult SetToEmpty(nsDiscriminatedUnion* aData);
|
||||
static nsresult SetToEmptyArray(nsDiscriminatedUnion* aData);
|
||||
|
Loading…
Reference in New Issue
Block a user