MCPcopy Index your code
hub / github.com/dop251/goja / TestArraySparseExportProps

Function TestArraySparseExportProps

array_sparse_test.go:176–232  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

174}
175
176func TestArraySparseExportProps(t *testing.T) {
177 vm := New()
178 proto := vm.NewArray()
179 for _, idx := range []string{"0", "500", "9999", "10001", "20471"} {
180 err := proto.Set(idx, true)
181 if err != nil {
182 t.Fatal(err)
183 }
184 }
185
186 arr := vm.NewArray()
187 err := arr.SetPrototype(proto)
188 if err != nil {
189 t.Fatal(err)
190 }
191 err = arr.DefineDataProperty("20470", vm.ToValue(true), FLAG_TRUE, FLAG_FALSE, FLAG_TRUE)
192 if err != nil {
193 t.Fatal(err)
194 }
195 err = arr.DefineDataProperty("10000", vm.ToValue(true), FLAG_TRUE, FLAG_FALSE, FLAG_TRUE)
196 if err != nil {
197 t.Fatal(err)
198 }
199 err = arr.Set("length", 20472)
200 if err != nil {
201 t.Fatal(err)
202 }
203 actual := arr.Export()
204 if actualArr, ok := actual.([]interface{}); ok {
205 if len(actualArr) == 20472 {
206 expectedIdx := map[int]struct{}{
207 0: {},
208 500: {},
209 9999: {},
210 10000: {},
211 10001: {},
212 20470: {},
213 20471: {},
214 }
215 for i, v := range actualArr {
216 if _, exists := expectedIdx[i]; exists {
217 if v != true {
218 t.Fatalf("Expected true at %d, got %v", i, v)
219 }
220 } else {
221 if v != nil {
222 t.Fatalf("Expected nil at %d, got %v", i, v)
223 }
224 }
225 }
226 } else {
227 t.Fatalf("Expected len 20471, actual: %d", len(actualArr))
228 }
229 } else {
230 t.Fatalf("Invalid export type: %T", actual)
231 }
232}
233

Callers

nothing calls this directly

Calls 7

NewFunction · 0.85
NewArrayMethod · 0.80
SetPrototypeMethod · 0.80
DefineDataPropertyMethod · 0.80
ToValueMethod · 0.80
SetMethod · 0.65
ExportMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…