use of com.github.anba.es6draft.runtime.types.PropertyDescriptor in project es6draft by anba.
the class GlobalEnvironmentRecord method createGlobalFunctionBinding.
/**
* 8.1.1.4.18 CreateGlobalFunctionBinding (N, V, D)
*
* @param name
* the binding name
* @param value
* the function value
* @param deletable
* the deletable for the binding
*/
public void createGlobalFunctionBinding(String name, Object value, boolean deletable) {
/* steps 1-3 (omitted) */
/* steps 4-5 */
Property existingProp = globalObject.getOwnProperty(cx, name);
/* steps 6-7 */
PropertyDescriptor desc;
if (existingProp == null || existingProp.isConfigurable()) {
desc = new PropertyDescriptor(value, true, true, deletable);
} else {
desc = new PropertyDescriptor(value);
}
/* steps 8-9 */
DefinePropertyOrThrow(cx, globalObject, name, desc);
/* steps 10-12 */
Set(cx, globalObject, name, value, false);
/* steps 13-14 */
varNames.add(name);
/* step 15 (return) */
}
use of com.github.anba.es6draft.runtime.types.PropertyDescriptor in project es6draft by anba.
the class ObjectEnvironmentRecord method createMutableBinding.
/**
* 8.1.1.2.2 CreateMutableBinding (N,D)
*/
@Override
public void createMutableBinding(String name, boolean deletable) {
/* steps 1-2 (omitted) */
/* steps 3-4 */
PropertyDescriptor desc = new PropertyDescriptor(UNDEFINED, true, true, deletable);
DefinePropertyOrThrow(cx, bindings, name, desc);
}
use of com.github.anba.es6draft.runtime.types.PropertyDescriptor in project es6draft by anba.
the class WrapperProxy method set.
@Override
public boolean set(ExecutionContext cx, Symbol 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.PropertyDescriptor in project es6draft by anba.
the class ObjectConstructor method ObjectDefineProperties.
/**
* 19.1.2.3.1 Runtime Semantics: ObjectDefineProperties ( O, Properties )
*
* @param cx
* the execution context
* @param o
* the script object
* @param properties
* the properties object
* @return the script object
*/
public static ScriptObject ObjectDefineProperties(ExecutionContext cx, Object o, Object properties) {
/* step 1 */
if (!Type.isObject(o)) {
throw newTypeError(cx, Messages.Key.NotObjectType);
}
ScriptObject obj = Type.objectValue(o);
/* steps 2-3 */
ScriptObject props = ToObject(cx, properties);
/* steps 4-5 */
List<?> keys = props.ownPropertyKeys(cx);
/* step 6 */
int initialSize = Math.min(32, keys.size());
ArrayList<PropertyDescriptor> descriptors = new ArrayList<>(initialSize);
ArrayList<Object> names = new ArrayList<>(initialSize);
/* step 7 */
for (Object nextKey : keys) {
Property propDesc = props.getOwnProperty(cx, nextKey);
if (propDesc != null && propDesc.isEnumerable()) {
Object descObj = Get(cx, props, nextKey);
PropertyDescriptor desc = ToPropertyDescriptor(cx, descObj);
descriptors.add(desc);
names.add(nextKey);
}
}
/* step 8 */
for (int i = 0, size = names.size(); i < size; ++i) {
Object p = names.get(i);
PropertyDescriptor desc = descriptors.get(i);
DefinePropertyOrThrow(cx, obj, p, desc);
}
/* step 9 */
return obj;
}
use of com.github.anba.es6draft.runtime.types.PropertyDescriptor in project es6draft by anba.
the class IntlAbstractOperations method SupportedLocales.
/**
* 9.2.9 SupportedLocales (availableLocales, requestedLocales, options)
*
* @param cx
* the execution context
* @param availableLocales
* the set of available locales
* @param requestedLocales
* the set of requested locales
* @param options
* the options object
* @return the supported locales array
*/
public static ScriptObject SupportedLocales(ExecutionContext cx, Set<String> availableLocales, Set<String> requestedLocales, Object options) {
/* step 1 */
String matcher = null;
if (!Type.isUndefined(options)) {
matcher = GetStringOption(cx, ToObject(cx, options), "localeMatcher", set("lookup", "best fit"), "best fit");
}
/* steps 2-5 */
List<String> supportedLocales;
if (matcher == null || "best fit".equals(matcher)) {
supportedLocales = BestFitSupportedLocales(availableLocales, requestedLocales);
} else {
supportedLocales = LookupSupportedLocales(availableLocales, requestedLocales);
}
/* steps 6-8 */
ArrayObject subset = ArrayCreate(cx, supportedLocales.size());
int index = 0;
for (Object value : supportedLocales) {
subset.defineOwnProperty(cx, index++, new PropertyDescriptor(value, false, true, false));
}
PropertyDescriptor nonConfigurableWritable = new PropertyDescriptor();
nonConfigurableWritable.setConfigurable(false);
nonConfigurableWritable.setWritable(false);
subset.defineOwnProperty(cx, "length", nonConfigurableWritable);
/* step 9 */
return subset;
}
Aggregations