[runtime] Handle Exceptions from Indexed- and NamedInterceptor

LOG=N
BUG=v8:4026

Review URL: https://codereview.chromium.org/1416873008

Cr-Commit-Position: refs/heads/master@{#31580}
This commit is contained in:
cbruni 2015-10-26 10:24:17 -07:00 committed by Commit bot
parent fc3933ff3f
commit c05137e108
2 changed files with 92 additions and 0 deletions

View File

@ -7833,6 +7833,7 @@ MaybeHandle<FixedArray> JSReceiver::GetKeys(Handle<JSReceiver> object,
.ToHandle(&result)) {
accumulator.AddElementKeysFromInterceptor(result);
}
RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, FixedArray);
}
if (filter == SKIP_SYMBOLS) {
@ -7872,6 +7873,7 @@ MaybeHandle<FixedArray> JSReceiver::GetKeys(Handle<JSReceiver> object,
.ToHandle(&result)) {
accumulator.AddKeys(result);
}
RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, FixedArray);
}
}

View File

@ -2881,6 +2881,96 @@ THREADED_TEST(GetOwnPropertyNamesWithInterceptor) {
}
static void IndexedPropertyEnumeratorException(
const v8::PropertyCallbackInfo<v8::Array>& info) {
info.GetIsolate()->ThrowException(v8_num(42));
}
THREADED_TEST(GetOwnPropertyNamesWithIndexedInterceptorExceptions_regress4026) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handle_scope(isolate);
v8::Handle<v8::ObjectTemplate> obj_template =
v8::ObjectTemplate::New(isolate);
obj_template->Set(v8_str("7"), v8::Integer::New(CcTest::isolate(), 7));
obj_template->Set(v8_str("x"), v8::Integer::New(CcTest::isolate(), 42));
// First just try a failing indexed interceptor.
obj_template->SetHandler(v8::IndexedPropertyHandlerConfiguration(
NULL, NULL, NULL, NULL, IndexedPropertyEnumeratorException));
LocalContext context;
v8::Handle<v8::Object> global = context->Global();
global->Set(v8_str("object"), obj_template->NewInstance());
v8::Handle<v8::Value> result = CompileRun(
"var result = []; "
"try { "
" for (var k in object) result .push(k);"
"} catch (e) {"
" result = e"
"}"
"result ");
CHECK(!result->IsArray());
CHECK(v8_num(42)->Equals(result));
result = CompileRun(
"var result = [];"
"try { "
" result = Object.keys(object);"
"} catch (e) {"
" result = e;"
"}"
"result");
CHECK(!result->IsArray());
CHECK(v8_num(42)->Equals(result));
}
static void NamedPropertyEnumeratorException(
const v8::PropertyCallbackInfo<v8::Array>& info) {
info.GetIsolate()->ThrowException(v8_num(43));
}
THREADED_TEST(GetOwnPropertyNamesWithNamedInterceptorExceptions_regress4026) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handle_scope(isolate);
v8::Handle<v8::ObjectTemplate> obj_template =
v8::ObjectTemplate::New(isolate);
obj_template->Set(v8_str("7"), v8::Integer::New(CcTest::isolate(), 7));
obj_template->Set(v8_str("x"), v8::Integer::New(CcTest::isolate(), 42));
// First just try a failing indexed interceptor.
obj_template->SetHandler(v8::NamedPropertyHandlerConfiguration(
NULL, NULL, NULL, NULL, NamedPropertyEnumeratorException));
LocalContext context;
v8::Handle<v8::Object> global = context->Global();
global->Set(v8_str("object"), obj_template->NewInstance());
v8::Handle<v8::Value> result = CompileRun(
"var result = []; "
"try { "
" for (var k in object) result.push(k);"
"} catch (e) {"
" result = e"
"}"
"result");
CHECK(!result->IsArray());
CHECK(v8_num(43)->Equals(result));
result = CompileRun(
"var result = [];"
"try { "
" result = Object.keys(object);"
"} catch (e) {"
" result = e;"
"}"
"result");
CHECK(!result->IsArray());
CHECK(v8_num(43)->Equals(result));
}
namespace {
template <typename T>