Inheritance: IdScriptableObject
Exemplo n.º 1
0
		internal static void Init(ScriptableObject scope, bool @sealed)
		{
			// Iterator
			Rhino.NativeIterator iterator = new Rhino.NativeIterator();
			iterator.ExportAsJSClass(MAX_PROTOTYPE_ID, scope, @sealed);
			// Generator
			NativeGenerator.Init(scope, @sealed);
			// StopIteration
			NativeObject obj = new NativeIterator.StopIteration();
			obj.SetPrototype(GetObjectPrototype(scope));
			obj.SetParentScope(scope);
			if (@sealed)
			{
				obj.SealObject();
			}
			ScriptableObject.DefineProperty(scope, STOP_ITERATION, obj, ScriptableObject.DONTENUM);
			// Use "associateValue" so that generators can continue to
			// throw StopIteration even if the property of the global
			// scope is replaced or deleted.
			scope.AssociateValue(ITERATOR_TAG, obj);
		}
Exemplo n.º 2
0
		private static object JsConstructor(Context cx, Scriptable scope, Scriptable thisObj, object[] args)
		{
			if (args.Length == 0 || args[0] == null || args[0] == Undefined.instance)
			{
				object argument = args.Length == 0 ? Undefined.instance : args[0];
				throw ScriptRuntime.TypeError1("msg.no.properties", ScriptRuntime.ToString(argument));
			}
			Scriptable obj = ScriptRuntime.ToObject(scope, args[0]);
			bool keyOnly = args.Length > 1 && ScriptRuntime.ToBoolean(args[1]);
			if (thisObj != null)
			{
				// Called as a function. Convert to iterator if possible.
				// For objects that implement java.lang.Iterable or
				// java.util.Iterator, have JavaScript Iterator call the underlying
				// iteration methods
				IEnumerator<object> iterator = VMBridge.instance.GetJavaIterator(cx, scope, obj);
				if (iterator != null)
				{
					scope = ScriptableObject.GetTopLevelScope(scope);
					return cx.GetWrapFactory().Wrap(cx, scope, new NativeIterator.WrappedJavaIterator(iterator, scope), typeof(NativeIterator.WrappedJavaIterator));
				}
				// Otherwise, just call the runtime routine
				Scriptable jsIterator = ScriptRuntime.ToIterator(cx, scope, obj, keyOnly);
				if (jsIterator != null)
				{
					return jsIterator;
				}
			}
			// Otherwise, just set up to iterate over the properties of the object.
			// Do not call __iterator__ method.
			object objectIterator = ScriptRuntime.EnumInit(obj, cx, keyOnly ? ScriptRuntime.ENUMERATE_KEYS_NO_ITERATOR : ScriptRuntime.ENUMERATE_ARRAY_NO_ITERATOR);
			ScriptRuntime.SetEnumNumbers(objectIterator, true);
			NativeIterator result = new NativeIterator(objectIterator);
			result.SetPrototype(ScriptableObject.GetClassPrototype(scope, result.GetClassName()));
			result.SetParentScope(scope);
			return result;
		}