diff --git a/bindings/cpp/event.cc b/bindings/cpp/event.cc index 01f3c0dd..8693e79f 100644 --- a/bindings/cpp/event.cc +++ b/bindings/cpp/event.cc @@ -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. diff --git a/bindings/cpp/event_test.cc b/bindings/cpp/event_test.cc index 3f33b3ad..df9d7497 100644 --- a/bindings/cpp/event_test.cc +++ b/bindings/cpp/event_test.cc @@ -15,6 +15,11 @@ class EventTest : public ::testing::Test { return EventDefinition::Create( /*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); + } }; @@ -31,7 +36,7 @@ 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"); @@ -39,7 +44,7 @@ TEST_F(EventTest, CheckNameSpecParsing) { 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"); @@ -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 diff --git a/bindings/cpp/include/wtf/event.h b/bindings/cpp/include/wtf/event.h index 6305765c..f6bed5fc 100644 --- a/bindings/cpp/include/wtf/event.h +++ b/bindings/cpp/include/wtf/event.h @@ -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 {