diff --git a/src/renderers/dom/client/utils/DOMChildrenOperations.js b/src/renderers/dom/client/utils/DOMChildrenOperations.js index e71266c559..ce266352d7 100644 --- a/src/renderers/dom/client/utils/DOMChildrenOperations.js +++ b/src/renderers/dom/client/utils/DOMChildrenOperations.js @@ -9,8 +9,6 @@ * @providesModule DOMChildrenOperations */ -/* globals MSApp */ - 'use strict'; var DOMLazyTree = require('DOMLazyTree'); @@ -18,6 +16,7 @@ var Danger = require('Danger'); var ReactMultiChildUpdateTypes = require('ReactMultiChildUpdateTypes'); var ReactPerf = require('ReactPerf'); +var createMicrosoftUnsafeLocalFunction = require('createMicrosoftUnsafeLocalFunction'); var setInnerHTML = require('setInnerHTML'); var setTextContent = require('setTextContent'); @@ -33,19 +32,14 @@ function getNodeAfter(parentNode, node) { * @param {number} index Index at which to insert the child. * @internal */ -function insertChildAt(parentNode, childNode, referenceNode) { - // We rely exclusively on `insertBefore(node, null)` instead of also using - // `appendChild(node)`. (Using `undefined` is not allowed by all browsers so - // we are careful to use `null`.) - - if (typeof MSApp !== 'undefined' && MSApp.execUnsafeLocalFunction) { - MSApp.execUnsafeLocalFunction(function() { - parentNode.insertBefore(childNode, referenceNode); - }); - } else { +var insertChildAt = createMicrosoftUnsafeLocalFunction( + function(parentNode, childNode, referenceNode) { + // We rely exclusively on `insertBefore(node, null)` instead of also using + // `appendChild(node)`. (Using `undefined` is not allowed by all browsers so + // we are careful to use `null`.) parentNode.insertBefore(childNode, referenceNode); } -} +); function insertLazyTreeChildAt(parentNode, childTree, referenceNode) { DOMLazyTree.insertTreeBefore(parentNode, childTree, referenceNode); diff --git a/src/renderers/dom/client/utils/DOMLazyTree.js b/src/renderers/dom/client/utils/DOMLazyTree.js index 38b63b4415..28ae4b98ed 100644 --- a/src/renderers/dom/client/utils/DOMLazyTree.js +++ b/src/renderers/dom/client/utils/DOMLazyTree.js @@ -9,10 +9,9 @@ * @providesModule DOMLazyTree */ -/* globals MSApp */ - 'use strict'; +var createMicrosoftUnsafeLocalFunction = require('createMicrosoftUnsafeLocalFunction'); var setTextContent = require('setTextContent'); /** @@ -52,17 +51,12 @@ function insertTreeChildren(tree) { } } -function insertTreeBefore(parentNode, tree, referenceNode) { - if (typeof MSApp !== 'undefined' && MSApp.execUnsafeLocalFunction) { - MSApp.execUnsafeLocalFunction(function() { - parentNode.insertBefore(tree.node, referenceNode); - }); - } else { +var insertTreeBefore = createMicrosoftUnsafeLocalFunction( + function(parentNode, tree, referenceNode) { parentNode.insertBefore(tree.node, referenceNode); + insertTreeChildren(tree); } - - insertTreeChildren(tree); -} +); function replaceChildWithTree(oldNode, newTree) { oldNode.parentNode.replaceChild(newTree.node, oldNode); diff --git a/src/renderers/dom/client/utils/createMicrosoftUnsafeLocalFunction.js b/src/renderers/dom/client/utils/createMicrosoftUnsafeLocalFunction.js new file mode 100644 index 0000000000..834ad9849b --- /dev/null +++ b/src/renderers/dom/client/utils/createMicrosoftUnsafeLocalFunction.js @@ -0,0 +1,31 @@ +/** + * Copyright 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @providesModule createMicrosoftUnsafeLocalFunction + */ + +/* globals MSApp */ + +'use strict'; + +/** + * Create a function which has 'unsafe' privileges (required by windows8 apps) + */ +var createMicrosoftUnsafeLocalFunction = function(func) { + if (typeof MSApp !== 'undefined' && MSApp.execUnsafeLocalFunction) { + return function(arg0, arg1, arg2, arg3) { + MSApp.execUnsafeLocalFunction(function() { + return func(arg0, arg1, arg2, arg3); + }); + }; + } else { + return func; + } +}; + +module.exports = createMicrosoftUnsafeLocalFunction; diff --git a/src/renderers/dom/client/utils/setInnerHTML.js b/src/renderers/dom/client/utils/setInnerHTML.js index 15278d4474..222ddfbdce 100644 --- a/src/renderers/dom/client/utils/setInnerHTML.js +++ b/src/renderers/dom/client/utils/setInnerHTML.js @@ -9,8 +9,6 @@ * @providesModule setInnerHTML */ -/* globals MSApp */ - 'use strict'; var ExecutionEnvironment = require('ExecutionEnvironment'); @@ -18,6 +16,8 @@ var ExecutionEnvironment = require('ExecutionEnvironment'); var WHITESPACE_TEST = /^[ \r\n\t\f]/; var NONVISIBLE_TEST = /<(!--|link|noscript|meta|script|style)[ \r\n\t\f\/>]/; +var createMicrosoftUnsafeLocalFunction = require('createMicrosoftUnsafeLocalFunction'); + /** * Set the innerHTML property of a node, ensuring that whitespace is preserved * even in IE8. @@ -26,18 +26,11 @@ var NONVISIBLE_TEST = /<(!--|link|noscript|meta|script|style)[ \r\n\t\f\/>]/; * @param {string} html * @internal */ -var setInnerHTML = function(node, html) { - node.innerHTML = html; -}; - -// Win8 apps: Allow all html to be inserted -if (typeof MSApp !== 'undefined' && MSApp.execUnsafeLocalFunction) { - setInnerHTML = function(node, html) { - MSApp.execUnsafeLocalFunction(function() { - node.innerHTML = html; - }); - }; -} +var setInnerHTML = createMicrosoftUnsafeLocalFunction( + function(node, html) { + node.innerHTML = html; + } +); if (ExecutionEnvironment.canUseDOM) { // IE8: When updating a just created node with innerHTML only leading