本文整理汇总了C++中MutableHandleObject::set方法的典型用法代码示例。如果您正苦于以下问题:C++ MutableHandleObject::set方法的具体用法?C++ MutableHandleObject::set怎么用?C++ MutableHandleObject::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MutableHandleObject
的用法示例。
在下文中一共展示了MutableHandleObject::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: argsobj
static bool
args_resolve(JSContext *cx, HandleObject obj, HandleId id, unsigned flags,
MutableHandleObject objp)
{
objp.set(nullptr);
Rooted<NormalArgumentsObject*> argsobj(cx, &obj->as<NormalArgumentsObject>());
unsigned attrs = JSPROP_SHARED | JSPROP_SHADOWABLE;
if (JSID_IS_INT(id)) {
uint32_t arg = uint32_t(JSID_TO_INT(id));
if (arg >= argsobj->initialLength() || argsobj->isElementDeleted(arg))
return true;
attrs |= JSPROP_ENUMERATE;
} else if (JSID_IS_ATOM(id, cx->names().length)) {
if (argsobj->hasOverriddenLength())
return true;
} else {
if (!JSID_IS_ATOM(id, cx->names().callee))
return true;
if (argsobj->callee().isMagic(JS_OVERWRITTEN_CALLEE))
return true;
}
if (!baseops::DefineGeneric(cx, argsobj, id, UndefinedHandleValue, ArgGetter, ArgSetter, attrs))
return false;
objp.set(argsobj);
return true;
}
示例2: obj
JS_NondeterministicGetWeakMapKeys(JSContext *cx, HandleObject objArg, MutableHandleObject ret)
{
RootedObject obj(cx, objArg);
obj = UncheckedUnwrap(obj);
if (!obj || !obj->is<WeakMapObject>()) {
ret.set(nullptr);
return true;
}
RootedObject arr(cx, NewDenseEmptyArray(cx));
if (!arr)
return false;
ObjectValueMap *map = obj->as<WeakMapObject>().getMap();
if (map) {
// Prevent GC from mutating the weakmap while iterating.
AutoSuppressGC suppress(cx);
for (ObjectValueMap::Base::Range r = map->all(); !r.empty(); r.popFront()) {
RootedObject key(cx, r.front().key());
if (!cx->compartment()->wrap(cx, &key))
return false;
if (!NewbornArrayPush(cx, arr, ObjectValue(*key)))
return false;
}
}
ret.set(arr);
return true;
}
示例3: objectPassedToWrap
bool
JSCompartment::getNonWrapperObjectForCurrentCompartment(JSContext* cx, MutableHandleObject obj)
{
// Ensure that we have entered a compartment.
MOZ_ASSERT(cx->global());
// If we have a cross-compartment wrapper, make sure that the cx isn't
// associated with the self-hosting global. We don't want to create
// wrappers for objects in other runtimes, which may be the case for the
// self-hosting global.
MOZ_ASSERT(!cx->runtime()->isSelfHostingGlobal(cx->global()));
MOZ_ASSERT(!cx->runtime()->isSelfHostingGlobal(&obj->global()));
// The object is already in the right compartment. Normally same-
// compartment returns the object itself, however, windows are always
// wrapped by a proxy, so we have to check for that case here manually.
if (obj->compartment() == this) {
obj.set(ToWindowProxyIfWindow(obj));
return true;
}
// Note that if the object is same-compartment, but has been wrapped into a
// different compartment, we need to unwrap it and return the bare same-
// compartment object. Note again that windows are always wrapped by a
// WindowProxy even when same-compartment so take care not to strip this
// particular wrapper.
RootedObject objectPassedToWrap(cx, obj);
obj.set(UncheckedUnwrap(obj, /* stopAtWindowProxy = */ true));
if (obj->compartment() == this) {
MOZ_ASSERT(!IsWindow(obj));
return true;
}
// Invoke the prewrap callback. The prewrap callback is responsible for
// doing similar reification as above, but can account for any additional
// embedder requirements.
//
// We're a bit worried about infinite recursion here, so we do a check -
// see bug 809295.
auto preWrap = cx->runtime()->wrapObjectCallbacks->preWrap;
if (!CheckSystemRecursionLimit(cx))
return false;
if (preWrap) {
preWrap(cx, cx->global(), obj, objectPassedToWrap, obj);
if (!obj)
return false;
}
MOZ_ASSERT(!IsWindow(obj));
return true;
}
示例4: id
static bool
CreateExportObject(JSContext* cx, Handle<WasmModuleObject*> moduleObj, const ExportMap& exportMap,
const ExportVector& exports, MutableHandleObject exportObj)
{
MOZ_ASSERT(exportMap.exportNames.length() == exports.length());
MOZ_ASSERT(exportMap.fieldNames.length() == exportMap.fieldsToExports.length());
for (size_t fieldIndex = 0; fieldIndex < exportMap.fieldNames.length(); fieldIndex++) {
const char* fieldName = exportMap.fieldNames[fieldIndex].get();
if (!*fieldName) {
MOZ_ASSERT(!exportObj);
uint32_t exportIndex = exportMap.fieldsToExports[fieldIndex];
exportObj.set(NewExportedFunction(cx, moduleObj, exportMap, exportIndex));
if (!exportObj)
return false;
break;
}
}
Rooted<ValueVector> vals(cx, ValueVector(cx));
for (size_t exportIndex = 0; exportIndex < exports.length(); exportIndex++) {
JSFunction* fun = NewExportedFunction(cx, moduleObj, exportMap, exportIndex);
if (!fun || !vals.append(ObjectValue(*fun)))
return false;
}
if (!exportObj) {
exportObj.set(JS_NewPlainObject(cx));
if (!exportObj)
return false;
}
for (size_t fieldIndex = 0; fieldIndex < exportMap.fieldNames.length(); fieldIndex++) {
const char* fieldName = exportMap.fieldNames[fieldIndex].get();
if (!*fieldName)
continue;
JSAtom* atom = AtomizeUTF8Chars(cx, fieldName, strlen(fieldName));
if (!atom)
return false;
RootedId id(cx, AtomToId(atom));
HandleValue val = vals[exportMap.fieldsToExports[fieldIndex]];
if (!JS_DefinePropertyById(cx, exportObj, id, val, JSPROP_ENUMERATE))
return false;
}
return true;
}
示例5: obj
/*
* HasInstance hooks need to find an appropriate reflector in order to function
* properly. There are two complexities that we need to handle:
*
* 1 - Cross-compartment wrappers. Chrome uses over 100 compartments, all with
* system principal. The success of an instanceof check should not depend
* on which compartment an object comes from. At the same time, we want to
* make sure we don't unwrap important security wrappers.
* CheckedUnwrap does the right thing here.
*
* 2 - Prototype chains. Suppose someone creates a vanilla JS object |a| and
* sets its __proto__ to some WN |b|. If |b instanceof nsIFoo| returns true,
* one would expect |a instanceof nsIFoo| to return true as well, since
* instanceof is transitive up the prototype chain in ECMAScript. Moreover,
* there's chrome code that relies on this.
*
* This static method handles both complexities, returning either an XPCWN, a
* DOM object, or null. The object may well be cross-compartment from |cx|.
*/
static nsresult
FindObjectForHasInstance(JSContext* cx, HandleObject objArg, MutableHandleObject target)
{
RootedObject obj(cx, objArg), proto(cx);
while (obj && !IS_WN_REFLECTOR(obj) &&
!IsDOMObject(obj) && !mozilla::jsipc::IsCPOW(obj))
{
if (js::IsWrapper(obj)) {
obj = js::CheckedUnwrap(obj, /* stopAtWindowProxy = */ false);
continue;
}
{
JSAutoCompartment ac(cx, obj);
if (!js::GetObjectProto(cx, obj, &proto))
return NS_ERROR_FAILURE;
}
obj = proto;
}
target.set(obj);
return NS_OK;
}
示例6: rawValue
bool
JSCompartment::getTemplateLiteralObject(JSContext* cx, HandleArrayObject rawStrings,
MutableHandleObject templateObj)
{
if (TemplateRegistry::AddPtr p = templateLiteralMap_.lookupForAdd(rawStrings)) {
templateObj.set(p->value());
// The template object must have been frozen when it was added to the
// registry.
MOZ_ASSERT(!templateObj->nonProxyIsExtensible());
} else {
MOZ_ASSERT(templateObj->nonProxyIsExtensible());
RootedValue rawValue(cx, ObjectValue(*rawStrings));
if (!DefineDataProperty(cx, templateObj, cx->names().raw, rawValue, 0))
return false;
if (!FreezeObject(cx, rawStrings))
return false;
if (!FreezeObject(cx, templateObj))
return false;
if (!templateLiteralMap_.relookupOrAdd(p, rawStrings, templateObj))
return false;
}
return true;
}
示例7:
bool
OpaqueCrossCompartmentWrapper::getPrototype(JSContext* cx, HandleObject proxy,
MutableHandleObject protop) const
{
protop.set(nullptr);
return true;
}
示例8:
bool
ModuleNamespaceObject::ProxyHandler::getPrototype(JSContext* cx, HandleObject proxy,
MutableHandleObject protop) const
{
protop.set(nullptr);
return true;
}
示例9:
static bool
proxy_LookupProperty(JSContext* cx, HandleObject obj, HandleId id,
MutableHandleObject objp, MutableHandle<JS::PropertyResult> propp)
{
bool found;
if (!Proxy::has(cx, obj, id, &found))
return false;
if (found) {
propp.setNonNativeProperty();
objp.set(obj);
} else {
propp.setNotFound();
objp.set(nullptr);
}
return true;
}
示例10: assertSameCompartment
js::GetOriginalEval(JSContext *cx, HandleObject scope, MutableHandleObject eval)
{
assertSameCompartment(cx, scope);
if (!scope->global().getOrCreateObjectPrototype(cx))
return false;
eval.set(&scope->global().getOriginalEval().toObject());
return true;
}
示例11: obj
JS_NondeterministicGetWeakSetKeys(JSContext* cx, HandleObject objArg, MutableHandleObject ret)
{
RootedObject obj(cx, UncheckedUnwrap(objArg));
if (!obj || !obj->is<WeakSetObject>()) {
ret.set(nullptr);
return true;
}
return WeakCollectionObject::nondeterministicGetKeys(cx, obj.as<WeakCollectionObject>(), ret);
}
示例12:
/* static */ bool
GlobalObject::getOrCreateEval(JSContext* cx, Handle<GlobalObject*> global,
MutableHandleObject eval)
{
if (!global->getOrCreateObjectPrototype(cx))
return false;
eval.set(&global->getSlot(EVAL).toObject());
return true;
}
示例13: XDRInterpretedFunction
bool
XDRState<mode>::codeFunction(MutableHandleObject objp)
{
if (mode == XDR_DECODE)
objp.set(NULL);
if (!VersionCheck(this))
return false;
return XDRInterpretedFunction(this, NullPtr(), NullPtr(), objp);
}
示例14: wrapped
static bool
WrapForSameCompartment(JSContext *cx, MutableHandleObject obj, const JSWrapObjectCallbacks *cb)
{
JS_ASSERT(cx->compartment() == obj->compartment());
if (!cb->sameCompartmentWrap)
return true;
RootedObject wrapped(cx, cb->sameCompartmentWrap(cx, obj));
if (!wrapped)
return false;
obj.set(wrapped);
return true;
}
示例15: key
bool
JSCompartment::getOrCreateWrapper(JSContext* cx, HandleObject existing, MutableHandleObject obj)
{
// If we already have a wrapper for this value, use it.
RootedValue key(cx, ObjectValue(*obj));
if (WrapperMap::Ptr p = crossCompartmentWrappers.lookup(CrossCompartmentKey(key))) {
obj.set(&p->value().get().toObject());
MOZ_ASSERT(obj->is<CrossCompartmentWrapperObject>());
return true;
}
// Ensure that the wrappee is exposed in case we are creating a new wrapper
// for a gray object.
ExposeObjectToActiveJS(obj);
// Create a new wrapper for the object.
auto wrap = cx->runtime()->wrapObjectCallbacks->wrap;
RootedObject wrapper(cx, wrap(cx, existing, obj));
if (!wrapper)
return false;
// We maintain the invariant that the key in the cross-compartment wrapper
// map is always directly wrapped by the value.
MOZ_ASSERT(Wrapper::wrappedObject(wrapper) == &key.get().toObject());
if (!putWrapper(cx, CrossCompartmentKey(key), ObjectValue(*wrapper))) {
// Enforce the invariant that all cross-compartment wrapper object are
// in the map by nuking the wrapper if we couldn't add it.
// Unfortunately it's possible for the wrapper to still be marked if we
// took this path, for example if the object metadata callback stashes a
// reference to it.
if (wrapper->is<CrossCompartmentWrapperObject>())
NukeCrossCompartmentWrapper(cx, wrapper);
return false;
}
obj.set(wrapper);
return true;
}