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

Function ExampleRuntime_ExportTo_iterableToSlice

object_test.go:317–343  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

315}
316
317func ExampleRuntime_ExportTo_iterableToSlice() {
318 vm := New()
319 v, err := vm.RunString(`
320 function reverseIterator() {
321 const arr = this;
322 let idx = arr.length;
323 return {
324 next: () => idx > 0 ? {value: arr[--idx]} : {done: true}
325 }
326 }
327 const arr = [1,2,3];
328 arr[Symbol.iterator] = reverseIterator;
329 arr;
330 `)
331 if err != nil {
332 panic(err)
333 }
334
335 var arr []int
336 err = vm.ExportTo(v, &arr)
337 if err != nil {
338 panic(err)
339 }
340
341 fmt.Println(arr)
342 // Output: [3 2 1]
343}
344
345func TestRuntime_ExportTo_proxiedIterableToSlice(t *testing.T) {
346 vm := New()

Callers

nothing calls this directly

Calls 3

NewFunction · 0.85
RunStringMethod · 0.80
ExportToMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…