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