src/jdk/nashorn/internal/runtime/JSONFunctions.java

Print this page

        

*** 31,40 **** --- 31,41 ---- import jdk.nashorn.internal.ir.LiteralNode; import jdk.nashorn.internal.ir.Node; import jdk.nashorn.internal.ir.ObjectNode; import jdk.nashorn.internal.ir.PropertyNode; import jdk.nashorn.internal.ir.UnaryNode; + import jdk.nashorn.internal.objects.Global; import jdk.nashorn.internal.parser.JSONParser; import jdk.nashorn.internal.parser.TokenType; import jdk.nashorn.internal.runtime.arrays.ArrayIndex; import jdk.nashorn.internal.runtime.linker.Bootstrap;
*** 45,55 **** private JSONFunctions() {} private static final Object REVIVER_INVOKER = new Object(); private static MethodHandle getREVIVER_INVOKER() { ! return ((GlobalObject)Context.getGlobal()).getDynamicInvoker(REVIVER_INVOKER, new Callable<MethodHandle>() { @Override public MethodHandle call() { return Bootstrap.createDynamicInvoker("dyn:call", Object.class, ScriptFunction.class, ScriptObject.class, String.class, Object.class); --- 46,56 ---- private JSONFunctions() {} private static final Object REVIVER_INVOKER = new Object(); private static MethodHandle getREVIVER_INVOKER() { ! return Context.getGlobal().getDynamicInvoker(REVIVER_INVOKER, new Callable<MethodHandle>() { @Override public MethodHandle call() { return Bootstrap.createDynamicInvoker("dyn:call", Object.class, ScriptFunction.class, ScriptObject.class, String.class, Object.class);
*** 86,109 **** node = parser.parse(); } catch (final ParserException e) { throw ECMAErrors.syntaxError(e, "invalid.json", e.getMessage()); } ! final ScriptObject global = Context.getGlobalTrusted(); Object unfiltered = convertNode(global, node); return applyReviver(global, unfiltered, reviver); } // -- Internals only below this point // parse helpers // apply 'reviver' function if available ! private static Object applyReviver(final ScriptObject global, final Object unfiltered, final Object reviver) { if (reviver instanceof ScriptFunction) { ! assert global instanceof GlobalObject; ! final ScriptObject root = ((GlobalObject)global).newObject(); root.addOwnProperty("", Property.WRITABLE_ENUMERABLE_CONFIGURABLE, unfiltered); return walk(root, "", (ScriptFunction)reviver); } return unfiltered; } --- 87,110 ---- node = parser.parse(); } catch (final ParserException e) { throw ECMAErrors.syntaxError(e, "invalid.json", e.getMessage()); } ! final Global global = Context.getGlobal(); Object unfiltered = convertNode(global, node); return applyReviver(global, unfiltered, reviver); } // -- Internals only below this point // parse helpers // apply 'reviver' function if available ! private static Object applyReviver(final Global global, final Object unfiltered, final Object reviver) { if (reviver instanceof ScriptFunction) { ! assert global instanceof Global; ! final ScriptObject root = global.newObject(); root.addOwnProperty("", Property.WRITABLE_ENUMERABLE_CONFIGURABLE, unfiltered); return walk(root, "", (ScriptFunction)reviver); } return unfiltered; }
*** 136,147 **** throw new RuntimeException(t); } } // Converts IR node to runtime value ! private static Object convertNode(final ScriptObject global, final Node node) { ! assert global instanceof GlobalObject; if (node instanceof LiteralNode) { // check for array literal if (node.tokenType() == TokenType.ARRAY) { assert node instanceof LiteralNode.ArrayLiteralNode; --- 137,148 ---- throw new RuntimeException(t); } } // Converts IR node to runtime value ! private static Object convertNode(final Global global, final Node node) { ! assert global instanceof Global; if (node instanceof LiteralNode) { // check for array literal if (node.tokenType() == TokenType.ARRAY) { assert node instanceof LiteralNode.ArrayLiteralNode;
*** 155,182 **** int index = 0; for (final Node elem : elements) { values[index++] = JSType.toNumber(convertNode(global, elem)); } ! return ((GlobalObject)global).wrapAsObject(values); } final Object[] values = new Object[elements.length]; int index = 0; for (final Node elem : elements) { values[index++] = convertNode(global, elem); } ! return ((GlobalObject)global).wrapAsObject(values); } return ((LiteralNode<?>)node).getValue(); } else if (node instanceof ObjectNode) { final ObjectNode objNode = (ObjectNode) node; ! final ScriptObject object = ((GlobalObject)global).newObject(); for (final PropertyNode pNode: objNode.getElements()) { final Node valueNode = pNode.getValue(); final String name = pNode.getKeyName(); --- 156,183 ---- int index = 0; for (final Node elem : elements) { values[index++] = JSType.toNumber(convertNode(global, elem)); } ! return global.wrapAsObject(values); } final Object[] values = new Object[elements.length]; int index = 0; for (final Node elem : elements) { values[index++] = convertNode(global, elem); } ! return global.wrapAsObject(values); } return ((LiteralNode<?>)node).getValue(); } else if (node instanceof ObjectNode) { final ObjectNode objNode = (ObjectNode) node; ! final ScriptObject object = global.newObject(); for (final PropertyNode pNode: objNode.getElements()) { final Node valueNode = pNode.getValue(); final String name = pNode.getKeyName();