MCPcopy Create free account
hub / github.com/buke/quickjs-go / TestRuntimeOwnerCheckGatesRuntimeContextAndValuePaths

Function TestRuntimeOwnerCheckGatesRuntimeContextAndValuePaths

runtime_test.go:1685–1880  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1683}
1684
1685func TestRuntimeOwnerCheckGatesRuntimeContextAndValuePaths(t *testing.T) {
1686 oldGIDHook := ownerCheckCurrentGoroutineID
1687 oldThreadHook := ownerCheckCurrentThreadID
1688 defer func() {
1689 ownerCheckCurrentGoroutineID = oldGIDHook
1690 ownerCheckCurrentThreadID = oldThreadHook
1691 }()
1692
1693 var gid atomic.Uint64
1694 gid.Store(21)
1695 ownerCheckCurrentGoroutineID = func() uint64 { return gid.Load() }
1696 ownerCheckCurrentThreadID = func() uint64 { return 1 }
1697
1698 rt := NewRuntime()
1699 require.NotNil(t, rt)
1700 ctx := rt.NewContext()
1701 require.NotNil(t, ctx)
1702 defer ctx.Close()
1703 defer rt.Close()
1704
1705 obj := ctx.Eval(`({ x: 1, inc: function(){ return this.x + 1; } })`)
1706 require.NotNil(t, obj)
1707 require.False(t, obj.IsException())
1708 defer obj.Free()
1709
1710 throwVal := ctx.ThrowError(errors.New("owner-check-path"))
1711 require.NotNil(t, throwVal)
1712 require.True(t, throwVal.IsException())
1713 throwVal.Free()
1714
1715 incFn := obj.Get("inc")
1716 require.NotNil(t, incFn)
1717 defer incFn.Free()
1718
1719 ctor := ctx.Eval(`(function C(){ this.v = 1; })`)
1720 require.NotNil(t, ctor)
1721 require.False(t, ctor.IsException())
1722 defer ctor.Free()
1723
1724 val := ctx.NewInt32(9)
1725 require.NotNil(t, val)
1726 defer val.Free()
1727 val1 := ctx.NewInt32(1)
1728 defer val1.Free()
1729 val2 := ctx.NewInt32(2)
1730 defer val2.Free()
1731
1732 adderObj := ctx.Eval(`({ add: function(a, b){ return a + b; } })`)
1733 require.NotNil(t, adderObj)
1734 require.False(t, adderObj.IsException())
1735 defer adderObj.Free()
1736
1737 adderFn := ctx.Eval(`(function(a, b){ return a + b; })`)
1738 require.NotNil(t, adderFn)
1739 require.False(t, adderFn.IsException())
1740 defer adderFn.Free()
1741 thisVal := ctx.NewUndefined()
1742 defer thisVal.Free()

Callers

nothing calls this directly

Calls 15

NewContextMethod · 0.95
CloseMethod · 0.95
CloseMethod · 0.95
EvalMethod · 0.95
ThrowErrorMethod · 0.95
NewInt32Method · 0.95
NewUndefinedMethod · 0.95
RunGCMethod · 0.95
SetMemoryLimitMethod · 0.95
SetGCThresholdMethod · 0.95
SetMaxStackSizeMethod · 0.95
SetCanBlockMethod · 0.95

Tested by

no test coverage detected