use of com.oracle.truffle.api.object.Location in project graal by oracle.
the class LocationTest method testUnrelatedPrimitivesGoToObject.
@Test
public void testUnrelatedPrimitivesGoToObject() {
DynamicObject object = rootShape.newInstance();
object.define("foo", 42L);
Location location1 = object.getShape().getProperty("foo").getLocation();
Assert.assertEquals(long.class, getLocationType(location1));
DOTestAsserts.assertLocationFields(location1, 1, 0);
DOTestAsserts.assertShapeFields(object, 1, 0);
object.set("foo", 3.14);
Location location2 = object.getShape().getProperty("foo").getLocation();
Assert.assertEquals(Object.class, getLocationType(location2));
DOTestAsserts.assertLocationFields(location2, 0, 1);
DOTestAsserts.assertShapeFields(object, 1, 1);
}
use of com.oracle.truffle.api.object.Location 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.Location in project graal by oracle.
the class LocationTest method testOnlyObjectLocationForObject.
@Test
public void testOnlyObjectLocationForObject() {
DynamicObject object = rootShape.newInstance();
object.define("obj", new Object());
Location location = object.getShape().getProperty("obj").getLocation();
Assert.assertTrue(location instanceof ObjectLocation);
DOTestAsserts.assertLocationFields(location, 0, 1);
DOTestAsserts.assertShapeFields(object, 0, 1);
}
use of com.oracle.truffle.api.object.Location in project graal by oracle.
the class LocationTest method testDeleteDeclaredProperty.
@Test
public void testDeleteDeclaredProperty() {
DynamicObject object = rootShape.newInstance();
object.define("a", new Object(), 0, new LocationFactory() {
public Location createLocation(Shape shape, Object value) {
return shape.allocator().declaredLocation(value);
}
});
Assert.assertTrue(object.containsKey("a"));
object.define("a", 42);
Assert.assertEquals(1, object.getShape().getPropertyCount());
object.delete("a");
Assert.assertFalse(object.containsKey("a"));
}
use of com.oracle.truffle.api.object.Location in project graal by oracle.
the class SharedShapeTest method testReuseReplaceProperty.
@Test
public void testReuseReplaceProperty() {
DynamicObject object = sharedShape.newInstance();
object.define("a", 1);
Location location1 = object.getShape().getProperty("a").getLocation();
object.define("a", 2, 42);
Location location2 = object.getShape().getProperty("a").getLocation();
DOTestAsserts.assertSameLocation(location1, location2);
}
Aggregations