src/jdk/nashorn/internal/objects/NativeJSON.java

Print this page

        

*** 160,185 **** // If the space parameter is a number, make an indent // string containing that many spaces. String gap; ! if (space instanceof Number || space instanceof NativeNumber) { ! int indent; ! if (space instanceof NativeNumber) { ! indent = ((NativeNumber)space).intValue(); ! } else { ! indent = ((Number)space).intValue(); } final StringBuilder sb = new StringBuilder(); ! for (int i = 0; i < Math.min(10, indent); i++) { sb.append(' '); } gap = sb.toString(); ! ! } else if (space instanceof String || space instanceof ConsString || space instanceof NativeString) { ! final String str = (space instanceof String) ? (String)space : space.toString(); gap = str.substring(0, Math.min(10, str.length())); } else { gap = ""; } --- 160,190 ---- // If the space parameter is a number, make an indent // string containing that many spaces. String gap; ! // modifiable 'space' - parameter is final ! Object modSpace = space; ! if (modSpace instanceof NativeNumber) { ! modSpace = JSType.toNumber(JSType.toPrimitive(modSpace, Number.class)); ! } else if (modSpace instanceof NativeString) { ! modSpace = JSType.toString(JSType.toPrimitive(modSpace, String.class)); } + if (modSpace instanceof Number) { + int indent = Math.min(10, JSType.toInteger(modSpace)); + if (indent < 1) { + gap = ""; + } else { final StringBuilder sb = new StringBuilder(); ! for (int i = 0; i < indent; i++) { sb.append(' '); } gap = sb.toString(); ! } ! } else if (modSpace instanceof String || modSpace instanceof ConsString) { ! final String str = modSpace.toString(); gap = str.substring(0, Math.min(10, str.length())); } else { gap = ""; }