Skip to content

Deno and Node support for non-registered symbols in Weak{Map,Set,Ref} and FinalizationRegistry#22769

Merged
queengooborg merged 3 commits intomdn:mainfrom
lionel-rowe:non-registered-symbols-as-keys
May 11, 2024
Merged

Deno and Node support for non-registered symbols in Weak{Map,Set,Ref} and FinalizationRegistry#22769
queengooborg merged 3 commits intomdn:mainfrom
lionel-rowe:non-registered-symbols-as-keys

Conversation

@lionel-rowe
Copy link
Copy Markdown
Contributor

@lionel-rowe lionel-rowe commented Apr 4, 2024

Summary

Updated info about Deno and Node support for non-registered symbols as Weak{Map,Set} keys and as WeakRef/FinalizationRegistry targets.

I tested with the specified versions, but may well be supported by lower versions than these — not sure how important it is that the version specified is strictly the minimum requirement?

Test results and supporting details

function assert(cond) {
    if (!cond) throw '!'
}

const tests = {
    WeakMap() {
        const wm = new WeakMap()
        const key = Symbol()
        const val = { data: 1 }
        wm.set(key, val)
        assert(wm.get(key) === val)
    },
    WeakSet() {
        const ws = new WeakSet()
        const key = Symbol()
        ws.add(key)
        assert(ws.has(key))
    },
    WeakRef() {
        new WeakRef(Symbol())
    },
    FinalizationRegistry() {
        new FinalizationRegistry(() => {}).register(Symbol())
    },
}

for (const [name, test] of Object.entries(tests)) {
    try {
        test()
        console.info(`✅ ${name} supported`)
    } catch(e) {
        console.error(`❌ ${name} unsupported`, e.message)
    }
}

Related issues

N/A

@github-actions github-actions bot added the data:js Compat data for JS/ECMAScript features. https://developer.mozilla.org/docs/Web/JavaScript label Apr 4, 2024
@lionel-rowe lionel-rowe force-pushed the non-registered-symbols-as-keys branch from 5127384 to 4f236d8 Compare April 4, 2024 11:47
@lionel-rowe lionel-rowe changed the title Deno and Node support for non-registered symbols as Weak{Map,Set} keys Deno and Node support for non-registered symbols in Weak{Map,Set,Ref} and FinalizationRegistry Apr 5, 2024
@queengooborg
Copy link
Copy Markdown
Contributor

Hey there, thank you for digging into this!

This is something that could definitely be added to the mdn-bcd-collector. Would you be down to turn your test code into custom tests and submit a PR to the collector? (Happy to help if needed!)

I tested with the specified versions, but may well be supported by lower versions than these — not sure how important it is that the version specified is strictly the minimum requirement?

The version_added field should always be the earliest version the feature was supported in, rather than just the earliest version tested. We do, however, have "range syntax" -- in other words, prepending a character to state the feature may have been supported earlier -- which is allowed for releases older than two years!

@lionel-rowe
Copy link
Copy Markdown
Contributor Author

This is something that could definitely be added to the mdn-bcd-collector. Would you be down to turn your test code into custom tests and submit a PR to the collector? (Happy to help if needed!)

Done - PR here: openwebdocs/mdn-bcd-collector#1445

@lionel-rowe
Copy link
Copy Markdown
Contributor Author

The version_added field should always be the earliest version the feature was supported in, rather than just the earliest version tested. We do, however, have "range syntax" -- in other words, prepending a character to state the feature may have been supported earlier -- which is allowed for releases older than two years!

I've updated these too now.

@lionel-rowe lionel-rowe force-pushed the non-registered-symbols-as-keys branch from 649e264 to b63d3e7 Compare May 8, 2024 04:00
Copy link
Copy Markdown
Contributor

@queengooborg queengooborg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this is looking good to me!

@queengooborg queengooborg merged commit 21348c0 into mdn:main May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data:js Compat data for JS/ECMAScript features. https://developer.mozilla.org/docs/Web/JavaScript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants