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

Can't reference fields from PROTO javascript functions if not referenced directly #6566

Closed
brettle opened this issue Jun 28, 2024 · 0 comments · Fixed by #6614
Closed

Can't reference fields from PROTO javascript functions if not referenced directly #6566

brettle opened this issue Jun 28, 2024 · 0 comments · Fixed by #6614

Comments

@brettle
Copy link
Contributor

brettle commented Jun 28, 2024

As a test case, consider:

#VRML_SIM R2023b utf8
# template language: javascript

PROTO ExampleProto [
    field SFFloat field1 1
    field SFFloat field2 5
]
{
  Solid {
%<
function sum(fieldsObj) {
  return fieldsObj.field1.value + fieldsObj.field2.value;
}
>%
       radarCrossSection %<= sum(fields) >%
  }
}

When I insert that proto, I get:

ERROR: '.../ExampleProto.proto': error: Template engine error: failed to execute JavaScript template: Cannot read property 'value' of undefined.

I suspect I'm running up against this:

foreach (WbFieldModel *model, mFieldModels) {
// regex test cases:
// "You know nothing, John Snow." => false
// "%{=fields.model->name()}%" => false
// "%{= fields.model->name().value.x }% %{= fields.model->name().value.y }%" => true
// "abc %{= fields.model->name().value.y }% def" => true
// "%{= 17 % fields.model->name().value.y * 88 }%" => true
// "fields.model->name().value.y" => false
// "%{}% fields.model->name().value.y %{}%" => false
// "%{ a = \"fields.model->name().value.y\" }%" => false
// "%{= \"fields.model->name().value.y\" }%" => false
// "%{= fields.model->name().value.y }%" => true
if (token->word().contains(QRegularExpression(QString("%1(?:(?!%2|\").)*fields\\.%3(?:(?!%4|\").)*%5")
.arg(open)
.arg(close)
.arg(QRegularExpression::escape(model->name()))
.arg(close)
.arg(close))))
model->setTemplateRegenerator(true);

@brettle brettle mentioned this issue Aug 2, 2024
48 tasks
@CoolSpy3 CoolSpy3 linked a pull request Aug 4, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant