arguments-inl.h 2.89 KB
Newer Older
1 2 3 4 5 6 7 8 9
// 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.

#ifndef V8_OBJECTS_ARGUMENTS_INL_H_
#define V8_OBJECTS_ARGUMENTS_INL_H_

#include "src/objects/arguments.h"

10 11 12 13 14
#include "src/contexts-inl.h"
#include "src/isolate-inl.h"
#include "src/objects-inl.h"
#include "src/objects/fixed-array-inl.h"

15 16 17 18 19 20
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"

namespace v8 {
namespace internal {

21
OBJECT_CONSTRUCTORS_IMPL(SloppyArgumentsElements, FixedArray)
22
OBJECT_CONSTRUCTORS_IMPL(JSArgumentsObject, JSObject)
23
OBJECT_CONSTRUCTORS_IMPL(AliasedArgumentsEntry, Struct)
24

25 26 27
CAST_ACCESSOR(AliasedArgumentsEntry)
CAST_ACCESSOR(SloppyArgumentsElements)
CAST_ACCESSOR(JSArgumentsObject)
28 29 30

SMI_ACCESSORS(AliasedArgumentsEntry, aliased_context_slot, kAliasedContextSlot)

31
Context SloppyArgumentsElements::context() {
32 33 34
  return Context::cast(get(kContextIndex));
}

35
FixedArray SloppyArgumentsElements::arguments() {
36 37 38
  return FixedArray::cast(get(kArgumentsIndex));
}

39
void SloppyArgumentsElements::set_arguments(FixedArray arguments) {
40 41 42 43 44 45 46
  set(kArgumentsIndex, arguments);
}

uint32_t SloppyArgumentsElements::parameter_map_length() {
  return length() - kParameterMapStart;
}

47
Object SloppyArgumentsElements::get_mapped_entry(uint32_t entry) {
48 49 50
  return get(entry + kParameterMapStart);
}

51
void SloppyArgumentsElements::set_mapped_entry(uint32_t entry, Object object) {
52 53 54
  set(entry + kParameterMapStart, object);
}

55 56 57 58 59 60 61
// TODO(danno): This shouldn't be inline here, but to defensively avoid
// regressions associated with the fix for the bug 778574, it's staying that way
// until the splice implementation in builtin-arrays.cc can be removed and this
// function can be moved into runtime-arrays.cc near its other usage.
bool JSSloppyArgumentsObject::GetSloppyArgumentsLength(Isolate* isolate,
                                                       Handle<JSObject> object,
                                                       int* out) {
62
  Context context = *isolate->native_context();
63
  Map map = object->map();
64 65 66 67 68 69
  if (map != context->sloppy_arguments_map() &&
      map != context->strict_arguments_map() &&
      map != context->fast_aliased_arguments_map()) {
    return false;
  }
  DCHECK(object->HasFastElements() || object->HasFastArgumentsElements());
70
  Object len_obj =
71
      object->InObjectPropertyAt(JSArgumentsObjectWithLength::kLengthIndex);
72 73 74
  if (!len_obj->IsSmi()) return false;
  *out = Max(0, Smi::ToInt(len_obj));

75
  FixedArray parameters = FixedArray::cast(object->elements());
76
  if (object->HasSloppyArgumentsElements()) {
77
    FixedArray arguments = FixedArray::cast(parameters->get(1));
78 79 80 81 82
    return *out <= arguments->length();
  }
  return *out <= parameters->length();
}

83 84 85 86 87 88
}  // namespace internal
}  // namespace v8

#include "src/objects/object-macros-undef.h"

#endif  // V8_OBJECTS_ARGUMENTS_INL_H_