Skip to content

url: check forEach callback is a function

Currently, URLSearchParams' forEach function does not have a check to make sure that the type of the provided callback is a function. However, the Web IDL spec, to which this function should conform, insists that a TypeError be thrown if the callback is not callable.

This PR fulfills that requirement. Also included in this PR are additional tests for certain aspects of forEach that are defined in the spec but not yet tested.


Web IDL defines forEach as the following:

void forEach(Function callback, optional any thisArg);

callback therefore has type Function, which in turn is defined as a callback function:

callback Function = any (any... arguments);

The process to convert an ECMAScript value to an IDL callback function then contains the following:

  1. If the result of calling IsCallable(V) is false and the conversion to an IDL value is not being performed due to V being assigned to an attribute whose type is a nullable callback function that is annotated with [TreatNonObjectAsNull], then throw a TypeError.

And since callback is not declared with [TreatNonObjectAsNull], forEach should throw a TypeError in case callback is not a function.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

url

Merge request reports

Loading