test-JSObject.cpp (1491B)
1 #include "gdb-tests.h" 2 #include "jsapi.h" 3 #include "js/GlobalObject.h" 4 #include "js/Object.h" // JS::GetClass 5 6 FRAGMENT(JSObject, simple) { 7 JS::Rooted<JSObject*> glob(cx, JS::CurrentGlobalOrNull(cx)); 8 JS::Rooted<JSObject*> plain(cx, JS_NewPlainObject(cx)); 9 JS::Rooted<JSObject*> objectProto(cx, JS::GetRealmObjectPrototype(cx)); 10 JS::Rooted<JSObject*> global(cx, JS::CurrentGlobalOrNull(cx)); 11 JS::Rooted<JSObject*> func( 12 cx, (JSObject*)JS_NewFunction(cx, (JSNative)1, 0, 0, "dys")); 13 JS::Rooted<JSObject*> anon( 14 cx, (JSObject*)JS_NewFunction(cx, (JSNative)1, 0, 0, nullptr)); 15 JS::Rooted<JSFunction*> funcPtr( 16 cx, JS_NewFunction(cx, (JSNative)1, 0, 0, "formFollows")); 17 18 // JS_NewObject will now assert if you feed it a bad class name, so mangle 19 // the name after construction. 20 char namebuf[20] = "goodname"; 21 static JSClass cls{namebuf}; 22 JS::RootedObject badClassName(cx, JS_NewObject(cx, &cls)); 23 MOZ_RELEASE_ASSERT(badClassName); 24 strcpy(namebuf, "\xc7X"); 25 26 JSObject& plainRef = *plain; 27 JSFunction& funcRef = *funcPtr; 28 JSObject* plainRaw = plain; 29 JSObject* funcRaw = func; 30 31 breakpoint(); 32 33 use(glob); 34 use(plain); 35 use(objectProto); 36 use(func); 37 use(anon); 38 use(funcPtr); 39 use(&plainRef); 40 use(&funcRef); 41 use(JS::GetClass((JSObject*)&funcRef)); 42 use(plainRaw); 43 use(funcRaw); 44 } 45 46 FRAGMENT(JSObject, null) { 47 JS::Rooted<JSObject*> null(cx, nullptr); 48 JSObject* nullRaw = null; 49 50 breakpoint(); 51 52 use(null); 53 use(nullRaw); 54 }