private static Object handleMessage(Message message, Node messageNode, TruffleObject obj, String name, Object[] args) throws InteropException { if (message == Message.WRITE) { ForeignAccess.sendWrite(messageNode, obj, name, args[0]); return null; } if (message == Message.HAS_SIZE || message == Message.IS_BOXED || message == Message.IS_EXECUTABLE || message == Message.IS_NULL || message == Message.GET_SIZE) { return ForeignAccess.send(messageNode, obj); } if (message == Message.KEY_INFO) { return ForeignAccess.sendKeyInfo(messageNode, obj, name); } if (message == Message.READ) { return ForeignAccess.sendRead(messageNode, obj, name); } if (message == Message.UNBOX) { return ForeignAccess.sendUnbox(messageNode, obj); } if (Message.createExecute(0).equals(message)) { return ForeignAccess.sendExecute(messageNode, obj, args); } if (Message.createInvoke(0).equals(message)) { return ForeignAccess.sendInvoke(messageNode, obj, name, args); } if (Message.createNew(0).equals(message)) { return ForeignAccess.sendNew(messageNode, obj, args); } CompilerDirectives.transferToInterpreter(); throw UnsupportedMessageException.raise(message); }
/** * Sends a {@link Message#KEYS} message to the foreign receiver object. * * @param keysNode the createNode created by {@link Message#createNode()} * @param receiver foreign object to receive the message passed to {@link Message#createNode()} * method * @return return an instance of {@link TruffleObject} that responds to {@link Message#HAS_SIZE} * and {@link Message#GET_SIZE} and its 0 to {@link Message#GET_SIZE size - 1} indexes * contain {@link String} names of the properties of the <code>receiver</code> object * @throws UnsupportedMessageException if the message isn't handled * @throws ClassCastException if the createNode has not been created by * {@link Message#createNode()} method. * @since 0.24 */ public static TruffleObject sendKeys(Node keysNode, TruffleObject receiver) throws UnsupportedMessageException { try { return (TruffleObject) send(keysNode, receiver); } catch (UnsupportedMessageException ex) { CompilerDirectives.transferToInterpreter(); throw ex; } catch (InteropException e) { CompilerDirectives.transferToInterpreter(); throw new AssertionError("Unexpected exception caught.", e); } }
/** * Sends a {@link Message#KEYS} message to the foreign receiver object. * * @param keysNode the createNode created by {@link Message#createNode()} * @param receiver foreign object to receive the message passed to {@link Message#createNode()} * method * @return return an instance of {@link TruffleObject} that responds to {@link Message#HAS_SIZE} * and {@link Message#GET_SIZE} and its 0 to {@link Message#GET_SIZE size - 1} indexes * contain {@link String} names of the properties of the <code>receiver</code> object * @throws UnsupportedMessageException if the message isn't handled * @throws ClassCastException if the createNode has not been created by * {@link Message#createNode()} method. * @since 0.24 */ public static TruffleObject sendKeys(Node keysNode, TruffleObject receiver) throws UnsupportedMessageException { try { return (TruffleObject) send(keysNode, receiver); } catch (UnsupportedMessageException ex) { CompilerDirectives.transferToInterpreter(); throw ex; } catch (InteropException e) { CompilerDirectives.transferToInterpreter(); throw new AssertionError("Unexpected exception caught.", e); } }
/** * Sends a {@link Message#KEYS} message to the foreign receiver object, with a specification of * whether internal keys should be included in the result, or not. * * @param keysNode the createNode created by {@link Message#createNode()} * @param receiver foreign object to receive the message passed to {@link Message#createNode()} * method * @param includeInternal <code>true</code> to include internal keys in the result, * <code>false</code> to abandon them. * @return return an instance of {@link TruffleObject} that responds to {@link Message#HAS_SIZE} * and {@link Message#GET_SIZE} and its 0 to {@link Message#GET_SIZE size - 1} indexes * contain {@link String} names of the properties of the <code>receiver</code> object * @throws UnsupportedMessageException if the message isn't handled * @throws ClassCastException if the createNode has not been created by * {@link Message#createNode()} method. * @since 0.26 */ public static TruffleObject sendKeys(Node keysNode, TruffleObject receiver, boolean includeInternal) throws UnsupportedMessageException { try { return (TruffleObject) send(keysNode, receiver, includeInternal); } catch (UnsupportedMessageException ex) { CompilerDirectives.transferToInterpreter(); throw ex; } catch (InteropException e) { CompilerDirectives.transferToInterpreter(); throw new AssertionError("Unexpected exception caught.", e); } }
/** * Sends a {@link Message#KEYS} message to the foreign receiver object, with a specification of * whether internal keys should be included in the result, or not. * * @param keysNode the createNode created by {@link Message#createNode()} * @param receiver foreign object to receive the message passed to {@link Message#createNode()} * method * @param includeInternal <code>true</code> to include internal keys in the result, * <code>false</code> to abandon them. * @return return an instance of {@link TruffleObject} that responds to {@link Message#HAS_SIZE} * and {@link Message#GET_SIZE} and its 0 to {@link Message#GET_SIZE size - 1} indexes * contain {@link String} names of the properties of the <code>receiver</code> object * @throws UnsupportedMessageException if the message isn't handled * @throws ClassCastException if the createNode has not been created by * {@link Message#createNode()} method. * @since 0.26 */ public static TruffleObject sendKeys(Node keysNode, TruffleObject receiver, boolean includeInternal) throws UnsupportedMessageException { try { return (TruffleObject) send(keysNode, receiver, includeInternal); } catch (UnsupportedMessageException ex) { CompilerDirectives.transferToInterpreter(); throw ex; } catch (InteropException e) { CompilerDirectives.transferToInterpreter(); throw new AssertionError("Unexpected exception caught.", e); } }