40
40
*/
41
41
package com .oracle .truffle .js .test .polyglot ;
42
42
43
+ import static org .junit .Assert .assertEquals ;
43
44
import static org .junit .Assert .assertFalse ;
44
45
import static org .junit .Assert .assertTrue ;
45
46
46
47
import org .junit .Test ;
47
48
48
49
import com .oracle .truffle .js .runtime .JSRuntime ;
50
+ import com .oracle .truffle .js .test .JSTest ;
49
51
50
- public class ForeignTestMapTest {
52
+ public class ForeignTestMapTest extends JSTest {
51
53
52
54
@ Test
53
55
public void equalTest () {
@@ -67,4 +69,21 @@ public void equalTest() {
67
69
assertFalse (JSRuntime .equal (a , 0 ));
68
70
assertFalse (JSRuntime .equal (a , true ));
69
71
}
72
+
73
+ @ Test
74
+ public void foreignTestMapTests () {
75
+ ForeignTestMap map = new ForeignTestMap ();
76
+ map .getContainer ().put ("value" , "boxed" );
77
+
78
+ testHelper .getPolyglotContext ().getBindings ("js" ).putMember ("foreign" , map );
79
+
80
+ assertEquals ("boxed" , testHelper .run ("foreign.value" ));
81
+ assertEquals (42 , testHelper .run ("foreign.othervalue=42" ));
82
+ assertEquals (42 , testHelper .run ("foreign.othervalue" ));
83
+ assertEquals (true , testHelper .run ("delete foreign.othervalue" ));
84
+ assertEquals (true , testHelper .run ("foreign.othervalue === undefined" ));
85
+ assertEquals (84 , testHelper .run ("foreign.fn = (a)=>{ return a+a; }; foreign.fn(42);" ));
86
+
87
+ assertEquals (true , testHelper .run ("foreign.length=10; foreign[0]=42; foreign[1]=41; Array.prototype.sort.call(foreign); foreign[0]===41 && foreign[1]===42 && foreign[2]===undefined;" ));
88
+ }
70
89
}
0 commit comments