Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise sanity checks on AudioWorkletProcessor.process() method #1773

Merged
merged 14 commits into from
Oct 18, 2018

Conversation

hoch
Copy link
Member

@hoch hoch commented Sep 27, 2018

Fixes: #1767

  • Removes the process function check in AudioWorkletProcessor instantiation.
  • Introduce the new callable process internal slot to AudioWorkletProcessor.
  • Revise "Rendering an Audio Graph" section to add a new check on process function.
  • Minor editorial fixes. (numbering ordered list)

Preview | Diff

index.bs Outdated
<var>processor</var>.

9. <a>Queue a task</a> the <a>control thread</a> to set the associated
1. <a>Queue a task</a> the <a>control thread</a> to set the associated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're modifying this anyway: "Queue a task the" -> "Queue a task to the".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

index.bs Outdated
to [=Computing a block of audio|compute a block of audio=] with
the argument of [=input buffer=], output buffer and
[=input AudioParam buffer=].
4. If this {{AudioNode}} is an {{AudioWorkletNode}}, execute these step:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"step:" -> "steps:"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

index.bs Outdated

3. If <code><a href="http://www.ecma-international.org/ecma-262/6.0/#sec-iscallable">
IsCallable</a>(argument=<i><var>processFunction</var></i>)</code> is
false, throw a {{TypeError}}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not ReferenceError if the function doesn't exist?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am no expert on ES6 abstract operation, but technically IsCallable checks if the target is function type. So I think TypeError is correct here.

Example: https://www.ecma-international.org/ecma-262/7.0/#sec-getmethod

index.bs Outdated
@@ -9848,7 +9848,8 @@ custom audio node. {{AudioWorkletProcessor}} can
only be instantiated by the construction of an
{{AudioWorkletNode}} instance. Every
{{AudioWorkletProcessor}} has an associated <dfn>node
reference</dfn>, initially null.
reference</dfn> and <dfn>callable process</dfn> that are
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these internal slots (conceptually)? If so, we should probably use the [[foo]] notation to indicate that. If not, then these dfn's define the terms without really defining the what the terms mean.

Copy link
Member Author

@hoch hoch Oct 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the [[foo]] notation for the internal slot that are used by ECMAScript operation? We don't keep node reference in that way because it's not used by the operation itself. It is only used by the algorithm defined in the spec. I think callable process is same as well.

With that said, I am no expert on this issue and not sure what's the right way.

Copy link
Member

@rtoy rtoy Oct 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. But we use it all over some for slots like [[buffer set]] or [[internal reduction]] and these aren't all ECMAScript operations.

Nevertheless, the dfn don't define anything really, so a little bit of text about what it is would be useful. Or maybe you really just want them to be <var>s for the algorithm. This probably requires a bit more work.

index.bs Outdated

1. The associated {{AudioWorkletProcessor}}'s
<a>active source</a> flag is equal to `true`.
1. <a>callable process</a> is `true`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should not use numeric items since ordering is not needed?

index.bs Outdated
[=input AudioParam buffer=].
4. If this {{AudioNode}} is an {{AudioWorkletNode}}, execute these steps:

1. If <a>callable process</a> is `false`, abort the following sub steps.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to indent this some more. I see that this step is labeled 5.

Also, when the following steps are aborted, where do we go from here? What's the next step in the algorithm?

index.bs Outdated
IsCallable</a>(argument=<i><var>processFunction</var></i>)</code> is
false, execute the following:

1. Queue a control message to fire `onprocessorerror` event on the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice (but not necessary) if onprocessorerror were a link to the attribute.

index.bs Outdated
1. Queue a control message to fire `onprocessorerror` event on the
associated AudioWorkletNode.

1. Set <a>callable process</a> to `false`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The algorithm flow is to continue after setting this to false. Is that what you want? I think not since IsCallable returned false, you shouldn't call the process method in the next step.

index.bs Outdated

: <dfn>[[callable process]]</dfn>
::
A boolean flag represents whether {{AudioWorkletProcessor/process()}} is
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably s/represents/representing/

index.bs Outdated
: <dfn>[[callable process]]</dfn>
::
A boolean flag represents whether {{AudioWorkletProcessor/process()}} is
a valid function that can ba invoked.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/ba invoked/be invoked/

index.bs Outdated
<dfn dfn>active processing conditions</dfn> are true:
every <a>render quantum</a>, if both conditions are met:

* {{{[[callable process]]}} is `true`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/{{{/{{/


9. <a>Queue a task</a> the <a>control thread</a> to set the associated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to queue anything anymore?

Copy link
Member Author

@hoch hoch Oct 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. statechange event for AudioWorkletNode is removed. So we don't have to do anything here. It was simply an oversight.

@hoch hoch requested a review from padenot October 10, 2018 16:14
Copy link
Member

@rtoy rtoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine except for one nit.

[=input AudioParam buffer=].

1. Else if {{[[callable process]]}} is `false`,
<a>Queue a control message</a> to fire `onprocessorerror` event on
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we specify the type of error that occurred?

Copy link
Member Author

@hoch hoch Oct 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be an Event on the main thread, so it is not an actual ErrorEvent. You can't throw an error on the main thread, because technically it is an error from the other side.

What we can do instead is to throw a TypeError in AWGS before queueing a message, but it will halt the entire AWGS and that's not what we want here.

I think we have now is sufficient.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was just basically wondering if we could provide some kind of info in the Event about what happened. This isn't required, but we know exactly why we're sending a message and it would be nice to let the user also know exactly why instead of just some random Event object.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but the Event object does not have a valid field to fill with the detailed error message. For the Event.type, you'll get processorerror.

Also defining a better error reporting for AWP should be a separate piece of work. I've been meaning to do that, but this becomes also useless when you have a proper error handling mechanism in WGS.

@hoch hoch merged commit f840c41 into WebAudio:master Oct 18, 2018
@hoch hoch deleted the 1767-awp-process-check branch March 10, 2021 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Question about when to check if user's class implements AudioWorkletProcessor
3 participants