本文整理汇总了C++中MutableHandle类的典型用法代码示例。如果您正苦于以下问题:C++ MutableHandle类的具体用法?C++ MutableHandle怎么用?C++ MutableHandle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MutableHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: JS_GetPropertyDescriptorById
bool
BaseDOMProxyHandler::getPropertyDescriptor(JSContext* cx,
JS::Handle<JSObject*> proxy,
JS::Handle<jsid> id,
MutableHandle<JSPropertyDescriptor> desc,
unsigned flags)
{
if (!getOwnPropertyDescriptor(cx, proxy, id, desc, flags)) {
return false;
}
if (desc.object()) {
return true;
}
JS::Rooted<JSObject*> proto(cx);
if (!js::GetObjectProto(cx, proxy, &proto)) {
return false;
}
if (!proto) {
desc.object().set(nullptr);
return true;
}
return JS_GetPropertyDescriptorById(cx, proto, id, 0, desc);
}
示例2: thisFrame
bool
SavedStacks::insertFrames(JSContext *cx, ScriptFrameIter &iter, MutableHandle<SavedFrame*> frame)
{
if (iter.done()) {
frame.set(nullptr);
return true;
}
ScriptFrameIter thisFrame(iter);
Rooted<SavedFrame*> parentFrame(cx);
if (!insertFrames(cx, ++iter, &parentFrame))
return false;
RootedScript script(cx, thisFrame.script());
RootedFunction callee(cx, thisFrame.maybeCallee());
const char *filename = script->filename();
RootedAtom source(cx, Atomize(cx, filename, strlen(filename)));
if (!source)
return false;
uint32_t column;
uint32_t line = PCToLineNumber(script, thisFrame.pc(), &column);
SavedFrame::Lookup lookup(source,
line,
column,
callee ? callee->displayAtom() : nullptr,
parentFrame,
thisFrame.compartment()->principals);
frame.set(getOrCreateSavedFrame(cx, lookup));
return frame.address() != nullptr;
}
示例3: value
bool
JSCompartment::wrap(JSContext *cx, MutableHandle<PropDesc> desc)
{
if (desc.isUndefined())
return true;
JSCompartment *comp = cx->compartment();
if (desc.hasValue()) {
RootedValue value(cx, desc.value());
if (!comp->wrap(cx, &value))
return false;
desc.setValue(value);
}
if (desc.hasGet()) {
RootedValue get(cx, desc.getterValue());
if (!comp->wrap(cx, &get))
return false;
desc.setGetter(get);
}
if (desc.hasSet()) {
RootedValue set(cx, desc.setterValue());
if (!comp->wrap(cx, &set))
return false;
desc.setSetter(set);
}
return true;
}
示例4: InterposeProperty
bool
InterposeProperty(JSContext* cx, HandleObject target, const nsIID* iid, HandleId id,
MutableHandle<JSPropertyDescriptor> descriptor)
{
// We only want to do interpostion on DOM instances and
// wrapped natives.
RootedObject unwrapped(cx, UncheckedUnwrap(target));
const js::Class* clasp = js::GetObjectClass(unwrapped);
if (!mozilla::dom::IsDOMClass(clasp) &&
!IS_WN_CLASS(clasp) &&
!IS_PROTO_CLASS(clasp) &&
clasp != &OuterWindowProxyClass) {
return true;
}
XPCWrappedNativeScope* scope = ObjectScope(CurrentGlobalOrNull(cx));
MOZ_ASSERT(scope->HasInterposition());
nsCOMPtr<nsIAddonInterposition> interp = scope->GetInterposition();
JSAddonId* addonId = AddonIdOfObject(target);
RootedValue addonIdValue(cx, StringValue(StringOfAddonId(addonId)));
RootedValue prop(cx, IdToValue(id));
RootedValue targetValue(cx, ObjectValue(*target));
RootedValue descriptorVal(cx);
nsresult rv = interp->InterposeProperty(addonIdValue, targetValue,
iid, prop, &descriptorVal);
if (NS_FAILED(rv)) {
xpc::Throw(cx, rv);
return false;
}
if (!descriptorVal.isObject())
return true;
// We need to be careful parsing descriptorVal. |cx| is in the compartment
// of the add-on and the descriptor is in the compartment of the
// interposition. We could wrap the descriptor in the add-on's compartment
// and then parse it. However, parsing the descriptor fetches properties
// from it, and we would try to interpose on those property accesses. So
// instead we parse in the interposition's compartment and then wrap the
// descriptor.
{
JSAutoCompartment ac(cx, &descriptorVal.toObject());
if (!JS::ObjectToCompletePropertyDescriptor(cx, target, descriptorVal, descriptor))
return false;
}
// Always make the property non-configurable regardless of what the
// interposition wants.
descriptor.setAttributes(descriptor.attributes() | JSPROP_PERMANENT);
if (!JS_WrapPropertyDescriptor(cx, descriptor))
return false;
return true;
}
示例5: if
bool
JavaScriptShared::toDescriptor(JSContext* cx, const PPropertyDescriptor& in,
MutableHandle<JSPropertyDescriptor> out)
{
out.setAttributes(in.attrs());
if (!fromVariant(cx, in.value(), out.value()))
return false;
out.object().set(fromObjectOrNullVariant(cx, in.obj()));
if (in.getter().type() == GetterSetter::Tuint64_t && !in.getter().get_uint64_t()) {
out.setGetter(nullptr);
} else if (in.attrs() & JSPROP_GETTER) {
Rooted<JSObject*> getter(cx);
getter = fromObjectVariant(cx, in.getter().get_ObjectVariant());
if (!getter)
return false;
out.setGetter(JS_DATA_TO_FUNC_PTR(JSGetterOp, getter.get()));
} else {
out.setGetter(UnknownPropertyStub);
}
if (in.setter().type() == GetterSetter::Tuint64_t && !in.setter().get_uint64_t()) {
out.setSetter(nullptr);
} else if (in.attrs() & JSPROP_SETTER) {
Rooted<JSObject*> setter(cx);
setter = fromObjectVariant(cx, in.setter().get_ObjectVariant());
if (!setter)
return false;
out.setSetter(JS_DATA_TO_FUNC_PTR(JSSetterOp, setter.get()));
} else {
out.setSetter(UnknownStrictPropertyStub);
}
return true;
}
示例6: GetSharedTypedArray
static bool
GetSharedTypedArray(JSContext* cx, HandleValue v,
MutableHandle<TypedArrayObject*> viewp)
{
if (!v.isObject())
return ReportBadArrayType(cx);
if (!v.toObject().is<TypedArrayObject>())
return ReportBadArrayType(cx);
viewp.set(&v.toObject().as<TypedArrayObject>());
if (!viewp->isSharedMemory())
return ReportBadArrayType(cx);
return true;
}
示例7: defineProperty
bool
SecurityWrapper<Base>::defineProperty(JSContext *cx, HandleObject wrapper,
HandleId id, MutableHandle<PropertyDescriptor> desc)
{
if (desc.getter() || desc.setter()) {
JSString *str = IdToString(cx, id);
const jschar *prop = str ? str->getCharsZ(cx) : nullptr;
JS_ReportErrorNumberUC(cx, js_GetErrorMessage, nullptr,
JSMSG_ACCESSOR_DEF_DENIED, prop);
return false;
}
return Base::defineProperty(cx, wrapper, id, desc);
}
示例8: CloneModule
static bool
CloneModule(JSContext* cx, MutableHandle<AsmJSModuleObject*> moduleObj)
{
ScopedJSDeletePtr<AsmJSModule> module;
if (!moduleObj->module().clone(cx, &module))
return false;
AsmJSModuleObject* newModuleObj = AsmJSModuleObject::create(cx, &module);
if (!newModuleObj)
return false;
moduleObj.set(newModuleObj);
return true;
}
示例9: script
bool
BaselineFrame::copyRawFrameSlots(MutableHandle<GCVector<Value>> vec) const
{
unsigned nfixed = script()->nfixed();
unsigned nformals = numFormalArgs();
if (!vec.resize(nformals + nfixed))
return false;
mozilla::PodCopy(vec.begin(), argv(), nformals);
for (unsigned i = 0; i < nfixed; i++)
vec[nformals + i].set(*valueSlot(i));
return true;
}
示例10: getOwnPropertyDescriptor
bool
WaiveXrayWrapper::getOwnPropertyDescriptor(JSContext* cx, HandleObject wrapper, HandleId id,
MutableHandle<PropertyDescriptor> desc) const
{
return CrossCompartmentWrapper::getOwnPropertyDescriptor(cx, wrapper, id, desc) &&
WrapperFactory::WaiveXrayAndWrap(cx, desc.value()) && WaiveAccessors(cx, desc);
}
示例11: FillVector
static bool
FillVector(JSContext* cx, MutableHandle<ShapeVec> shapes)
{
for (size_t i = 0; i < 10; ++i) {
RootedObject obj(cx, JS_NewObject(cx, nullptr));
RootedValue val(cx, UndefinedValue());
// Construct a unique property name to ensure that the object creates a
// new shape.
char buffer[2];
buffer[0] = 'a' + i;
buffer[1] = '\0';
if (!JS_SetProperty(cx, obj, buffer, val))
return false;
if (!shapes.append(obj->as<NativeObject>().lastProperty()))
return false;
}
// Ensure iterator enumeration works through the mutable handle.
for (auto shape : shapes) {
if (!shape)
return false;
}
return true;
}
示例12: ImportFunctions
static bool
ImportFunctions(JSContext* cx, HandleObject importObj, const ImportNameVector& importNames,
MutableHandle<FunctionVector> imports)
{
if (!importNames.empty() && !importObj)
return Fail(cx, "no import object given");
for (const ImportName& name : importNames) {
RootedValue v(cx);
if (!GetProperty(cx, importObj, name.module.get(), &v))
return false;
if (*name.func.get()) {
if (!v.isObject())
return Fail(cx, "import object field is not an Object");
RootedObject obj(cx, &v.toObject());
if (!GetProperty(cx, obj, name.func.get(), &v))
return false;
}
if (!IsFunctionObject(v))
return Fail(cx, "import object field is not a Function");
if (!imports.append(&v.toObject().as<JSFunction>()))
return false;
}
return true;
}
示例13: source
bool
js::XDRScriptRegExpObject(XDRState<mode>* xdr, MutableHandle<RegExpObject*> objp)
{
/* NB: Keep this in sync with CloneScriptRegExpObject. */
RootedAtom source(xdr->cx());
uint32_t flagsword = 0;
if (mode == XDR_ENCODE) {
MOZ_ASSERT(objp);
RegExpObject& reobj = *objp;
source = reobj.getSource();
flagsword = reobj.getFlags();
}
if (!XDRAtom(xdr, &source) || !xdr->codeUint32(&flagsword))
return false;
if (mode == XDR_DECODE) {
RegExpFlag flags = RegExpFlag(flagsword);
RegExpObject* reobj = RegExpObject::createNoStatics(xdr->cx(), source, flags, nullptr,
xdr->cx()->tempLifoAlloc());
if (!reobj)
return false;
objp.set(reobj);
}
return true;
}
示例14: chars
bool
SecurityWrapper<Base>::defineProperty(JSContext *cx, HandleObject wrapper,
HandleId id, MutableHandle<PropertyDescriptor> desc) const
{
if (desc.getter() || desc.setter()) {
JSString *str = IdToString(cx, id);
AutoStableStringChars chars(cx);
const jschar *prop = nullptr;
if (str->ensureFlat(cx) && chars.initTwoByte(cx, str))
prop = chars.twoByteChars();
JS_ReportErrorNumberUC(cx, js_GetErrorMessage, nullptr,
JSMSG_ACCESSOR_DEF_DENIED, prop);
return false;
}
return Base::defineProperty(cx, wrapper, id, desc);
}
示例15: proxy_LookupProperty
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;
}