|
| 1 | +using Newtonsoft.Json.Linq; |
| 2 | +using ReactNative.Bridge; |
| 3 | +using System.Collections.Generic; |
| 4 | + |
| 5 | +namespace ReactNative.Modules.Core |
| 6 | +{ |
| 7 | + /// <summary> |
| 8 | + /// Module that exposes the URL to the source code map (used for exception |
| 9 | + /// stack trace parsing) to JavaScript. |
| 10 | + /// </summary> |
| 11 | + class SourceCodeModule : NativeModuleBase |
| 12 | + { |
| 13 | + private readonly string _sourceMapUrl; |
| 14 | + private readonly string _sourceUrl; |
| 15 | + |
| 16 | + /// <summary> |
| 17 | + /// Instantiates the <see cref="SourceCodeModule"/>. |
| 18 | + /// </summary> |
| 19 | + /// <param name="sourceUrl">The source URL.</param> |
| 20 | + /// <param name="sourceMapUrl">The source map URL.</param> |
| 21 | + public SourceCodeModule(string sourceUrl, string sourceMapUrl) |
| 22 | + { |
| 23 | + _sourceMapUrl = sourceMapUrl; |
| 24 | + _sourceUrl = sourceUrl; |
| 25 | + } |
| 26 | + |
| 27 | + /// <summary> |
| 28 | + /// The name of the module. |
| 29 | + /// </summary> |
| 30 | + public override string Name |
| 31 | + { |
| 32 | + get |
| 33 | + { |
| 34 | + return "RCTSourceCode"; |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + /// <summary> |
| 39 | + /// The module constants. |
| 40 | + /// </summary> |
| 41 | + public override IReadOnlyDictionary<string, object> Constants |
| 42 | + { |
| 43 | + get |
| 44 | + { |
| 45 | + return new Dictionary<string, object> |
| 46 | + { |
| 47 | + { "scriptURL", _sourceUrl }, |
| 48 | + }; |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + /// <summary> |
| 53 | + /// Gets the script mapping URL. |
| 54 | + /// </summary> |
| 55 | + /// <param name="promise">The promise.</param> |
| 56 | + [ReactMethod] |
| 57 | + public void getScriptText(IPromise promise) |
| 58 | + { |
| 59 | + var map = new JObject |
| 60 | + { |
| 61 | + { "fullSourceMappingURL", _sourceMapUrl }, |
| 62 | + }; |
| 63 | + |
| 64 | + promise.Resolve(map); |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments