custom snapshot

25 views
Skip to first unread message

mme

unread,
Jan 3, 2010, 3:41:38 PM1/3/10
to v8-users
I am trying to create a snapshot that contains a custom environment
and restore it in another program.
The following code will segfault when I create a new context in
readsnapshot.cpp.

What is the proper way to create a snapshot that contains a custom
predefined environment?

mksnapshot.cpp
------------------------
int main() {

v8::internal::Serializer::Enable();
v8::Persistent<v8::Context> env = v8::Context::New();
{
v8::HandleScope scope;
Context::Scope context_scope(env);
Handle<String> str = String::New("testvar=1;");
Handle<Script> script = Script::Compile(str);
Handle<Value> result = script->Run();
}
v8::internal::Snapshot::WriteToFile("test.snapshot");
env.Dispose();
return 0;
}


readsnapshot.cpp
-------------------------
int main() {
v8::internal::Snapshot::Initialize("test.snapshot");
HandleScope handle_scope;
Persistent<Context> context = v8::Context::New();
Handle<String> str = String::New("testvar;");
Handle<Script> script = Script::Compile(str);
Handle<Value> result = script->Run();
String::AsciiValue ascii(result);
printf("%s\n", *ascii);
return 0;
}

Reply all
Reply to author
Forward
0 new messages