Changeset 269757 in webkit
- Timestamp:
- Nov 12, 2020 2:54:19 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r269729 r269757 1 2020-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 1 37 2020-11-12 Dmitry Bezhetskov <dbezhetskov@igalia.com> 2 38 -
trunk/Source/JavaScriptCore/inspector/scripts/codegen/cpp_generator_templates.py
r266885 r269757 128 128 ${dispatchCases} 129 129 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)); 131 131 }""") 132 132 … … 140 140 using CallHandler = void (${domainName}BackendDispatcher::*)(long protocol_requestId, RefPtr<JSON::Object>&& protocol_message); 141 141 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({ 148 143 ${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)); 158 149 return; 159 150 } -
trunk/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_backend_dispatcher_implementation.py
r266885 r269757 121 121 122 122 first_command_string = "\n".join([ 123 ' if (protocol_method == "%s" ) {' % commands[0].command_name,123 ' if (protocol_method == "%s"_s) {' % commands[0].command_name, 124 124 ' %s(protocol_requestId, WTFMove(protocol_parameters));' % commands[0].command_name, 125 125 ' return;', … … 130 130 for command in commands[1:]: 131 131 additional_command_string = "\n".join([ 132 ' if (protocol_method == "%s" ) {' % command.command_name,132 ' if (protocol_method == "%s"_s) {' % command.command_name, 133 133 ' %s(protocol_requestId, WTFMove(protocol_parameters));' % command.command_name, 134 134 ' return;', … … 153 153 'commandName': command.command_name 154 154 } 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)) 156 156 157 157 switch_args = { -
trunk/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_protocol_types_header.py
r266885 r269757 277 277 for type_member in open_members: 278 278 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)) 280 280 281 281 lines.append('};') -
trunk/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_protocol_types_implementation.py
r266885 r269757 92 92 93 93 lines = [] 94 lines.append('static const char* constenum_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()]) 96 96 lines.append('};') 97 97 lines.append('') … … 182 182 open_members = Generator.open_fields(type_declaration) 183 183 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)) 185 185 if len(domain_lines): 186 186 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 233 233 auto protocol_parameters = protocol_message->getObject("params"_s); 234 234 235 if (protocol_method == "Command" ) {235 if (protocol_method == "Command"_s) { 236 236 Command(protocol_requestId, WTFMove(protocol_parameters)); 237 237 return; 238 238 } 239 239 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)); 241 241 } 242 242 -
trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/commands-with-async-attribute.json-result
r266885 r269757 255 255 auto protocol_parameters = protocol_message->getObject("params"_s); 256 256 257 if (protocol_method == "executeSQLSyncOptionalReturnValues" ) {257 if (protocol_method == "executeSQLSyncOptionalReturnValues"_s) { 258 258 executeSQLSyncOptionalReturnValues(protocol_requestId, WTFMove(protocol_parameters)); 259 259 return; 260 260 } 261 if (protocol_method == "executeSQLAsyncOptionalReturnValues" ) {261 if (protocol_method == "executeSQLAsyncOptionalReturnValues"_s) { 262 262 executeSQLAsyncOptionalReturnValues(protocol_requestId, WTFMove(protocol_parameters)); 263 263 return; 264 264 } 265 if (protocol_method == "executeSQLSync" ) {265 if (protocol_method == "executeSQLSync"_s) { 266 266 executeSQLSync(protocol_requestId, WTFMove(protocol_parameters)); 267 267 return; 268 268 } 269 if (protocol_method == "executeSQLAsync" ) {269 if (protocol_method == "executeSQLAsync"_s) { 270 270 executeSQLAsync(protocol_requestId, WTFMove(protocol_parameters)); 271 271 return; 272 272 } 273 273 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)); 275 275 } 276 276 … … 753 753 namespace TestHelpers { 754 754 755 static const char* constenum_constant_values[] = {756 "red" ,757 "green" ,758 "blue" ,759 "cyan" ,760 "magenta" ,761 "yellow" ,762 "black" ,755 static 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, 763 763 }; 764 764 -
trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/commands-with-optional-call-return-parameters.json-result
r266885 r269757 236 236 auto protocol_parameters = protocol_message->getObject("params"_s); 237 237 238 if (protocol_method == "executeAllOptionalParameters" ) {238 if (protocol_method == "executeAllOptionalParameters"_s) { 239 239 executeAllOptionalParameters(protocol_requestId, WTFMove(protocol_parameters)); 240 240 return; 241 241 } 242 if (protocol_method == "executeNoOptionalParameters" ) {242 if (protocol_method == "executeNoOptionalParameters"_s) { 243 243 executeNoOptionalParameters(protocol_requestId, WTFMove(protocol_parameters)); 244 244 return; 245 245 } 246 246 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)); 248 248 } 249 249 … … 666 666 namespace TestHelpers { 667 667 668 static const char* constenum_constant_values[] = {669 "red" ,670 "green" ,671 "blue" ,672 "cyan" ,673 "magenta" ,674 "yellow" ,675 "black" ,668 static 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, 676 676 }; 677 677 -
trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/definitions-with-mac-platform.json-result
r266885 r269757 257 257 258 258 #if COMMAND-MAC 259 if (protocol_method == "loadResource" ) {259 if (protocol_method == "loadResource"_s) { 260 260 loadResource(protocol_requestId, WTFMove(protocol_parameters)); 261 261 return; … … 263 263 #endif // COMMAND-MAC 264 264 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)); 266 266 } 267 267 -
trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/domain-debuggableTypes.json-result
r266885 r269757 233 233 auto protocol_parameters = protocol_message->getObject("params"_s); 234 234 235 if (protocol_method == "Command" ) {235 if (protocol_method == "Command"_s) { 236 236 Command(protocol_requestId, WTFMove(protocol_parameters)); 237 237 return; 238 238 } 239 239 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)); 241 241 } 242 242 -
trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/domain-targetType-matching-domain-debuggableType.json-result
r266885 r269757 233 233 auto protocol_parameters = protocol_message->getObject("params"_s); 234 234 235 if (protocol_method == "Command" ) {235 if (protocol_method == "Command"_s) { 236 236 Command(protocol_requestId, WTFMove(protocol_parameters)); 237 237 return; 238 238 } 239 239 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)); 241 241 } 242 242 -
trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/domain-targetTypes.json-result
r266885 r269757 233 233 auto protocol_parameters = protocol_message->getObject("params"_s); 234 234 235 if (protocol_method == "Command" ) {235 if (protocol_method == "Command"_s) { 236 236 Command(protocol_requestId, WTFMove(protocol_parameters)); 237 237 return; 238 238 } 239 239 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)); 241 241 } 242 242 -
trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/domains-with-varying-command-sizes.json-result
r266885 r269757 292 292 auto protocol_parameters = protocol_message->getObject("params"_s); 293 293 294 if (protocol_method == "loadResource1" ) {294 if (protocol_method == "loadResource1"_s) { 295 295 loadResource1(protocol_requestId, WTFMove(protocol_parameters)); 296 296 return; 297 297 } 298 298 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)); 300 300 } 301 301 … … 340 340 using CallHandler = void (Network3BackendDispatcher::*)(long protocol_requestId, RefPtr<JSON::Object>&& protocol_message); 341 341 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)); 364 355 return; 365 356 } -
trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/enum-values.json-result
r266885 r269757 244 244 auto protocol_parameters = protocol_message->getObject("params"_s); 245 245 246 if (protocol_method == "command" ) {246 if (protocol_method == "command"_s) { 247 247 command(protocol_requestId, WTFMove(protocol_parameters)); 248 248 return; 249 249 } 250 250 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)); 252 252 } 253 253 … … 567 567 namespace TestHelpers { 568 568 569 static const char* constenum_constant_values[] = {570 "shared" ,571 "1" ,572 "2" ,573 "sharedRequired" ,574 "grey" ,575 "sharedOptional" ,576 "green" ,577 "black" ,578 "red" ,579 "white" ,580 "blue" ,569 static 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, 581 581 }; 582 582 -
trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/event-targetType-matching-domain-debuggableType.json-result
r266885 r269757 233 233 auto protocol_parameters = protocol_message->getObject("params"_s); 234 234 235 if (protocol_method == "Command" ) {235 if (protocol_method == "Command"_s) { 236 236 Command(protocol_requestId, WTFMove(protocol_parameters)); 237 237 return; 238 238 } 239 239 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)); 241 241 } 242 242 -
trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/generate-domains-with-feature-guards.json-result
r266885 r269757 237 237 auto protocol_parameters = protocol_message->getObject("params"_s); 238 238 239 if (protocol_method == "loadResource" ) {239 if (protocol_method == "loadResource"_s) { 240 240 loadResource(protocol_requestId, WTFMove(protocol_parameters)); 241 241 return; 242 242 } 243 243 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)); 245 245 } 246 246 -
trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/shadowed-optional-type-setters.json-result
r266885 r269757 469 469 namespace TestHelpers { 470 470 471 static const char* constenum_constant_values[] = {472 "null" ,473 "string" ,474 "array" ,471 static const ASCIILiteral enum_constant_values[] = { 472 "null"_s, 473 "string"_s, 474 "array"_s, 475 475 }; 476 476 -
trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/type-declaration-array-type.json-result
r266885 r269757 429 429 namespace TestHelpers { 430 430 431 static const char* constenum_constant_values[] = {432 "Died" ,433 "Fainted" ,434 "Hungry" ,431 static const ASCIILiteral enum_constant_values[] = { 432 "Died"_s, 433 "Fainted"_s, 434 "Hungry"_s, 435 435 }; 436 436 -
trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/type-declaration-enum-type.json-result
r266885 r269757 430 430 namespace TestHelpers { 431 431 432 static const char* constenum_constant_values[] = {433 "Pigs" ,434 "Cows" ,435 "Cats" ,436 "Hens" ,437 "Ducks" ,438 "Crows" ,439 "Flamingos" ,432 static 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, 440 440 }; 441 441 -
trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/type-declaration-object-type.json-result
r266885 r269757 1009 1009 namespace TestHelpers { 1010 1010 1011 static const char* constenum_constant_values[] = {1012 "None" ,1013 "Left" ,1014 "Middle" ,1015 "Right" ,1016 "LTR" ,1017 "RTL" ,1011 static const ASCIILiteral enum_constant_values[] = { 1012 "None"_s, 1013 "Left"_s, 1014 "Middle"_s, 1015 "Right"_s, 1016 "LTR"_s, 1017 "RTL"_s, 1018 1018 }; 1019 1019 -
trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/type-requiring-runtime-casts.json-result
r266885 r269757 647 647 namespace TestHelpers { 648 648 649 static const char* constenum_constant_values[] = {650 "Ducks" ,651 "Hens" ,652 "Crows" ,653 "Flamingos" ,654 "Pigs" ,655 "Cows" ,656 "Cats" ,649 static 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, 657 657 }; 658 658 -
trunk/Source/JavaScriptCore/inspector/scripts/tests/expected/type-with-open-parameters.json-result
r266885 r269757 454 454 455 455 // Property names for type generated as open. 456 None static const char*alphaKey;456 None static const ASCIILiteral alphaKey; 457 457 }; 458 458 … … 505 505 namespace Protocol { 506 506 507 const char* Protocol::Test::OpenParameters::alphaKey = "alpha";507 const ASCIILiteral Protocol::Test::OpenParameters::alphaKey = "alpha"_s; 508 508 509 509 } // namespace Protocol -
trunk/Source/WTF/ChangeLog
r269726 r269757 1 2020-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 1 20 2020-11-12 Zalan Bujtas <zalan@apple.com> 2 21 -
trunk/Source/WTF/wtf/JSONValues.cpp
r267219 r269757 485 485 } 486 486 487 Ref<Value> Value::create(const char* value)488 {489 return adoptRef(*new Value(value));490 }491 492 487 RefPtr<Value> Value::asValue() 493 488 { -
trunk/Source/WTF/wtf/JSONValues.h
r267219 r269757 78 78 static Ref<Value> create(double); 79 79 static Ref<Value> create(const String&); 80 static Ref<Value> create(const char*);81 80 82 81 enum class Type { … … 151 150 } 152 151 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 162 152 private: 163 153 Type m_type { Type::Null }; … … 416 406 417 407 public: 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) 419 435 { 420 436 castedArray().pushValue(WTFMove(value)); 421 437 } 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)); 436 449 } 437 450 -
trunk/Tools/ChangeLog
r269752 r269757 1 2020-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 1 12 2020-11-12 Ali Juma <ajuma@chromium.org> 2 13 -
trunk/Tools/TestWebKitAPI/Tests/WTF/JSONValue.cpp
r266885 r269757 87 87 88 88 { 89 Ref<JSON::Value> value = JSON::Value::create( "webkit");89 Ref<JSON::Value> value = JSON::Value::create(makeString("webkit"_s)); 90 90 EXPECT_TRUE(value->type() == JSON::Value::Type::String); 91 91 auto stringValue = value->asString(); 92 92 EXPECT_TRUE(!!stringValue); 93 EXPECT_EQ(stringValue, "webkit" );93 EXPECT_EQ(stringValue, "webkit"_s); 94 94 95 95 String nullString; … … 161 161 EXPECT_EQ(*doubleValue, 1.5); 162 162 163 array->pushString("webkit" );163 array->pushString("webkit"_s); 164 164 EXPECT_EQ(array->length(), 5U); 165 165 value = array->get(4); … … 167 167 auto stringValue = value->asString(); 168 168 EXPECT_TRUE(!!stringValue); 169 EXPECT_EQ(stringValue, "webkit" );169 EXPECT_EQ(stringValue, "webkit"_s); 170 170 171 171 array->pushObject(JSON::Object::create()); … … 250 250 EXPECT_EQ(*doubleValue, 1.5); 251 251 252 array->addItem( "webkit");252 array->addItem(makeString("webkit"_s)); 253 253 EXPECT_EQ(array->length(), 4U); 254 254 value = array->get(3); … … 256 256 auto stringValue = value->asString(); 257 257 EXPECT_TRUE(!!stringValue); 258 EXPECT_EQ(stringValue, "webkit" );258 EXPECT_EQ(stringValue, "webkit"_s); 259 259 260 260 array->addItem(JSON::Object::create()); … … 312 312 object->setValue("null", JSON::Value::null()); 313 313 EXPECT_EQ(object->size(), 1U); 314 auto value = object->getValue("null" );314 auto value = object->getValue("null"_s); 315 315 EXPECT_TRUE(value); 316 316 EXPECT_TRUE(value->isNull()); … … 318 318 object->setBoolean("boolean", true); 319 319 EXPECT_EQ(object->size(), 2U); 320 auto booleanValue = object->getBoolean("boolean" );320 auto booleanValue = object->getBoolean("boolean"_s); 321 321 EXPECT_TRUE(booleanValue); 322 322 EXPECT_EQ(*booleanValue, true); … … 324 324 object->setInteger("integer", 1); 325 325 EXPECT_EQ(object->size(), 3U); 326 auto integerValue = object->getInteger("integer" );326 auto integerValue = object->getInteger("integer"_s); 327 327 EXPECT_TRUE(integerValue); 328 328 EXPECT_EQ(*integerValue, 1); … … 330 330 object->setDouble("double", 1.5); 331 331 EXPECT_EQ(object->size(), 4U); 332 auto doubleValue = object->getDouble("double" );332 auto doubleValue = object->getDouble("double"_s); 333 333 EXPECT_TRUE(doubleValue); 334 334 EXPECT_EQ(*doubleValue, 1.5); 335 335 336 object->setString("string", "webkit" );336 object->setString("string", "webkit"_s); 337 337 EXPECT_EQ(object->size(), 5U); 338 auto stringValue = object->getString("string" );338 auto stringValue = object->getString("string"_s); 339 339 EXPECT_TRUE(!!stringValue); 340 EXPECT_EQ(stringValue, "webkit" );340 EXPECT_EQ(stringValue, "webkit"_s); 341 341 342 342 object->setObject("object", JSON::Object::create()); 343 343 EXPECT_EQ(object->size(), 6U); 344 auto objectValue = object->getObject("object" );344 auto objectValue = object->getObject("object"_s); 345 345 EXPECT_TRUE(objectValue); 346 346 EXPECT_EQ(objectValue->size(), 0U); … … 348 348 object->setArray("array", JSON::Array::create()); 349 349 EXPECT_EQ(object->size(), 7U); 350 auto arrayValue = object->getArray("array" );350 auto arrayValue = object->getArray("array"_s); 351 351 EXPECT_TRUE(arrayValue); 352 352 EXPECT_EQ(arrayValue->length(), 0U); 353 353 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 }; 355 355 auto end = object->end(); 356 356 for (auto it = object->begin(); it != end; ++it) { … … 362 362 EXPECT_TRUE(keys.isEmpty()); 363 363 364 object->remove("null" );364 object->remove("null"_s); 365 365 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); 369 369 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); 373 373 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); 377 377 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); 381 381 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); 385 385 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); 389 389 EXPECT_EQ(object->size(), 0U); 390 EXPECT_TRUE(object->find("array" ) == object->end());390 EXPECT_TRUE(object->find("array"_s) == object->end()); 391 391 } 392 392 … … 395 395 { 396 396 Ref<JSON::Value> value = JSON::Value::null(); 397 EXPECT_EQ(value->toJSONString(), "null" );397 EXPECT_EQ(value->toJSONString(), "null"_s); 398 398 } 399 399 400 400 { 401 401 Ref<JSON::Value> value = JSON::Value::create(true); 402 EXPECT_EQ(value->toJSONString(), "true" );402 EXPECT_EQ(value->toJSONString(), "true"_s); 403 403 404 404 value = JSON::Value::create(false); 405 EXPECT_EQ(value->toJSONString(), "false" );405 EXPECT_EQ(value->toJSONString(), "false"_s); 406 406 } 407 407 408 408 { 409 409 Ref<JSON::Value> value = JSON::Value::create(1); 410 EXPECT_EQ(value->toJSONString(), "1" );410 EXPECT_EQ(value->toJSONString(), "1"_s); 411 411 } 412 412 413 413 { 414 414 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); 421 421 } 422 422 423 423 { 424 424 Ref<JSON::Array> array = JSON::Array::create(); 425 EXPECT_EQ(array->toJSONString(), "[]" );425 EXPECT_EQ(array->toJSONString(), "[]"_s); 426 426 array->pushValue(JSON::Value::null()); 427 EXPECT_EQ(array->toJSONString(), "[null]" );427 EXPECT_EQ(array->toJSONString(), "[null]"_s); 428 428 array->pushBoolean(true); 429 429 array->pushBoolean(false); 430 EXPECT_EQ(array->toJSONString(), "[null,true,false]" );430 EXPECT_EQ(array->toJSONString(), "[null,true,false]"_s); 431 431 array->pushInteger(1); 432 432 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); 436 436 Ref<JSON::Array> subArray = JSON::Array::create(); 437 subArray->pushString("string" );437 subArray->pushString("string"_s); 438 438 subArray->pushObject(JSON::Object::create()); 439 EXPECT_EQ(subArray->toJSONString(), "[\"string\",{}]" );439 EXPECT_EQ(subArray->toJSONString(), "[\"string\",{}]"_s); 440 440 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); 442 442 } 443 443 444 444 { 445 445 Ref<JSON::Object> object = JSON::Object::create(); 446 EXPECT_EQ(object->toJSONString(), "{}" );446 EXPECT_EQ(object->toJSONString(), "{}"_s); 447 447 object->setValue("null", JSON::Value::null()); 448 EXPECT_EQ(object->toJSONString(), "{\"null\":null}" );448 EXPECT_EQ(object->toJSONString(), "{\"null\":null}"_s); 449 449 object->setBoolean("boolean", true); 450 EXPECT_EQ(object->toJSONString(), "{\"null\":null,\"boolean\":true}" );450 EXPECT_EQ(object->toJSONString(), "{\"null\":null,\"boolean\":true}"_s); 451 451 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); 455 455 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); 457 457 Ref<JSON::Object> subObject = JSON::Object::create(); 458 subObject->setString("foo", "bar" );458 subObject->setString("foo", "bar"_s); 459 459 subObject->setInteger("baz", 25); 460 460 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); 462 462 } 463 463 } … … 466 466 { 467 467 { 468 auto value = JSON::Value::parseJSON("null" );468 auto value = JSON::Value::parseJSON("null"_s); 469 469 EXPECT_TRUE(value); 470 470 EXPECT_TRUE(value->isNull()); … … 472 472 473 473 { 474 auto value = JSON::Value::parseJSON("true" );474 auto value = JSON::Value::parseJSON("true"_s); 475 475 EXPECT_TRUE(value); 476 476 EXPECT_TRUE(value->type() == JSON::Value::Type::Boolean); … … 479 479 EXPECT_EQ(*booleanValue, true); 480 480 481 value = JSON::Value::parseJSON("false" );481 value = JSON::Value::parseJSON("false"_s); 482 482 EXPECT_TRUE(value); 483 483 EXPECT_TRUE(value->type() == JSON::Value::Type::Boolean); … … 488 488 489 489 { 490 auto value = JSON::Value::parseJSON("1" );490 auto value = JSON::Value::parseJSON("1"_s); 491 491 EXPECT_TRUE(value); 492 492 // Numbers are always parsed as double. … … 496 496 EXPECT_EQ(*doubleValue, 1.0); 497 497 498 value = JSON::Value::parseJSON("1.5" );498 value = JSON::Value::parseJSON("1.5"_s); 499 499 EXPECT_TRUE(value); 500 500 EXPECT_TRUE(value->type() == JSON::Value::Type::Double); … … 505 505 506 506 { 507 auto value = JSON::Value::parseJSON("\"string\"" );507 auto value = JSON::Value::parseJSON("\"string\""_s); 508 508 EXPECT_TRUE(value); 509 509 EXPECT_TRUE(value->type() == JSON::Value::Type::String); 510 510 auto stringValue = value->asString(); 511 511 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); 517 517 EXPECT_TRUE(value); 518 518 EXPECT_TRUE(value->type() == JSON::Value::Type::Array); … … 521 521 EXPECT_EQ(arrayValue->length(), 0U); 522 522 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); 524 524 EXPECT_TRUE(value); 525 525 EXPECT_TRUE(value->type() == JSON::Value::Type::Array); … … 555 555 EXPECT_TRUE(object); 556 556 EXPECT_EQ(object->size(), 1U); 557 auto stringValue = object->getString("foo" );557 auto stringValue = object->getString("foo"_s); 558 558 EXPECT_TRUE(!!stringValue); 559 EXPECT_EQ(stringValue, "bar" );559 EXPECT_EQ(stringValue, "bar"_s); 560 560 objectValue = subArrayValue->get(1); 561 561 EXPECT_TRUE(objectValue->type() == JSON::Value::Type::Object); … … 563 563 EXPECT_TRUE(object); 564 564 EXPECT_EQ(object->size(), 1U); 565 auto booleanValue = object->getBoolean("baz" );565 auto booleanValue = object->getBoolean("baz"_s); 566 566 EXPECT_TRUE(booleanValue); 567 567 EXPECT_EQ(*booleanValue, false); … … 572 572 stringValue = (*it)->asString(); 573 573 EXPECT_TRUE(!!stringValue); 574 EXPECT_EQ(stringValue, "webkit" );574 EXPECT_EQ(stringValue, "webkit"_s); 575 575 ++it; 576 576 EXPECT_TRUE(it == arrayValue->end()); … … 578 578 579 579 { 580 auto value = JSON::Value::parseJSON("{}" );580 auto value = JSON::Value::parseJSON("{}"_s); 581 581 EXPECT_TRUE(value); 582 582 EXPECT_TRUE(value->type() == JSON::Value::Type::Object); … … 585 585 EXPECT_EQ(objectValue->size(), 0U); 586 586 587 value = JSON::Value::parseJSON("{\"foo\": \"bar\", \"baz\": {\"sub\":[null,false]}}" );587 value = JSON::Value::parseJSON("{\"foo\": \"bar\", \"baz\": {\"sub\":[null,false]}}"_s); 588 588 EXPECT_TRUE(value); 589 589 EXPECT_TRUE(value->type() == JSON::Value::Type::Object); … … 592 592 EXPECT_EQ(objectValue->size(), 2U); 593 593 594 auto stringValue = objectValue->getString("foo" );594 auto stringValue = objectValue->getString("foo"_s); 595 595 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); 599 599 EXPECT_TRUE(object); 600 600 EXPECT_EQ(object->size(), 1U); 601 auto array = object->getArray("sub" );601 auto array = object->getArray("sub"_s); 602 602 EXPECT_TRUE(array); 603 603 EXPECT_EQ(array->length(), 2U); … … 605 605 606 606 { 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); 631 631 EXPECT_TRUE(value); 632 632 auto stringValue = value->asString(); … … 636 636 637 637 { 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)); 666 666 } 667 667 } … … 698 698 699 699 { 700 Ref<JSON::Value> value = JSON::Value::create( "test");700 Ref<JSON::Value> value = JSON::Value::create(makeString("test"_s)); 701 701 size_t memoryCost = value->memoryCost(); 702 702 EXPECT_GT(memoryCost, 0U); … … 705 705 706 706 { 707 Ref<JSON::Value> value = JSON::Value::create( "");707 Ref<JSON::Value> value = JSON::Value::create(emptyString()); 708 708 size_t memoryCost = value->memoryCost(); 709 709 EXPECT_GT(memoryCost, 0U); … … 719 719 720 720 { 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)); 725 725 EXPECT_LT(valueA->memoryCost(), valueB->memoryCost()); 726 726 EXPECT_LT(valueB->memoryCost(), valueC->memoryCost()); … … 729 729 730 730 { 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("😀")); 733 733 EXPECT_LT(valueA->memoryCost(), valueB->memoryCost()); 734 734 }
Note: See TracChangeset
for help on using the changeset viewer.