[quickjs-devel] ExoticSet / JS_SetProperty question

  • From: Guido Grassel <guido.grassel@xxxxxxxxxx>
  • To: "quickjs-devel@xxxxxxxxxxxxx" <quickjs-devel@xxxxxxxxxxxxx>
  • Date: Mon, 2 Nov 2020 17:27:24 +0000


Hi!

I would appreciate advise on how to use ExoticSet 'magic' function and 
JS_SetProperty/String/Internal in the following scenario:

I have created by own C++ class, wrapped this with a JS object, and exposed a 
few static C++ functions to JS.
I need to intercept  property write operations on this JS object. Therefore, I 
have also registered a function as 'magic' exoticSet function.

This all works well, the exoticSet static C++ function gets called all fine 
whenever creating a new property or setting an existing property on the 
wrapping JS object from JS code.

I understand the exoticSet function is responsible to set the JSValue to the 
new value. How to set the property value from the exoticSet static C++ function 
without causing an infinite loop (using JS_SetProperty -> ExoticSet -> 
JS_SetPropertyValue will cause such loop)?   How to just set the JSValue 
without calling any 'magic' functions?

Note: I want to suffice with just one JS object wrapping the C++ object.  In 
many other cases I created a separate JS proxy to proxy for the JS object 
holding the properties. But in this scenario I do not want to do this.

Thank you!

Best regards
  Guido

Other related posts:

  • » [quickjs-devel] ExoticSet / JS_SetProperty question - Guido Grassel