mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-22 12:04:38 +00:00
Bug 1094189 - Remove shell resolver function. r=jorendorff
This commit is contained in:
parent
b105928718
commit
20f0347ce8
@ -2820,131 +2820,6 @@ ShapeOf(JSContext *cx, unsigned argc, JS::Value *vp)
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* If referent has an own property named id, copy that property to obj[id].
|
||||
* Since obj is native, this isn't totally transparent; properties of a
|
||||
* non-native referent may be simplified to data properties.
|
||||
*/
|
||||
static bool
|
||||
CopyProperty(JSContext *cx, HandleNativeObject obj, HandleObject referent, HandleId id,
|
||||
MutableHandleObject objp)
|
||||
{
|
||||
RootedShape shape(cx);
|
||||
Rooted<PropertyDescriptor> desc(cx);
|
||||
RootedObject obj2(cx);
|
||||
|
||||
objp.set(nullptr);
|
||||
if (referent->isNative()) {
|
||||
if (!LookupNativeProperty(cx, referent.as<NativeObject>(), id, &obj2, &shape))
|
||||
return false;
|
||||
if (obj2 != referent)
|
||||
return true;
|
||||
|
||||
if (shape->hasSlot()) {
|
||||
desc.value().set(referent->as<NativeObject>().getSlot(shape->slot()));
|
||||
} else {
|
||||
desc.value().setUndefined();
|
||||
}
|
||||
|
||||
desc.setAttributes(shape->attributes());
|
||||
desc.setGetter(shape->getter());
|
||||
if (!desc.getter() && !desc.hasGetterObject())
|
||||
desc.setGetter(JS_PropertyStub);
|
||||
desc.setSetter(shape->setter());
|
||||
if (!desc.setter() && !desc.hasSetterObject())
|
||||
desc.setSetter(JS_StrictPropertyStub);
|
||||
} else if (referent->is<ProxyObject>()) {
|
||||
if (!Proxy::getOwnPropertyDescriptor(cx, referent, id, &desc))
|
||||
return false;
|
||||
if (!desc.object())
|
||||
return true;
|
||||
} else {
|
||||
if (!JSObject::lookupGeneric(cx, referent, id, objp, &shape))
|
||||
return false;
|
||||
if (objp != referent)
|
||||
return true;
|
||||
RootedValue value(cx);
|
||||
if (!JSObject::getGeneric(cx, referent, referent, id, &value) ||
|
||||
!JSObject::getGenericAttributes(cx, referent, id, &desc.attributesRef()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
desc.value().set(value);
|
||||
desc.attributesRef() &= JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT;
|
||||
desc.setGetter(JS_PropertyStub);
|
||||
desc.setSetter(JS_StrictPropertyStub);
|
||||
}
|
||||
|
||||
objp.set(obj);
|
||||
return DefineNativeProperty(cx, obj, id, desc.value(), desc.getter(), desc.setter(),
|
||||
desc.attributes());
|
||||
}
|
||||
|
||||
static bool
|
||||
resolver_resolve(JSContext *cx, HandleObject obj, HandleId id, MutableHandleObject objp)
|
||||
{
|
||||
jsval v = JS_GetReservedSlot(obj, 0);
|
||||
Rooted<JSObject*> vobj(cx, &v.toObject());
|
||||
return CopyProperty(cx, obj.as<NativeObject>(), vobj, id, objp);
|
||||
}
|
||||
|
||||
static bool
|
||||
resolver_enumerate(JSContext *cx, HandleObject obj)
|
||||
{
|
||||
jsval v = JS_GetReservedSlot(obj, 0);
|
||||
RootedObject referent(cx, v.toObjectOrNull());
|
||||
|
||||
AutoIdArray ida(cx, JS_Enumerate(cx, referent));
|
||||
bool ok = !!ida;
|
||||
RootedObject ignore(cx);
|
||||
for (size_t i = 0; ok && i < ida.length(); i++) {
|
||||
Rooted<jsid> id(cx, ida[i]);
|
||||
ok = CopyProperty(cx, obj.as<NativeObject>(), referent, id, &ignore);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
static const JSClass resolver_class = {
|
||||
"resolver",
|
||||
JSCLASS_NEW_RESOLVE | JSCLASS_HAS_RESERVED_SLOTS(1),
|
||||
JS_PropertyStub, JS_DeletePropertyStub,
|
||||
JS_PropertyStub, JS_StrictPropertyStub,
|
||||
resolver_enumerate, (JSResolveOp)resolver_resolve,
|
||||
JS_ConvertStub
|
||||
};
|
||||
|
||||
static bool
|
||||
Resolver(JSContext *cx, unsigned argc, jsval *vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
RootedObject referent(cx);
|
||||
if (!JS_ValueToObject(cx, args.get(0), &referent))
|
||||
return false;
|
||||
if (!referent) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_CANT_CONVERT_TO,
|
||||
args.get(0).isNull() ? "null" : "undefined", "object");
|
||||
return false;
|
||||
}
|
||||
|
||||
RootedObject proto(cx, nullptr);
|
||||
if (!args.get(1).isNullOrUndefined()) {
|
||||
if (!JS_ValueToObject(cx, args.get(1), &proto))
|
||||
return false;
|
||||
}
|
||||
|
||||
RootedObject parent(cx, JS_GetParent(referent));
|
||||
JSObject *result = (args.length() > 1
|
||||
? JS_NewObjectWithGivenProto
|
||||
: JS_NewObject)(cx, &resolver_class, proto, parent);
|
||||
if (!result)
|
||||
return false;
|
||||
|
||||
JS_SetReservedSlot(result, 0, ObjectValue(*referent));
|
||||
args.rval().setObject(*result);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that t1 comes strictly before t2. The function correctly deals with
|
||||
* wrap-around between t2 and t1 assuming that t2 and t1 stays within INT32_MAX
|
||||
@ -4548,11 +4423,6 @@ static const JSFunctionSpecWithHelp shell_functions[] = {
|
||||
"shapeOf(obj)",
|
||||
" Get the shape of obj (an implementation detail)."),
|
||||
|
||||
JS_FN_HELP("resolver", Resolver, 1, 0,
|
||||
"resolver(src[, proto])",
|
||||
" Create object with resolve hook that copies properties\n"
|
||||
" from src. If proto is omitted, use Object.prototype."),
|
||||
|
||||
#ifdef DEBUG
|
||||
JS_FN_HELP("arrayInfo", js_ArrayInfo, 1, 0,
|
||||
"arrayInfo(a1, a2, ...)",
|
||||
|
Loading…
x
Reference in New Issue
Block a user