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

Function TestBridgeNilCallbackResultsNormalizeToUndefined

bridge_test.go:263–307  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

261}
262
263func TestBridgeNilCallbackResultsNormalizeToUndefined(t *testing.T) {
264 rt := NewRuntime()
265 defer rt.Close()
266 ctx := rt.NewContext()
267 defer ctx.Close()
268
269 ctx.Globals().Set("nilFn", ctx.NewFunction(func(ctx *Context, this *Value, args []*Value) *Value {
270 return nil
271 }))
272
273 fnType := ctx.Eval(`typeof nilFn()`)
274 defer fnType.Free()
275 require.False(t, fnType.IsException())
276 require.Equal(t, "undefined", fnType.ToString())
277
278 constructor, _ := NewClassBuilder("NilBridgeClass").
279 Constructor(func(ctx *Context, instance *Value, args []*Value) (interface{}, error) {
280 return map[string]int{"ok": 1}, nil
281 }).
282 Method("m", func(ctx *Context, this *Value, args []*Value) *Value {
283 return nil
284 }).
285 Accessor("a", func(ctx *Context, this *Value) *Value {
286 return nil
287 }, func(ctx *Context, this *Value, val *Value) *Value {
288 return nil
289 }).
290 Build(ctx)
291 require.False(t, constructor.IsException())
292
293 ctx.Globals().Set("NilBridgeClass", constructor)
294
295 result := ctx.Eval(`
296 (() => {
297 const o = new NilBridgeClass();
298 const m = o.m();
299 const g = o.a;
300 o.a = 123;
301 return [m === undefined, g === undefined].join(',');
302 })()
303 `)
304 defer result.Free()
305 require.False(t, result.IsException())
306 require.Equal(t, "true,true", result.ToString())
307}
308
309func TestBridgeModuleInitFailClosedInvalidExportAndBuilderHandle(t *testing.T) {
310 newModuleContext := func(t *testing.T) *Context {

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
NewContextMethod · 0.95
CloseMethod · 0.95
GlobalsMethod · 0.95
NewFunctionMethod · 0.95
EvalMethod · 0.95
NewRuntimeFunction · 0.85
NewClassBuilderFunction · 0.85
SetMethod · 0.80
IsExceptionMethod · 0.80
EqualMethod · 0.80
AccessorMethod · 0.80

Tested by

no test coverage detected