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