(Object key, Scriptable holder, StringifyState state)
| 251 | } |
| 252 | |
| 253 | private static Object str(Object key, Scriptable holder, StringifyState state) { |
| 254 | Object value = null; |
| 255 | Object unwrappedJavaValue = null; |
| 256 | |
| 257 | String keyString = null; |
| 258 | int keyInt = 0; |
| 259 | if (key instanceof String) { |
| 260 | keyString = (String) key; |
| 261 | value = getProperty(holder, keyString); |
| 262 | } else { |
| 263 | keyInt = ((Number) key).intValue(); |
| 264 | value = getProperty(holder, keyInt); |
| 265 | } |
| 266 | |
| 267 | if (value instanceof Scriptable && hasProperty((Scriptable) value, "toJSON")) { |
| 268 | Object toJSON = getProperty((Scriptable) value, "toJSON"); |
| 269 | if (toJSON instanceof Callable) { |
| 270 | value = |
| 271 | callMethod( |
| 272 | state.cx, |
| 273 | (Scriptable) value, |
| 274 | "toJSON", |
| 275 | new Object[] { |
| 276 | keyString == null ? Integer.toString(keyInt) : keyString |
| 277 | }); |
| 278 | } |
| 279 | } else if (value instanceof BigInteger) { |
| 280 | Scriptable bigInt = ScriptRuntime.toObject(state.cx, state.scope, value); |
| 281 | if (hasProperty(bigInt, "toJSON")) { |
| 282 | Object toJSON = getProperty(bigInt, "toJSON"); |
| 283 | if (toJSON instanceof Callable) { |
| 284 | value = |
| 285 | callMethod( |
| 286 | state.cx, |
| 287 | bigInt, |
| 288 | "toJSON", |
| 289 | new Object[] { |
| 290 | keyString == null ? Integer.toString(keyInt) : keyString |
| 291 | }); |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | if (state.replacer != null) { |
| 297 | value = state.replacer.call(state.cx, state.scope, holder, new Object[] {key, value}); |
| 298 | } |
| 299 | |
| 300 | if (ScriptRuntime.isSymbol(value)) return Undefined.instance; |
| 301 | |
| 302 | if (value instanceof NativeNumber) { |
| 303 | value = Double.valueOf(ScriptRuntime.toNumber(value)); |
| 304 | } else if (value instanceof NativeString) { |
| 305 | value = ScriptRuntime.toString(value); |
| 306 | } else if (value instanceof NativeBoolean) { |
| 307 | value = ((NativeBoolean) value).getDefaultValue(ScriptRuntime.BooleanClass); |
| 308 | } else if (state.cx.getLanguageVersion() >= Context.VERSION_ES6 |
| 309 | && value instanceof NativeBigInt) { |
| 310 | value = ((NativeBigInt) value).getDefaultValue(ScriptRuntime.BigIntegerClass); |
no test coverage detected