@ -55,7 +55,7 @@ fn object_create_with_number() {
#[ test ]
#[ ignore ]
// to test on __proto__ somehow. __proto__ getter is not working as expected currently
// TODO: to test on __proto__ somehow. __proto__ getter is not working as expected currently
fn object_create_with_function ( ) {
let mut engine = Context ::new ( ) ;
@ -135,3 +135,43 @@ fn object_property_is_enumerable() {
) ;
assert_eq! ( forward ( & mut engine , r#"x.propertyIsEnumerable()"#), "false" , )
}
#[ test ]
fn object_to_string ( ) {
let mut ctx = Context ::new ( ) ;
let init = r #"
let u = undefined ;
let n = null ;
let a = [ ] ;
Array . prototype . toString = Object . prototype . toString ;
let f = ( ) = > { } ;
Function . prototype . toString = Object . prototype . toString ;
let b = Boolean ( ) ;
Boolean . prototype . toString = Object . prototype . toString ;
let i = Number ( 42 ) ;
Number . prototype . toString = Object . prototype . toString ;
let s = String ( ' boa ' ) ;
String . prototype . toString = Object . prototype . toString ;
let d = new Date ( Date . now ( ) ) ;
Date . prototype . toString = Object . prototype . toString ;
let re = / boa / ;
RegExp . prototype . toString = Object . prototype . toString ;
" #;
eprintln! ( "{}" , forward ( & mut ctx , init ) ) ;
// TODO: need Function.prototype.call to be implemented
// assert_eq!(
// forward(&mut ctx, "Object.prototype.toString.call(u)"),
// "\"[object Undefined]\""
// );
// assert_eq!(
// forward(&mut ctx, "Object.prototype.toString.call(n)"),
// "\"[object Null]\""
// );
assert_eq! ( forward ( & mut ctx , "a.toString()" ) , "\"[object Array]\"" ) ;
assert_eq! ( forward ( & mut ctx , "f.toString()" ) , "\"[object Function]\"" ) ;
assert_eq! ( forward ( & mut ctx , "b.toString()" ) , "\"[object Boolean]\"" ) ;
assert_eq! ( forward ( & mut ctx , "i.toString()" ) , "\"[object Number]\"" ) ;
assert_eq! ( forward ( & mut ctx , "s.toString()" ) , "\"[object String]\"" ) ;
assert_eq! ( forward ( & mut ctx , "d.toString()" ) , "\"[object Date]\"" ) ;
assert_eq! ( forward ( & mut ctx , "re.toString()" ) , "\"[object RegExp]\"" ) ;
}