Exemplo n.º 1
0
  protected void leaveInstanceOf(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
    WalkContext context = (WalkContext) c;
    int result = context.getValue(n);

    visit(n.getChild(0), context, visitor);
    int value = context.getValue(n.getChild(0));

    visit(n.getChild(1), context, visitor);
    int type = context.getValue(n.getChild(1));

    context.cfg().addInstruction(new JavaScriptInstanceOf(result, value, type));
  }
Exemplo n.º 2
0
 protected void doFieldWrite(
     WalkContext context, int receiver, CAstNode elt, CAstNode parent, int rval) {
   this.visit(elt, context, this);
   if (elt.getKind() == CAstNode.CONSTANT && elt.getValue() instanceof String) {
     String field = (String) elt.getValue();
     if (isPrologueScript(context) && "__proto__".equals(field)) {
       context.cfg().addInstruction(((JSInstructionFactory) insts).SetPrototype(receiver, rval));
       return;
     }
   }
   /*
     } else {
       context.currentScope().getConstantValue(field);
       SSAPutInstruction put = ((JSInstructionFactory) insts).PutInstruction(receiver, rval, field);
       try {
         assert field.equals(put.getDeclaredField().getName().toUnicodeString());
       } catch (UTFDataFormatException e) {
         Assertions.UNREACHABLE();
       }
       context.cfg().addInstruction(put);
     }
   } else {
   */
   context
       .cfg()
       .addInstruction(
           ((JSInstructionFactory) insts).PropertyWrite(receiver, context.getValue(elt), rval));
   // }
 }
Exemplo n.º 3
0
  protected boolean doVisit(CAstNode n, WalkContext cntxt, CAstVisitor<WalkContext> visitor) {
    WalkContext context = (WalkContext) cntxt;
    switch (n.getKind()) {
      case CAstNode.TYPE_OF:
        {
          int result = context.currentScope().allocateTempValue();

          this.visit(n.getChild(0), context, this);
          int ref = context.getValue(n.getChild(0));

          context
              .cfg()
              .addInstruction(((JSInstructionFactory) insts).TypeOfInstruction(result, ref));

          context.setValue(n, result);
          return true;
        }

      case JavaScriptCAstNode.ENTER_WITH:
      case JavaScriptCAstNode.EXIT_WITH:
        {
          this.visit(n.getChild(0), context, this);
          int ref = context.getValue(n.getChild(0));

          context
              .cfg()
              .addInstruction(
                  ((JSInstructionFactory) insts)
                      .WithRegion(ref, n.getKind() == JavaScriptCAstNode.ENTER_WITH));

          return true;
        }
      default:
        {
          return false;
        }
    }
  }
Exemplo n.º 4
0
  protected void doFieldRead(
      WalkContext context, int result, int receiver, CAstNode elt, CAstNode readNode) {
    this.visit(elt, context, this);
    int x = context.currentScope().allocateTempValue();

    context.cfg().addInstruction(((JSInstructionFactory) insts).AssignInstruction(x, receiver));

    context.cfg().addInstruction(((JSInstructionFactory) insts).PrototypeLookup(x, x));

    if (elt.getKind() == CAstNode.CONSTANT && elt.getValue() instanceof String) {
      String field = (String) elt.getValue();
      // symtab needs to have this value
      context.currentScope().getConstantValue(field);
      context.cfg().addInstruction(((JSInstructionFactory) insts).GetInstruction(result, x, field));
    } else {
      context
          .cfg()
          .addInstruction(
              ((JSInstructionFactory) insts).PropertyRead(result, x, context.getValue(elt)));
    }

    // generate code to handle read of non-existent property
    if (context.getControlFlow().getMappedNodes().contains(readNode)) {
      context.cfg().addPreNode(readNode, context.getUnwindState());

      context.cfg().newBlock(true);

      if (context.getControlFlow().getTarget(readNode, JavaScriptTypes.TypeError) != null)
        context
            .cfg()
            .addPreEdge(
                readNode,
                context.getControlFlow().getTarget(readNode, JavaScriptTypes.TypeError),
                true);
      else context.cfg().addPreEdgeToExit(readNode, true);
    }
  }
Exemplo n.º 5
0
  protected void doIsFieldDefined(WalkContext context, int result, int ref, CAstNode f) {
    if (f.getKind() == CAstNode.CONSTANT && f.getValue() instanceof String) {
      String field = (String) f.getValue();

      FieldReference fieldRef =
          FieldReference.findOrCreate(
              JavaScriptTypes.Root,
              Atom.findOrCreateUnicodeAtom((String) field),
              JavaScriptTypes.Root);

      context
          .cfg()
          .addInstruction(
              ((JSInstructionFactory) insts).IsDefinedInstruction(result, ref, fieldRef));

    } else {

      context
          .cfg()
          .addInstruction(
              ((JSInstructionFactory) insts)
                  .IsDefinedInstruction(result, ref, context.getValue(f)));
    }
  }