コード例 #1
0
 public static bool IsContinuationConstructor (IdFunctionObject f)
 {
     if (f.HasTag (FTAG) && f.MethodId == Id_constructor) {
         return true;
     }
     return false;
 }
コード例 #2
0
        public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args)
        {
            if (!f.HasTag (FTAG)) {
                return base.ExecIdCall (f, cx, scope, thisObj, args);
            }
            int id = f.MethodId;
            switch (id) {

                case Id_constructor:
                    throw Context.ReportRuntimeError ("Direct call is not supported");
            }
            throw new ArgumentException (Convert.ToString (id));
        }
コード例 #3
0
        public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args)
        {
            if (!f.HasTag(FTAG))
            {
                return(base.ExecIdCall(f, cx, scope, thisObj, args));
            }
            int id = f.MethodId;

            switch (id)
            {
            case Id_constructor:
                throw Context.ReportRuntimeError("Direct call is not supported");
            }
            throw new ArgumentException(Convert.ToString(id));
        }
コード例 #4
0
        public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args)
        {
            if (!f.HasTag(FUNCTION_TAG))
            {
                return(base.ExecIdCall(f, cx, scope, thisObj, args));
            }
            int id = f.MethodId;

            switch (id)
            {
            case Id_constructor:
                return(JsConstructor(cx, scope, args));


            case Id_toString: {
                BaseFunction realf  = RealFunction(thisObj, f);
                int          indent = ScriptConvert.ToInt32(args, 0);
                return(realf.Decompile(indent, Decompiler.TO_STRING_FLAG));
            }


            case Id_toSource: {
                BaseFunction realf  = RealFunction(thisObj, f);
                int          indent = 0;
                int          flags  = Decompiler.TO_SOURCE_FLAG;
                if (args.Length != 0)
                {
                    indent = ScriptConvert.ToInt32(args [0]);
                    if (indent >= 0)
                    {
                        flags = 0;
                    }
                    else
                    {
                        indent = 0;
                    }
                }
                return(realf.Decompile(indent, flags));
            }


            case Id_apply:
            case Id_call:
                return(ScriptRuntime.applyOrCall(id == Id_apply, cx, scope, thisObj, args));
            }
            throw new ArgumentException(Convert.ToString(id));
        }
コード例 #5
0
        public void InitPrototypeConstructor(IdFunctionObject f)
        {
            int id = prototypeValues.constructorId;

            if (id == 0)
            {
                throw new ApplicationException();
            }
            if (f.MethodId != id)
            {
                throw new ArgumentException();
            }
            if (Sealed)
            {
                f.SealObject();
            }
            prototypeValues.InitValue(id, "constructor", f, DONTENUM);
        }
コード例 #6
0
            private object EnsureId(int id)
            {
                object [] array = valueArray;
                if (array == null)
                {
                    lock (this) {
                        array = valueArray;
                        if (array == null)
                        {
                            array          = new object [maxId * SLOT_SPAN];
                            valueArray     = array;
                            attributeArray = new short [maxId];
                        }
                    }
                }
                int    valueSlot = (id - 1) * SLOT_SPAN + VALUE_SLOT;
                object value     = array [valueSlot];

                if (value == null)
                {
                    if (id == constructorId)
                    {
                        InitSlot(constructorId, "constructor", constructor, constructorAttrs);
                        constructor = null; // no need to refer it any longer
                    }
                    else
                    {
                        obj.InitPrototypeId(id);
                    }
                    value = array [valueSlot];
                    if (value == null)
                    {
                        throw new ApplicationException(obj.GetType().FullName + ".initPrototypeId(int id) " + "did not initialize id=" + id);
                    }
                }
                return(value);
            }
コード例 #7
0
        public IdFunctionObject ExportAsJSClass(int maxPrototypeId, IScriptable scope, bool zealed, int attributes)
        {
            // Set scope and prototype unless this is top level scope itself
            if (scope != this && scope != null)
            {
                ParentScope = scope;
                SetPrototype(GetObjectPrototype(scope));
            }

            ActivatePrototypeMap(maxPrototypeId);
            IdFunctionObject ctor = prototypeValues.createPrecachedConstructor();

            if (zealed)
            {
                SealObject();
            }
            FillConstructorProperties(ctor);
            if (zealed)
            {
                ctor.SealObject();
            }
            ctor.ExportAsScopeProperty(attributes);
            return(ctor);
        }
