Proxy compatibility for Chrome

This commit is contained in:
Michael Droettboom 2018-07-09 17:15:10 -04:00
parent 670473f29b
commit aa03438131
2 changed files with 9 additions and 5 deletions

View File

@ -142,6 +142,12 @@ EM_JS(int, pyproxy_init, (), {
isPyProxy: function(jsobj) { isPyProxy: function(jsobj) {
return jsobj['$$'] !== undefined && jsobj['$$']['type'] === 'PyProxy'; return jsobj['$$'] !== undefined && jsobj['$$']['type'] === 'PyProxy';
}, },
addExtraKeys: function(result) {
result.push('toString');
result.push('prototype');
result.push('arguments');
result.push('caller');
},
isExtensible: function() { return true }, isExtensible: function() { return true },
has: function (jsobj, jskey) { has: function (jsobj, jskey) {
ptrobj = this.getPtr(jsobj); ptrobj = this.getPtr(jsobj);
@ -197,8 +203,7 @@ EM_JS(int, pyproxy_init, (), {
var idresult = __pyproxy_ownKeys(ptrobj); var idresult = __pyproxy_ownKeys(ptrobj);
var jsresult = Module.hiwire_get_value(idresult); var jsresult = Module.hiwire_get_value(idresult);
Module.hiwire_decref(idresult); Module.hiwire_decref(idresult);
jsresult.push('toString'); this.addExtraKeys(jsresult);
jsresult.push('prototype');
return jsresult; return jsresult;
}, },
enumerate: function (jsobj) { enumerate: function (jsobj) {
@ -206,8 +211,7 @@ EM_JS(int, pyproxy_init, (), {
var idresult = __pyproxy_enumerate(ptrobj); var idresult = __pyproxy_enumerate(ptrobj);
var jsresult = Module.hiwire_get_value(idresult); var jsresult = Module.hiwire_get_value(idresult);
Module.hiwire_decref(idresult); Module.hiwire_decref(idresult);
jsresult.push('toString'); this.addExtraKeys(jsresult);
jsresult.push('prototype');
return jsresult; return jsresult;
}, },
apply: function (jsobj, jsthis, jsargs) { apply: function (jsobj, jsthis, jsargs) {

View File

@ -125,7 +125,7 @@ def test_pyproxy(selenium):
'__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__',
'__str__', '__subclasshook__', '__weakref__', 'bar', 'baz', '__str__', '__subclasshook__', '__weakref__', 'bar', 'baz',
'get_value', 'toString', 'prototype']) 'get_value', 'toString', 'prototype', 'arguments', 'caller'])
assert selenium.run("hasattr(f, 'baz')") assert selenium.run("hasattr(f, 'baz')")
selenium.run_js("delete pyodide.pyimport('f').baz") selenium.run_js("delete pyodide.pyimport('f').baz")
assert not selenium.run("hasattr(f, 'baz')") assert not selenium.run("hasattr(f, 'baz')")