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

Mon, 17 Mar 2014 18:02:00 +0530

author
sundar
date
Mon, 17 Mar 2014 18:02:00 +0530
changeset 771
5ab19753ce4a
parent 766
06ee95f094b4
child 952
6d5471a497fb
child 963
e2497b11a021
permissions
-rw-r--r--

8037400: Remove getInitialMap getters and GlobalObject interface
Reviewed-by: lagergren, jlaskey, attila

     1 /*
     2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package jdk.nashorn.internal.objects;
    28 import java.util.Objects;
    29 import jdk.nashorn.internal.objects.annotations.Property;
    30 import jdk.nashorn.internal.objects.annotations.ScriptClass;
    31 import jdk.nashorn.internal.runtime.JSType;
    32 import jdk.nashorn.internal.runtime.PropertyDescriptor;
    33 import jdk.nashorn.internal.runtime.PropertyMap;
    34 import jdk.nashorn.internal.runtime.ScriptFunction;
    35 import jdk.nashorn.internal.runtime.ScriptObject;
    36 import jdk.nashorn.internal.runtime.ScriptRuntime;
    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;
    51     /** Is the property writable? */
    52     @Property
    53     public Object enumerable;
    55     // initialized by nasgen
    56     private static PropertyMap $nasgenmap$;
    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     }
    64     @Override
    65     public boolean isConfigurable() {
    66         return JSType.toBoolean(configurable);
    67     }
    69     @Override
    70     public boolean isEnumerable() {
    71         return JSType.toBoolean(enumerable);
    72     }
    74     @Override
    75     public boolean isWritable() {
    76         // Not applicable for this. But simplifies flag calculations.
    77         return false;
    78     }
    80     @Override
    81     public Object getValue() {
    82         throw new UnsupportedOperationException("value");
    83     }
    85     @Override
    86     public ScriptFunction getGetter() {
    87         throw new UnsupportedOperationException("get");
    88     }
    90     @Override
    91     public ScriptFunction getSetter() {
    92         throw new UnsupportedOperationException("set");
    93     }
    95     @Override
    96     public void setConfigurable(final boolean flag) {
    97         this.configurable = flag;
    98     }
   100     @Override
   101     public void setEnumerable(final boolean flag) {
   102         this.enumerable = flag;
   103     }
   105     @Override
   106     public void setWritable(final boolean flag) {
   107         throw new UnsupportedOperationException("set writable");
   108     }
   110     @Override
   111     public void setValue(final Object value) {
   112         throw new UnsupportedOperationException("set value");
   113     }
   115     @Override
   116     public void setGetter(final Object getter) {
   117         throw new UnsupportedOperationException("set getter");
   118     }
   120     @Override
   121     public void setSetter(final Object setter) {
   122         throw new UnsupportedOperationException("set setter");
   123     }
   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         }
   133         if (sobj.has(ENUMERABLE)) {
   134             this.enumerable = JSType.toBoolean(sobj.get(ENUMERABLE));
   135         } else {
   136             delete(ENUMERABLE, false);
   137         }
   139         return this;
   140     }
   142     @Override
   143     public int type() {
   144         return GENERIC;
   145     }
   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         }
   155         if (has(ENUMERABLE) && other.has(ENUMERABLE)) {
   156             if (isEnumerable() != other.isEnumerable()) {
   157                 return false;
   158             }
   159         }
   161         return true;
   162     }
   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         }
   173         final GenericPropertyDescriptor other = (GenericPropertyDescriptor)obj;
   174         return ScriptRuntime.sameValue(configurable, other.configurable) &&
   175                ScriptRuntime.sameValue(enumerable, other.enumerable);
   176     }
   178     @Override
   179     public int hashCode() {
   180         int hash = 7;
   181         hash = 97 * hash + Objects.hashCode(this.configurable);
   182         hash = 97 * hash + Objects.hashCode(this.enumerable);
   183         return hash;
   184     }
   185 }

mercurial