コード例 #8
0
            private object EnsureId (int id)
            {
                object [] array = valueArray;
                if (array == null) {
                    lock (this) {
                        array = valueArray;
                        if (array == null) {
                            array = new object [maxId * SLOT_SPAN];
                            valueArray = array;
                            attributeArray = new short [maxId];
                        }
                    }
                }
                int valueSlot = (id - 1) * SLOT_SPAN + VALUE_SLOT;
                object value = array [valueSlot];

                if (value == null) {
                    if (id == constructorId) {
                        InitSlot (constructorId, "constructor", constructor, constructorAttrs);
                        constructor = null; // no need to refer it any longer
                    }
                    else {
                        obj.InitPrototypeId (id);
                    }
                    value = array [valueSlot];
                    if (value == null) {
                        throw new ApplicationException (obj.GetType ().FullName + ".initPrototypeId(int id) " + "did not initialize id=" + id);
                    }
                }
                return value;
            }
コード例 #9
0
        public override object ExecIdCall (IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args)
        {
            if (!f.HasTag (NAMESPACE_TAG)) {
                return base.ExecIdCall (f, cx, scope, thisObj, args);
            }
            int id = f.MethodId;
            switch (id) {

                case Id_constructor:
                    return jsConstructor (cx, (thisObj == null), args);

                case Id_toString:
                    return realThis (thisObj, f).ToString ();

                case Id_toSource:
                    return realThis (thisObj, f).js_toSource ();
            }
            throw new System.ArgumentException (System.Convert.ToString (id));
        }
コード例 #10
0
 private IdFunctionObject NewIdFunction (object tag, int id, string name, int arity, IScriptable scope)
 {
     IdFunctionObject f = new IdFunctionObject (this, tag, id, name, arity, scope);
     if (Sealed) {
         f.SealObject ();
     }
     return f;
 }
コード例 #11
0
 protected internal virtual void FillConstructorProperties (IdFunctionObject ctor)
 {
 }
コード例 #12
0
        public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args)
        {
            if (!f.HasTag (REGEXP_TAG)) {
                return base.ExecIdCall (f, cx, scope, thisObj, args);
            }
            int id = f.MethodId;
            switch (id) {

                case Id_compile:
                    return realThis (thisObj, f).compile (cx, scope, args);

                case Id_toString:
                case Id_toSource:
                    return realThis (thisObj, f).ToString ();

                case Id_exec:
                    return realThis (thisObj, f).execSub (cx, scope, args, MATCH);

                case Id_test: {
                        object x = realThis (thisObj, f).execSub (cx, scope, args, TEST);
                        return true.Equals (x) ? true : false;
                    }

                case Id_prefix:
                    return realThis (thisObj, f).execSub (cx, scope, args, PREFIX);
            }
            throw new ArgumentException (Convert.ToString (id));
        }
コード例 #13
0
 /// <summary>
 /// Utility method to construct type error to indicate incompatible call
 /// when converting script thisObj to a particular type is not possible.
 /// Possible usage would be to have a private function like realThis:
 /// <pre>
 /// private static NativeSomething realThis(Scriptable thisObj,
 /// IdFunctionObject f)
 /// {
 /// if (!(thisObj instanceof NativeSomething))
 /// throw incompatibleCallError(f);
 /// return (NativeSomething)thisObj;
 /// }
 /// </pre>
 /// Note that although such function can be implemented universally via
 /// java.lang.Class.isInstance(), it would be much more slower.
 /// </summary>
 /// <param name="readOnly">specify if the function f does not change state of
 /// object.
 /// </param>
 /// <returns> Scriptable object suitable for a check by the instanceof
 /// operator.
 /// </returns>
 /// <throws>  RuntimeException if no more instanceof target can be found </throws>
 protected internal static EcmaScriptError IncompatibleCallError(IdFunctionObject f)
 {
     throw ScriptRuntime.TypeErrorById("msg.incompat.call", f.FunctionName);
 }
コード例 #14
0
 protected internal virtual void FillConstructorProperties(IdFunctionObject ctor)
 {
 }
コード例 #15
0
 /// <summary>'thisObj' will be null if invoked as constructor, in which case
 /// * instance of Scriptable should be returned.
 /// </summary>
 public virtual object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args)
 {
     throw f.Unknown();
 }
コード例 #16
0
 /// <summary>'thisObj' will be null if invoked as constructor, in which case
 /// * instance of Scriptable should be returned. 
 /// </summary>
 public virtual object ExecIdCall (IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args)
 {
     throw f.Unknown ();
 }
コード例 #17
0
 public void InitPrototypeConstructor (IdFunctionObject f)
 {
     int id = prototypeValues.constructorId;
     if (id == 0)
         throw new ApplicationException ();
     if (f.MethodId != id)
         throw new ArgumentException ();
     if (Sealed) {
         f.SealObject ();
     }
     prototypeValues.InitValue (id, "constructor", f, DONTENUM);
 }
