9d23ec9f69
The AST-based graph builder is by now only used for asm.js code. This change hard-codes this assumption into the compilation pipeline and hence allows us to remove support pertaining to deoptimization from optimized code that was not derived from bytecode. R=jarin@chromium.org BUG=v8:6409 Change-Id: I1138f16f663db5b9ee34e3110184067b8fcffc8b Reviewed-on: https://chromium-review.googlesource.com/531026 Commit-Queue: Michael Starzinger <mstarzinger@chromium.org> Reviewed-by: Jaroslav Sevcik <jarin@chromium.org> Cr-Commit-Position: refs/heads/master@{#45887}
291 lines
6.8 KiB
C++
291 lines
6.8 KiB
C++
// Copyright 2014 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.
|
|
|
|
#include "src/objects-inl.h"
|
|
#include "test/cctest/compiler/function-tester.h"
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
namespace compiler {
|
|
|
|
TEST(Throw) {
|
|
FLAG_ignition = true;
|
|
FunctionTester T("(function(a,b) { if (a) { throw b; } else { return b; }})");
|
|
|
|
T.CheckThrows(T.true_value(), T.NewObject("new Error"));
|
|
T.CheckCall(T.Val(23), T.false_value(), T.Val(23));
|
|
}
|
|
|
|
|
|
TEST(ThrowMessagePosition) {
|
|
FLAG_ignition = true;
|
|
static const char* src =
|
|
"(function(a, b) { \n"
|
|
" if (a == 1) throw 1; \n"
|
|
" if (a == 2) {throw 2} \n"
|
|
" if (a == 3) {0;throw 3}\n"
|
|
" throw 4; \n"
|
|
"}) ";
|
|
FunctionTester T(src);
|
|
v8::Local<v8::Message> message;
|
|
v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext();
|
|
|
|
message = T.CheckThrowsReturnMessage(T.Val(1), T.undefined());
|
|
CHECK_EQ(2, message->GetLineNumber(context).FromMaybe(-1));
|
|
CHECK_EQ(40, message->GetStartPosition());
|
|
|
|
message = T.CheckThrowsReturnMessage(T.Val(2), T.undefined());
|
|
CHECK_EQ(3, message->GetLineNumber(context).FromMaybe(-1));
|
|
CHECK_EQ(67, message->GetStartPosition());
|
|
|
|
message = T.CheckThrowsReturnMessage(T.Val(3), T.undefined());
|
|
CHECK_EQ(4, message->GetLineNumber(context).FromMaybe(-1));
|
|
CHECK_EQ(95, message->GetStartPosition());
|
|
}
|
|
|
|
|
|
TEST(ThrowMessageDirectly) {
|
|
FLAG_ignition = true;
|
|
static const char* src =
|
|
"(function(a, b) {"
|
|
" if (a) { throw b; } else { throw new Error(b); }"
|
|
"})";
|
|
FunctionTester T(src);
|
|
v8::Local<v8::Message> message;
|
|
v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext();
|
|
v8::Maybe<bool> t = v8::Just(true);
|
|
|
|
message = T.CheckThrowsReturnMessage(T.false_value(), T.Val("Wat?"));
|
|
CHECK(t == message->Get()->Equals(context, v8_str("Uncaught Error: Wat?")));
|
|
|
|
message = T.CheckThrowsReturnMessage(T.true_value(), T.Val("Kaboom!"));
|
|
CHECK(t == message->Get()->Equals(context, v8_str("Uncaught Kaboom!")));
|
|
}
|
|
|
|
|
|
TEST(ThrowMessageIndirectly) {
|
|
FLAG_ignition = true;
|
|
static const char* src =
|
|
"(function(a, b) {"
|
|
" try {"
|
|
" if (a) { throw b; } else { throw new Error(b); }"
|
|
" } finally {"
|
|
" try { throw 'clobber'; } catch (e) { 'unclobber'; }"
|
|
" }"
|
|
"})";
|
|
FunctionTester T(src);
|
|
v8::Local<v8::Message> message;
|
|
v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext();
|
|
v8::Maybe<bool> t = v8::Just(true);
|
|
|
|
message = T.CheckThrowsReturnMessage(T.false_value(), T.Val("Wat?"));
|
|
CHECK(t == message->Get()->Equals(context, v8_str("Uncaught Error: Wat?")));
|
|
|
|
message = T.CheckThrowsReturnMessage(T.true_value(), T.Val("Kaboom!"));
|
|
CHECK(t == message->Get()->Equals(context, v8_str("Uncaught Kaboom!")));
|
|
}
|
|
|
|
|
|
TEST(Catch) {
|
|
FLAG_ignition = true;
|
|
const char* src =
|
|
"(function(a,b) {"
|
|
" var r = '-';"
|
|
" try {"
|
|
" r += 'A-';"
|
|
" throw 'B-';"
|
|
" } catch (e) {"
|
|
" r += e;"
|
|
" }"
|
|
" return r;"
|
|
"})";
|
|
FunctionTester T(src);
|
|
|
|
T.CheckCall(T.Val("-A-B-"));
|
|
}
|
|
|
|
|
|
TEST(CatchNested) {
|
|
FLAG_ignition = true;
|
|
const char* src =
|
|
"(function(a,b) {"
|
|
" var r = '-';"
|
|
" try {"
|
|
" r += 'A-';"
|
|
" throw 'C-';"
|
|
" } catch (e) {"
|
|
" try {"
|
|
" throw 'B-';"
|
|
" } catch (e) {"
|
|
" r += e;"
|
|
" }"
|
|
" r += e;"
|
|
" }"
|
|
" return r;"
|
|
"})";
|
|
FunctionTester T(src);
|
|
|
|
T.CheckCall(T.Val("-A-B-C-"));
|
|
}
|
|
|
|
|
|
TEST(CatchBreak) {
|
|
FLAG_ignition = true;
|
|
const char* src =
|
|
"(function(a,b) {"
|
|
" var r = '-';"
|
|
" L: try {"
|
|
" r += 'A-';"
|
|
" if (a) break L;"
|
|
" r += 'B-';"
|
|
" throw 'C-';"
|
|
" } catch (e) {"
|
|
" if (b) break L;"
|
|
" r += e;"
|
|
" }"
|
|
" r += 'D-';"
|
|
" return r;"
|
|
"})";
|
|
FunctionTester T(src);
|
|
|
|
T.CheckCall(T.Val("-A-D-"), T.true_value(), T.false_value());
|
|
T.CheckCall(T.Val("-A-B-D-"), T.false_value(), T.true_value());
|
|
T.CheckCall(T.Val("-A-B-C-D-"), T.false_value(), T.false_value());
|
|
}
|
|
|
|
|
|
TEST(CatchCall) {
|
|
FLAG_ignition = true;
|
|
const char* src =
|
|
"(function(fun) {"
|
|
" var r = '-';"
|
|
" try {"
|
|
" r += 'A-';"
|
|
" return r + 'B-' + fun();"
|
|
" } catch (e) {"
|
|
" r += e;"
|
|
" }"
|
|
" return r;"
|
|
"})";
|
|
FunctionTester T(src);
|
|
|
|
CompileRun("function thrower() { throw 'T-'; }");
|
|
T.CheckCall(T.Val("-A-T-"), T.NewFunction("thrower"));
|
|
CompileRun("function returner() { return 'R-'; }");
|
|
T.CheckCall(T.Val("-A-B-R-"), T.NewFunction("returner"));
|
|
}
|
|
|
|
|
|
TEST(Finally) {
|
|
FLAG_ignition = true;
|
|
const char* src =
|
|
"(function(a,b) {"
|
|
" var r = '-';"
|
|
" try {"
|
|
" r += 'A-';"
|
|
" } finally {"
|
|
" r += 'B-';"
|
|
" }"
|
|
" return r;"
|
|
"})";
|
|
FunctionTester T(src);
|
|
|
|
T.CheckCall(T.Val("-A-B-"));
|
|
}
|
|
|
|
|
|
TEST(FinallyBreak) {
|
|
FLAG_ignition = true;
|
|
const char* src =
|
|
"(function(a,b) {"
|
|
" var r = '-';"
|
|
" L: try {"
|
|
" r += 'A-';"
|
|
" if (a) return r;"
|
|
" r += 'B-';"
|
|
" if (b) break L;"
|
|
" r += 'C-';"
|
|
" } finally {"
|
|
" r += 'D-';"
|
|
" }"
|
|
" return r;"
|
|
"})";
|
|
FunctionTester T(src);
|
|
|
|
T.CheckCall(T.Val("-A-"), T.true_value(), T.false_value());
|
|
T.CheckCall(T.Val("-A-B-D-"), T.false_value(), T.true_value());
|
|
T.CheckCall(T.Val("-A-B-C-D-"), T.false_value(), T.false_value());
|
|
}
|
|
|
|
|
|
TEST(DeoptTry) {
|
|
FLAG_ignition = true;
|
|
const char* src =
|
|
"(function f(a) {"
|
|
" try {"
|
|
" %DeoptimizeFunction(f);"
|
|
" throw a;"
|
|
" } catch (e) {"
|
|
" return e + 1;"
|
|
" }"
|
|
"})";
|
|
FunctionTester T(src);
|
|
|
|
T.CheckCall(T.Val(2), T.Val(1));
|
|
}
|
|
|
|
|
|
TEST(DeoptCatch) {
|
|
FLAG_ignition = true;
|
|
const char* src =
|
|
"(function f(a) {"
|
|
" try {"
|
|
" throw a;"
|
|
" } catch (e) {"
|
|
" %DeoptimizeFunction(f);"
|
|
" return e + 1;"
|
|
" }"
|
|
"})";
|
|
FunctionTester T(src);
|
|
|
|
T.CheckCall(T.Val(2), T.Val(1));
|
|
}
|
|
|
|
|
|
TEST(DeoptFinallyReturn) {
|
|
FLAG_ignition = true;
|
|
const char* src =
|
|
"(function f(a) {"
|
|
" try {"
|
|
" throw a;"
|
|
" } finally {"
|
|
" %DeoptimizeFunction(f);"
|
|
" return a + 1;"
|
|
" }"
|
|
"})";
|
|
FunctionTester T(src);
|
|
|
|
T.CheckCall(T.Val(2), T.Val(1));
|
|
}
|
|
|
|
|
|
TEST(DeoptFinallyReThrow) {
|
|
FLAG_ignition = true;
|
|
const char* src =
|
|
"(function f(a) {"
|
|
" try {"
|
|
" throw a;"
|
|
" } finally {"
|
|
" %DeoptimizeFunction(f);"
|
|
" }"
|
|
"})";
|
|
FunctionTester T(src);
|
|
|
|
T.CheckThrows(T.NewObject("new Error"), T.Val(1));
|
|
}
|
|
|
|
} // namespace compiler
|
|
} // namespace internal
|
|
} // namespace v8
|