# Cannot create a JavaScript "Function" object

**URL:** <https://forums.creativeclouddeveloper.com/t/cannot-create-a-javascript-function-object/676>\
**Category:** UXP Plugin API\
**Tags:** feature-request, javascript\
**Created:** [February 28, 2019, 4:44pm UTC](https://forums.creativeclouddeveloper.com/t/cannot-create-a-javascript-function-object/676 "2019-02-28T16:44:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![koppasoft](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/koppasoft/32/293_2.png) [@koppasoft](https://forums.creativeclouddeveloper.com/u/koppasoft)\
**Post date:** [February 28, 2019, 4:44pm UTC](https://forums.creativeclouddeveloper.com/t/cannot-create-a-javascript-function-object/676/1 "2019-02-28T16:44:28Z")

</div>

When attempting to create a JavaScript “Function” object, the Adobe XD runtime issues an error stating “Code generation from strings disallowed for this context”.

We understand that Adobe prevents from this in order to make the plugin as save as possible, but in our case, we really need to run a small JavaScript code coming from an external JavaScript file, which is unknown at the time of the plugin publication.

How could we work this around, please?

---

<div class="post-metadata">

**Author:** ![pklaschka](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/pklaschka/32/3162_2.png) [@pklaschka](https://forums.creativeclouddeveloper.com/u/pklaschka)\
**Post date:** [February 28, 2019, 10:48pm UTC](https://forums.creativeclouddeveloper.com/t/cannot-create-a-javascript-function-object/676/2 "2019-02-28T22:48:11Z")

</div>

You could use a JS interpreter. Take a look at @kerrishotts comment in [Can I use `eval` or similar functions?](http://forums.creativeclouddeveloper.com/t/can-i-use-eval-or-similar-functions/40) for some options. May I ask what you’ll use that for? As you’ve said, the prevention of something like this is there for a reason (and one should therefore not just work around that without being extremely careful)…

---

<div class="post-metadata">

**Author:** ![koppasoft](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/koppasoft/32/293_2.png) [@koppasoft](https://forums.creativeclouddeveloper.com/u/koppasoft)\
**Post date:** [March 1, 2019, 8:11am UTC](https://forums.creativeclouddeveloper.com/t/cannot-create-a-javascript-function-object/676/3 "2019-03-01T08:11:46Z")

</div>

Thank you for your very responsive answer, we are going to explore the JS interpreter option.

---

<div class="post-metadata">

**Author:** ![kerrishotts](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/kerrishotts/32/8_2.png) [@kerrishotts](https://forums.creativeclouddeveloper.com/u/kerrishotts)\
**Post date:** [March 1, 2019, 8:37am UTC](https://forums.creativeclouddeveloper.com/t/cannot-create-a-javascript-function-object/676/4 "2019-03-01T08:37:34Z")

</div>

There are several options available; I’ve been able to use `sval` to good effect. Some interpreters only go up to ES5, although supposedly there are some out there that will also let you use modern JavaScript (haven’t tried yet).

What’s cool about `sval` is you can set it up to use the current context, so you can expose XD’s APIs to it with a single line of code. Super handy 🙂

---

<div class="post-metadata">

**Author:** ![cpryland](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/cpryland/32/1172_2.png) [@cpryland](https://forums.creativeclouddeveloper.com/u/cpryland)\
**Post date:** [March 5, 2019, 10:37pm UTC](https://forums.creativeclouddeveloper.com/t/cannot-create-a-javascript-function-object/676/5 "2019-03-05T22:37:11Z")

</div>

Nifty! Can you share that line of code? 😉
