[parser] Better error msg for destructuring non iterable

This patch updates the error positition and the error msg.

Previously,

  → ./out.gn/x64.release/d8 test.js
  test.js:1: TypeError: undefined is not a function
  var [a] = {};
  ^
  TypeError: undefined is not a function
      at test.js:1:1


With this patch,

  → ./out.gn/x64.release/d8 test.js
  test.js:1: TypeError: [Symbol.iterator] is not a function
  var [a] = {};
            ^
  TypeError: [Symbol.iterator] is not a function
      at test.js:1:11

Bug: v8:5532
Change-Id: Ib066e8ec8a53fdf06cce491bde4b1d0c6d564cbc
Reviewed-on: https://chromium-review.googlesource.com/539024
Reviewed-by: Adam Klein <adamk@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46015}
This commit is contained in:
Sathya Gunasekaran 2017-06-16 16:50:04 -07:00 committed by Commit Bot
parent 0fed926bf4
commit ea241630ae
8 changed files with 36 additions and 3 deletions

View File

@ -3420,6 +3420,7 @@ void BytecodeGenerator::VisitImportCallExpression(ImportCallExpression* expr) {
}
void BytecodeGenerator::VisitGetIterator(GetIterator* expr) {
builder()->SetExpressionPosition(expr);
FeedbackSlot load_slot = expr->IteratorPropertyFeedbackSlot();
FeedbackSlot call_slot = expr->IteratorCallFeedbackSlot();

View File

@ -435,9 +435,9 @@ void Parser::PatternRewriter::VisitArrayLiteral(ArrayLiteral* node,
DCHECK(block_->ignore_completion_value());
auto temp = *temp_var = CreateTempVar(current_value_);
auto iterator = CreateTempVar(
factory()->NewGetIterator(factory()->NewVariableProxy(temp),
IteratorType::kNormal, kNoSourcePosition));
auto iterator = CreateTempVar(factory()->NewGetIterator(
factory()->NewVariableProxy(temp), IteratorType::kNormal,
current_value_->position()));
auto done =
CreateTempVar(factory()->NewBooleanLiteral(false, kNoSourcePosition));
auto result = CreateTempVar();

View File

@ -0,0 +1,5 @@
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var [a] = 1;

View File

@ -0,0 +1,5 @@
*%(basename)s:5: TypeError: [Symbol.iterator] is not a function
var [a] = 1;
^
TypeError: [Symbol.iterator] is not a function
at *%(basename)s:5:11

View File

@ -0,0 +1,6 @@
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var x = {};
var [a] = x;

View File

@ -0,0 +1,5 @@
*%(basename)s:6: TypeError: [Symbol.iterator] is not a function
var [a] = x;
^
TypeError: [Symbol.iterator] is not a function
at *%(basename)s:6:11

View File

@ -0,0 +1,6 @@
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Array.prototype[Symbol.iterator] = function() { return 1; }
var [a] = [1];

View File

@ -0,0 +1,5 @@
*%(basename)s:6: TypeError: Result of the Symbol.iterator method is not an object
var [a] = [1];
^
TypeError: Result of the Symbol.iterator method is not an object
at *%(basename)s:6:11