How to get the memory address of a JavaScript variable?

Is it possible to find the memory address of a JavaScript variable? JavaScript code is part (embedded) in a regular application where JavaScript is used as a C ++ interface and does not run in a browser. The JavaScript implementation used is SpiderMonkey.

+42
javascript spidermonkey memory-address
Mar 12 '09 at 16:53
source share
2 answers

If it were possible at all, it would be very dependent on the javascript engine. The more modern javascript engine will compile its code using the compiler only in time and tinker with its internal variables, either it will be bad for performance or bad for stability.

If the engine allows this, why not make the function call interface some kind of native code for exchanging variable values?

+14
Mar 12 '09 at 16:59
source share
— -

It is more or less impossible. The Javascript evaluation strategy should always use a call by value, but in the case of objects (including arrays), the passed value is a reference to an object that is not copied or cloned. If you reassign the object itself to a function, the original will not be changed, but if you reassign one of the properties of the object, it will affect the original object.

So what are you trying to achieve? If it just passes complex data between C ++ and Javascript, you can use the JSON library to communicate. Send the JSON object to C ++ for processing and get a JSON object to replace the old one.

+8
Apr 23 '13 at 15:34
source share



All Articles