Example #1
0
        public static bool InstanceOf(this EcmaValue thisValue, EcmaValue constructor)
        {
            if (constructor.Type != EcmaValueType.Object)
            {
                throw new EcmaTypeErrorException(InternalString.Error.NotFunction);
            }
            RuntimeObject obj           = constructor.ToObject();
            RuntimeObject instOfHandler = obj.GetMethod(Symbol.HasInstance);

            if (instOfHandler != null)
            {
                return(instOfHandler.Call(constructor, thisValue).ToBoolean());
            }
            if (!constructor.IsCallable)
            {
                throw new EcmaTypeErrorException(InternalString.Error.NotFunction);
            }
            return(obj.HasInstance(thisValue.ToObject()));
        }