Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
 static void InitItObject(Context cx, ScriptableObject scope)
 {
     BuiltinObject itObj = new BuiltinObject ();
     itObj.SetPrototype (scope);
     itObj.DefineProperty ("color", Undefined.Value, ScriptableObject.PERMANENT);
     itObj.DefineProperty ("height", Undefined.Value, ScriptableObject.PERMANENT);
     itObj.DefineProperty ("width", Undefined.Value, ScriptableObject.PERMANENT);
     itObj.DefineProperty ("funny", Undefined.Value, ScriptableObject.PERMANENT);
     itObj.DefineProperty ("array", Undefined.Value, ScriptableObject.PERMANENT);
     itObj.DefineProperty ("rdonly", Undefined.Value, ScriptableObject.READONLY);
     scope.DefineProperty ("it", itObj, ScriptableObject.PERMANENT);
 }
Ejemplo n.º 3
0
 private void SetupDefaultPrototype()
 {
     BuiltinObject obj = new BuiltinObject ();
     obj.DefineProperty ("constructor", this, ScriptableObject.DONTENUM);
     // put the prototype property into the object now, then in the
     // wacky case of a user defining a function Object(), we don't
     // get an infinite loop trying to find the prototype.
     prototypeProperty = obj;
     IScriptable proto = GetObjectPrototype (this);
     if (proto != obj) {
         // not the one we just made, it must remain grounded
         obj.SetPrototype (proto);
     }
 }