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

Commit c280a21

Browse files
baxissimostellaraccident
authored andcommitted
Handle '::' in name_specs, replacing with '#'.
See #581.
1 parent ca4df14 commit c280a21

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

bindings/cpp/event.cc

+30-6
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,44 @@ bool PeelArgName(const char** arg_names, const char** out_arg_name,
5151
} // namespace
5252

5353
void EventDefinition::AppendName(std::string* output) const {
54-
const char* colon = strchr(name_spec_, ':');
55-
if (colon) {
56-
output->append(name_spec_, (colon - name_spec_));
57-
} else {
58-
output->append(name_spec_);
54+
// Colons are used as separators in WTF's binary format so can't be part of
55+
// identifiers, but '::' commonly appears in auto-generated C++ identifier
56+
// names, as with the __PRETTY_FUNCTION__ built-in macro.
57+
// Replace double colons with '#', which is WTF's class/namespace separator.
58+
//
59+
// A single : in a name_spec separates the name part from arguments.
60+
const char *src = name_spec_;
61+
const char* colon = strchr(src, ':');
62+
while (colon) {
63+
output->append(src, (colon - src));
64+
src = colon + 1;
65+
if (*src == ':') {
66+
// Double colon, replace with # and continue.
67+
output->append("#");
68+
src += 1;
69+
colon = strchr(src, ':');
70+
} else {
71+
// This was a single colon. Output no more.
72+
return;
73+
}
5974
}
75+
// Append anything remaining in src.
76+
output->append(src);
6077
}
6178

6279
void EventDefinition::AppendArguments(std::string* output) const {
6380
if (argument_zipper_ && name_spec_) {
6481
const char* arg_names = strchr(name_spec_, ':');
65-
if (arg_names) {
82+
while (arg_names) {
6683
// Colon found - advance.
6784
arg_names += 1;
85+
if (*arg_names == ':') {
86+
// Actually a '::' namespace separator, keep looking.
87+
arg_names += 1;
88+
arg_names = strchr(arg_names, ':');
89+
} else {
90+
break;
91+
}
6892
}
6993
argument_zipper_(output, arg_names);
7094
}

0 commit comments

Comments
 (0)