diff --git a/src/client/utils/dom.js b/src/client/utils/dom.js index 550a79117..9601d3a7e 100644 --- a/src/client/utils/dom.js +++ b/src/client/utils/dom.js @@ -96,7 +96,7 @@ function hasClassFallback (el, className) { return preparedElementClassName.indexOf(className) !== -1; } -function instanceToString (instance) { +export function instanceToString (instance) { if (!instanceAndPrototypeToStringAreEqual) return nativeMethods.objectToString.call(instance); diff --git a/src/client/utils/style.js b/src/client/utils/style.js index 645e89b1d..c666289ec 100644 --- a/src/client/utils/style.js +++ b/src/client/utils/style.js @@ -5,6 +5,12 @@ import nativeMethods from '../sandbox/native-methods'; // NOTE: For Chrome. const MIN_SELECT_SIZE_VALUE = 4; +const NATIVE_STYLE_STRINGS = [ + '[object CSSStyleDeclaration]', + '[object CSS2Properties]', + '[object MSStyleCSSProperties]' +]; + function getIntValue (value) { value = value || ''; @@ -17,25 +23,14 @@ export function isStyle (instance) { if (instance instanceof nativeMethods.styleClass) return true; - if (instance && typeof instance === 'object' && instance.border !== void 0 && - typeof instance.toString === 'function') { - instance = instance.toString(); - - return instance === '[object CSSStyleDeclaration]' || instance === '[object CSS2Properties]' || - instance === '[object MSStyleCSSProperties]'; - } - - return false; + return NATIVE_STYLE_STRINGS.indexOf(domUtils.instanceToString(instance)) !== -1; } export function isStyleSheet (instance) { if (instance instanceof nativeMethods.styleSheetClass) return true; - if (instance && typeof instance === 'object' && typeof instance.toString === 'function') - return instance.toString() === '[object CSSStyleSheet]'; - - return false; + return domUtils.instanceToString(instance) === '[object CSSStyleSheet]'; } export function get (el, property, doc) { diff --git a/test/client/fixtures/utils/style-test.js b/test/client/fixtures/utils/style-test.js index fc0adcbec..451a51b6b 100644 --- a/test/client/fixtures/utils/style-test.js +++ b/test/client/fixtures/utils/style-test.js @@ -237,3 +237,11 @@ module('regression'); test('isStyle throws an error for objects without the toString method (GH-561)', function () { ok(!styleUtils.isStyle({ border: 0, toString: void 0 })); }); + +test('isStyleSheet function should not throw the "Maximum call stack size exceeded" error for objects with the overridden toString method (GH-1055)', function () { + ok(!styleUtils.isStyleSheet({ + toString: function () { + return eval(processScript('this.href')); + } + })); +});