2 * Copyright (C) 2015 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef ScopedArgumentsTable_h
27 #define ScopedArgumentsTable_h
30 #include "ScopeOffset.h"
31 #include <wtf/Assertions.h>
35 // This class's only job is to hold onto the list of ScopeOffsets for each argument that a
36 // function has. Most of the time, the BytecodeGenerator will create one of these and it will
37 // never be modified subsequently. There is a rare case where a ScopedArguments object is created
38 // and aliases one of these and then decides to modify it; in that case we do copy-on-write. This
39 // makes sense because such modifications are so uncommon. You'd have to do something crazy like
40 // "delete arguments[i]" or some variant of defineOwnProperty.
41 class ScopedArgumentsTable final
: public JSCell
{
44 static const unsigned StructureFlags
= Base::StructureFlags
| StructureIsImmortal
;
47 ScopedArgumentsTable(VM
&);
48 ~ScopedArgumentsTable();
51 static ScopedArgumentsTable
* create(VM
&);
52 static ScopedArgumentsTable
* create(VM
&, uint32_t length
);
54 static const bool needsDestruction
= true;
55 static void destroy(JSCell
*);
57 ScopedArgumentsTable
* clone(VM
&);
59 uint32_t length() const { return m_length
; }
60 ScopedArgumentsTable
* setLength(VM
&, uint32_t newLength
);
62 ScopeOffset
get(uint32_t i
) const
64 return const_cast<ScopedArgumentsTable
*>(this)->at(i
);
72 ScopedArgumentsTable
* set(VM
&, uint32_t index
, ScopeOffset
);
76 static Structure
* createStructure(VM
&, JSGlobalObject
*, JSValue prototype
);
78 static ptrdiff_t offsetOfLength() { return OBJECT_OFFSETOF(ScopedArgumentsTable
, m_length
); }
79 static ptrdiff_t offsetOfArguments() { return OBJECT_OFFSETOF(ScopedArgumentsTable
, m_arguments
); }
82 ScopeOffset
& at(uint32_t i
)
84 ASSERT_WITH_SECURITY_IMPLICATION(i
< m_length
);
85 return m_arguments
[i
];
89 bool m_locked
; // Being locked means that there are multiple references to this object and none of them expect to see the others' modifications. This means that modifications need to make a copy first.
90 std::unique_ptr
<ScopeOffset
[]> m_arguments
;
95 #endif // ScopedArgumentsTable_h