MT#63980 fix Javascript prov templates raising errors

The JE module will populate $@, hence an enclosing eval{} wipes
the error string unintentionally.

in addition the "die" method is now exposed in Javascript
templates, to use it to bail out, ie. to propagate a msg
from an input validation to the UI.

Change-Id: Id3fcf8a7820ee3df51e0cc6323350f5f5908fcf4
(cherry picked from commit 5fb5a860c3)
mr13.0
Rene Krenn 2 months ago
parent cca1477f9a
commit 2dcbbd5885

@ -465,6 +465,14 @@ sub provision_begin {
_unbox_je_value($_);
} @_);
};
$subs{'trim'} = sub {
my $string = _unbox_je_value(shift @_);
$string =~ s/^\s+|\s+$//g;
return $string;
};
$subs{'die'} = sub {
return die(( map { _unbox_je_value($_); } @_));
};
while (each %subs) {
$context->{_je}->new_function($_ => $subs{$_});
}
@ -1433,11 +1441,13 @@ sub _calculate {
";\n_func = $c;");
die("$f: " . $@) if $@;
my $v;
my $err;
eval {
$v = _unbox_je_value($context->{_je}->eval('_func();'));
$err = $@;
};
if ($@) {
die("$f: " . $@);
if ($err or ($err = $@)) {
die("$f: " . $err);
}
return ($1 => $v);

Loading…
Cancel
Save