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

Function TestDynamicObject

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

Source from the content-addressed store, hash-verified

99}
100
101func TestDynamicObject(t *testing.T) {
102 vm := New()
103 dynObj := &testDynObject{
104 r: vm,
105 m: make(map[string]Value),
106 }
107 o := vm.NewDynamicObject(dynObj)
108 vm.Set("o", o)
109 vm.testScriptWithTestLibX(`
110 assert(o instanceof Object, "instanceof Object");
111 assert(o === o, "self equality");
112 assert(o !== {}, "non-equality");
113
114 o.test = 42;
115 assert("test" in o, "'test' in o");
116 assert(deepEqual(Object.getOwnPropertyDescriptor(o, "test"), {value: 42, writable: true, enumerable: true, configurable: true}), "prop desc");
117
118 assert.throws(TypeError, function() {
119 "use strict";
120 Object.defineProperty(o, "test1", {value: 0, writable: false, enumerable: false, configurable: true});
121 }, "define prop");
122
123 var keys = [];
124 for (var key in o) {
125 keys.push(key);
126 }
127 assert(compareArray(keys, ["test"]), "for-in");
128
129 assert(delete o.test, "delete");
130 assert(!("test" in o), "'test' in o after delete");
131
132 assert("__proto__" in o, "__proto__ in o");
133 assert.sameValue(o.__proto__, Object.prototype, "__proto__");
134 o.__proto__ = null;
135 assert(!("__proto__" in o), "__proto__ in o after setting to null");
136 `, _undefined, t)
137}
138
139func TestDynamicObjectCustomProto(t *testing.T) {
140 vm := New()

Callers

nothing calls this directly

Calls 4

NewFunction · 0.85
NewDynamicObjectMethod · 0.80
SetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…