| 1 |
# flake8: noqa: F821 |
| 2 |
import re |
| 3 |
|
| 4 |
test.compile("source.cpp") |
| 5 |
test.computeGCTypes() |
| 6 |
body = test.process_body(test.load_db_entry("src_body", re.compile(r"root_arg"))[0]) |
| 7 |
|
| 8 |
# Rendering positive and negative integers |
| 9 |
marker1 = body.assignment_line("MARKER1") |
| 10 |
equal(body.edge_from_line(marker1 + 2)["Exp"][1]["String"], "1") |
| 11 |
equal(body.edge_from_line(marker1 + 3)["Exp"][1]["String"], "-1") |
| 12 |
|
| 13 |
equal(body.edge_from_point(body.assignment_point("u1"))["Exp"][1]["String"], "1") |
| 14 |
equal( |
| 15 |
body.edge_from_point(body.assignment_point("u2"))["Exp"][1]["String"], "4294967295" |
| 16 |
) |
| 17 |
|
| 18 |
assert "obj" in body["Variables"] |
| 19 |
assert "random" in body["Variables"] |
| 20 |
assert "other1" in body["Variables"] |
| 21 |
assert "other2" in body["Variables"] |
| 22 |
|
| 23 |
# Test function annotations |
| 24 |
js_GC = test.process_body(test.load_db_entry("src_body", re.compile(r"js_GC"))[0]) |
| 25 |
annotations = js_GC["Variables"]["void js_GC()"]["Annotation"] |
| 26 |
assert annotations |
| 27 |
found_call_annotate = False |
| 28 |
for annotation in annotations: |
| 29 |
(annType, value) = annotation["Name"] |
| 30 |
if annType == "annotate" and value == "GC Call": |
| 31 |
found_call_annotate = True |
| 32 |
assert found_call_annotate |
| 33 |
|
| 34 |
# Test type annotations |
| 35 |
|
| 36 |
# js::gc::Cell first |
| 37 |
cell = test.load_db_entry("src_comp", "js::gc::Cell")[0] |
| 38 |
assert cell["Kind"] == "Struct" |
| 39 |
annotations = cell["Annotation"] |
| 40 |
assert len(annotations) == 1 |
| 41 |
(tag, value) = annotations[0]["Name"] |
| 42 |
assert tag == "annotate" |
| 43 |
assert value == "GC Thing" |
| 44 |
|
| 45 |
# Check JSObject inheritance. |
| 46 |
JSObject = test.load_db_entry("src_comp", "JSObject")[0] |
| 47 |
bases = [b["Base"] for b in JSObject["CSUBaseClass"]] |
| 48 |
assert "js::gc::Cell" in bases |
| 49 |
assert "Bogon" in bases |
| 50 |
assert len(bases) == 2 |
| 51 |
|
| 52 |
# Check type analysis |
| 53 |
gctypes = test.load_gcTypes() |
| 54 |
assert "js::gc::Cell" in gctypes["GCThings"] |
| 55 |
assert "JustACell" in gctypes["GCThings"] |
| 56 |
assert "JSObject" in gctypes["GCThings"] |
| 57 |
assert "SpecialObject" in gctypes["GCThings"] |
| 58 |
assert "UnrootedPointer" in gctypes["GCPointers"] |
| 59 |
assert "Bogon" not in gctypes["GCThings"] |
| 60 |
assert "Bogon" not in gctypes["GCPointers"] |
| 61 |
assert "ErrorResult" not in gctypes["GCPointers"] |
| 62 |
assert "OkContainer" not in gctypes["GCPointers"] |
| 63 |
assert "class Rooted<JSObject*>" not in gctypes["GCPointers"] |