How to save JavaScript close state?

I am working on a migration platform for transferring web applications from device to another. I am expanding it to add support for maintaining state of JavaScript. My main task is to create a file representing the current state of the executable application, transfer it to another device and reboot the state of the target device.

The main decision I made was to move the window object and save all its descendant properties using JSON as the base format for exporting and expanding it to implement some functions:

  • saving the reference to the object, even if it is circular (dojox.json.ref library)
  • timer support
  • the date
  • non-numeric array properties
  • reference to DOM elements

The most important task that I now need to solve is the export of closures. At this moment, I did not know how to implement this function. I read about the EcmaScript internal property [[scope]], which contains a whole chain of functions, a list-like object consisting of the entire nested function activation context. Sorry, JavaScript is not available. Does anyone know if there is a way to directly access a property [[scope]]? Or another way to keep the closing state?

+5
source share
2 answers

This sounds like an impossible feat, since you need access to the links stored in each variable.

, , - JSON.stringify/parse /.

,

var myFuncWithScope = (function() {
    var variable = 0;
    return function() {
        return variable++;
    }
})(); 

var serializedState = .... // no can do

var state = {
    myScope = {
        variable: 0
    }
};

var myFuncWithoutScope = function(){
    return state.myScope.variable++;
}

var serializedState = JSON.stringify(state);
+2

? -, , . script - .

[[Scope]] - ECMAScript, , ; [[...]] . , , , , , , , (, DOM)... .

-, , JS.

+2

All Articles