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;
}

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to