Fix recursion for safari 10 on pseudoelements

This commit is contained in:
Niklas von Hertzen 2017-08-13 21:39:57 +08:00
parent a101b52685
commit ea080e0f5d
3 changed files with 13 additions and 8 deletions

View File

@ -4,8 +4,7 @@
import type {Font} from './parsing/font';
const SAMPLE_TEXT = 'Hidden Text';
const SMALL_IMAGE =
'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
import {SMALL_IMAGE} from './Util';
export class FontMetrics {
_data: {};

View File

@ -46,6 +46,10 @@ const parseNodeTree = (
imageLoader: ImageLoader,
index: number
): void => {
if (__DEV__ && index > 50000) {
throw new Error(`Recursion error while parsing node tree`);
}
for (let childNode = node.firstChild, nextNode; childNode; childNode = nextNode) {
nextNode = childNode.nextSibling;
const defaultView = childNode.ownerDocument.defaultView;

View File

@ -4,13 +4,15 @@
export const contains = (bit: number, value: number): boolean => (bit & value) !== 0;
export const copyCSSStyles = (style: CSSStyleDeclaration, target: HTMLElement): void => {
if (style.cssText) {
target.style.cssText = style.cssText;
} else {
// Edge does not provide value for cssText
for (let i = style.length - 1; i >= 0; i--) {
const property = style.item(i);
// Edge does not provide value for cssText
for (let i = style.length - 1; i >= 0; i--) {
const property = style.item(i);
// Safari shows pseudoelements if content is set
if (property !== 'content') {
target.style.setProperty(property, style.getPropertyValue(property));
}
}
};
export const SMALL_IMAGE =
'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';