JavaScript proxy in additional context
See original GitHub issueIs it possible for additionalJsContext to capture a generic getter or setter from a proxy?
I’m providing:
const additionalJsContext = new Proxy({}, {
set(obj, prop, value) {
debug('set', {prop, value})
obj[prop] = value
return true
},
get(obj, prop) {
const value = obj[prop]
debug('get', {prop, value})
return value === undefined ? null : value
}
})
Then merge is used in this example [ref]:
const sandbox: { [ind: string]: any } = merge(
ctx.jsSandbox || {},
{
__code__: code,
__result__: undefined,
},
data,
ctx.options.additionalJsContext
);
The generic “get” and “set” are not being merged into the sandbox object. If I put static properties in the 1st argument to Proxy it works or if I test my proxy alone additionalJsContext.anyprop === null
it works. I’m not concerned about Proxy immutability, I can handle that with the set
.
I’m have asked on the timm project too: https://github.com/guigrpa/timm/issues/52
This may be better handled here. Looks like using data
instead will not help either. I’m also after the async support in additionalJsContext. Also, if you have a suggestion I don’t mind forking making changes and testing. I anticipate that I’m going to need to do this anyways.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
Just looked at the timm code and a work around should be:
Where the key is not present in data. (and is not code nor result)
[edit] Sorry I just got what you want…
I tested
v.__isProxy !== undefined
ref and it works when I replace the twov instanceof Proxy
checks . It errorserr: Error: TypeError: eval is not a function
. Probably this line: https://github.com/guigrpa/docx-templates/blob/28496607960efab8619ca006256d1d50fe5c0c7e/src/jsSandbox.ts#L49