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

Wed, 26 Jun 2013 15:40:52 +0200

author
hannesw
date
Wed, 26 Jun 2013 15:40:52 +0200
changeset 380
80c66d3fd872
parent 344
b0dcc3727fc3
child 414
ec84ba68ad39
permissions
-rw-r--r--

8019157: Avoid calling ScriptObject.setProto() if possible
Reviewed-by: jlaskey, sundar

     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() {
    59         this(false, false);
    60     }
    62     GenericPropertyDescriptor(final boolean configurable, final boolean enumerable) {
    63         super(Global.objectPrototype(), $nasgenmap$);
    64         this.configurable = configurable;
    65         this.enumerable   = enumerable;
    66     }
    68     @Override
    69     public boolean isConfigurable() {
    70         return JSType.toBoolean(configurable);
    71     }
    73     @Override
    74     public boolean isEnumerable() {
    75         return JSType.toBoolean(enumerable);
    76     }
    78     @Override
    79     public boolean isWritable() {
    80         // Not applicable for this. But simplifies flag calculations.
    81         return false;
    82     }
    84     @Override
    85     public Object getValue() {
    86         throw new UnsupportedOperationException("value");
    87     }
    89     @Override
    90     public ScriptFunction getGetter() {
    91         throw new UnsupportedOperationException("get");
    92     }
    94     @Override
    95     public ScriptFunction getSetter() {
    96         throw new UnsupportedOperationException("set");
    97     }
    99     @Override
   100     public void setConfigurable(final boolean flag) {
   101         this.configurable = flag;
   102     }
   104     @Override
   105     public void setEnumerable(final boolean flag) {
   106         this.enumerable = flag;
   107     }
   109     @Override
   110     public void setWritable(final boolean flag) {
   111         throw new UnsupportedOperationException("set writable");
   112     }
   114     @Override
   115     public void setValue(final Object value) {
   116         throw new UnsupportedOperationException("set value");
   117     }
   119     @Override
   120     public void setGetter(final Object getter) {
   121         throw new UnsupportedOperationException("set getter");
   122     }
   124     @Override
   125     public void setSetter(final Object setter) {
   126         throw new UnsupportedOperationException("set setter");
   127     }
   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         }
   137         if (sobj.has(ENUMERABLE)) {
   138             this.enumerable = JSType.toBoolean(sobj.get(ENUMERABLE));
   139         } else {
   140             delete(ENUMERABLE, false);
   141         }
   143         return this;
   144     }
   146     @Override
   147     public int type() {
   148         return GENERIC;
   149     }
   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         }
   160         final GenericPropertyDescriptor other = (GenericPropertyDescriptor)obj;
   161         return ScriptRuntime.sameValue(configurable, other.configurable) &&
   162                ScriptRuntime.sameValue(enumerable, other.enumerable);
   163     }
   165     @Override
   166     public int hashCode() {
   167         int hash = 7;
   168         hash = 97 * hash + Objects.hashCode(this.configurable);
   169         hash = 97 * hash + Objects.hashCode(this.enumerable);
   170         return hash;
   171     }
   172 }

mercurial