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

[ignition] Set correct expression position for ObjectLiteral keys/values

Given the following input,
  const config = {
    min: Math.min(1, 2),
    func: myfunc(),
  }

Previously, the error was,
  ➜ ./out.gn/x64.release/d8 _test.js
  _test.js:3: ReferenceError: myfunc is not defined
    min: Math.min(1, 2),
              ^
  ReferenceError: myfunc is not defined
      at _test.js:3:13

Now, the error is,
  ➜ ./out.gn/x64.release/d8 _test.js
  _test.js:4: ReferenceError: myfunc is not defined
    func: myfunc(),
          ^
  ReferenceError: myfunc is not defined
      at _test.js:4:9

Bug: v8:7507
Change-Id: Ia65b445fdbc1369ecce80f4fc2040e500c807d40
Reviewed-on: https://chromium-review.googlesource.com/964182Reviewed-by: 's avatarMathias Bynens <mathias@chromium.org>
Reviewed-by: 's avatarMythri Alle <mythria@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51964}
parent ef546d68
...@@ -2134,6 +2134,7 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { ...@@ -2134,6 +2134,7 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
if (key->IsStringLiteral()) { if (key->IsStringLiteral()) {
DCHECK(key->IsPropertyName()); DCHECK(key->IsPropertyName());
if (property->emit_store()) { if (property->emit_store()) {
builder()->SetExpressionPosition(property->value());
VisitForAccumulatorValue(property->value()); VisitForAccumulatorValue(property->value());
FeedbackSlot slot = feedback_spec()->AddStoreOwnICSlot(); FeedbackSlot slot = feedback_spec()->AddStoreOwnICSlot();
if (FunctionLiteral::NeedsHomeObject(property->value())) { if (FunctionLiteral::NeedsHomeObject(property->value())) {
...@@ -2148,13 +2149,16 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { ...@@ -2148,13 +2149,16 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
literal, key->AsRawPropertyName(), feedback_index(slot)); literal, key->AsRawPropertyName(), feedback_index(slot));
} }
} else { } else {
builder()->SetExpressionPosition(property->value());
VisitForEffect(property->value()); VisitForEffect(property->value());
} }
} else { } else {
RegisterList args = register_allocator()->NewRegisterList(4); RegisterList args = register_allocator()->NewRegisterList(4);
builder()->MoveRegister(literal, args[0]); builder()->MoveRegister(literal, args[0]);
builder()->SetExpressionPosition(property->key());
VisitForRegisterValue(property->key(), args[1]); VisitForRegisterValue(property->key(), args[1]);
builder()->SetExpressionPosition(property->value());
VisitForRegisterValue(property->value(), args[2]); VisitForRegisterValue(property->value(), args[2]);
if (property->emit_store()) { if (property->emit_store()) {
builder() builder()
...@@ -2174,6 +2178,7 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { ...@@ -2174,6 +2178,7 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
DCHECK(!property->NeedsSetFunctionName()); DCHECK(!property->NeedsSetFunctionName());
RegisterList args = register_allocator()->NewRegisterList(2); RegisterList args = register_allocator()->NewRegisterList(2);
builder()->MoveRegister(literal, args[0]); builder()->MoveRegister(literal, args[0]);
builder()->SetExpressionPosition(property->value());
VisitForRegisterValue(property->value(), args[1]); VisitForRegisterValue(property->value(), args[1]);
builder()->CallRuntime(Runtime::kInternalSetPrototype, args); builder()->CallRuntime(Runtime::kInternalSetPrototype, args);
break; break;
...@@ -2227,6 +2232,7 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { ...@@ -2227,6 +2232,7 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
DCHECK(!property->NeedsSetFunctionName()); DCHECK(!property->NeedsSetFunctionName());
RegisterList args = register_allocator()->NewRegisterList(2); RegisterList args = register_allocator()->NewRegisterList(2);
builder()->MoveRegister(literal, args[0]); builder()->MoveRegister(literal, args[0]);
builder()->SetExpressionPosition(property->value());
VisitForRegisterValue(property->value(), args[1]); VisitForRegisterValue(property->value(), args[1]);
builder()->CallRuntime(Runtime::kInternalSetPrototype, args); builder()->CallRuntime(Runtime::kInternalSetPrototype, args);
continue; continue;
...@@ -2238,6 +2244,7 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { ...@@ -2238,6 +2244,7 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
case ObjectLiteral::Property::MATERIALIZED_LITERAL: { case ObjectLiteral::Property::MATERIALIZED_LITERAL: {
Register key = register_allocator()->NewRegister(); Register key = register_allocator()->NewRegister();
BuildLoadPropertyKey(property, key); BuildLoadPropertyKey(property, key);
builder()->SetExpressionPosition(property->value());
Register value = VisitForRegisterValue(property->value()); Register value = VisitForRegisterValue(property->value());
VisitSetHomeObject(value, literal, property); VisitSetHomeObject(value, literal, property);
...@@ -2260,6 +2267,7 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { ...@@ -2260,6 +2267,7 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
RegisterList args = register_allocator()->NewRegisterList(4); RegisterList args = register_allocator()->NewRegisterList(4);
builder()->MoveRegister(literal, args[0]); builder()->MoveRegister(literal, args[0]);
BuildLoadPropertyKey(property, args[1]); BuildLoadPropertyKey(property, args[1]);
builder()->SetExpressionPosition(property->value());
VisitForRegisterValue(property->value(), args[2]); VisitForRegisterValue(property->value(), args[2]);
VisitSetHomeObject(args[2], literal, property); VisitSetHomeObject(args[2], literal, property);
builder() builder()
...@@ -2275,6 +2283,7 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { ...@@ -2275,6 +2283,7 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
case ObjectLiteral::Property::SPREAD: { case ObjectLiteral::Property::SPREAD: {
RegisterList args = register_allocator()->NewRegisterList(2); RegisterList args = register_allocator()->NewRegisterList(2);
builder()->MoveRegister(literal, args[0]); builder()->MoveRegister(literal, args[0]);
builder()->SetExpressionPosition(property->value());
VisitForRegisterValue(property->value(), args[1]); VisitForRegisterValue(property->value(), args[1]);
builder()->CallRuntime(Runtime::kCopyDataProperties, args); builder()->CallRuntime(Runtime::kCopyDataProperties, args);
break; break;
......
...@@ -98,7 +98,7 @@ bytecode array length: 17 ...@@ -98,7 +98,7 @@ bytecode array length: 17
bytecodes: [ bytecodes: [
/* 30 E> */ B(StackCheck), /* 30 E> */ B(StackCheck),
/* 34 S> */ B(CreateObjectLiteral), U8(0), U8(0), U8(41), R(0), /* 34 S> */ B(CreateObjectLiteral), U8(0), U8(0), U8(41), R(0),
B(CreateClosure), U8(1), U8(1), U8(2), /* 49 E> */ B(CreateClosure), U8(1), U8(1), U8(2),
B(StaNamedOwnProperty), R(0), U8(2), U8(2), B(StaNamedOwnProperty), R(0), U8(2), U8(2),
B(Ldar), R(0), B(Ldar), R(0),
/* 66 S> */ B(Return), /* 66 S> */ B(Return),
...@@ -121,7 +121,7 @@ bytecode array length: 17 ...@@ -121,7 +121,7 @@ bytecode array length: 17
bytecodes: [ bytecodes: [
/* 30 E> */ B(StackCheck), /* 30 E> */ B(StackCheck),
/* 34 S> */ B(CreateObjectLiteral), U8(0), U8(0), U8(41), R(0), /* 34 S> */ B(CreateObjectLiteral), U8(0), U8(0), U8(41), R(0),
B(CreateClosure), U8(1), U8(1), U8(2), /* 43 E> */ B(CreateClosure), U8(1), U8(1), U8(2),
B(StaNamedOwnProperty), R(0), U8(2), U8(2), B(StaNamedOwnProperty), R(0), U8(2), U8(2),
B(Ldar), R(0), B(Ldar), R(0),
/* 67 S> */ B(Return), /* 67 S> */ B(Return),
...@@ -289,7 +289,7 @@ bytecodes: [ ...@@ -289,7 +289,7 @@ bytecodes: [
/* 50 S> */ B(CreateObjectLiteral), U8(1), U8(0), U8(41), R(1), /* 50 S> */ B(CreateObjectLiteral), U8(1), U8(0), U8(41), R(1),
/* 60 E> */ B(ToName), R(2), /* 60 E> */ B(ToName), R(2),
B(LdaSmi), I8(1), B(LdaSmi), I8(1),
B(StaDataPropertyInLiteral), R(1), R(2), U8(0), U8(1), /* 64 E> */ B(StaDataPropertyInLiteral), R(1), R(2), U8(0), U8(1),
B(Ldar), R(1), B(Ldar), R(1),
/* 68 S> */ B(Return), /* 68 S> */ B(Return),
] ]
...@@ -316,7 +316,7 @@ bytecodes: [ ...@@ -316,7 +316,7 @@ bytecodes: [
B(Ldar), R(0), B(Ldar), R(0),
/* 68 E> */ B(ToName), R(2), /* 68 E> */ B(ToName), R(2),
B(LdaSmi), I8(1), B(LdaSmi), I8(1),
B(StaDataPropertyInLiteral), R(1), R(2), U8(0), U8(3), /* 72 E> */ B(StaDataPropertyInLiteral), R(1), R(2), U8(0), U8(3),
B(Ldar), R(1), B(Ldar), R(1),
/* 76 S> */ B(Return), /* 76 S> */ B(Return),
] ]
...@@ -342,8 +342,8 @@ bytecodes: [ ...@@ -342,8 +342,8 @@ bytecodes: [
/* 50 S> */ B(CreateObjectLiteral), U8(1), U8(0), U8(41), R(1), /* 50 S> */ B(CreateObjectLiteral), U8(1), U8(0), U8(41), R(1),
/* 60 E> */ B(ToName), R(2), /* 60 E> */ B(ToName), R(2),
B(LdaSmi), I8(1), B(LdaSmi), I8(1),
B(StaDataPropertyInLiteral), R(1), R(2), U8(0), U8(1), /* 64 E> */ B(StaDataPropertyInLiteral), R(1), R(2), U8(0), U8(1),
B(CreateEmptyObjectLiteral), /* 78 E> */ B(CreateEmptyObjectLiteral),
B(Star), R(3), B(Star), R(3),
B(Mov), R(1), R(2), B(Mov), R(1), R(2),
B(CallRuntime), U16(Runtime::kInternalSetPrototype), R(2), U8(2), B(CallRuntime), U16(Runtime::kInternalSetPrototype), R(2), U8(2),
...@@ -371,10 +371,10 @@ bytecodes: [ ...@@ -371,10 +371,10 @@ bytecodes: [
/* 50 S> */ B(CreateObjectLiteral), U8(1), U8(0), U8(41), R(1), /* 50 S> */ B(CreateObjectLiteral), U8(1), U8(0), U8(41), R(1),
/* 60 E> */ B(ToName), R(2), /* 60 E> */ B(ToName), R(2),
B(LdaConstant), U8(2), B(LdaConstant), U8(2),
B(StaDataPropertyInLiteral), R(1), R(2), U8(0), U8(1), /* 64 E> */ B(StaDataPropertyInLiteral), R(1), R(2), U8(0), U8(1),
B(LdaConstant), U8(3), B(LdaConstant), U8(3),
B(Star), R(3), B(Star), R(3),
B(CreateClosure), U8(4), U8(3), U8(2), /* 71 E> */ B(CreateClosure), U8(4), U8(3), U8(2),
B(Star), R(4), B(Star), R(4),
B(LdaZero), B(LdaZero),
B(Star), R(5), B(Star), R(5),
...@@ -382,7 +382,7 @@ bytecodes: [ ...@@ -382,7 +382,7 @@ bytecodes: [
B(CallRuntime), U16(Runtime::kDefineGetterPropertyUnchecked), R(2), U8(4), B(CallRuntime), U16(Runtime::kDefineGetterPropertyUnchecked), R(2), U8(4),
B(LdaConstant), U8(3), B(LdaConstant), U8(3),
B(Star), R(3), B(Star), R(3),
B(CreateClosure), U8(5), U8(4), U8(2), /* 84 E> */ B(CreateClosure), U8(5), U8(4), U8(2),
B(Star), R(4), B(Star), R(4),
B(LdaZero), B(LdaZero),
B(Star), R(5), B(Star), R(5),
......
...@@ -22,7 +22,7 @@ bytecodes: [ ...@@ -22,7 +22,7 @@ bytecodes: [
B(CallRuntime), U16(Runtime::kDeclareGlobalsForInterpreter), R(1), U8(3), B(CallRuntime), U16(Runtime::kDeclareGlobalsForInterpreter), R(1), U8(3),
/* 0 E> */ B(StackCheck), /* 0 E> */ B(StackCheck),
/* 8 S> */ B(CreateObjectLiteral), U8(1), U8(2), U8(41), R(1), /* 8 S> */ B(CreateObjectLiteral), U8(1), U8(2), U8(41), R(1),
B(CreateClosure), U8(2), U8(3), U8(0), /* 16 E> */ B(CreateClosure), U8(2), U8(3), U8(0),
B(StaNamedOwnProperty), R(1), U8(3), U8(4), B(StaNamedOwnProperty), R(1), U8(3), U8(4),
B(Ldar), R(1), B(Ldar), R(1),
/* 8 E> */ B(StaGlobal), U8(4), U8(6), /* 8 E> */ B(StaGlobal), U8(4), U8(6),
......
// Copyright 2018 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.
const config = {
min: Math.min(1, 2),
func: myfunc(),
}
*%(basename)s:8: ReferenceError: myfunc is not defined
func: myfunc(),
^
ReferenceError: myfunc is not defined
at *%(basename)s:8:9
\ 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