Commit 4d3935bc authored by Adam Langley's avatar Adam Langley Committed by Commit Bot

Support hyphens in dictionary identifiers.

WebIDL allows hyphens in identifiers[1], specifically in dictionary
keys. Currently the generated bindings end up emitting the hyphen in C++
which fails to compile.

One option would be to use the ImplementedBy name more uniformly: at the
moment it's used in a couple of places, but generally not for methods
that have strings appended or prepended (like "get" or "set"). That could
be changed at the cost of tweaking a bunch of existing usages.

Instead, this change doesn't touch existing code, but tweaks the
generation so that hyphens in WebIDL identifiers are lowerCamelCased.

This is all motivated because WebAuthn defines a dictionary of
extensions[2] and FIDO has defined an extension with a hyphen in the
name[3].

[1] https://heycam.github.io/webidl/#prod-identifier
[2] https://www.w3.org/TR/webauthn/#iface-authentication-extensions-client-inputs
[3] https://fidoalliance.org/specs/fido-v2.0-rd-20180702/fido-client-to-authenticator-protocol-v2.0-rd-20180702.html#sctn-hmac-secret-extension

Change-Id: Id17c528c5594251385a0a10fa5e91988908b88b6
Reviewed-on: https://chromium-review.googlesource.com/c/1247233
Commit-Queue: Adam Langley <agl@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#597296}
parent 9fae0279
......@@ -462,8 +462,6 @@ def shorten_union_name(union_type):
def to_snake_case(name):
if name.lower() == name:
return name
return NameStyleConverter(name).to_snake_case()
......
......@@ -35,6 +35,7 @@ import os
import re
import sys
from blinkbuild.name_style_converter import NameStyleConverter
from idl_types import IdlTypeBase
import idl_types
from idl_definitions import Exposure, IdlInterface, IdlAttribute
......@@ -366,6 +367,12 @@ def cpp_name(definition_or_member):
extended_attributes = definition_or_member.extended_attributes
if extended_attributes and 'ImplementedAs' in extended_attributes:
return extended_attributes['ImplementedAs']
# WebIDL identifiers can contain hyphens[1], but C++ identifiers cannot.
# Therefore camelCase hyphen-containing identifiers.
#
# [1] https://heycam.github.io/webidl/#prod-identifier
if '-' in definition_or_member.name:
return NameStyleConverter(definition_or_member.name).to_lower_camel_case()
return definition_or_member.name
......
......@@ -63,4 +63,5 @@ dictionary TestDictionary {
record<DOMString, (double or DOMString)?> unionOrNullRecordMember;
VoidCallbackFunction callbackFunctionMember;
required VoidCallbackFunction requiredCallbackFunctionMember;
boolean member-with-hyphen-in-name = false;
};
......@@ -22,6 +22,7 @@ TestDictionary::TestDictionary() {
setDoubleOrStringMember(DoubleOrString::FromDouble(3.14));
setEnumMember("foo");
setLongMember(1);
setMemberWithHyphenInName(false);
setOtherDoubleOrStringMember(DoubleOrString::FromString("default string value"));
setRestrictedDoubleMember(3.14);
setStringOrNullMember("default string value");
......
......@@ -222,6 +222,13 @@ class CORE_EXPORT TestDictionary : public IDLDictionaryBase {
}
inline void setLongMember(int32_t);
bool hasMemberWithHyphenInName() const { return has_member_with_hyphen_in_name_; }
bool memberWithHyphenInName() const {
DCHECK(has_member_with_hyphen_in_name_);
return member_with_hyphen_in_name_;
}
inline void setMemberWithHyphenInName(bool);
bool hasObjectMember() const { return !(object_member_.IsEmpty() || object_member_.IsNull() || object_member_.IsUndefined()); }
ScriptValue objectMember() const {
return object_member_;
......@@ -454,6 +461,7 @@ class CORE_EXPORT TestDictionary : public IDLDictionaryBase {
bool has_internal_dictionary_sequence_member_ = false;
bool has_is_public_ = false;
bool has_long_member_ = false;
bool has_member_with_hyphen_in_name_ = false;
bool has_origin_trial_member_ = false;
bool has_origin_trial_second_member_ = false;
bool has_record_member_ = false;
......@@ -498,6 +506,7 @@ class CORE_EXPORT TestDictionary : public IDLDictionaryBase {
HeapVector<InternalDictionary> internal_dictionary_sequence_member_;
bool is_public_;
int32_t long_member_;
bool member_with_hyphen_in_name_;
ScriptValue object_member_;
ScriptValue object_or_null_member_;
bool origin_trial_member_;
......@@ -602,6 +611,11 @@ void TestDictionary::setLongMember(int32_t value) {
has_long_member_ = true;
}
void TestDictionary::setMemberWithHyphenInName(bool value) {
member_with_hyphen_in_name_ = value;
has_member_with_hyphen_in_name_ = true;
}
void TestDictionary::setOriginTrialMember(bool value) {
origin_trial_member_ = value;
has_origin_trial_member_ = true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment