jdk.nashorn.internal.runtime.PropertyDescriptor Java Examples

The following examples show how to use jdk.nashorn.internal.runtime.PropertyDescriptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GenericPropertyDescriptor.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public PropertyDescriptor fillFrom(final ScriptObject sobj) {
    if (sobj.has(CONFIGURABLE)) {
        this.configurable = JSType.toBoolean(sobj.get(CONFIGURABLE));
    } else {
        delete(CONFIGURABLE, false);
    }

    if (sobj.has(ENUMERABLE)) {
        this.enumerable = JSType.toBoolean(sobj.get(ENUMERABLE));
    } else {
        delete(ENUMERABLE, false);
    }

    return this;
}
 
Example #2
Source File: GenericPropertyDescriptor.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public PropertyDescriptor fillFrom(final ScriptObject sobj) {
    if (sobj.has(CONFIGURABLE)) {
        this.configurable = JSType.toBoolean(sobj.get(CONFIGURABLE));
    } else {
        delete(CONFIGURABLE, false);
    }

    if (sobj.has(ENUMERABLE)) {
        this.enumerable = JSType.toBoolean(sobj.get(ENUMERABLE));
    } else {
        delete(ENUMERABLE, false);
    }

    return this;
}
 
Example #3
Source File: GenericPropertyDescriptor.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean hasAndEquals(final PropertyDescriptor other) {
    if (has(CONFIGURABLE) && other.has(CONFIGURABLE)) {
        if (isConfigurable() != other.isConfigurable()) {
            return false;
        }
    }

    if (has(ENUMERABLE) && other.has(ENUMERABLE)) {
        if (isEnumerable() != other.isEnumerable()) {
            return false;
        }
    }

    return true;
}
 
Example #4
Source File: GenericPropertyDescriptor.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public PropertyDescriptor fillFrom(final ScriptObject sobj) {
    if (sobj.has(CONFIGURABLE)) {
        this.configurable = JSType.toBoolean(sobj.get(CONFIGURABLE));
    } else {
        delete(CONFIGURABLE, false);
    }

    if (sobj.has(ENUMERABLE)) {
        this.enumerable = JSType.toBoolean(sobj.get(ENUMERABLE));
    } else {
        delete(ENUMERABLE, false);
    }

    return this;
}
 
Example #5
Source File: GenericPropertyDescriptor.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public PropertyDescriptor fillFrom(final ScriptObject sobj) {
    if (sobj.has(CONFIGURABLE)) {
        this.configurable = JSType.toBoolean(sobj.get(CONFIGURABLE));
    } else {
        delete(CONFIGURABLE, false);
    }

    if (sobj.has(ENUMERABLE)) {
        this.enumerable = JSType.toBoolean(sobj.get(ENUMERABLE));
    } else {
        delete(ENUMERABLE, false);
    }

    return this;
}
 
Example #6
Source File: GenericPropertyDescriptor.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public PropertyDescriptor fillFrom(final ScriptObject sobj) {
    if (sobj.has(CONFIGURABLE)) {
        this.configurable = JSType.toBoolean(sobj.get(CONFIGURABLE));
    } else {
        delete(CONFIGURABLE, false);
    }

    if (sobj.has(ENUMERABLE)) {
        this.enumerable = JSType.toBoolean(sobj.get(ENUMERABLE));
    } else {
        delete(ENUMERABLE, false);
    }

    return this;
}
 
Example #7
Source File: GenericPropertyDescriptor.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean hasAndEquals(final PropertyDescriptor other) {
    if (has(CONFIGURABLE) && other.has(CONFIGURABLE)) {
        if (isConfigurable() != other.isConfigurable()) {
            return false;
        }
    }

    if (has(ENUMERABLE) && other.has(ENUMERABLE)) {
        if (isEnumerable() != other.isEnumerable()) {
            return false;
        }
    }

    return true;
}
 
Example #8
Source File: GenericPropertyDescriptor.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean hasAndEquals(final PropertyDescriptor other) {
    if (has(CONFIGURABLE) && other.has(CONFIGURABLE)) {
        if (isConfigurable() != other.isConfigurable()) {
            return false;
        }
    }

    if (has(ENUMERABLE) && other.has(ENUMERABLE)) {
        if (isEnumerable() != other.isEnumerable()) {
            return false;
        }
    }

    return true;
}
 
Example #9
Source File: GenericPropertyDescriptor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public PropertyDescriptor fillFrom(final ScriptObject sobj) {
    if (sobj.has(CONFIGURABLE)) {
        this.configurable = JSType.toBoolean(sobj.get(CONFIGURABLE));
    } else {
        delete(CONFIGURABLE, false);
    }

    if (sobj.has(ENUMERABLE)) {
        this.enumerable = JSType.toBoolean(sobj.get(ENUMERABLE));
    } else {
        delete(ENUMERABLE, false);
    }

    return this;
}
 
Example #10
Source File: Global.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public PropertyDescriptor newAccessorDescriptor(final Object get, final Object set, final boolean configurable, final boolean enumerable) {
    final AccessorPropertyDescriptor desc = new AccessorPropertyDescriptor(configurable, enumerable, get == null ? UNDEFINED : get, set == null ? UNDEFINED : set, this);

    if (get == null) {
        desc.delete(PropertyDescriptor.GET, false);
    }

    if (set == null) {
        desc.delete(PropertyDescriptor.SET, false);
    }

    return desc;
}
 
Example #11
Source File: AccessorPropertyDescriptor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean hasAndEquals(final PropertyDescriptor otherDesc) {
    if (! (otherDesc instanceof AccessorPropertyDescriptor)) {
        return false;
    }
    final AccessorPropertyDescriptor other = (AccessorPropertyDescriptor)otherDesc;
    return (!has(CONFIGURABLE) || sameValue(configurable, other.configurable)) &&
           (!has(ENUMERABLE) || sameValue(enumerable, other.enumerable)) &&
           (!has(GET) || sameValue(get, other.get)) &&
           (!has(SET) || sameValue(set, other.set));
}
 
Example #12
Source File: AccessorPropertyDescriptor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public PropertyDescriptor fillFrom(final ScriptObject sobj) {
    if (sobj.has(CONFIGURABLE)) {
        this.configurable = JSType.toBoolean(sobj.get(CONFIGURABLE));
    } else {
        delete(CONFIGURABLE, false);
    }

    if (sobj.has(ENUMERABLE)) {
        this.enumerable = JSType.toBoolean(sobj.get(ENUMERABLE));
    } else {
        delete(ENUMERABLE, false);
    }

    if (sobj.has(GET)) {
        final Object getter = sobj.get(GET);
        if (getter == UNDEFINED || getter instanceof ScriptFunction) {
            this.get = getter;
        } else {
            throw typeError("not.a.function", ScriptRuntime.safeToString(getter));
        }
    } else {
        delete(GET, false);
    }

    if (sobj.has(SET)) {
        final Object setter = sobj.get(SET);
        if (setter == UNDEFINED || setter instanceof ScriptFunction) {
            this.set = setter;
        } else {
            throw typeError("not.a.function", ScriptRuntime.safeToString(setter));
        }
    } else {
        delete(SET, false);
    }

    return this;
}
 
Example #13
Source File: DataPropertyDescriptor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean hasAndEquals(final PropertyDescriptor otherDesc) {
    if (! (otherDesc instanceof DataPropertyDescriptor)) {
        return false;
    }

    final DataPropertyDescriptor other = (DataPropertyDescriptor)otherDesc;
    return (!has(CONFIGURABLE) || sameValue(configurable, other.configurable)) &&
           (!has(ENUMERABLE) || sameValue(enumerable, other.enumerable)) &&
           (!has(WRITABLE) || sameValue(writable, other.writable)) &&
           (!has(VALUE) || sameValue(value, other.value));
}
 
Example #14
Source File: AccessorPropertyDescriptor.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public PropertyDescriptor fillFrom(final ScriptObject sobj) {
    if (sobj.has(CONFIGURABLE)) {
        this.configurable = JSType.toBoolean(sobj.get(CONFIGURABLE));
    } else {
        delete(CONFIGURABLE, false);
    }

    if (sobj.has(ENUMERABLE)) {
        this.enumerable = JSType.toBoolean(sobj.get(ENUMERABLE));
    } else {
        delete(ENUMERABLE, false);
    }

    if (sobj.has(GET)) {
        final Object getter = sobj.get(GET);
        if (getter == UNDEFINED || getter instanceof ScriptFunction) {
            this.get = getter;
        } else {
            throw typeError("not.a.function", ScriptRuntime.safeToString(getter));
        }
    } else {
        delete(GET, false);
    }

    if (sobj.has(SET)) {
        final Object setter = sobj.get(SET);
        if (setter == UNDEFINED || setter instanceof ScriptFunction) {
            this.set = setter;
        } else {
            throw typeError("not.a.function", ScriptRuntime.safeToString(setter));
        }
    } else {
        delete(SET, false);
    }

    return this;
}
 
