本文整理汇总了C++中MutableHandleValue::set方法的典型用法代码示例。如果您正苦于以下问题:C++ MutableHandleValue::set方法的具体用法?C++ MutableHandleValue::set怎么用?C++ MutableHandleValue::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MutableHandleValue
的用法示例。
在下文中一共展示了MutableHandleValue::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 = js_NewStringCopyN<CanGC>(cx,
selfHostedString->chars(),
selfHostedString->length());
if (!clone)
return false;
vp.setString(clone);
} else {
MOZ_CRASH("Self-hosting CloneValue can't clone given value.");
}
return true;
}
示例2:
bool
CreateThis(JSContext *cx, HandleObject callee, MutableHandleValue rval)
{
rval.set(MagicValue(JS_IS_CONSTRUCTING));
if (callee->isFunction()) {
JSFunction *fun = callee->toFunction();
if (fun->isInterpreted()) {
JSScript *script = fun->getOrCreateScript(cx);
if (!script || !script->ensureHasTypes(cx))
return false;
rval.set(ObjectValue(*CreateThisForFunction(cx, callee, false)));
}
}
return true;
}
示例3: ToPrimitive
/*
* Wrapper forwards this call directly to the wrapped object for efficiency
* and transparency. In particular, the hint is needed to properly stringify
* Date objects in certain cases - see bug 646129. Note also the
* SecurityWrapper overrides this trap to avoid information leaks. See bug
* 720619.
*/
bool
Wrapper::defaultValue(JSContext *cx, HandleObject proxy, JSType hint, MutableHandleValue vp)
{
vp.set(ObjectValue(*proxy->as<ProxyObject>().target()));
if (hint == JSTYPE_VOID)
return ToPrimitive(cx, vp);
return ToPrimitive(cx, hint, vp);
}
示例4: global
bool
JavaScriptShared::toValue(JSContext *cx, const JSVariant &from, MutableHandleValue to)
{
switch (from.type()) {
case JSVariant::Tvoid_t:
to.set(UndefinedValue());
return true;
case JSVariant::Tuint64_t:
{
ObjectId id = from.get_uint64_t();
if (id) {
JSObject *obj = unwrap(cx, id);
if (!obj)
return false;
to.set(ObjectValue(*obj));
} else {
to.set(JSVAL_NULL);
}
return true;
}
case JSVariant::Tdouble:
to.set(JS_NumberValue(from.get_double()));
return true;
case JSVariant::Tbool:
to.set(BOOLEAN_TO_JSVAL(from.get_bool()));
return true;
case JSVariant::TnsString:
{
const nsString &old = from.get_nsString();
JSString *str = JS_NewUCStringCopyN(cx, old.BeginReading(), old.Length());
if (!str)
return false;
to.set(StringValue(str));
return true;
}
case JSVariant::TJSIID:
{
nsID iid;
const JSIID &id = from.get_JSIID();
ConvertID(id, &iid);
JSCompartment *compartment = GetContextCompartment(cx);
RootedObject global(cx, JS_GetGlobalForCompartmentOrNull(cx, compartment));
JSObject *obj = xpc_NewIDObject(cx, global, iid);
if (!obj)
return false;
to.set(ObjectValue(*obj));
return true;
}
default:
return false;
}
}
示例5: metadata
bool
DebugState::getGlobal(Instance& instance, uint32_t globalIndex, MutableHandleValue vp)
{
const GlobalDesc& global = metadata().globals[globalIndex];
if (global.isConstant()) {
Val value = global.constantValue();
switch (value.type()) {
case ValType::I32:
vp.set(Int32Value(value.i32()));
break;
case ValType::I64:
// Just display as a Number; it's ok if we lose some precision
vp.set(NumberValue((double)value.i64()));
break;
case ValType::F32:
vp.set(NumberValue(JS::CanonicalizeNaN(value.f32())));
break;
case ValType::F64:
vp.set(NumberValue(JS::CanonicalizeNaN(value.f64())));
break;
default:
MOZ_CRASH("Global constant type");
}
return true;
}
uint8_t* globalData = instance.globalData();
void* dataPtr = globalData + global.offset();
switch (global.type()) {
case ValType::I32: {
vp.set(Int32Value(*static_cast<int32_t*>(dataPtr)));
break;
}
case ValType::I64: {
// Just display as a Number; it's ok if we lose some precision
vp.set(NumberValue((double)*static_cast<int64_t*>(dataPtr)));
break;
}
case ValType::F32: {
vp.set(NumberValue(JS::CanonicalizeNaN(*static_cast<float*>(dataPtr))));
break;
}
case ValType::F64: {
vp.set(NumberValue(JS::CanonicalizeNaN(*static_cast<double*>(dataPtr))));
break;
}
default:
MOZ_CRASH("Global variable type");
break;
}
return true;
}
示例6: get
bool BaseProxyHandler::get(JSContext* cx, HandleObject proxy,
HandleValue receiver, HandleId id,
MutableHandleValue vp) const {
assertEnteredPolicy(cx, proxy, id, GET);
// This method is not covered by any spec, but we follow ES 2016
// (January 21, 2016) 9.1.8 fairly closely.
// Step 2. (Step 1 is a superfluous assertion.)
Rooted<PropertyDescriptor> desc(cx);
if (!getOwnPropertyDescriptor(cx, proxy, id, &desc)) {
return false;
}
desc.assertCompleteIfFound();
// Step 3.
if (!desc.object()) {
// The spec calls this variable "parent", but that word has weird
// connotations in SpiderMonkey, so let's go with "proto".
// Step 3.a.
RootedObject proto(cx);
if (!GetPrototype(cx, proxy, &proto)) {
return false;
}
// Step 3.b.
if (!proto) {
vp.setUndefined();
return true;
}
// Step 3.c.
return GetProperty(cx, proto, receiver, id, vp);
}
// Step 4.
if (desc.isDataDescriptor()) {
vp.set(desc.value());
return true;
}
// Step 5.
MOZ_ASSERT(desc.isAccessorDescriptor());
RootedObject getter(cx, desc.getterObject());
// Step 6.
if (!getter) {
vp.setUndefined();
return true;
}
// Step 7.
RootedValue getterFunc(cx, ObjectValue(*getter));
return CallGetter(cx, receiver, getterFunc, vp);
}
示例7: CreateThisForFunction
bool
CreateThis(JSContext *cx, HandleObject callee, MutableHandleValue rval)
{
rval.set(MagicValue(JS_IS_CONSTRUCTING));
if (callee->is<JSFunction>()) {
JSFunction *fun = &callee->as<JSFunction>();
if (fun->isInterpretedConstructor()) {
JSScript *script = fun->getOrCreateScript(cx);
if (!script || !script->ensureHasTypes(cx))
return false;
JSObject *thisObj = CreateThisForFunction(cx, callee, GenericObject);
if (!thisObj)
return false;
rval.set(ObjectValue(*thisObj));
}
}
return true;
}
示例8:
bool
FilteringWrapper<CrossCompartmentSecurityWrapper, GentlyOpaque>
::defaultValue(JSContext *cx, HandleObject obj,
JSType hint, MutableHandleValue vp)
{
JSString *str = JS_NewStringCopyZ(cx, "[Opaque]");
if (!str)
return false;
vp.set(JS::StringValue(str));
return true;
}
示例9: obj
static bool
ExportGlobalValue(JSContext* cx, const GlobalDescVector& globals, uint32_t globalIndex,
const ValVector& globalImports, MutableHandleValue jsval)
{
const GlobalDesc& global = globals[globalIndex];
// Imports are located upfront in the globals array.
Val val;
switch (global.kind()) {
case GlobalKind::Import: val = globalImports[globalIndex]; break;
case GlobalKind::Variable: MOZ_CRASH("mutable variables can't be exported");
case GlobalKind::Constant: val = global.constantValue(); break;
}
switch (global.type()) {
case ValType::I32: {
jsval.set(Int32Value(val.i32()));
return true;
}
case ValType::I64: {
MOZ_ASSERT(JitOptions.wasmTestMode, "no int64 in asm.js/wasm");
RootedObject obj(cx, CreateI64Object(cx, val.i64()));
if (!obj)
return false;
jsval.set(ObjectValue(*obj));
return true;
}
case ValType::F32: {
jsval.set(DoubleValue(double(val.f32())));
return true;
}
case ValType::F64: {
jsval.set(DoubleValue(val.f64()));
return true;
}
default: {
break;
}
}
MOZ_CRASH("unexpected type when creating global exports");
}
示例10:
static int32_t
CoerceInPlace_ToNumber(MutableHandleValue val)
{
JSContext* cx = JSRuntime::innermostWasmActivation()->cx();
double dbl;
if (!ToNumber(cx, val, &dbl))
return false;
val.set(DoubleValue(dbl));
return true;
}
示例11: idval
static bool
env_setProperty(JSContext* cx, HandleObject obj, HandleId id, bool strict, MutableHandleValue vp)
{
/* XXX porting may be easy, but these don't seem to supply setenv by default */
#if !defined XP_OS2 && !defined SOLARIS
JSString* valstr;
JS::Rooted<JSString*> idstr(cx);
int rv;
RootedValue idval(cx);
if (!JS_IdToValue(cx, id, &idval))
return false;
idstr = ToString(cx, idval);
valstr = ToString(cx, vp);
if (!idstr || !valstr)
return false;
JSAutoByteString name(cx, idstr);
if (!name)
return false;
JSAutoByteString value(cx, valstr);
if (!value)
return false;
#if defined XP_WIN || defined HPUX || defined OSF1 || defined SCO
{
char* waste = JS_smprintf("%s=%s", name.ptr(), value.ptr());
if (!waste) {
JS_ReportOutOfMemory(cx);
return false;
}
rv = putenv(waste);
#ifdef XP_WIN
/*
* HPUX9 at least still has the bad old non-copying putenv.
*
* Per mail from <[email protected]>, OSF1 also has a putenv
* that will crash if you pass it an auto char array (so it must place
* its argument directly in the char* environ[] array).
*/
free(waste);
#endif
}
#else
rv = setenv(name.ptr(), value.ptr(), 1);
#endif
if (rv < 0) {
JS_ReportError(cx, "can't set envariable %s to %s", name.ptr(), value.ptr());
return false;
}
vp.set(STRING_TO_JSVAL(valstr));
#endif /* !defined XP_OS2 && !defined SOLARIS */
return true;
}
示例12: frame
bool
JSAbstractFramePtr::getThisValue(JSContext *cx, MutableHandleValue thisv)
{
AbstractFramePtr frame(*this);
RootedObject scopeChain(cx, frame.scopeChain());
js::AutoCompartment ac(cx, scopeChain);
if (!ComputeThis(cx, frame))
return false;
thisv.set(frame.thisValue());
return true;
}
示例13: unsigned
static bool
MappedArgGetter(JSContext* cx, HandleObject obj, HandleId id, MutableHandleValue vp)
{
MappedArgumentsObject& argsobj = obj->as<MappedArgumentsObject>();
if (JSID_IS_INT(id)) {
/*
* arg can exceed the number of arguments if a script changed the
* prototype to point to another Arguments object with a bigger argc.
*/
unsigned arg = unsigned(JSID_TO_INT(id));
if (arg < argsobj.initialLength() && !argsobj.isElementDeleted(arg))
vp.set(argsobj.element(arg));
} else if (JSID_IS_ATOM(id, cx->names().length)) {
if (!argsobj.hasOverriddenLength())
vp.setInt32(argsobj.initialLength());
} else {
MOZ_ASSERT(JSID_IS_ATOM(id, cx->names().callee));
if (!argsobj.callee().isMagic(JS_OVERWRITTEN_CALLEE))
vp.set(argsobj.callee());
}
return true;
}
示例14: value
static bool
GetUnclonedValue(JSContext *cx, HandleNativeObject selfHostedObject,
HandleId id, MutableHandleValue vp)
{
vp.setUndefined();
if (JSID_IS_INT(id)) {
size_t index = JSID_TO_INT(id);
if (index < selfHostedObject->getDenseInitializedLength() &&
!selfHostedObject->getDenseElement(index).isMagic(JS_ELEMENTS_HOLE))
{
vp.set(selfHostedObject->getDenseElement(JSID_TO_INT(id)));
return true;
}
}
// Since all atoms used by self hosting are marked as permanent, any
// attempt to look up a non-permanent atom will fail. We should only
// see such atoms when code is looking for properties on the self
// hosted global which aren't present.
if (JSID_IS_STRING(id) && !JSID_TO_STRING(id)->isPermanentAtom()) {
MOZ_ASSERT(selfHostedObject->is<GlobalObject>());
RootedValue value(cx, IdToValue(id));
return js_ReportValueErrorFlags(cx, JSREPORT_ERROR, JSMSG_NO_SUCH_SELF_HOSTED_PROP,
JSDVG_IGNORE_STACK, value, NullPtr(), nullptr, nullptr);
}
RootedShape shape(cx, selfHostedObject->lookupPure(id));
if (!shape) {
RootedValue value(cx, IdToValue(id));
return js_ReportValueErrorFlags(cx, JSREPORT_ERROR, JSMSG_NO_SUCH_SELF_HOSTED_PROP,
JSDVG_IGNORE_STACK, value, NullPtr(), nullptr, nullptr);
}
MOZ_ASSERT(shape->hasSlot() && shape->hasDefaultGetter());
vp.set(selfHostedObject->getSlot(shape->slot()));
return true;
}
示例15: string
bool
js::DirectEvalValueFromIon(JSContext *cx,
HandleObject scopeobj, HandleScript callerScript,
HandleValue thisValue, HandleValue evalArg,
jsbytecode *pc, MutableHandleValue vp)
{
// Act as identity on non-strings per ES5 15.1.2.1 step 1.
if (!evalArg.isString()) {
vp.set(evalArg);
return true;
}
RootedString string(cx, evalArg.toString());
return DirectEvalStringFromIon(cx, scopeobj, callerScript, thisValue, string, pc, vp);
}