public override IPrecompiledScript PrecompileResource(string resourceName, Assembly assembly)
        {
            VerifyNotDisposed();

            if (resourceName == null)
            {
                throw new ArgumentNullException(
                          nameof(resourceName),
                          string.Format(CoreStrings.Common_ArgumentIsNull, nameof(resourceName))
                          );
            }

            if (assembly == null)
            {
                throw new ArgumentNullException(
                          nameof(assembly),
                          string.Format(CoreStrings.Common_ArgumentIsNull, nameof(assembly))
                          );
            }

            if (string.IsNullOrWhiteSpace(resourceName))
            {
                throw new ArgumentException(
                          string.Format(CoreStrings.Common_ArgumentIsEmpty, nameof(resourceName)),
                          nameof(resourceName)
                          );
            }

            if (!ValidationHelpers.CheckDocumentNameFormat(resourceName))
            {
                throw new ArgumentException(
                          string.Format(CoreStrings.Usage_InvalidResourceNameFormat, resourceName),
                          nameof(resourceName)
                          );
            }

            OriginalCompiledScript compiledScript;
            string uniqueDocumentName = _documentNameManager.GetUniqueName(resourceName);

            lock (_executionSynchronizer)
            {
                try
                {
                    var source = new ResourceScriptSource(uniqueDocumentName, resourceName, assembly);
                    compiledScript = OriginalCompiledScript.Compile(source);
                }
                catch (OriginalSyntaxException e)
                {
                    throw WrapSyntaxException(e);
                }
                catch (NullReferenceException)
                {
                    throw;
                }
            }

            return(new JurassicPrecompiledScript(compiledScript));
        }
        public override IPrecompiledScript PrecompileFile(string path, Encoding encoding = null)
        {
            VerifyNotDisposed();

            if (path == null)
            {
                throw new ArgumentNullException(
                          nameof(path),
                          string.Format(CoreStrings.Common_ArgumentIsNull, nameof(path))
                          );
            }

            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentException(
                          string.Format(CoreStrings.Common_ArgumentIsEmpty, nameof(path)),
                          nameof(path)
                          );
            }

            if (!ValidationHelpers.CheckDocumentNameFormat(path))
            {
                throw new ArgumentException(
                          string.Format(CoreStrings.Usage_InvalidFileNameFormat, path),
                          nameof(path)
                          );
            }

            OriginalCompiledScript compiledScript;
            string uniqueDocumentName = _documentNameManager.GetUniqueName(path);

            lock (_executionSynchronizer)
            {
                try
                {
                    var source = new FileScriptSource(uniqueDocumentName, path, encoding);
                    compiledScript = OriginalCompiledScript.Compile(source);
                }
                catch (OriginalSyntaxException e)
                {
                    throw WrapSyntaxException(e);
                }
                catch (FileNotFoundException)
                {
                    throw;
                }
            }

            return(new JurassicPrecompiledScript(compiledScript));
        }
        protected override IPrecompiledScript InnerPrecompile(string code, string documentName)
        {
            OriginalCompiledScript compiledScript;
            string uniqueDocumentName = _documentNameManager.GetUniqueName(documentName);

            lock (_executionSynchronizer)
            {
                try
                {
                    var source = new OriginalStringScriptSource(code, uniqueDocumentName);
                    compiledScript = OriginalCompiledScript.Compile(source);
                }
                catch (OriginalSyntaxException e)
                {
                    throw WrapSyntaxException(e);
                }
            }

            return(new JurassicPrecompiledScript(compiledScript));
        }