Example #15
Source File: NativeArguments.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.4.5.1 [[DefineOwnProperty]] ( P, Desc, Throw ) as specialized in
 * ECMA 10.6 for Arguments object.
 */
@Override
public boolean defineOwnProperty(final Object key, final Object propertyDesc, final boolean reject) {
    final int index = ArrayIndex.getArrayIndex(key);
    if (index >= 0) {
        final boolean isMapped = isMapped(index);
        final Object oldValue = isMapped ? getArray().getObject(index) : null;

        if (!super.defineOwnProperty(key, propertyDesc, false)) {
            if (reject) {
                throw typeError("cant.redefine.property",  key.toString(), ScriptRuntime.safeToString(this));
            }
            return false;
        }

        if (isMapped) {
            // When mapped argument is redefined, if new descriptor is accessor property
            // or data-non-writable property, we have to "unmap" (unlink).
            final PropertyDescriptor desc = toPropertyDescriptor(Global.instance(), propertyDesc);
            if (desc.type() == PropertyDescriptor.ACCESSOR) {
                setDeleted(index, oldValue);
            } else if (desc.has(PropertyDescriptor.WRITABLE) && !desc.isWritable()) {
                // delete and set value from new descriptor if it has one, otherwise use old value
                setDeleted(index, desc.has(PropertyDescriptor.VALUE) ? desc.getValue() : oldValue);
            } else if (desc.has(PropertyDescriptor.VALUE)) {
                setArray(getArray().set(index, desc.getValue(), false));
            }
        }

        return true;
    }

    return super.defineOwnProperty(key, propertyDesc, reject);
}
 
Example #16
Source File: NativeArguments.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.4.5.1 [[DefineOwnProperty]] ( P, Desc, Throw ) as specialized in
 * ECMA 10.6 for Arguments object.
 */
@Override
public boolean defineOwnProperty(final String key, final Object propertyDesc, final boolean reject) {
    final int index = ArrayIndex.getArrayIndex(key);
    if (index >= 0) {
        final boolean isMapped = isMapped(index);
        final Object oldValue = isMapped ? getArray().getObject(index) : null;

        if (!super.defineOwnProperty(key, propertyDesc, false)) {
            if (reject) {
                throw typeError("cant.redefine.property",  key, ScriptRuntime.safeToString(this));
            }
            return false;
        }

        if (isMapped) {
            // When mapped argument is redefined, if new descriptor is accessor property
            // or data-non-writable property, we have to "unmap" (unlink).
            final PropertyDescriptor desc = toPropertyDescriptor(Global.instance(), propertyDesc);
            if (desc.type() == PropertyDescriptor.ACCESSOR) {
                setDeleted(index, oldValue);
            } else if (desc.has(PropertyDescriptor.WRITABLE) && !desc.isWritable()) {
                // delete and set value from new descriptor if it has one, otherwise use old value
                setDeleted(index, desc.has(PropertyDescriptor.VALUE) ? desc.getValue() : oldValue);
            } else if (desc.has(PropertyDescriptor.VALUE)) {
                setArray(getArray().set(index, desc.getValue(), false));
            }
        }

        return true;
    }

    return super.defineOwnProperty(key, propertyDesc, reject);
}
 
Example #17
Source File: AccessorPropertyDescriptor.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public PropertyDescriptor fillFrom(final ScriptObject sobj) {
    if (sobj.has(CONFIGURABLE)) {
        this.configurable = JSType.toBoolean(sobj.get(CONFIGURABLE));
    } else {
        delete(CONFIGURABLE, false);
    }

    if (sobj.has(ENUMERABLE)) {
        this.enumerable = JSType.toBoolean(sobj.get(ENUMERABLE));
    } else {
        delete(ENUMERABLE, false);
    }

    if (sobj.has(GET)) {
        final Object getter = sobj.get(GET);
        if (getter == UNDEFINED || getter instanceof ScriptFunction) {
            this.get = getter;
        } else {
            throw typeError("not.a.function", ScriptRuntime.safeToString(getter));
        }
    } else {
        delete(GET, false);
    }

    if (sobj.has(SET)) {
        final Object setter = sobj.get(SET);
        if (setter == UNDEFINED || setter instanceof ScriptFunction) {
            this.set = setter;
        } else {
            throw typeError("not.a.function", ScriptRuntime.safeToString(setter));
        }
    } else {
        delete(SET, false);
    }

    return this;
}
 
