Пример #1
0
        public void reverse()
        {
            long idx;
            Dictionary <long, object> reversed = new Dictionary <long, object>();

            for (idx = 0; idx < length; idx++)
            {
                JSProperty prop = this[idx];
                if (prop != null)
                {
                    object o = prop.GetValue(GLOBAL);
                    if (!(o == null && o == JSUndefined.Undefined))
                    {
                        reversed[length - idx - 1] = o;
                    }
                }
            }

            for (idx = 0; idx < length; idx++)
            {
                object o;
                if (reversed.TryGetValue(idx, out o) && !(o == null && o == JSUndefined.Undefined))
                {
                    this[idx] = new JSSimpleProperty(idx.ToString(), o);
                }
                else
                {
                    Delete(idx.ToString());
                }
            }
        }
Пример #2
0
        public static void PutValue(ExecutionContext GLOBAL, object reference, object val)
        {
            Reference refer = reference as Reference;

            if (refer == null)
            {
                throw new ReferenceError(reference.ToString());
            }
            JSObjectBase baseOb = refer.GetBase();

            if (baseOb == null)
            {
                baseOb = GLOBAL.jobject;
            }
            JSProperty prop = baseOb.GetItem(GLOBAL, refer.GetPropertyName());

            if (prop == null)
            {
                baseOb.SetItem(GLOBAL, refer.GetPropertyName(), new JSSimpleProperty(refer.GetPropertyName(), GetValue(GLOBAL, val)));
            }
            else if (!prop.ReadOnly)
            {
                prop.SetValue(GLOBAL, GetValue(GLOBAL, val));
            }
        }
Пример #3
0
        public static object GetValue(ExecutionContext GLOBAL, object reference)
        {
            Reference refer = reference as Reference;

            if (refer == null)
            {
                return(reference);
            }
            JSObjectBase baseOb = refer.GetBase();

            if (baseOb == null)
            {
                baseOb = GLOBAL.jobject;
            }
            JSProperty prop = baseOb.GetItem(GLOBAL, refer.GetPropertyName());

            if (prop == null && baseOb == GLOBAL.jobject)
            {
                throw new ReferenceError(baseOb.ToString() + " of type " + baseOb.Class + " doesn't have a " + (refer != null ? refer.GetPropertyName() : reference.ToString()) + " property.");
            }
            else if (prop == null)
            {
                return(JSUndefined.Undefined);
            }
            else
            {
                return(prop.GetValue(GLOBAL));
            }
        }
Пример #4
0
        public override void SetItem(ExecutionContext GLOBAL, string index, JSProperty value)
        {
            long i;

            if (long.TryParse(index, out i) && i > length - 1)
            {
                mLength = i + 1;
            }
            base.SetItem(GLOBAL, index, value);
        }
Пример #5
0
        public Activation(ExecutionContext GLOBAL, Node f, JSObjectBase a)
        {
            int i, j;

            for (i = 0, j = f.fparams.Count; i < j; i++)
            {
                JSProperty ares = a.GetItem(GLOBAL, i.ToString());
                this.SetItem(GLOBAL, f.fparams[i].ToString(), new JSSimpleProperty(f.fparams[i].ToString(), ares != null ? ares.GetValue(GLOBAL) : JSUndefined.Undefined, true));
            }
            this.SetItem(GLOBAL, "arguments", new JSSimpleProperty("arguments", a, true));
        }
Пример #6
0
        public static object GlobalOrNull(ExecutionContext GLOBAL, string ident)
        {
            JSProperty prop = GLOBAL.jobject.GetItem(GLOBAL, ident);

            if (prop != null)
            {
                return(prop.GetValue(GLOBAL));
            }
            else
            {
                return(null);
            }
        }
