use of com.oracle.truffle.api.object.Property in project graal by oracle.
the class ConstantLocationTest method testConstantLocation.
@Test
public void testConstantLocation() {
DynamicObject object = shapeWithConstant.newInstance();
Assert.assertSame(value, object.get("constant"));
object.set("constant", value);
Assert.assertSame(shapeWithConstant, object.getShape());
Property property = object.getShape().getProperty("constant");
Assert.assertEquals(true, property.getLocation().canStore(value));
Assert.assertEquals(true, property.getLocation().canSet(value));
try {
property.set(object, value, shapeWithConstant);
} catch (IncompatibleLocationException | FinalLocationException e) {
Assert.fail(e.getMessage());
}
Object newValue = new Object();
Assert.assertEquals(false, property.getLocation().canStore(newValue));
Assert.assertEquals(false, property.getLocation().canSet(newValue));
try {
property.set(object, newValue, shapeWithConstant);
Assert.fail();
} catch (FinalLocationException | IncompatibleLocationException e) {
Assert.assertTrue(e instanceof FinalLocationException);
}
Assert.assertSame(value, object.get("constant"));
}
use of com.oracle.truffle.api.object.Property in project graal by oracle.
the class DeclaredLocationTest method testAddDeclaredLocation.
@Test
public void testAddDeclaredLocation() {
Property property = shapeWithDeclared.getProperty("declared");
DynamicObject object = rootShape.newInstance();
property.setSafe(object, value, rootShape, shapeWithDeclared);
Assert.assertSame(shapeWithDeclared, object.getShape());
Assert.assertSame(value, object.get("declared"));
DynamicObject object2 = rootShape.newInstance();
Object newValue = new Object();
Assert.assertEquals(false, property.getLocation().canStore(newValue));
Assert.assertEquals(false, property.getLocation().canSet(newValue));
try {
property.set(object2, newValue, rootShape, shapeWithDeclared);
Assert.fail();
} catch (IncompatibleLocationException e) {
// Expected
}
Assert.assertSame(rootShape, object2.getShape());
Assert.assertEquals(false, object2.containsKey("declared"));
}
use of com.oracle.truffle.api.object.Property in project graal by oracle.
the class ConsListPropertyMap method getEquals.
private Property getEquals(Object key) {
for (ConsListPropertyMap current = this; !current.isEmpty(); current = current.getParentMap()) {
Property p = current.getLastProperty();
Object pKey = p.getKey();
if (pKey == key || pKey.equals(key)) {
return p;
}
}
return null;
}
use of com.oracle.truffle.api.object.Property in project graal by oracle.
the class DynamicObjectImpl method delete.
/**
* @since 0.17 or earlier
*/
@Override
@TruffleBoundary
public boolean delete(Object key) {
ShapeImpl oldShape = getShape();
Property existing = oldShape.getProperty(key);
if (existing != null) {
oldShape.getLayout().getStrategy().objectRemoveProperty(this, existing, oldShape);
return true;
} else {
return false;
}
}
use of com.oracle.truffle.api.object.Property in project graal by oracle.
the class SLWritePropertyCacheNode method lookupLocation.
/**
* Try to find the given property in the shape.
*/
protected static Location lookupLocation(Shape shape, Object name) {
CompilerAsserts.neverPartOfCompilation();
Property property = shape.getProperty(name);
if (property == null) {
/* Property does not exist yet, so a shape change is necessary. */
return null;
}
return property.getLocation();
}
Aggregations