v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
json.cc
Go to the documentation of this file.
1// Copyright 2019 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
6
7#include <iostream>
8#include <sstream>
9#include "src/torque/utils.h"
10
11namespace v8 {
12namespace internal {
13namespace torque {
14namespace ls {
15
16namespace {
17
18void SerializeToString(std::stringstream& str, const JsonValue& value) {
19 switch (value.tag) {
21 str << value.ToNumber();
22 break;
24 str << StringLiteralQuote(value.ToString());
25 break;
27 str << "null";
28 break;
29 case JsonValue::BOOL:
30 str << (value.ToBool() ? "true" : "false");
31 break;
32 case JsonValue::OBJECT: {
33 str << "{";
34 size_t i = 0;
35 for (const auto& pair : value.ToObject()) {
36 str << "\"" << pair.first << "\":";
37 SerializeToString(str, pair.second);
38 if (++i < value.ToObject().size()) str << ",";
39 }
40 str << "}";
41 break;
42 }
43 case JsonValue::ARRAY: {
44 str << "[";
45 size_t i = 0;
46 for (const auto& element : value.ToArray()) {
47 SerializeToString(str, element);
48 if (++i < value.ToArray().size()) str << ",";
49 }
50 str << "]";
51 break;
52 }
53 default:
54 break;
55 }
56}
57
58} // namespace
59
60std::string SerializeToString(const JsonValue& value) {
61 std::stringstream result;
63 return result.str();
64}
65
66} // namespace ls
67} // namespace torque
68} // namespace internal
69} // namespace v8
ZoneVector< RpoNumber > & result
std::string SerializeToString(const JsonValue &value)
Definition json.cc:60
std::string StringLiteralQuote(const std::string &s)
Definition utils.cc:54