[Interpreter] Adds support for throw to bytecode graph builder.
Adds support and tests for throw to bytecode graph builder. BUG=v8:4280 LOG=N Review URL: https://codereview.chromium.org/1481763002 Cr-Commit-Position: refs/heads/master@{#32399}
This commit is contained in:
parent
0c7bc1cd5f
commit
c11e7bc219
@ -809,7 +809,13 @@ void BytecodeGraphBuilder::VisitNew(
|
||||
|
||||
void BytecodeGraphBuilder::VisitThrow(
|
||||
const interpreter::BytecodeArrayIterator& iterator) {
|
||||
UNIMPLEMENTED();
|
||||
Node* value = environment()->LookupAccumulator();
|
||||
// TODO(mythria): Change to Runtime::kThrow when we have deoptimization
|
||||
// information support in the interpreter.
|
||||
NewNode(javascript()->CallRuntime(Runtime::kReThrow, 1), value);
|
||||
Node* control = NewNode(common()->Throw(), value);
|
||||
UpdateControlDependencyToLeaveFunction(control);
|
||||
environment()->BindAccumulator(value);
|
||||
}
|
||||
|
||||
|
||||
|
@ -88,6 +88,18 @@ class BytecodeGraphTester {
|
||||
return BytecodeGraphCallable<A...>(isolate_, GetFunction());
|
||||
}
|
||||
|
||||
Local<Message> CheckThrowsReturnMessage() {
|
||||
TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate_));
|
||||
auto callable = GetCallable<>();
|
||||
MaybeHandle<Object> no_result = callable();
|
||||
CHECK(isolate_->has_pending_exception());
|
||||
CHECK(try_catch.HasCaught());
|
||||
CHECK(no_result.is_null());
|
||||
isolate_->OptionalRescheduleException(true);
|
||||
CHECK(!try_catch.Message().IsEmpty());
|
||||
return try_catch.Message();
|
||||
}
|
||||
|
||||
static Handle<Object> NewObject(const char* script) {
|
||||
return v8::Utils::OpenHandle(*CompileRun(script));
|
||||
}
|
||||
@ -154,16 +166,14 @@ class BytecodeGraphTester {
|
||||
REPEAT_4(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__) SEP() __VA_ARGS__
|
||||
|
||||
|
||||
template <int N>
|
||||
template <int N, typename T = Handle<Object>>
|
||||
struct ExpectedSnippet {
|
||||
const char* code_snippet;
|
||||
Handle<Object> return_value_and_parameters[N + 1];
|
||||
T return_value_and_parameters[N + 1];
|
||||
|
||||
inline Handle<Object> return_value() const {
|
||||
return return_value_and_parameters[0];
|
||||
}
|
||||
inline T return_value() const { return return_value_and_parameters[0]; }
|
||||
|
||||
inline Handle<Object> parameter(int i) const {
|
||||
inline T parameter(int i) const {
|
||||
DCHECK_GE(i, 0);
|
||||
DCHECK_LT(i, N);
|
||||
return return_value_and_parameters[1 + i];
|
||||
@ -951,6 +961,37 @@ TEST(BytecodeGraphBuilderTestInstanceOf) {
|
||||
// TODO(mythria): Add tests when CreateLiterals/CreateClousre are supported.
|
||||
}
|
||||
|
||||
|
||||
TEST(BytecodeGraphBuilderThrow) {
|
||||
HandleAndZoneScope scope;
|
||||
Isolate* isolate = scope.main_isolate();
|
||||
Zone* zone = scope.main_zone();
|
||||
|
||||
// TODO(mythria): Add more tests when real try-catch and deoptimization
|
||||
// information are supported.
|
||||
ExpectedSnippet<0, const char*> snippets[] = {
|
||||
{"throw undefined;", {"Uncaught undefined"}},
|
||||
{"throw 1;", {"Uncaught 1"}},
|
||||
{"throw 'Error';", {"Uncaught Error"}},
|
||||
{"throw 'Error1'; throw 'Error2'", {"Uncaught Error1"}},
|
||||
// TODO(mythria): Enable these tests when JumpIfTrue is supported.
|
||||
// {"var a = true; if (a) { throw 'Error'; }", {"Error"}},
|
||||
};
|
||||
|
||||
size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
|
||||
for (size_t i = 0; i < num_snippets; i++) {
|
||||
ScopedVector<char> script(1024);
|
||||
SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
|
||||
snippets[i].code_snippet, kFunctionName);
|
||||
BytecodeGraphTester tester(isolate, zone, script.start());
|
||||
v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get();
|
||||
v8::Local<v8::String> expected_string = v8_str(snippets[i].return_value());
|
||||
CHECK(
|
||||
message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string)
|
||||
.FromJust());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace compiler
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
Loading…
Reference in New Issue
Block a user