When there is no explicit return we need to generate an implicit
return undefined.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/
1308693014
Cr-Commit-Position: refs/heads/master@{#30639}
int BytecodeArrayBuilder::parameter_count() const { return parameter_count_; }
+bool BytecodeArrayBuilder::HasExplicitReturn() {
+ // TODO(rmcilroy): When we have control flow we should return false here if
+ // there is an outstanding jump target, even if the last bytecode is kReturn.
+ 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_);
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.
// 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();
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},