Well, ToString() does not seem to throw an exception when I'm trying
to convert my result to a string.

I just tried to make everything in the main, context creation, handle
scope, etc.

The code is very much like the hello world example from the wiki :

    // Create a stack-allocated handle scope.
    HandleScope handle_scope;

    // Create a new context.
    Persistent<Context> context = Context::New();

    // Enter the created context for compiling and
    // running the hello world script.
    Context::Scope context_scope(context);

    // Create a string containing the JavaScript source code.
    Handle<String> source = String::New("42;");

    // Compile the source code.
    Handle<Script> script = Script::Compile(source);

    // Run the script to get the result.
    Handle<Value> result = script->Run();

    // Convert the result to an ASCII string and print it.
    String::AsciiValue ascii(result);
    printf("%s\n", *ascii);

    // Dispose the persistent context.
    context.Dispose();

And here it works as expected and outputs "42". I am just guessing but
couldn't it be a problem of handle destruction? However, even with
"handleScope.Close", it still crashes.

Remi Gillig.

On Jan 17, 5:03 am, Abdulla Kamar <[email protected]> wrote:
> You should be checking whether *str* is actually a string with *
> str->IsString()*. Or you could try using *str->ToString()*, but I'm not sure
> if that performs the type conversion for you (try checking the docs and/or
> the source code).
>
>
>
> On Sun, Jan 17, 2010 at 8:59 AM, Remi Gillig <[email protected]> wrote:
> > Hello,
>
> > I have a little problem with this code :
>
> > #include <exception>
> > #include <string>
> > #include <v8/v8.h>
>
> > using namespace v8;
>
> > class Engine
> > {
> > private:
> >    Persistent<Context> context;
> > public:
> >    Engine()
> >    {
> >        context = Context::New();
> >    }
>
> >    Handle<Value> Run(const std::string& scriptContent)
> >    {
> >        Context::Scope contextScope(context);
>
> >        HandleScope handleScope;
>
> >        Handle<String> source = String::New(scriptContent.c_str());
>
> >        Handle<Script> script = Script::Compile(source);
>
> >        TryCatch trycatch;
>
> >        Handle<Value> result = script->Run();
>
> >        if (result.IsEmpty())
> >        {
> >            Handle<Value> exception = trycatch.Exception();
> >            String::AsciiValue exceptionString(exception);
> >            throw std::exception(*exceptionString);
> >        }
>
> >        return handleScope.Close(result);
> >    }
>
> >    ~Engine()
> >    {
> >        context.Dispose();
> >    }
> > };
>
> > int main(int argc, char* argv[])
> > {
> >    Engine engine;
>
> >    HandleScope handleScope;
> >    Handle<Value> str = engine.Run("42;");
>
> >    String::AsciiValue ascii(str);
> >    printf("%s", *ascii);
>
> >    return 0;
> > }
>
> > I am using Visual Studio 2008 and this code crashes at the conversion
> > to AsciiValue and the debugger breaks at line 38 in contexts.cc inside
> > Context::builtins() : GlobalObject* object = global();
>
> > What I would like to create is a little class which would load
> > configuration scripts and keep the context so that I can retrieve the
> > config data for my application.
>
> > Thanks for any help!
>
> > Remi Gillig.
>
> > --
> > v8-users mailing list
> > [email protected]
> >http://groups.google.com/group/v8-users
>
> --
> Thank you
> Abdulla
-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to