Reviewers: oth, Michael Starzinger,
Message:
Orion, please have a look, thanks.
Michi for owner stamp (comments welcome)
Description:
[Interpreter] Ensure that implicit return undefined is generated.
When there is no explicit return we need to generate an implicit
return undefined.
BUG=v8:4280
LOG=N
Please review this at https://codereview.chromium.org/1308693014/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+17, -0 lines):
M src/interpreter/bytecode-array-builder.h
M src/interpreter/bytecode-array-builder.cc
M src/interpreter/bytecode-generator.cc
M test/cctest/interpreter/test-bytecode-generator.cc
Index: src/interpreter/bytecode-array-builder.cc
diff --git a/src/interpreter/bytecode-array-builder.cc
b/src/interpreter/bytecode-array-builder.cc
index
dba816d61810d63259412f946f219494c2e134ef..5f97bce75b2f34184e3cd99753aebe084317169a
100644
--- a/src/interpreter/bytecode-array-builder.cc
+++ b/src/interpreter/bytecode-array-builder.cc
@@ -37,6 +37,12 @@ void BytecodeArrayBuilder::set_parameter_count(int
number_of_parameters) {
int BytecodeArrayBuilder::parameter_count() const { return
parameter_count_; }
+bool BytecodeArrayBuilder::HasExplicitReturn() {
+ return !bytecodes_.empty() &&
+ bytecodes_.back() == Bytecodes::ToByte(Bytecode::kReturn);
+}
+
+
Register BytecodeArrayBuilder::Parameter(int parameter_index) {
DCHECK_GE(parameter_index, 0);
DCHECK_LT(parameter_index, parameter_count_);
Index: src/interpreter/bytecode-array-builder.h
diff --git a/src/interpreter/bytecode-array-builder.h
b/src/interpreter/bytecode-array-builder.h
index
d4e1c34e540a2d67a22c19d61c7372c78dbf6cfb..a50c28b0ebe875252ea8ff68e34c0fdf58c1e67f
100644
--- a/src/interpreter/bytecode-array-builder.h
+++ b/src/interpreter/bytecode-array-builder.h
@@ -35,6 +35,9 @@ class BytecodeArrayBuilder {
void set_locals_count(int number_of_locals);
int locals_count() const;
+ // Returns true if the bytecode has an explicit return at the end.
+ bool HasExplicitReturn();
+
Register Parameter(int parameter_index);
// Constant loads to accumulator.
Index: src/interpreter/bytecode-generator.cc
diff --git a/src/interpreter/bytecode-generator.cc
b/src/interpreter/bytecode-generator.cc
index
487b86543794b9effc862db130ea37a2e0e36ca7..0f24995c92a9b150b38f002a73ea5d70ff61a360
100644
--- a/src/interpreter/bytecode-generator.cc
+++ b/src/interpreter/bytecode-generator.cc
@@ -45,6 +45,13 @@ Handle<BytecodeArray>
BytecodeGenerator::MakeBytecode(CompilationInfo* info) {
// Visit statements in the function body.
VisitStatements(info->literal()->body());
+ // If the last bytecode wasn't a return, then return 'undefined' to avoid
+ // falling off the end.
+ if (!builder_.HasExplicitReturn()) {
+ builder_.LoadUndefined();
+ builder_.Return();
+ }
+
set_scope(nullptr);
set_info(nullptr);
return builder_.ToBytecodeArray();
Index: test/cctest/interpreter/test-bytecode-generator.cc
diff --git a/test/cctest/interpreter/test-bytecode-generator.cc
b/test/cctest/interpreter/test-bytecode-generator.cc
index
c62e5efff9f2a93756f4022d64469b85d4f1f252..25a71488936bab3c9ecb5f1454990395a02bbd7c
100644
--- a/test/cctest/interpreter/test-bytecode-generator.cc
+++ b/test/cctest/interpreter/test-bytecode-generator.cc
@@ -79,6 +79,7 @@ TEST(PrimitiveReturnStatements) {
BytecodeGeneratorHelper helper;
ExpectedSnippet<void*> snippets[] = {
+ {"", 0, 1, 2, {B(LdaUndefined), B(Return)}, 0},
{"return;", 0, 1, 2, {B(LdaUndefined), B(Return)}, 0},
{"return null;", 0, 1, 2, {B(LdaNull), B(Return)}, 0},
{"return true;", 0, 1, 2, {B(LdaTrue), B(Return)}, 0},
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.