Skip to content

Commit d69afa8

Browse files
committed
adding PropertyTest redefinePropertyWithThreadSafeSlotMap as a repro case of Dead Lock that can occure when new SlotMap.compute method is used with ThreadSafeSlotMapContainer
1 parent 8b45873 commit d69afa8

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

tests/src/test/java/org/mozilla/javascript/tests/es6/PropertyTest.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package org.mozilla.javascript.tests.es6;
22

33
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
5+
import static org.mozilla.javascript.tests.Utils.DEFAULT_OPT_LEVELS;
46

7+
import java.io.FileReader;
8+
import java.io.IOException;
59
import java.lang.reflect.Method;
610
import org.junit.Test;
711
import org.mozilla.javascript.Context;
12+
import org.mozilla.javascript.ContextFactory;
13+
import org.mozilla.javascript.Scriptable;
814
import org.mozilla.javascript.ScriptableObject;
915
import org.mozilla.javascript.tests.Utils;
16+
import org.mozilla.javascript.tools.shell.Global;
1017

1118
public class PropertyTest {
1219

@@ -118,6 +125,59 @@ public void redefineSetterProperty() throws Exception {
118125

119126
return null;
120127
});
128+
129+
130+
131+
}
132+
133+
@Test
134+
public void redefinePropertyWithThreadSafeSlotMap() {
135+
136+
final ContextFactory factory =
137+
new ContextFactory() {
138+
@Override
139+
protected boolean hasFeature(Context cx, int featureIndex) {
140+
switch (featureIndex) {
141+
case Context.FEATURE_THREAD_SAFE_OBJECTS:
142+
return true;
143+
default:
144+
return super.hasFeature(cx, featureIndex);
145+
}
146+
}
147+
};
148+
149+
try (Context cx = factory.enterContext()) {
150+
cx.setLanguageVersion(Context.VERSION_ES6);
151+
ScriptableObject scope = cx.initStandardObjects();
152+
153+
final String expected = "undefined - true - true | function - function";
154+
155+
final String script =
156+
"Object.defineProperty(MyHostObject, 'foo', { enumerable: !0, configurable: !0, set: function() { return !0 }});\n"
157+
+ "var desc = Object.getOwnPropertyDescriptor(MyHostObject, 'foo');"
158+
+ "var result = '' + desc.writable + ' - ' + desc.configurable + ' - ' + desc.enumerable;"
159+
+ "result = result + ' | ' + typeof desc.get + ' - ' + typeof desc.set;"
160+
+ "result;";
161+
162+
try {
163+
final MyHostObject myHostObject = new MyHostObject();
164+
165+
// define custom getter method
166+
final Method getter = MyHostObject.class.getMethod("getFoo");
167+
final Method setter = MyHostObject.class.getMethod("setFoo", String.class);
168+
myHostObject.defineProperty(
169+
"foo", null, getter, setter, ScriptableObject.EMPTY);
170+
scope.put("MyHostObject", scope, myHostObject);
171+
} catch (Exception e) {
172+
}
173+
174+
final String result =
175+
(String) cx.evaluateString(scope, script, "myScript", 1, null);
176+
177+
assertEquals(expected, result);
178+
179+
}
180+
121181
}
122182

123183
public static class MyHostObject extends ScriptableObject {

0 commit comments

Comments
 (0)