GetLanguageVersion() public method

Get the current language version.
Get the current language version.

The language version number affects JavaScript semantics as detailed in the overview documentation.

public GetLanguageVersion ( ) : int
return int
Ejemplo n.º 1
0
		public virtual void InitFromContext(Context cx)
		{
			SetErrorReporter(cx.GetErrorReporter());
			languageVersion = cx.GetLanguageVersion();
			generateDebugInfo = (!cx.IsGeneratingDebugChanged() || cx.IsGeneratingDebug());
			reservedKeywordAsIdentifier = cx.HasFeature(Context.FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER);
			allowMemberExprAsFunctionName = cx.HasFeature(Context.FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME);
			strictMode = cx.HasFeature(Context.FEATURE_STRICT_MODE);
			warningAsError = cx.HasFeature(Context.FEATURE_WARNING_AS_ERROR);
			xmlAvailable = cx.HasFeature(Context.FEATURE_E4X);
			optimizationLevel = cx.GetOptimizationLevel();
			generatingSource = cx.IsGeneratingSource();
			activationNames = cx.activationNames;
			// Observer code generation in compiled code :
			generateObserverCount = cx.generateObserverCount;
		}
Ejemplo n.º 2
0
		internal static void CheckDeprecated(Context cx, string name)
		{
			int version = cx.GetLanguageVersion();
			if (version >= Context.VERSION_1_4 || version == Context.VERSION_DEFAULT)
			{
				string msg = GetMessage1("msg.deprec.ctor", name);
				if (version == Context.VERSION_DEFAULT)
				{
					Context.ReportWarning(msg);
				}
				else
				{
					throw Context.ReportRuntimeError(msg);
				}
			}
		}
Ejemplo n.º 3
0
		/// <summary>Get and set the language version.</summary>
		/// <remarks>
		/// Get and set the language version.
		/// This method is defined as a JavaScript function.
		/// </remarks>
		public static double Version(Context cx, Scriptable thisObj, object[] args, Function funObj)
		{
			double result = cx.GetLanguageVersion();
			if (args.Length > 0)
			{
				double d = Context.ToNumber(args[0]);
				cx.SetLanguageVersion((int)d);
			}
			return result;
		}
Ejemplo n.º 4
0
		public virtual object Js_split(Context cx, Scriptable scope, string target, object[] args)
		{
			// create an empty Array to return;
			Scriptable result = cx.NewArray(scope, 0);
			// return an array consisting of the target if no separator given
			// don't check against undefined, because we want
			// 'fooundefinedbar'.split(void 0) to split to ['foo', 'bar']
			if (args.Length < 1)
			{
				result.Put(0, result, target);
				return result;
			}
			// Use the second argument as the split limit, if given.
			bool limited = (args.Length > 1) && (args[1] != Undefined.instance);
			long limit = 0;
			// Initialize to avoid warning.
			if (limited)
			{
				limit = ScriptRuntime.ToUint32(args[1]);
				if (limit > target.Length)
				{
					limit = 1 + target.Length;
				}
			}
			string separator = null;
			int[] matchlen = new int[1];
			Scriptable re = null;
			RegExpProxy reProxy = null;
			if (args[0] is Scriptable)
			{
				reProxy = ScriptRuntime.GetRegExpProxy(cx);
				if (reProxy != null)
				{
					Scriptable test = (Scriptable)args[0];
					if (reProxy.IsRegExp(test))
					{
						re = test;
					}
				}
			}
			if (re == null)
			{
				separator = ScriptRuntime.ToString(args[0]);
				matchlen[0] = separator.Length;
			}
			// split target with separator or re
			int[] ip = new int[] { 0 };
			int match;
			int len = 0;
			bool[] matched = new bool[] { false };
			string[][] parens = new string[][] { null };
			int version = cx.GetLanguageVersion();
			while ((match = Find_split(cx, scope, target, separator, version, reProxy, re, ip, matchlen, matched, parens)) >= 0)
			{
				if ((limited && len >= limit) || (match > target.Length))
				{
					break;
				}
				string substr;
				if (target.Length == 0)
				{
					substr = target;
				}
				else
				{
					substr = Sharpen.Runtime.Substring(target, ip[0], match);
				}
				result.Put(len, result, substr);
				len++;
				if (re != null && matched[0] == true)
				{
					int size = parens[0].Length;
					for (int num = 0; num < size; num++)
					{
						if (limited && len >= limit)
						{
							break;
						}
						result.Put(len, result, parens[0][num]);
						len++;
					}
					matched[0] = false;
				}
				ip[0] = match + matchlen[0];
				if (version < Context.VERSION_1_3 && version != Context.VERSION_DEFAULT)
				{
					if (!limited && ip[0] == target.Length)
					{
						break;
					}
				}
			}
			return result;
		}
Ejemplo n.º 5
0
		private static SubString InterpretDollar(Context cx, RegExpImpl res, string da, int dp, int[] skip)
		{
			char dc;
			int num;
			int tmp;
			if (da[dp] != '$')
			{
				Kit.CodeBug();
			}
			int version = cx.GetLanguageVersion();
			if (version != Context.VERSION_DEFAULT && version <= Context.VERSION_1_4)
			{
				if (dp > 0 && da[dp - 1] == '\\')
				{
					return null;
				}
			}
			int daL = da.Length;
			if (dp + 1 >= daL)
			{
				return null;
			}
			dc = da[dp + 1];
			if (NativeRegExp.IsDigit(dc))
			{
				int cp;
				if (version != Context.VERSION_DEFAULT && version <= Context.VERSION_1_4)
				{
					if (dc == '0')
					{
						return null;
					}
					num = 0;
					cp = dp;
					while (++cp < daL && NativeRegExp.IsDigit(dc = da[cp]))
					{
						tmp = 10 * num + (dc - '0');
						if (tmp < num)
						{
							break;
						}
						num = tmp;
					}
				}
				else
				{
					int parenCount = (res.parens == null) ? 0 : res.parens.Length;
					num = dc - '0';
					if (num > parenCount)
					{
						return null;
					}
					cp = dp + 2;
					if ((dp + 2) < daL)
					{
						dc = da[dp + 2];
						if (NativeRegExp.IsDigit(dc))
						{
							tmp = 10 * num + (dc - '0');
							if (tmp <= parenCount)
							{
								cp++;
								num = tmp;
							}
						}
					}
					if (num == 0)
					{
						return null;
					}
				}
				num--;
				skip[0] = cp - dp;
				return res.GetParenSubString(num);
			}
			skip[0] = 2;
			switch (dc)
			{
				case '$':
				{
					return new SubString("$");
				}

				case '&':
				{
					return res.lastMatch;
				}

				case '+':
				{
					return res.lastParen;
				}

				case '`':
				{
					if (version == Context.VERSION_1_2)
					{
						res.leftContext.index = 0;
						res.leftContext.length = res.lastMatch.index;
					}
					return res.leftContext;
				}

				case '\'':
				{
					return res.rightContext;
				}
			}
			return null;
		}
Ejemplo n.º 6
0
		public virtual int Find_split(Context cx, Scriptable scope, string target, string separator, Scriptable reObj, int[] ip, int[] matchlen, bool[] matched, string[][] parensp)
		{
			int i = ip[0];
			int length = target.Length;
			int result;
			int version = cx.GetLanguageVersion();
			NativeRegExp re = (NativeRegExp)reObj;
			while (true)
			{
				// imitating C label
				int ipsave = ip[0];
				// reuse ip to save object creation
				ip[0] = i;
				object ret = re.ExecuteRegExp(cx, scope, this, target, ip, NativeRegExp.TEST);
				if (ret != true)
				{
					// Mismatch: ensure our caller advances i past end of string.
					ip[0] = ipsave;
					matchlen[0] = 1;
					matched[0] = false;
					return length;
				}
				i = ip[0];
				ip[0] = ipsave;
				matched[0] = true;
				SubString sep = this.lastMatch;
				matchlen[0] = sep.length;
				if (matchlen[0] == 0)
				{
					if (i == ip[0])
					{
						if (i == length)
						{
							if (version == Context.VERSION_1_2)
							{
								matchlen[0] = 1;
								result = i;
							}
							else
							{
								result = -1;
							}
							break;
						}
						i++;
						goto again_continue;
					}
				}
				// imitating C goto
				// PR_ASSERT((size_t)i >= sep->length);
				result = i - matchlen[0];
				break;
again_continue: ;
			}
again_break: ;
			int size = (parens == null) ? 0 : parens.Length;
			parensp[0] = new string[size];
			for (int num = 0; num < size; num++)
			{
				SubString parsub = GetParenSubString(num);
				parensp[0][num] = parsub.ToString();
			}
			return result;
		}
