Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Enable Atomics object unconditionally.
https://bugs.webkit.org/show_bug.cgi?id=243342
<rdar://97786341>

Reviewed by Geoffrey Garen and Yusuke Suzuki.

The Atomics object is only being created and made available to the runtime when
SharedArrayBuffer is enabled. In practice this means Atomics is only available when
crossOriginIsolation is true.

Other major browsers expose the Atomics object regardless of the state of crossOriginIsolation.
Using Atomics without shared memory isn't particularly useful but the goal of this is
to improve our interopability with other browsers.

* Source/JavaScriptCore/runtime/JSGlobalObject.cpp:
(JSC::createAtomicsProperty):
(JSC::JSGlobalObject::init):

Canonical link: https://commits.webkit.org/253137@main
  • Loading branch information
rreno authored and stwrt committed Aug 4, 2022
1 parent 474ef37 commit 09e0997
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions Source/JavaScriptCore/runtime/JSGlobalObject.cpp
Expand Up @@ -318,6 +318,12 @@ static JSValue createReflectProperty(VM& vm, JSObject* object)
return ReflectObject::create(vm, global, ReflectObject::createStructure(vm, global, global->objectPrototype()));
}

static JSValue createAtomicsProperty(VM& vm, JSObject *object)
{
JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
return AtomicsObject::create(vm, global, AtomicsObject::createStructure(vm, global, global->objectPrototype()));
}

static JSValue createConsoleProperty(VM& vm, JSObject* object)
{
JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
Expand Down Expand Up @@ -589,6 +595,7 @@ const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = {
Reflect createReflectProperty DontEnum|PropertyCallback
JSON createJSONProperty DontEnum|PropertyCallback
Math createMathProperty DontEnum|PropertyCallback
Atomics createAtomicsProperty DontEnum|PropertyCallback
console createConsoleProperty DontEnum|PropertyCallback
Int8Array JSGlobalObject::m_typedArrayInt8 DontEnum|ClassStructure
Int16Array JSGlobalObject::m_typedArrayInt16 DontEnum|ClassStructure
Expand Down Expand Up @@ -1067,10 +1074,6 @@ void JSGlobalObject::init(VM& vm)
m_regExpConstructor.set(vm, this, regExpConstructor);
m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::RegExp)].set(vm, this, regExpConstructor);
m_regExpGlobalData.cachedResult().record(vm, this, nullptr, jsEmptyString(vm), MatchResult(0, 0));

AtomicsObject* atomicsObject = nullptr;
if (Options::useSharedArrayBuffer())
atomicsObject = AtomicsObject::create(vm, this, AtomicsObject::createStructure(vm, this, m_objectPrototype.get()));

#define CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase, featureFlag) \
capitalName ## Constructor* lowerName ## Constructor = featureFlag ? capitalName ## Constructor::create(vm, capitalName ## Constructor::createStructure(vm, this, m_functionPrototype.get()), m_ ## lowerName ## Prototype.get(), m_speciesGetterSetter.get()) : nullptr; \
Expand Down Expand Up @@ -1151,10 +1154,8 @@ capitalName ## Constructor* lowerName ## Constructor = featureFlag ? capitalName
putDirectWithoutTransition(vm, vm.propertyNames->Array, arrayConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
putDirectWithoutTransition(vm, vm.propertyNames->RegExp, regExpConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));

if (Options::useSharedArrayBuffer()) {
if (Options::useSharedArrayBuffer())
putDirectWithoutTransition(vm, vm.propertyNames->SharedArrayBuffer, m_sharedArrayBufferStructure.constructor(this), static_cast<unsigned>(PropertyAttribute::DontEnum));
putDirectWithoutTransition(vm, vm.propertyNames->Atomics, atomicsObject, static_cast<unsigned>(PropertyAttribute::DontEnum));
}

#define PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase, featureFlag) \
if (featureFlag) \
Expand Down

0 comments on commit 09e0997

Please sign in to comment.