use of com.oracle.truffle.api.object.IncompatibleLocationException 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.IncompatibleLocationException 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.IncompatibleLocationException in project graal by oracle.
the class ConstantLocationTest method testAddConstantLocation.
@Test
public void testAddConstantLocation() {
Property property = shapeWithConstant.getProperty("constant");
DynamicObject object = rootShape.newInstance();
property.setSafe(object, value, rootShape, shapeWithConstant);
Assert.assertSame(shapeWithConstant, object.getShape());
Assert.assertSame(value, object.get("constant"));
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, shapeWithConstant);
Assert.fail();
} catch (IncompatibleLocationException e) {
// Expected
}
Assert.assertSame(rootShape, object2.getShape());
Assert.assertEquals(false, object2.containsKey("constant"));
}
use of com.oracle.truffle.api.object.IncompatibleLocationException 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