Skip to content

Commit

Permalink
fix `We need to use the instanceToString function from dom utils inst…
Browse files Browse the repository at this point in the history
…ead of toString function` (close #1055) (#1056)
  • Loading branch information
LavrovArtem authored and churkin committed Mar 2, 2017
1 parent e337ca5 commit 878e07c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/client/utils/dom.js
Expand Up @@ -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);

Expand Down
21 changes: 8 additions & 13 deletions src/client/utils/style.js
Expand Up @@ -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 || '';

Expand All @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions test/client/fixtures/utils/style-test.js
Expand Up @@ -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'));
}
}));
});

0 comments on commit 878e07c

Please sign in to comment.