Closed Bug 1748714 Opened 3 years ago Closed 3 years ago

Fix conversion to WebIDL for API methods with a JSONSchema definition that includes an optional parameters followed by non optional ones

Categories

(WebExtensions :: General, task, P1)

task
Points:
2

Tracking

(firefox100 fixed)

RESOLVED FIXED
100 Branch
Tracking Status
firefox100 --- fixed

People

(Reporter: rpl, Assigned: rpl)

References

(Blocks 1 open bug)

Details

(Whiteboard: [addons-jira])

Attachments

(4 files)

As part of Bug 1724026 we are going to run alarms API xpcshell tests also on the background service worker and Extensions WebIDL API bindings and one of the test was failure because the type signature of the alarms.create method as defined in ExtensionAlarms.webidl did not allow to call the method with a single parameter, while the current implementation of the Extensions APIs allows that.

The JSONSchema related to the alarms.create API method is:

     {
        "name": "create",
        "type": "function",
        ...
        "parameters": [
          { "name": "name", "optional": true, ... },
          { "type": "object", "name": "alarmInfo", ... }
        ]
      },

and the toolkit/components/extensions/webidl-api/GenerateWebIDLBindings.py converted that into a function part of the ExtensionAlarms.webidl file with the following type signature:

  [Throws, WebExtensionStub="NoReturn"]
  void create(optional DOMString name, any alarmInfo);

At a first glance the two definitions may look the same, but they actually behave differently because the WebIDL one does not actually allow to pass only a single parameter.

On the contrary generating two create methods (one with only the second parameter and one with both) would make browser.alarms.create to behave has the current bindings implementation (and without any additional change, the same NoReturn stub can be used for both and ext-alarms.js will be handling the two cases exactly as in the current bindings implementation):

  [Throws, WebExtensionStub="NoReturn"]
  void create(DOMString name, any alarmInfo);
  [Throws, WebExtensionStub="NoReturn"]
  void create(any alarmInfo);

This will likely be the case also for other API methods, we should update the python script to detect this kind of JSONSchema and generate multiple definitions of the same method as the snippet above.

While looking into this and also took the opportunity to use the python script to print a list of the other API methods which will need similar multiple type signatures:

  notifications.create
  alarms.create
  theme.update
  tabs.update
  tabs.executeScript
  tabs.insertCSS
  tabs.removeCSS
  tabs.setZoom
  tabs.setZoomSettings
Attachment #9258125 - Attachment description: WIP: Bug 1748714 - Regenerate ExtensionAlarms.webidl and remove skip on test_alarms_get_and_clear_single_argument. r?mixedpuppy! → Bug 1748714 - Regenerate ExtensionAlarms.webidl and remove skip on test_alarms_get_and_clear_single_argument. r?mixedpuppy!
Attachment #9258124 - Attachment description: WIP: Bug 1748714 - Generate multiple webidl method signatures on JSONSchema optional parameters followed by a mandatory one. r?robwu → Bug 1748714 - Generate multiple webidl method signatures on JSONSchema optional parameters followed by a mandatory one. r?robwu

Currently only used to hide browser.runtime.getFrameID, which isn't going to be usable
in a background service worker anyway and it is not deprecated in MV3.

Depends on D135420

ExtensionRuntime does also include some APIs that would need multiple signatures for the WebIDL methods
with optional parameters to match the behavior of the current Extensions API bindings.

Depends on D136951

Blocks: 1757727
Pushed by luca.greco@alcacoop.it: https://hg.mozilla.org/integration/autoland/rev/4896da925e83 Generate multiple webidl method signatures on JSONSchema optional parameters followed by a mandatory one. r=robwu https://hg.mozilla.org/integration/autoland/rev/d29943b5e5fd Regenerate ExtensionAlarms.webidl and remove skip on test_alarms_get_and_clear_single_argument. r=mixedpuppy,webidl,peterv https://hg.mozilla.org/integration/autoland/rev/a94f5b8ebdaa Add configuration to hide API methods in WebIDL ExtensionAPI definitions GenerateWebIDLBindings creates based on the JSONSchema data. r=robwu https://hg.mozilla.org/integration/autoland/rev/55e7751e8395 Regenerated ExtensionRuntime API webidl definitions. r=peterv
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: