Delegate unique id generation to embedder
This lets embedder to produce an id with sufficient entropy to facilitate an id appropriate for a multi-process system and immune to regular RNG seed being overriden, while maintaining deterministic id allocation for tests. Design doc: https://docs.google.com/document/d/1vGVWvKP9FTTX6kimcUJR_PAfVgDeIzXXITFpl0SyghQ Related blink-side change: https://chromium-review.googlesource.com/c/chromium/src/+/2600273 Bug: v8:11268 Change-Id: I1a4d12463cf56d4378859dfa3ee4d717e176d468 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2600442 Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Reviewed-by: Yang Guo <yangguo@chromium.org> Commit-Queue: Andrey Kosyakov <caseq@chromium.org> Cr-Commit-Position: refs/heads/master@{#71864}
This commit is contained in:
parent
72a7676110
commit
6e9f33f99c
@ -229,6 +229,10 @@ class V8_EXPORT V8InspectorClient {
|
||||
const StringView& resourceName) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// The caller would defer to generating a random 64 bit integer if
|
||||
// this method returns 0.
|
||||
virtual int64_t generateUniqueId() { return 0; }
|
||||
};
|
||||
|
||||
// These stack trace ids are intended to be passed between debuggers and be
|
||||
|
@ -68,12 +68,9 @@ V8DebuggerId::V8DebuggerId(std::pair<int64_t, int64_t> pair)
|
||||
: m_first(pair.first), m_second(pair.second) {}
|
||||
|
||||
// static
|
||||
V8DebuggerId V8DebuggerId::generate(v8::Isolate* isolate) {
|
||||
V8DebuggerId debuggerId;
|
||||
debuggerId.m_first = v8::debug::GetNextRandomInt64(isolate);
|
||||
debuggerId.m_second = v8::debug::GetNextRandomInt64(isolate);
|
||||
if (!debuggerId.m_first && !debuggerId.m_second) ++debuggerId.m_first;
|
||||
return debuggerId;
|
||||
V8DebuggerId V8DebuggerId::generate(V8InspectorImpl* inspector) {
|
||||
return V8DebuggerId(std::make_pair(inspector->generateUniqueId(),
|
||||
inspector->generateUniqueId()));
|
||||
}
|
||||
|
||||
V8DebuggerId::V8DebuggerId(const String16& debuggerId) {
|
||||
@ -1114,7 +1111,7 @@ void V8Debugger::setMaxAsyncTaskStacksForTest(int limit) {
|
||||
V8DebuggerId V8Debugger::debuggerIdFor(int contextGroupId) {
|
||||
auto it = m_contextGroupIdToDebuggerId.find(contextGroupId);
|
||||
if (it != m_contextGroupIdToDebuggerId.end()) return it->second;
|
||||
V8DebuggerId debuggerId = V8DebuggerId::generate(m_isolate);
|
||||
V8DebuggerId debuggerId = V8DebuggerId::generate(m_inspector);
|
||||
m_contextGroupIdToDebuggerId.insert(
|
||||
it, std::make_pair(contextGroupId, debuggerId));
|
||||
return debuggerId;
|
||||
|
@ -50,7 +50,7 @@ class V8DebuggerId {
|
||||
V8DebuggerId(const V8DebuggerId&) V8_NOEXCEPT = default;
|
||||
~V8DebuggerId() = default;
|
||||
|
||||
static V8DebuggerId generate(v8::Isolate*);
|
||||
static V8DebuggerId generate(V8InspectorImpl*);
|
||||
|
||||
String16 toString() const;
|
||||
bool isValid() const;
|
||||
|
@ -62,7 +62,7 @@ V8InspectorImpl::V8InspectorImpl(v8::Isolate* isolate,
|
||||
m_capturingStackTracesCount(0),
|
||||
m_lastExceptionId(0),
|
||||
m_lastContextId(0),
|
||||
m_isolateId(v8::debug::GetNextRandomInt64(m_isolate)) {
|
||||
m_isolateId(generateUniqueId()) {
|
||||
v8::debug::SetInspector(m_isolate, this);
|
||||
v8::debug::SetConsoleDelegate(m_isolate, console());
|
||||
}
|
||||
@ -416,6 +416,13 @@ void V8InspectorImpl::forEachSession(
|
||||
}
|
||||
}
|
||||
|
||||
int64_t V8InspectorImpl::generateUniqueId() {
|
||||
int64_t id = m_client->generateUniqueId();
|
||||
if (!id) id = v8::debug::GetNextRandomInt64(m_isolate);
|
||||
if (!id) id = 1;
|
||||
return id;
|
||||
}
|
||||
|
||||
V8InspectorImpl::EvaluateScope::EvaluateScope(
|
||||
const InjectedScript::Scope& scope)
|
||||
: m_scope(scope),
|
||||
|
@ -129,6 +129,7 @@ class V8InspectorImpl : public V8Inspector {
|
||||
void forEachSession(
|
||||
int contextGroupId,
|
||||
const std::function<void(V8InspectorSessionImpl*)>& callback);
|
||||
int64_t generateUniqueId();
|
||||
|
||||
class EvaluateScope {
|
||||
public:
|
||||
|
@ -487,5 +487,11 @@ std::unique_ptr<v8_inspector::StringBuffer> IsolateData::resourceNameToUrl(
|
||||
return std::make_unique<StringBufferImpl>(isolate(), url);
|
||||
}
|
||||
|
||||
int64_t IsolateData::generateUniqueId() {
|
||||
static int64_t last_unique_id = 0L;
|
||||
// Keep it not too random for tests.
|
||||
return ++last_unique_id;
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
@ -130,6 +130,7 @@ class IsolateData : public v8_inspector::V8InspectorClient {
|
||||
void maxAsyncCallStackDepthChanged(int depth) override;
|
||||
std::unique_ptr<v8_inspector::StringBuffer> resourceNameToUrl(
|
||||
const v8_inspector::StringView& resourceName) override;
|
||||
int64_t generateUniqueId() override;
|
||||
|
||||
// The isolate gets deleted by its {Dispose} method, not by the default
|
||||
// deleter. Therefore we have to define a custom deleter for the unique_ptr to
|
||||
|
Loading…
Reference in New Issue
Block a user