test-jsid.cpp (1584B)
1 #include "gdb-tests.h" 2 3 #include "js/Id.h" // jsid, JS::PropertyKey 4 #include "js/String.h" 5 #include "js/Symbol.h" 6 7 FRAGMENT(jsid, simple) { 8 const char* chars = "moon"; 9 JS::Rooted<JSString*> string(cx, JS_NewStringCopyZ(cx, chars)); 10 JS::Rooted<JSString*> interned(cx, JS_AtomizeAndPinString(cx, chars)); 11 JS::Rooted<jsid> string_id(cx, JS::PropertyKey::fromPinnedString(interned)); 12 JS::Rooted<jsid> int_id(cx, JS::PropertyKey::Int(1729)); 13 JS::Rooted<jsid> unique_symbol_id( 14 cx, JS::PropertyKey::Symbol(JS::NewSymbol(cx, interned))); 15 JS::Rooted<jsid> registry_symbol_id( 16 cx, JS::PropertyKey::Symbol(JS::GetSymbolFor(cx, interned))); 17 JS::Rooted<jsid> well_known_symbol_id( 18 cx, JS::GetWellKnownSymbolKey(cx, JS::SymbolCode::iterator)); 19 jsid void_id = JS::PropertyKey::Void(); 20 21 breakpoint(); 22 23 use(string_id); 24 use(int_id); 25 use(unique_symbol_id); 26 use(registry_symbol_id); 27 use(well_known_symbol_id); 28 use(void_id); 29 } 30 31 void jsid_handles(JS::Handle<jsid> jsid_handle, 32 JS::MutableHandle<jsid> mutable_jsid_handle) { 33 // Prevent the linker from unifying this function with others that are 34 // equivalent in machine code but not type. 35 fprintf(stderr, "Called " __FILE__ ":jsid_handles\n"); 36 breakpoint(); 37 } 38 39 FRAGMENT(jsid, handles) { 40 const char* chars = "shovel"; 41 JS::Rooted<JSString*> string(cx, JS_NewStringCopyZ(cx, chars)); 42 JS::Rooted<JSString*> interned(cx, JS_AtomizeAndPinString(cx, chars)); 43 JS::Rooted<jsid> string_id(cx, JS::PropertyKey::fromPinnedString(interned)); 44 jsid_handles(string_id, &string_id); 45 }