Skip to content
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

Fix for UDFs receiving JSON arguments as empty objects #3451

Merged
merged 10 commits into from
Jul 4, 2022

Conversation

dark-ether
Copy link
Contributor

@dark-ether dark-ether commented Jun 30, 2022

Identify the Bug or Feature request

resolves #3231

Description of the Change

the discussion of the issue gave me enough context to solve this issue, i searched for where code calls javascript evaluation and added conversions, to ensure that the objects behave exactly as their javascript counterpart new classes that implement the proxy interfaces were added as conversion targets.

Possible Drawbacks

whenever new forms of evaluating javascript are added it will be necessary to add code to convert the types.

I am converting the arguments for MTScript.getMTScriptCallingArgs before inserting in the stack, which shouldn't be a problem as long as we don't need them as their json counterparts before reconverting them back to MTscript types.

Besides that when receiving JSON objects and arrays not modified by javascript we get a JSArray or JSObject type which calls the HostObjectToMTscriptType method instead of the expected ValueToMTScriptType but this currently isn't a problem as the 2 classes are instances of list and AbstractMap respectively so they are converted correctly to MTScript values however if we were to change that part it could potentially be a problem.

when testing i found that BigDecimal can't be read by javascript and there isn't any way to add the number behaviour, so i am using double, if it is decided that precision is critical and double isn't enough it should be considered to export big decimal to the javascript context

Documentation Notes

i've attached a zip containing a test campaign showing that it is working now
testeJsUdf.zip

Release Notes

  • Fixed issue where JSON arrays and objects were received as a empty object to javascript code

This change is Reviewable

@Phergus Phergus requested a review from cwisniew June 30, 2022 15:38
Copy link
Collaborator

@thelsing thelsing left a comment

Choose a reason for hiding this comment

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

I didn't actual test the changes but the changes look good to me. I only added minor comments.

@Phergus
Copy link
Contributor

Phergus commented Jul 2, 2022

src/main/java/net/rptools/maptool/client/script/javascript/JSArray.java line 82 at r1 (raw file):

Previously, thelsing wrote…

typo

Still a typo: "deosn't"

@Phergus Phergus changed the title Issue#3231 Fix for UDFs receiving JSON arguments as empty objects Jul 2, 2022
Copy link
Contributor

@Phergus Phergus left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 2 of 4 files at r1, 1 of 1 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @thelsing)

@Phergus
Copy link
Contributor

Phergus commented Jul 3, 2022

@cwisniew need you to approve the change you requested.

Copy link
Contributor

@Phergus Phergus left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @thelsing)

Copy link
Contributor

@Phergus Phergus left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @thelsing)

@Phergus
Copy link
Contributor

Phergus commented Jul 4, 2022

@thelsing you haven't resolved the changes you requested.

Copy link
Collaborator

@thelsing thelsing left a comment

Choose a reason for hiding this comment

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

Reviewed all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @dark-ether)

@Phergus Phergus merged commit c2b9e07 into RPTools:develop Jul 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] javascript UDFs receive json arguments as empty objects
4 participants