areconnectedThroughProperties.js 889 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /**
  6. * @module watchdog/utils/areconnectedthroughproperties
  7. */
  8. import getSubNodes from './getsubnodes';
  9. /**
  10. * Traverses both structures to find out whether there is a reference that is shared between both structures.
  11. *
  12. * @param {Object|Array} obj1
  13. * @param {Object|Array} obj2
  14. */
  15. export default function areConnectedThroughProperties( obj1, obj2 ) {
  16. if ( obj1 === obj2 && isObject( obj1 ) ) {
  17. return true;
  18. }
  19. const subNodes1 = getSubNodes( obj1 );
  20. const subNodes2 = getSubNodes( obj2 );
  21. for ( const node of subNodes1 ) {
  22. if ( subNodes2.has( node ) ) {
  23. return true;
  24. }
  25. }
  26. return false;
  27. }
  28. function isObject( structure ) {
  29. return typeof structure === 'object' && structure !== null;
  30. }