Comments (3)
Serialization of code is not a part or purpose of this project. You can compile the code into plain JavaScript and use some other (maybe) existing library to do so.
from continuation.
It's more that the data representing the state of the continuation is serialized, rather than the code being serialized. Portability is a very useful property of continuations. For example, it could be used to break down the barrier between JavaScript running client side and server side.
from continuation.
@sanity I was looking at this too, but I'm pretty sure that's impossible in JavaScript, sadly. There's a few objects that I believe it's impossible to reliably serialize, and there's no serious reflection API for getting low-level info from a closure to help you out.
For example, to take some fairly common JS code:
function F() {
// [...some operation with side effects here, so you can't just rerun the constructor...]
var x = 1;
this.doSomething = function () {
this.myProperty = x;
}
}
var f = new F();
You can't reliably safely serialize and deserialize f
. You can get at the prototype and the properties from the object to do the basics, and you can get f.doSomething
, but even if you serialize that method's body, I don't think you can get a reliable mechanism to grab 'x' and recreate it in doSomething's closure during deserialization. Even knowing it exists requires you to turn doSomething
back into a string and reparse it yourself, and analyse the variables referenced within.
You can sort of get at it in this small example with some foolish hacks (parsing the whole constructor, comparing to the definition of doSomething, and going from there), but you can come up with more complex examples in the same vein where it's absolutely totally impossible (i.e. if x is outside both the constructor and the current scope). There's sadly no nice reflection APIs that let you get at the closure itself, so far as I can find, to reflect on what exactly it has references to, or to populate new closures when deserializing.
Without this you can easily pass function bodies and states around to share continuations, but not the variables on their stacks, which I think totally eliminates all the interesting uses of this (to my knowledge).
It might be possible to do something like this if you require any users to configure full serialization/deserialization methods for any very non-primitive objects that might be involved, but that's going to be hard work, and very unwieldy to use. I've seen a few mentions of improving the APIs around this in future as part of the ES7 spec, but I can't seem to find any concrete references to that, and it certainly isn't something that's widely available. Sorry!
from continuation.
Related Issues (20)
- continuous return value instead of continuous passsing style? HOT 3
- The compiler allow non-lvars as argument to cont() etc.
- Heuristics for exceptions don't work HOT 2
- Arguments scope bug HOT 2
- cont() and obtain() do not work when instantiating a class HOT 1
- using 'continue' in for (... in ...) HOT 2
- single file to use in browser or|and embed with rhino HOT 2
- Running compiler from the browser HOT 1
- Wrong binding of `this` inside `if`/`while/`for` HOT 1
- function declaration should goes to the top level HOT 3
- module searching terminates unexpectedly at certain directory HOT 1
- Wrong context when using `cont()` in switch..case HOT 1
- When using `cont()` in `if` block, the context in `if` is correct while the context after `if` is incorrect. HOT 1
- `this` get lost in try block
- new statement is mistakenly parsed in cont()'d block HOT 1
- ECMAScript 6 is not supported
- Incorrect textual representation of time
- Textual representation of time incorrect
- Want to meet
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from continuation.