src/jdk/nashorn/internal/objects/GenericPropertyDescriptor.java

Print this page
rev 754 : 8030197: Nashorn: Object.defineProperty() can be lured to change fixed NaN property
Reviewed-by: attila, jlaskey
rev 755 : 8035948: Redesign property listeners for shared classes
Reviewed-by: sundar, lagergren
rev 760 : 8037400: Remove getInitialMap getters and GlobalObject interface
Reviewed-by: lagergren, jlaskey, attila


  38 /**
  39  * Generic Property descriptor is used to represent attributes an object property
  40  * that is neither a data property descriptor nor an accessor property descriptor.
  41  *
  42  * See ECMA 8.10 The Property Descriptor and Property Identifier Specification Types
  43  *
  44  */
  45 @ScriptClass("GenericPropertyDescriptor")
  46 public final class GenericPropertyDescriptor extends ScriptObject implements PropertyDescriptor {
  47     /** Is the property configurable? */
  48     @Property
  49     public Object configurable;
  50 
  51     /** Is the property writable? */
  52     @Property
  53     public Object enumerable;
  54 
  55     // initialized by nasgen
  56     private static PropertyMap $nasgenmap$;
  57 
  58     static PropertyMap getInitialMap() {
  59         return $nasgenmap$;
  60     }
  61 
  62     GenericPropertyDescriptor(final boolean configurable, final boolean enumerable, final Global global) {
  63         super(global.getObjectPrototype(), global.getGenericPropertyDescriptorMap());
  64         this.configurable = configurable;
  65         this.enumerable   = enumerable;
  66     }
  67 
  68     @Override
  69     public boolean isConfigurable() {
  70         return JSType.toBoolean(configurable);
  71     }
  72 
  73     @Override
  74     public boolean isEnumerable() {
  75         return JSType.toBoolean(enumerable);
  76     }
  77 
  78     @Override
  79     public boolean isWritable() {
  80         // Not applicable for this. But simplifies flag calculations.
  81         return false;
  82     }
  83 


 129     @Override
 130     public PropertyDescriptor fillFrom(final ScriptObject sobj) {
 131         if (sobj.has(CONFIGURABLE)) {
 132             this.configurable = JSType.toBoolean(sobj.get(CONFIGURABLE));
 133         } else {
 134             delete(CONFIGURABLE, false);
 135         }
 136 
 137         if (sobj.has(ENUMERABLE)) {
 138             this.enumerable = JSType.toBoolean(sobj.get(ENUMERABLE));
 139         } else {
 140             delete(ENUMERABLE, false);
 141         }
 142 
 143         return this;
 144     }
 145 
 146     @Override
 147     public int type() {
 148         return GENERIC;

















 149     }
 150 
 151     @Override
 152     public boolean equals(final Object obj) {
 153         if (this == obj) {
 154             return true;
 155         }
 156         if (!(obj instanceof GenericPropertyDescriptor)) {
 157             return false;
 158         }
 159 
 160         final GenericPropertyDescriptor other = (GenericPropertyDescriptor)obj;
 161         return ScriptRuntime.sameValue(configurable, other.configurable) &&
 162                ScriptRuntime.sameValue(enumerable, other.enumerable);
 163     }
 164 
 165     @Override
 166     public int hashCode() {
 167         int hash = 7;
 168         hash = 97 * hash + Objects.hashCode(this.configurable);


  38 /**
  39  * Generic Property descriptor is used to represent attributes an object property
  40  * that is neither a data property descriptor nor an accessor property descriptor.
  41  *
  42  * See ECMA 8.10 The Property Descriptor and Property Identifier Specification Types
  43  *
  44  */
  45 @ScriptClass("GenericPropertyDescriptor")
  46 public final class GenericPropertyDescriptor extends ScriptObject implements PropertyDescriptor {
  47     /** Is the property configurable? */
  48     @Property
  49     public Object configurable;
  50 
  51     /** Is the property writable? */
  52     @Property
  53     public Object enumerable;
  54 
  55     // initialized by nasgen
  56     private static PropertyMap $nasgenmap$;
  57 




  58     GenericPropertyDescriptor(final boolean configurable, final boolean enumerable, final Global global) {
  59         super(global.getObjectPrototype(), $nasgenmap$);
  60         this.configurable = configurable;
  61         this.enumerable   = enumerable;
  62     }
  63 
  64     @Override
  65     public boolean isConfigurable() {
  66         return JSType.toBoolean(configurable);
  67     }
  68 
  69     @Override
  70     public boolean isEnumerable() {
  71         return JSType.toBoolean(enumerable);
  72     }
  73 
  74     @Override
  75     public boolean isWritable() {
  76         // Not applicable for this. But simplifies flag calculations.
  77         return false;
  78     }
  79 


 125     @Override
 126     public PropertyDescriptor fillFrom(final ScriptObject sobj) {
 127         if (sobj.has(CONFIGURABLE)) {
 128             this.configurable = JSType.toBoolean(sobj.get(CONFIGURABLE));
 129         } else {
 130             delete(CONFIGURABLE, false);
 131         }
 132 
 133         if (sobj.has(ENUMERABLE)) {
 134             this.enumerable = JSType.toBoolean(sobj.get(ENUMERABLE));
 135         } else {
 136             delete(ENUMERABLE, false);
 137         }
 138 
 139         return this;
 140     }
 141 
 142     @Override
 143     public int type() {
 144         return GENERIC;
 145     }
 146 
 147     @Override
 148     public boolean hasAndEquals(final PropertyDescriptor other) {
 149         if (has(CONFIGURABLE) && other.has(CONFIGURABLE)) {
 150             if (isConfigurable() != other.isConfigurable()) {
 151                 return false;
 152             }
 153         }
 154 
 155         if (has(ENUMERABLE) && other.has(ENUMERABLE)) {
 156             if (isEnumerable() != other.isEnumerable()) {
 157                 return false;
 158             }
 159         }
 160 
 161         return true;
 162     }
 163 
 164     @Override
 165     public boolean equals(final Object obj) {
 166         if (this == obj) {
 167             return true;
 168         }
 169         if (!(obj instanceof GenericPropertyDescriptor)) {
 170             return false;
 171         }
 172 
 173         final GenericPropertyDescriptor other = (GenericPropertyDescriptor)obj;
 174         return ScriptRuntime.sameValue(configurable, other.configurable) &&
 175                ScriptRuntime.sameValue(enumerable, other.enumerable);
 176     }
 177 
 178     @Override
 179     public int hashCode() {
 180         int hash = 7;
 181         hash = 97 * hash + Objects.hashCode(this.configurable);