use of com.github.anba.es6draft.runtime.types.ScriptObject 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.ScriptObject in project es6draft by anba.
the class JSONObject method SerializeJSONObject.
/**
* 24.3.2.3 Runtime Semantics: SerializeJSONObject ( value )
*
* @param cx
* the execution context
* @param serializer
* the serializer state
* @param value
* the script object
*/
private static void SerializeJSONObject(ExecutionContext cx, JSONSerializer serializer, ScriptObject value) {
/* steps 1-2 */
if (!serializer.stack.add(value)) {
throw newTypeError(cx, Messages.Key.JSONCyclicValue);
}
/* steps 3-4 (not applicable) */
/* steps 5-6 */
Iterable<String> k;
if (serializer.propertyList != null) {
k = serializer.propertyList;
} else {
k = EnumerableOwnNames(cx, value);
}
/* step 7 (not applicable) */
/* steps 8-10 */
boolean isEmpty = true;
String gap = serializer.gap;
StringBuilder result = serializer.result;
result.append('{');
serializer.level += 1;
for (String p : k) {
// Inlined: SerializeJSONProperty
Object v = Get(cx, value, p);
v = TransformJSONValue(cx, serializer, value, p, v);
if (!IsJSONSerializable(v)) {
continue;
}
if (!isEmpty) {
result.append(',');
}
isEmpty = false;
if (!gap.isEmpty()) {
indent(serializer, result);
}
QuoteJSONString(result, p);
result.append(':');
if (!gap.isEmpty()) {
result.append(' ');
}
SerializeJSONValue(cx, serializer, v);
}
serializer.level -= 1;
if (!isEmpty && !gap.isEmpty()) {
indent(serializer, result);
}
result.append('}');
/* step 11 */
serializer.stack.remove(value);
/* steps 12-13 (not applicable) */
}
use of com.github.anba.es6draft.runtime.types.ScriptObject 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.ScriptObject in project es6draft by anba.
the class ObjectConstructor method construct.
/**
* 19.1.1.1 Object ( [ value ] )
*/
@Override
public ScriptObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object value = argument(args, 0);
/* step 1 */
if (newTarget != this) {
return OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.ObjectPrototype);
}
/* step 2 */
if (Type.isUndefinedOrNull(value)) {
// (= `this`) is not the intrinsic %Object% constructor function.
return OrdinaryCreateFromConstructor(calleeContext, this, Intrinsics.ObjectPrototype);
}
/* step 3 */
return ToObject(calleeContext, value);
}
use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class ObjectConstructor method GetOwnPropertyNames.
/**
* 19.1.2.8.1 Runtime Semantics: GetOwnPropertyKeys ( O, Type ), with Type = String
*
* @param cx
* the execution context
* @param o
* the script object
* @return the own string-valued property keys of <var>o</var>
*/
public static ArrayObject GetOwnPropertyNames(ExecutionContext cx, Object o) {
/* steps 1-2 */
ScriptObject obj = ToObject(cx, o);
/* steps 3-4 */
List<?> keys = obj.ownPropertyKeys(cx);
/* step 5 */
int initialSize = Math.min(32, keys.size());
ArrayList<String> nameList = new ArrayList<>(initialSize);
/* step 6 */
for (Object key : keys) {
if (key instanceof String) {
nameList.add((String) key);
}
}
/* step 7 */
return CreateArrayFromList(cx, nameList);
}
Aggregations