本文整理汇总了C#中EcmaScript.NET.Context.NewObject方法的典型用法代码示例。如果您正苦于以下问题:C# Context.NewObject方法的具体用法?C# Context.NewObject怎么用?C# Context.NewObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EcmaScript.NET.Context
的用法示例。
在下文中一共展示了Context.NewObject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NewCatchScope
public static IScriptable NewCatchScope(Exception t, IScriptable lastCatchScope, string exceptionName, Context cx, IScriptable scope)
{
object obj;
bool cacheObj;
if (t is EcmaScriptThrow) {
cacheObj = false;
obj = ((EcmaScriptThrow)t).Value;
}
else {
cacheObj = true;
// Create wrapper object unless it was associated with
// the previous scope object
if (lastCatchScope != null) {
BuiltinObject last = (BuiltinObject)lastCatchScope;
obj = last.GetAssociatedValue (t);
if (obj == null)
Context.CodeBug ();
goto getObj_brk;
}
EcmaScriptException re;
string errorName;
string errorMsg;
Exception javaException = null;
if (t is EcmaScriptError) {
EcmaScriptError ee = (EcmaScriptError)t;
re = ee;
errorName = ee.Name;
errorMsg = ee.ErrorMessage;
}
else if (t is EcmaScriptRuntimeException) {
re = (EcmaScriptRuntimeException)t;
if (t.InnerException != null) {
javaException = t.InnerException;
errorName = "JavaException";
errorMsg = javaException.GetType ().FullName + ": " + javaException.Message;
}
else {
errorName = "InternalError";
errorMsg = re.Message;
}
}
else {
// Script can catch only instances of JavaScriptException,
// EcmaError and EvaluatorException
throw Context.CodeBug ();
}
string sourceUri = re.SourceName;
if (sourceUri == null) {
sourceUri = "";
}
int line = re.LineNumber;
object [] args;
if (line > 0) {
args = new object [] { errorMsg, sourceUri, (int)line };
}
else {
args = new object [] { errorMsg, sourceUri };
}
IScriptable errorObject = cx.NewObject (scope, errorName, args);
ScriptableObject.PutProperty (errorObject, "name", errorName);
if (javaException != null) {
object wrap = cx.Wrap (scope, javaException, null);
ScriptableObject.DefineProperty (errorObject, "javaException", wrap, ScriptableObject.PERMANENT | ScriptableObject.READONLY);
}
if (re != null) {
object wrap = cx.Wrap (scope, re, null);
ScriptableObject.DefineProperty (errorObject, "rhinoException", wrap, ScriptableObject.PERMANENT | ScriptableObject.READONLY);
}
obj = errorObject;
}
getObj_brk:
;
BuiltinObject catchScopeObject = new BuiltinObject ();
// See ECMA 12.4
catchScopeObject.DefineProperty (exceptionName, obj, ScriptableObject.PERMANENT);
if (cacheObj) {
catchScopeObject.AssociateValue (t, obj);
}
return catchScopeObject;
}
示例2: newObjectLiteral
public static IScriptable newObjectLiteral(object [] propertyIds, object [] propertyValues, Context cx, IScriptable scope)
{
IScriptable obj = cx.NewObject (scope);
for (int i = 0, end = propertyIds.Length; i != end; ++i) {
object id = propertyIds [i];
object value = propertyValues [i];
if (id is Node.GetterPropertyLiteral) {
BuiltinObject nativeObj = (BuiltinObject)obj;
InterpretedFunction fun = (InterpretedFunction)value;
nativeObj.DefineGetter ((string)((Node.GetterPropertyLiteral)id).Property, fun);
}
else if (id is Node.SetterPropertyLiteral) {
BuiltinObject nativeObj = (BuiltinObject)obj;
InterpretedFunction fun = (InterpretedFunction)value;
nativeObj.DefineSetter ((string)((Node.SetterPropertyLiteral)id).Property, fun);
}
else if (id is string) {
ScriptableObject.PutProperty (obj, (string)id, value);
}
else {
ScriptableObject.PutProperty (obj, (int)id, value);
}
}
return obj;
}
示例3: newArrayLiteral
public static IScriptable newArrayLiteral(object [] objects, int [] skipIndexces, Context cx, IScriptable scope)
{
int count = objects.Length;
int skipCount = 0;
if (skipIndexces != null) {
skipCount = skipIndexces.Length;
}
int length = count + skipCount;
int lengthObj = (int)length;
IScriptable arrayObj;
/*
* If the version is 120, then new Array(4) means create a new
* array with 4 as the first element. In this case, we have to
* set length property manually.
*/
if (cx.Version == Context.Versions.JS1_2) {
arrayObj = cx.NewObject (scope, "Array", ScriptRuntime.EmptyArgs);
ScriptableObject.PutProperty (arrayObj, "length", (object)lengthObj);
}
else {
arrayObj = cx.NewObject (scope, "Array", new object [] { lengthObj });
}
int skip = 0;
for (int i = 0, j = 0; i != length; ++i) {
if (skip != skipCount && skipIndexces [skip] == i) {
++skip;
continue;
}
ScriptableObject.PutProperty (arrayObj, i, objects [j]);
++j;
}
return arrayObj;
}