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  */
  25 
  26 package jdk.nashorn.internal.runtime;
  27 
  28 /**
  29  * Describes attributes of a specific property of a script object.
  30  */
  31 public interface PropertyDescriptor {
  32 
  33     /** Type: generic property descriptor - TODO this should be an enum */
  34     public static final int GENERIC  = 0;
  35 
  36     /** Type: data property descriptor - TODO this should be an enum */
  37     public static final int DATA     = 1;
  38 
  39     /** Type: accessor property descriptor - TODO this should be an enum */
  40     public static final int ACCESSOR = 2;
  41 
  42     /** descriptor for configurable property */
  43     public static final String CONFIGURABLE = "configurable";
  44 
  45     /** descriptor for enumerable property */
  46     public static final String ENUMERABLE = "enumerable";
  47 
  48     /** descriptor for writable property */
  49     public static final String WRITABLE = "writable";
  50 
  51     /** descriptor for value */
  52     public static final String VALUE = "value";
  53 
  54     /** descriptor for getter */
  55     public static final String GET = "get";
  56 
  57     /** descriptor for setter */
  58     public static final String SET = "set";
  59 
  60     /**
  61      * Check if this {@code PropertyDescriptor} describes a configurable property
  62      * @return true if configurable
  63      */
  64     public boolean isConfigurable();
  65 
  66     /**
  67      * Check if this {@code PropertyDescriptor} describes an enumerable property
  68      * @return true if enumerable
  69      */
  70     public boolean isEnumerable();
  71 
  72     /**
  73      * Check if this {@code PropertyDescriptor} describes a wriable property
  74      * @return true if writable
  75      */
  76     public boolean isWritable();
  77 
  78     /**
  79      * Get the property value as given by this {@code PropertyDescriptor}
  80      * @return property value
  81      */
  82     public Object getValue();
  83 
  84     /**
  85      * Get the {@link UserAccessorProperty} getter as given by this {@code PropertyDescriptor}
  86      * @return getter, or null if not available
  87      */
  88     public ScriptFunction getGetter();
  89 
  90     /**
  91      * Get the {@link UserAccessorProperty} setter as given by this {@code PropertyDescriptor}
  92      * @return setter, or null if not available
  93      */
  94     public ScriptFunction getSetter();
  95 
  96     /**
  97      * Set whether this {@code PropertyDescriptor} describes a configurable property
  98      * @param flag true if configurable, false otherwise
  99      */
 100     public void setConfigurable(boolean flag);
 101 
 102     /**
 103      * Set whether this {@code PropertyDescriptor} describes an enumerable property
 104      * @param flag true if enumerable, false otherwise
 105      */
 106     public void setEnumerable(boolean flag);
 107 
 108     /**
 109      * Set whether this {@code PropertyDescriptor} describes a writable property
 110      * @param flag true if writable, false otherwise
 111      */
 112     public void setWritable(boolean flag);
 113 
 114     /**
 115      * Set the property value for this {@code PropertyDescriptor}
 116      * @param value property value
 117      */
 118     public void setValue(Object value);
 119 
 120     /**
 121      * Assign a {@link UserAccessorProperty} getter as given to this {@code PropertyDescriptor}
 122      * @param getter getter, or null if not available
 123      */
 124     public void setGetter(Object getter);
 125 
 126     /**
 127      * Assign a {@link UserAccessorProperty} setter as given to this {@code PropertyDescriptor}
 128      * @param setter setter, or null if not available
 129      */
 130     public void setSetter(Object setter);
 131 
 132     /**
 133      * Fill in this {@code PropertyDescriptor} from the properties of a given {@link ScriptObject}
 134      *
 135      * @param obj the script object
 136      * @return filled in {@code PropertyDescriptor}
 137      *
 138      */
 139     public PropertyDescriptor fillFrom(ScriptObject obj);
 140 
 141     /**
 142      * Get the type of this property descriptor.
 143      * @return property descriptor type, one of {@link PropertyDescriptor#GENERIC}, {@link PropertyDescriptor#DATA} and {@link PropertyDescriptor#ACCESSOR}
 144      */
 145     public int type();
 146 
 147     /**
 148      * Wrapper for {@link ScriptObject#has(Object)}
 149      *
 150      * @param key property key
 151      * @return true if property exists in implementor
 152      */
 153     public boolean has(Object key);
 154 }
 155