Giter Club home page Giter Club logo

Comments (4)

wirthi avatar wirthi commented on May 23, 2024

Hi Daniel,

thanks for reporting. Can you please share a bit more code around; especially, what is your eventContext?

Intuitively, the error could just mean you try to access this where no this yet exists.

Best,
Christian

from graaljs.

numberpi avatar numberpi commented on May 23, 2024

Hi Christian,

here is more context:
This is the Factory which creates and inserts the inline-parsed Node:

final class InlineEvaluationEventFactory implements ExecutionEventNodeFactory {
    private final TruffleInstrument.Env env;

    public InlineEvaluationEventFactory(TruffleInstrument.Env env) {
        this.env = env;
    }

    public ExecutionEventNode create(final EventContext eventContext) {
        return new ExecutionEventNode() {
            @Override
            protected void onEnter(VirtualFrame frame) {
                final LanguageInfo info = eventContext.getInstrumentedNode().getRootNode().getLanguageInfo();
                final String code = eventContext.getInstrumentedSourceSection().getCharacters().toString();
                final Source source = Source.newBuilder(code).name("eval in context").language(info.getId()).mimeType("content/unknown").build();
                ExecutableNode fragment = env.parseInline(source, eventContext.getInstrumentedNode(), frame.materialize());
                if (fragment != null) {
                    insert(fragment);
                    Object result;
                    try {
                        result = fragment.execute(frame);
                    } catch (Exception e) {
                        ...
                    }
                    ...
                }
            }
        };
    }
}

The factory is used by:

CallTarget callTarget = parse(...);
EventBinding<ExecutionEventNodeFactory> binding = this.env.getInstrumenter().attachExecutionEventFactory(
                            createSourceSectionFilter(uri, sourceSection, name),
                            new InlineEvaluationEventFactory(this.env));
callTarget.call();

So what I am trying to do is getting runtime type information for a specific code snippet (e.g. this) by executing some js source code, attaching a listener for a specific source section and then inline-evaluating the code snippet when the execution reaches the desired source location. Like setting a breakpoint in a debugger and evaluating a piece of code when execution pauses at the breakpoint.

The code snippet I was using is for example:

function Filter(number) {
    this.number = number;
    this  // <- eval this expression when execution arrives here
}

new Filter(123);

So there should exist a this in the context of the Filter function. For everything else except this it is working.

from graaljs.

woess avatar woess commented on May 23, 2024

Thanks for the detailed information, this is helpful. We'll investigate.

from graaljs.

woess avatar woess commented on May 23, 2024

Should be fixed by 4d94b1c.

from graaljs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.