Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (269756 => 269757)
--- trunk/Source/_javascript_Core/ChangeLog 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/_javascript_Core/ChangeLog 2020-11-12 22:54:19 UTC (rev 269757)
@@ -1,3 +1,39 @@
+2020-11-12 Devin Rousso <[email protected]>
+
+ 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.
+
+ * 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:
+
2020-11-12 Dmitry Bezhetskov <[email protected]>
[WASM-References] Support imm for ref.null
Modified: trunk/Source/_javascript_Core/inspector/scripts/codegen/cpp_generator_templates.py (269756 => 269757)
--- trunk/Source/_javascript_Core/inspector/scripts/codegen/cpp_generator_templates.py 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/_javascript_Core/inspector/scripts/codegen/cpp_generator_templates.py 2020-11-12 22:54:19 UTC (rev 269757)
@@ -127,7 +127,7 @@
${dispatchCases}
- m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'${domainName}." + protocol_method + "' was not found");
+ m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'${domainName}."_s, protocol_method, "' was not found"_s));
}""")
BackendDispatcherImplementationLargeSwitch = (
@@ -139,22 +139,13 @@
using CallHandler = void (${domainName}BackendDispatcher::*)(long protocol_requestId, RefPtr<JSON::Object>&& protocol_message);
using DispatchMap = HashMap<String, CallHandler>;
- static NeverDestroyed<DispatchMap> dispatchMap;
- if (dispatchMap.get().isEmpty()) {
- static const struct MethodTable {
- const char* name;
- CallHandler handler;
- } commands[] = {
+ static NeverDestroyed<DispatchMap> dispatchMap = DispatchMap({
${dispatchCases}
- };
- size_t length = WTF_ARRAY_LENGTH(commands);
- for (size_t i = 0; i < length; ++i)
- dispatchMap.get().add(commands[i].name, commands[i].handler);
- }
+ });
- auto findResult = dispatchMap.get().find(protocol_method);
- if (findResult == dispatchMap.get().end()) {
- m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'${domainName}." + protocol_method + "' was not found");
+ auto findResult = dispatchMap->find(protocol_method);
+ if (findResult == dispatchMap->end()) {
+ m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'${domainName}."_s, protocol_method, "' was not found"_s));
return;
}
Modified: trunk/Source/_javascript_Core/inspector/scripts/codegen/generate_cpp_backend_dispatcher_implementation.py (269756 => 269757)
--- trunk/Source/_javascript_Core/inspector/scripts/codegen/generate_cpp_backend_dispatcher_implementation.py 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/_javascript_Core/inspector/scripts/codegen/generate_cpp_backend_dispatcher_implementation.py 2020-11-12 22:54:19 UTC (rev 269757)
@@ -120,7 +120,7 @@
cases = []
first_command_string = "\n".join([
- ' if (protocol_method == "%s") {' % commands[0].command_name,
+ ' if (protocol_method == "%s"_s) {' % commands[0].command_name,
' %s(protocol_requestId, WTFMove(protocol_parameters));' % commands[0].command_name,
' return;',
' }',
@@ -129,7 +129,7 @@
for command in commands[1:]:
additional_command_string = "\n".join([
- ' if (protocol_method == "%s") {' % command.command_name,
+ ' if (protocol_method == "%s"_s) {' % command.command_name,
' %s(protocol_requestId, WTFMove(protocol_parameters));' % command.command_name,
' return;',
' }',
@@ -152,7 +152,7 @@
'domainName': domain.domain_name,
'commandName': command.command_name
}
- cases.append(self.wrap_with_guard_for_condition(command.condition, ' { "%(commandName)s", &%(domainName)sBackendDispatcher::%(commandName)s },' % args))
+ cases.append(self.wrap_with_guard_for_condition(command.condition, ' { "%(commandName)s"_s, &%(domainName)sBackendDispatcher::%(commandName)s },' % args))
switch_args = {
'domainName': domain.domain_name,
Modified: trunk/Source/_javascript_Core/inspector/scripts/codegen/generate_cpp_protocol_types_header.py (269756 => 269757)
--- trunk/Source/_javascript_Core/inspector/scripts/codegen/generate_cpp_protocol_types_header.py 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/_javascript_Core/inspector/scripts/codegen/generate_cpp_protocol_types_header.py 2020-11-12 22:54:19 UTC (rev 269757)
@@ -276,7 +276,7 @@
open_members = Generator.open_fields(type_declaration)
for type_member in open_members:
export_macro = self.model().framework.setting('export_macro', None)
- lines.append(' %s static const char* %sKey;' % (export_macro, type_member.member_name))
+ lines.append(' %s static const ASCIILiteral %sKey;' % (export_macro, type_member.member_name))
lines.append('};')
return self.wrap_with_guard_for_condition(type_declaration.condition, '\n'.join(lines))
Modified: trunk/Source/_javascript_Core/inspector/scripts/codegen/generate_cpp_protocol_types_implementation.py (269756 => 269757)
--- trunk/Source/_javascript_Core/inspector/scripts/codegen/generate_cpp_protocol_types_implementation.py 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/_javascript_Core/inspector/scripts/codegen/generate_cpp_protocol_types_implementation.py 2020-11-12 22:54:19 UTC (rev 269757)
@@ -91,8 +91,8 @@
return []
lines = []
- lines.append('static const char* const enum_constant_values[] = {')
- lines.extend([' "%s",' % enum_value for enum_value in self.assigned_enum_values()])
+ lines.append('static const ASCIILiteral enum_constant_values[] = {')
+ lines.extend([' "%s"_s,' % enum_value for enum_value in self.assigned_enum_values()])
lines.append('};')
lines.append('')
lines.append('String getEnumConstantValue(int code) {')
@@ -181,7 +181,7 @@
for type_declaration in [decl for decl in type_declarations if Generator.type_has_open_fields(decl.type)]:
open_members = Generator.open_fields(type_declaration)
for type_member in sorted(open_members, key=lambda member: member.member_name):
- 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))
+ 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))
if len(domain_lines):
lines.append(self.wrap_with_guard_for_condition(domain.condition, '\n'.join(domain_lines)))
Modified: trunk/Source/_javascript_Core/inspector/scripts/tests/expected/command-targetType-matching-domain-debuggableType.json-result (269756 => 269757)
--- trunk/Source/_javascript_Core/inspector/scripts/tests/expected/command-targetType-matching-domain-debuggableType.json-result 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/_javascript_Core/inspector/scripts/tests/expected/command-targetType-matching-domain-debuggableType.json-result 2020-11-12 22:54:19 UTC (rev 269757)
@@ -232,12 +232,12 @@
auto protocol_parameters = protocol_message->getObject("params"_s);
- if (protocol_method == "Command") {
+ if (protocol_method == "Command"_s) {
Command(protocol_requestId, WTFMove(protocol_parameters));
return;
}
- m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Domain." + protocol_method + "' was not found");
+ m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Domain."_s, protocol_method, "' was not found"_s));
}
void DomainBackendDispatcher::Command(long protocol_requestId, RefPtr<JSON::Object>&&)
Modified: trunk/Source/_javascript_Core/inspector/scripts/tests/expected/commands-with-async-attribute.json-result (269756 => 269757)
--- trunk/Source/_javascript_Core/inspector/scripts/tests/expected/commands-with-async-attribute.json-result 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/_javascript_Core/inspector/scripts/tests/expected/commands-with-async-attribute.json-result 2020-11-12 22:54:19 UTC (rev 269757)
@@ -254,24 +254,24 @@
auto protocol_parameters = protocol_message->getObject("params"_s);
- if (protocol_method == "executeSQLSyncOptionalReturnValues") {
+ if (protocol_method == "executeSQLSyncOptionalReturnValues"_s) {
executeSQLSyncOptionalReturnValues(protocol_requestId, WTFMove(protocol_parameters));
return;
}
- if (protocol_method == "executeSQLAsyncOptionalReturnValues") {
+ if (protocol_method == "executeSQLAsyncOptionalReturnValues"_s) {
executeSQLAsyncOptionalReturnValues(protocol_requestId, WTFMove(protocol_parameters));
return;
}
- if (protocol_method == "executeSQLSync") {
+ if (protocol_method == "executeSQLSync"_s) {
executeSQLSync(protocol_requestId, WTFMove(protocol_parameters));
return;
}
- if (protocol_method == "executeSQLAsync") {
+ if (protocol_method == "executeSQLAsync"_s) {
executeSQLAsync(protocol_requestId, WTFMove(protocol_parameters));
return;
}
- m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Database." + protocol_method + "' was not found");
+ m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Database."_s, protocol_method, "' was not found"_s));
}
void DatabaseBackendDispatcher::executeSQLSyncOptionalReturnValues(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
@@ -752,14 +752,14 @@
namespace TestHelpers {
-static const char* const enum_constant_values[] = {
- "red",
- "green",
- "blue",
- "cyan",
- "magenta",
- "yellow",
- "black",
+static const ASCIILiteral enum_constant_values[] = {
+ "red"_s,
+ "green"_s,
+ "blue"_s,
+ "cyan"_s,
+ "magenta"_s,
+ "yellow"_s,
+ "black"_s,
};
String getEnumConstantValue(int code) {
Modified: trunk/Source/_javascript_Core/inspector/scripts/tests/expected/commands-with-optional-call-return-parameters.json-result (269756 => 269757)
--- trunk/Source/_javascript_Core/inspector/scripts/tests/expected/commands-with-optional-call-return-parameters.json-result 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/_javascript_Core/inspector/scripts/tests/expected/commands-with-optional-call-return-parameters.json-result 2020-11-12 22:54:19 UTC (rev 269757)
@@ -235,16 +235,16 @@
auto protocol_parameters = protocol_message->getObject("params"_s);
- if (protocol_method == "executeAllOptionalParameters") {
+ if (protocol_method == "executeAllOptionalParameters"_s) {
executeAllOptionalParameters(protocol_requestId, WTFMove(protocol_parameters));
return;
}
- if (protocol_method == "executeNoOptionalParameters") {
+ if (protocol_method == "executeNoOptionalParameters"_s) {
executeNoOptionalParameters(protocol_requestId, WTFMove(protocol_parameters));
return;
}
- m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Database." + protocol_method + "' was not found");
+ m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Database."_s, protocol_method, "' was not found"_s));
}
void DatabaseBackendDispatcher::executeAllOptionalParameters(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
@@ -665,14 +665,14 @@
namespace TestHelpers {
-static const char* const enum_constant_values[] = {
- "red",
- "green",
- "blue",
- "cyan",
- "magenta",
- "yellow",
- "black",
+static const ASCIILiteral enum_constant_values[] = {
+ "red"_s,
+ "green"_s,
+ "blue"_s,
+ "cyan"_s,
+ "magenta"_s,
+ "yellow"_s,
+ "black"_s,
};
String getEnumConstantValue(int code) {
Modified: trunk/Source/_javascript_Core/inspector/scripts/tests/expected/definitions-with-mac-platform.json-result (269756 => 269757)
--- trunk/Source/_javascript_Core/inspector/scripts/tests/expected/definitions-with-mac-platform.json-result 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/_javascript_Core/inspector/scripts/tests/expected/definitions-with-mac-platform.json-result 2020-11-12 22:54:19 UTC (rev 269757)
@@ -256,13 +256,13 @@
auto protocol_parameters = protocol_message->getObject("params"_s);
#if COMMAND-MAC
- if (protocol_method == "loadResource") {
+ if (protocol_method == "loadResource"_s) {
loadResource(protocol_requestId, WTFMove(protocol_parameters));
return;
}
#endif // COMMAND-MAC
- m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Network." + protocol_method + "' was not found");
+ m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Network."_s, protocol_method, "' was not found"_s));
}
#if COMMAND-MAC
Modified: trunk/Source/_javascript_Core/inspector/scripts/tests/expected/domain-debuggableTypes.json-result (269756 => 269757)
--- trunk/Source/_javascript_Core/inspector/scripts/tests/expected/domain-debuggableTypes.json-result 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/_javascript_Core/inspector/scripts/tests/expected/domain-debuggableTypes.json-result 2020-11-12 22:54:19 UTC (rev 269757)
@@ -232,12 +232,12 @@
auto protocol_parameters = protocol_message->getObject("params"_s);
- if (protocol_method == "Command") {
+ if (protocol_method == "Command"_s) {
Command(protocol_requestId, WTFMove(protocol_parameters));
return;
}
- m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Domain." + protocol_method + "' was not found");
+ m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Domain."_s, protocol_method, "' was not found"_s));
}
void DomainBackendDispatcher::Command(long protocol_requestId, RefPtr<JSON::Object>&&)
Modified: trunk/Source/_javascript_Core/inspector/scripts/tests/expected/domain-targetType-matching-domain-debuggableType.json-result (269756 => 269757)
--- trunk/Source/_javascript_Core/inspector/scripts/tests/expected/domain-targetType-matching-domain-debuggableType.json-result 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/_javascript_Core/inspector/scripts/tests/expected/domain-targetType-matching-domain-debuggableType.json-result 2020-11-12 22:54:19 UTC (rev 269757)
@@ -232,12 +232,12 @@
auto protocol_parameters = protocol_message->getObject("params"_s);
- if (protocol_method == "Command") {
+ if (protocol_method == "Command"_s) {
Command(protocol_requestId, WTFMove(protocol_parameters));
return;
}
- m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Domain." + protocol_method + "' was not found");
+ m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Domain."_s, protocol_method, "' was not found"_s));
}
void DomainBackendDispatcher::Command(long protocol_requestId, RefPtr<JSON::Object>&&)
Modified: trunk/Source/_javascript_Core/inspector/scripts/tests/expected/domain-targetTypes.json-result (269756 => 269757)
--- trunk/Source/_javascript_Core/inspector/scripts/tests/expected/domain-targetTypes.json-result 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/_javascript_Core/inspector/scripts/tests/expected/domain-targetTypes.json-result 2020-11-12 22:54:19 UTC (rev 269757)
@@ -232,12 +232,12 @@
auto protocol_parameters = protocol_message->getObject("params"_s);
- if (protocol_method == "Command") {
+ if (protocol_method == "Command"_s) {
Command(protocol_requestId, WTFMove(protocol_parameters));
return;
}
- m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Domain." + protocol_method + "' was not found");
+ m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Domain."_s, protocol_method, "' was not found"_s));
}
void DomainBackendDispatcher::Command(long protocol_requestId, RefPtr<JSON::Object>&&)
Modified: trunk/Source/_javascript_Core/inspector/scripts/tests/expected/domains-with-varying-command-sizes.json-result (269756 => 269757)
--- trunk/Source/_javascript_Core/inspector/scripts/tests/expected/domains-with-varying-command-sizes.json-result 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/_javascript_Core/inspector/scripts/tests/expected/domains-with-varying-command-sizes.json-result 2020-11-12 22:54:19 UTC (rev 269757)
@@ -291,12 +291,12 @@
auto protocol_parameters = protocol_message->getObject("params"_s);
- if (protocol_method == "loadResource1") {
+ if (protocol_method == "loadResource1"_s) {
loadResource1(protocol_requestId, WTFMove(protocol_parameters));
return;
}
- m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Network1." + protocol_method + "' was not found");
+ m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Network1."_s, protocol_method, "' was not found"_s));
}
void Network1BackendDispatcher::loadResource1(long protocol_requestId, RefPtr<JSON::Object>&&)
@@ -339,28 +339,19 @@
using CallHandler = void (Network3BackendDispatcher::*)(long protocol_requestId, RefPtr<JSON::Object>&& protocol_message);
using DispatchMap = HashMap<String, CallHandler>;
- static NeverDestroyed<DispatchMap> dispatchMap;
- if (dispatchMap.get().isEmpty()) {
- static const struct MethodTable {
- const char* name;
- CallHandler handler;
- } commands[] = {
- { "loadResource1", &Network3BackendDispatcher::loadResource1 },
- { "loadResource2", &Network3BackendDispatcher::loadResource2 },
- { "loadResource3", &Network3BackendDispatcher::loadResource3 },
- { "loadResource4", &Network3BackendDispatcher::loadResource4 },
- { "loadResource5", &Network3BackendDispatcher::loadResource5 },
- { "loadResource6", &Network3BackendDispatcher::loadResource6 },
- { "loadResource7", &Network3BackendDispatcher::loadResource7 },
- };
- size_t length = WTF_ARRAY_LENGTH(commands);
- for (size_t i = 0; i < length; ++i)
- dispatchMap.get().add(commands[i].name, commands[i].handler);
- }
+ static NeverDestroyed<DispatchMap> dispatchMap = DispatchMap({
+ { "loadResource1"_s, &Network3BackendDispatcher::loadResource1 },
+ { "loadResource2"_s, &Network3BackendDispatcher::loadResource2 },
+ { "loadResource3"_s, &Network3BackendDispatcher::loadResource3 },
+ { "loadResource4"_s, &Network3BackendDispatcher::loadResource4 },
+ { "loadResource5"_s, &Network3BackendDispatcher::loadResource5 },
+ { "loadResource6"_s, &Network3BackendDispatcher::loadResource6 },
+ { "loadResource7"_s, &Network3BackendDispatcher::loadResource7 },
+ });
- auto findResult = dispatchMap.get().find(protocol_method);
- if (findResult == dispatchMap.get().end()) {
- m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Network3." + protocol_method + "' was not found");
+ auto findResult = dispatchMap->find(protocol_method);
+ if (findResult == dispatchMap->end()) {
+ m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Network3."_s, protocol_method, "' was not found"_s));
return;
}
Modified: trunk/Source/_javascript_Core/inspector/scripts/tests/expected/enum-values.json-result (269756 => 269757)
--- trunk/Source/_javascript_Core/inspector/scripts/tests/expected/enum-values.json-result 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/_javascript_Core/inspector/scripts/tests/expected/enum-values.json-result 2020-11-12 22:54:19 UTC (rev 269757)
@@ -243,12 +243,12 @@
auto protocol_parameters = protocol_message->getObject("params"_s);
- if (protocol_method == "command") {
+ if (protocol_method == "command"_s) {
command(protocol_requestId, WTFMove(protocol_parameters));
return;
}
- m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'CommandDomain." + protocol_method + "' was not found");
+ m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'CommandDomain."_s, protocol_method, "' was not found"_s));
}
void CommandDomainBackendDispatcher::command(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
@@ -566,18 +566,18 @@
namespace TestHelpers {
-static const char* const enum_constant_values[] = {
- "shared",
- "1",
- "2",
- "sharedRequired",
- "grey",
- "sharedOptional",
- "green",
- "black",
- "red",
- "white",
- "blue",
+static const ASCIILiteral enum_constant_values[] = {
+ "shared"_s,
+ "1"_s,
+ "2"_s,
+ "sharedRequired"_s,
+ "grey"_s,
+ "sharedOptional"_s,
+ "green"_s,
+ "black"_s,
+ "red"_s,
+ "white"_s,
+ "blue"_s,
};
String getEnumConstantValue(int code) {
Modified: trunk/Source/_javascript_Core/inspector/scripts/tests/expected/event-targetType-matching-domain-debuggableType.json-result (269756 => 269757)
--- trunk/Source/_javascript_Core/inspector/scripts/tests/expected/event-targetType-matching-domain-debuggableType.json-result 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/_javascript_Core/inspector/scripts/tests/expected/event-targetType-matching-domain-debuggableType.json-result 2020-11-12 22:54:19 UTC (rev 269757)
@@ -232,12 +232,12 @@
auto protocol_parameters = protocol_message->getObject("params"_s);
- if (protocol_method == "Command") {
+ if (protocol_method == "Command"_s) {
Command(protocol_requestId, WTFMove(protocol_parameters));
return;
}
- m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Domain." + protocol_method + "' was not found");
+ m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Domain."_s, protocol_method, "' was not found"_s));
}
void DomainBackendDispatcher::Command(long protocol_requestId, RefPtr<JSON::Object>&&)
Modified: trunk/Source/_javascript_Core/inspector/scripts/tests/expected/generate-domains-with-feature-guards.json-result (269756 => 269757)
--- trunk/Source/_javascript_Core/inspector/scripts/tests/expected/generate-domains-with-feature-guards.json-result 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/_javascript_Core/inspector/scripts/tests/expected/generate-domains-with-feature-guards.json-result 2020-11-12 22:54:19 UTC (rev 269757)
@@ -236,12 +236,12 @@
auto protocol_parameters = protocol_message->getObject("params"_s);
- if (protocol_method == "loadResource") {
+ if (protocol_method == "loadResource"_s) {
loadResource(protocol_requestId, WTFMove(protocol_parameters));
return;
}
- m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, "'Network1." + protocol_method + "' was not found");
+ m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Network1."_s, protocol_method, "' was not found"_s));
}
void Network1BackendDispatcher::loadResource(long protocol_requestId, RefPtr<JSON::Object>&&)
Modified: trunk/Source/_javascript_Core/inspector/scripts/tests/expected/shadowed-optional-type-setters.json-result (269756 => 269757)
--- trunk/Source/_javascript_Core/inspector/scripts/tests/expected/shadowed-optional-type-setters.json-result 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/_javascript_Core/inspector/scripts/tests/expected/shadowed-optional-type-setters.json-result 2020-11-12 22:54:19 UTC (rev 269757)
@@ -468,10 +468,10 @@
namespace TestHelpers {
-static const char* const enum_constant_values[] = {
- "null",
- "string",
- "array",
+static const ASCIILiteral enum_constant_values[] = {
+ "null"_s,
+ "string"_s,
+ "array"_s,
};
String getEnumConstantValue(int code) {
Modified: trunk/Source/_javascript_Core/inspector/scripts/tests/expected/type-declaration-array-type.json-result (269756 => 269757)
--- trunk/Source/_javascript_Core/inspector/scripts/tests/expected/type-declaration-array-type.json-result 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/_javascript_Core/inspector/scripts/tests/expected/type-declaration-array-type.json-result 2020-11-12 22:54:19 UTC (rev 269757)
@@ -428,10 +428,10 @@
namespace TestHelpers {
-static const char* const enum_constant_values[] = {
- "Died",
- "Fainted",
- "Hungry",
+static const ASCIILiteral enum_constant_values[] = {
+ "Died"_s,
+ "Fainted"_s,
+ "Hungry"_s,
};
String getEnumConstantValue(int code) {
Modified: trunk/Source/_javascript_Core/inspector/scripts/tests/expected/type-declaration-enum-type.json-result (269756 => 269757)
--- trunk/Source/_javascript_Core/inspector/scripts/tests/expected/type-declaration-enum-type.json-result 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/_javascript_Core/inspector/scripts/tests/expected/type-declaration-enum-type.json-result 2020-11-12 22:54:19 UTC (rev 269757)
@@ -429,14 +429,14 @@
namespace TestHelpers {
-static const char* const enum_constant_values[] = {
- "Pigs",
- "Cows",
- "Cats",
- "Hens",
- "Ducks",
- "Crows",
- "Flamingos",
+static const ASCIILiteral enum_constant_values[] = {
+ "Pigs"_s,
+ "Cows"_s,
+ "Cats"_s,
+ "Hens"_s,
+ "Ducks"_s,
+ "Crows"_s,
+ "Flamingos"_s,
};
String getEnumConstantValue(int code) {
Modified: trunk/Source/_javascript_Core/inspector/scripts/tests/expected/type-declaration-object-type.json-result (269756 => 269757)
--- trunk/Source/_javascript_Core/inspector/scripts/tests/expected/type-declaration-object-type.json-result 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/_javascript_Core/inspector/scripts/tests/expected/type-declaration-object-type.json-result 2020-11-12 22:54:19 UTC (rev 269757)
@@ -1008,13 +1008,13 @@
namespace TestHelpers {
-static const char* const enum_constant_values[] = {
- "None",
- "Left",
- "Middle",
- "Right",
- "LTR",
- "RTL",
+static const ASCIILiteral enum_constant_values[] = {
+ "None"_s,
+ "Left"_s,
+ "Middle"_s,
+ "Right"_s,
+ "LTR"_s,
+ "RTL"_s,
};
String getEnumConstantValue(int code) {
Modified: trunk/Source/_javascript_Core/inspector/scripts/tests/expected/type-requiring-runtime-casts.json-result (269756 => 269757)
--- trunk/Source/_javascript_Core/inspector/scripts/tests/expected/type-requiring-runtime-casts.json-result 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/_javascript_Core/inspector/scripts/tests/expected/type-requiring-runtime-casts.json-result 2020-11-12 22:54:19 UTC (rev 269757)
@@ -646,14 +646,14 @@
namespace TestHelpers {
-static const char* const enum_constant_values[] = {
- "Ducks",
- "Hens",
- "Crows",
- "Flamingos",
- "Pigs",
- "Cows",
- "Cats",
+static const ASCIILiteral enum_constant_values[] = {
+ "Ducks"_s,
+ "Hens"_s,
+ "Crows"_s,
+ "Flamingos"_s,
+ "Pigs"_s,
+ "Cows"_s,
+ "Cats"_s,
};
String getEnumConstantValue(int code) {
Modified: trunk/Source/_javascript_Core/inspector/scripts/tests/expected/type-with-open-parameters.json-result (269756 => 269757)
--- trunk/Source/_javascript_Core/inspector/scripts/tests/expected/type-with-open-parameters.json-result 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/_javascript_Core/inspector/scripts/tests/expected/type-with-open-parameters.json-result 2020-11-12 22:54:19 UTC (rev 269757)
@@ -453,7 +453,7 @@
}
// Property names for type generated as open.
- None static const char* alphaKey;
+ None static const ASCIILiteral alphaKey;
};
} // Test
@@ -504,7 +504,7 @@
namespace Protocol {
-const char* Protocol::Test::OpenParameters::alphaKey = "alpha";
+const ASCIILiteral Protocol::Test::OpenParameters::alphaKey = "alpha"_s;
} // namespace Protocol
Modified: trunk/Source/WTF/ChangeLog (269756 => 269757)
--- trunk/Source/WTF/ChangeLog 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/WTF/ChangeLog 2020-11-12 22:54:19 UTC (rev 269757)
@@ -1,3 +1,22 @@
+2020-11-12 Devin Rousso <[email protected]>
+
+ 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.
+
+ * 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`.
+
2020-11-12 Zalan Bujtas <[email protected]>
Show legacy line layout visual coverage instead of "simple line" layout.
Modified: trunk/Source/WTF/wtf/JSONValues.cpp (269756 => 269757)
--- trunk/Source/WTF/wtf/JSONValues.cpp 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/WTF/wtf/JSONValues.cpp 2020-11-12 22:54:19 UTC (rev 269757)
@@ -484,11 +484,6 @@
return adoptRef(*new Value(value));
}
-Ref<Value> Value::create(const char* value)
-{
- return adoptRef(*new Value(value));
-}
-
RefPtr<Value> Value::asValue()
{
return this;
Modified: trunk/Source/WTF/wtf/JSONValues.h (269756 => 269757)
--- trunk/Source/WTF/wtf/JSONValues.h 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Source/WTF/wtf/JSONValues.h 2020-11-12 22:54:19 UTC (rev 269757)
@@ -77,7 +77,6 @@
static Ref<Value> create(int);
static Ref<Value> create(double);
static Ref<Value> create(const String&);
- static Ref<Value> create(const char*);
enum class Type {
Null = 0,
@@ -150,15 +149,6 @@
m_value.string->ref();
}
- explicit Value(const char* value)
- : m_type { Type::String }
- {
- String wrapper(value);
- m_value.string = wrapper.impl();
- if (m_value.string)
- m_value.string->ref();
- }
-
private:
Type m_type { Type::Null };
union {
@@ -415,26 +405,49 @@
}
public:
- void addItem(Ref<T>&& value)
+
+ template <typename V = T>
+ std::enable_if_t<std::is_same_v<bool, V> || std::is_same_v<Value, V>> addItem(bool value)
{
- castedArray().pushValue(WTFMove(value));
+ castedArray().pushBoolean(value);
}
-
- void addItem(const String& value)
+
+ template <typename V = T>
+ std::enable_if_t<std::is_same_v<int, V> || std::is_same_v<Value, V>> addItem(int value)
{
+ castedArray().pushInteger(value);
+ }
+
+ template <typename V = T>
+ std::enable_if_t<std::is_same_v<double, V> || std::is_same_v<Value, V>> addItem(double value)
+ {
+ castedArray().pushDouble(value);
+ }
+
+ template <typename V = T>
+ std::enable_if_t<std::is_same_v<String, V> || std::is_same_v<Value, V>> addItem(const String& value)
+ {
castedArray().pushString(value);
}
- void addItem(int value)
+ template <typename V = T>
+ 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)
{
- castedArray().pushInteger(value);
+ castedArray().pushValue(WTFMove(value));
}
- void addItem(double value)
+ template <typename V = T>
+ std::enable_if_t<std::is_base_of_v<ObjectBase, V>> addItem(Ref<ObjectBase>&& value)
{
- castedArray().pushDouble(value);
+ castedArray().pushObject(WTFMove(value));
}
+ template <typename V = T>
+ std::enable_if_t<std::is_base_of_v<ArrayBase, V>> addItem(Ref<ArrayBase>&& value)
+ {
+ castedArray().pushArray(WTFMove(value));
+ }
+
static Ref<ArrayOf<T>> create()
{
return adoptRef(*new ArrayOf<T>());
Modified: trunk/Tools/ChangeLog (269756 => 269757)
--- trunk/Tools/ChangeLog 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Tools/ChangeLog 2020-11-12 22:54:19 UTC (rev 269757)
@@ -1,3 +1,14 @@
+2020-11-12 Devin Rousso <[email protected]>
+
+ 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.
+
+ * TestWebKitAPI/Tests/WTF/JSONValue.cpp:
+ (TestWebKitAPI::TEST):
+ Use `_s` and `makeString` to ensure that the `String` function overload is used.
+
2020-11-12 Ali Juma <[email protected]>
configure-xcode-for-embedded-development breaks @available in Swift files
Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/JSONValue.cpp (269756 => 269757)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/JSONValue.cpp 2020-11-12 22:52:51 UTC (rev 269756)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/JSONValue.cpp 2020-11-12 22:54:19 UTC (rev 269757)
@@ -86,11 +86,11 @@
}
{
- Ref<JSON::Value> value = JSON::Value::create("webkit");
+ Ref<JSON::Value> value = JSON::Value::create(makeString("webkit"_s));
EXPECT_TRUE(value->type() == JSON::Value::Type::String);
auto stringValue = value->asString();
EXPECT_TRUE(!!stringValue);
- EXPECT_EQ(stringValue, "webkit");
+ EXPECT_EQ(stringValue, "webkit"_s);
String nullString;
value = JSON::Value::create(nullString);
@@ -160,13 +160,13 @@
EXPECT_TRUE(doubleValue);
EXPECT_EQ(*doubleValue, 1.5);
- array->pushString("webkit");
+ array->pushString("webkit"_s);
EXPECT_EQ(array->length(), 5U);
value = array->get(4);
EXPECT_TRUE(value->type() == JSON::Value::Type::String);
auto stringValue = value->asString();
EXPECT_TRUE(!!stringValue);
- EXPECT_EQ(stringValue, "webkit");
+ EXPECT_EQ(stringValue, "webkit"_s);
array->pushObject(JSON::Object::create());
EXPECT_EQ(array->length(), 6U);
@@ -249,13 +249,13 @@
EXPECT_TRUE(doubleValue);
EXPECT_EQ(*doubleValue, 1.5);
- array->addItem("webkit");
+ array->addItem(makeString("webkit"_s));
EXPECT_EQ(array->length(), 4U);
value = array->get(3);
EXPECT_TRUE(value->type() == JSON::Value::Type::String);
auto stringValue = value->asString();
EXPECT_TRUE(!!stringValue);
- EXPECT_EQ(stringValue, "webkit");
+ EXPECT_EQ(stringValue, "webkit"_s);
array->addItem(JSON::Object::create());
EXPECT_EQ(array->length(), 5U);
@@ -311,47 +311,47 @@
object->setValue("null", JSON::Value::null());
EXPECT_EQ(object->size(), 1U);
- auto value = object->getValue("null");
+ auto value = object->getValue("null"_s);
EXPECT_TRUE(value);
EXPECT_TRUE(value->isNull());
object->setBoolean("boolean", true);
EXPECT_EQ(object->size(), 2U);
- auto booleanValue = object->getBoolean("boolean");
+ auto booleanValue = object->getBoolean("boolean"_s);
EXPECT_TRUE(booleanValue);
EXPECT_EQ(*booleanValue, true);
object->setInteger("integer", 1);
EXPECT_EQ(object->size(), 3U);
- auto integerValue = object->getInteger("integer");
+ auto integerValue = object->getInteger("integer"_s);
EXPECT_TRUE(integerValue);
EXPECT_EQ(*integerValue, 1);
object->setDouble("double", 1.5);
EXPECT_EQ(object->size(), 4U);
- auto doubleValue = object->getDouble("double");
+ auto doubleValue = object->getDouble("double"_s);
EXPECT_TRUE(doubleValue);
EXPECT_EQ(*doubleValue, 1.5);
- object->setString("string", "webkit");
+ object->setString("string", "webkit"_s);
EXPECT_EQ(object->size(), 5U);
- auto stringValue = object->getString("string");
+ auto stringValue = object->getString("string"_s);
EXPECT_TRUE(!!stringValue);
- EXPECT_EQ(stringValue, "webkit");
+ EXPECT_EQ(stringValue, "webkit"_s);
object->setObject("object", JSON::Object::create());
EXPECT_EQ(object->size(), 6U);
- auto objectValue = object->getObject("object");
+ auto objectValue = object->getObject("object"_s);
EXPECT_TRUE(objectValue);
EXPECT_EQ(objectValue->size(), 0U);
object->setArray("array", JSON::Array::create());
EXPECT_EQ(object->size(), 7U);
- auto arrayValue = object->getArray("array");
+ auto arrayValue = object->getArray("array"_s);
EXPECT_TRUE(arrayValue);
EXPECT_EQ(arrayValue->length(), 0U);
- Vector<const char*> keys = { "null", "boolean", "integer", "double", "string", "object", "array" };
+ Vector<String> keys = { "null"_s, "boolean"_s, "integer"_s, "double"_s, "string"_s, "object"_s, "array"_s };
auto end = object->end();
for (auto it = object->begin(); it != end; ++it) {
auto position = keys.find(it->key);
@@ -361,33 +361,33 @@
}
EXPECT_TRUE(keys.isEmpty());
- object->remove("null");
+ object->remove("null"_s);
EXPECT_EQ(object->size(), 6U);
- EXPECT_TRUE(object->find("null") == object->end());
+ EXPECT_TRUE(object->find("null"_s) == object->end());
- object->remove("boolean");
+ object->remove("boolean"_s);
EXPECT_EQ(object->size(), 5U);
- EXPECT_TRUE(object->find("boolean") == object->end());
+ EXPECT_TRUE(object->find("boolean"_s) == object->end());
- object->remove("integer");
+ object->remove("integer"_s);
EXPECT_EQ(object->size(), 4U);
- EXPECT_TRUE(object->find("integer") == object->end());
+ EXPECT_TRUE(object->find("integer"_s) == object->end());
- object->remove("double");
+ object->remove("double"_s);
EXPECT_EQ(object->size(), 3U);
- EXPECT_TRUE(object->find("double") == object->end());
+ EXPECT_TRUE(object->find("double"_s) == object->end());
- object->remove("string");
+ object->remove("string"_s);
EXPECT_EQ(object->size(), 2U);
- EXPECT_TRUE(object->find("string") == object->end());
+ EXPECT_TRUE(object->find("string"_s) == object->end());
- object->remove("object");
+ object->remove("object"_s);
EXPECT_EQ(object->size(), 1U);
- EXPECT_TRUE(object->find("object") == object->end());
+ EXPECT_TRUE(object->find("object"_s) == object->end());
- object->remove("array");
+ object->remove("array"_s);
EXPECT_EQ(object->size(), 0U);
- EXPECT_TRUE(object->find("array") == object->end());
+ EXPECT_TRUE(object->find("array"_s) == object->end());
}
TEST(JSONValue, ToJSONString)
@@ -394,71 +394,71 @@
{
{
Ref<JSON::Value> value = JSON::Value::null();
- EXPECT_EQ(value->toJSONString(), "null");
+ EXPECT_EQ(value->toJSONString(), "null"_s);
}
{
Ref<JSON::Value> value = JSON::Value::create(true);
- EXPECT_EQ(value->toJSONString(), "true");
+ EXPECT_EQ(value->toJSONString(), "true"_s);
value = JSON::Value::create(false);
- EXPECT_EQ(value->toJSONString(), "false");
+ EXPECT_EQ(value->toJSONString(), "false"_s);
}
{
Ref<JSON::Value> value = JSON::Value::create(1);
- EXPECT_EQ(value->toJSONString(), "1");
+ EXPECT_EQ(value->toJSONString(), "1"_s);
}
{
Ref<JSON::Value> value = JSON::Value::create(1.5);
- EXPECT_EQ(value->toJSONString(), "1.5");
+ EXPECT_EQ(value->toJSONString(), "1.5"_s);
}
{
- Ref<JSON::Value> value = JSON::Value::create("webkit");
- EXPECT_EQ(value->toJSONString(), "\"webkit\"");
+ Ref<JSON::Value> value = JSON::Value::create(makeString("webkit"_s));
+ EXPECT_EQ(value->toJSONString(), "\"webkit\""_s);
}
{
Ref<JSON::Array> array = JSON::Array::create();
- EXPECT_EQ(array->toJSONString(), "[]");
+ EXPECT_EQ(array->toJSONString(), "[]"_s);
array->pushValue(JSON::Value::null());
- EXPECT_EQ(array->toJSONString(), "[null]");
+ EXPECT_EQ(array->toJSONString(), "[null]"_s);
array->pushBoolean(true);
array->pushBoolean(false);
- EXPECT_EQ(array->toJSONString(), "[null,true,false]");
+ EXPECT_EQ(array->toJSONString(), "[null,true,false]"_s);
array->pushInteger(1);
array->pushDouble(1.5);
- EXPECT_EQ(array->toJSONString(), "[null,true,false,1,1.5]");
- array->pushString("webkit");
- EXPECT_EQ(array->toJSONString(), "[null,true,false,1,1.5,\"webkit\"]");
+ EXPECT_EQ(array->toJSONString(), "[null,true,false,1,1.5]"_s);
+ array->pushString("webkit"_s);
+ EXPECT_EQ(array->toJSONString(), "[null,true,false,1,1.5,\"webkit\"]"_s);
Ref<JSON::Array> subArray = JSON::Array::create();
- subArray->pushString("string");
+ subArray->pushString("string"_s);
subArray->pushObject(JSON::Object::create());
- EXPECT_EQ(subArray->toJSONString(), "[\"string\",{}]");
+ EXPECT_EQ(subArray->toJSONString(), "[\"string\",{}]"_s);
array->pushArray(WTFMove(subArray));
- EXPECT_EQ(array->toJSONString(), "[null,true,false,1,1.5,\"webkit\",[\"string\",{}]]");
+ EXPECT_EQ(array->toJSONString(), "[null,true,false,1,1.5,\"webkit\",[\"string\",{}]]"_s);
}
{
Ref<JSON::Object> object = JSON::Object::create();
- EXPECT_EQ(object->toJSONString(), "{}");
+ EXPECT_EQ(object->toJSONString(), "{}"_s);
object->setValue("null", JSON::Value::null());
- EXPECT_EQ(object->toJSONString(), "{\"null\":null}");
+ EXPECT_EQ(object->toJSONString(), "{\"null\":null}"_s);
object->setBoolean("boolean", true);
- EXPECT_EQ(object->toJSONString(), "{\"null\":null,\"boolean\":true}");
+ EXPECT_EQ(object->toJSONString(), "{\"null\":null,\"boolean\":true}"_s);
object->setDouble("double", 1.5);
- EXPECT_EQ(object->toJSONString(), "{\"null\":null,\"boolean\":true,\"double\":1.5}");
- object->setString("string", "webkit");
- EXPECT_EQ(object->toJSONString(), "{\"null\":null,\"boolean\":true,\"double\":1.5,\"string\":\"webkit\"}");
+ EXPECT_EQ(object->toJSONString(), "{\"null\":null,\"boolean\":true,\"double\":1.5}"_s);
+ object->setString("string", "webkit"_s);
+ EXPECT_EQ(object->toJSONString(), "{\"null\":null,\"boolean\":true,\"double\":1.5,\"string\":\"webkit\"}"_s);
object->setArray("array", JSON::Array::create());
- EXPECT_EQ(object->toJSONString(), "{\"null\":null,\"boolean\":true,\"double\":1.5,\"string\":\"webkit\",\"array\":[]}");
+ EXPECT_EQ(object->toJSONString(), "{\"null\":null,\"boolean\":true,\"double\":1.5,\"string\":\"webkit\",\"array\":[]}"_s);
Ref<JSON::Object> subObject = JSON::Object::create();
- subObject->setString("foo", "bar");
+ subObject->setString("foo", "bar"_s);
subObject->setInteger("baz", 25);
object->setObject("object", WTFMove(subObject));
- EXPECT_EQ(object->toJSONString(), "{\"null\":null,\"boolean\":true,\"double\":1.5,\"string\":\"webkit\",\"array\":[],\"object\":{\"foo\":\"bar\",\"baz\":25}}");
+ EXPECT_EQ(object->toJSONString(), "{\"null\":null,\"boolean\":true,\"double\":1.5,\"string\":\"webkit\",\"array\":[],\"object\":{\"foo\":\"bar\",\"baz\":25}}"_s);
}
}
@@ -465,13 +465,13 @@
TEST(JSONValue, ParseJSON)
{
{
- auto value = JSON::Value::parseJSON("null");
+ auto value = JSON::Value::parseJSON("null"_s);
EXPECT_TRUE(value);
EXPECT_TRUE(value->isNull());
}
{
- auto value = JSON::Value::parseJSON("true");
+ auto value = JSON::Value::parseJSON("true"_s);
EXPECT_TRUE(value);
EXPECT_TRUE(value->type() == JSON::Value::Type::Boolean);
auto booleanValue = value->asBoolean();
@@ -478,7 +478,7 @@
EXPECT_TRUE(booleanValue);
EXPECT_EQ(*booleanValue, true);
- value = JSON::Value::parseJSON("false");
+ value = JSON::Value::parseJSON("false"_s);
EXPECT_TRUE(value);
EXPECT_TRUE(value->type() == JSON::Value::Type::Boolean);
booleanValue = value->asBoolean();
@@ -487,7 +487,7 @@
}
{
- auto value = JSON::Value::parseJSON("1");
+ auto value = JSON::Value::parseJSON("1"_s);
EXPECT_TRUE(value);
// Numbers are always parsed as double.
EXPECT_TRUE(value->type() == JSON::Value::Type::Double);
@@ -495,7 +495,7 @@
EXPECT_TRUE(doubleValue);
EXPECT_EQ(*doubleValue, 1.0);
- value = JSON::Value::parseJSON("1.5");
+ value = JSON::Value::parseJSON("1.5"_s);
EXPECT_TRUE(value);
EXPECT_TRUE(value->type() == JSON::Value::Type::Double);
doubleValue = value->asDouble();
@@ -504,16 +504,16 @@
}
{
- auto value = JSON::Value::parseJSON("\"string\"");
+ auto value = JSON::Value::parseJSON("\"string\""_s);
EXPECT_TRUE(value);
EXPECT_TRUE(value->type() == JSON::Value::Type::String);
auto stringValue = value->asString();
EXPECT_TRUE(!!stringValue);
- EXPECT_EQ(stringValue, "string");
+ EXPECT_EQ(stringValue, "string"_s);
}
{
- auto value = JSON::Value::parseJSON("[]");
+ auto value = JSON::Value::parseJSON("[]"_s);
EXPECT_TRUE(value);
EXPECT_TRUE(value->type() == JSON::Value::Type::Array);
auto arrayValue = value->asArray();
@@ -520,7 +520,7 @@
EXPECT_TRUE(arrayValue);
EXPECT_EQ(arrayValue->length(), 0U);
- value = JSON::Value::parseJSON("[null, 1 ,2.5,[{\"foo\":\"bar\"},{\"baz\":false}],\"webkit\"]");
+ value = JSON::Value::parseJSON("[null, 1 ,2.5,[{\"foo\":\"bar\"},{\"baz\":false}],\"webkit\"]"_s);
EXPECT_TRUE(value);
EXPECT_TRUE(value->type() == JSON::Value::Type::Array);
arrayValue = value->asArray();
@@ -554,15 +554,15 @@
auto object = objectValue->asObject();
EXPECT_TRUE(object);
EXPECT_EQ(object->size(), 1U);
- auto stringValue = object->getString("foo");
+ auto stringValue = object->getString("foo"_s);
EXPECT_TRUE(!!stringValue);
- EXPECT_EQ(stringValue, "bar");
+ EXPECT_EQ(stringValue, "bar"_s);
objectValue = subArrayValue->get(1);
EXPECT_TRUE(objectValue->type() == JSON::Value::Type::Object);
object =objectValue->asObject();
EXPECT_TRUE(object);
EXPECT_EQ(object->size(), 1U);
- auto booleanValue = object->getBoolean("baz");
+ auto booleanValue = object->getBoolean("baz"_s);
EXPECT_TRUE(booleanValue);
EXPECT_EQ(*booleanValue, false);
++it;
@@ -571,13 +571,13 @@
EXPECT_TRUE((*it)->type() == JSON::Value::Type::String);
stringValue = (*it)->asString();
EXPECT_TRUE(!!stringValue);
- EXPECT_EQ(stringValue, "webkit");
+ EXPECT_EQ(stringValue, "webkit"_s);
++it;
EXPECT_TRUE(it == arrayValue->end());
}
{
- auto value = JSON::Value::parseJSON("{}");
+ auto value = JSON::Value::parseJSON("{}"_s);
EXPECT_TRUE(value);
EXPECT_TRUE(value->type() == JSON::Value::Type::Object);
auto objectValue = value->asObject();
@@ -584,7 +584,7 @@
EXPECT_TRUE(objectValue);
EXPECT_EQ(objectValue->size(), 0U);
- value = JSON::Value::parseJSON("{\"foo\": \"bar\", \"baz\": {\"sub\":[null,false]}}");
+ value = JSON::Value::parseJSON("{\"foo\": \"bar\", \"baz\": {\"sub\":[null,false]}}"_s);
EXPECT_TRUE(value);
EXPECT_TRUE(value->type() == JSON::Value::Type::Object);
objectValue = value->asObject();
@@ -591,43 +591,43 @@
EXPECT_TRUE(objectValue);
EXPECT_EQ(objectValue->size(), 2U);
- auto stringValue = objectValue->getString("foo");
+ auto stringValue = objectValue->getString("foo"_s);
EXPECT_TRUE(!!stringValue);
- EXPECT_EQ(stringValue, "bar");
+ EXPECT_EQ(stringValue, "bar"_s);
- auto object = objectValue->getObject("baz");
+ auto object = objectValue->getObject("baz"_s);
EXPECT_TRUE(object);
EXPECT_EQ(object->size(), 1U);
- auto array = object->getArray("sub");
+ auto array = object->getArray("sub"_s);
EXPECT_TRUE(array);
EXPECT_EQ(array->length(), 2U);
}
{
- EXPECT_FALSE(JSON::Value::parseJSON(","));
- EXPECT_FALSE(JSON::Value::parseJSON("\"foo"));
- EXPECT_FALSE(JSON::Value::parseJSON("foo\""));
- EXPECT_FALSE(JSON::Value::parseJSON("TrUe"));
- EXPECT_FALSE(JSON::Value::parseJSON("False"));
- EXPECT_FALSE(JSON::Value::parseJSON("1.d"));
- EXPECT_FALSE(JSON::Value::parseJSON("[1,]"));
- EXPECT_FALSE(JSON::Value::parseJSON("1,2]"));
- EXPECT_FALSE(JSON::Value::parseJSON("[1,2"));
- EXPECT_FALSE(JSON::Value::parseJSON("[1 2]"));
- EXPECT_FALSE(JSON::Value::parseJSON("[1,2]]"));
- EXPECT_FALSE(JSON::Value::parseJSON("[1,2],"));
- EXPECT_FALSE(JSON::Value::parseJSON("{foo:\"bar\"}"));
- EXPECT_FALSE(JSON::Value::parseJSON("{\"foo\":bar}"));
- EXPECT_FALSE(JSON::Value::parseJSON("{\"foo:\"bar\"}"));
- EXPECT_FALSE(JSON::Value::parseJSON("{foo\":\"bar\"}"));
- EXPECT_FALSE(JSON::Value::parseJSON("{{\"foo\":\"bar\"}}"));
- EXPECT_FALSE(JSON::Value::parseJSON("{\"foo\":\"bar\"},"));
- EXPECT_FALSE(JSON::Value::parseJSON("[{\"foo\":\"bar\"},{\"baz\":false},]"));
- EXPECT_FALSE(JSON::Value::parseJSON("[{\"foo\":{\"baz\":false}]"));
+ EXPECT_FALSE(JSON::Value::parseJSON(","_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("\"foo"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("foo\""_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("TrUe"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("False"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("1.d"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("[1,]"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("1,2]"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("[1,2"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("[1 2]"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("[1,2]]"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("[1,2],"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("{foo:\"bar\"}"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("{\"foo\":bar}"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("{\"foo:\"bar\"}"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("{foo\":\"bar\"}"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("{{\"foo\":\"bar\"}}"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("{\"foo\":\"bar\"},"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("[{\"foo\":\"bar\"},{\"baz\":false},]"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("[{\"foo\":{\"baz\":false}]"_s));
}
{
- auto value = JSON::Value::parseJSON(" \"foo\" \n");
+ auto value = JSON::Value::parseJSON(" \"foo\" \n"_s);
EXPECT_TRUE(value);
auto stringValue = value->asString();
EXPECT_TRUE(!!stringValue);
@@ -635,34 +635,34 @@
}
{
- EXPECT_TRUE(JSON::Value::parseJSON(" 1"));
- EXPECT_TRUE(JSON::Value::parseJSON("\t1"));
- EXPECT_TRUE(JSON::Value::parseJSON("\n1"));
- EXPECT_TRUE(JSON::Value::parseJSON("1 "));
- EXPECT_TRUE(JSON::Value::parseJSON("1\t"));
- EXPECT_TRUE(JSON::Value::parseJSON("1\n"));
- EXPECT_TRUE(JSON::Value::parseJSON(" 1 "));
- EXPECT_TRUE(JSON::Value::parseJSON(" {} "));
- EXPECT_TRUE(JSON::Value::parseJSON(" [] "));
- EXPECT_TRUE(JSON::Value::parseJSON("\"\\xFF\""));
- EXPECT_TRUE(JSON::Value::parseJSON("\"\\u1234\""));
+ EXPECT_TRUE(JSON::Value::parseJSON(" 1"_s));
+ EXPECT_TRUE(JSON::Value::parseJSON("\t1"_s));
+ EXPECT_TRUE(JSON::Value::parseJSON("\n1"_s));
+ EXPECT_TRUE(JSON::Value::parseJSON("1 "_s));
+ EXPECT_TRUE(JSON::Value::parseJSON("1\t"_s));
+ EXPECT_TRUE(JSON::Value::parseJSON("1\n"_s));
+ EXPECT_TRUE(JSON::Value::parseJSON(" 1 "_s));
+ EXPECT_TRUE(JSON::Value::parseJSON(" {} "_s));
+ EXPECT_TRUE(JSON::Value::parseJSON(" [] "_s));
+ EXPECT_TRUE(JSON::Value::parseJSON("\"\\xFF\""_s));
+ EXPECT_TRUE(JSON::Value::parseJSON("\"\\u1234\""_s));
- EXPECT_FALSE(JSON::Value::parseJSON("1 1"));
- EXPECT_FALSE(JSON::Value::parseJSON("{} {}"));
- EXPECT_FALSE(JSON::Value::parseJSON("[] []"));
- EXPECT_FALSE(JSON::Value::parseJSON("\"\\"));
- EXPECT_FALSE(JSON::Value::parseJSON("\"\\xF"));
- EXPECT_FALSE(JSON::Value::parseJSON("\"\\xF\""));
- EXPECT_FALSE(JSON::Value::parseJSON("\"\\xF \""));
- EXPECT_FALSE(JSON::Value::parseJSON("\"\\u1"));
- EXPECT_FALSE(JSON::Value::parseJSON("\"\\u1\""));
- EXPECT_FALSE(JSON::Value::parseJSON("\"\\u1 \""));
- EXPECT_FALSE(JSON::Value::parseJSON("\"\\u12"));
- EXPECT_FALSE(JSON::Value::parseJSON("\"\\u12\""));
- EXPECT_FALSE(JSON::Value::parseJSON("\"\\u12 \""));
- EXPECT_FALSE(JSON::Value::parseJSON("\"\\u123"));
- EXPECT_FALSE(JSON::Value::parseJSON("\"\\u123\""));
- EXPECT_FALSE(JSON::Value::parseJSON("\"\\u123 \""));
+ EXPECT_FALSE(JSON::Value::parseJSON("1 1"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("{} {}"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("[] []"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("\"\\"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("\"\\xF"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("\"\\xF\""_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("\"\\xF \""_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("\"\\u1"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("\"\\u1\""_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("\"\\u1 \""_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("\"\\u12"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("\"\\u12\""_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("\"\\u12 \""_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("\"\\u123"_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("\"\\u123\""_s));
+ EXPECT_FALSE(JSON::Value::parseJSON("\"\\u123 \""_s));
}
}
@@ -697,7 +697,7 @@
}
{
- Ref<JSON::Value> value = JSON::Value::create("test");
+ Ref<JSON::Value> value = JSON::Value::create(makeString("test"_s));
size_t memoryCost = value->memoryCost();
EXPECT_GT(memoryCost, 0U);
EXPECT_LE(memoryCost, 36U);
@@ -704,7 +704,7 @@
}
{
- Ref<JSON::Value> value = JSON::Value::create("");
+ Ref<JSON::Value> value = JSON::Value::create(emptyString());
size_t memoryCost = value->memoryCost();
EXPECT_GT(memoryCost, 0U);
EXPECT_LE(memoryCost, 32U);
@@ -718,10 +718,10 @@
}
{
- Ref<JSON::Value> valueA = JSON::Value::create("t");
- Ref<JSON::Value> valueB = JSON::Value::create("te");
- Ref<JSON::Value> valueC = JSON::Value::create("tes");
- Ref<JSON::Value> valueD = JSON::Value::create("test");
+ Ref<JSON::Value> valueA = JSON::Value::create(makeString("t"_s));
+ Ref<JSON::Value> valueB = JSON::Value::create(makeString("te"_s));
+ Ref<JSON::Value> valueC = JSON::Value::create(makeString("tes"_s));
+ Ref<JSON::Value> valueD = JSON::Value::create(makeString("test"_s));
EXPECT_LT(valueA->memoryCost(), valueB->memoryCost());
EXPECT_LT(valueB->memoryCost(), valueC->memoryCost());
EXPECT_LT(valueC->memoryCost(), valueD->memoryCost());
@@ -728,8 +728,8 @@
}
{
- Ref<JSON::Value> valueA = JSON::Value::create("t");
- Ref<JSON::Value> valueB = JSON::Value::create("😀");
+ Ref<JSON::Value> valueA = JSON::Value::create(makeString("t"_s));
+ Ref<JSON::Value> valueB = JSON::Value::create(makeString("😀"));
EXPECT_LT(valueA->memoryCost(), valueB->memoryCost());
}