本文整理汇总了C#中IScriptable.GetIds方法的典型用法代码示例。如果您正苦于以下问题:C# IScriptable.GetIds方法的具体用法?C# IScriptable.GetIds怎么用?C# IScriptable.GetIds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IScriptable
的用法示例。
在下文中一共展示了IScriptable.GetIds方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPropertyIds
/// <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;
}
示例2: defaultObjectToSource
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 ();
}
}