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
5
#include "
src/torque/ls/json.h
"
6
7
#include <iostream>
8
#include <sstream>
9
#include "
src/torque/utils.h
"
10
11
namespace
v8
{
12
namespace
internal
{
13
namespace
torque {
14
namespace
ls
{
15
16
namespace
{
17
18
void
SerializeToString
(std::stringstream& str,
const
JsonValue& value) {
19
switch
(value.tag) {
20
case
JsonValue::NUMBER
:
21
str << value.ToNumber();
22
break
;
23
case
JsonValue::STRING
:
24
str <<
StringLiteralQuote
(value.ToString());
25
break
;
26
case
JsonValue::IS_NULL
:
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
60
std::string
SerializeToString
(
const
JsonValue
& value) {
61
std::stringstream
result
;
62
SerializeToString
(
result
, value);
63
return
result
.str();
64
}
65
66
}
// namespace ls
67
}
// namespace torque
68
}
// namespace internal
69
}
// namespace v8
size
json.h
result
ZoneVector< RpoNumber > & result
Definition
jump-threading.cc:21
v8::internal::torque::ls::SerializeToString
std::string SerializeToString(const JsonValue &value)
Definition
json.cc:60
v8::internal::torque::StringLiteralQuote
std::string StringLiteralQuote(const std::string &s)
Definition
utils.cc:54
v8::internal
Definition
api-arguments-inl.h:20
v8::internal::ls
@ ls
Definition
constants-arm.h:94
v8::internal::internal
internal
Definition
wasm-objects-inl.h:458
v8
Definition
api-arguments-inl.h:19
v8::internal::torque::ls::JsonValue
Definition
json.h:25
v8::internal::torque::ls::JsonValue::NUMBER
@ NUMBER
Definition
json.h:27
v8::internal::torque::ls::JsonValue::ARRAY
@ ARRAY
Definition
json.h:27
v8::internal::torque::ls::JsonValue::STRING
@ STRING
Definition
json.h:27
v8::internal::torque::ls::JsonValue::IS_NULL
@ IS_NULL
Definition
json.h:27
v8::internal::torque::ls::JsonValue::BOOL
@ BOOL
Definition
json.h:27
v8::internal::torque::ls::JsonValue::OBJECT
@ OBJECT
Definition
json.h:27
utils.h
src
torque
ls
json.cc
Generated on Sun Apr 6 2025 21:08:57 for v8 by
1.12.0