You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 6a6a378
Browse filesBrowse the repository at this point in the historyBrowse files
[Web Inspector] Add validation for optional enum parameters
https://bugs.webkit.org/show_bug.cgi?id=304062
Reviewed by Devin Rousso and BJ Burg.
The Inspector protocol code generator was not validating optional enum
parameters, allowing invalid values to pass through to the backend
implementation. This is a followup to #58033, handling enum validation at
the JSON-RPC error code level.
Per the JSON-RPC 2.0 specification (https://www.jsonrpc.org/specification),
invalid parameter values should return error code -32602 (Invalid params).
The W3C WebDriver BiDi specification (https://w3c.github.io/webdriver-bidi/)
explicitly follows JSON-RPC 2.0 and requires this error code for invalid
enum values.
This fix uses the framework settings system to configure error codes for
enum validation. The WebDriverBidi and Test frameworks use InvalidParams
(-32602) for both required and optional enum parameters, while other
frameworks preserve the existing ServerError (-32000) behavior for
compatibility. The per-framework settings can be unified once downstream
issues (such as Connection.js test breakages) are resolved.
Tests:
* imported/w3c/webdriver/tests/bidi/script/get_realms/invalid.py::test_params_type_invalid_value (protocol test)
* Source/JavaScriptCore/inspector/scripts/tests/webdriver-bidi-enum-validation.json (generator test)
* Source/JavaScriptCore/inspector/scripts/codegen/models.py:
Add enum_invalid_value_error_code setting to WebDriverBidi and Test framework
configurations.
* Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_backend_dispatcher_implementation.py:
Read error code from framework setting. Apply InvalidParams or ServerError for
both required and optional enum parameters based on framework configuration.
* Source/JavaScriptCore/inspector/scripts/tests/webdriver-bidi-enum-validation.json:
Add generator test fixture covering required and optional enum parameters.
* Source/JavaScriptCore/inspector/scripts/tests/expected/*.json-result:
Update expected outputs for Test framework to use InvalidParams for enum validation.
* WebDriverTests/TestExpectations.json:
Remove expected failure for test_params_type_invalid_value test.
Canonical link: https://commits.webkit.org/310738@main
parameter_enum_resolutions.append(' auto %(enumVariableName)s = Protocol::%(helpersNamespace)s::parseEnumValueFromString<%(enumType)s>(%(stringVariableName)s);'%enum_args)
259
+
enum_args['enumErrorCode'] =enum_error_code
258
260
ifparameter.is_optional:
261
+
parameter_enum_resolutions.append(' if (!%(stringVariableName)s.isEmpty() && !%(enumVariableName)s) {'%enum_args)
Copy file name to clipboardExpand all lines: Source/JavaScriptCore/inspector/scripts/tests/expected/commands-with-optional-call-return-parameters.json-result
0 commit comments