Search in sources :

Example 1 with FinalLocationException

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"));
}
Also used : DynamicObject(com.oracle.truffle.api.object.DynamicObject) IncompatibleLocationException(com.oracle.truffle.api.object.IncompatibleLocationException) DynamicObject(com.oracle.truffle.api.object.DynamicObject) FinalLocationException(com.oracle.truffle.api.object.FinalLocationException) Property(com.oracle.truffle.api.object.Property) Test(org.junit.Test)

Example 2 with FinalLocationException

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"));
}
Also used : DynamicObject(com.oracle.truffle.api.object.DynamicObject) IncompatibleLocationException(com.oracle.truffle.api.object.IncompatibleLocationException) DynamicObject(com.oracle.truffle.api.object.DynamicObject) FinalLocationException(com.oracle.truffle.api.object.FinalLocationException) Property(com.oracle.truffle.api.object.Property) Test(org.junit.Test)

Aggregations

DynamicObject (com.oracle.truffle.api.object.DynamicObject)2 FinalLocationException (com.oracle.truffle.api.object.FinalLocationException)2 IncompatibleLocationException (com.oracle.truffle.api.object.IncompatibleLocationException)2 Property (com.oracle.truffle.api.object.Property)2 Test (org.junit.Test)2