From 56317fb95213bcff146d824ab98d2676570da8d3 Mon Sep 17 00:00:00 2001 From: John Messerly Date: Wed, 28 Jan 2015 08:38:55 -0800 Subject: [PATCH] install createShadowRoot only if present, fixes #174 --- src/CustomElements/observe.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/CustomElements/observe.js b/src/CustomElements/observe.js index 23c3146..6a3f3b2 100644 --- a/src/CustomElements/observe.js +++ b/src/CustomElements/observe.js @@ -289,13 +289,17 @@ function upgradeDocumentTree(doc) { } -// ensure that all ShadowRoots watch for CustomElements. +// Patch `createShadowRoot()` if Shadow DOM is available, otherwise leave +// undefined to aid feature detection of Shadow DOM. var originalCreateShadowRoot = Element.prototype.createShadowRoot; -Element.prototype.createShadowRoot = function() { - var root = originalCreateShadowRoot.call(this); - CustomElements.watchShadow(this); - return root; -}; +if (originalCreateShadowRoot) { + // ensure that all ShadowRoots watch for CustomElements. + Element.prototype.createShadowRoot = function() { + var root = originalCreateShadowRoot.call(this); + CustomElements.watchShadow(this); + return root; + }; +} // exports scope.watchShadow = watchShadow;