Skip to content
Permalink
Browse files
Use JSONValues instead of a JSC::VM to parse WKContentRuleLists
https://bugs.webkit.org/show_bug.cgi?id=231704

Patch by Alex Christensen <achristensen@webkit.org> on 2021-10-19
Reviewed by Brady Eidson.

Source/WebCore:

This makes the parser much simpler and easier to see what is going on.
It probably also saves some memory because we don't need to make a VM just to parse JSON.
Covered by existing tests.  There are extensive tests for invalid input, and there is only
one change in the error reported: we used to say the top level has to be an object, then
we would say that it has to be an array.  JavaScript arrays are objects, but JSON arrays aren't.
Valid input continues to parse the same, and invalid input continues to fail to parse, but the
error is more accurate now.

* contentextensions/ContentExtensionError.cpp:
(WebCore::ContentExtensions::contentExtensionErrorCategory):
* contentextensions/ContentExtensionError.h:
* contentextensions/ContentExtensionParser.cpp:
(WebCore::ContentExtensions::getStringList):
(WebCore::ContentExtensions::getDomainList):
(WebCore::ContentExtensions::getTypeFlags):
(WebCore::ContentExtensions::loadTrigger):
(WebCore::ContentExtensions::loadAction):
(WebCore::ContentExtensions::loadRule):
(WebCore::ContentExtensions::loadEncodedRules):
(WebCore::ContentExtensions::parseRuleList):

Tools:

* TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
(TestWebKitAPI::TEST_F):

Canonical link: https://commits.webkit.org/243225@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@284465 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Alex Christensen authored and webkit-commit-queue committed Oct 19, 2021
1 parent 0e72e4a commit 1f90e62735b5cf8f09870f49080ba2aeac3ead5a
Showing 6 changed files with 138 additions and 205 deletions.
@@ -1,3 +1,31 @@
2021-10-19 Alex Christensen <achristensen@webkit.org>

Use JSONValues instead of a JSC::VM to parse WKContentRuleLists
https://bugs.webkit.org/show_bug.cgi?id=231704

Reviewed by Brady Eidson.

This makes the parser much simpler and easier to see what is going on.
It probably also saves some memory because we don't need to make a VM just to parse JSON.
Covered by existing tests. There are extensive tests for invalid input, and there is only
one change in the error reported: we used to say the top level has to be an object, then
we would say that it has to be an array. JavaScript arrays are objects, but JSON arrays aren't.
Valid input continues to parse the same, and invalid input continues to fail to parse, but the
error is more accurate now.

* contentextensions/ContentExtensionError.cpp:
(WebCore::ContentExtensions::contentExtensionErrorCategory):
* contentextensions/ContentExtensionError.h:
* contentextensions/ContentExtensionParser.cpp:
(WebCore::ContentExtensions::getStringList):
(WebCore::ContentExtensions::getDomainList):
(WebCore::ContentExtensions::getTypeFlags):
(WebCore::ContentExtensions::loadTrigger):
(WebCore::ContentExtensions::loadAction):
(WebCore::ContentExtensions::loadRule):
(WebCore::ContentExtensions::loadEncodedRules):
(WebCore::ContentExtensions::parseRuleList):

2021-10-19 Chris Dumez <cdumez@apple.com>

Drop assertion in RegistrationDatabase::importRecords()
@@ -49,8 +49,6 @@ const std::error_category& contentExtensionErrorCategory()
switch (static_cast<ContentExtensionError>(errorCode)) {
case ContentExtensionError::JSONInvalid:
return "Failed to parse the JSON String.";
case ContentExtensionError::JSONTopLevelStructureNotAnObject:
return "Invalid input, the top level structure is not an object.";
case ContentExtensionError::JSONTopLevelStructureNotAnArray:
return "Invalid input, the top level structure is not an array.";
case ContentExtensionError::JSONInvalidObjectInTopLevelArray:
@@ -37,7 +37,6 @@ enum class ContentExtensionError {
JSONInvalid = 1,

// JSON semantics error
JSONTopLevelStructureNotAnObject,
JSONTopLevelStructureNotAnArray,
JSONInvalidObjectInTopLevelArray,
JSONInvalidRule,

0 comments on commit 1f90e62

Please sign in to comment.