Changeset 269757 in webkit


Ignore:
Timestamp:
Nov 12, 2020 2:54:19 PM (3 years ago)
Author:
Devin Rousso
Message:

Web Inspector: ensure that JSON::ArrayOf<T> doesn't allow addItem to be called with a type other than T
https://bugs.webkit.org/show_bug.cgi?id=218686

Reviewed by Brian Burg.

Source/JavaScriptCore:

  • inspector/scripts/codegen/cpp_generator_templates.py:
  • inspector/scripts/codegen/generate_cpp_backend_dispatcher_implementation.py:

(CppBackendDispatcherImplementationGenerator._generate_small_dispatcher_switch_implementation_for_domain):
(CppBackendDispatcherImplementationGenerator._generate_large_dispatcher_switch_implementation_for_domain):

  • inspector/scripts/codegen/generate_cpp_protocol_types_header.py:
  • inspector/scripts/codegen/generate_cpp_protocol_types_implementation.py:

(CppProtocolTypesImplementationGenerator._generate_enum_mapping):
(CppProtocolTypesImplementationGenerator._generate_open_field_names):
Use ASCIILiteral, makeString, and _s instead of inlined char* to ensure that the
String function overload is used.

  • inspector/scripts/tests/expected/command-targetType-matching-domain-debuggableType.json-result:
  • inspector/scripts/tests/expected/commands-with-async-attribute.json-result:
  • inspector/scripts/tests/expected/commands-with-optional-call-return-parameters.json-result:
  • inspector/scripts/tests/expected/definitions-with-mac-platform.json-result:
  • inspector/scripts/tests/expected/domain-debuggableTypes.json-result:
  • inspector/scripts/tests/expected/domain-targetType-matching-domain-debuggableType.json-result:
  • inspector/scripts/tests/expected/domain-targetTypes.json-result:
  • inspector/scripts/tests/expected/domains-with-varying-command-sizes.json-result:
  • inspector/scripts/tests/expected/enum-values.json-result:
  • inspector/scripts/tests/expected/event-targetType-matching-domain-debuggableType.json-result:
  • inspector/scripts/tests/expected/generate-domains-with-feature-guards.json-result:
  • inspector/scripts/tests/expected/shadowed-optional-type-setters.json-result:
  • inspector/scripts/tests/expected/type-declaration-array-type.json-result:
  • inspector/scripts/tests/expected/type-declaration-enum-type.json-result:
  • inspector/scripts/tests/expected/type-declaration-object-type.json-result:
  • inspector/scripts/tests/expected/type-requiring-runtime-casts.json-result:
  • inspector/scripts/tests/expected/type-with-open-parameters.json-result:

Source/WTF:

  • wtf/JSONValues.h:

(WTF::JSONImpl::Value::Value):
(WTF::JSONImpl::Value::Value):
(WTF::JSONImpl::ArrayOf::addItem):

  • wtf/JSONValues.cpp:

(WTF::JSONImpl::Value::create):
Right now, JSON::ArrayOf<T> always has addItem overloads for int, double, String,
and Ref<T> (even when T is not a JSON::Value). This means that a JSON::ArrayOf<int>
can call addItem(42.0) or addItem("foo"_s) and it would work. This doesn't really match
the intention of JSON::ArrayOf<T>, so add some template std::enable_if to ensure that
the only addItem overload that exists is the one that matches T.

Tools:

  • TestWebKitAPI/Tests/WTF/JSONValue.cpp:

(TestWebKitAPI::TEST):
Use _s and makeString to ensure that the String function overload is used.

