Skip to content

Commit cef3963

Browse files
improve valueOf to print bytes instead their equivalent chars
1 parent 02e8566 commit cef3963

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/PyBytesProxyHandler.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ static bool array_valueOf(JSContext *cx, unsigned argc, JS::Value *vp) {
4343
if (index > 0) {
4444
valueOfString += ",";
4545
}
46-
valueOfString += data[index];
46+
47+
valueOfString += std::to_string(data[index]);
4748
}
4849

4950
args.rval().setString(JS_NewStringCopyZ(cx, valueOfString.c_str()));

tests/python/test_buffer_typed_array.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,19 +259,19 @@ def test_constructor_creates_typedarray():
259259

260260
def test_bytes_valueOf():
261261
a = pm.eval('(bytes) => bytes.valueOf()')(bytes("hello world", "ascii"))
262-
assert a == "h,e,l,l,o, ,w,o,r,l,d"
262+
assert a == "104,101,108,108,111,32,119,111,114,108,100"
263263

264264

265265
def test_bytes_toString():
266266
a = pm.eval('(bytes) => bytes.toString()')(bytes("hello world", "ascii"))
267-
assert a == "h,e,l,l,o, ,w,o,r,l,d"
267+
assert a == "104,101,108,108,111,32,119,111,114,108,100"
268268

269269

270270
def test_bytes_console():
271271
temp_out = StringIO()
272272
sys.stdout = temp_out
273273
pm.eval('console.log')(bytes("hello world", "ascii"))
274-
assert temp_out.getvalue().startswith("{ [String: 'h,e,l,l,o, ,w,o,r,l,d']")
274+
assert temp_out.getvalue().startswith("\x1b[32m[String: '104,101,108,108,111,32,119,111,114,108,100'")
275275

276276

277277
# iterator symbol property

0 commit comments

Comments
 (0)