Status: New
Owner: ----
New issue 3224 by albzey: Exceptions via ToString() to Utf8Value fails in
some cases
http://code.google.com/p/v8/issues/detail?id=3224
It's best demonstrated via some code:
#include <v8.h>
#include <list>
#include <iostream>
#include <string>
#include <assert.h>
using namespace std;
using namespace v8;
static std::string jsToStr(Local<Value> v, const std::string& fallback
= "<toStr failed>") {
if(v.IsEmpty()) return fallback;
auto obj = v->ToString();
String::Utf8Value utf8(obj);
if(*utf8) return *utf8;
return fallback;
}
static Local<Value> execJsScript(const std::string& jsCode) {
Local<String> source = String::NewFromUtf8(Isolate::GetCurrent(),
jsCode.c_str());
Local<v8::Script> script = Script::Compile(source);
assert(!script.IsEmpty());
return script->Run();
}
void test_js_ExcRethrow() {
auto isolate = Isolate::New();
Isolate::Scope isolateScope(isolate);
HandleScope handleScope(isolate);
Handle<Context> context = Context::New(isolate);
Context::Scope contextScope(context);
auto globalObj = context->Global();
{
TryCatch try_catch;
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "foo")));
assert(try_catch.HasCaught());
cout << jsToStr(try_catch.Exception()) << endl;
}
{
TryCatch try_catch;
{
TryCatch try_catch;
execJsScript("throw new Error('hi');");
assert(try_catch.HasCaught());
cout << jsToStr(try_catch.Exception()) << endl;
try_catch.ReThrow();
}
assert(try_catch.HasCaught());
cout << jsToStr(try_catch.Exception()) << endl;
}
}
This prints:
<toStr failed>
Error: hi
<toStr failed>
But I would have expected:
Error: foo
Error: hi
Error: hi
Am I doing something wrong?
This is with V8 3.25.8 and 3.25.14.
(I also asked in the mailing-list
[here](https://groups.google.com/forum/#!topic/v8-users/b7KOKAKYKlU).)
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.