Ejemplo n.º 7
0
		private static object JsConstructor(Context cx, Scriptable scope, object[] args)
		{
			int arglen = args.Length;
			StringBuilder sourceBuf = new StringBuilder();
			sourceBuf.Append("function ");
			if (cx.GetLanguageVersion() != Context.VERSION_1_2)
			{
				sourceBuf.Append("anonymous");
			}
			sourceBuf.Append('(');
			// Append arguments as coma separated strings
			for (int i = 0; i < arglen - 1; i++)
			{
				if (i > 0)
				{
					sourceBuf.Append(',');
				}
				sourceBuf.Append(ScriptRuntime.ToString(args[i]));
			}
			sourceBuf.Append(") {");
			if (arglen != 0)
			{
				// append function body
				string funBody = ScriptRuntime.ToString(args[arglen - 1]);
				sourceBuf.Append(funBody);
			}
			sourceBuf.Append("\n}");
			string source = sourceBuf.ToString();
			int[] linep = new int[1];
			string filename = Context.GetSourcePositionFromStack(linep);
			if (filename == null)
			{
				filename = "<eval'ed string>";
				linep[0] = 1;
			}
			string sourceURI = ScriptRuntime.MakeUrlForGeneratedScript(false, filename, linep[0]);
			Scriptable global = ScriptableObject.GetTopLevelScope(scope);
			ErrorReporter reporter;
			reporter = DefaultErrorReporter.ForEval(cx.GetErrorReporter());
			Evaluator evaluator = Context.CreateInterpreter();
			if (evaluator == null)
			{
				throw new JavaScriptException("Interpreter not present", filename, linep[0]);
			}
			// Compile with explicit interpreter instance to force interpreter
			// mode.
			return cx.CompileFunction(global, source, evaluator, reporter, sourceURI, 1, null);
		}
Ejemplo n.º 8
0
		internal virtual object ExecuteRegExp(Context cx, Scriptable scope, RegExpImpl res, string str, int[] indexp, int matchType)
		{
			REGlobalData gData = new REGlobalData();
			int start = indexp[0];
			int end = str.Length;
			if (start > end)
			{
				start = end;
			}
			//
			// Call the recursive matcher to do the real work.
			//
			bool matches = MatchRegExp(gData, re, str, start, end, res.multiline);
			if (!matches)
			{
				if (matchType != PREFIX)
				{
					return null;
				}
				return Undefined.instance;
			}
			int index = gData.cp;
			int ep = indexp[0] = index;
			int matchlen = ep - (start + gData.skipped);
			index -= matchlen;
			object result;
			Scriptable obj;
			if (matchType == TEST)
			{
				result = true;
				obj = null;
			}
			else
			{
				result = cx.NewArray(scope, 0);
				obj = (Scriptable)result;
				string matchstr = Sharpen.Runtime.Substring(str, index, index + matchlen);
				obj.Put(0, obj, matchstr);
			}
			if (re.parenCount == 0)
			{
				res.parens = null;
				res.lastParen = SubString.emptySubString;
			}
			else
			{
				SubString parsub = null;
				int num;
				res.parens = new SubString[re.parenCount];
				for (num = 0; num < re.parenCount; num++)
				{
					int cap_index = gData.ParensIndex(num);
					string parstr;
					if (cap_index != -1)
					{
						int cap_length = gData.ParensLength(num);
						parsub = new SubString(str, cap_index, cap_length);
						res.parens[num] = parsub;
						if (matchType != TEST)
						{
							obj.Put(num + 1, obj, parsub.ToString());
						}
					}
					else
					{
						if (matchType != TEST)
						{
							obj.Put(num + 1, obj, Undefined.instance);
						}
					}
				}
				res.lastParen = parsub;
			}
			if (!(matchType == TEST))
			{
				obj.Put("index", obj, Sharpen.Extensions.ValueOf(start + gData.skipped));
				obj.Put("input", obj, str);
			}
			if (res.lastMatch == null)
			{
				res.lastMatch = new SubString();
				res.leftContext = new SubString();
				res.rightContext = new SubString();
			}
			res.lastMatch.str = str;
			res.lastMatch.index = index;
			res.lastMatch.length = matchlen;
			res.leftContext.str = str;
			if (cx.GetLanguageVersion() == Context.VERSION_1_2)
			{
				res.leftContext.index = start;
				res.leftContext.length = gData.skipped;
			}
			else
			{
				res.leftContext.index = 0;
				res.leftContext.length = start + gData.skipped;
			}
			res.rightContext.str = str;
			res.rightContext.index = ep;
			res.rightContext.length = end - ep;
			return result;
		}
Ejemplo n.º 9
0
		private static CharSequence Js_substring(Context cx, CharSequence target, object[] args)
		{
			int length = target.Length;
			double start = ScriptRuntime.ToInteger(args, 0);
			double end;
			if (start < 0)
			{
				start = 0;
			}
			else
			{
				if (start > length)
				{
					start = length;
				}
			}
			if (args.Length <= 1 || args[1] == Undefined.instance)
			{
				end = length;
			}
			else
			{
				end = ScriptRuntime.ToInteger(args[1]);
				if (end < 0)
				{
					end = 0;
				}
				else
				{
					if (end > length)
					{
						end = length;
					}
				}
				// swap if end < start
				if (end < start)
				{
					if (cx.GetLanguageVersion() != Context.VERSION_1_2)
					{
						double temp = start;
						start = end;
						end = temp;
					}
					else
					{
						// Emulate old JDK1.0 java.lang.String.substring()
						end = start;
					}
				}
			}
			return target.SubSequence((int)start, (int)end);
		}