No bug - tagging b4d3227540c9ebc43d64aac6168fdca7019c22d8 with FIREFOX_BETA_126_BASE...
[gecko.git] / js / src / builtin / JSON.h
blobfd2d65e4f72d614f02643740d899116f946e62e9
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef builtin_JSON_h
8 #define builtin_JSON_h
10 #include "mozilla/Range.h"
12 #include "NamespaceImports.h"
14 #include "js/RootingAPI.h"
16 namespace js {
18 class StringBuffer;
20 extern const JSClass JSONClass;
22 enum class StringifyBehavior {
23 // Attempt an optimistic fast path if possible, bailing back to the slow path
24 // if anything is encountered that could invalidate the fast path results per
25 // spec. Default behavior for non-DEBUG builds.
26 Normal,
28 // Handle a subset of functionality when called by JS::ToJSONMaybeSafely.
29 // Different restrictions than the fast path described for Normal. See the
30 // Stringify() comment below for details.
31 RestrictedSafe,
33 // If the fast path fails, throw an exception instead of falling back to the
34 // slow path. Useful for testing that something that should be handled by the
35 // fast path actually is.
36 FastOnly,
38 // Do not attempt the fast path. Useful for timing comparisons.
39 SlowOnly,
41 // Attempt to run both the fast and slow paths and compare the results,
42 // crashing on any discrepancy. For correctness testing only. Default behavior
43 // when DEBUG is defined.
44 Compare
47 /**
48 * If stringifyBehavior is RestrictedSafe, Stringify will attempt to assert the
49 * API requirements of JS::ToJSONMaybeSafely as it traverses the graph, and will
50 * not try to invoke .toJSON on things as it goes.
52 extern bool Stringify(JSContext* cx, js::MutableHandleValue vp,
53 JSObject* replacer, const Value& space, StringBuffer& sb,
54 StringifyBehavior stringifyBehavior);
56 template <typename CharT>
57 extern bool ParseJSONWithReviver(JSContext* cx,
58 const mozilla::Range<const CharT> chars,
59 HandleValue reviver, MutableHandleValue vp);
61 } // namespace js
63 #endif /* builtin_JSON_h */