-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
strict.test.ts
58 lines (40 loc) · 1.6 KB
/
strict.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
namespace $ {
$mol_test({
'object to primitive'( $ ) {
class Foo extends Object {
[ Symbol.toPrimitive ]( hint: string ) { return 321 }
valueOf() { return 123 }
toString() { return 'foo' }
}
$mol_assert_equal( ( new Foo as any ) - 1, 320 )
$mol_assert_equal( new Foo + '!', '321!' )
$mol_assert_equal( `${ new Foo }!`, '321!' )
$mol_assert_fail( ()=> ( {} as number ) + 1, 'Field Symbol(Symbol.toPrimitive) is not defined' )
$mol_assert_fail( ()=> ({}) + '!', 'Field Symbol(Symbol.toPrimitive) is not defined' )
$mol_assert_fail( ()=> `${ {} }!`, 'Field Symbol(Symbol.toPrimitive) is not defined' )
},
'unknown properties'( $ ) {
$mol_assert_equal( [ 777 ][0], 777 )
$mol_assert_equal( [].slice, Array.prototype.slice )
$mol_assert_equal( ({ foo: 777 }).foo, 777 )
$mol_assert_ok( 'foo'.slice )
$mol_assert_fail( ()=> [ 777 ][1], 'Field "1" is not defined' )
$mol_assert_fail( ()=> [ 777 ]['foo'], 'Field "foo" is not defined' )
$mol_assert_fail( ()=> 'foo'['bar'], 'Field "bar" is not defined' )
},
'unknown properties of custom obects'( $ ) {
class Foo extends Object {
foo = 123
}
$mol_assert_equal( new Foo().foo, 123 )
$mol_assert_fail( ()=> new Foo()['bar'], 'Field "bar" is not defined' )
},
'prototype pollution'( $ ) {
const obj = { foo: 123 } as any
obj.__proto__ = { bar: 321 }
$mol_assert_equal( Reflect.getPrototypeOf( obj ), Reflect.getPrototypeOf({}) )
$mol_assert_like( obj.__proto__, { bar: 321 } )
$mol_assert_equal( obj.bar, undefined )
},
})
}