本文整理汇总了C++中JSFunction::setConstructorClass方法的典型用法代码示例。如果您正苦于以下问题:C++ JSFunction::setConstructorClass方法的具体用法?C++ JSFunction::setConstructorClass怎么用?C++ JSFunction::setConstructorClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSFunction
的用法示例。
在下文中一共展示了JSFunction::setConstructorClass方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
JSFunction *
GlobalObject::createConstructor(JSContext *cx, Native ctor, Class *clasp, JSAtom *name,
uintN length, gc::AllocKind kind)
{
JSFunction *fun = js_NewFunction(cx, NULL, ctor, length, JSFUN_CONSTRUCTOR, this, name, kind);
if (!fun)
return NULL;
/*
* Remember the class this function is a constructor for so that we know to
* create an object of this class when we call the constructor.
*/
fun->setConstructorClass(clasp);
return fun;
}
示例2: ids
JSObject *
GlobalObject::initFunctionAndObjectClasses(JSContext *cx)
{
JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
JS_ASSERT(isNative());
/*
* Calling a function from a cleared global triggers this (yeah, I know).
* Uncomment this once bug 470510 is fixed (if that bug doesn't remove
* isCleared entirely).
*/
// JS_ASSERT(!isCleared());
/* If cx has no global object, make this the global object. */
if (!cx->globalObject)
JS_SetGlobalObject(cx, this);
/*
* Create |Object.prototype| first, mirroring CreateBlankProto but for the
* prototype of the created object.
*/
JSObject *objectProto = NewObjectWithGivenProto(cx, &ObjectClass, NULL, this);
if (!objectProto || !objectProto->setSingletonType(cx))
return NULL;
/*
* The default 'new' type of Object.prototype is required by type inference
* to have unknown properties, to simplify handling of e.g. heterogenous
* objects in JSON and script literals.
*/
if (!objectProto->setNewTypeUnknown(cx))
return NULL;
/* Create |Function.prototype| next so we can create other functions. */
JSFunction *functionProto;
{
JSObject *proto = NewObjectWithGivenProto(cx, &FunctionClass, objectProto, this);
if (!proto)
return NULL;
/*
* Bizarrely, |Function.prototype| must be an interpreted function, so
* give it the guts to be one.
*/
functionProto = js_NewFunction(cx, proto, NULL, 0, JSFUN_INTERPRETED, this, NULL);
if (!functionProto)
return NULL;
JS_ASSERT(proto == functionProto);
functionProto->flags |= JSFUN_PROTOTYPE;
JSScript *script =
JSScript::NewScript(cx, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, JSVERSION_DEFAULT);
if (!script)
return NULL;
script->noScriptRval = true;
script->code[0] = JSOP_STOP;
script->code[1] = SRC_NULL;
functionProto->initScript(script);
functionProto->getType(cx)->interpretedFunction = functionProto;
script->setFunction(functionProto);
if (!proto->setSingletonType(cx))
return NULL;
/*
* The default 'new' type of Function.prototype is required by type
* inference to have unknown properties, to simplify handling of e.g.
* CloneFunctionObject.
*/
if (!proto->setNewTypeUnknown(cx))
return NULL;
}
/* Create the Object function now that we have a [[Prototype]] for it. */
jsid objectId = ATOM_TO_JSID(CLASS_ATOM(cx, Object));
JSFunction *objectCtor;
{
JSObject *ctor = NewObjectWithGivenProto(cx, &FunctionClass, functionProto, this);
if (!ctor)
return NULL;
objectCtor = js_NewFunction(cx, ctor, js_Object, 1, JSFUN_CONSTRUCTOR, this,
JSID_TO_ATOM(objectId));
if (!objectCtor)
return NULL;
JS_ASSERT(ctor == objectCtor);
objectCtor->setConstructorClass(&ObjectClass);
}
/*
* Install |Object| and |Object.prototype| for the benefit of subsequent
* code that looks for them.
*/
setObjectClassDetails(objectCtor, objectProto);
/* Create |Function| so it and |Function.prototype| can be installed. */
jsid functionId = ATOM_TO_JSID(CLASS_ATOM(cx, Function));
JSFunction *functionCtor;
{
JSObject *ctor =
//.........这里部分代码省略.........