Debian Codegraph @

js/src/gdb/tests/test-Root.cpp

raw
1 #include "gdb-tests.h"
2
3 #include "jsapi.h"
4
5 #include "gc/Barrier.h"
6 #include "js/Array.h" // JS::NewArrayObject
7 #include "js/GlobalObject.h"
8 #include "js/ValueArray.h"
9 #include "vm/JSFunction.h"
10
11 using namespace js;
12
13 FRAGMENT(Root, null) {
14 JS::Rooted<JSObject*> null(cx, nullptr);
15
16 breakpoint();
17
18 use(null);
19 }
20
21 void callee(JS::Handle<JSObject*> obj,
22 JS::MutableHandle<JSObject*> mutableObj) {
23 // Prevent the linker from unifying this function with others that are
24 // equivalent in machine code but not type.
25 fprintf(stderr, "Called " __FILE__ ":callee\n");
26 breakpoint();
27 }
28
29 FRAGMENT(Root, handle) {
30 JS::Rooted<JSObject*> global(cx, JS::CurrentGlobalOrNull(cx));
31 callee(global, &global);
32 use(global);
33 }
34
35 FRAGMENT(Root, HeapSlot) {
36 JS::Rooted<JS::Value> plinth(
37 cx, JS::StringValue(JS_NewStringCopyZ(cx, "plinth")));
38 JS::Rooted<JSObject*> array(
39 cx, JS::NewArrayObject(cx, JS::HandleValueArray(plinth)));
40
41 breakpoint();
42
43 use(plinth);
44 use(array);
45 }
46
47 FRAGMENT(Root, barriers) {
48 JSObject* obj = JS_NewPlainObject(cx);
49 PreBarriered<JSObject*> prebarriered(obj);
50 GCPtr<JSObject*> heapptr(obj);
51 HeapPtr<JSObject*> relocatable(obj);
52
53 JS::Value val = JS::ObjectValue(*obj);
54 PreBarriered<JS::Value> prebarrieredValue(JS::ObjectValue(*obj));
55 GCPtr<JS::Value> heapValue(JS::ObjectValue(*obj));
56 HeapPtr<JS::Value> relocatableValue(JS::ObjectValue(*obj));
57
58 breakpoint();
59
60 use(prebarriered);
61 use(heapptr);
62 use(relocatable);
63 use(val);
64 use(prebarrieredValue);
65 use(heapValue);
66 use(relocatableValue);
67 }