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

Function TestDynamicObjectCustomProto

object_dynamic_test.go:139–165  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

137}
138
139func TestDynamicObjectCustomProto(t *testing.T) {
140 vm := New()
141 m := make(map[string]Value)
142 dynObj := &testDynObject{
143 r: vm,
144 m: m,
145 }
146 o := vm.NewDynamicObject(dynObj)
147 vm.Set("o", o)
148 vm.testScriptWithTestLib(`
149 var proto = {
150 valueOf: function() {
151 return this.num;
152 }
153 };
154 proto[Symbol.toStringTag] = "GoObject";
155 Object.setPrototypeOf(o, proto);
156 o.num = 41;
157 assert(o instanceof Object, "instanceof");
158 assert.sameValue(o+1, 42);
159 assert.sameValue(o.toString(), "[object GoObject]");
160 `, _undefined, t)
161
162 if v := m["num"]; v.Export() != int64(41) {
163 t.Fatal(v)
164 }
165}
166
167func TestDynamicArray(t *testing.T) {
168 vm := New()

Callers

nothing calls this directly

Calls 5

NewFunction · 0.85
NewDynamicObjectMethod · 0.80
testScriptWithTestLibMethod · 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…