11/*
2- * Copyright (C) 2006-2019 Apple Inc. All rights reserved.
2+ * Copyright (C) 2006-2022 Apple Inc. All rights reserved.
33 *
44 * Redistribution and use in source and binary forms, with or without
55 * modification, are permitted provided that the following conditions
2323 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2424 */
2525
26- #ifndef APICast_h
27- #define APICast_h
26+ #pragma once
2827
28+ #include < wtf/Compiler.h>
29+
30+ WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN
31+
32+ #include " HeapCellInlines.h"
33+ #include " Integrity.h"
2934#include " JSAPIValueWrapper.h"
3035#include " JSCJSValue.h"
3136#include " JSCJSValueInlines.h"
32- # include " JSGlobalObject.h "
33- # include " HeapCellInlines.h "
37+
38+ WTF_ALLOW_UNSAFE_BUFFER_USAGE_END
3439
3540namespace JSC {
36- class ExecState ;
41+ class CallFrame ;
3742 class PropertyNameArray ;
3843 class VM ;
3944 class JSObject ;
@@ -49,26 +54,26 @@ typedef struct OpaqueJSValue* JSObjectRef;
4954
5055/* Opaque typing convenience methods */
5156
52- inline JSC ::ExecState * toJS (JSContextRef c )
57+ inline JSC ::JSGlobalObject * toJS (JSContextRef context )
5358{
54- ASSERT (c );
55- return reinterpret_cast <JSC ::ExecState *>(const_cast <OpaqueJSContext*>(c ));
59+ ASSERT (context );
60+ return JSC::Integrity::audit ( reinterpret_cast <JSC ::JSGlobalObject *>(const_cast <OpaqueJSContext*>(context) ));
5661}
5762
58- inline JSC ::ExecState * toJS (JSGlobalContextRef c )
63+ inline JSC ::JSGlobalObject * toJS (JSGlobalContextRef context )
5964{
60- ASSERT (c );
61- return reinterpret_cast <JSC ::ExecState *>(c );
65+ ASSERT (context );
66+ return JSC::Integrity::audit ( reinterpret_cast <JSC ::JSGlobalObject *>(context) );
6267}
6368
6469inline JSC ::JSGlobalObject* toJSGlobalObject (JSGlobalContextRef context)
6570{
66- return toJS (context)-> lexicalGlobalObject () ;
71+ return toJS (context);
6772}
6873
69- inline JSC ::JSValue toJS (JSC ::ExecState* exec , JSValueRef v)
74+ inline JSC ::JSValue toJS (JSC ::JSGlobalObject* globalObject , JSValueRef v)
7075{
71- ASSERT_UNUSED (exec, exec );
76+ ASSERT_UNUSED (globalObject, globalObject );
7277#if !CPU(ADDRESS64)
7378 JSC ::JSCell* jsCell = reinterpret_cast <JSC ::JSCell*>(const_cast <OpaqueJSValue*>(v));
7479 if (!jsCell)
@@ -79,42 +84,53 @@ inline JSC::JSValue toJS(JSC::ExecState* exec, JSValueRef v)
7984 else
8085 result = jsCell;
8186#else
82- JSC ::JSValue result = bitwise_cast <JSC ::JSValue>(v);
87+ JSC ::JSValue result = std::bit_cast <JSC ::JSValue>(v);
8388#endif
8489 if (!result)
8590 return JSC::jsNull ();
86- if (result.isCell ())
87- RELEASE_ASSERT (result.asCell ()->methodTable (exec->vm ()));
91+ if (result.isCell ()) {
92+ JSC::Integrity::audit (result.asCell ());
93+ RELEASE_ASSERT (result.asCell ()->methodTable ());
94+ }
8895 return result;
8996}
9097
91- inline JSC ::JSValue toJSForGC (JSC ::ExecState* exec, JSValueRef v)
98+ #if CPU(ADDRESS64)
99+ inline JSC ::JSValue toJS (JSValueRef value)
100+ {
101+ return JSC::Integrity::audit (std::bit_cast<JSC ::JSValue>(value));
102+ }
103+ #endif
104+
105+ inline JSC ::JSValue toJSForGC (JSC ::JSGlobalObject* globalObject, JSValueRef v)
92106{
93- ASSERT_UNUSED (exec, exec );
107+ ASSERT_UNUSED (globalObject, globalObject );
94108#if !CPU(ADDRESS64)
95109 JSC ::JSCell* jsCell = reinterpret_cast <JSC ::JSCell*>(const_cast <OpaqueJSValue*>(v));
96110 if (!jsCell)
97111 return JSC::JSValue ();
98112 JSC ::JSValue result = jsCell;
99113#else
100- JSC ::JSValue result = bitwise_cast <JSC ::JSValue>(v);
114+ JSC ::JSValue result = std::bit_cast <JSC ::JSValue>(v);
101115#endif
102- if (result && result.isCell ())
103- RELEASE_ASSERT (result.asCell ()->methodTable (exec->vm ()));
116+ if (result && result.isCell ()) {
117+ JSC::Integrity::audit (result.asCell ());
118+ RELEASE_ASSERT (result.asCell ()->methodTable ());
119+ }
104120 return result;
105121}
106122
107123// Used in JSObjectGetPrivate as that may be called during finalization
108124inline JSC ::JSObject* uncheckedToJS (JSObjectRef o)
109125{
110- return reinterpret_cast <JSC ::JSObject*>(o);
126+ return JSC::Integrity::audit ( reinterpret_cast <JSC ::JSObject*>(o) );
111127}
112128
113129inline JSC ::JSObject* toJS (JSObjectRef o)
114130{
115131 JSC ::JSObject* object = uncheckedToJS (o);
116132 if (object)
117- RELEASE_ASSERT (object->methodTable (object-> vm () ));
133+ RELEASE_ASSERT (object->methodTable ());
118134 return object;
119135}
120136
@@ -125,7 +141,7 @@ inline JSC::PropertyNameArray* toJS(JSPropertyNameAccumulatorRef a)
125141
126142inline JSC ::VM * toJS (JSContextGroupRef g)
127143{
128- return reinterpret_cast <JSC ::VM *>(const_cast <OpaqueJSContextGroup*>(g));
144+ return JSC::Integrity::audit ( reinterpret_cast <JSC ::VM *>(const_cast <OpaqueJSContextGroup*>(g) ));
129145}
130146
131147inline JSValueRef toRef (JSC ::VM & vm, JSC ::JSValue v)
@@ -139,34 +155,40 @@ inline JSValueRef toRef(JSC::VM& vm, JSC::JSValue v)
139155 return reinterpret_cast <JSValueRef>(v.asCell ());
140156#else
141157 UNUSED_PARAM (vm);
142- return bitwise_cast <JSValueRef>(v );
158+ return std::bit_cast <JSValueRef>(JSC::Integrity::audit (v) );
143159#endif
144160}
145161
146- inline JSValueRef toRef (JSC ::ExecState* exec , JSC ::JSValue v)
162+ inline JSValueRef toRef (JSC ::JSGlobalObject* globalObject , JSC ::JSValue v)
147163{
148- return toRef (exec-> vm ( ), v);
164+ return toRef (getVM (globalObject ), v);
149165}
150166
167+ #if CPU(ADDRESS64)
168+ inline JSValueRef toRefWithoutGlobalObject (JSC ::JSValue v)
169+ {
170+ return std::bit_cast<JSValueRef>(JSC::Integrity::audit (v));
171+ }
172+ #endif
173+
151174inline JSObjectRef toRef (JSC ::JSObject* o)
152175{
153- return reinterpret_cast <JSObjectRef>(o );
176+ return reinterpret_cast <JSObjectRef>(JSC::Integrity::audit (o) );
154177}
155178
156179inline JSObjectRef toRef (const JSC ::JSObject* o)
157180{
158- return reinterpret_cast <JSObjectRef>(const_cast <JSC ::JSObject*>(o));
181+ return reinterpret_cast <JSObjectRef>(JSC::Integrity::audit ( const_cast <JSC ::JSObject*>(o) ));
159182}
160183
161- inline JSContextRef toRef (JSC ::ExecState* e )
184+ inline JSContextRef toRef (JSC ::JSGlobalObject* globalObject )
162185{
163- return reinterpret_cast <JSContextRef>(e );
186+ return reinterpret_cast <JSContextRef>(JSC::Integrity::audit (globalObject) );
164187}
165188
166- inline JSGlobalContextRef toGlobalRef (JSC ::ExecState* e )
189+ inline JSGlobalContextRef toGlobalRef (JSC ::JSGlobalObject* globalObject )
167190{
168- ASSERT (e == e->lexicalGlobalObject ()->globalExec ());
169- return reinterpret_cast <JSGlobalContextRef>(e);
191+ return reinterpret_cast <JSGlobalContextRef>(JSC::Integrity::audit (globalObject));
170192}
171193
172194inline JSPropertyNameAccumulatorRef toRef (JSC ::PropertyNameArray* l)
@@ -176,7 +198,5 @@ inline JSPropertyNameAccumulatorRef toRef(JSC::PropertyNameArray* l)
176198
177199inline JSContextGroupRef toRef (JSC ::VM * g)
178200{
179- return reinterpret_cast <JSContextGroupRef>(g );
201+ return reinterpret_cast <JSContextGroupRef>(JSC::Integrity::audit (g) );
180202}
181-
182- #endif // APICast_h
0 commit comments