Skip to content

Replace cxjs_eval() with a Safe Implementation - #116

Open
Lightning11wins wants to merge 9 commits into
masterfrom
add-eval
Open

Replace cxjs_eval() with a Safe Implementation#116
Lightning11wins wants to merge 9 commits into
masterfrom
add-eval

Conversation

@Lightning11wins

Copy link
Copy Markdown
Contributor

This PR will add a safe client-side implementation of eval, replacing the previous unsafe version.

@Lightning11wins Lightning11wins self-assigned this Jun 5, 2026
@Lightning11wins Lightning11wins added ai-review Request AI review for PRs. size: trivial Easy to review, probably ~100 lines or fewer. labels Jun 5, 2026
@greptile-apps

greptile-apps Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR replaces client-side expression evaluation with a restricted evaluator and updates JavaScript generation to provide the widget context required for scoped property resolution.

  • Supports primitive literals and current, parent, and named-object property references.
  • Passes _context and _this into generated eval helper calls.
  • Removes the previously reported debug logging and adds boolean and null literal handling.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
centrallix-os/sys/js/ht_render.js Adds the restricted cxjs_eval implementation and resolves the previously reported implicit-global, debug-log, and literal-handling issues.
centrallix/expression/exp_generator.c Supplies the established client expression context arguments when generating calls to the eval helper.

Reviews (4): Last reviewed commit: "Remove left-over debug log." | Re-trigger Greptile

Comment thread centrallix-os/sys/js/ht_render.js Outdated
Comment thread centrallix-os/sys/js/ht_render.js Outdated
Comment thread centrallix-os/sys/js/ht_render.js
@Lightning11wins

Copy link
Copy Markdown
Contributor Author

This PR is ready for human review.

@Lightning11wins
Lightning11wins requested review from gbeeley and nboard June 5, 2026 20:34

@gbeeley gbeeley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to address 3rd/4th param consistency with server per Greptile.

Comment thread centrallix-os/sys/js/ht_render.js Outdated
@Lightning11wins Lightning11wins changed the title Replace cxjs_eval() with a Safe Implementation. Replace cxjs_eval() with a Safe Implementation Jun 10, 2026
@Lightning11wins
Lightning11wins requested a review from gbeeley June 10, 2026 22:31

@gbeeley gbeeley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of changes needed - thanks!

Comment thread centrallix-os/sys/js/ht_render.js Outdated
const prop = rest.substring(1);
const par_node = (par_obj_name !== null && par_obj_name !== undefined)
? wgtrGetNode(_context, par_obj_name)
: wgtrGetParent(_context);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This defaults to the parent of the context, rather than the parent of the current object (_this).

In server contexts, the parent object has a context-dependent meaning but usually refers to the immediate parent object of the current object. The most common use is in a QueryTree object.

On the client, the most useful meaning here would be to reference the parent of _this rather than the parent of _context which likely steps out of the current scope entirely.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh, so like this?

const par_node = (par_obj_name !== null && par_obj_name !== undefined)
    ? wgtrGetNode(_context, par_obj_name)
    : wgtrGetParent(_this);

This issue likely arises from me only having a surface-level understanding of what eval(), _context, and _this should do.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that looks correct - please test out and verify. Thanks!

@Lightning11wins Lightning11wins Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to test this, although I only barely understand what this function is supposed to do in this case.

Comment thread centrallix-os/sys/js/ht_render.js Outdated
@Lightning11wins

Copy link
Copy Markdown
Contributor Author

@gbeeley That should resolve your requested changes.

@Lightning11wins
Lightning11wins requested review from gbeeley and removed request for nboard June 16, 2026 20:44

@gbeeley gbeeley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops - one of my last recommendations was partly wrong.

Comment thread centrallix-os/sys/js/ht_render.js Outdated
}
else if (_this !== null && _this !== undefined)
{
return wgtrGetProperty(_this, rest);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take that back. There are cases where _this is a plain object rather than a widget. So this code should check first whether it is a widget via wgtrIsNode() before calling wgtrGetProperty(), otherwise use the _this[prop] approach.

An example of this is parameters passed from an event (the event params) which can be referenced as the current object as in :property.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, I think I understand. Should be fixed now.

@Lightning11wins

Copy link
Copy Markdown
Contributor Author

@gbeeley I think I've fixed those issues.

@Lightning11wins
Lightning11wins requested a review from gbeeley June 16, 2026 21:46
@gbeeley

gbeeley commented Sep 3, 2026

Copy link
Copy Markdown
Member

@greptileai please recheck - thanks!

@gbeeley gbeeley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor fix needed - thanks

Comment thread centrallix-os/sys/js/ht_render.js Outdated

function cxjs_eval(_context, _this, expr, permflags, cur_obj_name, par_obj_name)
{
console.log(_context, _this, expr, permflags, cur_obj_name, par_obj_name);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per greptile, let's remove this debugging line before merge.

@Lightning11wins Lightning11wins Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woops! Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request AI review for PRs. size: trivial Easy to review, probably ~100 lines or fewer.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants