You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Every symbol holds a SymbolCode enum to say what kind of Symbol it is.
We could make symbol!() a macro, so that description can be dynamically added, or description could be an
This means we should be safe to use the rand crate and generate u32 values here. As that’s all Spidermonkey is doing.
Spidermonkey team say random() should be fine
What is random() powered by?
random() is just a shortcut for thread_rnd().gen() which itself uses rand:rngs::StdRng.
The current algorithm used is the ChaCha block cipher, it is not secure.
More performance
rand::rngs::SmallRng is the best choice for small state, cheap initialisation, good statistical quality and good performance. We don’t care so much about security here, so we should go with this.
Can we just increment a number?
Technically we don’t ever expose the hash to a Symbol, and our only criteria is that they’re unique.
So we could just increment a number
Symbol instances are ordinary objects that inherit properties from the Symbol prototype object. Symbol instances have a [[SymbolData]] internal slot. The [[SymbolData]] internal slot is the Symbol value represented by this Symbol object.
Spidermonkey calls Symbol::new() with ctx, SymbolCode::Unique and description.
https://searchfox.org/mozilla-central/source/js/src/vm/SymbolType.cpp#34
Every symbol holds a SymbolCode enum to say what kind of Symbol it is.
We could make symbol!() a macro, so that description can be dynamically added, or description could be an
Hashing
Both Spidermonkey and V8 use u32 for their hash code. So there’s no reason we need a u64 here.
Spidermonkey uses XorShift128PlusSeed algorithm to generate random hashes.
https://searchfox.org/mozilla-central/source/js/src/vm/Runtime.cpp#682
This means we should be safe to use the rand crate and generate u32 values here. As that’s all Spidermonkey is doing.
Spidermonkey team say random() should be fine
What is random() powered by?
random() is just a shortcut for thread_rnd().gen() which itself uses rand:rngs::StdRng.
The current algorithm used is the ChaCha block cipher, it is not secure.
More performance
rand::rngs::SmallRng is the best choice for small state, cheap initialisation, good statistical quality and good performance. We don’t care so much about security here, so we should go with this.
Can we just increment a number?
Technically we don’t ever expose the hash to a Symbol, and our only criteria is that they’re unique.
So we could just increment a number
References:
Implement Symbols: https://bugzilla.mozilla.org/show_bug.cgi?id=645416
The text was updated successfully, but these errors were encountered: