diff --git a/src/code-stubs-hydrogen.cc b/src/code-stubs-hydrogen.cc index c679d4c3f5..826c1dd730 100644 --- a/src/code-stubs-hydrogen.cc +++ b/src/code-stubs-hydrogen.cc @@ -1313,16 +1313,25 @@ HValue* CodeStubGraphBuilder::BuildCodeInitializedStub() { Handle placeholer_value(Smi::FromInt(0), isolate()); Handle placeholder_cell = isolate()->factory()->NewPropertyCell(placeholer_value); - HParameter* value = GetParameter(StoreDescriptor::kValueIndex); - if (stub->check_global()) { // Check that the map of the global has not changed: use a placeholder map // that will be replaced later with the global object's map. + HParameter* proxy = GetParameter(StoreDescriptor::kReceiverIndex); + HValue* proxy_map = + Add(proxy, nullptr, HObjectAccess::ForMap()); + HValue* global = + Add(proxy_map, nullptr, HObjectAccess::ForPrototype()); Handle placeholder_map = isolate()->factory()->meta_map(); - HValue* global = Add( - StoreGlobalStub::global_placeholder(isolate())); - Add(global, placeholder_map); + HValue* cell = Add(Map::WeakCellForMap(placeholder_map)); + HValue* expected_map = + Add(cell, nullptr, HObjectAccess::ForWeakCellValue()); + HValue* map = + Add(global, nullptr, HObjectAccess::ForMap()); + IfBuilder map_check(this); + map_check.IfNot(expected_map, map); + map_check.ThenDeopt("Unknown map"); + map_check.End(); } HValue* cell = Add(placeholder_cell); diff --git a/src/code-stubs.h b/src/code-stubs.h index a0ffd129c3..f8009a2697 100644 --- a/src/code-stubs.h +++ b/src/code-stubs.h @@ -1092,8 +1092,8 @@ class StoreGlobalStub : public HandlerStub { Handle cell) { if (check_global()) { Code::FindAndReplacePattern pattern; - pattern.Add(Handle(global_placeholder(isolate())->map()), global); - pattern.Add(isolate()->factory()->meta_map(), Handle(global->map())); + pattern.Add(isolate()->factory()->meta_map(), + Map::WeakCellForMap(Handle(global->map()))); pattern.Add(isolate()->factory()->global_property_cell_map(), cell); return CodeStub::GetCodeCopy(pattern); } else { diff --git a/src/ic/ic.cc b/src/ic/ic.cc index 17d4ee211e..68c11596eb 100644 --- a/src/ic/ic.cc +++ b/src/ic/ic.cc @@ -1747,6 +1747,8 @@ Handle StoreIC::CompileHandler(LookupIterator* lookup, if (holder->IsGlobalObject()) { Handle cell = lookup->GetPropertyCell(); Handle union_type = PropertyCell::UpdatedType(cell, value); + DCHECK(holder.is_identical_to(receiver) || + receiver->map()->prototype() == *holder); StoreGlobalStub stub(isolate(), union_type->IsConstant(), receiver->IsJSGlobalProxy()); Handle code = stub.GetCodeCopyFromTemplate(