use of com.oracle.truffle.api.object.FinalLocationException 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.FinalLocationException in project graal by oracle.
the class DeclaredLocationTest method testDeclaredLocation.
@Test
public void testDeclaredLocation() {
DynamicObject object = shapeWithDeclared.newInstance();
Assert.assertSame(value, object.get("declared"));
object.set("declared", value);
Assert.assertSame(shapeWithDeclared, object.getShape());
Property property = object.getShape().getProperty("declared");
Assert.assertEquals(true, property.getLocation().canStore(value));
Assert.assertEquals(true, property.getLocation().canSet(value));
try {
property.set(object, value, shapeWithDeclared);
} 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, shapeWithDeclared);
Assert.fail();
} catch (FinalLocationException | IncompatibleLocationException e) {
Assert.assertTrue(e instanceof FinalLocationException);
}
Assert.assertSame(value, object.get("declared"));
}
Aggregations