v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
remote-object-id.cc
Go to the documentation of this file.
1// Copyright 2015 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 "../../third_party/inspector_protocol/crdtp/json.h"
8#include "src/inspector/protocol/Protocol.h"
10
11namespace v8_inspector {
12
13namespace {
14
15String16 serializeId(uint64_t isolateId, int injectedScriptId, int id) {
16 return String16::concat(
17 String16::fromInteger64(static_cast<int64_t>(isolateId)), ".",
18 String16::fromInteger(injectedScriptId), ".", String16::fromInteger(id));
19}
20
21} // namespace
22
24 : m_isolateId(0), m_injectedScriptId(0), m_id(0) {}
25
27 const UChar dot = '.';
28 size_t firstDotPos = objectId.find(dot);
29 if (firstDotPos == String16::kNotFound) return false;
30 bool ok = false;
31 int64_t isolateId = objectId.substring(0, firstDotPos).toInteger64(&ok);
32 if (!ok) return false;
33 firstDotPos++;
34 size_t secondDotPos = objectId.find(dot, firstDotPos);
35 if (secondDotPos == String16::kNotFound) return false;
36 int injectedScriptId =
37 objectId.substring(firstDotPos, secondDotPos - firstDotPos)
38 .toInteger(&ok);
39 if (!ok) return false;
40 secondDotPos++;
41 int id = objectId.substring(secondDotPos).toInteger(&ok);
42 if (!ok) return false;
43 m_isolateId = static_cast<uint64_t>(isolateId);
44 m_injectedScriptId = injectedScriptId;
45 m_id = id;
46 return true;
47}
48
49Response RemoteObjectId::parse(const String16& objectId,
50 std::unique_ptr<RemoteObjectId>* result) {
51 std::unique_ptr<RemoteObjectId> remoteObjectId(new RemoteObjectId());
52 if (!remoteObjectId->parseId(objectId))
53 return Response::ServerError("Invalid remote object id");
54 *result = std::move(remoteObjectId);
55 return Response::Success();
56}
57
58String16 RemoteObjectId::serialize(uint64_t isolateId, int injectedScriptId,
59 int id) {
60 return serializeId(isolateId, injectedScriptId, id);
61}
62
63Response RemoteCallFrameId::parse(const String16& objectId,
64 std::unique_ptr<RemoteCallFrameId>* result) {
65 std::unique_ptr<RemoteCallFrameId> remoteCallFrameId(new RemoteCallFrameId());
66 if (!remoteCallFrameId->parseId(objectId))
67 return Response::ServerError("Invalid call frame id");
68 *result = std::move(remoteCallFrameId);
69 return Response::Success();
70}
71
72String16 RemoteCallFrameId::serialize(uint64_t isolateId, int injectedScriptId,
73 int frameOrdinal) {
74 return serializeId(isolateId, injectedScriptId, frameOrdinal);
75}
76
77} // namespace v8_inspector
static Response parse(const String16 &, std::unique_ptr< RemoteCallFrameId > *)
static String16 serialize(uint64_t isolateId, int injectedScriptId, int frameOrdinal)
static Response parse(const String16 &, std::unique_ptr< RemoteObjectId > *)
static String16 serialize(uint64_t isolateId, int injectedScriptId, int id)
String16 substring(size_t pos, size_t len=UINT_MAX) const
Definition string-16.h:61
static String16 fromInteger(int)
Definition string-16.cc:71
int toInteger(bool *ok=nullptr) const
Definition string-16.cc:118
static String16 fromInteger64(int64_t)
Definition string-16.cc:91
static String16 concat(T... args)
Definition string-16.h:158
int64_t toInteger64(bool *ok=nullptr) const
Definition string-16.cc:114
size_t find(const String16 &str, size_t start=0) const
Definition string-16.h:64
static const size_t kNotFound
Definition string-16.h:26
ZoneVector< RpoNumber > & result
char16_t UChar
Definition string-16.h:22