jenkins-bot has submitted this change and it was merged.

Change subject: Convert DOM elements to stringifiable objects for reporting
......................................................................


Convert DOM elements to stringifiable objects for reporting

We already do this in unit test so moving getDomElementSummary
and convertDomElements from ve.qunit.js to ve.js.

Apply ve.convertDomElements to report data before serialising.

Bug: 47948
Change-Id: Id807ccc6ff31d063be815ed4988cb35684adb76a
---
M modules/ve/init/mw/ve.init.mw.Target.js
M modules/ve/test/ve.qunit.js
M modules/ve/ve.js
3 files changed, 59 insertions(+), 58 deletions(-)

Approvals:
  Krinkle: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/ve/init/mw/ve.init.mw.Target.js 
b/modules/ve/init/mw/ve.init.mw.Target.js
index 5cbc8f3..81fbedc 100644
--- a/modules/ve/init/mw/ve.init.mw.Target.js
+++ b/modules/ve/init/mw/ve.init.mw.Target.js
@@ -607,7 +607,7 @@
                };
        $.post(
                mw.config.get( 'wgVisualEditorConfig' ).reportProblemURL,
-               { 'data': JSON.stringify( report ) },
+               { 'data': JSON.stringify( ve.copyObject( report, 
ve.convertDomElements ) ) },
                function () {
                        // This space intentionally left blank
                },
diff --git a/modules/ve/test/ve.qunit.js b/modules/ve/test/ve.qunit.js
index e50b3c2..aacba38 100644
--- a/modules/ve/test/ve.qunit.js
+++ b/modules/ve/test/ve.qunit.js
@@ -84,59 +84,6 @@
 }
 
 /**
- * Builds a summary of an HTML element.
- *
- * Summaries include node name, text, attributes and recursive summaries of 
children.
- *
- * @method
- * @private
- * @param {HTMLElement} element Element to summarize
- * @returns {Object} Summary of element.
- */
-function getDomElementSummary( element ) {
-       var i,
-               $element = $( element ),
-               summary = {
-                       'type': element.nodeName.toLowerCase(),
-                       'text': $element.text(),
-                       'attributes': {},
-                       'children': []
-               };
-
-       // Gather attributes
-       if ( element.attributes ) {
-               for ( i = 0; i < element.attributes.length; i++ ) {
-                       summary.attributes[element.attributes[i].name] = 
element.attributes[i].value;
-               }
-       }
-       // Summarize children
-       if ( element.childNodes ) {
-               for ( i = 0; i < element.childNodes.length; i++ ) {
-                       if ( element.childNodes[i].nodeType !== Node.TEXT_NODE 
) {
-                               summary.children.push( getDomElementSummary( 
element.childNodes[i] ) );
-                       }
-               }
-       }
-       return summary;
-}
-
-/**
- * Callback for ve.copyArray/Object to convert nodes to a comparable summary
- *
- * @method
- * @private
- * @param {Object} value Value in the object/array
- * @returns {Object} DOM element summary if value is a node, otherwise just 
the value
- */
-function convertDomElements( value ) {
-       // Use duck typing rather than instanceof Node; the latter doesn't 
always work correctly
-       if ( value && value.nodeType ) {
-               return getDomElementSummary( value );
-       }
-       return value;
-}
-
-/**
  * Assertion helpers for VisualEditor test suite.
  * @class ve.QUnit.assert
  */
@@ -185,8 +132,8 @@
  * @static
  */
 QUnit.assert.equalDomElement = function ( actual, expected, message ) {
-       var actualSummary = getDomElementSummary( actual ),
-               expectedSummary = getDomElementSummary( expected );
+       var actualSummary = ve.getDomElementSummary( actual ),
+               expectedSummary = ve.getDomElementSummary( expected );
 
        QUnit.push(
                QUnit.equiv( actualSummary, expectedSummary ), actualSummary, 
expectedSummary, message
@@ -200,8 +147,8 @@
  */
 QUnit.assert.deepEqualWithDomElements = function ( actual, expected, message ) 
{
        // Recursively copy objects or arrays, converting any dom elements 
found to comparable summaries
-       actual = ve.isArray( actual ) ? ve.copyArray( actual, 
convertDomElements ) : ve.copyObject( actual, convertDomElements );
-       expected = ve.isArray( expected ) ? ve.copyArray( expected, 
convertDomElements ) : ve.copyObject( expected, convertDomElements );
+       actual = ve.isArray( actual ) ? ve.copyArray( actual, 
ve.convertDomElements ) : ve.copyObject( actual, ve.convertDomElements );
+       expected = ve.isArray( expected ) ? ve.copyArray( expected, 
ve.convertDomElements ) : ve.copyObject( expected, ve.convertDomElements );
 
        QUnit.push( QUnit.equiv(actual, expected), actual, expected, message );
 };
diff --git a/modules/ve/ve.js b/modules/ve/ve.js
index 9d33b64..d8783c3 100644
--- a/modules/ve/ve.js
+++ b/modules/ve/ve.js
@@ -925,6 +925,60 @@
        };
 
        /**
+        * Builds a summary of an HTML element.
+        *
+        * Summaries include node name, text, attributes and recursive 
summaries of children.
+        * Used for serializing or comparing HTML elements.
+        *
+        * @method
+        * @private
+        * @param {HTMLElement} element Element to summarize
+        * @returns {Object} Summary of element.
+        */
+       ve.getDomElementSummary = function ( element ) {
+               var i,
+                       $element = $( element ),
+                       summary = {
+                               'type': element.nodeName.toLowerCase(),
+                               'text': $element.text(),
+                               'attributes': {},
+                               'children': []
+                       };
+
+               // Gather attributes
+               if ( element.attributes ) {
+                       for ( i = 0; i < element.attributes.length; i++ ) {
+                               summary.attributes[element.attributes[i].name] 
= element.attributes[i].value;
+                       }
+               }
+               // Summarize children
+               if ( element.childNodes ) {
+                       for ( i = 0; i < element.childNodes.length; i++ ) {
+                               if ( element.childNodes[i].nodeType !== 
Node.TEXT_NODE ) {
+                                       summary.children.push( 
ve.getDomElementSummary( element.childNodes[i] ) );
+                               }
+                       }
+               }
+               return summary;
+       };
+
+       /**
+        * Callback for ve.copyArray/Object to convert nodes to a comparable 
summary
+        *
+        * @method
+        * @private
+        * @param {Object} value Value in the object/array
+        * @returns {Object} DOM element summary if value is a node, otherwise 
just the value
+        */
+       ve.convertDomElements = function ( value ) {
+               // Use duck typing rather than instanceof Node; the latter 
doesn't always work correctly
+               if ( value && value.nodeType ) {
+                       return ve.getDomElementSummary( value );
+               }
+               return value;
+       };
+
+       /**
         * Check whether a given DOM element is of a block or inline type
         * @param {HTMLElement} element
         * @returns {boolean} True if element is block, false if it is inline

-- 
To view, visit https://gerrit.wikimedia.org/r/62811
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Id807ccc6ff31d063be815ed4988cb35684adb76a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to