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/. */
10 #include "mozilla/Range.h"
12 #include "NamespaceImports.h"
14 #include "js/RootingAPI.h"
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.
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.
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.
38 // Do not attempt the fast path. Useful for timing comparisons.
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.
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
);
63 #endif /* builtin_JSON_h */