Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[JSC] Implement Symbols as WeakMap keys
https://bugs.webkit.org/show_bug.cgi?id=243483 Reviewed by Ross Kirsling and Saam Barati. This patch implements stage-3 proposal "Symbols as WeakMap keys"[1]. Previously, WeakMap, WeakSet, FinalizationRegistry, and WeakRef are only accepting objects as keys. But this proposal extends it to accept non-registered Symbols too. The runtime implementation is just changed from using JSObject* to JSCell*. And we check whether the given value is appropriate by using canBeHeldWeakly function (specified in the spec) instead of `isObject()`. A bit complicated part is DFG / FTL handling for WeakMap / WeakSet functions. We extend it to accept SymbolUse and CellUse. And we emit appropriate code for that, and modifying clobberizing rules and doesGC rules too for these new UseKind. [1]: https://github.com/tc39/proposal-symbols-as-weakmap-keys * JSTests/stress/finalization-registry-registered-symbol.js: Added. (shouldThrow): * JSTests/stress/v8-cleanup-from-different-realm-symbol.js: Added. (let.timeout_func): * JSTests/stress/v8-cleanup-proxy-from-different-realm-symbol.js: Added. (let.timeout_func): * JSTests/stress/v8-finalization-registry-basics-symbol.js: Copied from JSTests/stress/v8-finalization-registry-basics.js. (TestConstructFinalizationRegistry): (TestFinalizationRegistryConstructorCallAsFunction): (TestConstructFinalizationRegistryCleanupNotCallable): (TestConstructFinalizationRegistryWithNonCallableProxyAsCleanup): (TestRegisterTargetAndHoldingsSameValue): (TestRegisterWithoutFinalizationRegistry): (TestUnregisterWithNonExistentKey): (TestUnregisterWithNonFinalizationRegistry): (TestWeakRefConstructorWithNonObject): * JSTests/stress/v8-finalization-registry-basics.js: (TestWeakRefConstructorWithNonObject): * JSTests/stress/v8-finalizationregistry-and-weakref-symbol.js: Added. (let.cleanup): (setTimeout): * JSTests/stress/v8-finalizationregistry-keeps-holdings-alive-symbol.js: Added. (let.cleanup): (let.timeout_func): * JSTests/stress/v8-finalizationregistry-scheduled-for-cleanup-multiple-times-symbol.js: Added. (let.cleanup0): (let.cleanup1): (let.timeout_func): * JSTests/stress/v8-multiple-dirty-finalization-registries-symbol.js: Added. (let.cleanup): (let.timeout_func): * JSTests/stress/v8-reentrant-gc-from-cleanup-symbol.js: Added. (let.reentrant_gc): (setTimeout): * JSTests/stress/v8-stress-finalizationregistry-dirty-enqueue-symbol.js: Added. (i.registries.push.new.FinalizationRegistry): (registries.forEach): * JSTests/stress/v8-undefined-holdings-symbol.js: Added. (let.cleanup): (let.timeout_func): * JSTests/stress/v8-unregister-after-cleanup-symbol.js: Added. (let.cleanup): (let.timeout_func): * JSTests/stress/v8-unregister-before-cleanup-symbol.js: Added. (let.cleanup): (let.timeout_func): * JSTests/stress/v8-unregister-called-twice-symbol.js: Added. (let.cleanup): (let.timeout_func): * JSTests/stress/v8-unregister-inside-cleanup2-symbol.js: Added. (let.cleanup): (let.timeout_func): * JSTests/stress/v8-unregister-inside-cleanup3-symbol.js: Added. (let.cleanup): (let.timeout_func): * JSTests/stress/v8-unregister-many-symbol.js: Added. (let.cleanup): (let.timeout_func): * JSTests/stress/v8-weak-unregistertoken-symbol.js: Added. (FR.new.FinalizationRegistry): (tryAgain): * JSTests/stress/weak-map-constructor.js: * JSTests/stress/weak-map-registered-symbol.js: Added. (shouldBe): (shouldThrow): * JSTests/stress/weak-map-symbol.js: Added. (shouldBe): (test): * JSTests/stress/weak-map-various-one-site.js: Added. (shouldThrow): (getTest): (hasTest): (setTest): (deleteTest): (i.test.set shouldBe): (i.test): * JSTests/stress/weak-map-various.js: Added. (shouldBe): * JSTests/stress/weak-ref-registered-symbol.js: Added. (shouldThrow): * JSTests/stress/weak-set-constructor.js: * JSTests/stress/weak-set-registered-symbol.js: Added. (shouldBe): (shouldThrow): (test.set add): * JSTests/stress/weak-set-symbol.js: Added. (shouldBe): * JSTests/stress/weak-set-various-one-site.js: Added. (shouldThrow): (set shouldThrow): * JSTests/stress/weak-set-various.js: Added. (shouldBe): * JSTests/test262/config.yaml: * LayoutTests/js/dom/basic-weakmap-expected.txt: * LayoutTests/js/dom/basic-weakset-expected.txt: * Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h: (JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects): * Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::handleIntrinsicCall): * Source/JavaScriptCore/dfg/DFGClobberize.h: (JSC::DFG::clobberize): * Source/JavaScriptCore/dfg/DFGDoesGC.cpp: (JSC::DFG::doesGC): * Source/JavaScriptCore/dfg/DFGFixupPhase.cpp: (JSC::DFG::FixupPhase::fixupNode): * Source/JavaScriptCore/dfg/DFGOperations.cpp: (JSC::DFG::JSC_DEFINE_JIT_OPERATION): * Source/JavaScriptCore/dfg/DFGOperations.h: * Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp: * Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::compileCompareStrictEq): * Source/JavaScriptCore/runtime/FinalizationRegistryPrototype.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * Source/JavaScriptCore/runtime/JSFinalizationRegistry.cpp: (JSC::JSFinalizationRegistry::registerTarget): (JSC::JSFinalizationRegistry::unregister): * Source/JavaScriptCore/runtime/JSFinalizationRegistry.h: * Source/JavaScriptCore/runtime/JSWeakMap.h: * Source/JavaScriptCore/runtime/JSWeakMapInlines.h: (JSC::JSWeakMap::set): * Source/JavaScriptCore/runtime/JSWeakObjectRef.cpp: (JSC::JSWeakObjectRef::finishCreation): * Source/JavaScriptCore/runtime/JSWeakObjectRef.h: * Source/JavaScriptCore/runtime/WeakMapConstructor.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * Source/JavaScriptCore/runtime/WeakMapImpl.cpp: (JSC::WeakMapImpl<WeakMapBucket>::takeSnapshotInternal): (JSC::WeakMapImpl<WeakMapBucket<WeakMapBucketDataKey>>::takeSnapshot): (JSC::WeakMapImpl<WeakMapBucket<WeakMapBucketDataKeyValue>>::takeSnapshot): * Source/JavaScriptCore/runtime/WeakMapImpl.h: (JSC::WeakMapBucket::setKey): (JSC::WeakMapBucket::key const): (JSC::WeakMapBucket::deletedKey): (JSC::WeakMapImpl::get): (JSC::WeakMapImpl::findBucket): (JSC::WeakMapImpl::has): (JSC::WeakMapImpl::remove): (JSC::WeakMapImpl::canUseBucket): (JSC::WeakMapImpl::addInternal): (JSC::WeakMapImpl::findBucketAlreadyHashed): * Source/JavaScriptCore/runtime/WeakMapImplInlines.h: (JSC::jsWeakMapHash): (JSC::canBeHeldWeakly): (JSC::WeakMapImpl<WeakMapBucket>::add): * Source/JavaScriptCore/runtime/WeakMapPrototype.cpp: (JSC::WeakMapPrototype::finishCreation): (JSC::JSC_DEFINE_HOST_FUNCTION): * Source/JavaScriptCore/runtime/WeakMapPrototype.h: * Source/JavaScriptCore/runtime/WeakObjectRefConstructor.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * Source/JavaScriptCore/runtime/WeakSetConstructor.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * Source/JavaScriptCore/runtime/WeakSetPrototype.cpp: (JSC::WeakSetPrototype::finishCreation): (JSC::JSC_DEFINE_HOST_FUNCTION): * Source/JavaScriptCore/runtime/WeakSetPrototype.h: Canonical link: https://commits.webkit.org/253135@main
- Loading branch information