mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-06 15:58:39 +09:00
1175823 - Implement [[DefineOwnProperty]] for mapped arguments object.
This commit is contained in:
parent
1af9026a89
commit
3ce5343851
3 changed files with 71 additions and 2 deletions
|
|
@ -471,7 +471,7 @@ js::SetIntegrityLevel(JSContext* cx, HandleObject obj, IntegrityLevel level)
|
|||
|
||||
// Steps 8-9, loosely interpreted.
|
||||
if (obj->isNative() && !obj->as<NativeObject>().inDictionaryMode() &&
|
||||
!obj->is<TypedArrayObject>())
|
||||
!obj->is<TypedArrayObject>() && !obj->is<MappedArgumentsObject>())
|
||||
{
|
||||
HandleNativeObject nobj = obj.as<NativeObject>();
|
||||
|
||||
|
|
|
|||
|
|
@ -590,6 +590,64 @@ MappedArgumentsObject::obj_enumerate(JSContext* cx, HandleObject obj)
|
|||
return true;
|
||||
}
|
||||
|
||||
// ES 2017 draft 9.4.4.2
|
||||
/* static */ bool
|
||||
MappedArgumentsObject::obj_defineProperty(JSContext* cx, HandleObject obj, HandleId id,
|
||||
Handle<PropertyDescriptor> desc, ObjectOpResult& result)
|
||||
{
|
||||
// Step 1.
|
||||
Rooted<MappedArgumentsObject*> argsobj(cx, &obj->as<MappedArgumentsObject>());
|
||||
|
||||
// Steps 2-3.
|
||||
bool isMapped = false;
|
||||
if (JSID_IS_INT(id)) {
|
||||
unsigned arg = unsigned(JSID_TO_INT(id));
|
||||
isMapped = arg < argsobj->initialLength() && !argsobj->isElementDeleted(arg);
|
||||
}
|
||||
|
||||
// Step 4.
|
||||
Rooted<PropertyDescriptor> newArgDesc(cx, desc);
|
||||
if (!desc.isAccessorDescriptor() && isMapped) {
|
||||
// In this case the live mapping is supposed to keep working,
|
||||
// we have to pass along the Getter/Setter otherwise they are overwritten.
|
||||
newArgDesc.setGetter(MappedArgGetter);
|
||||
newArgDesc.setSetter(MappedArgSetter);
|
||||
}
|
||||
|
||||
// Steps 5-6. NativeDefineProperty will lookup [[Value]] for us.
|
||||
if (!NativeDefineProperty(cx, obj.as<NativeObject>(), id, newArgDesc, result))
|
||||
return false;
|
||||
// Step 7.
|
||||
if (!result.ok())
|
||||
return true;
|
||||
|
||||
// Step 8.
|
||||
if (isMapped) {
|
||||
unsigned arg = unsigned(JSID_TO_INT(id));
|
||||
if (desc.isAccessorDescriptor()) {
|
||||
if (!argsobj->markElementDeleted(cx, arg))
|
||||
return false;
|
||||
} else {
|
||||
if (desc.hasValue()) {
|
||||
RootedFunction callee(cx, &argsobj->callee());
|
||||
RootedScript script(cx, callee->getOrCreateScript(cx));
|
||||
if (!script)
|
||||
return false;
|
||||
argsobj->setElement(cx, arg, desc.value());
|
||||
if (arg < script->functionNonDelazifying()->nargs())
|
||||
TypeScript::SetArgument(cx, script, arg, desc.value());
|
||||
}
|
||||
if (desc.hasWritable() && !desc.writable()) {
|
||||
if (!argsobj->markElementDeleted(cx, arg))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Step 9.
|
||||
return result.succeed();
|
||||
}
|
||||
|
||||
static bool
|
||||
UnmappedArgGetter(JSContext* cx, HandleObject obj, HandleId id, MutableHandleValue vp)
|
||||
{
|
||||
|
|
@ -804,6 +862,11 @@ const ClassOps MappedArgumentsObject::classOps_ = {
|
|||
ArgumentsObject::trace
|
||||
};
|
||||
|
||||
const ObjectOps MappedArgumentsObject::objectOps_ = {
|
||||
nullptr, /* lookupProperty */
|
||||
MappedArgumentsObject::obj_defineProperty
|
||||
};
|
||||
|
||||
const Class MappedArgumentsObject::class_ = {
|
||||
"Arguments",
|
||||
JSCLASS_DELAY_METADATA_BUILDER |
|
||||
|
|
@ -811,7 +874,10 @@ const Class MappedArgumentsObject::class_ = {
|
|||
JSCLASS_HAS_CACHED_PROTO(JSProto_Object) |
|
||||
JSCLASS_SKIP_NURSERY_FINALIZE |
|
||||
JSCLASS_BACKGROUND_FINALIZE,
|
||||
&MappedArgumentsObject::classOps_
|
||||
&MappedArgumentsObject::classOps_,
|
||||
nullptr,
|
||||
nullptr,
|
||||
&MappedArgumentsObject::objectOps_
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -389,6 +389,7 @@ class ArgumentsObject : public NativeObject
|
|||
class MappedArgumentsObject : public ArgumentsObject
|
||||
{
|
||||
static const ClassOps classOps_;
|
||||
static const ObjectOps objectOps_;
|
||||
|
||||
public:
|
||||
static const Class class_;
|
||||
|
|
@ -410,6 +411,8 @@ class MappedArgumentsObject : public ArgumentsObject
|
|||
private:
|
||||
static bool obj_enumerate(JSContext* cx, HandleObject obj);
|
||||
static bool obj_resolve(JSContext* cx, HandleObject obj, HandleId id, bool* resolvedp);
|
||||
static bool obj_defineProperty(JSContext* cx, HandleObject obj, HandleId id,
|
||||
Handle<JS::PropertyDescriptor> desc, ObjectOpResult& result);
|
||||
};
|
||||
|
||||
class UnmappedArgumentsObject : public ArgumentsObject
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue