本文整理汇总了C++中JSFunction::setReservedSlot方法的典型用法代码示例。如果您正苦于以下问题:C++ JSFunction::setReservedSlot方法的具体用法?C++ JSFunction::setReservedSlot怎么用?C++ JSFunction::setReservedSlot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSFunction
的用法示例。
在下文中一共展示了JSFunction::setReservedSlot方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetExceptionProtoKey
static JSObject *
InitErrorClass(JSContext *cx, GlobalObject *global, intN type, JSObject &proto)
{
JSProtoKey key = GetExceptionProtoKey(type);
JSAtom *name = cx->runtime->atomState.classAtoms[key];
JSObject *errorProto = global->createBlankPrototypeInheriting(cx, &ErrorClass, proto);
if (!errorProto)
return NULL;
Value empty = StringValue(cx->runtime->emptyString);
jsid nameId = ATOM_TO_JSID(cx->runtime->atomState.nameAtom);
jsid messageId = ATOM_TO_JSID(cx->runtime->atomState.messageAtom);
jsid fileNameId = ATOM_TO_JSID(cx->runtime->atomState.fileNameAtom);
jsid lineNumberId = ATOM_TO_JSID(cx->runtime->atomState.lineNumberAtom);
if (!DefineNativeProperty(cx, errorProto, nameId, StringValue(name),
JS_PropertyStub, JS_StrictPropertyStub, 0, 0, 0) ||
!DefineNativeProperty(cx, errorProto, messageId, empty,
JS_PropertyStub, JS_StrictPropertyStub, 0, 0, 0) ||
!DefineNativeProperty(cx, errorProto, fileNameId, empty,
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_ENUMERATE, 0, 0) ||
!DefineNativeProperty(cx, errorProto, lineNumberId, Int32Value(0),
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_ENUMERATE, 0, 0))
{
return NULL;
}
/* Create the corresponding constructor. */
JSFunction *ctor = global->createConstructor(cx, Exception, &ErrorClass, name, 1);
if (!ctor)
return NULL;
ctor->setReservedSlot(JSSLOT_ERROR_EXNTYPE, Int32Value(int32(type)));
if (!LinkConstructorAndPrototype(cx, ctor, errorProto))
return NULL;
if (!DefineConstructorAndPrototype(cx, global, key, ctor, errorProto))
return NULL;
JS_ASSERT(!errorProto->getPrivate());
return errorProto;
}