Skip to content

Commit 156e55f

Browse files
committed
It seems like a struct named Map could shadow the scope of window.Map and cause unexpected behavior.
That's my hunch anyway. The code at https://github.com/gopherjs/gopherjs/blob/a4630ec28c790dd1be785f097d0268c4aa4a423f/nosync/map.go#L37 was making an object that didn't have a `.get` function. This fixes it. The before Javascript: ``` Map.ptr.prototype.LoadOrStore = function(key, value) { var _entry, _key, _tmp, _tmp$1, _tmp$2, _tmp$3, _tuple, actual, key, loaded, m, ok, value, value$1, x; actual = $ifaceNil; loaded = false; m = this; _tuple = (x = m.m, (_entry = typeof x.get === "function" ? x.get($emptyInterface.keyFor(key)) : undefined, _entry !== undefined ? [_entry.v, true] : [$ifaceNil, false])); value$1 = _tuple[0]; ok = _tuple[1]; if (ok) { _tmp = value$1; _tmp$1 = true; actual = _tmp; loaded = _tmp$1; return [actual, loaded]; } if (m.m === false) { m.m = new Map(); } _key = key; (m.m || $throwRuntimeError("assignment to entry in nil map")).set($emptyInterface.keyFor(_key), { k: _key, v: value }); _tmp$2 = value; _tmp$3 = false; actual = _tmp$2; loaded = _tmp$3; return [actual, loaded]; }; ```
1 parent 0ab08ce commit 156e55f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

compiler/expressions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,9 +931,9 @@ func (fc *funcContext) translateBuiltin(name string, sig *types.Signature, args
931931
return fc.formatExpr("$makeSlice(%s, %f)", t, args[1])
932932
case *types.Map:
933933
if len(args) == 2 && fc.pkgCtx.Types[args[1]].Value == nil {
934-
return fc.formatExpr(`((%1f < 0 || %1f > 2147483647) ? $throwRuntimeError("makemap: size out of range") : new Map())`, args[1])
934+
return fc.formatExpr(`((%1f < 0 || %1f > 2147483647) ? $throwRuntimeError("makemap: size out of range") : new window.Map())`, args[1])
935935
}
936-
return fc.formatExpr(`new Map()`)
936+
return fc.formatExpr(`new window.Map()`)
937937
case *types.Chan:
938938
length := "0"
939939
if len(args) == 2 {

0 commit comments

Comments
 (0)