JSDevSupportModule.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. * @flow strict-local
  9. */
  10. 'use strict';
  11. import NativeJSDevSupport from './NativeJSDevSupport';
  12. const ReactNative = require('../Renderer/shims/ReactNative');
  13. const JSDevSupportModule = {
  14. getJSHierarchy: function(tag: number) {
  15. if (NativeJSDevSupport) {
  16. const constants = NativeJSDevSupport.getConstants();
  17. try {
  18. const {
  19. computeComponentStackForErrorReporting,
  20. } = ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
  21. const componentStack = computeComponentStackForErrorReporting(tag);
  22. if (!componentStack) {
  23. NativeJSDevSupport.onFailure(
  24. constants.ERROR_CODE_VIEW_NOT_FOUND,
  25. "Component stack doesn't exist for tag " + tag,
  26. );
  27. } else {
  28. NativeJSDevSupport.onSuccess(componentStack);
  29. }
  30. } catch (e) {
  31. NativeJSDevSupport.onFailure(constants.ERROR_CODE_EXCEPTION, e.message);
  32. }
  33. }
  34. },
  35. };
  36. module.exports = JSDevSupportModule;