Example #18
Source File: Global.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public PropertyDescriptor newAccessorDescriptor(final Object get, final Object set, final boolean configurable, final boolean enumerable) {
    final AccessorPropertyDescriptor desc = new AccessorPropertyDescriptor(configurable, enumerable, get == null ? UNDEFINED : get, set == null ? UNDEFINED : set, this);

    if (get == null) {
        desc.delete(PropertyDescriptor.GET, false);
    }

    if (set == null) {
        desc.delete(PropertyDescriptor.SET, false);
    }

    return desc;
}
 
Example #19
Source File: DataPropertyDescriptor.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public PropertyDescriptor fillFrom(final ScriptObject sobj) {
    if (sobj.has(CONFIGURABLE)) {
        this.configurable = JSType.toBoolean(sobj.get(CONFIGURABLE));
    } else {
        delete(CONFIGURABLE, false);
    }

    if (sobj.has(ENUMERABLE)) {
        this.enumerable = JSType.toBoolean(sobj.get(ENUMERABLE));
    } else {
        delete(ENUMERABLE, false);
    }

    if (sobj.has(WRITABLE)) {
        this.writable = JSType.toBoolean(sobj.get(WRITABLE));
    } else {
        delete(WRITABLE, false);
    }

    if (sobj.has(VALUE)) {
        this.value = sobj.get(VALUE);
    } else {
        delete(VALUE, false);
    }

    return this;
}
 
Example #20
Source File: NativeArguments.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.4.5.1 [[DefineOwnProperty]] ( P, Desc, Throw ) as specialized in
 * ECMA 10.6 for Arguments object.
 */
@Override
public boolean defineOwnProperty(final String key, final Object propertyDesc, final boolean reject) {
    final int index = ArrayIndex.getArrayIndex(key);
    if (index >= 0) {
        final boolean isMapped = isMapped(index);
        final Object oldValue = isMapped ? getArray().getObject(index) : null;

        if (!super.defineOwnProperty(key, propertyDesc, false)) {
            if (reject) {
                throw typeError("cant.redefine.property",  key, ScriptRuntime.safeToString(this));
            }
            return false;
        }

        if (isMapped) {
            // When mapped argument is redefined, if new descriptor is accessor property
            // or data-non-writable property, we have to "unmap" (unlink).
            final PropertyDescriptor desc = toPropertyDescriptor(Global.instance(), propertyDesc);
            if (desc.type() == PropertyDescriptor.ACCESSOR) {
                setDeleted(index, oldValue);
            } else if (desc.has(PropertyDescriptor.WRITABLE) && !desc.isWritable()) {
                // delete and set value from new descriptor if it has one, otherwise use old value
                setDeleted(index, desc.has(PropertyDescriptor.VALUE) ? desc.getValue() : oldValue);
            } else if (desc.has(PropertyDescriptor.VALUE)) {
                setArray(getArray().set(index, desc.getValue(), false));
            }
        }

        return true;
    }

    return super.defineOwnProperty(key, propertyDesc, reject);
}
 
Example #21
Source File: AccessorPropertyDescriptor.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public PropertyDescriptor fillFrom(final ScriptObject sobj) {
    if (sobj.has(CONFIGURABLE)) {
        this.configurable = JSType.toBoolean(sobj.get(CONFIGURABLE));
    } else {
        delete(CONFIGURABLE, false);
    }

    if (sobj.has(ENUMERABLE)) {
        this.enumerable = JSType.toBoolean(sobj.get(ENUMERABLE));
    } else {
        delete(ENUMERABLE, false);
    }

    if (sobj.has(GET)) {
        final Object getter = sobj.get(GET);
        if (getter == UNDEFINED || getter instanceof ScriptFunction) {
            this.get = getter;
        } else {
            throw typeError("not.a.function", ScriptRuntime.safeToString(getter));
        }
    } else {
        delete(GET, false);
    }

    if (sobj.has(SET)) {
        final Object setter = sobj.get(SET);
        if (setter == UNDEFINED || setter instanceof ScriptFunction) {
            this.set = setter;
        } else {
            throw typeError("not.a.function", ScriptRuntime.safeToString(setter));
        }
    } else {
        delete(SET, false);
    }

    return this;
}
 
