• Sathya Gunasekaran's avatar
    [parser] Better error message when destructuring against undefined/null · bc2c785c
    Sathya Gunasekaran authored
    Previously, when destructuring against null or undefined we would
    print:
    
      d8> var { x } = null
      (d8):1: TypeError: Cannot match against 'undefined' or 'null'.
      var { x } = null
      ^
      TypeError: Cannot match against 'undefined' or 'null'.
          at (d8):1:1
    
    
    The above message uses the term "match" which isn't a common term in
    JavaScript to describe destructuring. This message also doesn't
    provide the name of the property that fails destructuring.
    
    This patch changes the error message to be:
    
      d8> var { x } = null;
      (d8):1: TypeError: Cannot destructure property `x` of 'undefined' or 'null'.
      var { x } = null;
            ^
      TypeError: Cannot destructure property `x` of 'undefined' or 'null'.
          at (d8):1:1
    
    This patch changes the message to say "destructure" instead of "match".
    
    This patch adds support for printing property names that are string
    literals. We iterate through every property and pick the first string
    literal property name if it exists. This provides at least some
    feedback to the developer.
    
    This patch also makes the pointer point to the position of the
    property name that fails destructuring.
    
    For computed and numeric property names, we print a generic error:
      d8> var { 1: x } = null
      (d8):1: TypeError: Cannot destructure against 'undefined' or 'null'.
      var { 1: x } = null
      ^
      TypeError: Cannot destructure against 'undefined' or 'null'.
          at (d8):1:1
    
    Bug: v8:6499
    Change-Id: I35b1ac749489828686f042975294b9926e2dfc53
    Reviewed-on: https://chromium-review.googlesource.com/537341Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
    Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#45965}
    bc2c785c
Name
Last commit
Last update
benchmarks Loading commit data...
build_overrides Loading commit data...
docs Loading commit data...
gni Loading commit data...
gypfiles Loading commit data...
include Loading commit data...
infra Loading commit data...
samples Loading commit data...
src Loading commit data...
test Loading commit data...
testing Loading commit data...
third_party Loading commit data...
tools Loading commit data...
.clang-format Loading commit data...
.gitignore Loading commit data...
.gn Loading commit data...
.ycm_extra_conf.py Loading commit data...
AUTHORS Loading commit data...
BUILD.gn Loading commit data...
CODE_OF_CONDUCT.md Loading commit data...
ChangeLog Loading commit data...
DEPS Loading commit data...
LICENSE Loading commit data...
LICENSE.fdlibm Loading commit data...
LICENSE.strongtalk Loading commit data...
LICENSE.v8 Loading commit data...
LICENSE.valgrind Loading commit data...
Makefile Loading commit data...
Makefile.android Loading commit data...
OWNERS Loading commit data...
PRESUBMIT.py Loading commit data...
README.md Loading commit data...
WATCHLISTS Loading commit data...
codereview.settings Loading commit data...
snapshot_toolchain.gni Loading commit data...