mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 09:20:06 +02:00
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:
parent
55f55f5859
commit
a5279897a7
13 changed files with 170 additions and 28 deletions
|
@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue