[quickjs-devel] Re: Patch: Better error message when reading/setting properties in undefined/null

  • From: Simon CORSIN <simon@xxxxxxxxx>
  • To: quickjs-devel@xxxxxxxxxxxxx
  • Date: Fri, 1 May 2020 10:01:53 -0400

Note that this patch doesn't solve all cases, for example when calling a
function on undefined like `object.message()`, if message was undefined it
will still say "not a function".
Ideally it'd say at least something like "'message' is not a function". The
change to do this might be a little bit more complicated.

On Fri, May 1, 2020 at 5:21 AM 小冶 <fatfatson@xxxxxxxxx> wrote:

I found the same problem and made a similar fix as you,
but it's only available for property accessing,
still lacking name info for null method invoking😇



Simon CORSIN <simon@xxxxxxxxx> 于2020年5月1日周五 上午2:18写道:

Hey folks,

QuickJS currently doesn't provide context whenever a type error occurs on
set/get properties on undefined values. This makes it hard to even know
what part of an expression is failing. This patch changes the error message
to show the property being set/read.
For example:

```
const obj = undefined;
obj.hello; // Will now show 'Cannot read property 'hello' of undefined'
obj.hello = 42; // Will now show 'Cannot set property 'hello' of
undefined'
```

Additionally, quickls-libc.c didn't compile for me (macOS 10.14) since
the "environ" symbol doesn't seem to exist on my system. I added a
workaround to use _NSGetEnviron() instead.

Cheers,
Simon


Other related posts: