v8 Race Bug?

18 views
Skip to first unread message

John Crom

unread,
Mar 29, 2014, 6:01:50 PM3/29/14
to v8-u...@googlegroups.com
Writing a very basic REPL.

Here's the code:

std::cout << "> ";
while (std::getline(std::cin, input)) {
    const char *eval_code = ("'typeof:' + typeof []").c_str();
    v8::Handle<v8::String> eval_source = v8::String::NewFromUtf8(isolate, eval_code);
    v8::Handle<v8::Script> eval_script = v8::Script::Compile(eval_source);
    v8::Handle<v8::Value> eval_result = eval_script->Run();
    if (!eval_result.IsEmpty()) {
        v8::String::Utf8Value eval_utf8(eval_result);
        std::cout << *eval_utf8 << std::endl;
    }
   
    std::cout << "> ";
}

Works only SOME of the time. Sometimes, the result for *eval_utf8 is "typeof:object" as expected. Sometimes, all I get is "undefined" (no "typeof:" string prefix so I know the code never really ran. Otherwise, I would expect at least "typeof:undefined")

Is this a bug with v8 or is this a bug with my code?

Thanks.

Ben Noordhuis

unread,
Mar 29, 2014, 7:09:17 PM3/29/14
to v8-u...@googlegroups.com
I'd say it's a bug in your code. The return value from
std::string::c_str() is used after the temporary is destroyed.

I'm kind of surprised that the snippet above compiles; I wouldn't
expect a compiler to perform an implicit conversion from a string
literal to a std::string. Is that with MSVC?
Reply all
Reply to author
Forward
0 new messages