Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing Symbol (Braindump) #90

Closed
jasonwilliams opened this issue Aug 22, 2019 · 1 comment
Closed

Implementing Symbol (Braindump) #90

jasonwilliams opened this issue Aug 22, 2019 · 1 comment
Assignees

Comments

@jasonwilliams
Copy link
Member

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

@jasonwilliams
Copy link
Member Author

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.

https://tc39.es/ecma262/#sec-properties-of-symbol-instances

@jasonwilliams jasonwilliams self-assigned this Oct 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant