示例#1
0
        public RegExpInstance Construct(string regExp)
        {
            var r = new RegExpInstance(Engine);

            r.Prototype  = PrototypeObject;
            r.Extensible = true;

            if (regExp[0] != '/')
            {
                throw new JavaScriptException(Engine.SyntaxError, "Regexp should start with slash");
            }
            var lastSlash = regExp.LastIndexOf('/');
            // Unescape escaped forward slashes (\/)
            var pattern = regExp.Substring(1, lastSlash - 1).Replace("\\/", "/");
            var flags   = regExp.Substring(lastSlash + 1);

            var options = ParseOptions(r, flags);

            try
            {
                r.Value = new Regex(pattern, options);
            }
            catch (Exception e)
            {
                throw new JavaScriptException(Engine.SyntaxError, e.Message);
            }

            r.Flags  = flags;
            r.Source = System.String.IsNullOrEmpty(pattern) ? "(?:)" : pattern;

            r.FastAddProperty("global", r.Global, false, false, false);
            r.FastAddProperty("ignoreCase", r.IgnoreCase, false, false, false);
            r.FastAddProperty("multiline", r.Multiline, false, false, false);
            r.FastAddProperty("source", r.Source, false, false, false);
            r.FastAddProperty("lastIndex", 0, true, false, false);

            return(r);
        }
示例#2
0
        /// <summary>
        /// http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.5
        /// http://www.ecma-international.org/ecma-262/5.1/#sec-15.10.4
        /// </summary>
        /// <param name="arguments"></param>
        /// <returns></returns>
        public ObjectInstance Construct(JsValue[] arguments)
        {
            string p;
            string f;

            var pattern = arguments.At(0);
            var flags   = arguments.At(1);

            var r = pattern.TryCast <RegExpInstance>();

            if (flags == Undefined.Instance && r != null)
            {
                return(r);
            }
            else if (flags != Undefined.Instance && r != null)
            {
                throw new JavaScriptException(Engine.TypeError);
            }
            else
            {
                if (pattern == Undefined.Instance)
                {
                    p = "";
                }
                else
                {
                    p = TypeConverter.ToString(pattern);
                }

                f = flags != Undefined.Instance ? TypeConverter.ToString(flags) : "";
            }

            r            = new RegExpInstance(Engine);
            r.Prototype  = PrototypeObject;
            r.Extensible = true;

            var options = ParseOptions(r, f);

            try
            {
                r.Value = new Regex(p, options);
            }
            catch (Exception e)
            {
                throw new JavaScriptException(Engine.SyntaxError, e.Message);
            }

            string s;

            s = p;

            if (System.String.IsNullOrEmpty(s))
            {
                s = "(?:)";
            }

            r.Flags  = f;
            r.Source = s;

            r.FastAddProperty("global", r.Global, false, false, false);
            r.FastAddProperty("ignoreCase", r.IgnoreCase, false, false, false);
            r.FastAddProperty("multiline", r.Multiline, false, false, false);
            r.FastAddProperty("source", r.Source, false, false, false);
            r.FastAddProperty("lastIndex", 0, true, false, false);

            return(r);
        }
        /// <summary>
        /// http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.5
        /// http://www.ecma-international.org/ecma-262/5.1/#sec-15.10.4
        /// </summary>
        /// <param name="arguments"></param>
        /// <returns></returns>
        public ObjectInstance Construct(JsValue[] arguments)
        {
            string p;
            string f;

            var pattern = arguments.At(0);
            var flags = arguments.At(1);

            var r = pattern.TryCast<RegExpInstance>();
            if (flags == Undefined.Instance && r != null)
            {
                return r;
            }
            else if (flags != Undefined.Instance && r != null)
            {
                throw new JavaScriptException(Engine.TypeError);
            }
            else
            {
                if (pattern == Undefined.Instance)
                {
                    p = "";

                }
                else
                {
                    p = TypeConverter.ToString(pattern);
                }
                
                f = flags != Undefined.Instance ? TypeConverter.ToString(flags) : "";
            }

            r = new RegExpInstance(Engine);
            r.Prototype = PrototypeObject;
            r.Extensible = true;

            var options = ParseOptions(r, f);

            try
            {
                r.Value = new Regex(p, options);
            }
            catch (Exception e)
            {
                throw new JavaScriptException(Engine.SyntaxError, e.Message);
            }

            string s;
            s = p;
             
            if (System.String.IsNullOrEmpty(s))
            {
                s = "(?:)";
            }

            r.Flags = f;
            r.Source = s;

            r.FastAddProperty("global", r.Global, false, false, false);
            r.FastAddProperty("ignoreCase", r.IgnoreCase, false, false, false);
            r.FastAddProperty("multiline", r.Multiline, false, false, false);
            r.FastAddProperty("source", r.Source, false, false, false);
            r.FastAddProperty("lastIndex", 0, true, false, false);

            return r;
        }
        public RegExpInstance Construct(string regExp)
        {
            var r = new RegExpInstance(Engine);
            r.Prototype = PrototypeObject;
            r.Extensible = true;
 
            if (regExp[0] != '/')
            {
                throw new JavaScriptException(Engine.SyntaxError, "Regexp should start with slash");
            }
            var lastSlash = regExp.LastIndexOf('/');
            // Unescape escaped forward slashes (\/)
            var pattern = regExp.Substring(1, lastSlash - 1).Replace("\\/", "/");
            var flags = regExp.Substring(lastSlash + 1);

            var options = ParseOptions(r, flags);
            try
            {
                r.Value = new Regex(pattern, options);
            }
            catch (Exception e)
            {
                throw new JavaScriptException(Engine.SyntaxError, e.Message);
            }

            r.Flags = flags;
            r.Source = System.String.IsNullOrEmpty(pattern) ? "(?:)" : pattern;

            r.FastAddProperty("global", r.Global, false, false, false);
            r.FastAddProperty("ignoreCase", r.IgnoreCase, false, false, false);
            r.FastAddProperty("multiline", r.Multiline, false, false, false);
            r.FastAddProperty("source", r.Source, false, false, false);
            r.FastAddProperty("lastIndex", 0, true, false, false);

            return r;
        }