nsIJSON.idl 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "domstubs.idl"
  6. interface nsIInputStream;
  7. interface nsIOutputStream;
  8. interface nsIScriptGlobalObject;
  9. [ptr] native JSValPtr(JS::Value);
  10. [ptr] native JSContext(JSContext);
  11. %{C++
  12. #include "js/TypeDecls.h"
  13. %}
  14. /**
  15. * Don't use this! Use JSON.parse and JSON.stringify directly.
  16. */
  17. [scriptable, uuid(083aebb0-7790-43b2-ae81-9e404e626236)]
  18. interface nsIJSON : nsISupports
  19. {
  20. /**
  21. * New users should use JSON.stringify!
  22. * The encode() method is only present for backward compatibility.
  23. * encode() is not a conforming JSON stringify implementation!
  24. */
  25. [deprecated,implicit_jscontext,optional_argc]
  26. AString encode([optional] in jsval value);
  27. /**
  28. * New users should use JSON.stringify.
  29. * You may also want to have a look at nsIConverterOutputStream.
  30. *
  31. * The encodeToStream() method is only present for backward compatibility.
  32. * encodeToStream() is not a conforming JSON stringify implementation!
  33. */
  34. [deprecated,implicit_jscontext,optional_argc]
  35. void encodeToStream(in nsIOutputStream stream,
  36. in string charset,
  37. in boolean writeBOM,
  38. [optional] in jsval value);
  39. /**
  40. * New users should use JSON.parse!
  41. * The decode() method is only present for backward compatibility.
  42. */
  43. [deprecated,implicit_jscontext]
  44. jsval decode(in AString str);
  45. [implicit_jscontext]
  46. jsval decodeFromStream(in nsIInputStream stream,
  47. in long contentLength);
  48. [noscript] AString encodeFromJSVal(in JSValPtr value, in JSContext cx);
  49. // Make sure you GCroot the result of this function before using it.
  50. [noscript] jsval decodeToJSVal(in AString str, in JSContext cx);
  51. };