fix(inspector): Deno.inspect should inspect the object the proxy represents rather than the target of the proxy (#10977)

This commit is contained in:
David Sherret 2021-06-15 15:33:13 -04:00 committed by GitHub
parent 0c0058f118
commit 984b8bf0c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 6 deletions

View file

@ -1737,16 +1737,40 @@ unitTest(function inspectIterableLimit(): void {
unitTest(function inspectProxy(): void {
assertEquals(
stripColor(Deno.inspect(
new Proxy([1, 2, 3], { get(): void {} }),
new Proxy([1, 2, 3], {}),
)),
"[ 1, 2, 3 ]",
);
assertEquals(
stripColor(Deno.inspect(
new Proxy({ key: "value" }, { get(): void {} }),
new Proxy({ key: "value" }, {}),
)),
`{ key: "value" }`,
);
assertEquals(
stripColor(Deno.inspect(
new Proxy({}, {
get(_target, key) {
if (key === Symbol.toStringTag) {
return "MyProxy";
} else {
return 5;
}
},
getOwnPropertyDescriptor() {
return {
enumerable: true,
configurable: true,
value: 5,
};
},
ownKeys() {
return ["prop1", "prop2"];
},
}),
)),
`MyProxy { prop1: 5, prop2: 5 }`,
);
assertEquals(
stripColor(Deno.inspect(
new Proxy([1, 2, 3], { get(): void {} }),