本文整理汇总了C++中HandleObject::getPrivate方法的典型用法代码示例。如果您正苦于以下问题:C++ HandleObject::getPrivate方法的具体用法?C++ HandleObject::getPrivate怎么用?C++ HandleObject::getPrivate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HandleObject
的用法示例。
在下文中一共展示了HandleObject::getPrivate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: id
static bool
CloneProperties(JSContext *cx, HandleObject obj, HandleObject clone, CloneMemory &clonedObjects)
{
RootedId id(cx);
RootedValue val(cx);
AutoIdVector ids(cx);
{
AutoCompartment ac(cx, obj);
if (!GetPropertyNames(cx, obj, JSITER_OWNONLY, &ids))
return false;
}
for (uint32_t i = 0; i < ids.length(); i++) {
id = ids[i];
if (!GetUnclonedValue(cx, obj, id, &val) ||
!CloneValue(cx, &val, clonedObjects) ||
!JS_DefinePropertyById(cx, clone, id, val.get(), NULL, NULL, 0))
{
return false;
}
}
if (SelfHostedClass::is(cx, obj->getClass())) {
for (uint32_t i = 0; i < JSCLASS_RESERVED_SLOTS(obj->getClass()); i++) {
val = obj->getReservedSlot(i);
if (!CloneValue(cx, &val, clonedObjects))
return false;
clone->setReservedSlot(i, val);
}
/* Privates are not cloned, so be careful! */
if (obj->hasPrivate())
clone->setPrivate(obj->getPrivate());
}
return true;
}
示例2: seg
static bool
InitExnPrivate(JSContext *cx, HandleObject exnObject, HandleString message,
HandleString filename, unsigned lineno, unsigned column,
JSErrorReport *report, int exnType)
{
JS_ASSERT(exnObject->isError());
JS_ASSERT(!exnObject->getPrivate());
JSCheckAccessOp checkAccess = cx->runtime->securityCallbacks->checkObjectAccess;
Vector<JSStackTraceStackElem> frames(cx);
{
SuppressErrorsGuard seg(cx);
for (NonBuiltinScriptFrameIter i(cx); !i.done(); ++i) {
/* Ask the crystal CAPS ball whether we can see across compartments. */
if (checkAccess && i.isNonEvalFunctionFrame()) {
RootedValue v(cx);
RootedId callerid(cx, NameToId(cx->names().caller));
RootedObject obj(cx, i.callee());
if (!checkAccess(cx, obj, callerid, JSACC_READ, &v))
break;
}
if (!frames.growBy(1))
return false;
JSStackTraceStackElem &frame = frames.back();
if (i.isNonEvalFunctionFrame()) {
RawAtom atom = i.callee()->displayAtom();
if (atom == NULL)
atom = cx->runtime->emptyString;
frame.funName = atom;
} else {
frame.funName = NULL;
}
RootedScript script(cx, i.script());
const char *cfilename = script->filename();
if (!cfilename)
cfilename = "";
frame.filename = cfilename;
frame.ulineno = PCToLineNumber(script, i.pc());
}
}
/* Do not need overflow check: the vm stack is already bigger. */
JS_STATIC_ASSERT(sizeof(JSStackTraceElem) <= sizeof(StackFrame));
size_t nbytes = offsetof(JSExnPrivate, stackElems) +
frames.length() * sizeof(JSStackTraceElem);
JSExnPrivate *priv = (JSExnPrivate *)cx->malloc_(nbytes);
if (!priv)
return false;
/* Initialize to zero so that write barriers don't witness undefined values. */
memset(priv, 0, nbytes);
if (report) {
/*
* Construct a new copy of the error report struct. We can't use the
* error report struct that was passed in, because it's allocated on
* the stack, and also because it may point to transient data in the
* TokenStream.
*/
priv->errorReport = CopyErrorReport(cx, report);
if (!priv->errorReport) {
js_free(priv);
return false;
}
} else {
priv->errorReport = NULL;
}
priv->message.init(message);
priv->filename.init(filename);
priv->lineno = lineno;
priv->column = column;
priv->stackDepth = frames.length();
priv->exnType = exnType;
for (size_t i = 0; i < frames.length(); ++i) {
priv->stackElems[i].funName.init(frames[i].funName);
priv->stackElems[i].filename = JS_strdup(cx, frames[i].filename);
if (!priv->stackElems[i].filename)
return false;
priv->stackElems[i].ulineno = frames[i].ulineno;
}
SetExnPrivate(exnObject, priv);
return true;
}
示例3: seg
static bool
InitExnPrivate(JSContext *cx, HandleObject exnObject, HandleString message,
HandleString filename, unsigned lineno, JSErrorReport *report, int exnType)
{
JS_ASSERT(exnObject->isError());
JS_ASSERT(!exnObject->getPrivate());
JSCheckAccessOp checkAccess = cx->runtime->securityCallbacks->checkObjectAccess;
Vector<JSStackTraceStackElem> frames(cx);
{
SuppressErrorsGuard seg(cx);
for (FrameRegsIter i(cx); !i.done(); ++i) {
StackFrame *fp = i.fp();
/*
* Ask the crystal CAPS ball whether we can see across compartments.
* NB: this means 'fp' may point to cross-compartment frames.
*/
if (checkAccess && fp->isNonEvalFunctionFrame()) {
Value v = NullValue();
jsid callerid = ATOM_TO_JSID(cx->runtime->atomState.callerAtom);
if (!checkAccess(cx, &fp->callee(), callerid, JSACC_READ, &v))
break;
}
if (!frames.growBy(1))
return false;
JSStackTraceStackElem &frame = frames.back();
if (fp->isNonEvalFunctionFrame())
frame.funName = fp->fun()->atom ? fp->fun()->atom : cx->runtime->emptyString;
else
frame.funName = NULL;
if (fp->isScriptFrame()) {
frame.filename = SaveScriptFilename(cx, fp->script()->filename);
if (!frame.filename)
return false;
frame.ulineno = PCToLineNumber(fp->script(), i.pc());
} else {
frame.ulineno = 0;
frame.filename = NULL;
}
}
}
/* Do not need overflow check: the vm stack is already bigger. */
JS_STATIC_ASSERT(sizeof(JSStackTraceElem) <= sizeof(StackFrame));
size_t nbytes = offsetof(JSExnPrivate, stackElems) +
frames.length() * sizeof(JSStackTraceElem);
JSExnPrivate *priv = (JSExnPrivate *)cx->malloc_(nbytes);
if (!priv)
return false;
/* Initialize to zero so that write barriers don't witness undefined values. */
memset(priv, 0, nbytes);
if (report) {
/*
* Construct a new copy of the error report struct. We can't use the
* error report struct that was passed in, because it's allocated on
* the stack, and also because it may point to transient data in the
* TokenStream.
*/
priv->errorReport = CopyErrorReport(cx, report);
if (!priv->errorReport) {
cx->free_(priv);
return false;
}
} else {
priv->errorReport = NULL;
}
priv->message.init(message);
priv->filename.init(filename);
priv->lineno = lineno;
priv->stackDepth = frames.length();
priv->exnType = exnType;
for (size_t i = 0; i < frames.length(); ++i) {
priv->stackElems[i].funName.init(frames[i].funName);
priv->stackElems[i].filename = frames[i].filename;
priv->stackElems[i].ulineno = frames[i].ulineno;
}
SetExnPrivate(cx, exnObject, priv);
return true;
}