Skip to content

Commit

Permalink
fix: rewrite JS exception classes from polyfill to correct DOMExcepti…
Browse files Browse the repository at this point in the history
…on in attachShadow polyfill (fixes #46)
  • Loading branch information
martok committed Oct 3, 2022
1 parent 9d550f0 commit 5c717d9
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions lib/polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,24 +405,22 @@ exports.Element_attachShadow = jss`
}
rel.call(target, type, listener, options);
}
function sanityChecks(a, name, cls) {
const namDef = a.a.get(name),
clsDef = a.g.get(cls);
console.dir({
_name: name,
_cls: cls,
regName: namDef,
regCls: clsDef,
sameConstrName: (namDef?namDef.constructorFunction==cls:undefined),
sameConstrClass: (clsDef?clsDef.constructorFunction==cls:undefined),
});
}
customElements.define = function (name, cls) {
asNames.add(name);
sanityChecks(customElements.a, name, cls);
cls.prototype.addEventListener = addCEEventListener;
cls.prototype.removeEventListener = removeCEEventListener;
oldCED.call(customElements, name, cls);
try {
return oldCED.call(customElements, name, cls);
} catch(c) {
// rewrite JS exception classes from polyfill to correct DOMException
if (c instanceof SyntaxError) {
throw new DOMException(c.message, "SyntaxError");
} else
if (c instanceof Error && c.name==="Error") {
throw new DOMException(c.message, "NotSupportedError");
} else
throw c;
}
};
}
}())`;
Expand Down

0 comments on commit 5c717d9

Please sign in to comment.