Skip to content

Store source in bytecode #217

@bnoordhuis

Description

@bnoordhuis

This is an example that demonstrates the problem:

$ git describe --tags
v0.2.0-39-gba8b80f
$ make
$ cat test.js

function test()
{
        print("aaa");
}

print("Start test");
print("Source code of the function: " + test.toString());
print("End test");

$ ./qjsc -e ./test.js -o test.c
$ gcc ./test.c ./libqjs.a -lm -ldl -pthread

$ ./a.out

Start test
Source code of the function:
End test

$ ./qjs ./test.js

Start test
Source code of the function: function test()
{
        print("aaa");
}
End test

As you can see using previously generated bytecode the source code in not available.
Causes a different result when executing bytecode and javascript raw code.

Probably this is expected result by many to minimize bytecode size. Source code is not saved during bytes code save.
In any case, this causes problems with some scripts checking own source code during runtime, so it will be great to have option to save/load field "JSFunctionBytecode.source" when bytecode is saved.

Originally posted by @e2iplayer in #215 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions