Exemplo n.º 1
0
 public static bool DefinePropertyOrThrow(this RuntimeObject obj, EcmaPropertyKey propertyKey, EcmaPropertyDescriptor descriptor)
 {
     Guard.ArgumentNotNull(obj, "obj");
     if (!obj.DefineOwnProperty(propertyKey, descriptor))
     {
         throw new EcmaTypeErrorException(InternalString.Error.CreatePropertyThrow);
     }
     return(true);
 }
Exemplo n.º 2
0
        public override bool DefineOwnProperty(EcmaPropertyKey propertyKey, EcmaPropertyDescriptor descriptor)
        {
            RuntimeObject target = ThrowIfProxyRevoked();
            RuntimeObject trap   = handler.GetMethod(WellKnownProperty.DefineProperty);

            if (trap == null)
            {
                return(target.DefineOwnProperty(propertyKey, descriptor));
            }
            if (!(bool)trap.Call(handler, target, propertyKey.ToValue(), descriptor.ToValue()))
            {
                return(false);
            }
            bool settingUnconfigurable     = descriptor.Configurable == false;
            EcmaPropertyDescriptor current = target.GetOwnProperty(propertyKey);

            if (current == null)
            {
                if (!target.IsExtensible || settingUnconfigurable)
                {
                    throw new EcmaTypeErrorException(InternalString.Error.InvalidTrapResult);
                }
            }
            else
            {
                if (!EcmaPropertyDescriptor.ValidateAndApplyPropertyDescriptor(ref descriptor, current, !target.IsExtensible))
                {
                    throw new EcmaTypeErrorException(InternalString.Error.InvalidTrapResult);
                }
                if (settingUnconfigurable && current.Configurable)
                {
                    throw new EcmaTypeErrorException(InternalString.Error.InvalidTrapResult);
                }
            }
            return(true);
        }
Exemplo n.º 3
0
 public static bool CreateMethodProperty(this RuntimeObject obj, EcmaPropertyKey propertyKey, EcmaValue value)
 {
     Guard.ArgumentNotNull(obj, "obj");
     return(obj.DefineOwnProperty(propertyKey, new EcmaPropertyDescriptor(value, EcmaPropertyAttributes.DefaultMethodProperty)));
 }
Exemplo n.º 4
0
 protected void SetPrototypeInternal(RuntimeObject proto)
 {
     proto.DefineOwnProperty(WellKnownProperty.Constructor, new EcmaPropertyDescriptor(this, EcmaPropertyAttributes.Configurable | EcmaPropertyAttributes.Writable));
     DefineOwnProperty(WellKnownProperty.Prototype, new EcmaPropertyDescriptor(proto, EcmaPropertyAttributes.Writable));
 }