Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c74dd49

Browse files
committed
fix: handle frozen receivers in $methodVal
Fixes #1408
1 parent 346e3e9 commit c74dd49

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

compiler/prelude/prelude.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ var $mapDelete = (m, key) => {
118118
// standalone function. Bound function is cached for later reuse.
119119
var $methodVal = (recv, name) => {
120120
var vals = recv.$methodVals || {};
121-
recv.$methodVals = vals; /* noop for primitives */
121+
if (Object.isExtensible(recv)) {
122+
recv.$methodVals = vals; /* noop for primitives */
123+
}
122124
var f = vals[name];
123125
if (f !== undefined) {
124126
return f;

tests/frozenreceiver_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package tests
2+
3+
import "testing"
4+
5+
type mySlice []int
6+
7+
func (s mySlice) Len() int { return len(s) }
8+
func TestMethodValueOnNilSlice(t *testing.T) {
9+
var s mySlice
10+
f := s.Len
11+
if got := f(); got != 0 {
12+
t.Errorf("got %d, want 0", got)
13+
}
14+
}

0 commit comments

Comments
 (0)