10000 WiP Separate the scalalib from the Scala.js library. by sjrd · Pull Request #4787 · scala-js/scala-js · GitHub
[go: up one dir, main page]

Skip to content

WiP Separate the scalalib from the Scala.js library. #4787

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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use js.Dynamic instead of js.Dictionary in UniquenessCache.
This removes references to run-time components of
`js.WrappedDictionary` that the IR cleaner cannot get rid of.
  • Loading branch information
sjrd committed Oct 27, 2023
commit b0033b8a079d15eb75b2e2bf16290827bc6a9339
19 changes: 16 additions & 3 deletions scalalib/overrides/scala/UniquenessCache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,26 @@ import scala.scalajs.js

// Used in the various Symbol.scala files spread in version-dependent overrides.
private[scala] abstract class UniquenessCache[V >: Null] {
private val cache = js.Dictionary.empty[V]
private val safeHasOwnProperty = {
js.Dynamic.global.Object.prototype.hasOwnProperty
.asInstanceOf[js.ThisFunction1[js.Dynamic, String, Boolean]]
}

private val cache = new js.Object().asInstanceOf[js.Dynamic]

protected def valueFromKey(k: String): V
protected def keyFromValue(v: V): Option[String]

def apply(name: String): V =
cache.getOrElseUpdate(name, valueFromKey(name))
def apply(name: String): V = {
val cache = this.cache // local copy
if (safeHasOwnProperty(cache, name)) {
cache.selectDynamic(name).asInstanceOf[V]
} else {
val value = valueFromKey(name)
cache.updateDynamic(name)(value.asInstanceOf[js.Any])
value
}
}

def unapply(other: V): Option[String] = keyFromValue(other)
}
0