v8 14.1.146 (node 25.0.0)
V8 is Google's open source JavaScript engine
Loading...
Searching...
No Matches
v8-json.h
Go to the documentation of this file.
1// Copyright 2021 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef INCLUDE_V8_JSON_H_
6#define INCLUDE_V8_JSON_H_
7
8#include <optional>
9
10#include "v8-local-handle.h" // NOLINT(build/include_directory)
11#include "v8-message.h" // NOLINT(build/include_directory)
12#include "v8config.h" // NOLINT(build/include_directory)
13
14namespace v8 {
15
16class Context;
17class Value;
18class String;
19
20/**
21 * A JSON Parser and Stringifier.
22 */
24 public:
25 /**
26 * Tries to parse the string |json_string| and returns it as value if
27 * successful.
28 *
29 * \param the context in which to parse and create the value.
30 * \param json_string The string to parse.
31 * \param origin Optional script origin to use for error reporting.
32 * If not provided, error reporting will use default origin options
33 * or attempt to infer origin from the current stack.
34 * \return The corresponding value if successfully parsed.
35 */
37 Local<Context> context, Local<String> json_string,
38 std::optional<ScriptOrigin> origin = std::nullopt);
39
40 /**
41 * Tries to stringify the JSON-serializable object |json_object| and returns
42 * it as string if successful.
43 *
44 * \param json_object The JSON-serializable object to stringify.
45 * \return The corresponding string if successfully stringified.
46 */
48 Local<Context> context, Local<Value> json_object,
49 Local<String> gap = Local<String>());
50};
51
52} // namespace v8
53
54#endif // INCLUDE_V8_JSON_H_
static V8_WARN_UNUSED_RESULT MaybeLocal< String > Stringify(Local< Context > context, Local< Value > json_object, Local< String > gap=Local< String >())
static V8_WARN_UNUSED_RESULT MaybeLocal< Value > Parse(Local< Context > context, Local< String > json_string, std::optional< ScriptOrigin > origin=std::nullopt)
friend class Local
friend class MaybeLocal
#define V8_EXPORT
Definition v8config.h:860
#define V8_WARN_UNUSED_RESULT
Definition v8config.h:684