-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
vm.compileFunction throws an RangeError when invoked with options.lineOffset < 0 #43207
Comments
i think technically the bug here is that we allow negative numbers elsewhere. |
But IMO negative number should be allowed, actually. Here's my use case: await vm.compileFunction(
"return (async () => {\n" +
(await fsp.readFile("something")).toString() +
"\n})();",
[], {
lineOffset: -1,
contextExtensions: [{ something: something }]
}) (); |
It seems like a better approach might be to support async function bodies in |
Orthogonal issues? V8 deliberately supports negative line and column offsets, ergo, it seems reasonable to support them in node as well. |
Yes, but anyway we should support negative lineOffset. In most circumstances we add wrappers around the code, not remove parts of the code.
to work. Line 1044 in a346572
Line 1112 in a346572
node/deps/v8/include/v8-message.h Line 65 in a346572
lineOffset is a signed int32. |
@bnoordhuis @devsnek So this question should support negative numbers? I'm happy to submit a pull request - internalCompileFunction method in the verification lineOffset parameter, validateUint32 to validateInt32 on the line, right? |
@sinkhaha yes, I believe so. |
@bnoordhuis After testing that 'lineOffset' supports negative numbers, stack failed to print the correct line number. For example, the following example passed the test assert.throws(() => {
vm.compileFunction(
'throw new Error("Sample Error")',
[],
{ lineOffset: -1 }
)();
}, {
message: 'Sample Error',
stack: 'Error: Sample Error\n at <anonymous>'
}); I'm not sure if this behavior meets expectations. If stack is changed to "Error: Sample Error\n at :0:7", the test will not pass. I'm not sure it makes sense to support negative numbers. |
Closed via #49855 |
Version
v18.2.0
Platform
Linux localhost 5.17.0-rc7-asahi-next-20220310-5-2-ARCH #4 SMP PREEMPT Fri, 20 May 2022 00:28:08 +0000 aarch64 GNU/Linux
Subsystem
node:vm
What steps will reproduce the bug?
node -p 'vm.compileFunction("", [], { lineOffset: -1 })'
How often does it reproduce? Is there a required condition?
Always, without conditions.
What is the expected behavior?
What do you see instead?
Additional information
script.runInContext
,runInContext
, etc. acceptoptions.lineOffset
< 0.The text was updated successfully, but these errors were encountered: