本文整理汇总了C++中HandleValue::isNullOrUndefined方法的典型用法代码示例。如果您正苦于以下问题:C++ HandleValue::isNullOrUndefined方法的具体用法?C++ HandleValue::isNullOrUndefined怎么用?C++ HandleValue::isNullOrUndefined使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HandleValue
的用法示例。
在下文中一共展示了HandleValue::isNullOrUndefined方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: selfHostedObject
static bool
CloneValue(JSContext *cx, HandleValue selfHostedValue, MutableHandleValue vp)
{
if (selfHostedValue.isObject()) {
RootedObject selfHostedObject(cx, &selfHostedValue.toObject());
JSObject *clone = CloneObject(cx, selfHostedObject);
if (!clone)
return false;
vp.setObject(*clone);
} else if (selfHostedValue.isBoolean() || selfHostedValue.isNumber() || selfHostedValue.isNullOrUndefined()) {
// Nothing to do here: these are represented inline in the value.
vp.set(selfHostedValue);
} else if (selfHostedValue.isString()) {
if (!selfHostedValue.toString()->isFlat())
MOZ_CRASH();
JSFlatString *selfHostedString = &selfHostedValue.toString()->asFlat();
JSString *clone = CloneString(cx, selfHostedString);
if (!clone)
return false;
vp.setString(clone);
} else {
MOZ_CRASH("Self-hosting CloneValue can't clone given value.");
}
return true;
}
示例2: selfHostedObject
static bool
CloneValue(JSContext *cx, HandleValue selfHostedValue, MutableHandleValue vp)
{
if (selfHostedValue.isObject()) {
RootedNativeObject selfHostedObject(cx, &selfHostedValue.toObject().as<NativeObject>());
JSObject *clone = CloneObject(cx, selfHostedObject);
if (!clone)
return false;
vp.setObject(*clone);
} else if (selfHostedValue.isBoolean() || selfHostedValue.isNumber() || selfHostedValue.isNullOrUndefined()) {
// Nothing to do here: these are represented inline in the value.
vp.set(selfHostedValue);
} else if (selfHostedValue.isString()) {
if (!selfHostedValue.toString()->isFlat())
MOZ_CRASH();
JSFlatString *selfHostedString = &selfHostedValue.toString()->asFlat();
JSString *clone = CloneString(cx, selfHostedString);
if (!clone)
return false;
vp.setString(clone);
} else if (selfHostedValue.isSymbol()) {
// Well-known symbols are shared.
mozilla::DebugOnly<JS::Symbol *> sym = selfHostedValue.toSymbol();
MOZ_ASSERT(sym->isWellKnownSymbol());
MOZ_ASSERT(cx->wellKnownSymbols().get(size_t(sym->code())) == sym);
vp.set(selfHostedValue);
} else {
MOZ_CRASH("Self-hosting CloneValue can't clone given value.");
}
return true;
}
示例3: CallArgsFromVp
static bool
ProtoSetter(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
HandleValue thisv = args.thisv();
if (thisv.isNullOrUndefined()) {
ReportIncompatible(cx, args);
return false;
}
if (thisv.isPrimitive()) {
// Mutating a boxed primitive's [[Prototype]] has no side effects.
args.rval().setUndefined();
return true;
}
if (!cx->runningWithTrustedPrincipals())
++sSetProtoCalled;
Rooted<JSObject*> obj(cx, &args.thisv().toObject());
/* Do nothing if __proto__ isn't being set to an object or null. */
if (args.length() == 0 || !args[0].isObjectOrNull()) {
args.rval().setUndefined();
return true;
}
Rooted<JSObject*> newProto(cx, args[0].toObjectOrNull());
if (!SetPrototype(cx, obj, newProto))
return false;
args.rval().setUndefined();
return true;
}
示例4: ToString
bool
xpc_qsJsvalToCharStr(JSContext *cx, HandleValue v, JSAutoByteString *bytes)
{
MOZ_ASSERT(!bytes->ptr());
if (v.isNullOrUndefined())
return true;
JSString *str = ToString(cx, v);
if (!str)
return false;
return !!bytes->encodeLatin1(cx, str);
}
示例5:
static bool
TestProtoSetterThis(HandleValue v)
{
if (v.isNullOrUndefined())
return false;
/* These will work as if on a boxed primitive; dumb, but whatever. */
if (!v.isObject())
return true;
/* Otherwise, only accept non-proxies. */
return !v.toObject().is<ProxyObject>();
}
示例6: obj
static bool
ProtoGetter(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
HandleValue thisv = args.thisv();
if (thisv.isNullOrUndefined()) {
ReportIncompatible(cx, args);
return false;
}
if (thisv.isPrimitive() && !BoxNonStrictThis(cx, args))
return false;
RootedObject obj(cx, &args.thisv().toObject());
RootedObject proto(cx);
if (!GetPrototype(cx, obj, &proto))
return false;
args.rval().setObjectOrNull(proto);
return true;
}
示例7: callee
static bool
ProtoSetter(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
// Do this here, rather than after the this-check so even likely-buggy
// use of the __proto__ setter on unacceptable values, where no subsequent
// use occurs on an acceptable value, will trigger a warning.
RootedObject callee(cx, &args.callee());
if (!GlobalObject::warnOnceAboutPrototypeMutation(cx, callee))
return false;
HandleValue thisv = args.thisv();
if (thisv.isNullOrUndefined()) {
ReportIncompatible(cx, args);
return false;
}
if (thisv.isPrimitive()) {
// Mutating a boxed primitive's [[Prototype]] has no side effects.
args.rval().setUndefined();
return true;
}
if (!cx->runningWithTrustedPrincipals())
++sSetProtoCalled;
Rooted<JSObject*> obj(cx, &args.thisv().toObject());
/* Do nothing if __proto__ isn't being set to an object or null. */
if (args.length() == 0 || !args[0].isObjectOrNull()) {
args.rval().setUndefined();
return true;
}
Rooted<JSObject*> newProto(cx, args[0].toObjectOrNull());
if (!SetPrototype(cx, obj, newProto))
return false;
args.rval().setUndefined();
return true;
}
示例8: obj
static bool
ProtoSetterImpl(JSContext *cx, CallArgs args)
{
JS_ASSERT(TestProtoThis(args.thisv()));
HandleValue thisv = args.thisv();
if (thisv.isPrimitive()) {
JS_ASSERT(!thisv.isNullOrUndefined());
// Mutating a boxed primitive's [[Prototype]] has no side effects.
args.rval().setUndefined();
return true;
}
if (!cx->runningWithTrustedPrincipals())
++sSetProtoCalled;
Rooted<JSObject*> obj(cx, &args.thisv().toObject());
/* Do nothing if __proto__ isn't being set to an object or null. */
if (args.length() == 0 || !args[0].isObjectOrNull()) {
args.rval().setUndefined();
return true;
}
Rooted<JSObject*> newProto(cx, args[0].toObjectOrNull());
bool success;
if (!JSObject::setProto(cx, obj, newProto, &success))
return false;
if (!success) {
js_ReportValueError(cx, JSMSG_SETPROTOTYPEOF_FAIL, JSDVG_IGNORE_STACK, thisv, js::NullPtr());
return false;
}
args.rval().setUndefined();
return true;
}
示例9:
static bool
TestProtoThis(HandleValue v)
{
return !v.isNullOrUndefined();
}
示例10: nid
static bool
ProtoSetterImpl(JSContext *cx, CallArgs args)
{
JS_ASSERT(TestProtoSetterThis(args.thisv()));
HandleValue thisv = args.thisv();
if (thisv.isPrimitive()) {
JS_ASSERT(!thisv.isNullOrUndefined());
// Mutating a boxed primitive's [[Prototype]] has no side effects.
args.rval().setUndefined();
return true;
}
if (!cx->runningWithTrustedPrincipals())
++sSetProtoCalled;
Rooted<JSObject*> obj(cx, &args.thisv().toObject());
/* ES5 8.6.2 forbids changing [[Prototype]] if not [[Extensible]]. */
bool extensible;
if (!JSObject::isExtensible(cx, obj, &extensible))
return false;
if (!extensible) {
obj->reportNotExtensible(cx);
return false;
}
/*
* Disallow mutating the [[Prototype]] of a proxy that wasn't simply
* wrapping some other object. Also disallow it on ArrayBuffer objects,
* which due to their complicated delegate-object shenanigans can't easily
* have a mutable [[Prototype]].
*/
if (obj->is<ProxyObject>() || obj->is<ArrayBufferObject>()) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
"Object", "__proto__ setter",
obj->is<ProxyObject>() ? "Proxy" : "ArrayBuffer");
return false;
}
/* Do nothing if __proto__ isn't being set to an object or null. */
if (args.length() == 0 || !args[0].isObjectOrNull()) {
args.rval().setUndefined();
return true;
}
Rooted<JSObject*> newProto(cx, args[0].toObjectOrNull());
unsigned dummy;
RootedId nid(cx, NameToId(cx->names().proto));
RootedValue v(cx);
if (!CheckAccess(cx, obj, nid, JSAccessMode(JSACC_PROTO | JSACC_WRITE), &v, &dummy))
return false;
if (!SetClassAndProto(cx, obj, obj->getClass(), newProto, true))
return false;
args.rval().setUndefined();
return true;
}