Commit ea241630 authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

[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/539024Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46015}
parent 0fed926b
...@@ -3420,6 +3420,7 @@ void BytecodeGenerator::VisitImportCallExpression(ImportCallExpression* expr) { ...@@ -3420,6 +3420,7 @@ void BytecodeGenerator::VisitImportCallExpression(ImportCallExpression* expr) {
} }
void BytecodeGenerator::VisitGetIterator(GetIterator* expr) { void BytecodeGenerator::VisitGetIterator(GetIterator* expr) {
builder()->SetExpressionPosition(expr);
FeedbackSlot load_slot = expr->IteratorPropertyFeedbackSlot(); FeedbackSlot load_slot = expr->IteratorPropertyFeedbackSlot();
FeedbackSlot call_slot = expr->IteratorCallFeedbackSlot(); FeedbackSlot call_slot = expr->IteratorCallFeedbackSlot();
......
...@@ -435,9 +435,9 @@ void Parser::PatternRewriter::VisitArrayLiteral(ArrayLiteral* node, ...@@ -435,9 +435,9 @@ void Parser::PatternRewriter::VisitArrayLiteral(ArrayLiteral* node,
DCHECK(block_->ignore_completion_value()); DCHECK(block_->ignore_completion_value());
auto temp = *temp_var = CreateTempVar(current_value_); auto temp = *temp_var = CreateTempVar(current_value_);
auto iterator = CreateTempVar( auto iterator = CreateTempVar(factory()->NewGetIterator(
factory()->NewGetIterator(factory()->NewVariableProxy(temp), factory()->NewVariableProxy(temp), IteratorType::kNormal,
IteratorType::kNormal, kNoSourcePosition)); current_value_->position()));
auto done = auto done =
CreateTempVar(factory()->NewBooleanLiteral(false, kNoSourcePosition)); CreateTempVar(factory()->NewBooleanLiteral(false, kNoSourcePosition));
auto result = CreateTempVar(); auto result = CreateTempVar();
......
// 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;
*%(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
// 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;
*%(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
// 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];
*%(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
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment