Пример #1
0
 private void ChangeObject()
 {
     object [] ids = null;
     while (obj != null)
     {
         ids = obj.GetIds();
         if (ids.Length != 0)
         {
             break;
         }
         obj = obj.GetPrototype();
     }
     if (obj != null && this.ids != null)
     {
         object [] previous = this.ids;
         int       L        = previous.Length;
         if (used == null)
         {
             used = new ObjToIntMap(L);
         }
         for (int i = 0; i != L; ++i)
         {
             used.intern(previous [i]);
         }
     }
     this.ids   = ids;
     this.index = 0;
 }
 /// <summary> Returns an array of all ids from an object and its prototypes.
 /// <p>
 /// </summary>
 /// <param name="obj">a JavaScript object
 /// </param>
 /// <returns> an array of all ids from all object in the prototype chain.
 /// If a given id occurs multiple times in the prototype chain,
 /// it will occur only once in this list.
 /// </returns>
 public static object [] GetPropertyIds (IScriptable obj)
 {
     if (obj == null) {
         return ScriptRuntime.EmptyArgs;
     }
     object [] result = obj.GetIds ();
     ObjToIntMap map = null;
     for (; ; ) {
         obj = obj.GetPrototype ();
         if (obj == null) {
             break;
         }
         object [] ids = obj.GetIds ();
         if (ids.Length == 0) {
             continue;
         }
         if (map == null) {
             if (result.Length == 0) {
                 result = ids;
                 continue;
             }
             map = new ObjToIntMap (result.Length + ids.Length);
             for (int i = 0; i != result.Length; ++i) {
                 map.intern (result [i]);
             }
             result = null; // Allow to GC the result
         }
         for (int i = 0; i != ids.Length; ++i) {
             map.intern (ids [i]);
         }
     }
     if (map != null) {
         result = map.getKeys ();
     }
     return result;
 }
Пример #3
0
        internal static string defaultObjectToSource(Context cx, IScriptable scope, IScriptable thisObj, object [] args)
        {
            using (Helpers.StackOverflowVerifier sov = new Helpers.StackOverflowVerifier (1024)) {
                bool toplevel, iterating;
                if (cx.iterating == null) {
                    toplevel = true;
                    iterating = false;
                    cx.iterating = new ObjToIntMap (31);
                }
                else {
                    toplevel = false;
                    iterating = cx.iterating.has (thisObj);
                }

                System.Text.StringBuilder result = new System.Text.StringBuilder (128);
                if (toplevel) {
                    result.Append ("(");
                }
                result.Append ('{');

                // Make sure cx.iterating is set to null when done
                // so we don't leak memory
                try {
                    if (!iterating) {
                        cx.iterating.intern (thisObj); // stop recursion.
                        object [] ids = thisObj.GetIds ();
                        for (int i = 0; i < ids.Length; i++) {
                            if (i > 0)
                                result.Append (", ");
                            object id = ids [i];
                            object value;
                            if (id is int) {
                                int intId = ((int)id);
                                value = thisObj.Get (intId, thisObj);
                                result.Append (intId);
                            }
                            else {
                                string strId = (string)id;
                                value = thisObj.Get (strId, thisObj);
                                if (ScriptRuntime.isValidIdentifierName (strId)) {
                                    result.Append (strId);
                                }
                                else {
                                    result.Append ('\'');
                                    result.Append (ScriptRuntime.escapeString (strId, '\''));
                                    result.Append ('\'');
                                }
                            }
                            result.Append (':');
                            result.Append (ScriptRuntime.uneval (cx, scope, value));
                        }
                    }
                }
                finally {
                    if (toplevel) {
                        cx.iterating = null;
                    }
                }

                result.Append ('}');
                if (toplevel) {
                    result.Append (')');
                }
                return result.ToString ();
            }
        }
Пример #4
0
 public virtual object [] GetIds()
 {
     return(obj.GetIds());
 }