Skip to content

Commit e1dc260

Browse files
ExE-BossTimothyGu
andcommitted
Improve constructor error messages
Co-authored-by: Timothy Gu <timothygu99@gmail.com>
1 parent 4a72a78 commit e1dc260

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

index.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22
const webidlWrapper = require('./webidl2js-wrapper.js');
3-
const webidlConversions = require('webidl-conversions');
43

54
const sharedGlobalObject = {};
65
webidlWrapper.install(sharedGlobalObject);
@@ -14,13 +13,11 @@ const origCSSStyleDeclaration = sharedGlobalObject.CSSStyleDeclaration;
1413
*/
1514
function CSSStyleDeclaration(onChangeCallback = null) {
1615
if (new.target === undefined) {
17-
throw new TypeError('Illegal invocation');
16+
throw new TypeError("Class constructor CSSStyleDeclaration cannot be invoked without 'new'");
1817
}
1918

20-
if (onChangeCallback !== null) {
21-
onChangeCallback = webidlConversions.Function(onChangeCallback, {
22-
context: 'Failed to constructor CSSStyleDeclaration: parameter 1',
23-
});
19+
if (onChangeCallback !== null && typeof onChangeCallback !== 'function') {
20+
throw new TypeError('Failed to constructor CSSStyleDeclaration: parameter 1 is not a function');
2421
}
2522

2623
return webidlWrapper.create(sharedGlobalObject, undefined, { onChangeCallback });

0 commit comments

Comments
 (0)