Debian Codegraph @

js/src/builtin/Array-inl.h

raw
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef builtin_Array_inl_h
8 #define builtin_Array_inl_h
9
10 #include "builtin/Array.h"
11
12 #include "vm/JSObject.h"
13
14 #include "vm/ArgumentsObject-inl.h"
15 #include "vm/ObjectOperations-inl.h"
16
17 namespace js {
18
19 inline bool GetElement(JSContext* cx, HandleObject obj, uint32_t index,
20 MutableHandleValue vp) {
21 if (obj->is<NativeObject>() &&
22 index < obj->as<NativeObject>().getDenseInitializedLength()) {
23 vp.set(obj->as<NativeObject>().getDenseElement(index));
24 if (!vp.isMagic(JS_ELEMENTS_HOLE)) {
25 return true;
26 }
27 }
28
29 if (obj->is<ArgumentsObject>()) {
30 if (obj->as<ArgumentsObject>().maybeGetElement(index, vp)) {
31 return true;
32 }
33 }
34
35 return GetElement(cx, obj, obj, index, vp);
36 }
37
38 } // namespace js
39
40 #endif // builtin_Array_inl_h