Commit ccb86fc5 authored by Feng Yu's avatar Feng Yu Committed by V8 LUCI CQ

[test] Migrate rest cctest/compiler/test-run-js* to unittests/

Bug: v8:12781
Change-Id: I19de9ab655e3e4b7ad45cde7f9bc659741d856a4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3858928Reviewed-by: 's avatarAnton Bikineev <bikineev@chromium.org>
Commit-Queue: Feng Yu <f3n67u@gmail.com>
Cr-Commit-Position: refs/heads/main@{#82786}
parent 9c71246b
......@@ -121,10 +121,6 @@ v8_source_set("cctest_sources") {
"compiler/test-representation-change.cc",
"compiler/test-run-bytecode-graph-builder.cc",
"compiler/test-run-calls-to-external-references.cc",
"compiler/test-run-jsbranches.cc",
"compiler/test-run-jscalls.cc",
"compiler/test-run-jsexceptions.cc",
"compiler/test-run-jsobjects.cc",
"compiler/test-run-load-store.cc",
"compiler/test-run-machops.cc",
"compiler/test-run-stackcheck.cc",
......
......@@ -590,10 +590,7 @@
'test-run-calls-to-external-references/*': [SKIP],
'test-run-deopt/*': [SKIP],
'test-run-intrinsics/*': [SKIP],
'test-run-jsbranches/*': [SKIP],
'test-run-jscalls/*': [SKIP],
'test-run-jsexceptions/*': [SKIP],
'test-run-jsobjects/*': [SKIP],
'test-run-load-store/*': [SKIP],
'test-run-machops/*': [SKIP],
'test-run-native-calls/*': [SKIP],
......
// 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/objects-inl.h"
#include "test/cctest/compiler/function-tester.h"
namespace v8 {
namespace internal {
namespace compiler {
TEST(Conditional) {
FunctionTester T("(function(a) { return a ? 23 : 42; })");
T.CheckCall(T.Val(23), T.true_value(), T.undefined());
T.CheckCall(T.Val(42), T.false_value(), T.undefined());
T.CheckCall(T.Val(42), T.undefined(), T.undefined());
T.CheckCall(T.Val(42), T.Val(0.0), T.undefined());
T.CheckCall(T.Val(23), T.Val(999), T.undefined());
T.CheckCall(T.Val(23), T.Val("x"), T.undefined());
}
TEST(LogicalAnd) {
FunctionTester T("(function(a,b) { return a && b; })");
T.CheckCall(T.true_value(), T.true_value(), T.true_value());
T.CheckCall(T.false_value(), T.false_value(), T.true_value());
T.CheckCall(T.false_value(), T.true_value(), T.false_value());
T.CheckCall(T.false_value(), T.false_value(), T.false_value());
T.CheckCall(T.Val(999), T.Val(777), T.Val(999));
T.CheckCall(T.Val(0.0), T.Val(0.0), T.Val(999));
T.CheckCall(T.Val("b"), T.Val("a"), T.Val("b"));
}
TEST(LogicalOr) {
FunctionTester T("(function(a,b) { return a || b; })");
T.CheckCall(T.true_value(), T.true_value(), T.true_value());
T.CheckCall(T.true_value(), T.false_value(), T.true_value());
T.CheckCall(T.true_value(), T.true_value(), T.false_value());
T.CheckCall(T.false_value(), T.false_value(), T.false_value());
T.CheckCall(T.Val(777), T.Val(777), T.Val(999));
T.CheckCall(T.Val(999), T.Val(0.0), T.Val(999));
T.CheckCall(T.Val("a"), T.Val("a"), T.Val("b"));
}
TEST(LogicalEffect) {
FunctionTester T("(function(a,b) { a && (b = a); return b; })");
T.CheckCall(T.true_value(), T.true_value(), T.true_value());
T.CheckCall(T.true_value(), T.false_value(), T.true_value());
T.CheckCall(T.true_value(), T.true_value(), T.false_value());
T.CheckCall(T.false_value(), T.false_value(), T.false_value());
T.CheckCall(T.Val(777), T.Val(777), T.Val(999));
T.CheckCall(T.Val(999), T.Val(0.0), T.Val(999));
T.CheckCall(T.Val("a"), T.Val("a"), T.Val("b"));
}
TEST(IfStatement) {
FunctionTester T("(function(a) { if (a) { return 1; } else { return 2; } })");
T.CheckCall(T.Val(1), T.true_value(), T.undefined());
T.CheckCall(T.Val(2), T.false_value(), T.undefined());
T.CheckCall(T.Val(2), T.undefined(), T.undefined());
T.CheckCall(T.Val(2), T.Val(0.0), T.undefined());
T.CheckCall(T.Val(1), T.Val(999), T.undefined());
T.CheckCall(T.Val(1), T.Val("x"), T.undefined());
}
TEST(DoWhileStatement) {
FunctionTester T("(function(a,b) { do { a+=23; } while(a < b) return a; })");
T.CheckCall(T.Val(24), T.Val(1), T.Val(1));
T.CheckCall(T.Val(24), T.Val(1), T.Val(23));
T.CheckCall(T.Val(47), T.Val(1), T.Val(25));
T.CheckCall(T.Val("str23"), T.Val("str"), T.Val("str"));
}
TEST(WhileStatement) {
FunctionTester T("(function(a,b) { while(a < b) { a+=23; } return a; })");
T.CheckCall(T.Val(1), T.Val(1), T.Val(1));
T.CheckCall(T.Val(24), T.Val(1), T.Val(23));
T.CheckCall(T.Val(47), T.Val(1), T.Val(25));
T.CheckCall(T.Val("str"), T.Val("str"), T.Val("str"));
}
TEST(ForStatement) {
FunctionTester T("(function(a,b) { for (; a < b; a+=23) {} return a; })");
T.CheckCall(T.Val(1), T.Val(1), T.Val(1));
T.CheckCall(T.Val(24), T.Val(1), T.Val(23));
T.CheckCall(T.Val(47), T.Val(1), T.Val(25));
T.CheckCall(T.Val("str"), T.Val("str"), T.Val("str"));
}
TEST(ForOfContinueStatement) {
const char* src =
"(function(a,b) {"
" var r = '-';"
" for (var x of a) {"
" r += x + '-';"
" if (b) continue;"
" r += 'X-';"
" }"
" return r;"
"})";
FunctionTester T(src);
CompileRun(
"function wrap(v) {"
" var iterable = {};"
" function next() { return { done:!v.length, value:v.shift() }; };"
" iterable[Symbol.iterator] = function() { return { next:next }; };"
" return iterable;"
"}");
T.CheckCall(T.Val("-"), T.NewObject("wrap([])"), T.true_value());
T.CheckCall(T.Val("-1-2-"), T.NewObject("wrap([1,2])"), T.true_value());
T.CheckCall(T.Val("-1-X-2-X-"), T.NewObject("wrap([1,2])"), T.false_value());
}
TEST(SwitchStatement) {
const char* src =
"(function(a,b) {"
" var r = '-';"
" switch (a) {"
" case 'x' : r += 'X-';"
" case b + 'b': r += 'B-';"
" default : r += 'D-';"
" case 'y' : r += 'Y-';"
" }"
" return r;"
"})";
FunctionTester T(src);
T.CheckCall(T.Val("-X-B-D-Y-"), T.Val("x"), T.Val("B"));
T.CheckCall(T.Val("-B-D-Y-"), T.Val("Bb"), T.Val("B"));
T.CheckCall(T.Val("-D-Y-"), T.Val("z"), T.Val("B"));
T.CheckCall(T.Val("-Y-"), T.Val("y"), T.Val("B"));
CompileRun("var c = 0; var o = { toString:function(){return c++} };");
T.CheckCall(T.Val("-D-Y-"), T.Val("1b"), T.NewObject("o"));
T.CheckCall(T.Val("-B-D-Y-"), T.Val("1b"), T.NewObject("o"));
T.CheckCall(T.Val("-D-Y-"), T.Val("1b"), T.NewObject("o"));
}
TEST(BlockBreakStatement) {
FunctionTester T("(function(a,b) { L:{ if (a) break L; b=1; } return b; })");
T.CheckCall(T.Val(7), T.true_value(), T.Val(7));
T.CheckCall(T.Val(1), T.false_value(), T.Val(7));
}
TEST(BlockReturnStatement) {
FunctionTester T("(function(a,b) { L:{ if (a) b=1; return b; } })");
T.CheckCall(T.Val(1), T.true_value(), T.Val(7));
T.CheckCall(T.Val(7), T.false_value(), T.Val(7));
}
TEST(NestedIfConditional) {
FunctionTester T("(function(a,b) { if (a) { b = (b?b:7) + 1; } return b; })");
T.CheckCall(T.Val(4), T.false_value(), T.Val(4));
T.CheckCall(T.Val(6), T.true_value(), T.Val(5));
T.CheckCall(T.Val(8), T.true_value(), T.undefined());
}
TEST(NestedIfLogical) {
const char* src =
"(function(a,b) {"
" if (a || b) { return 1; } else { return 2; }"
"})";
FunctionTester T(src);
T.CheckCall(T.Val(1), T.true_value(), T.true_value());
T.CheckCall(T.Val(1), T.false_value(), T.true_value());
T.CheckCall(T.Val(1), T.true_value(), T.false_value());
T.CheckCall(T.Val(2), T.false_value(), T.false_value());
T.CheckCall(T.Val(1), T.Val(1.0), T.Val(1.0));
T.CheckCall(T.Val(1), T.Val(0.0), T.Val(1.0));
T.CheckCall(T.Val(1), T.Val(1.0), T.Val(0.0));
T.CheckCall(T.Val(2), T.Val(0.0), T.Val(0.0));
}
TEST(NestedIfElseFor) {
const char* src =
"(function(a,b) {"
" if (!a) { return b - 3; } else { for (; a < b; a++); }"
" return a;"
"})";
FunctionTester T(src);
T.CheckCall(T.Val(1), T.false_value(), T.Val(4));
T.CheckCall(T.Val(2), T.true_value(), T.Val(2));
T.CheckCall(T.Val(3), T.Val(3), T.Val(1));
}
TEST(NestedWhileWhile) {
const char* src =
"(function(a) {"
" var i = a; while (false) while(false) return i;"
" return i;"
"})";
FunctionTester T(src);
T.CheckCall(T.Val(2.0), T.Val(2.0), T.Val(-1.0));
T.CheckCall(T.Val(65.0), T.Val(65.0), T.Val(-1.0));
}
TEST(NestedForIf) {
FunctionTester T("(function(a,b) { for (; a > 1; a--) if (b) return 1; })");
T.CheckCall(T.Val(1), T.Val(3), T.true_value());
T.CheckCall(T.undefined(), T.Val(2), T.false_value());
T.CheckCall(T.undefined(), T.Val(1), T.null());
}
TEST(NestedForConditional) {
FunctionTester T("(function(a,b) { for (; a > 1; a--) return b ? 1 : 2; })");
T.CheckCall(T.Val(1), T.Val(3), T.true_value());
T.CheckCall(T.Val(2), T.Val(2), T.false_value());
T.CheckCall(T.undefined(), T.Val(1), T.null());
}
TEST(IfTrue) {
FunctionTester T("(function(a,b) { if (true) return a; return b; })");
T.CheckCall(T.Val(55), T.Val(55), T.Val(11));
T.CheckCall(T.Val(666), T.Val(666), T.Val(-444));
}
TEST(TernaryTrue) {
FunctionTester T("(function(a,b) { return true ? a : b; })");
T.CheckCall(T.Val(77), T.Val(77), T.Val(11));
T.CheckCall(T.Val(111), T.Val(111), T.Val(-444));
}
TEST(IfFalse) {
FunctionTester T("(function(a,b) { if (false) return a; return b; })");
T.CheckCall(T.Val(11), T.Val(22), T.Val(11));
T.CheckCall(T.Val(-555), T.Val(333), T.Val(-555));
}
TEST(TernaryFalse) {
FunctionTester T("(function(a,b) { return false ? a : b; })");
T.CheckCall(T.Val(99), T.Val(33), T.Val(99));
T.CheckCall(T.Val(-99), T.Val(-33), T.Val(-99));
}
TEST(WhileTrue) {
FunctionTester T("(function(a,b) { while (true) return a; return b; })");
T.CheckCall(T.Val(551), T.Val(551), T.Val(111));
T.CheckCall(T.Val(661), T.Val(661), T.Val(-444));
}
TEST(WhileFalse) {
FunctionTester T("(function(a,b) { while (false) return a; return b; })");
T.CheckCall(T.Val(115), T.Val(551), T.Val(115));
T.CheckCall(T.Val(-445), T.Val(661), T.Val(-445));
}
TEST(DoWhileTrue) {
FunctionTester T(
"(function(a,b) { do { return a; } while (true); return b; })");
T.CheckCall(T.Val(7551), T.Val(7551), T.Val(7111));
T.CheckCall(T.Val(7661), T.Val(7661), T.Val(-7444));
}
TEST(DoWhileFalse) {
FunctionTester T(
"(function(a,b) { do { "
"; } while (false); return b; })");
T.CheckCall(T.Val(8115), T.Val(8551), T.Val(8115));
T.CheckCall(T.Val(-8445), T.Val(8661), T.Val(-8445));
}
TEST(EmptyFor) {
FunctionTester T("(function(a,b) { if (a) for(;;) ; return b; })");
T.CheckCall(T.Val(8126.1), T.Val(0.0), T.Val(8126.1));
T.CheckCall(T.Val(1123.1), T.Val(0.0), T.Val(1123.1));
}
} // namespace compiler
} // namespace internal
} // namespace v8
// 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/flags/flags.h"
#include "src/objects/contexts.h"
#include "src/objects/objects-inl.h"
#include "src/objects/objects.h"
#include "test/cctest/compiler/function-tester.h"
namespace v8 {
namespace internal {
namespace compiler {
TEST(SimpleCall) {
FunctionTester T("(function(foo,a) { return foo(a); })");
Handle<JSFunction> foo = T.NewFunction("(function(a) { return a; })");
T.CheckCall(T.Val(3), foo, T.Val(3));
T.CheckCall(T.Val(3.1), foo, T.Val(3.1));
T.CheckCall(foo, foo, foo);
T.CheckCall(T.Val("Abba"), foo, T.Val("Abba"));
}
TEST(SimpleCall2) {
FunctionTester T("(function(foo,a) { return foo(a); })");
FunctionTester U("(function(a) { return a; })");
T.CheckCall(T.Val(3), U.function, T.Val(3));
T.CheckCall(T.Val(3.1), U.function, T.Val(3.1));
T.CheckCall(U.function, U.function, U.function);
T.CheckCall(T.Val("Abba"), U.function, T.Val("Abba"));
}
TEST(ConstCall) {
FunctionTester T("(function(foo,a) { return foo(a,3); })");
FunctionTester U("(function (a,b) { return a + b; })");
T.CheckCall(T.Val(6), U.function, T.Val(3));
T.CheckCall(T.Val(6.1), U.function, T.Val(3.1));
T.CheckCall(T.Val("function (a,b) { return a + b; }3"), U.function,
U.function);
T.CheckCall(T.Val("Abba3"), U.function, T.Val("Abba"));
}
TEST(ConstCall2) {
FunctionTester T("(function(foo,a) { return foo(a,\"3\"); })");
FunctionTester U("(function (a,b) { return a + b; })");
T.CheckCall(T.Val("33"), U.function, T.Val(3));
T.CheckCall(T.Val("3.13"), U.function, T.Val(3.1));
T.CheckCall(T.Val("function (a,b) { return a + b; }3"), U.function,
U.function);
T.CheckCall(T.Val("Abba3"), U.function, T.Val("Abba"));
}
TEST(PropertyNamedCall) {
FunctionTester T("(function(a,b) { return a.foo(b,23); })");
CompileRun("function foo(y,z) { return this.x + y + z; }");
T.CheckCall(T.Val(32), T.NewObject("({ foo:foo, x:4 })"), T.Val(5));
T.CheckCall(T.Val("xy23"), T.NewObject("({ foo:foo, x:'x' })"), T.Val("y"));
T.CheckCall(T.nan(), T.NewObject("({ foo:foo, y:0 })"), T.Val(3));
}
TEST(PropertyKeyedCall) {
FunctionTester T("(function(a,b) { var f = 'foo'; return a[f](b,23); })");
CompileRun("function foo(y,z) { return this.x + y + z; }");
T.CheckCall(T.Val(32), T.NewObject("({ foo:foo, x:4 })"), T.Val(5));
T.CheckCall(T.Val("xy23"), T.NewObject("({ foo:foo, x:'x' })"), T.Val("y"));
T.CheckCall(T.nan(), T.NewObject("({ foo:foo, y:0 })"), T.Val(3));
}
TEST(GlobalCall) {
FunctionTester T("(function(a,b) { return foo(a,b); })");
CompileRun("function foo(a,b) { return a + b + this.c; }");
CompileRun("var c = 23;");
T.CheckCall(T.Val(32), T.Val(4), T.Val(5));
T.CheckCall(T.Val("xy23"), T.Val("x"), T.Val("y"));
T.CheckCall(T.nan(), T.undefined(), T.Val(3));
}
TEST(LookupCall) {
FunctionTester T("(function(a,b) { with (a) { return foo(a,b); } })");
CompileRun("function f1(a,b) { return a.val + b; }");
T.CheckCall(T.Val(5), T.NewObject("({ foo:f1, val:2 })"), T.Val(3));
T.CheckCall(T.Val("xy"), T.NewObject("({ foo:f1, val:'x' })"), T.Val("y"));
CompileRun("function f2(a,b) { return this.val + b; }");
T.CheckCall(T.Val(9), T.NewObject("({ foo:f2, val:4 })"), T.Val(5));
T.CheckCall(T.Val("xy"), T.NewObject("({ foo:f2, val:'x' })"), T.Val("y"));
}
TEST(MismatchCallTooFew) {
FunctionTester T("(function(a,b) { return foo(a,b); })");
CompileRun("function foo(a,b,c) { return a + b + c; }");
T.CheckCall(T.nan(), T.Val(23), T.Val(42));
T.CheckCall(T.nan(), T.Val(4.2), T.Val(2.3));
T.CheckCall(T.Val("abundefined"), T.Val("a"), T.Val("b"));
}
TEST(MismatchCallTooMany) {
FunctionTester T("(function(a,b) { return foo(a,b); })");
CompileRun("function foo(a) { return a; }");
T.CheckCall(T.Val(23), T.Val(23), T.Val(42));
T.CheckCall(T.Val(4.2), T.Val(4.2), T.Val(2.3));
T.CheckCall(T.Val("a"), T.Val("a"), T.Val("b"));
}
TEST(ConstructorCall) {
FunctionTester T("(function(a,b) { return new foo(a,b).value; })");
CompileRun("function foo(a,b) { return { value: a + b + this.c }; }");
CompileRun("foo.prototype.c = 23;");
T.CheckCall(T.Val(32), T.Val(4), T.Val(5));
T.CheckCall(T.Val("xy23"), T.Val("x"), T.Val("y"));
T.CheckCall(T.nan(), T.undefined(), T.Val(3));
}
TEST(RuntimeCall) {
FLAG_allow_natives_syntax = true;
FunctionTester T("(function(a) { return %IsJSReceiver(a); })");
T.CheckCall(T.false_value(), T.Val(23), T.undefined());
T.CheckCall(T.false_value(), T.Val(4.2), T.undefined());
T.CheckCall(T.false_value(), T.Val("str"), T.undefined());
T.CheckCall(T.false_value(), T.true_value(), T.undefined());
T.CheckCall(T.false_value(), T.false_value(), T.undefined());
T.CheckCall(T.false_value(), T.undefined(), T.undefined());
T.CheckCall(T.true_value(), T.NewObject("({})"), T.undefined());
T.CheckCall(T.true_value(), T.NewObject("([])"), T.undefined());
}
TEST(EvalCall) {
FunctionTester T("(function(a,b) { return eval(a); })");
Handle<JSObject> g(T.function->context().global_object().global_proxy(),
T.isolate);
T.CheckCall(T.Val(23), T.Val("17 + 6"), T.undefined());
T.CheckCall(T.Val("'Y'; a"), T.Val("'Y'; a"), T.Val("b-val"));
T.CheckCall(T.Val("b-val"), T.Val("'Y'; b"), T.Val("b-val"));
T.CheckCall(g, T.Val("this"), T.undefined());
T.CheckCall(g, T.Val("'use strict'; this"), T.undefined());
CompileRun("eval = function(x) { return x; }");
T.CheckCall(T.Val("17 + 6"), T.Val("17 + 6"), T.undefined());
CompileRun("eval = function(x) { return this; }");
T.CheckCall(g, T.Val("17 + 6"), T.undefined());
CompileRun("eval = function(x) { 'use strict'; return this; }");
T.CheckCall(T.undefined(), T.Val("17 + 6"), T.undefined());
}
TEST(ReceiverPatching) {
// TODO(turbofan): Note that this test only checks that the function prologue
// patches an undefined receiver to the global receiver. If this starts to
// fail once we fix the calling protocol, just remove this test.
FunctionTester T("(function(a) { return this; })");
Handle<JSObject> g(T.function->context().global_object().global_proxy(),
T.isolate);
T.CheckCall(g, T.undefined());
}
TEST(CallEval) {
FunctionTester T(
"var x = 42;"
"(function () {"
"function bar() { return eval('x') };"
"return bar;"
"})();");
T.CheckCall(T.Val(42), T.Val("x"), T.undefined());
}
} // namespace compiler
} // namespace internal
} // namespace v8
......@@ -349,6 +349,10 @@ v8_source_set("unittests_sources") {
"compiler/regalloc/move-optimizer-unittest.cc",
"compiler/regalloc/register-allocator-unittest.cc",
"compiler/run-deopt-unittest.cc",
"compiler/run-jsbranches-unittest.cc",
"compiler/run-jscalls-unittest.cc",
"compiler/run-jsexceptions-unittest.cc",
"compiler/run-jsobjects-unittest.cc",
"compiler/run-jsops-unittest.cc",
"compiler/schedule-unittest.cc",
"compiler/scheduler-rpo-unittest.cc",
......
// 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/objects-inl.h"
#include "test/unittests/compiler/function-tester.h"
#include "test/unittests/test-utils.h"
namespace v8 {
namespace internal {
namespace compiler {
using RunJSBranchesTest = TestWithContext;
TEST_F(RunJSBranchesTest, Conditional) {
FunctionTester T(i_isolate(), "(function(a) { return a ? 23 : 42; })");
T.CheckCall(T.NewNumber(23), T.true_value(), T.undefined());
T.CheckCall(T.NewNumber(42), T.false_value(), T.undefined());
T.CheckCall(T.NewNumber(42), T.undefined(), T.undefined());
T.CheckCall(T.NewNumber(42), T.NewNumber(0.0), T.undefined());
T.CheckCall(T.NewNumber(23), T.NewNumber(999), T.undefined());
T.CheckCall(T.NewNumber(23), T.NewString("x"), T.undefined());
}
TEST_F(RunJSBranchesTest, LogicalAnd) {
FunctionTester T(i_isolate(), "(function(a,b) { return a && b; })");
T.CheckCall(T.true_value(), T.true_value(), T.true_value());
T.CheckCall(T.false_value(), T.false_value(), T.true_value());
T.CheckCall(T.false_value(), T.true_value(), T.false_value());
T.CheckCall(T.false_value(), T.false_value(), T.false_value());
T.CheckCall(T.NewNumber(999), T.NewNumber(777), T.NewNumber(999));
T.CheckCall(T.NewNumber(0.0), T.NewNumber(0.0), T.NewNumber(999));
T.CheckCall(T.NewString("b"), T.NewString("a"), T.NewString("b"));
}
TEST_F(RunJSBranchesTest, LogicalOr) {
FunctionTester T(i_isolate(), "(function(a,b) { return a || b; })");
T.CheckCall(T.true_value(), T.true_value(), T.true_value());
T.CheckCall(T.true_value(), T.false_value(), T.true_value());
T.CheckCall(T.true_value(), T.true_value(), T.false_value());
T.CheckCall(T.false_value(), T.false_value(), T.false_value());
T.CheckCall(T.NewNumber(777), T.NewNumber(777), T.NewNumber(999));
T.CheckCall(T.NewNumber(999), T.NewNumber(0.0), T.NewNumber(999));
T.CheckCall(T.NewString("a"), T.NewString("a"), T.NewString("b"));
}
TEST_F(RunJSBranchesTest, LogicalEffect) {
FunctionTester T(i_isolate(), "(function(a,b) { a && (b = a); return b; })");
T.CheckCall(T.true_value(), T.true_value(), T.true_value());
T.CheckCall(T.true_value(), T.false_value(), T.true_value());
T.CheckCall(T.true_value(), T.true_value(), T.false_value());
T.CheckCall(T.false_value(), T.false_value(), T.false_value());
T.CheckCall(T.NewNumber(777), T.NewNumber(777), T.NewNumber(999));
T.CheckCall(T.NewNumber(999), T.NewNumber(0.0), T.NewNumber(999));
T.CheckCall(T.NewString("a"), T.NewString("a"), T.NewString("b"));
}
TEST_F(RunJSBranchesTest, IfStatement) {
FunctionTester T(i_isolate(),
"(function(a) { if (a) { return 1; } else { return 2; } })");
T.CheckCall(T.NewNumber(1), T.true_value(), T.undefined());
T.CheckCall(T.NewNumber(2), T.false_value(), T.undefined());
T.CheckCall(T.NewNumber(2), T.undefined(), T.undefined());
T.CheckCall(T.NewNumber(2), T.NewNumber(0.0), T.undefined());
T.CheckCall(T.NewNumber(1), T.NewNumber(999), T.undefined());
T.CheckCall(T.NewNumber(1), T.NewString("x"), T.undefined());
}
TEST_F(RunJSBranchesTest, DoWhileStatement) {
FunctionTester T(i_isolate(),
"(function(a,b) { do { a+=23; } while(a < b) return a; })");
T.CheckCall(T.NewNumber(24), T.NewNumber(1), T.NewNumber(1));
T.CheckCall(T.NewNumber(24), T.NewNumber(1), T.NewNumber(23));
T.CheckCall(T.NewNumber(47), T.NewNumber(1), T.NewNumber(25));
T.CheckCall(T.NewString("str23"), T.NewString("str"), T.NewString("str"));
}
TEST_F(RunJSBranchesTest, WhileStatement) {
FunctionTester T(i_isolate(),
"(function(a,b) { while(a < b) { a+=23; } return a; })");
T.CheckCall(T.NewNumber(1), T.NewNumber(1), T.NewNumber(1));
T.CheckCall(T.NewNumber(24), T.NewNumber(1), T.NewNumber(23));
T.CheckCall(T.NewNumber(47), T.NewNumber(1), T.NewNumber(25));
T.CheckCall(T.NewString("str"), T.NewString("str"), T.NewString("str"));
}
TEST_F(RunJSBranchesTest, ForStatement) {
FunctionTester T(i_isolate(),
"(function(a,b) { for (; a < b; a+=23) {} return a; })");
T.CheckCall(T.NewNumber(1), T.NewNumber(1), T.NewNumber(1));
T.CheckCall(T.NewNumber(24), T.NewNumber(1), T.NewNumber(23));
T.CheckCall(T.NewNumber(47), T.NewNumber(1), T.NewNumber(25));
T.CheckCall(T.NewString("str"), T.NewString("str"), T.NewString("str"));
}
TEST_F(RunJSBranchesTest, ForOfContinueStatement) {
const char* src =
"(function(a,b) {"
" var r = '-';"
" for (var x of a) {"
" r += x + '-';"
" if (b) continue;"
" r += 'X-';"
" }"
" return r;"
"})";
FunctionTester T(i_isolate(), src);
TryRunJS(
"function wrap(v) {"
" var iterable = {};"
" function next() { return { done:!v.length, value:v.shift() }; };"
" iterable[Symbol.iterator] = function() { return { next:next }; };"
" return iterable;"
"}");
T.CheckCall(T.NewString("-"), T.NewObject("wrap([])"), T.true_value());
T.CheckCall(T.NewString("-1-2-"), T.NewObject("wrap([1,2])"), T.true_value());
T.CheckCall(T.NewString("-1-X-2-X-"), T.NewObject("wrap([1,2])"),
T.false_value());
}
TEST_F(RunJSBranchesTest, SwitchStatement) {
const char* src =
"(function(a,b) {"
" var r = '-';"
" switch (a) {"
" case 'x' : r += 'X-';"
" case b + 'b': r += 'B-';"
" default : r += 'D-';"
" case 'y' : r += 'Y-';"
" }"
" return r;"
"})";
FunctionTester T(i_isolate(), src);
T.CheckCall(T.NewString("-X-B-D-Y-"), T.NewString("x"), T.NewString("B"));
T.CheckCall(T.NewString("-B-D-Y-"), T.NewString("Bb"), T.NewString("B"));
T.CheckCall(T.NewString("-D-Y-"), T.NewString("z"), T.NewString("B"));
T.CheckCall(T.NewString("-Y-"), T.NewString("y"), T.NewString("B"));
TryRunJS("var c = 0; var o = { toString:function(){return c++} };");
T.CheckCall(T.NewString("-D-Y-"), T.NewString("1b"), T.NewObject("o"));
T.CheckCall(T.NewString("-B-D-Y-"), T.NewString("1b"), T.NewObject("o"));
T.CheckCall(T.NewString("-D-Y-"), T.NewString("1b"), T.NewObject("o"));
}
TEST_F(RunJSBranchesTest, BlockBreakStatement) {
FunctionTester T(i_isolate(),
"(function(a,b) { L:{ if (a) break L; b=1; } return b; })");
T.CheckCall(T.NewNumber(7), T.true_value(), T.NewNumber(7));
T.CheckCall(T.NewNumber(1), T.false_value(), T.NewNumber(7));
}
TEST_F(RunJSBranchesTest, BlockReturnStatement) {
FunctionTester T(i_isolate(),
"(function(a,b) { L:{ if (a) b=1; return b; } })");
T.CheckCall(T.NewNumber(1), T.true_value(), T.NewNumber(7));
T.CheckCall(T.NewNumber(7), T.false_value(), T.NewNumber(7));
}
TEST_F(RunJSBranchesTest, NestedIfConditional) {
FunctionTester T(i_isolate(),
"(function(a,b) { if (a) { b = (b?b:7) + 1; } return b; })");
T.CheckCall(T.NewNumber(4), T.false_value(), T.NewNumber(4));
T.CheckCall(T.NewNumber(6), T.true_value(), T.NewNumber(5));
T.CheckCall(T.NewNumber(8), T.true_value(), T.undefined());
}
TEST_F(RunJSBranchesTest, NestedIfLogical) {
const char* src =
"(function(a,b) {"
" if (a || b) { return 1; } else { return 2; }"
"})";
FunctionTester T(i_isolate(), src);
T.CheckCall(T.NewNumber(1), T.true_value(), T.true_value());
T.CheckCall(T.NewNumber(1), T.false_value(), T.true_value());
T.CheckCall(T.NewNumber(1), T.true_value(), T.false_value());
T.CheckCall(T.NewNumber(2), T.false_value(), T.false_value());
T.CheckCall(T.NewNumber(1), T.NewNumber(1.0), T.NewNumber(1.0));
T.CheckCall(T.NewNumber(1), T.NewNumber(0.0), T.NewNumber(1.0));
T.CheckCall(T.NewNumber(1), T.NewNumber(1.0), T.NewNumber(0.0));
T.CheckCall(T.NewNumber(2), T.NewNumber(0.0), T.NewNumber(0.0));
}
TEST_F(RunJSBranchesTest, NestedIfElseFor) {
const char* src =
"(function(a,b) {"
" if (!a) { return b - 3; } else { for (; a < b; a++); }"
" return a;"
"})";
FunctionTester T(i_isolate(), src);
T.CheckCall(T.NewNumber(1), T.false_value(), T.NewNumber(4));
T.CheckCall(T.NewNumber(2), T.true_value(), T.NewNumber(2));
T.CheckCall(T.NewNumber(3), T.NewNumber(3), T.NewNumber(1));
}
TEST_F(RunJSBranchesTest, NestedWhileWhile) {
const char* src =
"(function(a) {"
" var i = a; while (false) while(false) return i;"
" return i;"
"})";
FunctionTester T(i_isolate(), src);
T.CheckCall(T.NewNumber(2.0), T.NewNumber(2.0), T.NewNumber(-1.0));
T.CheckCall(T.NewNumber(65.0), T.NewNumber(65.0), T.NewNumber(-1.0));
}
TEST_F(RunJSBranchesTest, NestedForIf) {
FunctionTester T(i_isolate(),
"(function(a,b) { for (; a > 1; a--) if (b) return 1; })");
T.CheckCall(T.NewNumber(1), T.NewNumber(3), T.true_value());
T.CheckCall(T.undefined(), T.NewNumber(2), T.false_value());
T.CheckCall(T.undefined(), T.NewNumber(1), T.null());
}
TEST_F(RunJSBranchesTest, NestedForConditional) {
FunctionTester T(i_isolate(),
"(function(a,b) { for (; a > 1; a--) return b ? 1 : 2; })");
T.CheckCall(T.NewNumber(1), T.NewNumber(3), T.true_value());
T.CheckCall(T.NewNumber(2), T.NewNumber(2), T.false_value());
T.CheckCall(T.undefined(), T.NewNumber(1), T.null());
}
TEST_F(RunJSBranchesTest, IfTrue) {
FunctionTester T(i_isolate(),
"(function(a,b) { if (true) return a; return b; })");
T.CheckCall(T.NewNumber(55), T.NewNumber(55), T.NewNumber(11));
T.CheckCall(T.NewNumber(666), T.NewNumber(666), T.NewNumber(-444));
}
TEST_F(RunJSBranchesTest, TernaryTrue) {
FunctionTester T(i_isolate(), "(function(a,b) { return true ? a : b; })");
T.CheckCall(T.NewNumber(77), T.NewNumber(77), T.NewNumber(11));
T.CheckCall(T.NewNumber(111), T.NewNumber(111), T.NewNumber(-444));
}
TEST_F(RunJSBranchesTest, IfFalse) {
FunctionTester T(i_isolate(),
"(function(a,b) { if (false) return a; return b; })");
T.CheckCall(T.NewNumber(11), T.NewNumber(22), T.NewNumber(11));
T.CheckCall(T.NewNumber(-555), T.NewNumber(333), T.NewNumber(-555));
}
TEST_F(RunJSBranchesTest, TernaryFalse) {
FunctionTester T(i_isolate(), "(function(a,b) { return false ? a : b; })");
T.CheckCall(T.NewNumber(99), T.NewNumber(33), T.NewNumber(99));
T.CheckCall(T.NewNumber(-99), T.NewNumber(-33), T.NewNumber(-99));
}
TEST_F(RunJSBranchesTest, WhileTrue) {
FunctionTester T(i_isolate(),
"(function(a,b) { while (true) return a; return b; })");
T.CheckCall(T.NewNumber(551), T.NewNumber(551), T.NewNumber(111));
T.CheckCall(T.NewNumber(661), T.NewNumber(661), T.NewNumber(-444));
}
TEST_F(RunJSBranchesTest, WhileFalse) {
FunctionTester T(i_isolate(),
"(function(a,b) { while (false) return a; return b; })");
T.CheckCall(T.NewNumber(115), T.NewNumber(551), T.NewNumber(115));
T.CheckCall(T.NewNumber(-445), T.NewNumber(661), T.NewNumber(-445));
}
TEST_F(RunJSBranchesTest, DoWhileTrue) {
FunctionTester T(
i_isolate(),
"(function(a,b) { do { return a; } while (true); return b; })");
T.CheckCall(T.NewNumber(7551), T.NewNumber(7551), T.NewNumber(7111));
T.CheckCall(T.NewNumber(7661), T.NewNumber(7661), T.NewNumber(-7444));
}
TEST_F(RunJSBranchesTest, DoWhileFalse) {
FunctionTester T(i_isolate(),
"(function(a,b) { do { "
"; } while (false); return b; })");
T.CheckCall(T.NewNumber(8115), T.NewNumber(8551), T.NewNumber(8115));
T.CheckCall(T.NewNumber(-8445), T.NewNumber(8661), T.NewNumber(-8445));
}
TEST_F(RunJSBranchesTest, EmptyFor) {
FunctionTester T(i_isolate(),
"(function(a,b) { if (a) for(;;) ; return b; })");
T.CheckCall(T.NewNumber(8126.1), T.NewNumber(0.0), T.NewNumber(8126.1));
T.CheckCall(T.NewNumber(1123.1), T.NewNumber(0.0), T.NewNumber(1123.1));
}
} // namespace compiler
} // namespace internal
} // namespace v8
// 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/flags/flags.h"
#include "src/objects/contexts.h"
#include "src/objects/objects-inl.h"
#include "src/objects/objects.h"
#include "test/unittests/compiler/function-tester.h"
#include "test/unittests/test-utils.h"
namespace v8 {
namespace internal {
namespace compiler {
using RunJSCallsTest = TestWithContext;
TEST_F(RunJSCallsTest, SimpleCall) {
FunctionTester T(i_isolate(), "(function(foo,a) { return foo(a); })");
Handle<JSFunction> foo = T.NewFunction("(function(a) { return a; })");
T.CheckCall(T.NewNumber(3), foo, T.NewNumber(3));
T.CheckCall(T.NewNumber(3.1), foo, T.NewNumber(3.1));
T.CheckCall(foo, foo, foo);
T.CheckCall(T.NewString("Abba"), foo, T.NewString("Abba"));
}
TEST_F(RunJSCallsTest, SimpleCall2) {
FunctionTester T(i_isolate(), "(function(foo,a) { return foo(a); })");
FunctionTester U(i_isolate(), "(function(a) { return a; })");
T.CheckCall(T.NewNumber(3), U.function, T.NewNumber(3));
T.CheckCall(T.NewNumber(3.1), U.function, T.NewNumber(3.1));
T.CheckCall(U.function, U.function, U.function);
T.CheckCall(T.NewString("Abba"), U.function, T.NewString("Abba"));
}
TEST_F(RunJSCallsTest, ConstCall) {
FunctionTester T(i_isolate(), "(function(foo,a) { return foo(a,3); })");
FunctionTester U(i_isolate(), "(function (a,b) { return a + b; })");
T.CheckCall(T.NewNumber(6), U.function, T.NewNumber(3));
T.CheckCall(T.NewNumber(6.1), U.function, T.NewNumber(3.1));
T.CheckCall(T.NewString("function (a,b) { return a + b; }3"), U.function,
U.function);
T.CheckCall(T.NewString("Abba3"), U.function, T.NewString("Abba"));
}
TEST_F(RunJSCallsTest, ConstCall2) {
FunctionTester T(i_isolate(), "(function(foo,a) { return foo(a,\"3\"); })");
FunctionTester U(i_isolate(), "(function (a,b) { return a + b; })");
T.CheckCall(T.NewString("33"), U.function, T.NewNumber(3));
T.CheckCall(T.NewString("3.13"), U.function, T.NewNumber(3.1));
T.CheckCall(T.NewString("function (a,b) { return a + b; }3"), U.function,
U.function);
T.CheckCall(T.NewString("Abba3"), U.function, T.NewString("Abba"));
}
TEST_F(RunJSCallsTest, PropertyNamedCall) {
FunctionTester T(i_isolate(), "(function(a,b) { return a.foo(b,23); })");
TryRunJS("function foo(y,z) { return this.x + y + z; }");
T.CheckCall(T.NewNumber(32), T.NewObject("({ foo:foo, x:4 })"),
T.NewNumber(5));
T.CheckCall(T.NewString("xy23"), T.NewObject("({ foo:foo, x:'x' })"),
T.NewString("y"));
T.CheckCall(T.nan(), T.NewObject("({ foo:foo, y:0 })"), T.NewNumber(3));
}
TEST_F(RunJSCallsTest, PropertyKeyedCall) {
FunctionTester T(i_isolate(),
"(function(a,b) { var f = 'foo'; return a[f](b,23); })");
TryRunJS("function foo(y,z) { return this.x + y + z; }");
T.CheckCall(T.NewNumber(32), T.NewObject("({ foo:foo, x:4 })"),
T.NewNumber(5));
T.CheckCall(T.NewString("xy23"), T.NewObject("({ foo:foo, x:'x' })"),
T.NewString("y"));
T.CheckCall(T.nan(), T.NewObject("({ foo:foo, y:0 })"), T.NewNumber(3));
}
TEST_F(RunJSCallsTest, GlobalCall) {
FunctionTester T(i_isolate(), "(function(a,b) { return foo(a,b); })");
TryRunJS("function foo(a,b) { return a + b + this.c; }");
TryRunJS("var c = 23;");
T.CheckCall(T.NewNumber(32), T.NewNumber(4), T.NewNumber(5));
T.CheckCall(T.NewString("xy23"), T.NewString("x"), T.NewString("y"));
T.CheckCall(T.nan(), T.undefined(), T.NewNumber(3));
}
TEST_F(RunJSCallsTest, LookupCall) {
FunctionTester T(i_isolate(),
"(function(a,b) { with (a) { return foo(a,b); } })");
TryRunJS("function f1(a,b) { return a.val + b; }");
T.CheckCall(T.NewNumber(5), T.NewObject("({ foo:f1, val:2 })"),
T.NewNumber(3));
T.CheckCall(T.NewString("xy"), T.NewObject("({ foo:f1, val:'x' })"),
T.NewString("y"));
TryRunJS("function f2(a,b) { return this.val + b; }");
T.CheckCall(T.NewNumber(9), T.NewObject("({ foo:f2, val:4 })"),
T.NewNumber(5));
T.CheckCall(T.NewString("xy"), T.NewObject("({ foo:f2, val:'x' })"),
T.NewString("y"));
}
TEST_F(RunJSCallsTest, MismatchCallTooFew) {
FunctionTester T(i_isolate(), "(function(a,b) { return foo(a,b); })");
TryRunJS("function foo(a,b,c) { return a + b + c; }");
T.CheckCall(T.nan(), T.NewNumber(23), T.NewNumber(42));
T.CheckCall(T.nan(), T.NewNumber(4.2), T.NewNumber(2.3));
T.CheckCall(T.NewString("abundefined"), T.NewString("a"), T.NewString("b"));
}
TEST_F(RunJSCallsTest, MismatchCallTooMany) {
FunctionTester T(i_isolate(), "(function(a,b) { return foo(a,b); })");
TryRunJS("function foo(a) { return a; }");
T.CheckCall(T.NewNumber(23), T.NewNumber(23), T.NewNumber(42));
T.CheckCall(T.NewNumber(4.2), T.NewNumber(4.2), T.NewNumber(2.3));
T.CheckCall(T.NewString("a"), T.NewString("a"), T.NewString("b"));
}
TEST_F(RunJSCallsTest, ConstructorCall) {
FunctionTester T(i_isolate(),
"(function(a,b) { return new foo(a,b).value; })");
TryRunJS("function foo(a,b) { return { value: a + b + this.c }; }");
TryRunJS("foo.prototype.c = 23;");
T.CheckCall(T.NewNumber(32), T.NewNumber(4), T.NewNumber(5));
T.CheckCall(T.NewString("xy23"), T.NewString("x"), T.NewString("y"));
T.CheckCall(T.nan(), T.undefined(), T.NewNumber(3));
}
TEST_F(RunJSCallsTest, RuntimeCall) {
FLAG_allow_natives_syntax = true;
FunctionTester T(i_isolate(), "(function(a) { return %IsJSReceiver(a); })");
T.CheckCall(T.false_value(), T.NewNumber(23), T.undefined());
T.CheckCall(T.false_value(), T.NewNumber(4.2), T.undefined());
T.CheckCall(T.false_value(), T.NewString("str"), T.undefined());
T.CheckCall(T.false_value(), T.true_value(), T.undefined());
T.CheckCall(T.false_value(), T.false_value(), T.undefined());
T.CheckCall(T.false_value(), T.undefined(), T.undefined());
T.CheckCall(T.true_value(), T.NewObject("({})"), T.undefined());
T.CheckCall(T.true_value(), T.NewObject("([])"), T.undefined());
}
TEST_F(RunJSCallsTest, EvalCall) {
FunctionTester T(i_isolate(), "(function(a,b) { return eval(a); })");
Handle<JSObject> g(T.function->context().global_object().global_proxy(),
T.isolate);
T.CheckCall(T.NewNumber(23), T.NewString("17 + 6"), T.undefined());
T.CheckCall(T.NewString("'Y'; a"), T.NewString("'Y'; a"),
T.NewString("b-val"));
T.CheckCall(T.NewString("b-val"), T.NewString("'Y'; b"),
T.NewString("b-val"));
T.CheckCall(g, T.NewString("this"), T.undefined());
T.CheckCall(g, T.NewString("'use strict'; this"), T.undefined());
TryRunJS("eval = function(x) { return x; }");
T.CheckCall(T.NewString("17 + 6"), T.NewString("17 + 6"), T.undefined());
TryRunJS("eval = function(x) { return this; }");
T.CheckCall(g, T.NewString("17 + 6"), T.undefined());
TryRunJS("eval = function(x) { 'use strict'; return this; }");
T.CheckCall(T.undefined(), T.NewString("17 + 6"), T.undefined());
}
TEST_F(RunJSCallsTest, ReceiverPatching) {
// TODO(turbofan): Note that this test only checks that the function prologue
// patches an undefined receiver to the global receiver. If this starts to
// fail once we fix the calling protocol, just remove this test.
FunctionTester T(i_isolate(), "(function(a) { return this; })");
Handle<JSObject> g(T.function->context().global_object().global_proxy(),
T.isolate);
T.CheckCall(g, T.undefined());
}
TEST_F(RunJSCallsTest, CallEval) {
FunctionTester T(i_isolate(),
"var x = 42;"
"(function () {"
"function bar() { return eval('x') };"
"return bar;"
"})();");
T.CheckCall(T.NewNumber(42), T.NewString("x"), T.undefined());
}
} // namespace compiler
} // namespace internal
} // namespace v8
......@@ -3,21 +3,24 @@
// found in the LICENSE file.
#include "src/objects/objects-inl.h"
#include "test/cctest/compiler/function-tester.h"
#include "test/unittests/compiler/function-tester.h"
#include "test/unittests/test-utils.h"
namespace v8 {
namespace internal {
namespace compiler {
TEST(Throw) {
FunctionTester T("(function(a,b) { if (a) { throw b; } else { return b; }})");
using RunJSExceptionsTest = TestWithContext;
TEST_F(RunJSExceptionsTest, Throw) {
FunctionTester T(i_isolate(),
"(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));
T.CheckCall(T.NewNumber(23), T.false_value(), T.NewNumber(23));
}
TEST(ThrowMessagePosition) {
TEST_F(RunJSExceptionsTest, ThrowMessagePosition) {
static const char* src =
"(function(a, b) { \n"
" if (a == 1) throw 1; \n"
......@@ -25,43 +28,42 @@ TEST(ThrowMessagePosition) {
" if (a == 3) {0;throw 3}\n"
" throw 4; \n"
"}) ";
FunctionTester T(src);
FunctionTester T(i_isolate(), src);
v8::Local<v8::Message> message;
v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext();
v8::Local<v8::Context> context = isolate()->GetCurrentContext();
message = T.CheckThrowsReturnMessage(T.Val(1), T.undefined());
message = T.CheckThrowsReturnMessage(T.NewNumber(1), T.undefined());
CHECK_EQ(2, message->GetLineNumber(context).FromMaybe(-1));
CHECK_EQ(40, message->GetStartPosition());
message = T.CheckThrowsReturnMessage(T.Val(2), T.undefined());
message = T.CheckThrowsReturnMessage(T.NewNumber(2), T.undefined());
CHECK_EQ(3, message->GetLineNumber(context).FromMaybe(-1));
CHECK_EQ(67, message->GetStartPosition());
message = T.CheckThrowsReturnMessage(T.Val(3), T.undefined());
message = T.CheckThrowsReturnMessage(T.NewNumber(3), T.undefined());
CHECK_EQ(4, message->GetLineNumber(context).FromMaybe(-1));
CHECK_EQ(95, message->GetStartPosition());
}
TEST(ThrowMessageDirectly) {
TEST_F(RunJSExceptionsTest, ThrowMessageDirectly) {
static const char* src =
"(function(a, b) {"
" if (a) { throw b; } else { throw new Error(b); }"
"})";
FunctionTester T(src);
FunctionTester T(i_isolate(), src);
v8::Local<v8::Message> message;
v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext();
v8::Local<v8::Context> context = 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.false_value(), T.NewString("Wat?"));
CHECK(t ==
message->Get()->Equals(context, NewString("Uncaught Error: Wat?")));
message = T.CheckThrowsReturnMessage(T.true_value(), T.Val("Kaboom!"));
CHECK(t == message->Get()->Equals(context, v8_str("Uncaught Kaboom!")));
message = T.CheckThrowsReturnMessage(T.true_value(), T.NewString("Kaboom!"));
CHECK(t == message->Get()->Equals(context, NewString("Uncaught Kaboom!")));
}
TEST(ThrowMessageIndirectly) {
TEST_F(RunJSExceptionsTest, ThrowMessageIndirectly) {
static const char* src =
"(function(a, b) {"
" try {"
......@@ -70,20 +72,20 @@ TEST(ThrowMessageIndirectly) {
" try { throw 'clobber'; } catch (e) { 'unclobber'; }"
" }"
"})";
FunctionTester T(src);
FunctionTester T(i_isolate(), src);
v8::Local<v8::Message> message;
v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext();
v8::Local<v8::Context> context = 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.false_value(), T.NewString("Wat?"));
CHECK(t ==
message->Get()->Equals(context, NewString("Uncaught Error: Wat?")));
message = T.CheckThrowsReturnMessage(T.true_value(), T.Val("Kaboom!"));
CHECK(t == message->Get()->Equals(context, v8_str("Uncaught Kaboom!")));
message = T.CheckThrowsReturnMessage(T.true_value(), T.NewString("Kaboom!"));
CHECK(t == message->Get()->Equals(context, NewString("Uncaught Kaboom!")));
}
TEST(Catch) {
TEST_F(RunJSExceptionsTest, Catch) {
const char* src =
"(function(a,b) {"
" var r = '-';"
......@@ -95,13 +97,12 @@ TEST(Catch) {
" }"
" return r;"
"})";
FunctionTester T(src);
FunctionTester T(i_isolate(), src);
T.CheckCall(T.Val("-A-B-"));
T.CheckCall(T.NewString("-A-B-"));
}
TEST(CatchNested) {
TEST_F(RunJSExceptionsTest, CatchNested) {
const char* src =
"(function(a,b) {"
" var r = '-';"
......@@ -118,13 +119,12 @@ TEST(CatchNested) {
" }"
" return r;"
"})";
FunctionTester T(src);
FunctionTester T(i_isolate(), src);
T.CheckCall(T.Val("-A-B-C-"));
T.CheckCall(T.NewString("-A-B-C-"));
}
TEST(CatchBreak) {
TEST_F(RunJSExceptionsTest, CatchBreak) {
const char* src =
"(function(a,b) {"
" var r = '-';"
......@@ -140,15 +140,14 @@ TEST(CatchBreak) {
" r += 'D-';"
" return r;"
"})";
FunctionTester T(src);
FunctionTester T(i_isolate(), 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());
T.CheckCall(T.NewString("-A-D-"), T.true_value(), T.false_value());
T.CheckCall(T.NewString("-A-B-D-"), T.false_value(), T.true_value());
T.CheckCall(T.NewString("-A-B-C-D-"), T.false_value(), T.false_value());
}
TEST(CatchCall) {
TEST_F(RunJSExceptionsTest, CatchCall) {
const char* src =
"(function(fun) {"
" var r = '-';"
......@@ -160,16 +159,15 @@ TEST(CatchCall) {
" }"
" return r;"
"})";
FunctionTester T(src);
FunctionTester T(i_isolate(), 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"));
TryRunJS("function thrower() { throw 'T-'; }");
T.CheckCall(T.NewString("-A-T-"), T.NewFunction("thrower"));
TryRunJS("function returner() { return 'R-'; }");
T.CheckCall(T.NewString("-A-B-R-"), T.NewFunction("returner"));
}
TEST(Finally) {
TEST_F(RunJSExceptionsTest, Finally) {
const char* src =
"(function(a,b) {"
" var r = '-';"
......@@ -180,13 +178,12 @@ TEST(Finally) {
" }"
" return r;"
"})";
FunctionTester T(src);
FunctionTester T(i_isolate(), src);
T.CheckCall(T.Val("-A-B-"));
T.CheckCall(T.NewString("-A-B-"));
}
TEST(FinallyBreak) {
TEST_F(RunJSExceptionsTest, FinallyBreak) {
const char* src =
"(function(a,b) {"
" var r = '-';"
......@@ -201,15 +198,14 @@ TEST(FinallyBreak) {
" }"
" return r;"
"})";
FunctionTester T(src);
FunctionTester T(i_isolate(), 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());
T.CheckCall(T.NewString("-A-"), T.true_value(), T.false_value());
T.CheckCall(T.NewString("-A-B-D-"), T.false_value(), T.true_value());
T.CheckCall(T.NewString("-A-B-C-D-"), T.false_value(), T.false_value());
}
TEST(DeoptTry) {
TEST_F(RunJSExceptionsTest, DeoptTry) {
const char* src =
"(function f(a) {"
" try {"
......@@ -219,13 +215,12 @@ TEST(DeoptTry) {
" return e + 1;"
" }"
"})";
FunctionTester T(src);
FunctionTester T(i_isolate(), src);
T.CheckCall(T.Val(2), T.Val(1));
T.CheckCall(T.NewNumber(2), T.NewNumber(1));
}
TEST(DeoptCatch) {
TEST_F(RunJSExceptionsTest, DeoptCatch) {
const char* src =
"(function f(a) {"
" try {"
......@@ -235,13 +230,12 @@ TEST(DeoptCatch) {
" return e + 1;"
" }"
"})";
FunctionTester T(src);
FunctionTester T(i_isolate(), src);
T.CheckCall(T.Val(2), T.Val(1));
T.CheckCall(T.NewNumber(2), T.NewNumber(1));
}
TEST(DeoptFinallyReturn) {
TEST_F(RunJSExceptionsTest, DeoptFinallyReturn) {
const char* src =
"(function f(a) {"
" try {"
......@@ -251,13 +245,12 @@ TEST(DeoptFinallyReturn) {
" return a + 1;"
" }"
"})";
FunctionTester T(src);
FunctionTester T(i_isolate(), src);
T.CheckCall(T.Val(2), T.Val(1));
T.CheckCall(T.NewNumber(2), T.NewNumber(1));
}
TEST(DeoptFinallyReThrow) {
TEST_F(RunJSExceptionsTest, DeoptFinallyReThrow) {
const char* src =
"(function f(a) {"
" try {"
......@@ -266,9 +259,9 @@ TEST(DeoptFinallyReThrow) {
" %DeoptimizeFunction(f);"
" }"
"})";
FunctionTester T(src);
FunctionTester T(i_isolate(), src);
T.CheckThrows(T.NewObject("new Error"), T.Val(1));
T.CheckThrows(T.NewObject("new Error"), T.NewNumber(1));
}
} // namespace compiler
......
// Copyright 2015 the V8 project authors. All rights reserved.
// Copyright 2022 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/execution/isolate.h"
#include "src/heap/factory.h"
#include "src/objects/objects-inl.h"
#include "test/cctest/compiler/function-tester.h"
#include "test/unittests/compiler/function-tester.h"
#include "test/unittests/test-utils.h"
namespace v8 {
namespace internal {
namespace compiler {
TEST(ArgumentsMapped) {
FunctionTester T("(function(a) { return arguments; })");
using RunJSObjectsTest = TestWithContext;
TEST_F(RunJSObjectsTest, ArgumentsMapped) {
FunctionTester T(i_isolate(), "(function(a) { return arguments; })");
Handle<Object> arguments =
T.Call(T.Val(19), T.Val(23), T.Val(42), T.Val(65)).ToHandleChecked();
T.Call(T.NewNumber(19), T.NewNumber(23), T.NewNumber(42), T.NewNumber(65))
.ToHandleChecked();
CHECK(arguments->IsJSObject() && !arguments->IsJSArray());
CHECK(JSObject::cast(*arguments).HasSloppyArgumentsElements());
Handle<String> l = T.isolate->factory()->length_string();
......@@ -24,12 +28,13 @@ TEST(ArgumentsMapped) {
CHECK_EQ(4, length->Number());
}
TEST(ArgumentsUnmapped) {
FunctionTester T("(function(a) { 'use strict'; return arguments; })");
TEST_F(RunJSObjectsTest, ArgumentsUnmapped) {
FunctionTester T(i_isolate(),
"(function(a) { 'use strict'; return arguments; })");
Handle<Object> arguments =
T.Call(T.Val(19), T.Val(23), T.Val(42), T.Val(65)).ToHandleChecked();
T.Call(T.NewNumber(19), T.NewNumber(23), T.NewNumber(42), T.NewNumber(65))
.ToHandleChecked();
CHECK(arguments->IsJSObject() && !arguments->IsJSArray());
CHECK(!JSObject::cast(*arguments).HasSloppyArgumentsElements());
Handle<String> l = T.isolate->factory()->length_string();
......@@ -38,12 +43,12 @@ TEST(ArgumentsUnmapped) {
CHECK_EQ(4, length->Number());
}
TEST(ArgumentsRest) {
FunctionTester T("(function(a, ...args) { return args; })");
TEST_F(RunJSObjectsTest, ArgumentsRest) {
FunctionTester T(i_isolate(), "(function(a, ...args) { return args; })");
Handle<Object> arguments =
T.Call(T.Val(19), T.Val(23), T.Val(42), T.Val(65)).ToHandleChecked();
T.Call(T.NewNumber(19), T.NewNumber(23), T.NewNumber(42), T.NewNumber(65))
.ToHandleChecked();
CHECK(arguments->IsJSObject() && arguments->IsJSArray());
CHECK(!JSObject::cast(*arguments).HasSloppyArgumentsElements());
Handle<String> l = T.isolate->factory()->length_string();
......
......@@ -272,6 +272,10 @@
'RegExpTest.Graph': [SKIP],
'SloppyEqualityTest/*' : [SKIP],
'DisasmX64Test.*': [SKIP],
'RunJSBranchesTest.*': [SKIP],
'RunJSCallsTest.*': [SKIP],
'RunJSExceptionsTest.*': [SKIP],
'RunJSObjectsTest.*': [SKIP],
'RunJSOpsTest.*': [SKIP],
# Tests generated irregexp code.
......
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