I want to know how to set the data setter/getter in Jint.

Asked 2 years ago, Updated 2 years ago, 66 views

C# is developing using Jint.

I was trying to do something else when the variables (data) in Jint's engine were rewritten during development, but I didn't know how to set Setter/Getter, so I inquired every time and looked at them with changes.

Include an example code.

 engine = new Engine();
engine.Execute("var hoge={x:1, fuga:function() {this.x++;}}";
var hoge=engine.GetValue("hoge");
var x = hoge.Get("x");
var fuga=hoge.Get("fuga");
fuga.Invoke(hoge, new JsValue[]{});
// Now I'm reacquiring whether hoge.x has changed or not.
var x2 = hoge.Get("x");
if(x!=x2){
    // x is changed
}

I don't know if there is a way to set up Setter/Getter in Jint, but if possible, I would appreciate it if you could tell me how to do it.

[Additional note (January 15, 2020)]
·The js side pointed out that it is okay to set getter/setter, so I will explain the details.
 ·Js entered by users are interpreted by Jint to create a program that works.
 ·There is a function in the Js, but in order to understand how the value has changed, we are currently using the method of obtaining the same value again after the function is executed and comparing it.It's inefficient.
 ·The format of Js input by the user has already been decided, so it is difficult to write the setter/getter on the Js side

c#

2022-09-30 21:47

1 Answers

Jint Downloaded and checked for details

Jint is a JavaScript interpreter that rewrites variable values

Jint.Engine Class
PutValue method.

As far as I've tried many things, it seems difficult to interrupt the setter process without affecting JavaScript processing.

Since the source is published, extend the Jint.Engine class to
putValue method How about remodeling it?

As a suggestion, attach the ValueBeforChangeEventHandler to the Engine and enter PutValue.
Call the event handler.

How about that?


2022-09-30 21:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.