Skip to content

Commit

Permalink
Treat numbers as strings when accessing properties
Browse files Browse the repository at this point in the history
With this change, numbers are now treated as strings when setting
properties of javascript objects. This aligns with how object properties
are accessed in javascript already:

```sh
$ node
Welcome to Node.js v18.7.0.
Type ".help" for more information.
> var o = {}
undefined
> o[111] = 222
222
> o["111"]
222
>
```

Before this, the following error would be thrown.

```
CL-USER> (jscl::oset 222 (jscl::new) 111)
ERROR: activechars.join is not a function
CL-USER>
```
  • Loading branch information
nagy committed Aug 22, 2022
1 parent ffccdb1 commit 5b0f2b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/prelude.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ internals.safe_char_downcase = function(x) {
};

internals.xstring = function(x){
if(typeof x === "number") return x.toString();
const hasFillPointer = typeof x.fillpointer === 'number'
const activechars = hasFillPointer? x.slice(0, x.fillpointer): x
return activechars.join('');
Expand Down
7 changes: 7 additions & 0 deletions tests/ffi.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,11 @@
(test (js-object-p obj))
(test (js-object-signature obj)))

;;; test in can handle numbers

(let ((obj (make-new #j:Object)))
(test (js-object-p obj))
(test (oset 456 obj 123))
(test (equal 456 (oget obj 123))))

;;; EOF

0 comments on commit 5b0f2b4

Please sign in to comment.