void js_register_cocos2dx_audioengine_AudioProfile(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_experimental_AudioProfile_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_experimental_AudioProfile_class->name = "AudioProfile"; jsb_cocos2d_experimental_AudioProfile_class->addProperty = JS_PropertyStub; jsb_cocos2d_experimental_AudioProfile_class->delProperty = JS_DeletePropertyStub; jsb_cocos2d_experimental_AudioProfile_class->getProperty = JS_PropertyStub; jsb_cocos2d_experimental_AudioProfile_class->setProperty = JS_StrictPropertyStub; jsb_cocos2d_experimental_AudioProfile_class->enumerate = JS_EnumerateStub; jsb_cocos2d_experimental_AudioProfile_class->resolve = JS_ResolveStub; jsb_cocos2d_experimental_AudioProfile_class->convert = JS_ConvertStub; jsb_cocos2d_experimental_AudioProfile_class->finalize = js_cocos2d_experimental_AudioProfile_finalize; jsb_cocos2d_experimental_AudioProfile_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_PSGS("name", js_cocos2dx_audioengine_AudioProfile_get_name, js_cocos2dx_audioengine_AudioProfile_set_name, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_PSGS("maxInstances", js_cocos2dx_audioengine_AudioProfile_get_maxInstances, js_cocos2dx_audioengine_AudioProfile_set_maxInstances, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_PSGS("minDelay", js_cocos2dx_audioengine_AudioProfile_get_minDelay, js_cocos2dx_audioengine_AudioProfile_set_minDelay, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_PS_END }; static JSFunctionSpec funcs[] = { JS_FS_END }; JSFunctionSpec *st_funcs = NULL; jsb_cocos2d_experimental_AudioProfile_prototype = JS_InitClass( cx, global, JS::NullPtr(), // parent proto jsb_cocos2d_experimental_AudioProfile_class, js_cocos2dx_audioengine_AudioProfile_constructor, 0, // constructor properties, funcs, NULL, // no static properties st_funcs); // make the class enumerable in the registered namespace // bool found; //FIXME: Removed in Firefox v27 // JS_SetPropertyAttributes(cx, global, "AudioProfile", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table TypeTest<cocos2d::experimental::AudioProfile> t; js_type_class_t *p; std::string typeName = t.s_name(); if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) { p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); p->jsclass = jsb_cocos2d_experimental_AudioProfile_class; p->proto = jsb_cocos2d_experimental_AudioProfile_prototype; p->parentProto = NULL; _js_global_type_map.insert(std::make_pair(typeName, p)); } }
namespace js { /* static */ DebuggerMemory * DebuggerMemory::create(JSContext *cx, Debugger *dbg) { Value memoryProto = dbg->object->getReservedSlot(Debugger::JSSLOT_DEBUG_MEMORY_PROTO); RootedObject memory(cx, NewObjectWithGivenProto(cx, &class_, &memoryProto.toObject(), nullptr)); if (!memory) return nullptr; dbg->object->setReservedSlot(Debugger::JSSLOT_DEBUG_MEMORY_INSTANCE, ObjectValue(*memory)); memory->setReservedSlot(JSSLOT_DEBUGGER, ObjectValue(*dbg->object)); return &memory->as<DebuggerMemory>(); } /* static */ bool DebuggerMemory::construct(JSContext *cx, unsigned argc, Value *vp) { JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_NO_CONSTRUCTOR, "Debugger.Memory"); return false; } /* static */ const Class DebuggerMemory::class_ = { "Memory", JSCLASS_HAS_PRIVATE | JSCLASS_IMPLEMENTS_BARRIERS | JSCLASS_HAS_RESERVED_SLOTS(DebuggerMemory::JSSLOT_COUNT), JS_PropertyStub, // addProperty JS_DeletePropertyStub, // delProperty JS_PropertyStub, // getProperty JS_StrictPropertyStub, // setProperty JS_EnumerateStub, // enumerate JS_ResolveStub, // resolve JS_ConvertStub, // convert nullptr, // finalize nullptr, // call nullptr, // hasInstance nullptr, // construct nullptr // trace }; /* static */ DebuggerMemory * DebuggerMemory::checkThis(JSContext *cx, CallArgs &args, const char *fnName) { const Value &thisValue = args.thisv(); if (!thisValue.isObject()) { JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_NOT_NONNULL_OBJECT); return nullptr; } JSObject &thisObject = thisValue.toObject(); if (!thisObject.is<DebuggerMemory>()) { JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO, DebuggerMemory::class_.name, fnName, thisObject.getClass()->name); return nullptr; } // Check for Debugger.Memory.prototype, which has the same class as // Debugger.Memory instances, however doesn't actually represent an instance // of Debugger.Memory. It is the only object that is<DebuggerMemory>() but // doesn't have a Debugger instance. if (thisObject.getReservedSlot(JSSLOT_DEBUGGER).isUndefined()) { JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO, DebuggerMemory::class_.name, fnName, "prototype object"); return nullptr; } return &thisObject.as<DebuggerMemory>(); } /** * Get the |DebuggerMemory *| from the current this value and handle any errors * that might occur therein. * * These parameters must already exist when calling this macro: * - JSContext *cx * - unsigned argc * - Value *vp * - const char *fnName * These parameters will be defined after calling this macro: * - CallArgs args * - DebuggerMemory *memory (will be non-null) */ #define THIS_DEBUGGER_MEMORY(cx, argc, vp, fnName, args, memory) \ CallArgs args = CallArgsFromVp(argc, vp); \ Rooted<DebuggerMemory *> memory(cx, checkThis(cx, args, fnName)); \ if (!memory) \ return false Debugger * DebuggerMemory::getDebugger() { return Debugger::fromJSObject(&getReservedSlot(JSSLOT_DEBUGGER).toObject()); } /* static */ bool DebuggerMemory::setTrackingAllocationSites(JSContext *cx, unsigned argc, Value *vp) { THIS_DEBUGGER_MEMORY(cx, argc, vp, "(set trackingAllocationSites)", args, memory); if (!args.requireAtLeast(cx, "(set trackingAllocationSites)", 1)) return false; Debugger *dbg = memory->getDebugger(); bool enabling = ToBoolean(args[0]); if (enabling == dbg->trackingAllocationSites) { // Nothing to do here... args.rval().setUndefined(); return true; } if (enabling) { for (GlobalObjectSet::Range r = dbg->debuggees.all(); !r.empty(); r.popFront()) { JSCompartment *compartment = r.front()->compartment(); if (compartment->hasObjectMetadataCallback()) { JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_OBJECT_METADATA_CALLBACK_ALREADY_SET); return false; } } } for (GlobalObjectSet::Range r = dbg->debuggees.all(); !r.empty(); r.popFront()) { if (enabling) { r.front()->compartment()->setObjectMetadataCallback(SavedStacksMetadataCallback); } else { r.front()->compartment()->forgetObjectMetadataCallback(); } } dbg->trackingAllocationSites = enabling; args.rval().setUndefined(); return true; } /* static */ bool DebuggerMemory::getTrackingAllocationSites(JSContext *cx, unsigned argc, Value *vp) { THIS_DEBUGGER_MEMORY(cx, argc, vp, "(get trackingAllocationSites)", args, memory); args.rval().setBoolean(memory->getDebugger()->trackingAllocationSites); return true; } /* static */ const JSPropertySpec DebuggerMemory::properties[] = { JS_PSGS("trackingAllocationSites", DebuggerMemory::getTrackingAllocationSites, DebuggerMemory::setTrackingAllocationSites, 0), JS_PS_END }; /* static */ const JSFunctionSpec DebuggerMemory::methods[] = { JS_FS_END }; } /* namespace js */