MCPcopy Create free account
hub / github.com/mozilla/rhino / str

Method str

rhino/src/main/java/org/mozilla/javascript/NativeJSON.java:253–357  ·  view source on GitHub ↗
(Object key, Scriptable holder, StringifyState state)

Source from the content-addressed store, hash-verified

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);

Callers 4

stringifyMethod · 0.95
joMethod · 0.95
jaMethod · 0.95
javaToJSONMethod · 0.95

Calls 15

toObjectMethod · 0.95
isSymbolMethod · 0.95
toNumberMethod · 0.95
toStringMethod · 0.95
quoteMethod · 0.95
typeErrorByIdMethod · 0.95
javaToJSONMethod · 0.95
isObjectArrayLikeMethod · 0.95
jaMethod · 0.95
joMethod · 0.95
getClassMethod · 0.80
toStringMethod · 0.65

Tested by

no test coverage detected