Skip to content

Commit 487f323

Browse files
committed
Extending tests of Value->String conversion in Nashorn compatibility mode.
1 parent 6259cd8 commit 487f323

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

graal-js/src/com.oracle.truffle.js.scriptengine.test/src/com/oracle/truffle/js/scriptengine/test/TestNashornTypeConversion.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -84,6 +84,15 @@ private static void testToString(Object value, String expectedResult) throws Scr
8484
assertEquals(expectedResult, holder.getValue());
8585
}
8686

87+
private static void testToStringExpressionValue(String expression, String expectedResult) throws ScriptException {
88+
ScriptEngine engine = getEngineNashornCompat();
89+
ValueHolder holder = new ValueHolder();
90+
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
91+
bindings.put("holder", holder);
92+
engine.eval("holder.setValue(" + expression + ")");
93+
assertEquals(expectedResult, holder.getValue());
94+
}
95+
8796
@Test
8897
public void testNumberToString() throws ScriptException {
8998
testToString(42, "42");
@@ -100,6 +109,41 @@ public void testObjectToString() throws ScriptException {
100109
testToString(p, p.toString());
101110
}
102111

112+
@Test
113+
public void testRegExpToString() throws ScriptException {
114+
testToStringExpressionValue("/foo/i", "/foo/i");
115+
}
116+
117+
@Test
118+
public void testArrayToString() throws ScriptException {
119+
testToStringExpressionValue("[42,211]", "42,211");
120+
}
121+
122+
@Test
123+
public void testObjectToStringToString() throws ScriptException {
124+
testToStringExpressionValue("({ toString: function() { return 'foo'; } })", "foo");
125+
}
126+
127+
@Test
128+
public void testObjectValueOfToString() throws ScriptException {
129+
testToStringExpressionValue("Object.setPrototypeOf({ valueOf: function() { return 42; } }, null)", "42");
130+
}
131+
132+
@Test
133+
public void testBooleanObjectToString() throws ScriptException {
134+
testToStringExpressionValue("Object(true)", "true");
135+
}
136+
137+
@Test
138+
public void testNumberObjectToString() throws ScriptException {
139+
testToStringExpressionValue("Object(3.14)", "3.14");
140+
}
141+
142+
@Test
143+
public void testStringObjectToString() throws ScriptException {
144+
testToStringExpressionValue("Object('xyz')", "xyz");
145+
}
146+
103147
@Test
104148
public void testNumberToDouble() throws ScriptException {
105149
ScriptEngine engine = getEngineNashornCompat();

0 commit comments

Comments
 (0)