Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Testing constructors with no arguments misses some ways of disabling constructors #970

Closed
foolip opened this issue Feb 15, 2021 · 1 comment
Labels
Component: Custom Anything related to the custom tests, IDL, or other injections Priority 3 (Medium) Medium priority, should be done but can wait

Comments

@foolip
Copy link
Owner

foolip commented Feb 15, 2021

mdn/browser-compat-data#7923 revealed that there's a problem with our generated tests for the Notification constructor, which testing new Notification('hello') (and expecting that to work) would have avoided.

The problem is that we're probing for error messages thrown by generated bindings for anything that has a Web IDL constructor, but it's also possible to disable constructors by throwing exceptions from non-generated code.

We could add "Illegal constructor" to the list of strings that we check for, but the general problem can only be solved by invoking the constructor in a way that should work, and only treating it as supported if it does. Unfortunately this would be a lot of work...

@foolip
Copy link
Owner Author

foolip commented Feb 15, 2021

Here's the code:

function testConstructor(iface) {
var result = {};
try {
eval('new '+iface+'()');
result.result = true;
} catch (err) {
if (
stringIncludes(err.message, 'Illegal constructor') ||
stringIncludes(err.message, 'is not a constructor') ||
stringIncludes(err.message, 'Function expected')
) {
result.result = false;
} else if (
stringIncludes(err.message, 'Not enough arguments') ||
stringIncludes(err.message, 'argument required') ||
stringIncludes(err.message, 'arguments required') ||
stringIncludes(err.message, 'Argument not optional') ||
stringIncludes(err.message, 'Arguments can\'t be empty') ||
stringIncludes(err.message, 'undefined is not an object')
) {
// If it failed to construct and it's not illegal or just needs
// more arguments, the constructor's good
result.result = true;
} else {
result.result = null;
}
result.message = 'threw ' + stringify(err);
}
return result;
}

We already check for "Illegal constructor" but that doesn't help if we invoke the constructor with too few arguments.

@queengooborg queengooborg added Component: Custom Anything related to the custom tests, IDL, or other injections Priority 3 (Medium) Medium priority, should be done but can wait labels Sep 19, 2021
jugglinmike added a commit to bocoup/browser-compat-data that referenced this issue Sep 28, 2022
The mdn-bcd-collector tool has a deficiency which cause it to produce
incorrect changes for the Notification constructor. See "Testing
constructors with no arguments misses some ways of disabling
constructors": foolip/mdn-bcd-collector#970
jugglinmike added a commit to bocoup/browser-compat-data that referenced this issue Dec 2, 2022
The mdn-bcd-collector tool has a deficiency which cause it to produce
incorrect changes for the Notification constructor. See "Testing
constructors with no arguments misses some ways of disabling
constructors": foolip/mdn-bcd-collector#970
@foolip foolip closed this as completed Sep 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Component: Custom Anything related to the custom tests, IDL, or other injections Priority 3 (Medium) Medium priority, should be done but can wait
Projects
None yet
Development

No branches or pull requests

2 participants