当前位置: 首页>>代码示例>>C#>>正文


C# Context.NewObject方法代码示例

本文整理汇总了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;
        }
开发者ID:arifbudiman,项目名称:TridionMinifier,代码行数:93,代码来源:ScriptRuntime.cs

示例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;
        }
开发者ID:arifbudiman,项目名称:TridionMinifier,代码行数:26,代码来源:ScriptRuntime.cs

示例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;
 }
开发者ID:arifbudiman,项目名称:TridionMinifier,代码行数:33,代码来源:ScriptRuntime.cs


注:本文中的EcmaScript.NET.Context.NewObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。