use of com.oracle.truffle.api.object.Property in project graal by oracle.
the class LocationTest method testChangeFlagsChangeLocation.
@Test
public void testChangeFlagsChangeLocation() {
DynamicObject object = rootShape.newInstance();
object.define("foo", 42);
Location location = object.getShape().getProperty("foo").getLocation();
object.define("foo", "str", 111);
Assert.assertEquals("str", object.get("foo"));
Property newProperty = object.getShape().getProperty("foo");
Assert.assertEquals(111, newProperty.getFlags());
Location newLocation = newProperty.getLocation();
Assert.assertNotSame(location, newLocation);
}
use of com.oracle.truffle.api.object.Property in project graal by oracle.
the class LocationTest method testChangeFlagsReuseLocation.
@Test
public void testChangeFlagsReuseLocation() {
DynamicObject object = rootShape.newInstance();
object.define("foo", 42);
Location location = object.getShape().getProperty("foo").getLocation();
object.define("foo", 43, 111);
Assert.assertEquals(43, object.get("foo"));
Property newProperty = object.getShape().getProperty("foo");
Assert.assertEquals(111, newProperty.getFlags());
Location newLocation = newProperty.getLocation();
Assert.assertSame(location, newLocation);
}
use of com.oracle.truffle.api.object.Property 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.Property 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.Property in project graal by oracle.
the class LayoutStrategy method objectDefineProperty.
/**
* @since 0.17 or earlier
*/
protected void objectDefineProperty(DynamicObjectImpl object, Object key, Object value, int flags, LocationFactory locationFactory, ShapeImpl currentShape) {
ShapeImpl oldShape = currentShape;
Property oldProperty = oldShape.getProperty(key);
ShapeImpl newShape = defineProperty(oldShape, key, value, flags, locationFactory, oldProperty);
if (oldShape == newShape) {
assert oldProperty.equals(newShape.getProperty(key));
oldProperty.setSafe(object, value, oldShape);
} else {
Property newProperty = newShape.getProperty(key);
newProperty.setSafe(object, value, oldShape, newShape);
}
}
Aggregations