Add JS_Eval* overloads taking line#822
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. |
|
@saghul gentle ping |
bnoordhuis
left a comment
There was a problem hiding this comment.
LGTM
@saghul can you take a quick look as well?
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.