forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathJSInternalFieldObjectImpl.h
More file actions
104 lines (86 loc) · 4.19 KB
/
Copy pathJSInternalFieldObjectImpl.h
File metadata and controls
104 lines (86 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Copyright (C) 2019-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "JSObject.h"
#include <wtf/Atomics.h>
WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN
namespace JSC {
// This is used for sharing interface and implementation. It should not have its own classInfo.
template<unsigned passedNumberOfInternalFields = 1>
class JSInternalFieldObjectImpl : public JSNonFinalObject {
public:
friend class LLIntOffsetsExtractor;
using Base = JSNonFinalObject;
static constexpr unsigned numberOfInternalFields = passedNumberOfInternalFields;
template<typename CellType, SubspaceAccess>
static void subspaceFor(VM&)
{
RELEASE_ASSERT_NOT_REACHED();
}
static size_t allocationSize(Checked<size_t> inlineCapacity)
{
ASSERT_UNUSED(inlineCapacity, !inlineCapacity);
return sizeof(JSInternalFieldObjectImpl);
}
const WriteBarrier<Unknown>& internalField(unsigned index) const
{
ASSERT(index < numberOfInternalFields);
return m_internalFields[index];
}
WriteBarrier<Unknown>& internalField(unsigned index)
{
ASSERT(index < numberOfInternalFields);
return m_internalFields[index];
}
// SPEC-ungil §N.5 (annex N7 row R7): the generic atomic word view onto an
// internal field, for the resume-claim CAS / release-publish primitives
// (@atomicInternalFieldClaim/Publish in the spec; landed as host hooks —
// see SPEC-ungil-history.md "§N.5 LANDED SHAPE"). Layout-only: every
// WriteBarrier<Unknown> slot is exactly one EncodedJSValue word and
// naturally aligned, so the bit_cast is the same word op_get/put_
// internal_field touches in every tier. No write-barrier is implied — the
// §N.5 claim word holds int32 jsNumbers only (states + tokens), never a
// cell; callers storing a cell through this view would need their own
// barrier. Flag-off byte-identical: the accessor is dead code (every
// caller is behind the @gilOffProcess constant branch / vm.gilOff()).
Atomic<EncodedJSValue>& atomicInternalField(unsigned index)
{
static_assert(sizeof(WriteBarrier<Unknown>) == sizeof(EncodedJSValue));
static_assert(alignof(WriteBarrier<Unknown>) >= alignof(EncodedJSValue));
ASSERT(index < numberOfInternalFields);
return *std::bit_cast<Atomic<EncodedJSValue>*>(&m_internalFields[index]);
}
static constexpr ptrdiff_t offsetOfInternalFields() { return OBJECT_OFFSETOF(JSInternalFieldObjectImpl, m_internalFields); }
static constexpr ptrdiff_t offsetOfInternalField(unsigned index) { return OBJECT_OFFSETOF(JSInternalFieldObjectImpl, m_internalFields) + index * sizeof(WriteBarrier<Unknown>); }
DECLARE_VISIT_CHILDREN;
protected:
JSInternalFieldObjectImpl(VM& vm, Structure* structure)
: Base(vm, structure)
{
}
WriteBarrier<Unknown> m_internalFields[numberOfInternalFields] { };
};
} // namespace JSC
WTF_ALLOW_UNSAFE_BUFFER_USAGE_END