MCPcopy Create free account
hub / github.com/dop251/goja / TestGoReflectArrayCopyOnChange

Function TestGoReflectArrayCopyOnChange

object_goarray_reflect_test.go:53–171  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

51}
52
53func TestGoReflectArrayCopyOnChange(t *testing.T) {
54 vm := New()
55
56 v, err := vm.RunString(`
57 a => {
58 let tmp = a[0];
59 if (tmp !== a[0]) {
60 throw new Error("tmp !== a[0]");
61 }
62
63 a[0] = a[1];
64 if (tmp === a[0]) {
65 throw new Error("tmp === a[0]");
66 }
67 if (tmp.Test !== "1") {
68 throw new Error("tmp.Test: " + tmp.Test + " (" + typeof tmp.Test + ")");
69 }
70 if (a[0].Test !== "2") {
71 throw new Error("a[0].Test: " + a[0].Test);
72 }
73
74 a[0].Test = "3";
75 if (a[0].Test !== "3") {
76 throw new Error("a[0].Test (1): " + a[0].Test);
77 }
78
79 tmp = a[0];
80 tmp.Test = "4";
81 if (a[0].Test !== "4") {
82 throw new Error("a[0].Test (2): " + a[0].Test);
83 }
84
85 delete a[0];
86 if (a[0] && a[0].Test !== "") {
87 throw new Error("a[0].Test (3): " + a[0].Test);
88 }
89 if (tmp.Test !== "4") {
90 throw new Error("tmp.Test (1): " + tmp.Test);
91 }
92
93 a[1] = tmp;
94 if (a[1].Test !== "4") {
95 throw new Error("a[1].Test: " + a[1].Test);
96 }
97
98 // grow
99 tmp = a[1];
100 a.push(null);
101 if (a.length !== 3) {
102 throw new Error("a.length after push: " + a.length);
103 }
104
105 tmp.Test = "5";
106 if (a[1].Test !== "5") {
107 throw new Error("a[1].Test (1): " + a[1].Test);
108 }
109
110 // shrink

Callers

nothing calls this directly

Calls 4

NewFunction · 0.85
AssertFunctionFunction · 0.85
RunStringMethod · 0.80
ToValueMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…