11cb0ef41Sopenharmony_ci// Copyright 2015 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#include "src/inspector/remote-object-id.h" 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci#include "../../third_party/inspector_protocol/crdtp/json.h" 81cb0ef41Sopenharmony_ci#include "src/inspector/protocol/Protocol.h" 91cb0ef41Sopenharmony_ci#include "src/inspector/string-util.h" 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_cinamespace v8_inspector { 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_cinamespace { 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciString16 serializeId(uint64_t isolateId, int injectedScriptId, int id) { 161cb0ef41Sopenharmony_ci return String16::concat( 171cb0ef41Sopenharmony_ci String16::fromInteger64(static_cast<int64_t>(isolateId)), ".", 181cb0ef41Sopenharmony_ci String16::fromInteger(injectedScriptId), ".", String16::fromInteger(id)); 191cb0ef41Sopenharmony_ci} 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci} // namespace 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ciRemoteObjectIdBase::RemoteObjectIdBase() 241cb0ef41Sopenharmony_ci : m_isolateId(0), m_injectedScriptId(0), m_id(0) {} 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_cibool RemoteObjectIdBase::parseId(const String16& objectId) { 271cb0ef41Sopenharmony_ci const UChar dot = '.'; 281cb0ef41Sopenharmony_ci size_t firstDotPos = objectId.find(dot); 291cb0ef41Sopenharmony_ci if (firstDotPos == String16::kNotFound) return false; 301cb0ef41Sopenharmony_ci bool ok = false; 311cb0ef41Sopenharmony_ci int64_t isolateId = objectId.substring(0, firstDotPos).toInteger64(&ok); 321cb0ef41Sopenharmony_ci if (!ok) return false; 331cb0ef41Sopenharmony_ci firstDotPos++; 341cb0ef41Sopenharmony_ci size_t secondDotPos = objectId.find(dot, firstDotPos); 351cb0ef41Sopenharmony_ci if (secondDotPos == String16::kNotFound) return false; 361cb0ef41Sopenharmony_ci int injectedScriptId = 371cb0ef41Sopenharmony_ci objectId.substring(firstDotPos, secondDotPos - firstDotPos) 381cb0ef41Sopenharmony_ci .toInteger(&ok); 391cb0ef41Sopenharmony_ci if (!ok) return false; 401cb0ef41Sopenharmony_ci secondDotPos++; 411cb0ef41Sopenharmony_ci int id = objectId.substring(secondDotPos).toInteger(&ok); 421cb0ef41Sopenharmony_ci if (!ok) return false; 431cb0ef41Sopenharmony_ci m_isolateId = static_cast<uint64_t>(isolateId); 441cb0ef41Sopenharmony_ci m_injectedScriptId = injectedScriptId; 451cb0ef41Sopenharmony_ci m_id = id; 461cb0ef41Sopenharmony_ci return true; 471cb0ef41Sopenharmony_ci} 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ciResponse RemoteObjectId::parse(const String16& objectId, 501cb0ef41Sopenharmony_ci std::unique_ptr<RemoteObjectId>* result) { 511cb0ef41Sopenharmony_ci std::unique_ptr<RemoteObjectId> remoteObjectId(new RemoteObjectId()); 521cb0ef41Sopenharmony_ci if (!remoteObjectId->parseId(objectId)) 531cb0ef41Sopenharmony_ci return Response::ServerError("Invalid remote object id"); 541cb0ef41Sopenharmony_ci *result = std::move(remoteObjectId); 551cb0ef41Sopenharmony_ci return Response::Success(); 561cb0ef41Sopenharmony_ci} 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ciString16 RemoteObjectId::serialize(uint64_t isolateId, int injectedScriptId, 591cb0ef41Sopenharmony_ci int id) { 601cb0ef41Sopenharmony_ci return serializeId(isolateId, injectedScriptId, id); 611cb0ef41Sopenharmony_ci} 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ciResponse RemoteCallFrameId::parse(const String16& objectId, 641cb0ef41Sopenharmony_ci std::unique_ptr<RemoteCallFrameId>* result) { 651cb0ef41Sopenharmony_ci std::unique_ptr<RemoteCallFrameId> remoteCallFrameId(new RemoteCallFrameId()); 661cb0ef41Sopenharmony_ci if (!remoteCallFrameId->parseId(objectId)) 671cb0ef41Sopenharmony_ci return Response::ServerError("Invalid call frame id"); 681cb0ef41Sopenharmony_ci *result = std::move(remoteCallFrameId); 691cb0ef41Sopenharmony_ci return Response::Success(); 701cb0ef41Sopenharmony_ci} 711cb0ef41Sopenharmony_ci 721cb0ef41Sopenharmony_ciString16 RemoteCallFrameId::serialize(uint64_t isolateId, int injectedScriptId, 731cb0ef41Sopenharmony_ci int frameOrdinal) { 741cb0ef41Sopenharmony_ci return serializeId(isolateId, injectedScriptId, frameOrdinal); 751cb0ef41Sopenharmony_ci} 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ci} // namespace v8_inspector 78