JS -- Add listener for sandbox events only if there are some actions

* When no actions then set it to null instead of empty object
* Even if a field has no actions, it needs to listen to events from the sandbox in order to be updated if an action changes something in it.
This commit is contained in:
Calixte Denizet 2020-10-28 19:16:56 +01:00
parent 55f55f5859
commit a5279897a7
13 changed files with 170 additions and 28 deletions

View file

@ -73,12 +73,14 @@ class Field extends PDFObject {
// Private
this._actions = Object.create(null);
const doc = (this._document = data.doc);
for (const [eventType, actions] of Object.entries(data.actions)) {
// This code is running in a sandbox so it's safe to use Function
this._actions[eventType] = actions.map(action =>
// eslint-disable-next-line no-new-func
Function("event", `with (this) {${action}}`).bind(doc)
);
if (data.actions !== null) {
for (const [eventType, actions] of Object.entries(data.actions)) {
// This code is running in a sandbox so it's safe to use Function
this._actions[eventType] = actions.map(action =>
// eslint-disable-next-line no-new-func
Function("event", `with (this) {${action}}`).bind(doc)
);
}
}
}