• 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 #ifndef V8_OBJECTS_ARGUMENTS_INL_H_
6 #define V8_OBJECTS_ARGUMENTS_INL_H_
7 
8 #include "src/objects/arguments.h"
9 
10 #include "src/contexts-inl.h"
11 #include "src/isolate-inl.h"
12 #include "src/objects-inl.h"
13 #include "src/objects/fixed-array-inl.h"
14 
15 // Has to be the last include (doesn't have include guards):
16 #include "src/objects/object-macros.h"
17 
18 namespace v8 {
19 namespace internal {
20 
21 CAST_ACCESSOR(AliasedArgumentsEntry)
CAST_ACCESSOR(JSArgumentsObject)22 CAST_ACCESSOR(JSArgumentsObject)
23 CAST_ACCESSOR(SloppyArgumentsElements)
24 
25 SMI_ACCESSORS(AliasedArgumentsEntry, aliased_context_slot, kAliasedContextSlot)
26 
27 Context* SloppyArgumentsElements::context() {
28   return Context::cast(get(kContextIndex));
29 }
30 
arguments()31 FixedArray* SloppyArgumentsElements::arguments() {
32   return FixedArray::cast(get(kArgumentsIndex));
33 }
34 
set_arguments(FixedArray * arguments)35 void SloppyArgumentsElements::set_arguments(FixedArray* arguments) {
36   set(kArgumentsIndex, arguments);
37 }
38 
parameter_map_length()39 uint32_t SloppyArgumentsElements::parameter_map_length() {
40   return length() - kParameterMapStart;
41 }
42 
get_mapped_entry(uint32_t entry)43 Object* SloppyArgumentsElements::get_mapped_entry(uint32_t entry) {
44   return get(entry + kParameterMapStart);
45 }
46 
set_mapped_entry(uint32_t entry,Object * object)47 void SloppyArgumentsElements::set_mapped_entry(uint32_t entry, Object* object) {
48   set(entry + kParameterMapStart, object);
49 }
50 
51 // TODO(danno): This shouldn't be inline here, but to defensively avoid
52 // regressions associated with the fix for the bug 778574, it's staying that way
53 // until the splice implementation in builtin-arrays.cc can be removed and this
54 // function can be moved into runtime-arrays.cc near its other usage.
GetSloppyArgumentsLength(Isolate * isolate,Handle<JSObject> object,int * out)55 bool JSSloppyArgumentsObject::GetSloppyArgumentsLength(Isolate* isolate,
56                                                        Handle<JSObject> object,
57                                                        int* out) {
58   Context* context = *isolate->native_context();
59   Map* map = object->map();
60   if (map != context->sloppy_arguments_map() &&
61       map != context->strict_arguments_map() &&
62       map != context->fast_aliased_arguments_map()) {
63     return false;
64   }
65   DCHECK(object->HasFastElements() || object->HasFastArgumentsElements());
66   Object* len_obj = object->InObjectPropertyAt(JSArgumentsObject::kLengthIndex);
67   if (!len_obj->IsSmi()) return false;
68   *out = Max(0, Smi::ToInt(len_obj));
69 
70   FixedArray* parameters = FixedArray::cast(object->elements());
71   if (object->HasSloppyArgumentsElements()) {
72     FixedArray* arguments = FixedArray::cast(parameters->get(1));
73     return *out <= arguments->length();
74   }
75   return *out <= parameters->length();
76 }
77 
78 }  // namespace internal
79 }  // namespace v8
80 
81 #include "src/objects/object-macros-undef.h"
82 
83 #endif  // V8_OBJECTS_ARGUMENTS_INL_H_
84