Пример #7
0
    public override ObjectHandle Initialize(bool isConstructCall, params InternalHandle[] args)
    {
        base.Initialize(isConstructCall, args);

        Console.WriteLine("\r\nInitializing V8DotNetTester ...\r\n");

        Console.WriteLine("Creating test property 1 (adding new JSProperty directly) ...");

        var myProperty1 = new JSProperty(Engine.CreateValue("Test property 1"));

        this.Properties.Add("testProperty1", myProperty1);

        Console.WriteLine("Creating test property 2 (adding new JSProperty using the IV8ManagedObject interface) ...");

        var myProperty2 = new JSProperty(Engine.CreateValue(true));

        this["testProperty2"] = myProperty2;

        Console.WriteLine("Creating test property 3 (reusing JSProperty instance for property 1) ...");

        // Note: This effectively links property 3 to property 1, so they will both always have the same value, even if the value changes.
        this.Properties.Add("testProperty3", myProperty1); // (reuse a value)

        Console.WriteLine("Creating test property 4 (just creating a 'null' property which will be intercepted later) ...");

        this.Properties.Add("testProperty4", JSProperty.Empty);

        Console.WriteLine("Creating test property 5 (test the 'this' overload in V8ManagedObject, which will set/update property 5 without calling into V8) ...");

        this["testProperty5"] = (JSProperty)Engine.CreateValue("Test property 5");

        Console.WriteLine("Creating test property 6 (using a dynamic property) ...");

        InternalHandle strValHandle = Engine.CreateValue("Test property 6");

        this.AsDynamic.testProperty6 = strValHandle;

        Console.WriteLine("Creating test function property 1 ...");

        var funcTemplate1 = Engine.CreateFunctionTemplate("_" + GetType().Name + "_");

        _MyFunc = funcTemplate1.GetFunctionObject(TestJSFunction1);
        this.AsDynamic.testFunction1 = _MyFunc;

        Console.WriteLine("\r\n... initialization complete.");

        return(Handle);
    }
Пример #8
0
        public virtual object DefaultValue(ExecutionContext GLOBAL, string hint)
        {
            string checkFirst, checkSecond;

            if (hint == "string")
            {
                checkFirst  = "toString";
                checkSecond = "valueOf";
            }
            else
            {
                checkFirst  = "valueOf";
                checkSecond = "toString";
            }

            JSProperty toStringMethod = this.GetItem(GLOBAL, checkFirst);

            if (toStringMethod != null)
            {
                try
                {
                    return(((JSObjectBase)toStringMethod.GetValue(GLOBAL)).Call(GLOBAL, this, new JSArray(GLOBAL), GLOBAL.currentContext));
                }
                catch (Exception) { }
            }

            JSProperty valueOfMethod = this.GetItem(GLOBAL, checkSecond);

            if (valueOfMethod != null)
            {
                try
                {
                    return(((JSObjectBase)valueOfMethod.GetValue(GLOBAL)).Call(GLOBAL, this, new JSArray(GLOBAL), GLOBAL.currentContext));
                }
                catch (Exception ex)
                {
                    throw new TypeError("Can't convert to primitive type: " + ex.Message);
                }
            }

            return(ToString());
        }
Пример #9
0
 public PropertyAccessReplacer(JSExpression thisReference, JSProperty property, JSExpression replacement)
 {
     ThisReference = thisReference;
     Property      = property;
     Replacement   = replacement;
 }
Пример #10
0
        public virtual InternalHandle NamedPropertySetter(ref string propertyName, InternalHandle value, V8PropertyAttributes attributes = V8PropertyAttributes.Undefined)
        {
            if (_Proxy != this)
            {
                var result = ((IV8ManagedObject)_Proxy).NamedPropertySetter(ref propertyName, value, attributes);
                if (!result.IsUndefined) return result;
            }

            var jsVal = this[propertyName];

            if (jsVal.Value.IsEmpty)
                this[propertyName] = jsVal = new JSProperty(value, attributes != V8PropertyAttributes.Undefined ? attributes : V8PropertyAttributes.None);
            else
            {
                if (attributes != V8PropertyAttributes.Undefined)
                {
                    jsVal.Attributes = attributes;
                    jsVal.Value = value; // (note: updating attributes automatically assumes writable access)
                }
                else if ((jsVal.Attributes & V8PropertyAttributes.ReadOnly) == 0)
                    jsVal.Value = value;
            }

            return jsVal.Value;
        }
Пример #11
0
 public virtual void SetItem(ExecutionContext GLOBAL, string ident, JSProperty value)
 {
     mProperties[ident] = value;
 }
Пример #12
0
 public virtual void SetItem(ExecutionContext GLOBAL, string ident, JSProperty value)
 {
     mProperties[ident] = value;
 }