2007-12-27 13:34:03 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-12-27 13:34:03 -08:00
|
|
|
|
|
|
|
#include "domstubs.idl"
|
|
|
|
|
|
|
|
interface nsIInputStream;
|
|
|
|
interface nsIOutputStream;
|
|
|
|
interface nsIScriptGlobalObject;
|
|
|
|
|
2009-09-01 09:45:05 -07:00
|
|
|
[ptr] native JSValPtr(jsval);
|
|
|
|
[ptr] native JSContext(JSContext);
|
|
|
|
|
2007-12-27 13:34:03 -08:00
|
|
|
/**
|
|
|
|
* Encode and decode JSON text.
|
|
|
|
*/
|
2011-11-26 02:21:47 -08:00
|
|
|
[scriptable, uuid(43845d58-1054-47fb-8be3-970b3f7bd7ea)]
|
2007-12-27 13:34:03 -08:00
|
|
|
interface nsIJSON : nsISupports
|
|
|
|
{
|
2011-07-22 05:12:34 -07:00
|
|
|
/**
|
|
|
|
* New users should use JSON.stringify!
|
|
|
|
* The encode() method is only present for backward compatibility.
|
|
|
|
* encode() is not a conforming JSON stringify implementation!
|
|
|
|
*/
|
2011-11-26 02:21:47 -08:00
|
|
|
[deprecated,implicit_jscontext,optional_argc]
|
|
|
|
AString encode([optional] in jsval value);
|
2011-07-22 05:12:34 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* New users should use JSON.stringify.
|
|
|
|
* You may also want to have a look at nsIConverterOutputStream.
|
|
|
|
*
|
|
|
|
* The encodeToStream() method is only present for backward compatibility.
|
|
|
|
* encodeToStream() is not a conforming JSON stringify implementation!
|
|
|
|
*/
|
2011-11-26 02:21:47 -08:00
|
|
|
[deprecated,implicit_jscontext,optional_argc]
|
|
|
|
void encodeToStream(in nsIOutputStream stream,
|
|
|
|
in string charset,
|
|
|
|
in boolean writeBOM,
|
|
|
|
[optional] in jsval value);
|
2011-07-22 05:12:34 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* New users should use JSON.parse!
|
|
|
|
* The decode() method is only present for backward compatibility.
|
|
|
|
*/
|
2011-11-26 02:21:29 -08:00
|
|
|
[deprecated,implicit_jscontext]
|
|
|
|
jsval decode(in AString str);
|
2007-12-27 13:34:03 -08:00
|
|
|
|
2011-11-26 02:21:29 -08:00
|
|
|
[implicit_jscontext]
|
|
|
|
jsval decodeFromStream(in nsIInputStream stream,
|
|
|
|
in long contentLength);
|
2009-09-01 09:45:05 -07:00
|
|
|
|
|
|
|
[noscript] AString encodeFromJSVal(in JSValPtr value, in JSContext cx);
|
|
|
|
|
|
|
|
// Make sure you GCroot the result of this function before using it.
|
2010-05-12 06:18:51 -07:00
|
|
|
[noscript] jsval decodeToJSVal(in AString str, in JSContext cx);
|
2010-07-14 11:48:36 -07:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decode a JSON string, but also accept some strings in non-JSON format, as
|
|
|
|
* the decoding methods here did previously before tightening.
|
|
|
|
*
|
|
|
|
* This method is provided only as a temporary transition path for users of
|
|
|
|
* the old code who depended on the ability to decode leniently; new users
|
2011-03-28 19:27:15 -07:00
|
|
|
* should use JSON.parse.
|
|
|
|
*
|
|
|
|
* This method must only be called from script.
|
2010-07-14 11:48:36 -07:00
|
|
|
*
|
|
|
|
* @param str the string to parse
|
|
|
|
*/
|
2011-11-26 02:21:29 -08:00
|
|
|
[implicit_jscontext]
|
|
|
|
jsval legacyDecode(in AString str);
|
2010-07-14 11:48:36 -07:00
|
|
|
|
|
|
|
/* Identical to legacyDecode, but decode the contents of stream. */
|
2011-11-26 02:21:29 -08:00
|
|
|
[implicit_jscontext]
|
|
|
|
jsval legacyDecodeFromStream(in nsIInputStream stream,
|
|
|
|
in long contentLength);
|
2010-07-14 11:48:36 -07:00
|
|
|
|
|
|
|
/* Identical to legacyDecode, but decode into a jsval. */
|
|
|
|
// Make sure you GCroot the result of this function before using it.
|
|
|
|
[noscript] jsval legacyDecodeToJSVal(in AString str, in JSContext cx);
|
2007-12-27 13:34:03 -08:00
|
|
|
};
|