Example #22
Source File: Global.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new ECMAScript AccessorPropertyDescriptor object.
 *
 * @param get getter function of the user accessor property
 * @param set setter function of the user accessor property
 * @param configurable is the property configurable?
 * @param enumerable is the property enumerable?
 * @return newly created AccessorPropertyDescriptor object
 */
public PropertyDescriptor newAccessorDescriptor(final Object get, final Object set, final boolean configurable, final boolean enumerable) {
    final AccessorPropertyDescriptor desc = new AccessorPropertyDescriptor(configurable, enumerable, get == null ? UNDEFINED : get, set == null ? UNDEFINED : set, this);

    if (get == null) {
        desc.delete(PropertyDescriptor.GET, false);
    }

    if (set == null) {
        desc.delete(PropertyDescriptor.SET, false);
    }

    return desc;
}
 
Example #23
Source File: NativeArguments.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.4.5.1 [[DefineOwnProperty]] ( P, Desc, Throw ) as specialized in
 * ECMA 10.6 for Arguments object.
 */
@Override
public boolean defineOwnProperty(final String key, final Object propertyDesc, final boolean reject) {
    final int index = ArrayIndex.getArrayIndex(key);
    if (index >= 0) {
        final boolean isMapped = isMapped(index);
        final Object oldValue = isMapped ? getArray().getObject(index) : null;

        if (!super.defineOwnProperty(key, propertyDesc, false)) {
            if (reject) {
                throw typeError("cant.redefine.property",  key, ScriptRuntime.safeToString(this));
            }
            return false;
        }

        if (isMapped) {
            // When mapped argument is redefined, if new descriptor is accessor property
            // or data-non-writable property, we have to "unmap" (unlink).
            final PropertyDescriptor desc = toPropertyDescriptor(Global.instance(), propertyDesc);
            if (desc.type() == PropertyDescriptor.ACCESSOR) {
                setDeleted(index, oldValue);
            } else if (desc.has(PropertyDescriptor.WRITABLE) && !desc.isWritable()) {
                // delete and set value from new descriptor if it has one, otherwise use old value
                setDeleted(index, desc.has(PropertyDescriptor.VALUE) ? desc.getValue() : oldValue);
            } else if (desc.has(PropertyDescriptor.VALUE)) {
                setArray(getArray().set(index, desc.getValue(), false));
            }
        }

        return true;
    }

    return super.defineOwnProperty(key, propertyDesc, reject);
}
 
Example #24
Source File: AccessorPropertyDescriptor.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean hasAndEquals(final PropertyDescriptor otherDesc) {
    if (! (otherDesc instanceof AccessorPropertyDescriptor)) {
        return false;
    }
    final AccessorPropertyDescriptor other = (AccessorPropertyDescriptor)otherDesc;
    return (!has(CONFIGURABLE) || sameValue(configurable, other.configurable)) &&
           (!has(ENUMERABLE) || sameValue(enumerable, other.enumerable)) &&
           (!has(GET) || sameValue(get, other.get)) &&
           (!has(SET) || sameValue(set, other.set));
}
 
Example #25
Source File: AccessorPropertyDescriptor.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public PropertyDescriptor fillFrom(final ScriptObject sobj) {
    if (sobj.has(CONFIGURABLE)) {
        this.configurable = JSType.toBoolean(sobj.get(CONFIGURABLE));
    } else {
        delete(CONFIGURABLE, false);
    }

    if (sobj.has(ENUMERABLE)) {
        this.enumerable = JSType.toBoolean(sobj.get(ENUMERABLE));
    } else {
        delete(ENUMERABLE, false);
    }

    if (sobj.has(GET)) {
        final Object getter = sobj.get(GET);
        if (getter == UNDEFINED || getter instanceof ScriptFunction) {
            this.get = getter;
        } else {
            throw typeError("not.a.function", ScriptRuntime.safeToString(getter));
        }
    } else {
        delete(GET, false);
    }

    if (sobj.has(SET)) {
        final Object setter = sobj.get(SET);
        if (setter == UNDEFINED || setter instanceof ScriptFunction) {
            this.set = setter;
        } else {
            throw typeError("not.a.function", ScriptRuntime.safeToString(setter));
        }
    } else {
        delete(SET, false);
    }

    return this;
}
 
