From 637f96b8d39570947a97f6f11ae8843f0ce8b845 Mon Sep 17 00:00:00 2001 From: dcarney Date: Wed, 25 Mar 2015 05:34:01 -0700 Subject: [PATCH] fix nonmasking interceptor ic with interceptor on receiver TBR=verwaest@chromium.org BUG= Review URL: https://codereview.chromium.org/1036843002 Cr-Commit-Position: refs/heads/master@{#27436} --- src/ic/handler-compiler.cc | 10 +++-- test/cctest/test-api-interceptors.cc | 63 ++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/src/ic/handler-compiler.cc b/src/ic/handler-compiler.cc index 9c25f0a15..f103f8daf 100644 --- a/src/ic/handler-compiler.cc +++ b/src/ic/handler-compiler.cc @@ -332,9 +332,13 @@ Handle NamedLoadHandlerCompiler::CompileLoadInterceptor( // Reset the holder so further calculations are correct. set_holder(holder_orig); if (lost_holder_register) { - // Reload lost holder register. - auto cell = isolate()->factory()->NewWeakCell(holder()); - __ LoadWeakValue(reg, cell, &miss); + if (*it->GetReceiver() == *holder()) { + reg = receiver(); + } else { + // Reload lost holder register. + auto cell = isolate()->factory()->NewWeakCell(holder()); + __ LoadWeakValue(reg, cell, &miss); + } } FrontendFooter(it->name(), &miss); InterceptorVectorSlotPop(reg); diff --git a/test/cctest/test-api-interceptors.cc b/test/cctest/test-api-interceptors.cc index 0b060d1e6..8c2b222bb 100644 --- a/test/cctest/test-api-interceptors.cc +++ b/test/cctest/test-api-interceptors.cc @@ -3247,3 +3247,66 @@ THREADED_TEST(NonMaskingInterceptorPrototypePropertyIC) { ExpectInt32("f(obj)", 239); ExpectInt32("f(outer)", 4); } + + +namespace { + +void DatabaseGetter(Local name, + const v8::PropertyCallbackInfo& info) { + ApiTestFuzzer::Fuzz(); + auto context = info.GetIsolate()->GetCurrentContext(); + Local db = info.Holder() + ->GetRealNamedProperty(context, v8_str("db")) + .ToLocalChecked() + .As(); + if (!db->Has(context, name).FromJust()) return; + info.GetReturnValue().Set(db->Get(context, name).ToLocalChecked()); +} + + +void DatabaseSetter(Local name, Local value, + const v8::PropertyCallbackInfo& info) { + ApiTestFuzzer::Fuzz(); + auto context = info.GetIsolate()->GetCurrentContext(); + if (name->Equals(v8_str("db"))) return; + Local db = info.Holder() + ->GetRealNamedProperty(context, v8_str("db")) + .ToLocalChecked() + .As(); + db->Set(context, name, value).FromJust(); + info.GetReturnValue().Set(value); +} +} + + +THREADED_TEST(NonMaskingInterceptorGlobalEvalRegression) { + auto isolate = CcTest::isolate(); + v8::HandleScope handle_scope(isolate); + LocalContext context; + + auto interceptor_templ = v8::ObjectTemplate::New(isolate); + v8::NamedPropertyHandlerConfiguration conf(DatabaseGetter, DatabaseSetter); + conf.flags = v8::PropertyHandlerFlags::kNonMasking; + interceptor_templ->SetHandler(conf); + + context->Global()->Set(v8_str("intercepted_1"), + interceptor_templ->NewInstance()); + context->Global()->Set(v8_str("intercepted_2"), + interceptor_templ->NewInstance()); + + // Init dbs. + CompileRun( + "intercepted_1.db = {};" + "intercepted_2.db = {};"); + + ExpectInt32( + "var obj = intercepted_1;" + "obj.x = 4;" + "eval('obj.x');" + "eval('obj.x');" + "eval('obj.x');" + "obj = intercepted_2;" + "obj.x = 9;" + "eval('obj.x');", + 9); +} -- 2.34.1