Closed Bug 1757808 Opened 3 years ago Closed 3 years ago

Merge Underlying{Sink,Source}*Callback class sets into a single class for each set

Categories

(Core :: DOM: Streams, task)

task

Tracking

()

RESOLVED FIXED
100 Branch
Tracking Status
firefox100 --- fixed

People

(Reporter: saschanaz, Assigned: saschanaz)

References

Details

Attachments

(2 files)

Having separate callback classes requires implementing all four classes whenever we get a new native use (currently we have BodyStream* where the start callback is a bit hacky - bug 1746077). And sometimes one of the callbacks is just like "let algorithm be a step that returns undefined", currently doing so requires a full class definition, which is way too much.

Since AFAICT those callbacks are always used together, having a class-as-a-callback-set will shorten the lines and simplify the cycle collection.

(Chrome is seemingly also doing that, so I believe doing the same here shouldn't mean we risk diverting too much from the spec.)

I appreciate the current design for being very easy to map from specification to implementation. Having said that, I agree that it leads to lots of boiler plate.

Some questions:

  1. You've been working on reducing boilerplate with the macros: Do you see this as alternative approach and we'd skip the macro patches then?
  2. You link to Bug 1746077; I agree we'd have a cleaner situation this way. However, this also makes me wonder: we get into situations like var source = { pull(controller) { ... } }, where the Pull callback is IDL provided, but the start and cancel callbacks would be the default implementation. How does that end up looking in this world where we have a single object?
Flags: needinfo?(krosylight)
  1. You've been working on reducing boilerplate with the macros: Do you see this as alternative approach and we'd skip the macro patches then?

Yup, with merged classes I don't think the macros are needed.

  1. You link to Bug 1746077; I agree we'd have a cleaner situation this way. However, this also makes me wonder: we get into situations like var source = { pull(controller) { ... } }, where the Pull callback is IDL provided, but the start and cancel callbacks would be the default implementation. How does that end up looking in this world where we have a single object?

Maybe the IDL helper class can include the default implementation in that case?

// pseudocode...
class IDLUnderlyingSourceCallbacks {
  pull() {
    if (mPullCallback) {
      mPullCallback->Call();
      return;
    }
    DefaultImpl();
  }
}

Edit: And if any native class ever need the default algorithms, then we can expose them as static functions.

Flags: needinfo?(krosylight)

Ok; I think that this will be a valuable exploration and potentially compelling cleanup.

BTW, with that same logic the existing IDL helper classes could also do that. https://searchfox.org/mozilla-central/rev/48c71577cbb4ce5a218cf4385aff1ff244dc4432/dom/streams/ReadableByteStreamController.cpp#561-564

Was there reasons not to include the default impls in the IDL helpers?

Flags: needinfo?(mgaudet)

I think it didn't quite occur to me; it is a slight violation of the single responsibility principle, but, it definitely could have been done.. but the inlining of the default algorithm was to avoid having yet-another-object in the default case.

I am less enamoured of the decision than I was when I first made it.

Flags: needinfo?(mgaudet)

Okay, I'd like to do this before I add any native helpers for transfer/transform things.

Assignee: nobody → krosylight
Status: NEW → ASSIGNED
Pushed by krosylight@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/90c80d7dc7a8
Part 1: Merge SinkCallback classes as UnderlyingSinkAlgorithms r=mgaudet
https://hg.mozilla.org/integration/autoland/rev/919e468d0f28
Part 2: Merge SourceCallback classes as UnderlyingSourceAlgorithms r=mgaudet
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 100 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: