TINY-8414: Fixed SandHTMLElement.isPrototypeOf throwing an illegal invocation error for HTMLAnchorElement

This commit is contained in:
Lee Newson
2022-01-20 17:35:23 +10:00
committed by Lee Newson
parent 587094ecea
commit 3db0ff5f59
3 changed files with 9 additions and 1 deletions

View File

@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- The `isOSX` API has been renamed to `isMacOS` #TINY-8175
- The `isChrome` API has been renamed to `isChromium` to better reflect its functionality #TINY-8300
### Fixed
- The `SandHTMLElement.isPrototypeOf` API would throw an illegal invocation error on Chromium based browsers #TINY-8414
## 5.0.0 - 2021-08-26
### Improved

View File

@ -21,7 +21,7 @@ const isPrototypeOf = (x: any): x is HTMLElement => {
// TINY-7374: We can't rely on looking at the owner window HTMLElement as the element may have
// been constructed in a different window and then appended to the current window document.
return Type.isObject(x) && (sandHTMLElement(scope).prototype.isPrototypeOf(x) || /^\[object HTML\w*Element\]$/.test(getPrototypeOf(x).toString()));
return Type.isObject(x) && (sandHTMLElement(scope).prototype.isPrototypeOf(x) || /^HTML\w*Element$/.test(getPrototypeOf(x).constructor.name));
};
export {

View File

@ -28,11 +28,14 @@ describe('HtmlElementTest', () => {
it('same window elements should be true', () => {
const div = document.createElement('div');
const a = document.createElement('a');
assert.isTrue(SandHTMLElement.isPrototypeOf(div));
assert.isTrue(SandHTMLElement.isPrototypeOf(a));
});
it('TINY-7374: different window elements should be true', () => {
const span = document.createElement('span'); // HTMLSpanElement
const a = document.createElement('a'); // HTMLAnchorElement
const strong = document.createElement('strong'); // HTMLElement
const iframe = document.createElement('iframe');
document.body.appendChild(iframe);
@ -43,8 +46,10 @@ describe('HtmlElementTest', () => {
iframeDoc.close();
iframeDoc.body.appendChild(span);
iframeDoc.body.appendChild(a);
iframeDoc.body.appendChild(strong);
assert.isTrue(SandHTMLElement.isPrototypeOf(span));
assert.isTrue(SandHTMLElement.isPrototypeOf(a));
assert.isTrue(SandHTMLElement.isPrototypeOf(strong));
document.body.removeChild(iframe);