Example #26
Source File: DataPropertyDescriptor.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean hasAndEquals(final PropertyDescriptor otherDesc) {
    if (! (otherDesc instanceof DataPropertyDescriptor)) {
        return false;
    }

    final DataPropertyDescriptor other = (DataPropertyDescriptor)otherDesc;
    return (!has(CONFIGURABLE) || sameValue(configurable, other.configurable)) &&
           (!has(ENUMERABLE) || sameValue(enumerable, other.enumerable)) &&
           (!has(WRITABLE) || sameValue(writable, other.writable)) &&
           (!has(VALUE) || sameValue(value, other.value));
}
 
Example #27
Source File: DataPropertyDescriptor.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public PropertyDescriptor fillFrom(final ScriptObject sobj) {
    if (sobj.has(CONFIGURABLE)) {
        this.configurable = JSType.toBoolean(sobj.get(CONFIGURABLE));
    } else {
        delete(CONFIGURABLE, false);
    }

    if (sobj.has(ENUMERABLE)) {
        this.enumerable = JSType.toBoolean(sobj.get(ENUMERABLE));
    } else {
        delete(ENUMERABLE, false);
    }

    if (sobj.has(WRITABLE)) {
        this.writable = JSType.toBoolean(sobj.get(WRITABLE));
    } else {
        delete(WRITABLE, false);
    }

    if (sobj.has(VALUE)) {
        this.value = sobj.get(VALUE);
    } else {
        delete(VALUE, false);
    }

    return this;
}
 
Example #28
Source File: DataPropertyDescriptor.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean hasAndEquals(final PropertyDescriptor otherDesc) {
    if (! (otherDesc instanceof DataPropertyDescriptor)) {
        return false;
    }

    final DataPropertyDescriptor other = (DataPropertyDescriptor)otherDesc;
    return (!has(CONFIGURABLE) || sameValue(configurable, other.configurable)) &&
           (!has(ENUMERABLE) || sameValue(enumerable, other.enumerable)) &&
           (!has(WRITABLE) || sameValue(writable, other.writable)) &&
           (!has(VALUE) || sameValue(value, other.value));
}
 
Example #29
Source File: Global.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new ECMAScript AccessorPropertyDescriptor object.
 *
 * @param get getter function of the user accessor property
 * @param set setter function of the user accessor property
 * @param configurable is the property configurable?
 * @param enumerable is the property enumerable?
 * @return newly created AccessorPropertyDescriptor object
 */
public PropertyDescriptor newAccessorDescriptor(final Object get, final Object set, final boolean configurable, final boolean enumerable) {
    final AccessorPropertyDescriptor desc = new AccessorPropertyDescriptor(configurable, enumerable, get == null ? UNDEFINED : get, set == null ? UNDEFINED : set, this);

    if (get == null) {
        desc.delete(PropertyDescriptor.GET, false);
    }

    if (set == null) {
        desc.delete(PropertyDescriptor.SET, false);
    }

    return desc;
}
 
Example #30
Source File: NativeArguments.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.4.5.1 [[DefineOwnProperty]] ( P, Desc, Throw ) as specialized in
 * ECMA 10.6 for Arguments object.
 */
@Override
public boolean defineOwnProperty(final String key, final Object propertyDesc, final boolean reject) {
    final int index = ArrayIndex.getArrayIndex(key);
    if (index >= 0) {
        final boolean isMapped = isMapped(index);
        final Object oldValue = isMapped ? getArray().getObject(index) : null;

        if (!super.defineOwnProperty(key, propertyDesc, false)) {
            if (reject) {
                throw typeError("cant.redefine.property",  key, ScriptRuntime.safeToString(this));
            }
            return false;
        }

        if (isMapped) {
            // When mapped argument is redefined, if new descriptor is accessor property
            // or data-non-writable property, we have to "unmap" (unlink).
            final PropertyDescriptor desc = toPropertyDescriptor(Global.instance(), propertyDesc);
            if (desc.type() == PropertyDescriptor.ACCESSOR) {
                setDeleted(index, oldValue);
            } else if (desc.has(PropertyDescriptor.WRITABLE) && !desc.isWritable()) {
                // delete and set value from new descriptor if it has one, otherwise use old value
                setDeleted(index, desc.has(PropertyDescriptor.VALUE) ? desc.getValue() : oldValue);
            } else if (desc.has(PropertyDescriptor.VALUE)) {
                setArray(getArray().set(index, desc.getValue(), false));
            }
        }

        return true;
    }

    return super.defineOwnProperty(key, propertyDesc, reject);
}