Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Don't strip colons in WTF name specs if no arguments are expected. #608

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions bindings/cpp/event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,23 @@ void EventDefinition::AppendName(std::string* output) const {
// names, as with the __PRETTY_FUNCTION__ built-in macro.
// Replace double colons with '#', which is WTF's class/namespace separator.
//
// A single : in a name_spec separates the name part from arguments.
// A single : in a name_spec separates the name part from arguments,
// if there are arguments.
const char *src = name_spec_;
const char* colon = strchr(src, ':');
while (colon) {
output->append(src, (colon - src));
src = colon + 1;
if (*src == ':') {
// Double colon, replace with # and continue.
output->append("#");
src += 1;
colon = strchr(src, ':');
} else {
// This was a single colon. Output no more.
return;
if (argument_zipper_) {
const char* colon = strchr(src, ':');
while (colon) {
output->append(src, (colon - src));
src = colon + 1;
if (*src == ':') {
// Double colon, just output it and continue.
output->append("::");
src += 1;
colon = strchr(src, ':');
} else {
// This was a single colon. Output no more.
return;
}
}
}
// Append anything remaining in src.
Expand Down
25 changes: 23 additions & 2 deletions bindings/cpp/event_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class EventTest : public ::testing::Test {
return EventDefinition::Create<int, const char*>(
/*wire_id=*/0, EventClass::kScoped, /*flags=*/0, name_spec);
}

EventDefinition CreateEventDefinition0(const char *name_spec) {
return EventDefinition::Create(
/*wire_id=*/0, EventClass::kScoped, /*flags=*/0, name_spec);
}
};


Expand All @@ -31,15 +36,15 @@ TEST_F(EventTest, CheckNameSpecParsing) {
output.clear();
event = CreateEventDefinition("MyNamespace::MyClass::MyFunc");
event.AppendName(&output);
EXPECT_EQ(output, "MyNamespace#MyClass#MyFunc");
EXPECT_EQ(output, "MyNamespace::MyClass::MyFunc");
output.clear();
event.AppendArguments(&output);
EXPECT_EQ(output, "int32 a0, ascii a1");

output.clear();
event = CreateEventDefinition("MyClass::MyFunc2: arg1 , arg2");
event.AppendName(&output);
EXPECT_EQ(output, "MyClass#MyFunc2");
EXPECT_EQ(output, "MyClass::MyFunc2");
output.clear();
event.AppendArguments(&output);
EXPECT_EQ(output, "int32 arg1, ascii arg2");
Expand All @@ -59,6 +64,22 @@ TEST_F(EventTest, CheckNameSpecParsing) {
output.clear();
event.AppendArguments(&output);
EXPECT_EQ(output, "int32 arg1, ascii a1");

output.clear();
event = CreateEventDefinition0("MyMethodNoArgs");
event.AppendName(&output);
EXPECT_EQ(output, "MyMethodNoArgs");
output.clear();
event.AppendArguments(&output);
EXPECT_EQ(output, "");

output.clear();
event = CreateEventDefinition0("-[MyMethod looksLikeObjC:hasColons:]");
event.AppendName(&output);
EXPECT_EQ(output, "-[MyMethod looksLikeObjC:hasColons:]");
output.clear();
event.AppendArguments(&output);
EXPECT_EQ(output, "");
}

} // namespace
Expand Down
8 changes: 8 additions & 0 deletions bindings/cpp/include/wtf/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ class EventDefinition {
ArgumentZipperCallback argument_zipper_ = nullptr;
};

// Explicit EventDefinition::Create() specialization for zero ArgTypes.
// It creates an EventDefinition with a nullptr ArgumentZipper.
template <>
inline EventDefinition EventDefinition::Create(
int wire_id, EventClass event_class, int flags, const char* name_spec) {
return EventDefinition{wire_id, event_class, flags, name_spec, nullptr};
}

// Singleton registry of all EventDefinitions.
// The registry is thread safe.
class EventRegistry {
Expand Down