Skip to content

Commit 10d761d

Browse files
committed
Partial fix fro the issue #17
* References to host objects need to be extracted from the global object associated with provided element
1 parent 733984e commit 10d761d

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

src/ResizeObserverSPI.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Map} from './shims/es6-collections.js';
22
import ResizeObservation from './ResizeObservation.js';
33
import ResizeObserverEntry from './ResizeObserverEntry.js';
4+
import getWindowOf from './utils/getWindowOf.js';
45

56
export default class ResizeObserverSPI {
67
/**
@@ -76,7 +77,7 @@ export default class ResizeObserverSPI {
7677
return;
7778
}
7879

79-
if (!(target instanceof Element)) {
80+
if (!(target instanceof getWindowOf(target).Element)) {
8081
throw new TypeError('parameter 1 is not of type "Element".');
8182
}
8283

@@ -111,7 +112,7 @@ export default class ResizeObserverSPI {
111112
return;
112113
}
113114

114-
if (!(target instanceof Element)) {
115+
if (!(target instanceof getWindowOf(target).Element)) {
115116
throw new TypeError('parameter 1 is not of type "Element".');
116117
}
117118

src/utils/geometry.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import defineConfigurable from './defineConfigurable.js';
2+
import getWindowOf from './getWindowOf.js';
23
import isBrowser from './isBrowser.js';
34

45
// Placeholder of an empty content rectangle.
@@ -84,7 +85,7 @@ function getHTMLElementContentRect(target) {
8485
return emptyRect;
8586
}
8687

87-
const styles = getComputedStyle(target);
88+
const styles = getWindowOf(target).getComputedStyle(target);
8889
const paddings = getPaddings(styles);
8990
const horizPad = paddings.left + paddings.right;
9091
const vertPad = paddings.top + paddings.bottom;
@@ -152,15 +153,15 @@ function getHTMLElementContentRect(target) {
152153
const isSVGGraphicsElement = (() => {
153154
// Some browsers, namely IE and Edge, don't have the SVGGraphicsElement
154155
// interface.
155-
if (typeof SVGGraphicsElement != 'undefined') {
156-
return target => target instanceof SVGGraphicsElement;
156+
if (typeof SVGGraphicsElement !== 'undefined') {
157+
return target => target instanceof getWindowOf(target).SVGGraphicsElement;
157158
}
158159

159160
// If it's so, then check that element is at least an instance of the
160161
// SVGElement and that it has the "getBBox" method.
161162
// eslint-disable-next-line no-extra-parens
162163
return target => (
163-
target instanceof SVGElement &&
164+
target instanceof getWindowOf(target).SVGElement &&
164165
typeof target.getBBox === 'function'
165166
);
166167
})();
@@ -172,7 +173,7 @@ const isSVGGraphicsElement = (() => {
172173
* @returns {boolean}
173174
*/
174175
function isDocumentElement(target) {
175-
return target === document.documentElement;
176+
return target === getWindowOf(target).document.documentElement;
176177
}
177178

178179
/**
@@ -202,7 +203,7 @@ export function getContentRect(target) {
202203
*/
203204
export function createReadOnlyRect({x, y, width, height}) {
204205
// If DOMRectReadOnly is available use it as a prototype for the rectangle.
205-
const Constr = typeof DOMRectReadOnly != 'undefined' ? DOMRectReadOnly : Object;
206+
const Constr = typeof DOMRectReadOnly !== 'undefined' ? DOMRectReadOnly : Object;
206207
const rect = Object.create(Constr.prototype);
207208

208209
// Rectangle's properties are not writable and non-enumerable.

src/utils/getWindowOf.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import global from '../shims/global.js';
2+
3+
/**
4+
* Returns the global object associated with provided element.
5+
*
6+
* @param {Object} target
7+
* @returns {Object}
8+
*/
9+
export default target => {
10+
// Assume that the element is an instance of Node, which means that it
11+
// has the "ownerDocument" property from which we can retrieve a
12+
// corresponding global object.
13+
const ownerGlobal = target && target.ownerDocument && target.ownerDocument.defaultView;
14+
15+
// Return the local global object if it's not possible extract one from
16+
// provided element.
17+
return ownerGlobal || global;
18+
};

0 commit comments

Comments
 (0)