Location:
trunk
Files:
27 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r269729 r269757  
     12020-11-12  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: ensure that `JSON::ArrayOf<T>` doesn't allow `addItem` to be called with a type other than `T`
     4        https://bugs.webkit.org/show_bug.cgi?id=218686
     5
     6        Reviewed by Brian Burg.
     7
     8        * inspector/scripts/codegen/cpp_generator_templates.py:
     9        * inspector/scripts/codegen/generate_cpp_backend_dispatcher_implementation.py:
     10        (CppBackendDispatcherImplementationGenerator._generate_small_dispatcher_switch_implementation_for_domain):
     11        (CppBackendDispatcherImplementationGenerator._generate_large_dispatcher_switch_implementation_for_domain):
     12        * inspector/scripts/codegen/generate_cpp_protocol_types_header.py:
     13        * inspector/scripts/codegen/generate_cpp_protocol_types_implementation.py:
     14        (CppProtocolTypesImplementationGenerator._generate_enum_mapping):
     15        (CppProtocolTypesImplementationGenerator._generate_open_field_names):
     16        Use `ASCIILiteral`, `makeString`, and `_s` instead of inlined `char*` to ensure that the
     17        `String` function overload is used.
     18
     19        * inspector/scripts/tests/expected/command-targetType-matching-domain-debuggableType.json-result:
     20        * inspector/scripts/tests/expected/commands-with-async-attribute.json-result:
     21        * inspector/scripts/tests/expected/commands-with-optional-call-return-parameters.json-result:
     22        * inspector/scripts/tests/expected/definitions-with-mac-platform.json-result:
     23        * inspector/scripts/tests/expected/domain-debuggableTypes.json-result:
     24        * inspector/scripts/tests/expected/domain-targetType-matching-domain-debuggableType.json-result:
     25        * inspector/scripts/tests/expected/domain-targetTypes.json-result:
     26        * inspector/scripts/tests/expected/domains-with-varying-command-sizes.json-result:
     27        * inspector/scripts/tests/expected/enum-values.json-result:
     28        * inspector/scripts/tests/expected/event-targetType-matching-domain-debuggableType.json-result:
     29        * inspector/scripts/tests/expected/generate-domains-with-feature-guards.json-result:
     30        * inspector/scripts/tests/expected/shadowed-optional-type-setters.json-result:
     31        * inspector/scripts/tests/expected/type-declaration-array-type.json-result:
     32        * inspector/scripts/tests/expected/type-declaration-enum-type.json-result:
     33        * inspector/scripts/tests/expected/type-declaration-object-type.json-result:
     34        * inspector/scripts/tests/expected/type-requiring-runtime-casts.json-result:
     35        * inspector/scripts/tests/expected/type-with-open-parameters.json-result:
     36
    1372020-11-12  Dmitry Bezhetskov  <dbezhetskov@igalia.com>
    238
  • trunk/Source/JavaScriptCore/inspector/scripts/codegen/cpp_generator_templates.py

    r266885 r269757  
    128128${dispatchCases}
    129129
    130     m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'${domainName}." + protocol_method + "' was not found");
     130    m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'${domainName}."_s, protocol_method, "' was not found"_s));
    131131}""")
    132132
     
    140140    using CallHandler = void (${domainName}BackendDispatcher::*)(long protocol_requestId, RefPtr<JSON::Object>&& protocol_message);
    141141    using DispatchMap = HashMap<String, CallHandler>;
    142     static NeverDestroyed<DispatchMap> dispatchMap;
    143     if (dispatchMap.get().isEmpty()) {
    144         static const struct MethodTable {
    145             const char* name;
    146             CallHandler handler;
    147         } commands[] = {
     142    static NeverDestroyed<DispatchMap> dispatchMap = DispatchMap({
    148143${dispatchCases}
    149         };
    150         size_t length = WTF_ARRAY_LENGTH(commands);
    151         for (size_t i = 0; i < length; ++i)
    152             dispatchMap.get().add(commands[i].name, commands[i].handler);
    153     }
    154 
    155     auto findResult = dispatchMap.get().find(protocol_method);
    156     if (findResult == dispatchMap.get().end()) {
    157         m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'${domainName}." + protocol_method + "' was not found");
     144    });
     145
     146    auto findResult = dispatchMap->find(protocol_method);
     147    if (findResult == dispatchMap->end()) {
     148        m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'${domainName}."_s, protocol_method, "' was not found"_s));
    158149        return;
    159150    }
  • trunk/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_backend_dispatcher_implementation.py

    r266885 r269757  
    121121
    122122        first_command_string = "\n".join([
    123             '    if (protocol_method == "%s") {' % commands[0].command_name,
     123            '    if (protocol_method == "%s"_s) {' % commands[0].command_name,
    124124            '        %s(protocol_requestId, WTFMove(protocol_parameters));' % commands[0].command_name,
    125125            '        return;',
     
    130130        for command in commands[1:]:
    131131            additional_command_string = "\n".join([
    132                 '    if (protocol_method == "%s") {' % command.command_name,
     132                '    if (protocol_method == "%s"_s) {' % command.command_name,
    133133                '        %s(protocol_requestId, WTFMove(protocol_parameters));' % command.command_name,
    134134                '        return;',
     
    153153                'commandName': command.command_name
    154154            }
    155             cases.append(self.wrap_with_guard_for_condition(command.condition, '            { "%(commandName)s", &%(domainName)sBackendDispatcher::%(commandName)s },' % args))
     155            cases.append(self.wrap_with_guard_for_condition(command.condition, '        { "%(commandName)s"_s, &%(domainName)sBackendDispatcher::%(commandName)s },' % args))
    156156
    157157        switch_args = {
  • trunk/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_protocol_types_header.py

    r266885 r269757  
    277277            for type_member in open_members:
    278278                export_macro = self.model().framework.setting('export_macro', None)
    279                 lines.append('    %s static const char* %sKey;' % (export_macro, type_member.member_name))
     279                lines.append('    %s static const ASCIILiteral %sKey;' % (export_macro, type_member.member_name))
    280280
    281281        lines.append('};')
  • trunk/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_protocol_types_implementation.py

    r266885 r269757  
    9292
    9393        lines = []
    94         lines.append('static const char* const enum_constant_values[] = {')
    95         lines.extend(['    "%s",' % enum_value for enum_value in self.assigned_enum_values()])
     94        lines.append('static const ASCIILiteral enum_constant_values[] = {')
     95        lines.extend(['    "%s"_s,' % enum_value for enum_value in self.assigned_enum_values()])
    9696        lines.append('};')
    9797        lines.append('')
     
    182182                open_members = Generator.open_fields(type_declaration)
    183183                for type_member in sorted(open_members, key=lambda member: member.member_name):
    184                     domain_lines.append('const char* Protocol::%s::%s::%sKey = "%s";' % (domain.domain_name, ucfirst(type_declaration.type_name), type_member.member_name, type_member.member_name))
     184                    domain_lines.append('const ASCIILiteral Protocol::%s::%s::%sKey = "%s"_s;' % (domain.domain_name, ucfirst(type_declaration.type_name), type_member.member_name, type_member.member_name))
    185185            if len(domain_lines):
    186186                lines.append(self.wrap_with_guard_for_condition(domain.condition, '\n'.join(domain_lines)))
  • trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/command-targetType-matching-domain-debuggableType.json-result

    r266885 r269757  
    233233    auto protocol_parameters = protocol_message->getObject("params"_s);
    234234
    235     if (protocol_method == "Command") {
     235    if (protocol_method == "Command"_s) {
    236236        Command(protocol_requestId, WTFMove(protocol_parameters));
    237237        return;
    238238    }
    239239
    240     m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Domain." + protocol_method + "' was not found");
     240    m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Domain."_s, protocol_method, "' was not found"_s));
    241241}
    242242
  • trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/commands-with-async-attribute.json-result

    r266885 r269757  
    255255    auto protocol_parameters = protocol_message->getObject("params"_s);
    256256
    257     if (protocol_method == "executeSQLSyncOptionalReturnValues") {
     257    if (protocol_method == "executeSQLSyncOptionalReturnValues"_s) {
    258258        executeSQLSyncOptionalReturnValues(protocol_requestId, WTFMove(protocol_parameters));
    259259        return;
    260260    }
    261     if (protocol_method == "executeSQLAsyncOptionalReturnValues") {
     261    if (protocol_method == "executeSQLAsyncOptionalReturnValues"_s) {
    262262        executeSQLAsyncOptionalReturnValues(protocol_requestId, WTFMove(protocol_parameters));
    263263        return;
    264264    }
    265     if (protocol_method == "executeSQLSync") {
     265    if (protocol_method == "executeSQLSync"_s) {
    266266        executeSQLSync(protocol_requestId, WTFMove(protocol_parameters));
    267267        return;
    268268    }
    269     if (protocol_method == "executeSQLAsync") {
     269    if (protocol_method == "executeSQLAsync"_s) {
    270270        executeSQLAsync(protocol_requestId, WTFMove(protocol_parameters));
    271271        return;
    272272    }
    273273
    274     m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Database." + protocol_method + "' was not found");
     274    m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Database."_s, protocol_method, "' was not found"_s));
    275275}
    276276
     
    753753namespace TestHelpers {
    754754
    755 static const char* const enum_constant_values[] = {
    756     "red",
    757     "green",
    758     "blue",
    759     "cyan",
    760     "magenta",
    761     "yellow",
    762     "black",
     755static const ASCIILiteral enum_constant_values[] = {
     756    "red"_s,
     757    "green"_s,
     758    "blue"_s,
     759    "cyan"_s,
     760    "magenta"_s,
     761    "yellow"_s,
     762    "black"_s,
    763763};
    764764
  • trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/commands-with-optional-call-return-parameters.json-result

    r266885 r269757  
    236236    auto protocol_parameters = protocol_message->getObject("params"_s);
    237237
    238     if (protocol_method == "executeAllOptionalParameters") {
     238    if (protocol_method == "executeAllOptionalParameters"_s) {
    239239        executeAllOptionalParameters(protocol_requestId, WTFMove(protocol_parameters));
    240240        return;
    241241    }
    242     if (protocol_method == "executeNoOptionalParameters") {
     242    if (protocol_method == "executeNoOptionalParameters"_s) {
    243243        executeNoOptionalParameters(protocol_requestId, WTFMove(protocol_parameters));
    244244        return;
    245245    }
    246246
    247     m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Database." + protocol_method + "' was not found");
     247    m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Database."_s, protocol_method, "' was not found"_s));
    248248}
    249249
     
    666666namespace TestHelpers {
    667667
    668 static const char* const enum_constant_values[] = {
    669     "red",
    670     "green",
    671     "blue",
    672     "cyan",
    673     "magenta",
    674     "yellow",
    675     "black",
     668static const ASCIILiteral enum_constant_values[] = {
     669    "red"_s,
     670    "green"_s,
     671    "blue"_s,
     672    "cyan"_s,
     673    "magenta"_s,
     674    "yellow"_s,
     675    "black"_s,
    676676};
    677677
  • trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/definitions-with-mac-platform.json-result

    r266885 r269757  
    257257
    258258#if COMMAND-MAC
    259     if (protocol_method == "loadResource") {
     259    if (protocol_method == "loadResource"_s) {
    260260        loadResource(protocol_requestId, WTFMove(protocol_parameters));
    261261        return;
     
    263263#endif // COMMAND-MAC
    264264
    265     m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Network." + protocol_method + "' was not found");
     265    m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Network."_s, protocol_method, "' was not found"_s));
    266266}
    267267
  • trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/domain-debuggableTypes.json-result

    r266885 r269757  
    233233    auto protocol_parameters = protocol_message->getObject("params"_s);
    234234
    235     if (protocol_method == "Command") {
     235    if (protocol_method == "Command"_s) {
    236236        Command(protocol_requestId, WTFMove(protocol_parameters));
    237237        return;
    238238    }
    239239
    240     m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Domain." + protocol_method + "' was not found");
     240    m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Domain."_s, protocol_method, "' was not found"_s));
    241241}
    242242
  • trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/domain-targetType-matching-domain-debuggableType.json-result

    r266885 r269757  
    233233    auto protocol_parameters = protocol_message->getObject("params"_s);
    234234
    235     if (protocol_method == "Command") {
     235    if (protocol_method == "Command"_s) {
    236236        Command(protocol_requestId, WTFMove(protocol_parameters));
    237237        return;
    238238    }
    239239
    240     m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Domain." + protocol_method + "' was not found");
     240    m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Domain."_s, protocol_method, "' was not found"_s));
    241241}
    242242
  • trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/domain-targetTypes.json-result

    r266885 r269757  
    233233    auto protocol_parameters = protocol_message->getObject("params"_s);
    234234
    235     if (protocol_method == "Command") {
     235    if (protocol_method == "Command"_s) {
    236236        Command(protocol_requestId, WTFMove(protocol_parameters));
    237237        return;
    238238    }
    239239
    240     m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Domain." + protocol_method + "' was not found");
     240    m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Domain."_s, protocol_method, "' was not found"_s));
    241241}
    242242
  • trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/domains-with-varying-command-sizes.json-result

    r266885 r269757  
    292292    auto protocol_parameters = protocol_message->getObject("params"_s);
    293293
    294     if (protocol_method == "loadResource1") {
     294    if (protocol_method == "loadResource1"_s) {
    295295        loadResource1(protocol_requestId, WTFMove(protocol_parameters));
    296296        return;
    297297    }
    298298
    299     m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Network1." + protocol_method + "' was not found");
     299    m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Network1."_s, protocol_method, "' was not found"_s));
    300300}
    301301
     
    340340    using CallHandler = void (Network3BackendDispatcher::*)(long protocol_requestId, RefPtr<JSON::Object>&& protocol_message);
    341341    using DispatchMap = HashMap<String, CallHandler>;
    342     static NeverDestroyed<DispatchMap> dispatchMap;
    343     if (dispatchMap.get().isEmpty()) {
    344         static const struct MethodTable {
    345             const char* name;
    346             CallHandler handler;
    347         } commands[] = {
    348             { "loadResource1", &Network3BackendDispatcher::loadResource1 },
    349             { "loadResource2", &Network3BackendDispatcher::loadResource2 },
    350             { "loadResource3", &Network3BackendDispatcher::loadResource3 },
    351             { "loadResource4", &Network3BackendDispatcher::loadResource4 },
    352             { "loadResource5", &Network3BackendDispatcher::loadResource5 },
    353             { "loadResource6", &Network3BackendDispatcher::loadResource6 },
    354             { "loadResource7", &Network3BackendDispatcher::loadResource7 },
    355         };
    356         size_t length = WTF_ARRAY_LENGTH(commands);
    357         for (size_t i = 0; i < length; ++i)
    358             dispatchMap.get().add(commands[i].name, commands[i].handler);
    359     }
    360 
    361     auto findResult = dispatchMap.get().find(protocol_method);
    362     if (findResult == dispatchMap.get().end()) {
    363         m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Network3." + protocol_method + "' was not found");
     342    static NeverDestroyed<DispatchMap> dispatchMap = DispatchMap({
     343        { "loadResource1"_s, &Network3BackendDispatcher::loadResource1 },
     344        { "loadResource2"_s, &Network3BackendDispatcher::loadResource2 },
     345        { "loadResource3"_s, &Network3BackendDispatcher::loadResource3 },
     346        { "loadResource4"_s, &Network3BackendDispatcher::loadResource4 },
     347        { "loadResource5"_s, &Network3BackendDispatcher::loadResource5 },
     348        { "loadResource6"_s, &Network3BackendDispatcher::loadResource6 },
     349        { "loadResource7"_s, &Network3BackendDispatcher::loadResource7 },
     350    });
     351
     352    auto findResult = dispatchMap->find(protocol_method);
     353    if (findResult == dispatchMap->end()) {
     354        m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Network3."_s, protocol_method, "' was not found"_s));
    364355        return;
    365356    }
  • trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/enum-values.json-result

    r266885 r269757  
    244244    auto protocol_parameters = protocol_message->getObject("params"_s);
    245245
    246     if (protocol_method == "command") {
     246    if (protocol_method == "command"_s) {
    247247        command(protocol_requestId, WTFMove(protocol_parameters));
    248248        return;
    249249    }
    250250
    251     m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'CommandDomain." + protocol_method + "' was not found");
     251    m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'CommandDomain."_s, protocol_method, "' was not found"_s));
    252252}
    253253
     
    567567namespace TestHelpers {
    568568
    569 static const char* const enum_constant_values[] = {
    570     "shared",
    571     "1",
    572     "2",
    573     "sharedRequired",
    574     "grey",
    575     "sharedOptional",
    576     "green",
    577     "black",
    578     "red",
    579     "white",
    580     "blue",
     569static const ASCIILiteral enum_constant_values[] = {
     570    "shared"_s,
     571    "1"_s,
     572    "2"_s,
     573    "sharedRequired"_s,
     574    "grey"_s,
     575    "sharedOptional"_s,
     576    "green"_s,
     577    "black"_s,
     578    "red"_s,
     579    "white"_s,
     580    "blue"_s,
    581581};
    582582
  • trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/event-targetType-matching-domain-debuggableType.json-result

    r266885 r269757  
    233233    auto protocol_parameters = protocol_message->getObject("params"_s);
    234234
    235     if (protocol_method == "Command") {
     235    if (protocol_method == "Command"_s) {
    236236        Command(protocol_requestId, WTFMove(protocol_parameters));
    237237        return;
    238238    }
    239239
    240     m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Domain." + protocol_method + "' was not found");
     240    m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Domain."_s, protocol_method, "' was not found"_s));
    241241}
    242242
  • trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/generate-domains-with-feature-guards.json-result

    r266885 r269757  
    237237    auto protocol_parameters = protocol_message->getObject("params"_s);
    238238
    239     if (protocol_method == "loadResource") {
     239    if (protocol_method == "loadResource"_s) {
    240240        loadResource(protocol_requestId, WTFMove(protocol_parameters));
    241241        return;
    242242    }
    243243
    244     m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Network1." + protocol_method + "' was not found");
     244    m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Network1."_s, protocol_method, "' was not found"_s));
    245245}
    246246
  • trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/shadowed-optional-type-setters.json-result

    r266885 r269757  
    469469namespace TestHelpers {
    470470
    471 static const char* const enum_constant_values[] = {
    472     "null",
    473     "string",
    474     "array",
     471static const ASCIILiteral enum_constant_values[] = {
     472    "null"_s,
     473    "string"_s,
     474    "array"_s,
    475475};
    476476
  • trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/type-declaration-array-type.json-result

    r266885 r269757  
    429429namespace TestHelpers {
    430430
    431 static const char* const enum_constant_values[] = {
    432     "Died",
    433     "Fainted",
    434     "Hungry",
     431static const ASCIILiteral enum_constant_values[] = {
     432    "Died"_s,
     433    "Fainted"_s,
     434    "Hungry"_s,
    435435};
    436436
  • trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/type-declaration-enum-type.json-result

    r266885 r269757  
    430430namespace TestHelpers {
    431431
    432 static const char* const enum_constant_values[] = {
    433     "Pigs",
    434     "Cows",
    435     "Cats",
    436     "Hens",
    437     "Ducks",
    438     "Crows",
    439     "Flamingos",
     432static const ASCIILiteral enum_constant_values[] = {
     433    "Pigs"_s,
     434    "Cows"_s,
     435    "Cats"_s,
     436    "Hens"_s,
     437    "Ducks"_s,
     438    "Crows"_s,
     439    "Flamingos"_s,
    440440};
    441441
  • trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/type-declaration-object-type.json-result

    r266885 r269757  
    10091009namespace TestHelpers {
    10101010
    1011 static const char* const enum_constant_values[] = {
    1012     "None",
    1013     "Left",
    1014     "Middle",
    1015     "Right",
    1016     "LTR",
    1017     "RTL",
     1011static const ASCIILiteral enum_constant_values[] = {
     1012    "None"_s,
     1013    "Left"_s,
     1014    "Middle"_s,
     1015    "Right"_s,
     1016    "LTR"_s,
     1017    "RTL"_s,
    10181018};
    10191019
  • trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/type-requiring-runtime-casts.json-result

    r266885 r269757  
    647647namespace TestHelpers {
    648648
    649 static const char* const enum_constant_values[] = {
    650     "Ducks",
    651     "Hens",
    652     "Crows",
    653     "Flamingos",
    654     "Pigs",
    655     "Cows",
    656     "Cats",
     649static const ASCIILiteral enum_constant_values[] = {
     650    "Ducks"_s,
     651    "Hens"_s,
     652    "Crows"_s,
     653    "Flamingos"_s,
     654    "Pigs"_s,
     655    "Cows"_s,
     656    "Cats"_s,
    657657};
    658658
  • trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/type-with-open-parameters.json-result

    r266885 r269757  
    454454
    455455    // Property names for type generated as open.
    456     None static const char* alphaKey;
     456    None static const ASCIILiteral alphaKey;
    457457};
    458458
     
    505505namespace Protocol {
    506506
    507 const char* Protocol::Test::OpenParameters::alphaKey = "alpha";
     507const ASCIILiteral Protocol::Test::OpenParameters::alphaKey = "alpha"_s;
    508508
    509509} // namespace Protocol
  • trunk/Source/WTF/ChangeLog

    r269726 r269757  
     12020-11-12  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: ensure that `JSON::ArrayOf<T>` doesn't allow `addItem` to be called with a type other than `T`
     4        https://bugs.webkit.org/show_bug.cgi?id=218686
     5
     6        Reviewed by Brian Burg.
     7
     8        * wtf/JSONValues.h:
     9        (WTF::JSONImpl::Value::Value):
     10        (WTF::JSONImpl::Value::Value):
     11        (WTF::JSONImpl::ArrayOf::addItem):
     12        * wtf/JSONValues.cpp:
     13        (WTF::JSONImpl::Value::create):
     14        Right now, `JSON::ArrayOf<T>` always has `addItem` overloads for `int`, `double`, `String`,
     15        and `Ref<T>` (even when `T` is not a `JSON::Value`). This means that a `JSON::ArrayOf<int>`
     16        can call `addItem(42.0)` or `addItem("foo"_s)` and it would work. This doesn't really match
     17        the intention of `JSON::ArrayOf<T>`, so add some template `std::enable_if` to ensure that
     18        the only `addItem` overload that exists is the one that matches `T`.
     19
    1202020-11-12  Zalan Bujtas  <zalan@apple.com>
    221
  • trunk/Source/WTF/wtf/JSONValues.cpp

    r267219 r269757  
    485485}
    486486
    487 Ref<Value> Value::create(const char* value)
    488 {
    489     return adoptRef(*new Value(value));
    490 }
    491 
    492487RefPtr<Value> Value::asValue()
    493488{
  • trunk/Source/WTF/wtf/JSONValues.h

    r267219 r269757  
    7878    static Ref<Value> create(double);
    7979    static Ref<Value> create(const String&);
    80     static Ref<Value> create(const char*);
    8180
    8281    enum class Type {
     
    151150    }
    152151
    153     explicit Value(const char* value)
    154         : m_type { Type::String }
    155     {
    156         String wrapper(value);
    157         m_value.string = wrapper.impl();
    158         if (m_value.string)
    159             m_value.string->ref();
    160     }
    161 
    162152private:
    163153    Type m_type { Type::Null };
     
    416406
    417407public:
    418     void addItem(Ref<T>&& value)
     408
     409    template <typename V = T>
     410    std::enable_if_t<std::is_same_v<bool, V> || std::is_same_v<Value, V>> addItem(bool value)
     411    {
     412        castedArray().pushBoolean(value);
     413    }
     414
     415    template <typename V = T>
     416    std::enable_if_t<std::is_same_v<int, V> || std::is_same_v<Value, V>> addItem(int value)
     417    {
     418        castedArray().pushInteger(value);
     419    }
     420
     421    template <typename V = T>
     422    std::enable_if_t<std::is_same_v<double, V> || std::is_same_v<Value, V>> addItem(double value)
     423    {
     424        castedArray().pushDouble(value);
     425    }
     426
     427    template <typename V = T>
     428    std::enable_if_t<std::is_same_v<String, V> || std::is_same_v<Value, V>> addItem(const String& value)
     429    {
     430        castedArray().pushString(value);
     431    }
     432
     433    template <typename V = T>
     434    std::enable_if_t<std::is_base_of_v<Value, V> && !std::is_base_of_v<ObjectBase, V> && !std::is_base_of_v<ArrayBase, V>> addItem(Ref<Value>&& value)
    419435    {
    420436        castedArray().pushValue(WTFMove(value));
    421437    }
    422    
    423     void addItem(const String& value)
    424     {
    425         castedArray().pushString(value);
    426     }
    427 
    428     void addItem(int value)
    429     {
    430         castedArray().pushInteger(value);
    431     }
    432 
    433     void addItem(double value)
    434     {
    435         castedArray().pushDouble(value);
     438
     439    template <typename V = T>
     440    std::enable_if_t<std::is_base_of_v<ObjectBase, V>> addItem(Ref<ObjectBase>&& value)
     441    {
     442        castedArray().pushObject(WTFMove(value));
     443    }
     444
     445    template <typename V = T>
     446    std::enable_if_t<std::is_base_of_v<ArrayBase, V>> addItem(Ref<ArrayBase>&& value)
     447    {
     448        castedArray().pushArray(WTFMove(value));
    436449    }
    437450
  • trunk/Tools/ChangeLog

    r269752 r269757  
     12020-11-12  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: ensure that `JSON::ArrayOf<T>` doesn't allow `addItem` to be called with a type other than `T`
     4        https://bugs.webkit.org/show_bug.cgi?id=218686
     5
     6        Reviewed by Brian Burg.
     7
     8        * TestWebKitAPI/Tests/WTF/JSONValue.cpp:
     9        (TestWebKitAPI::TEST):
     10        Use `_s` and `makeString` to ensure that the `String` function overload is used.
     11
    1122020-11-12  Ali Juma  <ajuma@chromium.org>
    213
  • trunk/Tools/TestWebKitAPI/Tests/WTF/JSONValue.cpp

    r266885 r269757  
    8787
    8888    {
    89         Ref<JSON::Value> value = JSON::Value::create("webkit");
     89        Ref<JSON::Value> value = JSON::Value::create(makeString("webkit"_s));
    9090        EXPECT_TRUE(value->type() == JSON::Value::Type::String);
    9191        auto stringValue = value->asString();
    9292        EXPECT_TRUE(!!stringValue);
    93         EXPECT_EQ(stringValue, "webkit");
     93        EXPECT_EQ(stringValue, "webkit"_s);
    9494
    9595        String nullString;
     
    161161    EXPECT_EQ(*doubleValue, 1.5);
    162162
    163     array->pushString("webkit");
     163    array->pushString("webkit"_s);
    164164    EXPECT_EQ(array->length(), 5U);
    165165    value = array->get(4);
     
    167167    auto stringValue = value->asString();
    168168    EXPECT_TRUE(!!stringValue);
    169     EXPECT_EQ(stringValue, "webkit");
     169    EXPECT_EQ(stringValue, "webkit"_s);
    170170
    171171    array->pushObject(JSON::Object::create());
     
    250250    EXPECT_EQ(*doubleValue, 1.5);
    251251
    252     array->addItem("webkit");
     252    array->addItem(makeString("webkit"_s));
    253253    EXPECT_EQ(array->length(), 4U);
    254254    value = array->get(3);
     
    256256    auto stringValue = value->asString();
    257257    EXPECT_TRUE(!!stringValue);
    258     EXPECT_EQ(stringValue, "webkit");
     258    EXPECT_EQ(stringValue, "webkit"_s);
    259259
    260260    array->addItem(JSON::Object::create());
     
    312312    object->setValue("null", JSON::Value::null());
    313313    EXPECT_EQ(object->size(), 1U);
    314     auto value = object->getValue("null");
     314    auto value = object->getValue("null"_s);
    315315    EXPECT_TRUE(value);
    316316    EXPECT_TRUE(value->isNull());
     
    318318    object->setBoolean("boolean", true);
    319319    EXPECT_EQ(object->size(), 2U);
    320     auto booleanValue = object->getBoolean("boolean");
     320    auto booleanValue = object->getBoolean("boolean"_s);
    321321    EXPECT_TRUE(booleanValue);
    322322    EXPECT_EQ(*booleanValue, true);
     
    324324    object->setInteger("integer", 1);
    325325    EXPECT_EQ(object->size(), 3U);
    326     auto integerValue = object->getInteger("integer");
     326    auto integerValue = object->getInteger("integer"_s);
    327327    EXPECT_TRUE(integerValue);
    328328    EXPECT_EQ(*integerValue, 1);
     
    330330    object->setDouble("double", 1.5);
    331331    EXPECT_EQ(object->size(), 4U);
    332     auto doubleValue = object->getDouble("double");
     332    auto doubleValue = object->getDouble("double"_s);
    333333    EXPECT_TRUE(doubleValue);
    334334    EXPECT_EQ(*doubleValue, 1.5);
    335335
    336     object->setString("string", "webkit");
     336    object->setString("string", "webkit"_s);
    337337    EXPECT_EQ(object->size(), 5U);
    338     auto stringValue = object->getString("string");
     338    auto stringValue = object->getString("string"_s);
    339339    EXPECT_TRUE(!!stringValue);
    340     EXPECT_EQ(stringValue, "webkit");
     340    EXPECT_EQ(stringValue, "webkit"_s);
    341341
    342342    object->setObject("object", JSON::Object::create());
    343343    EXPECT_EQ(object->size(), 6U);
    344     auto objectValue = object->getObject("object");
     344    auto objectValue = object->getObject("object"_s);
    345345    EXPECT_TRUE(objectValue);
    346346    EXPECT_EQ(objectValue->size(), 0U);
     
    348348    object->setArray("array", JSON::Array::create());
    349349    EXPECT_EQ(object->size(), 7U);
    350     auto arrayValue = object->getArray("array");
     350    auto arrayValue = object->getArray("array"_s);
    351351    EXPECT_TRUE(arrayValue);
    352352    EXPECT_EQ(arrayValue->length(), 0U);
    353353
    354     Vector<const char*> keys = { "null", "boolean", "integer", "double", "string", "object", "array" };
     354    Vector<String> keys = { "null"_s, "boolean"_s, "integer"_s, "double"_s, "string"_s, "object"_s, "array"_s };
    355355    auto end = object->end();
    356356    for (auto it = object->begin(); it != end; ++it) {
     
    362362    EXPECT_TRUE(keys.isEmpty());
    363363
    364     object->remove("null");
     364    object->remove("null"_s);
    365365    EXPECT_EQ(object->size(), 6U);
    366     EXPECT_TRUE(object->find("null") == object->end());
    367 
    368     object->remove("boolean");
     366    EXPECT_TRUE(object->find("null"_s) == object->end());
     367
     368    object->remove("boolean"_s);
    369369    EXPECT_EQ(object->size(), 5U);
    370     EXPECT_TRUE(object->find("boolean") == object->end());
    371 
    372     object->remove("integer");
     370    EXPECT_TRUE(object->find("boolean"_s) == object->end());
     371
     372    object->remove("integer"_s);
    373373    EXPECT_EQ(object->size(), 4U);
    374     EXPECT_TRUE(object->find("integer") == object->end());
    375 
    376     object->remove("double");
     374    EXPECT_TRUE(object->find("integer"_s) == object->end());
     375
     376    object->remove("double"_s);
    377377    EXPECT_EQ(object->size(), 3U);
    378     EXPECT_TRUE(object->find("double") == object->end());
    379 
    380     object->remove("string");
     378    EXPECT_TRUE(object->find("double"_s) == object->end());
     379
     380    object->remove("string"_s);
    381381    EXPECT_EQ(object->size(), 2U);
    382     EXPECT_TRUE(object->find("string") == object->end());
    383 
    384     object->remove("object");
     382    EXPECT_TRUE(object->find("string"_s) == object->end());
     383
     384    object->remove("object"_s);
    385385    EXPECT_EQ(object->size(), 1U);
    386     EXPECT_TRUE(object->find("object") == object->end());
    387 
    388     object->remove("array");
     386    EXPECT_TRUE(object->find("object"_s) == object->end());
     387
     388    object->remove("array"_s);
    389389    EXPECT_EQ(object->size(), 0U);
    390     EXPECT_TRUE(object->find("array") == object->end());
     390    EXPECT_TRUE(object->find("array"_s) == object->end());
    391391}
    392392
     
    395395    {
    396396        Ref<JSON::Value> value = JSON::Value::null();
    397         EXPECT_EQ(value->toJSONString(), "null");
     397        EXPECT_EQ(value->toJSONString(), "null"_s);
    398398    }
    399399
    400400    {
    401401        Ref<JSON::Value> value = JSON::Value::create(true);
    402         EXPECT_EQ(value->toJSONString(), "true");
     402        EXPECT_EQ(value->toJSONString(), "true"_s);
    403403
    404404        value = JSON::Value::create(false);
    405         EXPECT_EQ(value->toJSONString(), "false");
     405        EXPECT_EQ(value->toJSONString(), "false"_s);
    406406    }
    407407
    408408    {
    409409        Ref<JSON::Value> value = JSON::Value::create(1);
    410         EXPECT_EQ(value->toJSONString(), "1");
     410        EXPECT_EQ(value->toJSONString(), "1"_s);
    411411    }
    412412
    413413    {
    414414        Ref<JSON::Value> value = JSON::Value::create(1.5);
    415         EXPECT_EQ(value->toJSONString(), "1.5");
    416     }
    417 
    418     {
    419         Ref<JSON::Value> value = JSON::Value::create("webkit");
    420         EXPECT_EQ(value->toJSONString(), "\"webkit\"");
     415        EXPECT_EQ(value->toJSONString(), "1.5"_s);
     416    }
     417
     418    {
     419        Ref<JSON::Value> value = JSON::Value::create(makeString("webkit"_s));
     420        EXPECT_EQ(value->toJSONString(), "\"webkit\""_s);
    421421    }
    422422
    423423    {
    424424        Ref<JSON::Array> array = JSON::Array::create();
    425         EXPECT_EQ(array->toJSONString(), "[]");
     425        EXPECT_EQ(array->toJSONString(), "[]"_s);
    426426        array->pushValue(JSON::Value::null());
    427         EXPECT_EQ(array->toJSONString(), "[null]");
     427        EXPECT_EQ(array->toJSONString(), "[null]"_s);
    428428        array->pushBoolean(true);
    429429        array->pushBoolean(false);
    430         EXPECT_EQ(array->toJSONString(), "[null,true,false]");
     430        EXPECT_EQ(array->toJSONString(), "[null,true,false]"_s);
    431431        array->pushInteger(1);
    432432        array->pushDouble(1.5);
    433         EXPECT_EQ(array->toJSONString(), "[null,true,false,1,1.5]");
    434         array->pushString("webkit");
    435         EXPECT_EQ(array->toJSONString(), "[null,true,false,1,1.5,\"webkit\"]");
     433        EXPECT_EQ(array->toJSONString(), "[null,true,false,1,1.5]"_s);
     434        array->pushString("webkit"_s);
     435        EXPECT_EQ(array->toJSONString(), "[null,true,false,1,1.5,\"webkit\"]"_s);
    436436        Ref<JSON::Array> subArray = JSON::Array::create();
    437         subArray->pushString("string");
     437        subArray->pushString("string"_s);
    438438        subArray->pushObject(JSON::Object::create());
    439         EXPECT_EQ(subArray->toJSONString(), "[\"string\",{}]");
     439        EXPECT_EQ(subArray->toJSONString(), "[\"string\",{}]"_s);
    440440        array->pushArray(WTFMove(subArray));
    441         EXPECT_EQ(array->toJSONString(), "[null,true,false,1,1.5,\"webkit\",[\"string\",{}]]");
     441        EXPECT_EQ(array->toJSONString(), "[null,true,false,1,1.5,\"webkit\",[\"string\",{}]]"_s);
    442442    }
    443443
    444444    {
    445445        Ref<JSON::Object> object = JSON::Object::create();
    446         EXPECT_EQ(object->toJSONString(), "{}");
     446        EXPECT_EQ(object->toJSONString(), "{}"_s);
    447447        object->setValue("null", JSON::Value::null());
    448         EXPECT_EQ(object->toJSONString(), "{\"null\":null}");
     448        EXPECT_EQ(object->toJSONString(), "{\"null\":null}"_s);
    449449        object->setBoolean("boolean", true);
    450         EXPECT_EQ(object->toJSONString(), "{\"null\":null,\"boolean\":true}");
     450        EXPECT_EQ(object->toJSONString(), "{\"null\":null,\"boolean\":true}"_s);
    451451        object->setDouble("double", 1.5);
    452         EXPECT_EQ(object->toJSONString(), "{\"null\":null,\"boolean\":true,\"double\":1.5}");
    453         object->setString("string", "webkit");
    454         EXPECT_EQ(object->toJSONString(), "{\"null\":null,\"boolean\":true,\"double\":1.5,\"string\":\"webkit\"}");
     452        EXPECT_EQ(object->toJSONString(), "{\"null\":null,\"boolean\":true,\"double\":1.5}"_s);
     453        object->setString("string", "webkit"_s);
     454        EXPECT_EQ(object->toJSONString(), "{\"null\":null,\"boolean\":true,\"double\":1.5,\"string\":\"webkit\"}"_s);
    455455        object->setArray("array", JSON::Array::create());
    456         EXPECT_EQ(object->toJSONString(), "{\"null\":null,\"boolean\":true,\"double\":1.5,\"string\":\"webkit\",\"array\":[]}");
     456        EXPECT_EQ(object->toJSONString(), "{\"null\":null,\"boolean\":true,\"double\":1.5,\"string\":\"webkit\",\"array\":[]}"_s);
    457457        Ref<JSON::Object> subObject = JSON::Object::create();
    458         subObject->setString("foo", "bar");
     458        subObject->setString("foo", "bar"_s);
    459459        subObject->setInteger("baz", 25);
    460460        object->setObject("object", WTFMove(subObject));
    461         EXPECT_EQ(object->toJSONString(), "{\"null\":null,\"boolean\":true,\"double\":1.5,\"string\":\"webkit\",\"array\":[],\"object\":{\"foo\":\"bar\",\"baz\":25}}");
     461        EXPECT_EQ(object->toJSONString(), "{\"null\":null,\"boolean\":true,\"double\":1.5,\"string\":\"webkit\",\"array\":[],\"object\":{\"foo\":\"bar\",\"baz\":25}}"_s);
    462462    }
    463463}
     
    466466{
    467467    {
    468         auto value = JSON::Value::parseJSON("null");
     468        auto value = JSON::Value::parseJSON("null"_s);
    469469        EXPECT_TRUE(value);
    470470        EXPECT_TRUE(value->isNull());
     
    472472
    473473    {
    474         auto value = JSON::Value::parseJSON("true");
     474        auto value = JSON::Value::parseJSON("true"_s);
    475475        EXPECT_TRUE(value);
    476476        EXPECT_TRUE(value->type() == JSON::Value::Type::Boolean);
     
    479479        EXPECT_EQ(*booleanValue, true);
    480480
    481         value = JSON::Value::parseJSON("false");
     481        value = JSON::Value::parseJSON("false"_s);
    482482        EXPECT_TRUE(value);
    483483        EXPECT_TRUE(value->type() == JSON::Value::Type::Boolean);
     
    488488
    489489    {
    490         auto value = JSON::Value::parseJSON("1");
     490        auto value = JSON::Value::parseJSON("1"_s);
    491491        EXPECT_TRUE(value);
    492492        // Numbers are always parsed as double.
     
    496496        EXPECT_EQ(*doubleValue, 1.0);
    497497
    498         value = JSON::Value::parseJSON("1.5");
     498        value = JSON::Value::parseJSON("1.5"_s);
    499499        EXPECT_TRUE(value);
    500500        EXPECT_TRUE(value->type() == JSON::Value::Type::Double);
     
    505505
    506506    {
    507         auto value = JSON::Value::parseJSON("\"string\"");
     507        auto value = JSON::Value::parseJSON("\"string\""_s);
    508508        EXPECT_TRUE(value);
    509509        EXPECT_TRUE(value->type() == JSON::Value::Type::String);
    510510        auto stringValue = value->asString();
    511511        EXPECT_TRUE(!!stringValue);
    512         EXPECT_EQ(stringValue, "string");
    513     }
    514 
    515     {
    516         auto value = JSON::Value::parseJSON("[]");
     512        EXPECT_EQ(stringValue, "string"_s);
     513    }
     514
     515    {
     516        auto value = JSON::Value::parseJSON("[]"_s);
    517517        EXPECT_TRUE(value);
    518518        EXPECT_TRUE(value->type() == JSON::Value::Type::Array);
     
    521521        EXPECT_EQ(arrayValue->length(), 0U);
    522522
    523         value = JSON::Value::parseJSON("[null, 1 ,2.5,[{\"foo\":\"bar\"},{\"baz\":false}],\"webkit\"]");
     523        value = JSON::Value::parseJSON("[null, 1 ,2.5,[{\"foo\":\"bar\"},{\"baz\":false}],\"webkit\"]"_s);
    524524        EXPECT_TRUE(value);
    525525        EXPECT_TRUE(value->type() == JSON::Value::Type::Array);
     
    555555        EXPECT_TRUE(object);
    556556        EXPECT_EQ(object->size(), 1U);
    557         auto stringValue = object->getString("foo");
     557        auto stringValue = object->getString("foo"_s);
    558558        EXPECT_TRUE(!!stringValue);
    559         EXPECT_EQ(stringValue, "bar");
     559        EXPECT_EQ(stringValue, "bar"_s);
    560560        objectValue = subArrayValue->get(1);
    561561        EXPECT_TRUE(objectValue->type() == JSON::Value::Type::Object);
     
    563563        EXPECT_TRUE(object);
    564564        EXPECT_EQ(object->size(), 1U);
    565         auto booleanValue = object->getBoolean("baz");
     565        auto booleanValue = object->getBoolean("baz"_s);
    566566        EXPECT_TRUE(booleanValue);
    567567        EXPECT_EQ(*booleanValue, false);
     
    572572        stringValue = (*it)->asString();
    573573        EXPECT_TRUE(!!stringValue);
    574         EXPECT_EQ(stringValue, "webkit");
     574        EXPECT_EQ(stringValue, "webkit"_s);
    575575        ++it;
    576576        EXPECT_TRUE(it == arrayValue->end());
     
    578578
    579579    {
    580         auto value = JSON::Value::parseJSON("{}");
     580        auto value = JSON::Value::parseJSON("{}"_s);
    581581        EXPECT_TRUE(value);
    582582        EXPECT_TRUE(value->type() == JSON::Value::Type::Object);
     
    585585        EXPECT_EQ(objectValue->size(), 0U);
    586586
    587         value = JSON::Value::parseJSON("{\"foo\": \"bar\", \"baz\": {\"sub\":[null,false]}}");
     587        value = JSON::Value::parseJSON("{\"foo\": \"bar\", \"baz\": {\"sub\":[null,false]}}"_s);
    588588        EXPECT_TRUE(value);
    589589        EXPECT_TRUE(value->type() == JSON::Value::Type::Object);
     
    592592        EXPECT_EQ(objectValue->size(), 2U);
    593593
    594         auto stringValue = objectValue->getString("foo");
     594        auto stringValue = objectValue->getString("foo"_s);
    595595        EXPECT_TRUE(!!stringValue);
    596         EXPECT_EQ(stringValue, "bar");
    597 
    598         auto object = objectValue->getObject("baz");
     596        EXPECT_EQ(stringValue, "bar"_s);
     597
     598        auto object = objectValue->getObject("baz"_s);
    599599        EXPECT_TRUE(object);
    600600        EXPECT_EQ(object->size(), 1U);
    601         auto array = object->getArray("sub");
     601        auto array = object->getArray("sub"_s);
    602602        EXPECT_TRUE(array);
    603603        EXPECT_EQ(array->length(), 2U);
     
    605605
    606606    {
    607         EXPECT_FALSE(JSON::Value::parseJSON(","));
    608         EXPECT_FALSE(JSON::Value::parseJSON("\"foo"));
    609         EXPECT_FALSE(JSON::Value::parseJSON("foo\""));
    610         EXPECT_FALSE(JSON::Value::parseJSON("TrUe"));
    611         EXPECT_FALSE(JSON::Value::parseJSON("False"));
    612         EXPECT_FALSE(JSON::Value::parseJSON("1.d"));
    613         EXPECT_FALSE(JSON::Value::parseJSON("[1,]"));
    614         EXPECT_FALSE(JSON::Value::parseJSON("1,2]"));
    615         EXPECT_FALSE(JSON::Value::parseJSON("[1,2"));
    616         EXPECT_FALSE(JSON::Value::parseJSON("[1 2]"));
    617         EXPECT_FALSE(JSON::Value::parseJSON("[1,2]]"));
    618         EXPECT_FALSE(JSON::Value::parseJSON("[1,2],"));
    619         EXPECT_FALSE(JSON::Value::parseJSON("{foo:\"bar\"}"));
    620         EXPECT_FALSE(JSON::Value::parseJSON("{\"foo\":bar}"));
    621         EXPECT_FALSE(JSON::Value::parseJSON("{\"foo:\"bar\"}"));
    622         EXPECT_FALSE(JSON::Value::parseJSON("{foo\":\"bar\"}"));
    623         EXPECT_FALSE(JSON::Value::parseJSON("{{\"foo\":\"bar\"}}"));
    624         EXPECT_FALSE(JSON::Value::parseJSON("{\"foo\":\"bar\"},"));
    625         EXPECT_FALSE(JSON::Value::parseJSON("[{\"foo\":\"bar\"},{\"baz\":false},]"));
    626         EXPECT_FALSE(JSON::Value::parseJSON("[{\"foo\":{\"baz\":false}]"));
    627     }
    628 
    629     {
    630         auto value = JSON::Value::parseJSON(" \"foo\" \n");
     607        EXPECT_FALSE(JSON::Value::parseJSON(","_s));
     608        EXPECT_FALSE(JSON::Value::parseJSON("\"foo"_s));
     609        EXPECT_FALSE(JSON::Value::parseJSON("foo\""_s));
     610        EXPECT_FALSE(JSON::Value::parseJSON("TrUe"_s));
     611        EXPECT_FALSE(JSON::Value::parseJSON("False"_s));
     612        EXPECT_FALSE(JSON::Value::parseJSON("1.d"_s));
     613        EXPECT_FALSE(JSON::Value::parseJSON("[1,]"_s));
     614        EXPECT_FALSE(JSON::Value::parseJSON("1,2]"_s));
     615        EXPECT_FALSE(JSON::Value::parseJSON("[1,2"_s));
     616        EXPECT_FALSE(JSON::Value::parseJSON("[1 2]"_s));
     617        EXPECT_FALSE(JSON::Value::parseJSON("[1,2]]"_s));
     618        EXPECT_FALSE(JSON::Value::parseJSON("[1,2],"_s));
     619        EXPECT_FALSE(JSON::Value::parseJSON("{foo:\"bar\"}"_s));
     620        EXPECT_FALSE(JSON::Value::parseJSON("{\"foo\":bar}"_s));
     621        EXPECT_FALSE(JSON::Value::parseJSON("{\"foo:\"bar\"}"_s));
     622        EXPECT_FALSE(JSON::Value::parseJSON("{foo\":\"bar\"}"_s));
     623        EXPECT_FALSE(JSON::Value::parseJSON("{{\"foo\":\"bar\"}}"_s));
     624        EXPECT_FALSE(JSON::Value::parseJSON("{\"foo\":\"bar\"},"_s));
     625        EXPECT_FALSE(JSON::Value::parseJSON("[{\"foo\":\"bar\"},{\"baz\":false},]"_s));
     626        EXPECT_FALSE(JSON::Value::parseJSON("[{\"foo\":{\"baz\":false}]"_s));
     627    }
     628
     629    {
     630        auto value = JSON::Value::parseJSON(" \"foo\" \n"_s);
    631631        EXPECT_TRUE(value);
    632632        auto stringValue = value->asString();
     
    636636
    637637    {
    638         EXPECT_TRUE(JSON::Value::parseJSON(" 1"));
    639         EXPECT_TRUE(JSON::Value::parseJSON("\t1"));
    640         EXPECT_TRUE(JSON::Value::parseJSON("\n1"));
    641         EXPECT_TRUE(JSON::Value::parseJSON("1 "));
    642         EXPECT_TRUE(JSON::Value::parseJSON("1\t"));
    643         EXPECT_TRUE(JSON::Value::parseJSON("1\n"));
    644         EXPECT_TRUE(JSON::Value::parseJSON(" 1 "));
    645         EXPECT_TRUE(JSON::Value::parseJSON(" {} "));
    646         EXPECT_TRUE(JSON::Value::parseJSON(" [] "));
    647         EXPECT_TRUE(JSON::Value::parseJSON("\"\\xFF\""));
    648         EXPECT_TRUE(JSON::Value::parseJSON("\"\\u1234\""));
    649 
    650         EXPECT_FALSE(JSON::Value::parseJSON("1 1"));
    651         EXPECT_FALSE(JSON::Value::parseJSON("{} {}"));
    652         EXPECT_FALSE(JSON::Value::parseJSON("[] []"));
    653         EXPECT_FALSE(JSON::Value::parseJSON("\"\\"));
    654         EXPECT_FALSE(JSON::Value::parseJSON("\"\\xF"));
    655         EXPECT_FALSE(JSON::Value::parseJSON("\"\\xF\""));
    656         EXPECT_FALSE(JSON::Value::parseJSON("\"\\xF \""));
    657         EXPECT_FALSE(JSON::Value::parseJSON("\"\\u1"));
    658         EXPECT_FALSE(JSON::Value::parseJSON("\"\\u1\""));
    659         EXPECT_FALSE(JSON::Value::parseJSON("\"\\u1   \""));
    660         EXPECT_FALSE(JSON::Value::parseJSON("\"\\u12"));
    661         EXPECT_FALSE(JSON::Value::parseJSON("\"\\u12\""));
    662         EXPECT_FALSE(JSON::Value::parseJSON("\"\\u12  \""));
    663         EXPECT_FALSE(JSON::Value::parseJSON("\"\\u123"));
    664         EXPECT_FALSE(JSON::Value::parseJSON("\"\\u123\""));
    665         EXPECT_FALSE(JSON::Value::parseJSON("\"\\u123 \""));
     638        EXPECT_TRUE(JSON::Value::parseJSON(" 1"_s));
     639        EXPECT_TRUE(JSON::Value::parseJSON("\t1"_s));
     640        EXPECT_TRUE(JSON::Value::parseJSON("\n1"_s));
     641        EXPECT_TRUE(JSON::Value::parseJSON("1 "_s));
     642        EXPECT_TRUE(JSON::Value::parseJSON("1\t"_s));
     643        EXPECT_TRUE(JSON::Value::parseJSON("1\n"_s));
     644        EXPECT_TRUE(JSON::Value::parseJSON(" 1 "_s));
     645        EXPECT_TRUE(JSON::Value::parseJSON(" {} "_s));
     646        EXPECT_TRUE(JSON::Value::parseJSON(" [] "_s));
     647        EXPECT_TRUE(JSON::Value::parseJSON("\"\\xFF\""_s));
     648        EXPECT_TRUE(JSON::Value::parseJSON("\"\\u1234\""_s));
     649
     650        EXPECT_FALSE(JSON::Value::parseJSON("1 1"_s));
     651        EXPECT_FALSE(JSON::Value::parseJSON("{} {}"_s));
     652        EXPECT_FALSE(JSON::Value::parseJSON("[] []"_s));
     653        EXPECT_FALSE(JSON::Value::parseJSON("\"\\"_s));
     654        EXPECT_FALSE(JSON::Value::parseJSON("\"\\xF"_s));
     655        EXPECT_FALSE(JSON::Value::parseJSON("\"\\xF\""_s));
     656        EXPECT_FALSE(JSON::Value::parseJSON("\"\\xF \""_s));
     657        EXPECT_FALSE(JSON::Value::parseJSON("\"\\u1"_s));
     658        EXPECT_FALSE(JSON::Value::parseJSON("\"\\u1\""_s));
     659        EXPECT_FALSE(JSON::Value::parseJSON("\"\\u1   \""_s));
     660        EXPECT_FALSE(JSON::Value::parseJSON("\"\\u12"_s));
     661        EXPECT_FALSE(JSON::Value::parseJSON("\"\\u12\""_s));
     662        EXPECT_FALSE(JSON::Value::parseJSON("\"\\u12  \""_s));
     663        EXPECT_FALSE(JSON::Value::parseJSON("\"\\u123"_s));
     664        EXPECT_FALSE(JSON::Value::parseJSON("\"\\u123\""_s));
     665        EXPECT_FALSE(JSON::Value::parseJSON("\"\\u123 \""_s));
    666666    }
    667667}
     
    698698
    699699    {
    700         Ref<JSON::Value> value = JSON::Value::create("test");
     700        Ref<JSON::Value> value = JSON::Value::create(makeString("test"_s));
    701701        size_t memoryCost = value->memoryCost();
    702702        EXPECT_GT(memoryCost, 0U);
     
    705705
    706706    {
    707         Ref<JSON::Value> value = JSON::Value::create("");
     707        Ref<JSON::Value> value = JSON::Value::create(emptyString());
    708708        size_t memoryCost = value->memoryCost();
    709709        EXPECT_GT(memoryCost, 0U);
     
    719719
    720720    {
    721         Ref<JSON::Value> valueA = JSON::Value::create("t");
    722         Ref<JSON::Value> valueB = JSON::Value::create("te");
    723         Ref<JSON::Value> valueC = JSON::Value::create("tes");
    724         Ref<JSON::Value> valueD = JSON::Value::create("test");
     721        Ref<JSON::Value> valueA = JSON::Value::create(makeString("t"_s));
     722        Ref<JSON::Value> valueB = JSON::Value::create(makeString("te"_s));
     723        Ref<JSON::Value> valueC = JSON::Value::create(makeString("tes"_s));
     724        Ref<JSON::Value> valueD = JSON::Value::create(makeString("test"_s));
    725725        EXPECT_LT(valueA->memoryCost(), valueB->memoryCost());
    726726        EXPECT_LT(valueB->memoryCost(), valueC->memoryCost());
     
    729729
    730730    {
    731         Ref<JSON::Value> valueA = JSON::Value::create("t");
    732         Ref<JSON::Value> valueB = JSON::Value::create("😀");
     731        Ref<JSON::Value> valueA = JSON::Value::create(makeString("t"_s));
     732        Ref<JSON::Value> valueB = JSON::Value::create(makeString("😀"));
    733733        EXPECT_LT(valueA->memoryCost(), valueB->memoryCost());
    734734    }
Note: See TracChangeset for help on using the changeset viewer.