-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add JS_Eval* overloads taking line #822
base: master
Are you sure you want to change the base?
Conversation
Can't this be implemented in user land with Error.prepareStackTrace? This API feels quite strange. |
How so? We evaluate JS code on RHS of properties and then work with the value in C++ code. |
I think Saúl is saying (and I agree) the way the new API is designed is too niche / too special-case. A better way is to pass in a versioned struct, e.g.: #define JS_EVAL_OPTIONS_VERSION 1
typedef struct JSEValOptions {
int version;
const char *filename;
int eval_flags;
int line_num;
// can add new fields in ABI-compatible manner by incrementing JS_EVAL2_VERSION
} JSEValOptions;
JS_EXTERN JSValue JS_Eval2(JSContext *ctx, const char *input, size_t input_len, JSEvalOptions *options); And callers use that like this: JSValue r = JS_Eval2(ctx, source, strlen(source), &(JSEvalOptions) {
.version = JS_EVAL_OPTIONS_VERSION,
.filename = "x.js",
.line_num = 1,
}); JS_Eval2 should use good defaults for omitted fields, e.g. JSValue JS_Eval2(JSContext *ctx, const char *input, size_t input_len, JSEvalOptions *options)
{
const char *filename = "<unnamed>";
// ...
if (options && options->filename)
filename = options->filename;
// ...
} |
Ops, forgot to reply! WHat I meant is something like so:
I don't know how your app works really, so apologies if this misses the point. |
typedef struct JSEvalOptions { | ||
int version; | ||
const char *filename; | ||
int eval_flags; | ||
int line_num; | ||
// can add new fields in ABI-compatible manner by incrementing JS_EVAL2_VERSION | ||
} JSEvalOptions; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filename
should be moved to first or third position to avoid padding on 64-bit targets
When evaluating QML code, only parts of the file contain valid JS code; and it is crucial to pass the line of that part rather than 1 in order to report correct lines to user.