@Override public boolean enterAccessNode(final AccessNode accessNode) { enterDefault(accessNode); type("MemberExpression"); comma(); property("object"); accessNode.getBase().accept(this); comma(); property("property", accessNode.getProperty()); comma(); property("computed", false); return leave(); }
private Object evaluateSafely(final Expression expr) { if (expr instanceof IdentNode) { return runtimeScope == null ? null : evaluatePropertySafely(runtimeScope, ((IdentNode)expr).getName()); } if (expr instanceof AccessNode) { final AccessNode accessNode = (AccessNode)expr; final Object base = evaluateSafely(accessNode.getBase()); if (!(base instanceof ScriptObject)) { return null; } return evaluatePropertySafely((ScriptObject)base, accessNode.getProperty()); } return null; }
private boolean checkValidLValue(final Expression init, final String contextString) { if (init instanceof IdentNode) { if (!checkIdentLValue((IdentNode)init)) { return false; } verifyIdent((IdentNode)init, contextString); return true; } else if (init instanceof AccessNode || init instanceof IndexNode) { return true; } else if (isDestructuringLhs(init)) { verifyDestructuringAssignmentPattern(init, contextString); return true; } else { return false; } }
@Override public boolean enterAccessNode(final AccessNode accessNode) { enterDefault(accessNode); type("MemberExpression"); comma(); property("object"); accessNode.getBase().accept(this); comma(); property("property"); accessNode.getProperty().accept(this); comma(); property("computed", false); return leave(); }
@Override public Node leaveASSIGN(final BinaryNode binaryNode) { final SpecializedNode specialized = specialize(binaryNode); final BinaryNode specBinaryNode = (BinaryNode)specialized.node; Type destType = specialized.type; if (destType == null) { destType = specBinaryNode.getType(); } // Register assignments to this object in case this is used as constructor if (binaryNode.lhs() instanceof AccessNode) { AccessNode accessNode = (AccessNode) binaryNode.lhs(); if (accessNode.getBase().getSymbol().isThis()) { lc.getCurrentFunction().addThisProperty(accessNode.getProperty().getName()); } } return specBinaryNode.setRHS(convert(specBinaryNode.rhs(), destType)); }
private String getDefaultFunctionName() { if(!defaultNames.isEmpty()) { final Object nameExpr = defaultNames.peek(); if(nameExpr instanceof PropertyKey) { markDefaultNameUsed(); return ((PropertyKey)nameExpr).getPropertyName(); } else if(nameExpr instanceof AccessNode) { markDefaultNameUsed(); return ((AccessNode)nameExpr).getProperty(); } } return null; }
private Node leaveASSIGN(final BinaryNode binaryNode) { // If we're assigning a property of the this object ("this.foo = ..."), record it. final Expression lhs = binaryNode.lhs(); if (lhs instanceof AccessNode) { final AccessNode accessNode = (AccessNode) lhs; final Expression base = accessNode.getBase(); if (base instanceof IdentNode) { final Symbol symbol = ((IdentNode)base).getSymbol(); if(symbol.isThis()) { thisProperties.peek().add(accessNode.getProperty()); } } } return binaryNode; }
private String getDefaultFunctionName() { if (!defaultNames.isEmpty()) { final Object nameExpr = defaultNames.peek(); if (nameExpr instanceof PropertyKey) { markDefaultNameUsed(); return ((PropertyKey)nameExpr).getPropertyName(); } else if (nameExpr instanceof AccessNode) { markDefaultNameUsed(); return ((AccessNode)nameExpr).getProperty(); } } return null; }
private Node leaveASSIGN(final BinaryNode binaryNode) { // If we're assigning a property of the this object ("this.foo = ..."), record it. final Expression lhs = binaryNode.lhs(); if (lhs instanceof AccessNode) { final AccessNode accessNode = (AccessNode) lhs; final Expression base = accessNode.getBase(); if (base instanceof IdentNode) { final Symbol symbol = ((IdentNode) base).getSymbol(); if (symbol.isThis()) { thisProperties.peek().add(accessNode.getProperty()); } } } return binaryNode; }
/** * Verify an assignment expression. * @param op Operation token. * @param lhs Left hand side expression. * @param rhs Right hand side expression. * @return Verified expression. */ private Expression verifyAssignment(final long op, final Expression lhs, final Expression rhs) { final TokenType opType = Token.descType(op); switch (opType) { case ASSIGN: case ASSIGN_ADD: case ASSIGN_BIT_AND: case ASSIGN_BIT_OR: case ASSIGN_BIT_XOR: case ASSIGN_DIV: case ASSIGN_MOD: case ASSIGN_MUL: case ASSIGN_SAR: case ASSIGN_SHL: case ASSIGN_SHR: case ASSIGN_SUB: if (!(lhs instanceof AccessNode || lhs instanceof IndexNode || lhs instanceof IdentNode)) { return referenceError(lhs, rhs, env._early_lvalue_error); } if (lhs instanceof IdentNode) { if (!checkIdentLValue((IdentNode)lhs)) { return referenceError(lhs, rhs, false); } verifyStrictIdent((IdentNode)lhs, "assignment"); } break; default: break; } // Build up node. return new BinaryNode(op, lhs, rhs); }
@Override public Node leaveAccessNode(final AccessNode accessNode) { //While Object type is assigned here, Access Specialization in FinalizeTypes may narrow this, that //is why we can't set the access node base to be an object here, that will ruin access specialization //for example for a.x | 17. return end(ensureSymbol(Type.OBJECT, accessNode)); }