Skip to content

Commit

Permalink
Merge pull request #1 from JamesHutchison/None_null_fix
Browse files Browse the repository at this point in the history
Fixes JSObject(null)
  • Loading branch information
PierreQuentel committed Sep 18, 2014
2 parents a7473b9 + 5d9b8bf commit 02f1c1c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions site/tests/test_null.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from javascript import JSObject

assert(JSObject(null) == None)
assert(JSObject(null) is None)
assert(None is None)
assert(None is JSObject(null))
assert(None == JSObject(null))
assert(JSObject(null) is JSObject(null))

print("All tests passed")
2 changes: 1 addition & 1 deletion src/js_objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ function JSObject(obj){
// If obj is a function, calling it with JSObject implies that it is
// a function defined in Javascript. It must be wrapped in a JSObject
// so that when called, the arguments are transformed into JS values
if (obj === null) {return _b_.None}
if(typeof obj=='function'){return {__class__:$JSObjectDict,js:obj}}

var klass = $B.get_class(obj)
if(klass===_b_.list.$dict){
// JS arrays not created by list() must be wrapped
Expand Down
2 changes: 1 addition & 1 deletion src/py_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ $B.get_class = function(obj){
// generally we get the attribute __class__ of an object by obj.__class__
// but Javascript builtins used by Brython (functions, numbers, strings...)
// don't have this attribute so we must return it
if(obj==null){obj=_b_.None}
if(obj===null){return $B.$NoneDict}
var klass = obj.__class__
if(klass===undefined){
switch(typeof obj) {
Expand Down

0 comments on commit 02f1c1c

Please sign in to comment.