@ -50,12 +50,14 @@ impl BuiltIn for Map {
entries_function ,
entries_function ,
Attribute ::WRITABLE | Attribute ::NON_ENUMERABLE | Attribute ::CONFIGURABLE ,
Attribute ::WRITABLE | Attribute ::NON_ENUMERABLE | Attribute ::CONFIGURABLE ,
)
)
. method ( Self ::keys , "keys" , 0 )
. method ( Self ::set , "set" , 2 )
. method ( Self ::set , "set" , 2 )
. method ( Self ::delete , "delete" , 1 )
. method ( Self ::delete , "delete" , 1 )
. method ( Self ::get , "get" , 1 )
. method ( Self ::get , "get" , 1 )
. method ( Self ::clear , "clear" , 0 )
. method ( Self ::clear , "clear" , 0 )
. method ( Self ::has , "has" , 1 )
. method ( Self ::has , "has" , 1 )
. method ( Self ::for_each , "forEach" , 1 )
. method ( Self ::for_each , "forEach" , 1 )
. method ( Self ::values , "values" , 0 )
. callable ( false )
. callable ( false )
. build ( ) ;
. build ( ) ;
@ -134,6 +136,20 @@ impl Map {
MapIterator ::create_map_iterator ( ctx , this . clone ( ) , MapIterationKind ::KeyAndValue )
MapIterator ::create_map_iterator ( ctx , this . clone ( ) , MapIterationKind ::KeyAndValue )
}
}
/// `Map.prototype.keys()`
///
/// Returns a new Iterator object that contains the keys for each element in the Map object in insertion order.
///
/// More information:
/// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn]
///
/// [spec]: https://tc39.es/ecma262/#sec-map.prototype.keys
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys
pub ( crate ) fn keys ( this : & Value , _ : & [ Value ] , ctx : & mut Context ) -> Result < Value > {
MapIterator ::create_map_iterator ( ctx , this . clone ( ) , MapIterationKind ::Key )
}
/// Helper function to set the size property.
/// Helper function to set the size property.
fn set_size ( this : & Value , size : usize ) {
fn set_size ( this : & Value , size : usize ) {
let size = DataDescriptor ::new (
let size = DataDescriptor ::new (
@ -321,6 +337,20 @@ impl Map {
Ok ( Value ::Undefined )
Ok ( Value ::Undefined )
}
}
/// `Map.prototype.values()`
///
/// Returns a new Iterator object that contains the values for each element in the Map object in insertion order.
///
/// More information:
/// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn]
///
/// [spec]: https://tc39.es/ecma262/#sec-map.prototype.values
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values
pub ( crate ) fn values ( this : & Value , _ : & [ Value ] , ctx : & mut Context ) -> Result < Value > {
MapIterator ::create_map_iterator ( ctx , this . clone ( ) , MapIterationKind ::Value )
}
/// Helper function to get a key-value pair from an array.
/// Helper function to get a key-value pair from an array.
fn get_key_value ( value : & Value ) -> Option < ( Value , Value ) > {
fn get_key_value ( value : & Value ) -> Option < ( Value , Value ) > {
if let Value ::Object ( object ) = value {
if let Value ::Object ( object ) = value {