well, I meant "running your program", not just script On 23 фев, 13:41, Степан Орлов <[email protected]> wrote: > Hi, I tried running your script on Windows - it produces no error, > even if script evaluation is repeated 100 times. I'm using some recent > version of V8 (checked out a couple of days ago) > > Regards, > Deadmorous > > 2010/2/23 Igor Sysoev <[email protected]>: > > > Hi, > > > could anyone tell why the program below is able to run the script only > > two times: > > ------ > > i: 0 > > result: 10 > > i: 1 > > result: 11 > > i: 2 > > Segmentation fault: 11 (core dumped) > > ------ > > > If I remove from JS script access to an external object and change it > > to something like "'Hello '+'World'", it runs without issues. > > I use revision r3690. > > > ------ > > #include <iostream> > > #include <v8.h> > > > using namespace std; > > using namespace v8; > > > Persistent<FunctionTemplate> ft; > > Persistent<Context> context; > > Persistent<Script> script; > > > typedef struct { > > int value; > > } v8_object_t; > > > v8_object_t obj; > > int i; > > > static Handle<Value> > > v8_get(Local<String> property, const AccessorInfo& info) > > { > > cout << "i: " << i << endl; > > return Integer::New(10 + i++); > > } > > > static void > > v8_set(Local<String> property, Local<Value> value, const AccessorInfo& > > info) > > { > > // void > > } > > > main() > > { > > HandleScope handle_scope; > > > Local<FunctionTemplate> lf = FunctionTemplate::New(); > > ft = Persistent<FunctionTemplate>::New(lf); > > Local<ObjectTemplate> ot = ft->InstanceTemplate(); > > ot->SetInternalFieldCount(1); > > ot->SetAccessor(String::New("value"), v8_get, v8_set); > > > context = Context::New(); > > Context::Scope context_scope(context); > > TryCatch try_catch; > > > Local<Function> f = ft->GetFunction(); > > Persistent<Object> o = Persistent<Object>::New(f->NewInstance()); > > o->SetInternalField(0, External::New(&obj)); > > context->Global()->Set(String::New("object"), o); > > > Local<Script> s = Script::New(String::New("object.value")); > > > if (s.IsEmpty()) { > > Local<Value> exception = try_catch.Exception(); > > String::Utf8Value text(exception); > > cout << "v8 compilation failed: " << *text << endl; > > exit(1); > > } > > > script = Persistent<Script>::New(s); > > > Local<Value> result = script->Run(); > > cout << "result: " << *String::Utf8Value(result) << endl; > > > result = script->Run(); > > cout << "result: " << *String::Utf8Value(result) << endl; > > > result = script->Run(); > > cout << "result: " << *String::Utf8Value(result) << endl; > > } > > > -- > > v8-users mailing list > > [email protected] > >http://groups.google.com/group/v8-users
-- v8-users mailing list [email protected] http://groups.google.com/group/v8-users
