DIRECT mode: obj.name returns the wrong value when name matches one of iEvaluate's local variables

Open
#628 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript
Domain
desktop, tooling

Research direction

Start by reading EWC/dWC.aplf around the proxy namespace setup, then trace iEvaluate in EWC/proxySpace/iEvaluate.dyalog and check iSyntax for the same name-hiding problem. Verify reads and assignments for affected names, including child objects, and add regression coverage; the issue asks for the full demo and Multi suites to pass.

Written by the indexing model from the issue text.

Description

[!NOTE]
Discovered during eNEW implementation

Summary

In DIRECT mode, a variable or child object inside an EWC object can't be reached through the object when its name matches one of iEvaluate's ~30 local names. F.a returns the string 'a', and F.e gives VALUE ERROR. Short names like these are common in GUI code (F.b, F.n, F.l), and some of them silently return wrong values rather than failing.

This affects every object created with eWC (and with eNEW).

Reproduce

'F1' eWC 'Form'
F1.(a e n r x)←1 2 3 4 5
F1.x      ⍝ 5      ✓
F1.a      ⍝ 'a'    ✗ should be 1
F1.n      ⍝ ' n '  ✗ should be 3
F1.e      ⍝ VALUE ERROR   ✗ should be 2
F1.r      ⍝ VALUE ERROR   ✗ should be 4

The same happens with a child object: a child named e, created with 'F.G.e' eWC 'Edit', can't be reached as F.G.e (VALUE ERROR in exec[0]).

Cause

In DIRECT mode (EWC.DIRECT=1, i.e. when 700⌶ is available), ∆WC copies proxySpace (iSyntax and iEvaluate) into every object namespace and enables 2(700⌶) on it (EWC/dWC.aplf, around fullname ⎕NS proxySpace / 2(700⌶)REF). From then on, every obj.name reference or assignment is routed through obj.iEvaluate, which evaluates the expression with ⍎ inside its own frame (exec, and r←o exec a, in EWC/proxySpace/iEvaluate.dyalog).

iEvaluate lives in the object namespace and has this header:

r←{l}iEvaluate args;z;m;v;a;i;n;o;this;exec;dot;d;e;f;caller;name;p;wgid;msg;conn;t;id;⎕TRAP;set;index;indexed;data;ixexpr;sub

Because of dynamic scoping, each of these localised names (plus r, l and args) hides the object's own variable or child object of the same name while the expression is evaluated. So F1.a evaluates iEvaluate's local a, which holds the text of the name being looked up.

Affected names (case-sensitive, so properties such as Data are not affected):

a d e f i l m n o p r t v z args caller conn data dot exec id index indexed ixexpr msg name set sub this wgid

Expected

obj.name should behave as on a plain namespace or a native GUI object: any variable or child name reads and assigns normally, whatever its name.

Suggested fix

Leave only a thin wrapper inside the object, with no common names, and move the logic into #.EWC, where its locals can't hide the object's names:

_EWC_r←{_EWC_l}iEvaluate _EWC_a
⍝ calls #.EWC.evaluateProxy with ⎕THIS, which evaluates with obj⍎expr

iSyntax (a dfn) should be checked too: it evaluates ⍎⍵ for ⎕ names, and its dfn locals (c, nc, n, x) could hide object names the same way.

To check while fixing

  • Whether assignment (F1.a←99) is also affected. F1.⎕NL 2 currently gives LENGTH ERROR through the proxy, so this couldn't be confirmed.
  • Every property read and write goes through iEvaluate, so run the full demo and Multi suites.
  • Add a regression test that reads and assigns a variable and a child object named after each former local.
Dominant language
JavaScript
Stars
2
Forks
6
Avg merge
3d 13h
Merged PRs (30d)
12

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Dyalog/ewc

All issues in Dyalog/ewc

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.