Skip to content

Commit 55265ae

Browse files
Merge branch 'main' into caleb/fix/this
2 parents f44db82 + b56503c commit 55265ae

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
@@ -533,8 +533,9 @@ function formatValue(ctx, value, recurseTimes, ln) {
533533
base = ` ${dateToISOString.call(value)}`;
534534
} else if (isError(value)) {
535535
// Make error with message first say the error
536-
if (keyLength === 0)
536+
if (keyLength === 0 || keys.every(k => k === 'stack')) // There's only a 'stack' property
537537
return formatError(ctx, value);
538+
keys = keys.filter(k => k !== 'stack'); // When changing the 'stack' property in SpiderMonkey, it becomes enumerable.
538539
base = ` ${formatError(ctx, value)}\n`;
539540
braces.length=0;
540541
} 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)