@ -37,31 +37,29 @@ pub(crate) fn arguments_exotic_get_own_property(
} ;
// 3. Let map be args.[[ParameterMap]].
let map = obj
. borrow ( )
. as_mapped_arguments ( )
. expect ( "arguments exotic method must only be callable from arguments objects" )
. parameter_map ( ) ;
Ok ( Some (
// 4. Let isMapped be ! HasOwnProperty(map, P).
// 5. If isMapped is true, then
if map
. has_own_property ( key . clone ( ) , context )
. expect ( "HasOwnProperty must not fail per the spec" )
// 4. Let isMapped be ! HasOwnProperty(map, P).
// 5. If isMapped is true, then
if let PropertyKey ::Index ( index ) = key {
if let Some ( value ) = obj
. borrow ( )
. as_mapped_arguments ( )
. expect ( "arguments exotic method must only be callable from arguments objects" )
. get ( * index as usize )
{
// a. Set desc.[[Value]] to Get(map, P).
PropertyDescriptor ::builder ( )
. value ( map . get ( key . clone ( ) , context ) ? )
. maybe_writable ( desc . writable ( ) )
. maybe_enumerable ( desc . enumerable ( ) )
. maybe_configurable ( desc . configurable ( ) )
. build ( )
} else {
// 6. Return desc.
desc
} ,
) )
return Ok ( Some (
PropertyDescriptor ::builder ( )
. value ( value )
. maybe_writable ( desc . writable ( ) )
. maybe_enumerable ( desc . enumerable ( ) )
. maybe_configurable ( desc . configurable ( ) )
. build ( ) ,
) ) ;
}
}
// 6. Return desc.
Ok ( Some ( desc ) )
}
/// `[[DefineOwnProperty]]` for arguments exotic objects.
@ -77,15 +75,17 @@ pub(crate) fn arguments_exotic_define_own_property(
desc : PropertyDescriptor ,
context : & mut Context ,
) -> JsResult < bool > {
// 1. Let map be args.[[ParameterMap]].
let map = obj
. borrow ( )
. as_mapped_arguments ( )
. expect ( "arguments exotic method must only be callable from arguments objects" )
. parameter_map ( ) ;
// 2. Let isMapped be HasOwnProperty(map, P).
let is_mapped = map . has_own_property ( key . clone ( ) , context ) ? ;
let mapped = if let PropertyKey ::Index ( index ) = key {
// 1. Let map be args.[[ParameterMap]].
obj . borrow ( )
. as_mapped_arguments ( )
. expect ( "arguments exotic method must only be callable from arguments objects" )
. get ( index as usize )
. map ( | value | ( index as usize , value ) )
} else {
None
} ;
let new_arg_desc = match desc . kind ( ) {
// 4. If isMapped is true and IsDataDescriptor(Desc) is true, then
@ -94,16 +94,20 @@ pub(crate) fn arguments_exotic_define_own_property(
DescriptorKind ::Data {
writable : Some ( false ) ,
value : None ,
} if is_mapped = >
} = >
// i. Set newArgDesc to a copy of Desc.
// ii. Set newArgDesc.[[Value]] to Get(map, P).
{
PropertyDescriptor ::builder ( )
. value ( map . get ( key . clone ( ) , context ) ? )
. writable ( false )
. maybe_enumerable ( desc . enumerable ( ) )
. maybe_configurable ( desc . configurable ( ) )
. build ( )
if let Some ( ( _ , value ) ) = & mapped {
PropertyDescriptor ::builder ( )
. value ( value )
. writable ( false )
. maybe_enumerable ( desc . enumerable ( ) )
. maybe_configurable ( desc . configurable ( ) )
. build ( )
} else {
desc . clone ( )
}
}
// 3. Let newArgDesc be Desc.
@ -112,32 +116,36 @@ pub(crate) fn arguments_exotic_define_own_property(
// 5. Let allowed be ? OrdinaryDefineOwnProperty(args, P, newArgDesc).
// 6. If allowed is false, return false.
if ! super ::ordinary_define_own_property ( obj , key . clone ( ) , new_arg_desc , context ) ? {
if ! super ::ordinary_define_own_property ( obj , key , new_arg_desc , context ) ? {
return Ok ( false ) ;
}
// 7. If isMapped is true, then
if is_mapped {
if let Some ( ( index , _ ) ) = mapped {
// 1. Let map be args.[[ParameterMap]].
let mut obj_mut = obj . borrow_mut ( ) ;
let map = obj_mut
. as_mapped_arguments_mut ( )
. expect ( "arguments exotic method must only be callable from arguments objects" ) ;
// a. If IsAccessorDescriptor(Desc) is true, then
if desc . is_accessor_descriptor ( ) {
// i. Call map.[[Delete]](P).
map . __delete__ ( & key , context ) ? ;
map . delete ( index ) ;
}
// b. Else,
else {
// i. If Desc.[[Value]] is present, then
if let Some ( value ) = desc . value ( ) {
// 1. Let setStatus be Set(map, P, Desc.[[Value]], false).
let set_status = map . set ( key . clone ( ) , value , false , context ) ;
// 2. Assert: setStatus is true because formal parameters mapped by argument objects are always writable.
assert_eq! ( set_status , Ok ( true ) ) ;
map . set ( index , value ) ;
}
// ii. If Desc.[[Writable]] is present and its value is false, then
if let Some ( false ) = desc . writable ( ) {
// 1. Call map.[[Delete]](P).
map . __delete__ ( & key , context ) ? ;
map . delete ( index ) ;
}
}
}
@ -158,28 +166,24 @@ pub(crate) fn arguments_exotic_get(
receiver : JsValue ,
context : & mut Context ,
) -> JsResult < JsValue > {
// 1. Let map be args.[[ParameterMap]].
let map = obj
. borrow ( )
. as_mapped_arguments ( )
. expect ( "arguments exotic method must only be callable from arguments objects" )
. parameter_map ( ) ;
// 2. Let isMapped be ! HasOwnProperty(map, P).
// 4. Else,
if map
. has_own_property ( key . clone ( ) , context )
. expect ( "HasOwnProperty must not fail per the spec" )
{
// a. Assert: map contains a formal parameter mapping for P.
// b. Return Get(map, P).
map . get ( key . clone ( ) , context )
if let PropertyKey ::Index ( index ) = key {
// 1. Let map be args.[[ParameterMap]].
// 2. Let isMapped be ! HasOwnProperty(map, P).
if let Some ( value ) = obj
. borrow ( )
. as_mapped_arguments ( )
. expect ( "arguments exotic method must only be callable from arguments objects" )
. get ( * index as usize )
{
// a. Assert: map contains a formal parameter mapping for P.
// b. Return Get(map, P).
return Ok ( value ) ;
}
}
// 3. If isMapped is false, then
} else {
// a. Return ? OrdinaryGet(args, P, Receiver).
super ::ordinary_get ( obj , key , receiver , context )
}
// a. Return ? OrdinaryGet(args, P, Receiver).
super ::ordinary_get ( obj , key , receiver , context )
}
/// `[[Set]]` for arguments exotic objects.
@ -198,25 +202,17 @@ pub(crate) fn arguments_exotic_set(
// 1. If SameValue(args, Receiver) is false, then
// a. Let isMapped be false.
// 2. Else,
if JsValue ::same_value ( & obj . clone ( ) . into ( ) , & receiver ) {
// a. Let map be args.[[ParameterMap]].
let map = obj
. borrow ( )
. as_mapped_arguments ( )
. expect ( "arguments exotic method must only be callable from arguments objects" )
. parameter_map ( ) ;
// b. Let isMapped be ! HasOwnProperty(map, P).
// 3. If isMapped is true, then
if map
. has_own_property ( key . clone ( ) , context )
. expect ( "HasOwnProperty must not fail per the spec" )
{
if let PropertyKey ::Index ( index ) = key {
if JsValue ::same_value ( & obj . clone ( ) . into ( ) , & receiver ) {
// a. Let map be args.[[ParameterMap]].
// b. Let isMapped be ! HasOwnProperty(map, P).
// 3. If isMapped is true, then
// a. Let setStatus be Set(map, P, V, false).
let set_status = map . set ( key . clone ( ) , value . clone ( ) , false , context ) ;
// b. Assert: setStatus is true because formal parameters mapped by argument objects are always writable.
assert_eq! ( set_status , Ok ( true ) ) ;
obj . borrow_mut ( )
. as_mapped_arguments_mut ( )
. expect ( "arguments exotic method must only be callable from arguments objects" )
. set ( index as usize , & value ) ;
}
}
@ -235,25 +231,20 @@ pub(crate) fn arguments_exotic_delete(
key : & PropertyKey ,
context : & mut Context ,
) -> JsResult < bool > {
// 1. Let map be args.[[ParameterMap]].
let map = obj
. borrow ( )
. as_mapped_arguments ( )
. expect ( "arguments exotic method must only be callable from arguments objects" )
. parameter_map ( ) ;
// 2. Let isMapped be ! HasOwnProperty(map, P).
let is_mapped = map
. has_own_property ( key . clone ( ) , context )
. expect ( "HasOwnProperty must not fail per the spec" ) ;
// 3. Let result be ? OrdinaryDelete(args, P).
let result = super ::ordinary_delete ( obj , key , context ) ? ;
// 4. If result is true and isMapped is true, then
if is_mapped & & result {
// a. Call map.[[Delete]](P).
map . __delete__ ( key , context ) ? ;
if result {
if let PropertyKey ::Index ( index ) = key {
// 1. Let map be args.[[ParameterMap]].
// 2. Let isMapped be ! HasOwnProperty(map, P).
// 4. If result is true and isMapped is true, then
// a. Call map.[[Delete]](P).
obj . borrow_mut ( )
. as_mapped_arguments_mut ( )
. expect ( "arguments exotic method must only be callable from arguments objects" )
. delete ( * index as usize ) ;
}
}
// 5. Return result.