[JS] apache-arrow doesn't work on platform restricting eval/new Function
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript, typescript
- Domain
- backend
Research direction
Read builder/valid.ts, especially createIsValidFunction and its handling of null values and NaN. Confirm the change works on platforms that restrict eval and new Function while preserving the existing validation behavior; the issue does not name a test file, so inspect the surrounding validation tests or entry points before running them.
Written by the indexing model from the issue text.
Description
Describe the bug, including details regarding any error messages, version, and platform.
Some platforms don't allow eval or new Function. CloudFlare workers is one such platform.
createIsValidFunction templates out a validation function using switch, since it's very fast. However, this doesn't work on CloudFlare workers (or generally workerd).
The function in question:
builder/valid.ts
export function createIsValidFunction<T extends DataType = any, TNull = any>(nullValues?: ReadonlyArray<TNull>) {
if (!nullValues || nullValues.length <= 0) {
// @ts-ignore
return function isValid(value: any) { return true; };
}
let fnBody = '';
const noNaNs = nullValues.filter((x) => x === x);
if (noNaNs.length > 0) {
fnBody = `
switch (x) {${noNaNs.map((x) => `
case ${valueToCase(x)}:`).join('')}
return false;
}`;
}
// NaN doesn't equal anything including itself, so it doesn't work as a
// switch case. Instead we must explicitly check for NaN before the switch.
if (nullValues.length !== noNaNs.length) {
fnBody = `if (x !== x) return false;\n${fnBody}`;
}
return new Function(`x`, `${fnBody}\nreturn true;`) as (value: T['TValue'] | TNull) => boolean;
}
This is the only place in apache-arrow that uses new Function.
I have been able to patch it locally and moved forward doing that. I'd like to know if there's any interest in having the library function out-of-the-box on CloudFlare. If so, we would be willing to refine our patch and submit for review.
Thank you.
Component(s)
JavaScript
- Dominant language
- TypeScript
- Stars
- 112
- Forks
- 23
- Avg merge
- 17h 55m
- Merged PRs (30d)
- 10
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/arrow-js
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 50/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
mksglu/context-mode#1200 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
jaegertracing/jaeger-ui#4506 ·
-
area:desktop area:ui bug platform:macos
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
anthropics/claude-code#96687 ·
-
good first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
AOSSIE-Org/DebateAI#582 · 2 comments ·