Skip to content

Commit 073972b

Browse files
Merge branch 'caleb/fix/this' into philippe/pyTypeFactory-cleanup
2 parents e08a1e7 + 55265ae commit 073972b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

python/pythonmonkey/builtin_modules/util.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,9 @@ function formatValue(ctx, value, recurseTimes, ln) {
532532
base = ` ${dateToISOString.call(value)}`;
533533
} else if (isError(value)) {
534534
// Make error with message first say the error
535-
if (keyLength === 0)
535+
if (keyLength === 0 || keys.every(k => k === 'stack')) // There's only a 'stack' property
536536
return formatError(ctx, value);
537+
keys = keys.filter(k => k !== 'stack'); // When changing the 'stack' property in SpiderMonkey, it becomes enumerable.
537538
base = ` ${formatError(ctx, value)}\n`;
538539
braces.length=0;
539540
} else if (isAnyArrayBuffer(value)) {

tests/js/util-module.simple

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @file util-module.simple
3+
* Simple test for the builtin util module
4+
* @author Tom Tang <[email protected]>
5+
* @date March 2024
6+
*/
7+
8+
const util = require('util');
9+
10+
// https://github.com/Distributive-Network/PythonMonkey/pull/300
11+
const err = new TypeError();
12+
if (err.propertyIsEnumerable('stack'))
13+
throw new Error('The stack property should not be enumerable.');
14+
err.anything = 123;
15+
err.stack = 'abc';
16+
if (!err.propertyIsEnumerable('stack'))
17+
throw new Error('In SpiderMonkey, the stack property should be enumerable after changing it.');
18+
const output = util.format(err);
19+
if (output.match(/abc/g).length !== 1) // should only be printed once
20+
throw new Error('The stack property should not be printed along with other enumerable properties');

0 commit comments

Comments
 (0)