本文整理汇总了C#中Rhino.Context.NewArray方法的典型用法代码示例。如果您正苦于以下问题:C# Context.NewArray方法的具体用法?C# Context.NewArray怎么用?C# Context.NewArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rhino.Context
的用法示例。
在下文中一共展示了Context.NewArray方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecIdCall
public override object ExecIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, object[] args)
{
if (!f.HasTag(XMLOBJECT_TAG))
{
return base.ExecIdCall(f, cx, scope, thisObj, args);
}
int id = f.MethodId();
if (id == Id_constructor)
{
return JsConstructor(cx, thisObj == null, args);
}
// All (XML|XMLList).prototype methods require thisObj to be XML
if (!(thisObj is Rhino.Xmlimpl.XMLObjectImpl))
{
throw IncompatibleCallError(f);
}
Rhino.Xmlimpl.XMLObjectImpl realThis = (Rhino.Xmlimpl.XMLObjectImpl)thisObj;
XML xml = realThis.GetXML();
switch (id)
{
case Id_appendChild:
{
if (xml == null)
{
XmlMethodNotFound(realThis, "appendChild");
}
return xml.AppendChild(Arg(args, 0));
}
case Id_addNamespace:
{
if (xml == null)
{
XmlMethodNotFound(realThis, "addNamespace");
}
Namespace ns = lib.CastToNamespace(cx, Arg(args, 0));
return xml.AddNamespace(ns);
}
case Id_childIndex:
{
if (xml == null)
{
XmlMethodNotFound(realThis, "childIndex");
}
return ScriptRuntime.WrapInt(xml.ChildIndex());
}
case Id_inScopeNamespaces:
{
if (xml == null)
{
XmlMethodNotFound(realThis, "inScopeNamespaces");
}
return cx.NewArray(scope, ToObjectArray(xml.InScopeNamespaces()));
}
case Id_insertChildAfter:
{
if (xml == null)
{
XmlMethodNotFound(realThis, "insertChildAfter");
}
object arg0 = Arg(args, 0);
if (arg0 == null || arg0 is XML)
{
return xml.InsertChildAfter((XML)arg0, Arg(args, 1));
}
return Undefined.instance;
}
case Id_insertChildBefore:
{
if (xml == null)
{
XmlMethodNotFound(realThis, "insertChildBefore");
}
object arg0 = Arg(args, 0);
if (arg0 == null || arg0 is XML)
{
return xml.InsertChildBefore((XML)arg0, Arg(args, 1));
}
return Undefined.instance;
}
case Id_localName:
{
if (xml == null)
{
XmlMethodNotFound(realThis, "localName");
}
return xml.LocalName();
}
case Id_name:
{
if (xml == null)
{
XmlMethodNotFound(realThis, "name");
}
//.........这里部分代码省略.........
示例2: EnumId
public static object EnumId(object enumObj, Context cx)
{
ScriptRuntime.IdEnumeration x = (ScriptRuntime.IdEnumeration)enumObj;
if (x.iterator != null)
{
return x.currentId;
}
switch (x.enumType)
{
case ENUMERATE_KEYS:
case ENUMERATE_KEYS_NO_ITERATOR:
{
return x.currentId;
}
case ENUMERATE_VALUES:
case ENUMERATE_VALUES_NO_ITERATOR:
{
return EnumValue(enumObj, cx);
}
case ENUMERATE_ARRAY:
case ENUMERATE_ARRAY_NO_ITERATOR:
{
object[] elements = new object[] { x.currentId, EnumValue(enumObj, cx) };
return cx.NewArray(ScriptableObject.GetTopLevelScope(x.obj), elements);
}
default:
{
throw Kit.CodeBug();
}
}
}
示例3: NewArrayLiteral
public static Scriptable NewArrayLiteral(object[] objects, int[] skipIndices, Context cx, Scriptable scope)
{
int SKIP_DENSITY = 2;
int count = objects.Length;
int skipCount = 0;
if (skipIndices != null)
{
skipCount = skipIndices.Length;
}
int length = count + skipCount;
if (length > 1 && skipCount * SKIP_DENSITY < length)
{
// If not too sparse, create whole array for constructor
object[] sparse;
if (skipCount == 0)
{
sparse = objects;
}
else
{
sparse = new object[length];
int skip = 0;
for (int i = 0, j = 0; i != length; ++i)
{
if (skip != skipCount && skipIndices[skip] == i)
{
sparse[i] = ScriptableConstants.NOT_FOUND;
++skip;
continue;
}
sparse[i] = objects[j];
++j;
}
}
return cx.NewArray(scope, sparse);
}
Scriptable array = cx.NewArray(scope, length);
int skip_1 = 0;
for (int i_1 = 0, j_1 = 0; i_1 != length; ++i_1)
{
if (skip_1 != skipCount && skipIndices[skip_1] == i_1)
{
++skip_1;
continue;
}
ScriptableObject.PutProperty(array, i_1, objects[j_1]);
++j_1;
}
return array;
}
示例4: Require
/// <summary>Creates a new instance of the require() function.</summary>
/// <remarks>
/// Creates a new instance of the require() function. Upon constructing it,
/// you will either want to install it in the global (or some other) scope
/// using
/// <see cref="Install(Rhino.Scriptable)">Install(Rhino.Scriptable)</see>
/// , or alternatively, you can load the
/// program's main module using
/// <see cref="RequireMain(Rhino.Context, string)">RequireMain(Rhino.Context, string)</see>
/// and
/// then act on the main module's exports.
/// </remarks>
/// <param name="cx">the current context</param>
/// <param name="nativeScope">
/// a scope that provides the standard native JavaScript
/// objects.
/// </param>
/// <param name="moduleScriptProvider">a provider for module scripts</param>
/// <param name="preExec">
/// an optional script that is executed in every module's
/// scope before its module script is run.
/// </param>
/// <param name="postExec">
/// an optional script that is executed in every module's
/// scope after its module script is run.
/// </param>
/// <param name="sandboxed">
/// if set to true, the require function will be sandboxed.
/// This means that it doesn't have the "paths" property, and also that the
/// modules it loads don't export the "module.uri" property.
/// </param>
public Require(Context cx, Scriptable nativeScope, ModuleScriptProvider moduleScriptProvider, Script preExec, Script postExec, bool sandboxed)
{
// Modules that completed loading; visible to all threads
// Modules currently being loaded on the thread. Used to resolve circular
// dependencies while loading.
this.moduleScriptProvider = moduleScriptProvider;
this.nativeScope = nativeScope;
this.sandboxed = sandboxed;
this.preExec = preExec;
this.postExec = postExec;
SetPrototype(ScriptableObject.GetFunctionPrototype(nativeScope));
if (!sandboxed)
{
paths = cx.NewArray(nativeScope, 0);
DefineReadOnlyProperty(this, "paths", paths);
}
else
{
paths = null;
}
}
示例5: InitFrameForNoSuchMethod
/// <summary>Call __noSuchMethod__.</summary>
/// <remarks>Call __noSuchMethod__.</remarks>
private static Interpreter.CallFrame InitFrameForNoSuchMethod(Context cx, Interpreter.CallFrame frame, int indexReg, object[] stack, double[] sDbl, int stackTop, int op, Scriptable funThisObj, Scriptable calleeScope, ScriptRuntime.NoSuchMethodShim noSuchMethodShim, InterpretedFunction ifun)
{
// create an args array from the stack
object[] argsArray = null;
// exactly like getArgsArray except that the first argument
// is the method name from the shim
int shift = stackTop + 2;
object[] elements = new object[indexReg];
for (int i = 0; i < indexReg; ++i, ++shift)
{
object val = stack[shift];
if (val == UniqueTag.DOUBLE_MARK)
{
val = ScriptRuntime.WrapNumber(sDbl[shift]);
}
elements[i] = val;
}
argsArray = new object[2];
argsArray[0] = noSuchMethodShim.methodName;
argsArray[1] = cx.NewArray(calleeScope, elements);
// exactly the same as if it's a regular InterpretedFunction
Interpreter.CallFrame callParentFrame = frame;
Interpreter.CallFrame calleeFrame = new Interpreter.CallFrame();
if (op == Icode_TAIL_CALL)
{
callParentFrame = frame.parentFrame;
ExitFrame(cx, frame, null);
}
// init the frame with the underlying method with the
// adjusted args array and shim's function
InitFrame(cx, calleeScope, funThisObj, argsArray, null, 0, 2, ifun, callParentFrame, calleeFrame);
if (op != Icode_TAIL_CALL)
{
frame.savedStackTop = stackTop;
frame.savedCallOp = op;
}
return calleeFrame;
}
示例6: Init
public virtual void Init(Context cx)
{
// Define some global functions particular to the shell. Note
// that these functions are not part of ECMA.
InitStandardObjects(cx, sealedStdLib);
string[] names = new string[] { "defineClass", "deserialize", "doctest", "gc", "help", "load", "loadClass", "print", "quit", "readFile", "readUrl", "runCommand", "seal", "serialize", "spawn", "sync", "toint32", "version" };
DefineFunctionProperties(names, typeof(Rhino.Tools.Shell.Global), ScriptableObject.DONTENUM);
// Set up "environment" in the global scope to provide access to the
// System environment variables.
Environment.DefineClass(this);
Environment environment = new Environment(this);
DefineProperty("environment", environment, ScriptableObject.DONTENUM);
history = (NativeArray)cx.NewArray(this, 0);
DefineProperty("history", history, ScriptableObject.DONTENUM);
initialized = true;
}
示例7: Js_split
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;
}
示例8: Match_glob
private static void Match_glob(GlobData mdata, Context cx, Scriptable scope, int count, RegExpImpl reImpl)
{
if (mdata.arrayobj == null)
{
mdata.arrayobj = cx.NewArray(scope, 0);
}
SubString matchsub = reImpl.lastMatch;
string matchstr = matchsub.ToString();
mdata.arrayobj.Put(count, mdata.arrayobj, matchstr);
}
示例9: ExecuteRegExp
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;
//.........这里部分代码省略.........
示例10: Run
public object Run(Context cx)
{
ScriptableObject global = ScriptRuntime.GetGlobal(cx);
// get the command line arguments and define "arguments"
// array in the top-level object
object[] argsCopy = new object[args.Length];
System.Array.Copy(args, 0, argsCopy, 0, args.Length);
Scriptable argsObj = cx.NewArray(global, argsCopy);
global.DefineProperty("arguments", argsObj, ScriptableObject.DONTENUM);
script.Exec(cx, global);
return null;
}