< prev index next >

src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JSObjectLinker.java

Print this page




  54         this.nashornBeansLinker = nashornBeansLinker;
  55     }
  56 
  57     @Override
  58     public boolean canLinkType(final Class<?> type) {
  59         return canLinkTypeStatic(type);
  60     }
  61 
  62     static boolean canLinkTypeStatic(final Class<?> type) {
  63         // can link JSObject also handles Map, Bindings to make
  64         // sure those are not JSObjects.
  65         return Map.class.isAssignableFrom(type) ||
  66                Bindings.class.isAssignableFrom(type) ||
  67                JSObject.class.isAssignableFrom(type);
  68     }
  69 
  70     @Override
  71     public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception {
  72         final Object self = request.getReceiver();
  73         final CallSiteDescriptor desc = request.getCallSiteDescriptor();



  74 
  75         GuardedInvocation inv;
  76         if (self instanceof JSObject) {
  77             inv = lookup(desc, request, linkerServices);
  78             inv = inv.replaceMethods(linkerServices.filterInternalObjects(inv.getInvocation()), inv.getGuard());
  79         } else if (self instanceof Map || self instanceof Bindings) {
  80             // guard to make sure the Map or Bindings does not turn into JSObject later!
  81             final GuardedInvocation beanInv = nashornBeansLinker.getGuardedInvocation(request, linkerServices);
  82             inv = new GuardedInvocation(beanInv.getInvocation(),
  83                 NashornGuards.combineGuards(beanInv.getGuard(), NashornGuards.getNotJSObjectGuard()));
  84         } else {
  85             throw new AssertionError(); // Should never reach here.
  86         }
  87 
  88         return Bootstrap.asTypeSafeReturn(inv, linkerServices, desc);
  89     }
  90 
  91     private GuardedInvocation lookup(final CallSiteDescriptor desc, final LinkRequest request, final LinkerServices linkerServices) throws Exception {
  92         final StandardOperation op = NashornCallSiteDescriptor.getFirstStandardOperation(desc);
  93         if (op == null) {
  94             return null;
  95         }
  96         final String name = NashornCallSiteDescriptor.getOperand(desc);
  97         switch (op) {
  98         case GET_PROPERTY:
  99         case GET_ELEMENT:
 100         case GET_METHOD:
 101             if (name != null) {
 102                 return findGetMethod(name);
 103             }
 104             // For indexed get, we want get GuardedInvocation beans linker and pass it.
 105             // JSObjectLinker.get uses this fallback getter for explicit signature method access.




  54         this.nashornBeansLinker = nashornBeansLinker;
  55     }
  56 
  57     @Override
  58     public boolean canLinkType(final Class<?> type) {
  59         return canLinkTypeStatic(type);
  60     }
  61 
  62     static boolean canLinkTypeStatic(final Class<?> type) {
  63         // can link JSObject also handles Map, Bindings to make
  64         // sure those are not JSObjects.
  65         return Map.class.isAssignableFrom(type) ||
  66                Bindings.class.isAssignableFrom(type) ||
  67                JSObject.class.isAssignableFrom(type);
  68     }
  69 
  70     @Override
  71     public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception {
  72         final Object self = request.getReceiver();
  73         final CallSiteDescriptor desc = request.getCallSiteDescriptor();
  74         if (self == null || !canLinkTypeStatic(self.getClass())) {
  75             return null;
  76         }
  77 
  78         GuardedInvocation inv;
  79         if (self instanceof JSObject) {
  80             inv = lookup(desc, request, linkerServices);
  81             inv = inv.replaceMethods(linkerServices.filterInternalObjects(inv.getInvocation()), inv.getGuard());
  82         } else if (self instanceof Map || self instanceof Bindings) {
  83             // guard to make sure the Map or Bindings does not turn into JSObject later!
  84             final GuardedInvocation beanInv = nashornBeansLinker.getGuardedInvocation(request, linkerServices);
  85             inv = new GuardedInvocation(beanInv.getInvocation(),
  86                 NashornGuards.combineGuards(beanInv.getGuard(), NashornGuards.getNotJSObjectGuard()));
  87         } else {
  88             throw new AssertionError("got instanceof: " + self.getClass()); // Should never reach here.
  89         }
  90 
  91         return Bootstrap.asTypeSafeReturn(inv, linkerServices, desc);
  92     }
  93 
  94     private GuardedInvocation lookup(final CallSiteDescriptor desc, final LinkRequest request, final LinkerServices linkerServices) throws Exception {
  95         final StandardOperation op = NashornCallSiteDescriptor.getFirstStandardOperation(desc);
  96         if (op == null) {
  97             return null;
  98         }
  99         final String name = NashornCallSiteDescriptor.getOperand(desc);
 100         switch (op) {
 101         case GET_PROPERTY:
 102         case GET_ELEMENT:
 103         case GET_METHOD:
 104             if (name != null) {
 105                 return findGetMethod(name);
 106             }
 107             // For indexed get, we want get GuardedInvocation beans linker and pass it.
 108             // JSObjectLinker.get uses this fallback getter for explicit signature method access.


< prev index next >