зеркало из https://github.com/mozilla/pjs.git
Bug 675797 - Warn in calls to nsIJSON.encode and nsIJSON.decode that the two methods are deprecated. r=jst
--HG-- extra : rebase_source : ec4bda0ae1c71955bd42e45f51b996141cf4372c
This commit is contained in:
Родитель
1e07dbc39c
Коммит
8f1222d785
|
@ -108,3 +108,6 @@ IsSupportedWarning=Use of attributes' isSupported() is deprecated.
|
||||||
IsEqualNodeWarning=Use of attributes' isEqualNode() is deprecated.
|
IsEqualNodeWarning=Use of attributes' isEqualNode() is deprecated.
|
||||||
TextContentWarning=Use of attributes' textContent attribute is deprecated. Use value instead.
|
TextContentWarning=Use of attributes' textContent attribute is deprecated. Use value instead.
|
||||||
EnablePrivilegeWarning=Use of enablePrivilege is deprecated. Please use code that runs with the system principal (e.g. an extension) instead.
|
EnablePrivilegeWarning=Use of enablePrivilege is deprecated. Please use code that runs with the system principal (e.g. an extension) instead.
|
||||||
|
|
||||||
|
nsIJSONDecodeDeprecatedWarning=nsIJSON.decode is deprecated. Please use JSON.parse instead.
|
||||||
|
nsIJSONEncodeDeprecatedWarning=nsIJSON.encode is deprecated. Please use JSON.stringify instead.
|
||||||
|
|
|
@ -52,6 +52,7 @@
|
||||||
#include "nsXPCOMStrings.h"
|
#include "nsXPCOMStrings.h"
|
||||||
#include "nsNetUtil.h"
|
#include "nsNetUtil.h"
|
||||||
#include "nsContentUtils.h"
|
#include "nsContentUtils.h"
|
||||||
|
#include "nsIScriptError.h"
|
||||||
#include "nsCRTGlue.h"
|
#include "nsCRTGlue.h"
|
||||||
#include "nsAutoPtr.h"
|
#include "nsAutoPtr.h"
|
||||||
#include "nsIScriptSecurityManager.h"
|
#include "nsIScriptSecurityManager.h"
|
||||||
|
@ -76,11 +77,29 @@ nsJSON::~nsJSON()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum DeprecationWarning { EncodeWarning, DecodeWarning };
|
||||||
|
|
||||||
|
static nsresult
|
||||||
|
WarnDeprecatedMethod(DeprecationWarning warning)
|
||||||
|
{
|
||||||
|
return nsContentUtils::ReportToConsole(nsContentUtils::eDOM_PROPERTIES,
|
||||||
|
warning == EncodeWarning
|
||||||
|
? "nsIJSONEncodeDeprecatedWarning"
|
||||||
|
: "nsIJSONDecodeDeprecatedWarning",
|
||||||
|
nsnull, 0,
|
||||||
|
nsnull,
|
||||||
|
EmptyString(), 0, 0,
|
||||||
|
nsIScriptError::warningFlag,
|
||||||
|
"DOM Core");
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsJSON::Encode(nsAString &aJSON)
|
nsJSON::Encode(nsAString &aJSON)
|
||||||
{
|
{
|
||||||
// This function should only be called from JS.
|
// This function should only be called from JS.
|
||||||
nsresult rv;
|
nsresult rv = WarnDeprecatedMethod(EncodeWarning);
|
||||||
|
if (NS_FAILED(rv))
|
||||||
|
return rv;
|
||||||
|
|
||||||
nsJSONWriter writer;
|
nsJSONWriter writer;
|
||||||
rv = EncodeInternal(&writer);
|
rv = EncodeInternal(&writer);
|
||||||
|
@ -424,13 +443,17 @@ nsJSONWriter::WriteToStream(nsIOutputStream *aStream,
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsJSON::Decode(const nsAString& json)
|
nsJSON::Decode(const nsAString& json)
|
||||||
{
|
{
|
||||||
|
nsresult rv = WarnDeprecatedMethod(DecodeWarning);
|
||||||
|
if (NS_FAILED(rv))
|
||||||
|
return rv;
|
||||||
|
|
||||||
const PRUnichar *data;
|
const PRUnichar *data;
|
||||||
PRUint32 len = NS_StringGetData(json, &data);
|
PRUint32 len = NS_StringGetData(json, &data);
|
||||||
nsCOMPtr<nsIInputStream> stream;
|
nsCOMPtr<nsIInputStream> stream;
|
||||||
nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream),
|
rv = NS_NewByteInputStream(getter_AddRefs(stream),
|
||||||
(const char*) data,
|
reinterpret_cast<const char*>(data),
|
||||||
len * sizeof(PRUnichar),
|
len * sizeof(PRUnichar),
|
||||||
NS_ASSIGNMENT_DEPEND);
|
NS_ASSIGNMENT_DEPEND);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
return DecodeInternal(stream, len, PR_FALSE);
|
return DecodeInternal(stream, len, PR_FALSE);
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче