Example #1
0
 public static EcmaValue GetIntrinsicPrimitiveValue(this EcmaValue thisValue, EcmaValueType type)
 {
     if (thisValue.Type == type)
     {
         return(thisValue);
     }
     if (thisValue.Type == EcmaValueType.Object)
     {
         if (thisValue.GetUnderlyingObjectInternal() is PrimitiveObject obj && obj.PrimitiveValue.Type == type)
         {
             return(obj.PrimitiveValue);
         }
     }
     throw new EcmaTypeErrorException(InternalString.Error.IncompatibleObject);
 }
Example #2
0
        public static T GetUnderlyingObject <T>(this EcmaValue thisValue)
        {
            if (thisValue.Type != EcmaValueType.Object)
            {
                throw new EcmaTypeErrorException(InternalString.Error.NotObject);
            }
            object obj = thisValue.GetUnderlyingObjectInternal();

            if (obj is T value)
            {
                return(value);
            }
            if (obj is INativeObjectWrapper wrapper && wrapper.Target is T value2)
            {
                return(value2);
            }
            throw new EcmaTypeErrorException(InternalString.Error.IncompatibleObject);
        }