コード例 #18
0
 private static BuiltinRegExp realThis(IScriptable thisObj, IdFunctionObject f)
 {
     if (!(thisObj is BuiltinRegExp))
         throw IncompatibleCallError (f);
     return (BuiltinRegExp)thisObj;
 }
コード例 #19
0
 /// <summary> 
 /// Utility method to construct type error to indicate incompatible call
 /// when converting script thisObj to a particular type is not possible.
 /// Possible usage would be to have a private function like realThis:
 /// <pre>
 /// private static NativeSomething realThis(Scriptable thisObj,
 /// IdFunctionObject f)
 /// {
 /// if (!(thisObj instanceof NativeSomething))
 /// throw incompatibleCallError(f);
 /// return (NativeSomething)thisObj;
 /// }
 /// </pre>
 /// Note that although such function can be implemented universally via
 /// java.lang.Class.isInstance(), it would be much more slower.
 /// </summary>
 /// <param name="readOnly">specify if the function f does not change state of
 /// object.
 /// </param>
 /// <returns> Scriptable object suitable for a check by the instanceof
 /// operator.
 /// </returns>
 /// <throws>  RuntimeException if no more instanceof target can be found </throws>
 protected internal static EcmaScriptError IncompatibleCallError (IdFunctionObject f)
 {
     throw ScriptRuntime.TypeErrorById ("msg.incompat.call", f.FunctionName);
 }
コード例 #20
0
        public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args)
        {
            if (!f.HasTag (FUNCTION_TAG)) {
                return base.ExecIdCall (f, cx, scope, thisObj, args);
            }
            int id = f.MethodId;
            switch (id) {

                case Id_constructor:
                    return JsConstructor (cx, scope, args);

                case Id_toString: {
                        BaseFunction realf = RealFunction (thisObj, f);
                        int indent = ScriptConvert.ToInt32 (args, 0);
                        return realf.Decompile (indent, Decompiler.TO_STRING_FLAG);
                    }

                case Id_toSource: {
                        BaseFunction realf = RealFunction (thisObj, f);
                        int indent = 0;
                        int flags = Decompiler.TO_SOURCE_FLAG;
                        if (args.Length != 0) {
                            indent = ScriptConvert.ToInt32 (args [0]);
                            if (indent >= 0) {
                                flags = 0;
                            }
                            else {
                                indent = 0;
                            }
                        }
                        return realf.Decompile (indent, flags);
                    }

                case Id_apply:
                case Id_call:
                    return ScriptRuntime.applyOrCall (id == Id_apply, cx, scope, thisObj, args);
            }
            throw new ArgumentException (Convert.ToString (id));
        }
コード例 #21
0
            internal void InitValue (int id, string name, object value, int attributes)
            {
                if (!(1 <= id && id <= maxId))
                    throw new ArgumentException ();
                if (name == null)
                    throw new ArgumentException ();
                if (value == UniqueTag.NotFound)
                    throw new ArgumentException ();
                ScriptableObject.CheckValidAttributes (attributes);
                if (obj.FindPrototypeId (name) != id)
                    throw new ArgumentException (name);

                if (id == constructorId) {
                    if (!(value is IdFunctionObject)) {
                        throw new ArgumentException ("consructor should be initialized with IdFunctionObject");
                    }
                    constructor = (IdFunctionObject)value;
                    constructorAttrs = (short)attributes;
                    return;
                }

                InitSlot (id, name, value, attributes);
            }
コード例 #22
0
 protected internal override void FillConstructorProperties(IdFunctionObject ctor)
 {
     // Fix up bootstrapping problem: getPrototype of the IdFunctionObject
     // can not return Function.prototype because Function object is not
     // yet defined.
     ctor.SetPrototype (this);
     base.FillConstructorProperties (ctor);
 }
コード例 #23
0
 private Namespace realThis (IScriptable thisObj, IdFunctionObject f)
 {
     if (!(thisObj is Namespace))
         throw IncompatibleCallError (f);
     return (Namespace)thisObj;
 }
コード例 #24
0
 private BaseFunction RealFunction(IScriptable thisObj, IdFunctionObject f)
 {
     object x = thisObj.GetDefaultValue (typeof (IFunction));
     if (x is BaseFunction) {
         return (BaseFunction)x;
     }
     throw ScriptRuntime.TypeErrorById ("msg.incompat.call", f.FunctionName);
 }