Java Code Examples for com.oracle.truffle.api.nodes.Node#Child

The following examples show how to use com.oracle.truffle.api.nodes.Node#Child . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LiteralFactory.java    From nodeprof.js with Apache License 2.0 6 votes vote down vote up
@Override
public BaseEventHandlerNode create(EventContext context) {
    return new LiteralEventHandler(context) {
        private final boolean skip = !types.contains(LiteralTag.Type.valueOf(getLiteralType()));
        @Node.Child private InteropLibrary postDispatch = (post == null) ? null : createDispatchNode();

        @Override
        public void executePost(VirtualFrame frame, Object result,
                        Object[] inputs) throws InteropException {
            if (post != null && !skip) {
                wrappedDispatchExecution(this, postDispatch, post, getSourceIID(), convertResult(result), Undefined.instance, getLiteralType());
            }
        }

    };
}
 
Example 2
Source File: DeclareFactory.java    From nodeprof.js with Apache License 2.0 6 votes vote down vote up
@Override
public BaseEventHandlerNode create(EventContext context) {
    return new DeclareEventHandler(context) {
        @Node.Child private InteropLibrary postDispatch = (post == null) ? null : createDispatchNode();

        @Override
        public void executePost(VirtualFrame frame, Object result,
                        Object[] inputs) throws InteropException {
            if (post != null) {
                checkForSymbolicLocation(context.getInstrumentedNode(), frame.getArguments());

                wrappedDispatchExecution(this, postDispatch, post, getSourceIID(), getDeclareName(), getDeclareType());
            }
        }

    };
}
 
Example 3
Source File: ForObjectFactory.java    From nodeprof.js with Apache License 2.0 5 votes vote down vote up
@Override
public BaseEventHandlerNode create(EventContext context) {
    return new LoopEventHandler(context) {
        @Node.Child private InteropLibrary preDispatch = (pre == null) ? null : createDispatchNode();

        @Override
        public void executePre(VirtualFrame frame,
                        Object[] inputs) throws InteropException {
            if (pre != null && (isForIn() || isForOf())) {
                wrappedDispatchExecution(this, preDispatch, pre, getSourceIID(), isForIn());
            }
        }
    };
}
 
Example 4
Source File: InitialRootFactory.java    From nodeprof.js with Apache License 2.0 5 votes vote down vote up
@Override
public BaseEventHandlerNode create(EventContext context) {
    return new FunctionRootEventHandler(context) {
        @Node.Child private InteropLibrary postDispatch = (post == null) ? null : createDispatchNode();

        @Override
        public int getPriority() {
            return -1;
        }

        @Override
        public BaseEventHandlerNode wantsToUpdateHandler() {
            // remove after initial execution
            return null;
        }

        @Override
        public void executePre(VirtualFrame frame, Object[] inputs) throws InteropException {
            checkForSymbolicLocation(context.getInstrumentedNode(), getArguments(frame));

            if (post == null) {
                return;
            }

            Source source = getSource();
            if (source == null) {
                return;
            }

            if (isNewSource(source)) {
                wrappedDispatchExecution(this, postDispatch, post,
                                SourceMapping.getJSObjectForSource(source), // arg 1: source
                                                                            // object
                                source.getCharacters().toString()); // arg 2: source code
            }
        }
    };
}
 
Example 5
Source File: AwaitFactory.java    From nodeprof.js with Apache License 2.0 4 votes vote down vote up
@Override
public BaseEventHandlerNode create(EventContext context) {
    return new CFBranchEventHandler(context) {
        @Node.Child private InteropLibrary preDispatch = (pre == null) ? null : createDispatchNode();
        @Node.Child private InteropLibrary postDispatch = (post == null) ? null : createDispatchNode();

        @Override

        public void executePre(VirtualFrame frame, Object[] inputs) throws InteropException {
            if (!this.isAwaitNode()) {
                return;
            }
            if (inputs == null || inputs.length == 0) {
                return;
            }
            if (pre != null) {
                if (inputs[0] == inputs[1] && JSPromise.isJSPromise(inputs[0])) {
                    // await some promise
                    wrappedDispatchExecution(this, preDispatch, pre, getSourceIID(), assertGetInput(0, inputs, "awaited val"));
                } else if (inputs[0] != inputs[1] && JSPromise.isJSPromise(inputs[1])) {
                    // await some value, and inputs[1] is the internal promise
                    wrappedDispatchExecution(this, preDispatch, pre, getSourceIID(), assertGetInput(0, inputs, "awaited val"));
                }
            }
            if (post != null) {
                if (inputs[0] != inputs[1] && !JSPromise.isJSPromise((inputs[1]))) {
                    wrappedDispatchExecution(this, postDispatch, post, getSourceIID(),
                                    inputs[0] == null ? Undefined.instance : inputs[0],
                                    assertGetInput(1, inputs, "awaited ret"),
                                    inputs[0] != null && JSPromise.isJSPromise(inputs[0]) && JSPromise.isRejected((DynamicObject) inputs[0]));
                } else if (inputs[0] == inputs[1] && !JSPromise.isJSPromise(inputs[0])) {
                    // await some value
                    wrappedDispatchExecution(this, postDispatch, post, getSourceIID(),
                                    assertGetInput(0, inputs, "awaited val"),
                                    assertGetInput(0, inputs, "awaited ret"),
                                    false);

                }
            }
        }

    };
}