Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I execute Dynamically (like Eval) in Dart? #36989

Closed
smile2014 opened this issue May 17, 2019 · 3 comments
Closed

How do I execute Dynamically (like Eval) in Dart? #36989

smile2014 opened this issue May 17, 2019 · 3 comments
Labels
closed-not-planned Closed as we don't intend to take action on the reported issue type-question A question about expected behavior or functionality

Comments

@smile2014
Copy link

var doAdd = new Function("iNum", "alert(iNum + 10)");
doAdd(10);----> 20

@lrhn
Copy link
Member

lrhn commented May 17, 2019

Dart does not allow you to create code at run-time.

What problem are you trying to solve?

There are workarounds when you are running on the VM and has access to isolates. You can create a new library with a main function, encode the source code as a data: URI and spawn it as a new isolate, but that will not allow you to create a new functions in the current isolate. You'll have to communicate with the new code using isolate port communication.

In general, I'd recommend trying something else. It is often possible to get the effect of generating code by just combining first-class function values, but that obviously depends on the problem at hand.

@lrhn lrhn added the type-question A question about expected behavior or functionality label May 17, 2019
@smile2014
Copy link
Author

I dynamically render the form through the json data given by the backend. The disabled corresponds to a piece of javascript, similar to angular ngx-formly expression

@a-siva a-siva added the closed-not-planned Closed as we don't intend to take action on the reported issue label May 28, 2019
@a-siva a-siva closed this as completed May 28, 2019
@Sunbreak
Copy link

Sunbreak commented Feb 23, 2022

Though not planned, but it is possible actually.

Dart could take advantage of JavaScript prototype chain as Kotlin/JS in https://rosettacode.org/wiki/Reflection/Get_source#Kotlin

It is possible even in Dart/VM in JIT mode: https://iiro.dev/how-to-eval-in-dart/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-not-planned Closed as we don't intend to take action on the reported issue type-question A question about expected behavior or functionality
Projects
None yet
Development

No branches or pull requests

4 participants