Skip to content

Commit

Permalink
deps: V8: backport 844fe8f7d965
Browse files Browse the repository at this point in the history
Original commit message:

    Make StringBuffer::string return a StringView instead of a reference.

    A StringView is pretty light, so this should be similar to
    how absl::string_view is typically used, e.g. see the guidance here:
    https://github.com/abseil/abseil-cpp/blob/master/absl/strings/string_view.h
    I suspect this reasoning holds even though StringView (defined
    just above StringBuffer in v8-inspector.h) carries an additional bool.
    This yields a small simplification of the StringBuffer implementations.

    Change-Id: I03f850049afe2327913070838f39649fcdfa6fa8
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2045110
    Commit-Queue: Yang Guo <yangguo@chromium.org>
    Reviewed-by: Yang Guo <yangguo@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#66858}

(Neighbouring-line conflicts were resolved while backporting.)

Refs: v8/v8@844fe8f

PR-URL: #32885
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ujjwal Sharma <ryzokuken@disroot.org>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>
  • Loading branch information
addaleax authored and BethGriggs committed Apr 20, 2020
1 parent 1b78785 commit 4a11a54
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 97 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.14',
'v8_embedder_string': '-node.15',

##### V8 defaults for Node.js #####

Expand Down
56 changes: 28 additions & 28 deletions deps/v8/include/v8-inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ class V8_EXPORT StringView {
class V8_EXPORT StringBuffer {
public:
virtual ~StringBuffer() = default;
virtual const StringView& string() = 0;
virtual StringView string() const = 0;
// This method copies contents.
static std::unique_ptr<StringBuffer> create(const StringView&);
static std::unique_ptr<StringBuffer> create(StringView);
};

class V8_EXPORT V8ContextInfo {
public:
V8ContextInfo(v8::Local<v8::Context> context, int contextGroupId,
const StringView& humanReadableName)
StringView humanReadableName)
: context(context),
contextGroupId(contextGroupId),
humanReadableName(humanReadableName),
Expand Down Expand Up @@ -132,37 +132,36 @@ class V8_EXPORT V8InspectorSession {
virtual void addInspectedObject(std::unique_ptr<Inspectable>) = 0;

// Dispatching protocol messages.
static bool canDispatchMethod(const StringView& method);
virtual void dispatchProtocolMessage(const StringView& message) = 0;
static bool canDispatchMethod(StringView method);
virtual void dispatchProtocolMessage(StringView message) = 0;
virtual std::vector<uint8_t> state() = 0;
virtual std::vector<std::unique_ptr<protocol::Schema::API::Domain>>
supportedDomains() = 0;

// Debugger actions.
virtual void schedulePauseOnNextStatement(const StringView& breakReason,
const StringView& breakDetails) = 0;
virtual void schedulePauseOnNextStatement(StringView breakReason,
StringView breakDetails) = 0;
virtual void cancelPauseOnNextStatement() = 0;
virtual void breakProgram(const StringView& breakReason,
const StringView& breakDetails) = 0;
virtual void breakProgram(StringView breakReason,
StringView breakDetails) = 0;
virtual void setSkipAllPauses(bool) = 0;
virtual void resume() = 0;
virtual void stepOver() = 0;
virtual std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>>
searchInTextByLines(const StringView& text, const StringView& query,
bool caseSensitive, bool isRegex) = 0;
searchInTextByLines(StringView text, StringView query, bool caseSensitive,
bool isRegex) = 0;

// Remote objects.
virtual std::unique_ptr<protocol::Runtime::API::RemoteObject> wrapObject(
v8::Local<v8::Context>, v8::Local<v8::Value>, const StringView& groupName,
v8::Local<v8::Context>, v8::Local<v8::Value>, StringView groupName,
bool generatePreview) = 0;

virtual bool unwrapObject(std::unique_ptr<StringBuffer>* error,
const StringView& objectId, v8::Local<v8::Value>*,
StringView objectId, v8::Local<v8::Value>*,
v8::Local<v8::Context>*,
std::unique_ptr<StringBuffer>* objectGroup) = 0;
virtual void releaseObjectGroup(const StringView&) = 0;
virtual void triggerPreciseCoverageDeltaUpdate(
const StringView& occassion) = 0;
virtual void releaseObjectGroup(StringView) = 0;
virtual void triggerPreciseCoverageDeltaUpdate(StringView occassion) = 0;
};

class V8_EXPORT V8InspectorClient {
Expand Down Expand Up @@ -240,7 +239,7 @@ struct V8_EXPORT V8StackTraceId {
V8StackTraceId(uintptr_t id, const std::pair<int64_t, int64_t> debugger_id);
V8StackTraceId(uintptr_t id, const std::pair<int64_t, int64_t> debugger_id,
bool should_pause);
explicit V8StackTraceId(const StringView&);
explicit V8StackTraceId(StringView);
V8StackTraceId& operator=(const V8StackTraceId&) = default;
V8StackTraceId& operator=(V8StackTraceId&&) noexcept = default;
~V8StackTraceId() = default;
Expand All @@ -265,26 +264,26 @@ class V8_EXPORT V8Inspector {
virtual void idleFinished() = 0;

// Async stack traces instrumentation.
virtual void asyncTaskScheduled(const StringView& taskName, void* task,
virtual void asyncTaskScheduled(StringView taskName, void* task,
bool recurring) = 0;
virtual void asyncTaskCanceled(void* task) = 0;
virtual void asyncTaskStarted(void* task) = 0;
virtual void asyncTaskFinished(void* task) = 0;
virtual void allAsyncTasksCanceled() = 0;

virtual V8StackTraceId storeCurrentStackTrace(
const StringView& description) = 0;
virtual V8StackTraceId storeCurrentStackTrace(StringView description) = 0;
virtual void externalAsyncTaskStarted(const V8StackTraceId& parent) = 0;
virtual void externalAsyncTaskFinished(const V8StackTraceId& parent) = 0;

// Exceptions instrumentation.
virtual unsigned exceptionThrown(
v8::Local<v8::Context>, const StringView& message,
v8::Local<v8::Value> exception, const StringView& detailedMessage,
const StringView& url, unsigned lineNumber, unsigned columnNumber,
std::unique_ptr<V8StackTrace>, int scriptId) = 0;
virtual unsigned exceptionThrown(v8::Local<v8::Context>, StringView message,
v8::Local<v8::Value> exception,
StringView detailedMessage, StringView url,
unsigned lineNumber, unsigned columnNumber,
std::unique_ptr<V8StackTrace>,
int scriptId) = 0;
virtual void exceptionRevoked(v8::Local<v8::Context>, unsigned exceptionId,
const StringView& message) = 0;
StringView message) = 0;

// Connection.
class V8_EXPORT Channel {
Expand All @@ -295,8 +294,9 @@ class V8_EXPORT V8Inspector {
virtual void sendNotification(std::unique_ptr<StringBuffer> message) = 0;
virtual void flushProtocolNotifications() = 0;
};
virtual std::unique_ptr<V8InspectorSession> connect(
int contextGroupId, Channel*, const StringView& state) = 0;
virtual std::unique_ptr<V8InspectorSession> connect(int contextGroupId,
Channel*,
StringView state) = 0;

// API methods.
virtual std::unique_ptr<V8StackTrace> createStackTrace(
Expand Down
23 changes: 10 additions & 13 deletions deps/v8/src/inspector/string-util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,41 +129,38 @@ namespace {
// default-constructed StringView instance.
class EmptyStringBuffer : public StringBuffer {
public:
const StringView& string() override { return string_; }

private:
StringView string_;
StringView string() const override { return StringView(); }
};

// Contains LATIN1 text data or CBOR encoded binary data in a vector.
class StringBuffer8 : public StringBuffer {
public:
explicit StringBuffer8(std::vector<uint8_t> data)
: data_(std::move(data)), string_(data_.data(), data_.size()) {}
explicit StringBuffer8(std::vector<uint8_t> data) : data_(std::move(data)) {}

const StringView& string() override { return string_; }
StringView string() const override {
return StringView(data_.data(), data_.size());
}

private:
std::vector<uint8_t> data_;
StringView string_;
};

// Contains a 16 bit string (String16).
class StringBuffer16 : public StringBuffer {
public:
explicit StringBuffer16(String16 data)
: data_(std::move(data)), string_(data_.characters16(), data_.length()) {}
explicit StringBuffer16(String16 data) : data_(std::move(data)) {}

const StringView& string() override { return string_; }
StringView string() const override {
return StringView(data_.characters16(), data_.length());
}

private:
String16 data_;
StringView string_;
};
} // namespace

// static
std::unique_ptr<StringBuffer> StringBuffer::create(const StringView& string) {
std::unique_ptr<StringBuffer> StringBuffer::create(StringView string) {
if (string.length() == 0) return std::make_unique<EmptyStringBuffer>();
if (string.is8Bit()) {
return std::make_unique<StringBuffer8>(std::vector<uint8_t>(
Expand Down
16 changes: 7 additions & 9 deletions deps/v8/src/inspector/v8-inspector-impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ std::unique_ptr<V8StackTrace> V8InspectorImpl::createStackTrace(
}

std::unique_ptr<V8InspectorSession> V8InspectorImpl::connect(
int contextGroupId, V8Inspector::Channel* channel,
const StringView& state) {
int contextGroupId, V8Inspector::Channel* channel, StringView state) {
int sessionId = ++m_lastSessionId;
std::unique_ptr<V8InspectorSessionImpl> session =
V8InspectorSessionImpl::create(this, contextGroupId, sessionId, channel,
Expand Down Expand Up @@ -256,9 +255,9 @@ void V8InspectorImpl::idleStarted() { m_isolate->SetIdle(true); }
void V8InspectorImpl::idleFinished() { m_isolate->SetIdle(false); }

unsigned V8InspectorImpl::exceptionThrown(
v8::Local<v8::Context> context, const StringView& message,
v8::Local<v8::Value> exception, const StringView& detailedMessage,
const StringView& url, unsigned lineNumber, unsigned columnNumber,
v8::Local<v8::Context> context, StringView message,
v8::Local<v8::Value> exception, StringView detailedMessage, StringView url,
unsigned lineNumber, unsigned columnNumber,
std::unique_ptr<V8StackTrace> stackTrace, int scriptId) {
int groupId = contextGroupId(context);
if (!groupId || m_muteExceptionsMap[groupId]) return 0;
Expand All @@ -277,7 +276,7 @@ unsigned V8InspectorImpl::exceptionThrown(

void V8InspectorImpl::exceptionRevoked(v8::Local<v8::Context> context,
unsigned exceptionId,
const StringView& message) {
StringView message) {
int groupId = contextGroupId(context);
if (!groupId) return;

Expand All @@ -292,8 +291,7 @@ std::unique_ptr<V8StackTrace> V8InspectorImpl::captureStackTrace(
return m_debugger->captureStackTrace(fullStack);
}

V8StackTraceId V8InspectorImpl::storeCurrentStackTrace(
const StringView& description) {
V8StackTraceId V8InspectorImpl::storeCurrentStackTrace(StringView description) {
return m_debugger->storeCurrentStackTrace(description);
}

Expand All @@ -305,7 +303,7 @@ void V8InspectorImpl::externalAsyncTaskFinished(const V8StackTraceId& parent) {
m_debugger->externalAsyncTaskFinished(parent);
}

void V8InspectorImpl::asyncTaskScheduled(const StringView& taskName, void* task,
void V8InspectorImpl::asyncTaskScheduled(StringView taskName, void* task,
bool recurring) {
if (!task) return;
m_debugger->asyncTaskScheduled(taskName, task, recurring);
Expand Down
16 changes: 8 additions & 8 deletions deps/v8/src/inspector/v8-inspector-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,33 +77,33 @@ class V8InspectorImpl : public V8Inspector {
// V8Inspector implementation.
std::unique_ptr<V8InspectorSession> connect(int contextGroupId,
V8Inspector::Channel*,
const StringView& state) override;
StringView state) override;
void contextCreated(const V8ContextInfo&) override;
void contextDestroyed(v8::Local<v8::Context>) override;
v8::MaybeLocal<v8::Context> contextById(int contextId) override;
void contextCollected(int contextGroupId, int contextId);
void resetContextGroup(int contextGroupId) override;
void idleStarted() override;
void idleFinished() override;
unsigned exceptionThrown(v8::Local<v8::Context>, const StringView& message,
unsigned exceptionThrown(v8::Local<v8::Context>, StringView message,
v8::Local<v8::Value> exception,
const StringView& detailedMessage,
const StringView& url, unsigned lineNumber,
unsigned columnNumber, std::unique_ptr<V8StackTrace>,
StringView detailedMessage, StringView url,
unsigned lineNumber, unsigned columnNumber,
std::unique_ptr<V8StackTrace>,
int scriptId) override;
void exceptionRevoked(v8::Local<v8::Context>, unsigned exceptionId,
const StringView& message) override;
StringView message) override;
std::unique_ptr<V8StackTrace> createStackTrace(
v8::Local<v8::StackTrace>) override;
std::unique_ptr<V8StackTrace> captureStackTrace(bool fullStack) override;
void asyncTaskScheduled(const StringView& taskName, void* task,
void asyncTaskScheduled(StringView taskName, void* task,
bool recurring) override;
void asyncTaskCanceled(void* task) override;
void asyncTaskStarted(void* task) override;
void asyncTaskFinished(void* task) override;
void allAsyncTasksCanceled() override;

V8StackTraceId storeCurrentStackTrace(const StringView& description) override;
V8StackTraceId storeCurrentStackTrace(StringView description) override;
void externalAsyncTaskStarted(const V8StackTraceId& parent) override;
void externalAsyncTaskFinished(const V8StackTraceId& parent) override;

Expand Down
Loading

0 comments on commit 4a11a54

Please sign in to comment.