|
1 | 1 | package org.mozilla.javascript.tests.es6;
|
2 | 2 |
|
3 | 3 | import static org.junit.Assert.assertEquals;
|
| 4 | +import static org.junit.Assert.assertFalse; |
| 5 | +import static org.mozilla.javascript.tests.Utils.DEFAULT_OPT_LEVELS; |
4 | 6 |
|
| 7 | +import java.io.FileReader; |
| 8 | +import java.io.IOException; |
5 | 9 | import java.lang.reflect.Method;
|
6 | 10 | import org.junit.Test;
|
7 | 11 | import org.mozilla.javascript.Context;
|
| 12 | +import org.mozilla.javascript.ContextFactory; |
| 13 | +import org.mozilla.javascript.Scriptable; |
8 | 14 | import org.mozilla.javascript.ScriptableObject;
|
9 | 15 | import org.mozilla.javascript.tests.Utils;
|
| 16 | +import org.mozilla.javascript.tools.shell.Global; |
10 | 17 |
|
11 | 18 | public class PropertyTest {
|
12 | 19 |
|
@@ -118,6 +125,59 @@ public void redefineSetterProperty() throws Exception {
|
118 | 125 |
|
119 | 126 | return null;
|
120 | 127 | });
|
| 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 | + |
121 | 181 | }
|
122 | 182 |
|
123 | 183 | public static class MyHostObject extends ScriptableObject {
|
|
0 commit comments