0

Fix lite js_templates

Sanitze the method parameter names to ensure proper handling of
arguments that match reserved javascript keywords.

Example:
frame.mojom's JavaScriptMethodExecuteRequest method which has a
parameter named `arguments` - a reserved word.

Change-Id: I468e781fef1ff9e2207d926e0d7a61029905b24e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6244181
Reviewed-by: Alex Gough <ajgo@chromium.org>
Commit-Queue: Ali Hijazi <ahijazi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1418185}
This commit is contained in:
Ali Hijazi
2025-02-10 08:52:08 -08:00
committed by Chromium LUCI CQ
parent b650165e7b
commit db8b988113
4 changed files with 22 additions and 4 deletions
content/test/data
mojo/public/tools/bindings/generators/js_templates/lite
third_party/blink/web_tests/http/tests/mojo/shared

@ -57,6 +57,11 @@ interface TestMessageTarget {
RequestSubinterface(pending_receiver<Subinterface> receiver,
pending_remote<SubinterfaceClient> client);
// This ensures we properly handle method parameters that have reserved
// javascript names when generating js bindings.
MethodWithReservedNameParameter(array<int32> arguments)
=> (array<int32> arguments);
};
interface Subinterface {

@ -93,7 +93,7 @@ goog.provide('{{module.namespace}}.{{interface.name}}PendingReceiver');
{{generateMethodAnnotation(method)}}
{{method.name}}(
{%- for param in method.parameters %}
{{param.name}}{%- if not loop.last %},{% endif %}
{{param.name|sanitize_identifier}}{%- if not loop.last %},{% endif %}
{%- endfor -%}) {
{%- if method.response_parameters != None %}
return this.proxy.sendMessage(
@ -109,7 +109,7 @@ goog.provide('{{module.namespace}}.{{interface.name}}PendingReceiver');
{%- endif %}
[
{%- for param in method.parameters %}
{{param.name}}{%- if not loop.last %},{% endif %}
{{param.name|sanitize_identifier}}{%- if not loop.last %},{% endif %}
{%- endfor %}
]);
}

@ -78,7 +78,7 @@ export class {{interface.name}}Remote {
{{generateMethodAnnotation(method)}}
{{method.name}}(
{%- for param in method.parameters %}
{{param.name}}{%- if not loop.last %},{% endif %}
{{param.name|sanitize_identifier}}{%- if not loop.last %},{% endif %}
{%- endfor -%}) {
{%- if method.response_parameters != None %}
return this.proxy.sendMessage(
@ -94,7 +94,7 @@ export class {{interface.name}}Remote {
{%- endif %}
[
{%- for param in method.parameters %}
{{param.name}}{%- if not loop.last %},{% endif %}
{{param.name|sanitize_identifier}}{%- if not loop.last %},{% endif %}
{%- endfor %}
]);
}

@ -21,6 +21,9 @@ class TargetImpl {
flattenUnions(unions) {}
flattenMap(map) {}
requestSubinterface(request, client) {}
methodWithReservedNameParameter(arguments_) {
return Promise.resolve({arguments: arguments_});
}
}
promise_test(() => {
@ -32,6 +35,16 @@ promise_test(() => {
});
}, 'messages with replies return Promises that resolve on reply received');
promise_test(() => {
let impl = new TargetImpl;
let remote = impl.target.$.bindNewPipeAndPassRemote();
return remote.methodWithReservedNameParameter([1, 2, 3, 4]).then(reply => {
assert_array_equals(reply.arguments, [1, 2, 3, 4]);
});
}, 'Methods with reserved argument names are properly handled.');
promise_test(() => {
let impl = new TargetImpl;
let remote = impl.target.$.bindNewPipeAndPassRemote();