Status: New
Owner: ----
New issue 1072 by [email protected]: TryCatch doesn't catch
exceptions thrown from an accessor.
http://code.google.com/p/v8/issues/detail?id=1072
v8::TryCatch object can't catch an exception that is thrown from an
accessor. Code below shows the issue:
static v8::Handle<v8::Value> ThrowFromAccessorGetter(v8::Local<v8::String>
property,
const v8::AccessorInfo&
info)
{
return
v8::ThrowException(v8::Exception::Error(v8::String::New("Test")));
}
TEST(ThrowFromAccessor) {
v8::HandleScope scope;
LocalContext context;
// Create an object with one property from function template
v8::Handle<v8::String> name = v8::String::New("propertyName");
v8::Handle<v8::FunctionTemplate> funcTempl = v8::FunctionTemplate::New();
v8::Handle<v8::ObjectTemplate> instTempl = funcTempl->InstanceTemplate();
instTempl->SetAccessor(name, ThrowFromAccessorGetter);
v8::Handle<v8::Object> object = instTempl->NewInstance();
// Check if an exception is thrown from JS env.
context->Global()->Set(v8::String::New("obj"), object);
ExpectTrue(
"result = false; "
"try {"
"obj.propertyName;"
"} catch (e) {"
"if (e.toString() == 'Error: Test')"
"result = true;"
"}"
"result");
// Do similar exercise but from C++ api
v8::TryCatch exception;
v8::Handle<v8::Value> property = object->Get(name);
CHECK(property.IsEmpty());
CHECK(exception.HasCaught()); // <====== that line will fail =======>
CHECK(!exception.Exception().IsEmpty());
}
I would suppose that if 'property' is empty then exception.HasCaught would
return true.
------------------------------
System: Debian testing 32
Revision: Trunk
Problem was reproduced with Isolate branch too.
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev