当前位置: 首页>>代码示例>>C#>>正文


C# Context.HasFeature方法代码示例

本文整理汇总了C#中Rhino.Context.HasFeature方法的典型用法代码示例。如果您正苦于以下问题:C# Context.HasFeature方法的具体用法?C# Context.HasFeature怎么用?C# Context.HasFeature使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rhino.Context的用法示例。


在下文中一共展示了Context.HasFeature方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateSpecial

		internal static Ref CreateSpecial(Context cx, object @object, string name)
		{
			Scriptable target = ScriptRuntime.ToObjectOrNull(cx, @object);
			if (target == null)
			{
				throw ScriptRuntime.UndefReadError(@object, name);
			}
			int type;
			if (name.Equals("__proto__"))
			{
				type = SPECIAL_PROTO;
			}
			else
			{
				if (name.Equals("__parent__"))
				{
					type = SPECIAL_PARENT;
				}
				else
				{
					throw new ArgumentException(name);
				}
			}
			if (!cx.HasFeature(Context.FEATURE_PARENT_PROTO_PROPERTIES))
			{
				// Clear special after checking for valid name!
				type = SPECIAL_NONE;
			}
			return new Rhino.SpecialRef(target, type, name);
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:30,代码来源:SpecialRef.cs

示例2: InitFromContext

		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;
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:16,代码来源:CompilerEnvirons.cs

示例3: WrapException

		public static Scriptable WrapException(Exception t, Scriptable scope, Context cx)
		{
			RhinoException re;
			string errorName;
			string errorMsg;
			Exception javaException = null;
			if (t is EcmaError)
			{
				EcmaError ee = (EcmaError)t;
				re = ee;
				errorName = ee.GetName();
				errorMsg = ee.GetErrorMessage();
			}
			else
			{
				if (t is WrappedException)
				{
					WrappedException we = (WrappedException)t;
					re = we;
					javaException = we.GetWrappedException();
					errorName = "JavaException";
					errorMsg = javaException.GetType().FullName + ": " + javaException.Message;
				}
				else
				{
					if (t is EvaluatorException)
					{
						// Pure evaluator exception, nor WrappedException instance
						EvaluatorException ee = (EvaluatorException)t;
						re = ee;
						errorName = "InternalError";
						errorMsg = ee.Message;
					}
					else
					{
						if (cx.HasFeature(Context.FEATURE_ENHANCED_JAVA_ACCESS))
						{
							// With FEATURE_ENHANCED_JAVA_ACCESS, scripts can catch
							// all exception types
							re = new WrappedException(t);
							errorName = "JavaException";
							errorMsg = t.ToString();
						}
						else
						{
							// Script can catch only instances of JavaScriptException,
							// EcmaError and EvaluatorException
							throw Kit.CodeBug();
						}
					}
				}
			}
			string sourceUri = re.SourceName();
			if (sourceUri == null)
			{
				sourceUri = string.Empty;
			}
			int line = re.LineNumber();
			object[] args;
			if (line > 0)
			{
				args = new object[] { errorMsg, sourceUri, Sharpen.Extensions.ValueOf(line) };
			}
			else
			{
				args = new object[] { errorMsg, sourceUri };
			}
			Scriptable errorObject = cx.NewObject(scope, errorName, args);
			ScriptableObject.PutProperty(errorObject, "name", errorName);
			// set exception in Error objects to enable non-ECMA "stack" property
			if (errorObject is NativeError)
			{
				((NativeError)errorObject).SetStackProvider(re);
			}
			if (javaException != null && IsVisible(cx, javaException))
			{
				object wrap = cx.GetWrapFactory().Wrap(cx, scope, javaException, null);
				ScriptableObject.DefineProperty(errorObject, "javaException", wrap, ScriptableObject.PERMANENT | ScriptableObject.READONLY);
			}
			if (IsVisible(cx, re))
			{
				object wrap = cx.GetWrapFactory().Wrap(cx, scope, re, null);
				ScriptableObject.DefineProperty(errorObject, "rhinoException", wrap, ScriptableObject.PERMANENT | ScriptableObject.READONLY);
			}
			return errorObject;
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:86,代码来源:ScriptRuntime.cs

示例4: DoTopCall

		public static object DoTopCall(Callable callable, Context cx, Scriptable scope, Scriptable thisObj, object[] args)
		{
			if (scope == null)
			{
				throw new ArgumentException();
			}
			if (cx.topCallScope != null)
			{
				throw new InvalidOperationException();
			}
			object result;
			cx.topCallScope = ScriptableObject.GetTopLevelScope(scope);
			cx.useDynamicScope = cx.HasFeature(Context.FEATURE_DYNAMIC_SCOPE);
			ContextFactory f = cx.GetFactory();
			try
			{
				result = f.DoTopCall(callable, cx, scope, thisObj, args);
			}
			finally
			{
				cx.topCallScope = null;
				// Cleanup cached references
				cx.cachedXMLLib = null;
				if (cx.currentActivationCall != null)
				{
					// Function should always call exitActivationFunction
					// if it creates activation record
					throw new InvalidOperationException();
				}
			}
			return result;
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:32,代码来源:ScriptRuntime.cs

示例5: EvalSpecial

		/// <summary>The eval function property of the global object.</summary>
		/// <remarks>
		/// The eval function property of the global object.
		/// See ECMA 15.1.2.1
		/// </remarks>
		public static object EvalSpecial(Context cx, Scriptable scope, object thisArg, object[] args, string filename, int lineNumber)
		{
			if (args.Length < 1)
			{
				return Undefined.instance;
			}
			object x = args[0];
			if (!(x is CharSequence))
			{
				if (cx.HasFeature(Context.FEATURE_STRICT_MODE) || cx.HasFeature(Context.FEATURE_STRICT_EVAL))
				{
					throw Context.ReportRuntimeError0("msg.eval.nonstring.strict");
				}
				string message = ScriptRuntime.GetMessage0("msg.eval.nonstring");
				Context.ReportWarning(message);
				return x;
			}
			if (filename == null)
			{
				int[] linep = new int[1];
				filename = Context.GetSourcePositionFromStack(linep);
				if (filename != null)
				{
					lineNumber = linep[0];
				}
				else
				{
					filename = string.Empty;
				}
			}
			string sourceName = ScriptRuntime.MakeUrlForGeneratedScript(true, filename, lineNumber);
			ErrorReporter reporter;
			reporter = DefaultErrorReporter.ForEval(cx.GetErrorReporter());
			Evaluator evaluator = Context.CreateInterpreter();
			if (evaluator == null)
			{
				throw new JavaScriptException("Interpreter not present", filename, lineNumber);
			}
			// Compile with explicit interpreter instance to force interpreter
			// mode.
			Script script = cx.CompileString(x.ToString(), evaluator, reporter, sourceName, 1, null);
			evaluator.SetEvalScriptFlag(script);
			Callable c = (Callable)script;
			return c.Call(cx, scope, (Scriptable)thisArg, ScriptRuntime.emptyArgs);
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:50,代码来源:ScriptRuntime.cs

示例6: SetName

		public static object SetName(Scriptable bound, object value, Context cx, Scriptable scope, string id)
		{
			if (bound != null)
			{
				// TODO: we used to special-case XMLObject here, but putProperty
				// seems to work for E4X and it's better to optimize  the common case
				ScriptableObject.PutProperty(bound, id, value);
			}
			else
			{
				// "newname = 7;", where 'newname' has not yet
				// been defined, creates a new property in the
				// top scope unless strict mode is specified.
				if (cx.HasFeature(Context.FEATURE_STRICT_MODE) || cx.HasFeature(Context.FEATURE_STRICT_VARS))
				{
					Context.ReportWarning(ScriptRuntime.GetMessage1("msg.assn.create.strict", id));
				}
				// Find the top scope by walking up the scope chain.
				bound = ScriptableObject.GetTopLevelScope(scope);
				if (cx.useDynamicScope)
				{
					bound = CheckDynamicScope(cx.topCallScope, bound);
				}
				bound.Put(id, bound, value);
			}
			return value;
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:27,代码来源:ScriptRuntime.cs

示例7: GetObjectProp

		public static object GetObjectProp(Scriptable obj, string property, Context cx)
		{
			object result = ScriptableObject.GetProperty(obj, property);
			if (result == ScriptableConstants.NOT_FOUND)
			{
				if (cx.HasFeature(Context.FEATURE_STRICT_MODE))
				{
					Context.ReportWarning(ScriptRuntime.GetMessage1("msg.ref.undefined.prop", property));
				}
				result = Undefined.instance;
			}
			return result;
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:13,代码来源:ScriptRuntime.cs

示例8: InitStandardObjects

		public static ScriptableObject InitStandardObjects(Context cx, ScriptableObject scope, bool @sealed)
		{
			if (scope == null)
			{
				scope = new NativeObject();
			}
			scope.AssociateValue(LIBRARY_SCOPE_KEY, scope);
			(new ClassCache()).Associate(scope);
			BaseFunction.Init(scope, @sealed);
			NativeObject.Init(scope, @sealed);
			Scriptable objectProto = ScriptableObject.GetObjectPrototype(scope);
			// Function.prototype.__proto__ should be Object.prototype
			Scriptable functionProto = ScriptableObject.GetClassPrototype(scope, "Function");
			functionProto.SetPrototype(objectProto);
			// Set the prototype of the object passed in if need be
			if (scope.GetPrototype() == null)
			{
				scope.SetPrototype(objectProto);
			}
			// must precede NativeGlobal since it's needed therein
			NativeError.Init(scope, @sealed);
			NativeGlobal.Init(cx, scope, @sealed);
			NativeArray.Init(scope, @sealed);
			if (cx.GetOptimizationLevel() > 0)
			{
				// When optimizing, attempt to fulfill all requests for new Array(N)
				// with a higher threshold before switching to a sparse
				// representation
				NativeArray.SetMaximumInitialCapacity(200000);
			}
			NativeString.Init(scope, @sealed);
			NativeBoolean.Init(scope, @sealed);
			NativeNumber.Init(scope, @sealed);
			NativeDate.Init(scope, @sealed);
			NativeMath.Init(scope, @sealed);
			NativeJSON.Init(scope, @sealed);
			NativeWith.Init(scope, @sealed);
			NativeCall.Init(scope, @sealed);
			NativeScript.Init(scope, @sealed);
			NativeIterator.Init(scope, @sealed);
			// Also initializes NativeGenerator
			bool withXml = cx.HasFeature(Context.FEATURE_E4X) && cx.GetE4xImplementationFactory() != null;
			// define lazy-loaded properties using their class name
			new LazilyLoadedCtor(scope, "RegExp", "org.mozilla.javascript.regexp.NativeRegExp", @sealed, true);
			new LazilyLoadedCtor(scope, "Packages", "org.mozilla.javascript.NativeJavaTopPackage", @sealed, true);
			new LazilyLoadedCtor(scope, "getClass", "org.mozilla.javascript.NativeJavaTopPackage", @sealed, true);
			new LazilyLoadedCtor(scope, "JavaAdapter", "org.mozilla.javascript.JavaAdapter", @sealed, true);
			new LazilyLoadedCtor(scope, "JavaImporter", "org.mozilla.javascript.ImporterTopLevel", @sealed, true);
			new LazilyLoadedCtor(scope, "Continuation", "org.mozilla.javascript.NativeContinuation", @sealed, true);
			foreach (string packageName in GetTopPackageNames())
			{
				new LazilyLoadedCtor(scope, packageName, "org.mozilla.javascript.NativeJavaTopPackage", @sealed, true);
			}
			if (withXml)
			{
				string xmlImpl = cx.GetE4xImplementationFactory().GetImplementationClassName();
				new LazilyLoadedCtor(scope, "XML", xmlImpl, @sealed, true);
				new LazilyLoadedCtor(scope, "XMLList", xmlImpl, @sealed, true);
				new LazilyLoadedCtor(scope, "Namespace", xmlImpl, @sealed, true);
				new LazilyLoadedCtor(scope, "QName", xmlImpl, @sealed, true);
			}
			if (scope is TopLevel)
			{
				((TopLevel)scope).CacheBuiltins();
			}
			return scope;
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:67,代码来源:ScriptRuntime.cs

示例9: ExecIdCall


//.........这里部分代码省略.........
				case Id_toUTCString:
				{
					if (t == t)
					{
						return Js_toUTCString(t);
					}
					return js_NaN_date_str;
				}

				case Id_toSource:
				{
					return "(new Date(" + ScriptRuntime.ToString(t) + "))";
				}

				case Id_valueOf:
				case Id_getTime:
				{
					return ScriptRuntime.WrapNumber(t);
				}

				case Id_getYear:
				case Id_getFullYear:
				case Id_getUTCFullYear:
				{
					if (t == t)
					{
						if (id != Id_getUTCFullYear)
						{
							t = LocalTime(t);
						}
						t = YearFromTime(t);
						if (id == Id_getYear)
						{
							if (cx.HasFeature(Context.FEATURE_NON_ECMA_GET_YEAR))
							{
								if (1900 <= t && t < 2000)
								{
									t -= 1900;
								}
							}
							else
							{
								t -= 1900;
							}
						}
					}
					return ScriptRuntime.WrapNumber(t);
				}

				case Id_getMonth:
				case Id_getUTCMonth:
				{
					if (t == t)
					{
						if (id == Id_getMonth)
						{
							t = LocalTime(t);
						}
						t = MonthFromTime(t);
					}
					return ScriptRuntime.WrapNumber(t);
				}

				case Id_getDate:
				case Id_getUTCDate:
				{
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:67,代码来源:NativeDate.cs

示例10: InterpretLoop


//.........这里部分代码省略.........
				if (generatorState != null && generatorState.operation == NativeGenerator.GENERATOR_CLOSE && throwable == generatorState.value)
				{
					exState = EX_FINALLY_STATE;
				}
				else
				{
					if (throwable is JavaScriptException)
					{
						exState = EX_CATCH_STATE;
					}
					else
					{
						if (throwable is EcmaError)
						{
							// an offical ECMA error object,
							exState = EX_CATCH_STATE;
						}
						else
						{
							if (throwable is EvaluatorException)
							{
								exState = EX_CATCH_STATE;
							}
							else
							{
								if (throwable is ContinuationPending)
								{
									exState = EX_NO_JS_STATE;
								}
								else
								{
									if (throwable is Exception)
									{
										exState = cx.HasFeature(Context.FEATURE_ENHANCED_JAVA_ACCESS) ? EX_CATCH_STATE : EX_FINALLY_STATE;
									}
									else
									{
										if (throwable is Exception)
										{
											exState = cx.HasFeature(Context.FEATURE_ENHANCED_JAVA_ACCESS) ? EX_CATCH_STATE : EX_NO_JS_STATE;
										}
										else
										{
											if (throwable is Interpreter.ContinuationJump)
											{
												// It must be ContinuationJump
												exState = EX_FINALLY_STATE;
												cjump_1 = (Interpreter.ContinuationJump)throwable;
											}
											else
											{
												exState = cx.HasFeature(Context.FEATURE_ENHANCED_JAVA_ACCESS) ? EX_CATCH_STATE : EX_FINALLY_STATE;
											}
										}
									}
								}
							}
						}
					}
				}
				if (instructionCounting)
				{
					try
					{
						AddInstructionCount(cx, frame, EXCEPTION_COST);
					}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:67,代码来源:Interpreter.cs

示例11: FindFunction


//.........这里部分代码省略.........
					if (!NativeJavaObject.CanConvert(args[j], argTypes[j]))
					{
						goto search_continue;
					}
				}
				if (firstBestFit < 0)
				{
					firstBestFit = i;
				}
				else
				{
					// Compare with all currently fit methods.
					// The loop starts from -1 denoting firstBestFit and proceed
					// until extraBestFitsCount to avoid extraBestFits allocation
					// in the most common case of no ambiguity
					int betterCount = 0;
					// number of times member was prefered over
					// best fits
					int worseCount = 0;
					// number of times best fits were prefered
					// over member
					for (int j_1 = -1; j_1 != extraBestFitsCount; ++j_1)
					{
						int bestFitIndex;
						if (j_1 == -1)
						{
							bestFitIndex = firstBestFit;
						}
						else
						{
							bestFitIndex = extraBestFits[j_1];
						}
						MemberBox bestFit = methodsOrCtors[bestFitIndex];
						if (cx.HasFeature(Context.FEATURE_ENHANCED_JAVA_ACCESS) && (bestFit.Member().Attributes & Modifier.PUBLIC) != (member.Member().Attributes & Modifier.PUBLIC))
						{
							// When FEATURE_ENHANCED_JAVA_ACCESS gives us access
							// to non-public members, continue to prefer public
							// methods in overloading
							if ((bestFit.Member().Attributes & Modifier.PUBLIC) == 0)
							{
								++betterCount;
							}
							else
							{
								++worseCount;
							}
						}
						else
						{
							int preference = PreferSignature(args, argTypes, member.vararg, bestFit.argTypes, bestFit.vararg);
							if (preference == PREFERENCE_AMBIGUOUS)
							{
								break;
							}
							else
							{
								if (preference == PREFERENCE_FIRST_ARG)
								{
									++betterCount;
								}
								else
								{
									if (preference == PREFERENCE_SECOND_ARG)
									{
										++worseCount;
									}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:67,代码来源:NativeJavaMethod.cs

示例12: ReportWarning

		private static void ReportWarning(Context cx, string messageId, string arg)
		{
			if (cx.HasFeature(Context.FEATURE_STRICT_MODE))
			{
				string msg = ScriptRuntime.GetMessage1(messageId, arg);
				Context.ReportWarning(msg);
			}
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:8,代码来源:NativeRegExp.cs


注:本文中的Rhino.Context.HasFeature方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。