|
16 | 16 | // limitations under the License. |
17 | 17 | // </copyright> |
18 | 18 |
|
19 | | -using System; |
20 | 19 | using System.Globalization; |
21 | 20 |
|
| 21 | +#nullable enable |
| 22 | + |
22 | 23 | namespace OpenQA.Selenium |
23 | 24 | { |
24 | 25 | /// <summary> |
25 | 26 | /// A class representing a pinned JavaScript function that can be repeatedly called |
26 | 27 | /// without sending the entire script across the wire for every execution. |
27 | 28 | /// </summary> |
28 | | - public class PinnedScript |
| 29 | + public sealed class PinnedScript |
29 | 30 | { |
30 | | - private string scriptSource; |
31 | | - private string scriptHandle; |
32 | | - private string scriptId; |
33 | | - |
34 | 31 | /// <summary> |
35 | 32 | /// Initializes a new instance of the <see cref="PinnedScript"/> class. |
36 | 33 | /// </summary> |
37 | 34 | /// <param name="script">The body of the JavaScript function to pin.</param> |
| 35 | + /// <param name="stringHandle">The unique handle for this pinned script.</param> |
| 36 | + /// <param name="scriptId">The internal ID of this script.</param> |
38 | 37 | /// <remarks> |
39 | 38 | /// This constructor is explicitly internal. Creation of pinned script objects |
40 | 39 | /// is strictly the perview of Selenium, and should not be required by external |
41 | 40 | /// libraries. |
42 | 41 | /// </remarks> |
43 | | - internal PinnedScript(string script) |
| 42 | + internal PinnedScript(string script, string stringHandle, string scriptId) |
44 | 43 | { |
45 | | - this.scriptSource = script; |
46 | | - this.scriptHandle = Guid.NewGuid().ToString("N"); |
| 44 | + this.Source = script; |
| 45 | + this.Handle = stringHandle; |
| 46 | + this.ScriptId = scriptId; |
47 | 47 | } |
48 | 48 |
|
49 | 49 | /// <summary> |
50 | 50 | /// Gets the unique handle for this pinned script. |
51 | 51 | /// </summary> |
52 | | - public string Handle |
53 | | - { |
54 | | - get { return this.scriptHandle; } |
55 | | - } |
| 52 | + public string Handle { get; } |
56 | 53 |
|
57 | 54 | /// <summary> |
58 | 55 | /// Gets the source representing the body of the function in the pinned script. |
59 | 56 | /// </summary> |
60 | | - public string Source |
61 | | - { |
62 | | - get { return this.scriptSource; } |
63 | | - } |
| 57 | + public string Source { get; } |
64 | 58 |
|
65 | | - /// <summary> |
66 | | - /// Gets the script to create the pinned script in the browser. |
67 | | - /// </summary> |
68 | | - internal string CreationScript |
| 59 | + internal static string MakeCreationScript(string scriptHandle, string scriptSource) |
69 | 60 | { |
70 | | - get { return string.Format(CultureInfo.InvariantCulture, "function __webdriver_{0}(arguments) {{ {1} }}", this.scriptHandle, this.scriptSource); } |
| 61 | + return string.Format(CultureInfo.InvariantCulture, "function __webdriver_{0}(arguments) {{ {1} }}", scriptHandle, scriptSource); |
71 | 62 | } |
72 | 63 |
|
73 | 64 | /// <summary> |
74 | 65 | /// Gets the script used to execute the pinned script in the browser. |
75 | 66 | /// </summary> |
76 | | - internal string ExecutionScript |
| 67 | + internal string MakeExecutionScript() |
77 | 68 | { |
78 | | - get { return string.Format(CultureInfo.InvariantCulture, "return __webdriver_{0}(arguments)", this.scriptHandle); } |
| 69 | + return string.Format(CultureInfo.InvariantCulture, "return __webdriver_{0}(arguments)", this.Handle); |
79 | 70 | } |
80 | 71 |
|
81 | 72 | /// <summary> |
82 | 73 | /// Gets the script used to remove the pinned script from the browser. |
83 | 74 | /// </summary> |
84 | | - internal string RemovalScript |
| 75 | + internal string MakeRemovalScript() |
85 | 76 | { |
86 | | - get { return string.Format(CultureInfo.InvariantCulture, "__webdriver_{0} = undefined", this.scriptHandle); } |
| 77 | + return string.Format(CultureInfo.InvariantCulture, "__webdriver_{0} = undefined", this.Handle); |
87 | 78 | } |
88 | 79 |
|
89 | 80 | /// <summary> |
90 | 81 | /// Gets or sets the ID of this script. |
91 | 82 | /// </summary> |
92 | | - internal string ScriptId |
93 | | - { |
94 | | - get { return this.scriptId; } |
95 | | - set { this.scriptId = value; } |
96 | | - } |
| 83 | + internal string ScriptId { get; set; } |
97 | 84 | } |
98 | 85 | } |
0 commit comments