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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
/*
* Copyright (C) 2006-2022 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. ``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
* 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 <wtf/Compiler.h>
WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN
#include "Integrity.h"
#include "JSAPIValueWrapper.h"
#include "JSCJSValue.h"
#include "JSCJSValueInlines.h"
#include "HeapCellInlines.h"
WTF_ALLOW_UNSAFE_BUFFER_USAGE_END
namespace JSC {
class CallFrame;
class PropertyNameArray;
class VM;
class JSObject;
class JSValue;
}
typedef const struct OpaqueJSContextGroup* JSContextGroupRef;
typedef const struct OpaqueJSContext* JSContextRef;
typedef struct OpaqueJSContext* JSGlobalContextRef;
typedef struct OpaqueJSPropertyNameAccumulator* JSPropertyNameAccumulatorRef;
typedef const struct OpaqueJSValue* JSValueRef;
typedef struct OpaqueJSValue* JSObjectRef;
/* Opaque typing convenience methods */
inline JSC::JSGlobalObject* toJS(JSContextRef context)
{
ASSERT(context);
return JSC::Integrity::audit(reinterpret_cast<JSC::JSGlobalObject*>(const_cast<OpaqueJSContext*>(context)));
}
inline JSC::JSGlobalObject* toJS(JSGlobalContextRef context)
{
ASSERT(context);
return JSC::Integrity::audit(reinterpret_cast<JSC::JSGlobalObject*>(context));
}
inline JSC::JSGlobalObject* toJSGlobalObject(JSGlobalContextRef context)
{
return toJS(context);
}
inline JSC::JSValue toJS(JSC::JSGlobalObject* globalObject, JSValueRef v)
{
ASSERT_UNUSED(globalObject, globalObject);
#if !CPU(ADDRESS64)
JSC::JSCell* jsCell = reinterpret_cast<JSC::JSCell*>(const_cast<OpaqueJSValue*>(v));
if (!jsCell)
return JSC::jsNull();
JSC::JSValue result;
if (jsCell->isAPIValueWrapper())
result = JSC::jsCast<JSC::JSAPIValueWrapper*>(jsCell)->value();
else
result = jsCell;
#else
JSC::JSValue result = std::bit_cast<JSC::JSValue>(v);
#endif
if (!result)
return JSC::jsNull();
if (result.isCell()) {
JSC::Integrity::audit(result.asCell());
RELEASE_ASSERT(result.asCell()->methodTable());
}
return result;
}
#if CPU(ADDRESS64)
inline JSC::JSValue toJS(JSValueRef value)
{
return JSC::Integrity::audit(std::bit_cast<JSC::JSValue>(value));
}
#endif
inline JSC::JSValue toJSForGC(JSC::JSGlobalObject* globalObject, JSValueRef v)
{
ASSERT_UNUSED(globalObject, globalObject);
#if !CPU(ADDRESS64)
JSC::JSCell* jsCell = reinterpret_cast<JSC::JSCell*>(const_cast<OpaqueJSValue*>(v));
if (!jsCell)
return JSC::JSValue();
JSC::JSValue result = jsCell;
#else
JSC::JSValue result = std::bit_cast<JSC::JSValue>(v);
#endif
if (result && result.isCell()) {
JSC::Integrity::audit(result.asCell());
RELEASE_ASSERT(result.asCell()->methodTable());
}
return result;
}
// Used in JSObjectGetPrivate as that may be called during finalization
inline JSC::JSObject* uncheckedToJS(JSObjectRef o)
{
return JSC::Integrity::audit(reinterpret_cast<JSC::JSObject*>(o));
}
inline JSC::JSObject* toJS(JSObjectRef o)
{
JSC::JSObject* object = uncheckedToJS(o);
if (object)
RELEASE_ASSERT(object->methodTable());
return object;
}
inline JSC::PropertyNameArray* toJS(JSPropertyNameAccumulatorRef a)
{
return reinterpret_cast<JSC::PropertyNameArray*>(a);
}
inline JSC::VM* toJS(JSContextGroupRef g)
{
return JSC::Integrity::audit(reinterpret_cast<JSC::VM*>(const_cast<OpaqueJSContextGroup*>(g)));
}
inline JSValueRef toRef(JSC::VM& vm, JSC::JSValue v)
{
ASSERT(vm.currentThreadIsHoldingAPILock());
#if !CPU(ADDRESS64)
if (!v)
return 0;
if (!v.isCell())
return reinterpret_cast<JSValueRef>(JSC::JSAPIValueWrapper::create(vm, v));
return reinterpret_cast<JSValueRef>(v.asCell());
#else
UNUSED_PARAM(vm);
return std::bit_cast<JSValueRef>(JSC::Integrity::audit(v));
#endif
}
inline JSValueRef toRef(JSC::JSGlobalObject* globalObject, JSC::JSValue v)
{
return toRef(getVM(globalObject), v);
}
#if CPU(ADDRESS64)
inline JSValueRef toRef(JSC::JSValue v)
{
return std::bit_cast<JSValueRef>(JSC::Integrity::audit(v));
}
#endif
inline JSObjectRef toRef(JSC::JSObject* o)
{
return reinterpret_cast<JSObjectRef>(JSC::Integrity::audit(o));
}
inline JSObjectRef toRef(const JSC::JSObject* o)
{
return reinterpret_cast<JSObjectRef>(JSC::Integrity::audit(const_cast<JSC::JSObject*>(o)));
}
inline JSContextRef toRef(JSC::JSGlobalObject* globalObject)
{
return reinterpret_cast<JSContextRef>(JSC::Integrity::audit(globalObject));
}
inline JSGlobalContextRef toGlobalRef(JSC::JSGlobalObject* globalObject)
{
return reinterpret_cast<JSGlobalContextRef>(JSC::Integrity::audit(globalObject));
}
inline JSPropertyNameAccumulatorRef toRef(JSC::PropertyNameArray* l)
{
return reinterpret_cast<JSPropertyNameAccumulatorRef>(l);
}
inline JSContextGroupRef toRef(JSC::VM* g)
{
return reinterpret_cast<JSContextGroupRef>(JSC::Integrity::audit(g));
}
|