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); }
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); }
public static bool CreateMethodProperty(this RuntimeObject obj, EcmaPropertyKey propertyKey, EcmaValue value) { Guard.ArgumentNotNull(obj, "obj"); return(obj.DefineOwnProperty(propertyKey, new EcmaPropertyDescriptor(value, EcmaPropertyAttributes.DefaultMethodProperty))); }
protected void SetPrototypeInternal(RuntimeObject proto) { proto.DefineOwnProperty(WellKnownProperty.Constructor, new EcmaPropertyDescriptor(this, EcmaPropertyAttributes.Configurable | EcmaPropertyAttributes.Writable)); DefineOwnProperty(WellKnownProperty.Prototype, new EcmaPropertyDescriptor(proto, EcmaPropertyAttributes.Writable)); }