@Override public boolean enterObjectNode(final ObjectNode objectNode) { weight += OBJECT_WEIGHT; final List<PropertyNode> properties = objectNode.getElements(); final boolean isSpillObject = properties.size() > CodeGenerator.OBJECT_SPILL_THRESHOLD; for (final PropertyNode property : properties) { if (!LiteralNode.isConstant(property.getValue())) { weight += SETPROP_WEIGHT; property.getValue().accept(this); } else if (!isSpillObject) { // constants in spill object are set via preset spill array, // but fields objects need to set constants. weight += SETPROP_WEIGHT; } } return false; }
@Override public boolean enterObjectNode(final ObjectNode objectNode) { enterDefault(objectNode); type("ObjectExpression"); comma(); array("properties", objectNode.getElements()); return leave(); }
/** * Check if a property value contains a particular program point * @param value value * @param pp program point * @return true if it's there. */ private static boolean propertyValueContains(final Expression value, final int pp) { return new Supplier<Boolean>() { boolean contains; @Override public Boolean get() { value.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { @Override public boolean enterFunctionNode(final FunctionNode functionNode) { return false; } @Override public boolean enterObjectNode(final ObjectNode objectNode) { return false; } @Override public boolean enterDefault(final Node node) { if (contains) { return false; } if (node instanceof Optimistic && ((Optimistic)node).getProgramPoint() == pp) { contains = true; return false; } return true; } }); return contains; } }.get(); }
@Override public boolean enterObjectNode(final ObjectNode objectNode) { final List<PropertyNode> propNodes = objectNode.getElements(); final List<? extends PropertyTree> propTrees = translateProperties(propNodes); curExpr = new ObjectLiteralTreeImpl(objectNode, propTrees); return false; }
@Override public Node leaveObjectNode(final ObjectNode objectNode) { final List<Splittable.SplitRange> ranges = objectNode.getSplitRanges(); if (ranges != null) { final List<Splittable.SplitRange> newRanges = new ArrayList<>(); for (final Splittable.SplitRange range : ranges) { newRanges.add(new Splittable.SplitRange(getExistingReplacement(range), range.getLow(), range.getHigh())); } return objectNode.setSplitRanges(lc, newRanges); } return super.leaveObjectNode(objectNode); }
@Override public boolean enterForNode(final ForNode forNode) { if (es6 && (forNode.getInit() instanceof ObjectNode || forNode.getInit() instanceof ArrayLiteralNode)) { throwNotImplementedYet("es6.destructuring", forNode); } return super.enterForNode(forNode); }
@Override public boolean enterASSIGN(BinaryNode binaryNode) { if (es6 && (binaryNode.lhs() instanceof ObjectNode || binaryNode.lhs() instanceof ArrayLiteralNode)) { throwNotImplementedYet("es6.destructuring", binaryNode); } return super.enterASSIGN(binaryNode); }
@Override public boolean enterObjectNode(final ObjectNode objectNode) { for(final PropertyNode propertyNode: objectNode.getElements()) { // Avoid falsely adding property keys to the control flow graph final Expression value = propertyNode.getValue(); if (value != null) { visitExpression(value); } } return pushExpressionType(objectNode); }
@Override public boolean enterObjectNode(final ObjectNode objectNode) { final List<PropertyNode> propNodes = objectNode.getElements(); final List<PropertyTreeImpl> propTrees = new ArrayList<>(propNodes.size()); for (final PropertyNode propNode : propNodes) { propTrees.add(new PropertyTreeImpl(propNode, translateExpr(propNode.getKey()), translateExpr(propNode.getValue()), (FunctionExpressionTree) translateExpr(propNode.getGetter()), (FunctionExpressionTree) translateExpr(propNode.getSetter()))); } curExpr = new ObjectLiteralTreeImpl(objectNode, propTrees); return false; }
/** * Check if a property value contains a particular program point * @param value value * @param pp program point * @return true if it's there. */ private static boolean propertyValueContains(final Expression value, final int pp) { return new Supplier<Boolean>() { boolean contains; @Override public Boolean get() { value.accept(new SimpleNodeVisitor() { @Override public boolean enterFunctionNode(final FunctionNode functionNode) { return false; } @Override public boolean enterObjectNode(final ObjectNode objectNode) { return false; } @Override public boolean enterDefault(final Node node) { if (contains) { return false; } if (node instanceof Optimistic && ((Optimistic)node).getProgramPoint() == pp) { contains = true; return false; } return true; } }); return contains; } }.get(); }
/** * Parse an object literal from the token stream * @return the object literal as a Node */ private ObjectNode objectLiteral() { // Capture LBRACE token. final long objectToken = token; // LBRACE tested in caller. next(); // Prepare to accumulate elements. final List<PropertyNode> elements = new ArrayList<>(); // Create a block for the object literal. loop: while (true) { switch (type) { case RBRACE: next(); break loop; case COMMARIGHT: next(); // check for trailing comma - not allowed in JSON if (type == RBRACE) { throw error(AbstractParser.message("trailing.comma.in.json", type.getNameOrType())); } break; default: // Get and add the next property. final PropertyNode property = propertyAssignment(); elements.add(property); // Comma between property assigments is mandatory in JSON. if (type != RBRACE && type != COMMARIGHT) { throw error(AbstractParser.message("expected", ", or }", type.getNameOrType())); } break; } } // Construct new object literal. return new ObjectNode(objectToken, finish, elements); }
ObjectLiteralTreeImpl(final ObjectNode node, final List<? extends PropertyTree> props) { super(node); this.props = props; }
private boolean isDestructuringLhs(final Expression lhs) { if (lhs instanceof ObjectNode || lhs instanceof LiteralNode.ArrayLiteralNode) { return isES6(); } return false; }
@Override public boolean enterObjectNode(final ObjectNode objectNode) { return true; }
private boolean isDestructuringLhs(Expression lhs) { if (lhs instanceof ObjectNode || lhs instanceof LiteralNode.ArrayLiteralNode) { return isES6(); } return false; }