// Copyright 2017 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "src/objects/template-objects.h" #include "src/base/functional.h" #include "src/execution/isolate.h" #include "src/heap/factory.h" #include "src/objects/js-array.h" #include "src/objects/objects-inl.h" #include "src/objects/property-descriptor.h" #include "src/objects/template-objects-inl.h" namespace v8 { namespace internal { namespace { bool CachedTemplateMatches(Isolate* isolate, Tagged native_context, Tagged entry, int function_literal_id, int slot_id, DisallowGarbageCollection& no_gc) { if (native_context->is_js_array_template_literal_object_map( entry->map(isolate))) { Tagged template_object = TemplateLiteralObject::cast(entry); return template_object->function_literal_id() == function_literal_id && template_object->slot_id() == slot_id; } Handle entry_handle(entry, isolate); Tagged cached_function_literal_id = Smi::cast(*JSReceiver::GetDataProperty( isolate, entry_handle, isolate->factory()->template_literal_function_literal_id_symbol())); if (cached_function_literal_id.value() != function_literal_id) return false; Tagged cached_slot_id = Smi::cast(*JSReceiver::GetDataProperty( isolate, entry_handle, isolate->factory()->template_literal_slot_id_symbol())); if (cached_slot_id.value() != slot_id) return false; return true; } } // namespace // static Handle TemplateObjectDescription::GetTemplateObject( Isolate* isolate, Handle native_context, Handle description, Handle shared_info, int slot_id) { int function_literal_id = shared_info->function_literal_id(); // Check the template weakmap to see if the template object already exists. Handle