use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.
the class WrapperProxy method set.
@Override
public boolean set(ExecutionContext cx, String propertyKey, Object value, Object receiver) {
/* modified 9.1.9 [[Set] (P, V, Receiver) */
Property ownDesc = proxyTarget.getOwnProperty(cx, propertyKey);
if (ownDesc == null) {
// modified
ScriptObject parent = getPrototype();
if (parent != null) {
return parent.set(cx, propertyKey, value, receiver);
} else {
ownDesc = new Property(UNDEFINED, true, true, true);
}
}
if (ownDesc.isDataDescriptor()) {
if (!ownDesc.isWritable()) {
return false;
}
if (!Type.isObject(receiver)) {
return false;
}
ScriptObject _receiver = Type.objectValue(receiver);
Property existingDescriptor = _receiver.getOwnProperty(cx, propertyKey);
if (existingDescriptor != null) {
PropertyDescriptor valueDesc = new PropertyDescriptor(value);
return _receiver.defineOwnProperty(cx, propertyKey, valueDesc);
} else {
return CreateDataProperty(cx, _receiver, propertyKey, value);
}
}
assert ownDesc.isAccessorDescriptor();
Callable setter = ownDesc.getSetter();
if (setter == null) {
return false;
}
setter.call(cx, receiver, value);
return true;
}
use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.
the class WrapperProxy method get.
@Override
public Object get(ExecutionContext cx, String propertyKey, Object receiver) {
/* modified 9.1.8 [[Get]] (P, Receiver) */
Property desc = proxyTarget.getOwnProperty(cx, propertyKey);
if (desc == null) {
// modified
ScriptObject parent = getPrototype();
if (parent == null) {
return UNDEFINED;
}
return parent.get(cx, propertyKey, receiver);
}
if (desc.isDataDescriptor()) {
return desc.getValue();
}
assert desc.isAccessorDescriptor();
Callable getter = desc.getGetter();
if (getter == null) {
return UNDEFINED;
}
return getter.call(cx, receiver);
}
use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.
the class WrapperProxy method set.
@Override
public boolean set(ExecutionContext cx, long propertyKey, Object value, Object receiver) {
/* modified 9.1.9 [[Set] (P, V, Receiver) */
Property ownDesc = proxyTarget.getOwnProperty(cx, propertyKey);
if (ownDesc == null) {
// modified
ScriptObject parent = getPrototype();
if (parent != null) {
return parent.set(cx, propertyKey, value, receiver);
} else {
ownDesc = new Property(UNDEFINED, true, true, true);
}
}
if (ownDesc.isDataDescriptor()) {
if (!ownDesc.isWritable()) {
return false;
}
if (!Type.isObject(receiver)) {
return false;
}
ScriptObject _receiver = Type.objectValue(receiver);
Property existingDescriptor = _receiver.getOwnProperty(cx, propertyKey);
if (existingDescriptor != null) {
PropertyDescriptor valueDesc = new PropertyDescriptor(value);
return _receiver.defineOwnProperty(cx, propertyKey, valueDesc);
} else {
return CreateDataProperty(cx, _receiver, propertyKey, value);
}
}
assert ownDesc.isAccessorDescriptor();
Callable setter = ownDesc.getSetter();
if (setter == null) {
return false;
}
setter.call(cx, receiver, value);
return true;
}
use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.
the class ObjectConstructor method EnumerableOwnProperties.
/**
* EnumerableOwnProperties (O)
*
* @param cx
* the execution context
* @param object
* the script object
* @param kind
* the property kind
* @return <var>object</var>'s own enumerable properties
*/
static List<Object> EnumerableOwnProperties(ExecutionContext cx, ScriptObject object, PropertyKind kind) {
/* step 1 (not applicable) */
/* steps 2-3 */
List<?> ownKeys = object.ownPropertyKeys(cx);
/* step 4 */
int initialSize = Math.min(16, ownKeys.size());
ArrayList<Object> properties = new ArrayList<>(initialSize);
/* step 5 */
for (Object key : ownKeys) {
if (key instanceof String) {
String skey = (String) key;
Property desc = object.getOwnProperty(cx, skey);
if (desc != null && desc.isEnumerable()) {
if (kind == PropertyKind.Key) {
properties.add(skey);
} else {
Object value = Get(cx, object, skey);
if (kind == PropertyKind.Value) {
properties.add(value);
} else {
ArrayObject entry = CreateArrayFromList(cx, key, value);
properties.add(entry);
}
}
}
}
}
/* step 7 */
return properties;
}
use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.
the class RegExpConstructor method RegExpAlloc.
/**
* 21.2.3.2 Abstract Operations for the RegExp Constructor<br>
* 21.2.3.2.1 Runtime Semantics: RegExpAlloc ( newTarget )
*
* @param cx
* the execution context
* @param newTarget
* the constructor function
* @return the new regular expression object
*/
public static RegExpObject RegExpAlloc(ExecutionContext cx, Constructor newTarget) {
/* steps 1-2 */
RegExpObject obj = OrdinaryCreateFromConstructor(cx, newTarget, Intrinsics.RegExpPrototype, RegExpObject::new);
/* steps 3-4 */
obj.infallibleDefineOwnProperty("lastIndex", new Property(0, true, false, false));
/* step 5 */
return obj;
}
Aggregations