PetterS / quickjs

Thin Python wrapper of https://bellard.org/quickjs/
https://github.com/bellard/QuickJS
MIT License
177 stars 19 forks source link

Implement context_set and add unit test for it. #55

Closed qwenger closed 3 years ago

qwenger commented 3 years ago

Proposal for https://github.com/PetterS/quickjs/issues/54.

Note that the same caveat applies as in https://github.com/PetterS/quickjs/issues/38: dicts and lists cannot be passed directly to set:

# does not work
ctx.set("a", [1, 2])
# works
ctx.set("a", ctx.parse_json(json.dumps([1, 2])))

Which is not like Function.__call__.

qwenger commented 3 years ago

@PetterS ready for review.

PetterS commented 3 years ago

I have now configured CI to build from forks.

Can you push an empty commit? git commit -m Empty --allow-empty

PetterS commented 3 years ago

Thank you!

qwenger commented 3 years ago

@PetterS just realizing that I did not implement error checking on JS_SetPropertyStr (as in https://github.com/PetterS/quickjs/blob/master/module.c#L618, for example).

Any risk that it ever fails?

PetterS commented 3 years ago

It may actually fail for weird strings like the empty string. Also if memory allocation fails. So it may actually be best to add a check for this.

EDIT: strikethrough after testing.

qwenger commented 3 years ago

Weird attributes names should be fine, just like you can do

obj["some weird name"] = value;

I started #56 .