• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "src/objects/literal-objects.h"
6 
7 #include "src/factory.h"
8 #include "src/isolate.h"
9 #include "src/objects-inl.h"
10 
11 namespace v8 {
12 namespace internal {
13 
name(int index) const14 Object* BoilerplateDescription::name(int index) const {
15   // get() already checks for out of bounds access, but we do not want to allow
16   // access to the last element, if it is the number of properties.
17   DCHECK_NE(size(), index);
18   return get(2 * index);
19 }
20 
value(int index) const21 Object* BoilerplateDescription::value(int index) const {
22   return get(2 * index + 1);
23 }
24 
size() const25 int BoilerplateDescription::size() const {
26   DCHECK_EQ(0, (length() - (this->has_number_of_properties() ? 1 : 0)) % 2);
27   // Rounding is intended.
28   return length() / 2;
29 }
30 
backing_store_size() const31 int BoilerplateDescription::backing_store_size() const {
32   if (has_number_of_properties()) {
33     // If present, the last entry contains the number of properties.
34     return Smi::cast(this->get(length() - 1))->value();
35   }
36   // If the number is not given explicitly, we assume there are no
37   // properties with computed names.
38   return size();
39 }
40 
set_backing_store_size(Isolate * isolate,int backing_store_size)41 void BoilerplateDescription::set_backing_store_size(Isolate* isolate,
42                                                     int backing_store_size) {
43   DCHECK(has_number_of_properties());
44   DCHECK_NE(size(), backing_store_size);
45   Handle<Object> backing_store_size_obj =
46       isolate->factory()->NewNumberFromInt(backing_store_size);
47   set(length() - 1, *backing_store_size_obj);
48 }
49 
has_number_of_properties() const50 bool BoilerplateDescription::has_number_of_properties() const {
51   return length() % 2 != 0;
52 }
53 
54 }  // namespace internal
55 }  // namespace v8
56