コード例 #1
0
ファイル: WeakMapInstance.cs プロジェクト: KurtGokhan/jint
        internal void WeakMapSet(JsValue key, JsValue value)
        {
            if (key.IsPrimitive())
            {
                ExceptionHelper.ThrowTypeError(_engine.Realm, "WeakMap key must be an object, got " + key);
            }

#if NETSTANDARD2_1
            _table.AddOrUpdate(key, value);
#else
            _table.Remove(key);
            _table.Add(key, value);
#endif
        }
コード例 #2
0
        /// <summary>
        /// http://www.ecma-international.org/ecma-262/5.1/#sec-9.1
        /// </summary>
        /// <param name="input"></param>
        /// <param name="preferredType"></param>
        /// <returns></returns>
        public static JsValue ToPrimitive(JsValue input, Types preferredType = Types.None)
        {
            if (input == Null.Instance || input == Undefined.Instance)
            {
                return(input);
            }

            if (input.IsPrimitive())
            {
                return(input);
            }

            return(input.AsObject().DefaultValue(preferredType));
        }
コード例 #3
0
        /// <summary>
        /// http://www.ecma-international.org/ecma-262/5.1/#sec-9.1
        /// </summary>
        /// <param name="input"></param>
        /// <param name="preferredType"></param>
        /// <returns></returns>
        public static JsValue ToPrimitive(JsValue input, Types preferredType = Types.None)
        {
            if (input == Null.Instance || input == Undefined.Instance)
            {
                return input;
            }

            if (input.IsPrimitive())
            {
                return input;
            }

            return input.AsObject().DefaultValue(preferredType);
        }
コード例 #4
0
ファイル: WeakSetInstance.cs プロジェクト: KurtGokhan/jint
        internal void WeakSetAdd(JsValue value)
        {
            if (value.IsPrimitive())
            {
                ExceptionHelper.ThrowTypeError(_engine.Realm, "WeakSet value must be an object, got " + value.ToString());
            }

#if NETSTANDARD2_1
            _table.AddOrUpdate(value, _tableValue);
#else
            _table.Remove(value);
            _table.Add(value, _tableValue);
#endif
        }
コード例 #5
0
        public void ShouldBeANumber()
        {
            var value = new JsValue(2);

            Assert.Equal(false, value.IsBoolean());
            Assert.Equal(false, value.IsArray());
            Assert.Equal(false, value.IsDate());
            Assert.Equal(false, value.IsNull());
            Assert.Equal(true, value.IsNumber());
            Assert.Equal(2, value.AsNumber());
            Assert.Equal(false, value.IsObject());
            Assert.Equal(true, value.IsPrimitive());
            Assert.Equal(false, value.IsRegExp());
            Assert.Equal(false, value.IsString());
            Assert.Equal(false, value.IsUndefined());
        }
コード例 #6
0
        public static Object As(this JsValue value, Type targetType, EngineInstance engine)
        {
            if (value != JsValue.Null)
            {
                if (targetType == typeof(Int32))
                {
                    return(TypeConverter.ToInt32(value));
                }
                else if (targetType == typeof(Double))
                {
                    return(TypeConverter.ToNumber(value));
                }
                else if (targetType == typeof(String))
                {
                    return(value.IsPrimitive() ? TypeConverter.ToString(value) : value.ToString());
                }
                else if (targetType == typeof(Boolean))
                {
                    return(TypeConverter.ToBoolean(value));
                }
                else if (targetType == typeof(UInt32))
                {
                    return(TypeConverter.ToUint32(value));
                }
                else if (targetType == typeof(UInt16))
                {
                    return(TypeConverter.ToUint16(value));
                }
                else
                {
                    return(value.AsComplex(targetType, engine));
                }
            }

            return(null);
        }
コード例 #7
0
 public bool HasPrimitiveBase()
 {
     return(_baseValue.IsPrimitive());
 }