use of com.oracle.truffle.api.object.DynamicObject in project graal by oracle.
the class SharedShapeTest method testCannotDeleteFromSharedShape.
@Test
public void testCannotDeleteFromSharedShape() {
DynamicObject object = sharedShape.newInstance();
object.define("a", 1);
try {
object.delete("a");
Assert.fail();
} catch (UnsupportedOperationException e) {
Assert.assertEquals(1, object.get("a"));
}
}
use of com.oracle.truffle.api.object.DynamicObject 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.DynamicObject in project graal by oracle.
the class DeclaredLocationTest method testMigrateDeclaredLocation.
@Test
public void testMigrateDeclaredLocation() {
DynamicObject object = shapeWithDeclared.newInstance();
Assert.assertSame(shapeWithDeclared, object.getShape());
Assert.assertSame(value, object.get("declared"));
Object newValue = new Object();
object.set("declared", newValue);
Assert.assertNotSame(shapeWithDeclared, object.getShape());
Assert.assertSame(newValue, object.get("declared"));
}
use of com.oracle.truffle.api.object.DynamicObject 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"));
}
use of com.oracle.truffle.api.object.DynamicObject in project graal by oracle.
the class DynamicObjectFactoryTest method testFactory.
@Test
public void testFactory() {
Shape shape = rootShape.defineProperty("x", 1, 0).defineProperty("y", 2, 0);
DynamicObjectFactory factory = shape.createFactory();
try {
factory.newInstance();
Assert.fail();
} catch (AssertionError e) {
Assert.assertEquals("0 arguments given but the factory takes 2: x, y", e.getMessage());
}
try {
factory.newInstance("only one argument");
Assert.fail();
} catch (AssertionError e) {
Assert.assertEquals("1 arguments given but the factory takes 2: x, y", e.getMessage());
}
DynamicObject object = factory.newInstance(3, 4);
Assert.assertEquals(3, object.get("x"));
Assert.assertEquals(4, object.get("y"));
try {
factory.newInstance(1, 2, 3);
Assert.fail();
} catch (AssertionError e) {
Assert.assertEquals("3 arguments given but the factory takes 2: x, y", e.getMessage());
}
}
Aggregations