()
| 2250 | } |
| 2251 | |
| 2252 | func ExampleObject_SetSymbol() { |
| 2253 | type IterResult struct { |
| 2254 | Done bool |
| 2255 | Value Value |
| 2256 | } |
| 2257 | |
| 2258 | vm := New() |
| 2259 | vm.SetFieldNameMapper(UncapFieldNameMapper()) // to use IterResult |
| 2260 | |
| 2261 | o := vm.NewObject() |
| 2262 | o.SetSymbol(SymIterator, func() *Object { |
| 2263 | count := 0 |
| 2264 | iter := vm.NewObject() |
| 2265 | iter.Set("next", func() IterResult { |
| 2266 | if count < 10 { |
| 2267 | count++ |
| 2268 | return IterResult{ |
| 2269 | Value: vm.ToValue(count), |
| 2270 | } |
| 2271 | } |
| 2272 | return IterResult{ |
| 2273 | Done: true, |
| 2274 | } |
| 2275 | }) |
| 2276 | return iter |
| 2277 | }) |
| 2278 | vm.Set("o", o) |
| 2279 | |
| 2280 | res, err := vm.RunString(` |
| 2281 | var acc = ""; |
| 2282 | for (var v of o) { |
| 2283 | acc += v + " "; |
| 2284 | } |
| 2285 | acc; |
| 2286 | `) |
| 2287 | if err != nil { |
| 2288 | panic(err) |
| 2289 | } |
| 2290 | fmt.Println(res) |
| 2291 | // Output: 1 2 3 4 5 6 7 8 9 10 |
| 2292 | } |
| 2293 | |
| 2294 | func ExampleRuntime_NewArray() { |
| 2295 | vm := New() |
nothing calls this directly
no test coverage detected
searching dependent graphs…