use of com.github.anba.es6draft.runtime.types.PropertyDescriptor in project es6draft by anba.
the class Properties method createExternalAccessors.
private static void createExternalAccessors(ExecutionContext cx, OrdinaryObject target, ObjectLayout layout, Converter converter) {
LinkedHashMap<String, PropertyDescriptor> stringProps = new LinkedHashMap<>();
EnumMap<BuiltinSymbol, PropertyDescriptor> symbolProps = new EnumMap<>(BuiltinSymbol.class);
for (Entry<Accessor, MethodHandle> entry : layout.accessors.entrySet()) {
MethodHandle handle = getStaticMethodHandle(cx, converter, entry.getValue());
createExternalAccessor(cx, entry.getKey(), handle, stringProps, symbolProps);
}
defineProperties(cx, target, stringProps, symbolProps);
}
use of com.github.anba.es6draft.runtime.types.PropertyDescriptor in project es6draft by anba.
the class Properties method createConstructor.
private static OrdinaryObject createConstructor(ExecutionContext cx, String className, OrdinaryObject proto, Converter converter, ObjectLayout layout) {
Entry<Function, MethodHandle> constructorEntry = findConstructor(layout);
if (constructorEntry != null) {
// User supplied method, perform manual ClassDefinitionEvaluation for constructors
Function function = constructorEntry.getKey();
MethodHandle unreflect = constructorEntry.getValue();
MethodHandle callMethod = getConstructorStaticMethodHandle(cx, converter, unreflect, MethodKind.Call);
MethodHandle constructMethod = getConstructorStaticMethodHandle(cx, converter, unreflect, MethodKind.Construct);
NativeConstructor constructor = new NativeConstructor(cx.getRealm(), className, function.arity(), callMethod, constructMethod);
constructor.defineOwnProperty(cx, "prototype", new PropertyDescriptor(proto, false, false, false));
proto.defineOwnProperty(cx, "constructor", new PropertyDescriptor(constructor, true, false, true));
return constructor;
}
// Create default constructor
String sourceText = String.format("(class %s { })", sanitizeName(className));
ScriptLoader scriptLoader = cx.getRealm().getScriptLoader();
Script script = scriptLoader.script(new Source("<Constructor>", 1), sourceText);
Object constructor = script.evaluate(cx);
assert constructor instanceof OrdinaryConstructorFunction : constructor.getClass();
return (OrdinaryConstructorFunction) constructor;
}
use of com.github.anba.es6draft.runtime.types.PropertyDescriptor in project es6draft by anba.
the class ArgumentsObject method getProperty.
/**
* 9.4.4.1 [[GetOwnProperty]] (P)
*/
@Override
protected Property getProperty(ExecutionContext cx, long propertyKey) {
/* step 1 (not applicable) */
/* step 2 */
Property desc = ordinaryGetOwnProperty(propertyKey);
/* step 3 */
if (desc == null) {
return desc;
}
/* step 4 */
ParameterMap map = this.parameterMap;
/* steps 5-6 */
boolean isMapped = map != null && map.hasOwnProperty(propertyKey);
/* step 7 */
if (isMapped) {
// FIXME: spec issue - maybe add assertion: IsDataDescriptor(desc)?
assert desc.isDataDescriptor();
PropertyDescriptor d = desc.toPropertyDescriptor();
d.setValue(map.get(propertyKey));
desc = d.toProperty();
}
/* step 9 */
return desc;
}
use of com.github.anba.es6draft.runtime.types.PropertyDescriptor in project es6draft by anba.
the class ArrayObject method ArraySetLength.
/**
* 9.4.2.4 ArraySetLength(A, Desc)
*
* @param cx
* the execution context
* @param array
* the array object
* @param desc
* the property descriptor
* @return {@code true} on success
*/
public static boolean ArraySetLength(ExecutionContext cx, ArrayObject array, PropertyDescriptor desc) {
/* step 1 */
if (!desc.hasValue()) {
return array.defineLength(desc, -1);
}
/* step 2 */
PropertyDescriptor newLenDesc = desc.clone();
/* steps 3-4 */
long newLen = ToUint32(cx, desc.getValue());
/* steps 5-6 */
double numberLen = ToNumber(cx, desc.getValue());
/* step 7 */
if (newLen != numberLen) {
throw newRangeError(cx, Messages.Key.InvalidArrayLength);
}
/* step 8 */
newLenDesc.setValue(newLen);
/* steps 9-11 */
long oldLen = array.length;
/* step 12 */
if (newLen >= oldLen) {
return array.defineLength(newLenDesc, newLen);
}
/* step 13 */
if (!array.lengthWritable) {
return false;
}
/* steps 14-15 */
boolean newWritable;
if (!newLenDesc.hasWritable() || newLenDesc.isWritable()) {
newWritable = true;
} else {
newWritable = false;
newLenDesc.setWritable(true);
}
/* steps 16-17 */
boolean succeeded = array.defineLength(newLenDesc, newLen);
/* step 18 */
if (!succeeded) {
return false;
}
/* step 19 */
long nonDeletableIndex = array.deleteRange(newLen, oldLen);
/* step 19.d */
if (nonDeletableIndex >= 0) {
array.length = nonDeletableIndex + 1;
if (!newWritable) {
array.lengthWritable = false;
}
return false;
}
/* step 20 */
if (!newWritable) {
array.lengthWritable = false;
}
/* step 21 */
return true;
}
use of com.github.anba.es6draft.runtime.types.PropertyDescriptor in project es6draft by anba.
the class ProxyObject method validateGetOwnProperty.
private Property validateGetOwnProperty(ExecutionContext cx, ScriptObject target, Object trapResultObj, Property targetDesc) {
/* step 14 */
if (Type.isUndefined(trapResultObj)) {
if (targetDesc == null) {
return null;
}
if (!targetDesc.isConfigurable()) {
throw newTypeError(cx, Messages.Key.ProxyNotConfigurable);
}
boolean extensibleTarget = IsExtensible(cx, target);
if (!extensibleTarget) {
throw newTypeError(cx, Messages.Key.ProxyNotExtensible);
}
return null;
}
if (targetDesc != null) {
// need copy because of possible side-effects in IsExtensible()
targetDesc = targetDesc.clone();
}
/* steps 15-16 */
boolean extensibleTarget = IsExtensible(cx, target);
/* steps 17-18 */
PropertyDescriptor resultDesc = ToPropertyDescriptor(cx, trapResultObj);
/* step 19 */
CompletePropertyDescriptor(resultDesc);
/* step 20 */
boolean valid = IsCompatiblePropertyDescriptor(extensibleTarget, resultDesc, targetDesc);
/* step 21 */
if (!valid) {
throw newTypeError(cx, Messages.Key.ProxyIncompatibleDescriptor);
}
/* step 22 */
if (!resultDesc.isConfigurable()) {
if (targetDesc == null || targetDesc.isConfigurable()) {
throw newTypeError(cx, Messages.Key.ProxyAbsentOrConfigurable);
}
}
/* step 23 */
return resultDesc.toProperty();
}
Aggregations