Skip to content

Commit 38e94ed

Browse files
added toString support
1 parent bf24651 commit 38e94ed

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/PyBytesProxyHandler.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ static bool bytes_valueOf(JSContext *cx, unsigned argc, JS::Value *vp) {
5050
return true;
5151
}
5252

53+
static bool bytes_toString(JSContext *cx, unsigned argc, JS::Value *vp) {
54+
return bytes_valueOf(cx, argc, vp);
55+
}
56+
5357
JSMethodDef PyBytesProxyHandler::bytes_methods[] = {
58+
{"toString", bytes_toString, 0},
5459
{"valueOf", bytes_valueOf, 0},
5560
{NULL, NULL, 0}
5661
};

src/PyObjectProxyHandler.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ bool PyObjectProxyHandler::handleOwnPropertyKeys(JSContext *cx, PyObject *keys,
7272
return true;
7373
}
7474

75+
// TODO need to let subclasses call superclass methods
7576
bool PyObjectProxyHandler::handleGetOwnPropertyDescriptor(JSContext *cx, JS::HandleId id,
7677
JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc, PyObject *item) {
7778
// see if we're calling a function

tests/python/test_buffer_typed_array.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,20 @@ def test_bytes_byteoffset():
246246

247247
def test_bytes_instanceof():
248248
result = [None]
249-
pm.eval("(result, obj) => {result[0] = obj instanceof Uint8Array}")(result, bytes("hello world", "ascii"))
249+
pm.eval("(result, bytes) => {result[0] = bytes instanceof Uint8Array}")(result, bytes("hello world", "ascii"))
250250
assert result[0]
251251

252252

253+
def test_bytes_valueOf():
254+
a = pm.eval('(bytes) => bytes.valueOf()')(bytes("hello world", "ascii"))
255+
assert a == "h,e,l,l,o, ,w,o,r,l,d"
256+
257+
258+
def test_bytes_toString():
259+
a = pm.eval('(bytes) => bytes.toString()')(bytes("hello world", "ascii"))
260+
assert a == "h,e,l,l,o, ,w,o,r,l,d"
261+
262+
253263
def test_bytes_console():
254264
temp_out = StringIO()
255265
sys.stdout = temp_out

0 commit comments

Comments
 (0)