Bug 1554138 - nsCookie::Create should return an already_AddRef<> instead of a raw pointer, r=Ehsan

Depends on D32461

Differential Revision: https://phabricator.services.mozilla.com/D32462

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2019-05-25 01:32:24 +00:00
parent 27e8e74b73
commit 1f043863ca
2 changed files with 16 additions and 17 deletions

View File

@ -75,13 +75,12 @@ int64_t nsCookie::GenerateUniqueCreationTime(int64_t aCreationTime) {
return ++gLastCreationTime;
}
nsCookie* nsCookie::Create(const nsACString& aName, const nsACString& aValue,
const nsACString& aHost, const nsACString& aPath,
int64_t aExpiry, int64_t aLastAccessed,
int64_t aCreationTime, bool aIsSession,
bool aIsSecure, bool aIsHttpOnly,
const OriginAttributes& aOriginAttributes,
int32_t aSameSite) {
// static
already_AddRefed<nsCookie> nsCookie::Create(
const nsACString& aName, const nsACString& aValue, const nsACString& aHost,
const nsACString& aPath, int64_t aExpiry, int64_t aLastAccessed,
int64_t aCreationTime, bool aIsSession, bool aIsSecure, bool aIsHttpOnly,
const OriginAttributes& aOriginAttributes, int32_t aSameSite) {
// Ensure mValue contains a valid UTF-8 sequence. Otherwise XPConnect will
// truncate the string after the first invalid octet.
nsAutoCString aUTF8Value;
@ -111,9 +110,11 @@ nsCookie* nsCookie::Create(const nsACString& aName, const nsACString& aValue,
}
// construct the cookie. placement new, oh yeah!
return new (place) nsCookie(
RefPtr<nsCookie> cookie = new (place) nsCookie(
name, value, host, path, end, aExpiry, aLastAccessed, aCreationTime,
aIsSession, aIsSecure, aIsHttpOnly, aOriginAttributes, aSameSite);
return cookie.forget();
}
size_t nsCookie::SizeOfIncludingThis(

View File

@ -59,15 +59,13 @@ class nsCookie final : public nsICookie2 {
// in nsCookie.cpp.
static int64_t GenerateUniqueCreationTime(int64_t aCreationTime);
// public helper to create an nsCookie object. use |operator delete|
// to destroy an object created by this method.
static nsCookie* Create(const nsACString& aName, const nsACString& aValue,
const nsACString& aHost, const nsACString& aPath,
int64_t aExpiry, int64_t aLastAccessed,
int64_t aCreationTime, bool aIsSession,
bool aIsSecure, bool aIsHttpOnly,
const OriginAttributes& aOriginAttributes,
int32_t aSameSite);
// public helper to create an nsCookie object.
static already_AddRefed<nsCookie> Create(
const nsACString& aName, const nsACString& aValue,
const nsACString& aHost, const nsACString& aPath, int64_t aExpiry,
int64_t aLastAccessed, int64_t aCreationTime, bool aIsSession,
bool aIsSecure, bool aIsHttpOnly,
const OriginAttributes& aOriginAttributes, int32_t aSameSite);
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;