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, 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.PropertyDescriptor 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.PropertyDescriptor in project es6draft by anba.
the class JSONParser method jsonObject.
/**
* <pre>
* JSONObject :
* { }
* { JSONMemberList }
* JSONMemberList :
* JSONMember
* JSONMemberList , JSONMember
* JSONMember :
* JSONString : JSONValue
* </pre>
*
* @return the script object represented by the JSON object
*/
private OrdinaryObject jsonObject() {
OrdinaryObject object = ObjectCreate(cx, Intrinsics.ObjectPrototype);
consume(Token.LC);
if (token() != Token.RC) {
for (; ; ) {
consume(Token.STRING);
String name = ts.getString();
consume(Token.COLON);
Object value = jsonValue();
object.defineOwnProperty(cx, name, new PropertyDescriptor(value, true, true, true));
if (token() == Token.RC) {
break;
}
consume(Token.COMMA);
}
}
consume(Token.RC);
return object;
}
use of com.github.anba.es6draft.runtime.types.PropertyDescriptor in project es6draft by anba.
the class JSONParser method jsonArray.
/**
* <pre>
* JSONArray :
* [ ]
* [ JSONElementList ]
* JSONElementList :
* JSONValue
* JSONElementList , JSONValue
* </pre>
*
* @return the script object represented by the JSON array
*/
private ArrayObject jsonArray() {
ArrayObject array = ArrayCreate(cx, 0);
consume(Token.LB);
if (token() != Token.RB) {
for (long index = 0; ; ) {
Object value = jsonValue();
array.defineOwnProperty(cx, index++, new PropertyDescriptor(value, true, true, true));
if (token() == Token.RB) {
break;
}
consume(Token.COMMA);
}
}
consume(Token.RB);
return array;
}
use of com.github.anba.es6draft.runtime.types.PropertyDescriptor in project es6draft by anba.
the class Realm method SetDefaultGlobalBindings.
/**
* 8.2.4 SetDefaultGlobalBindings ( realmRec )
* <p>
* Initializes {@code [[globalObject]]} with the default properties of the Global Object.
*
* @param cx
* the execution context
* @param realm
* the realm instance
* @return the global object
*/
public static ScriptObject SetDefaultGlobalBindings(ExecutionContext cx, Realm realm) {
/* step 1 */
ScriptObject globalObject = realm.getGlobalObject();
GlobalObject globalTemplate = realm.getGlobalObjectTemplate();
assert globalObject != null && globalTemplate != null;
/* step 2 */
for (Object key : globalTemplate.ownPropertyKeys(cx)) {
Property prop = globalTemplate.getOwnProperty(cx, key);
if (prop != null) {
PropertyDescriptor desc = prop.toPropertyDescriptor();
DefinePropertyOrThrow(cx, globalObject, key, desc);
}
}
/* step 3 */
return globalObject;
}
Aggregations