2015-08-18 13:46:43 +00:00
|
|
|
// Copyright 2015 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.
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
#include <fstream>
|
|
|
|
|
2015-08-18 13:46:43 +00:00
|
|
|
#include "src/v8.h"
|
|
|
|
|
2015-09-24 11:48:22 +00:00
|
|
|
#include "src/interpreter/bytecode-array-iterator.h"
|
2015-08-18 13:46:43 +00:00
|
|
|
#include "src/interpreter/bytecode-generator.h"
|
|
|
|
#include "src/interpreter/interpreter.h"
|
2017-01-09 13:43:28 +00:00
|
|
|
#include "src/objects-inl.h"
|
2015-08-18 13:46:43 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
2016-02-25 12:07:07 +00:00
|
|
|
#include "test/cctest/interpreter/bytecode-expectations-printer.h"
|
2015-10-01 13:48:05 +00:00
|
|
|
#include "test/cctest/test-feedback-vector.h"
|
2015-08-18 13:46:43 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace interpreter {
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
#define XSTR(A) #A
|
|
|
|
#define STR(A) XSTR(A)
|
2016-02-04 17:47:08 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
#define UNIQUE_VAR() "var a" STR(__COUNTER__) " = 0;\n"
|
2015-08-18 13:46:43 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
#define REPEAT_2(...) __VA_ARGS__ __VA_ARGS__
|
|
|
|
#define REPEAT_4(...) REPEAT_2(__VA_ARGS__) REPEAT_2(__VA_ARGS__)
|
|
|
|
#define REPEAT_8(...) REPEAT_4(__VA_ARGS__) REPEAT_4(__VA_ARGS__)
|
|
|
|
#define REPEAT_16(...) REPEAT_8(__VA_ARGS__) REPEAT_8(__VA_ARGS__)
|
|
|
|
#define REPEAT_32(...) REPEAT_16(__VA_ARGS__) REPEAT_16(__VA_ARGS__)
|
|
|
|
#define REPEAT_64(...) REPEAT_32(__VA_ARGS__) REPEAT_32(__VA_ARGS__)
|
|
|
|
#define REPEAT_128(...) REPEAT_64(__VA_ARGS__) REPEAT_64(__VA_ARGS__)
|
|
|
|
#define REPEAT_256(...) REPEAT_128(__VA_ARGS__) REPEAT_128(__VA_ARGS__)
|
|
|
|
|
|
|
|
#define REPEAT_127(...) \
|
|
|
|
REPEAT_64(__VA_ARGS__) \
|
|
|
|
REPEAT_32(__VA_ARGS__) \
|
|
|
|
REPEAT_16(__VA_ARGS__) \
|
|
|
|
REPEAT_8(__VA_ARGS__) \
|
|
|
|
REPEAT_4(__VA_ARGS__) \
|
|
|
|
REPEAT_2(__VA_ARGS__) \
|
|
|
|
__VA_ARGS__
|
2015-09-02 13:03:06 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
#define REPEAT_249(...) \
|
|
|
|
REPEAT_127(__VA_ARGS__) \
|
|
|
|
REPEAT_64(__VA_ARGS__) \
|
|
|
|
REPEAT_32(__VA_ARGS__) \
|
|
|
|
REPEAT_16(__VA_ARGS__) \
|
|
|
|
REPEAT_8(__VA_ARGS__) \
|
|
|
|
REPEAT_2(__VA_ARGS__)
|
|
|
|
|
|
|
|
#define REPEAT_2_UNIQUE_VARS() UNIQUE_VAR() UNIQUE_VAR()
|
|
|
|
#define REPEAT_4_UNIQUE_VARS() REPEAT_2_UNIQUE_VARS() REPEAT_2_UNIQUE_VARS()
|
|
|
|
#define REPEAT_8_UNIQUE_VARS() REPEAT_4_UNIQUE_VARS() REPEAT_4_UNIQUE_VARS()
|
|
|
|
#define REPEAT_16_UNIQUE_VARS() REPEAT_8_UNIQUE_VARS() REPEAT_8_UNIQUE_VARS()
|
|
|
|
#define REPEAT_32_UNIQUE_VARS() REPEAT_16_UNIQUE_VARS() REPEAT_16_UNIQUE_VARS()
|
|
|
|
#define REPEAT_64_UNIQUE_VARS() REPEAT_32_UNIQUE_VARS() REPEAT_32_UNIQUE_VARS()
|
|
|
|
#define REPEAT_128_UNIQUE_VARS() REPEAT_64_UNIQUE_VARS() REPEAT_64_UNIQUE_VARS()
|
|
|
|
|
2016-09-07 06:54:36 +00:00
|
|
|
#define REPEAT_250_UNIQUE_VARS() \
|
2016-02-25 12:07:07 +00:00
|
|
|
REPEAT_128_UNIQUE_VARS() \
|
|
|
|
REPEAT_64_UNIQUE_VARS() \
|
|
|
|
REPEAT_32_UNIQUE_VARS() \
|
|
|
|
REPEAT_16_UNIQUE_VARS() \
|
|
|
|
REPEAT_8_UNIQUE_VARS() \
|
2016-09-07 06:54:36 +00:00
|
|
|
UNIQUE_VAR() \
|
2016-02-25 12:07:07 +00:00
|
|
|
UNIQUE_VAR()
|
|
|
|
|
|
|
|
static const char* kGoldenFileDirectory =
|
|
|
|
"test/cctest/interpreter/bytecode_expectations/";
|
|
|
|
|
|
|
|
class InitializedIgnitionHandleScope : public InitializedHandleScope {
|
|
|
|
public:
|
|
|
|
InitializedIgnitionHandleScope() {
|
2015-08-18 13:46:43 +00:00
|
|
|
i::FLAG_ignition = true;
|
2015-09-10 16:21:34 +00:00
|
|
|
i::FLAG_always_opt = false;
|
2015-10-02 18:13:41 +00:00
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2015-08-18 13:46:43 +00:00
|
|
|
}
|
2016-02-25 12:07:07 +00:00
|
|
|
};
|
2015-08-18 13:46:43 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
void SkipGoldenFileHeader(std::istream& stream) { // NOLINT
|
|
|
|
std::string line;
|
|
|
|
int separators_seen = 0;
|
|
|
|
while (std::getline(stream, line)) {
|
|
|
|
if (line == "---") separators_seen += 1;
|
|
|
|
if (separators_seen == 2) return;
|
2015-10-07 21:18:58 +00:00
|
|
|
}
|
2016-02-25 12:07:07 +00:00
|
|
|
}
|
2015-10-07 21:18:58 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
std::string LoadGolden(const std::string& golden_filename) {
|
|
|
|
std::ifstream expected_file((kGoldenFileDirectory + golden_filename).c_str());
|
|
|
|
CHECK(expected_file.is_open());
|
|
|
|
SkipGoldenFileHeader(expected_file);
|
|
|
|
std::ostringstream expected_stream;
|
|
|
|
// Restore the first separator, which was consumed by SkipGoldenFileHeader
|
|
|
|
expected_stream << "---\n" << expected_file.rdbuf();
|
|
|
|
return expected_stream.str();
|
|
|
|
}
|
2015-08-18 13:46:43 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
template <size_t N>
|
|
|
|
std::string BuildActual(const BytecodeExpectationsPrinter& printer,
|
|
|
|
const char* (&snippet_list)[N],
|
|
|
|
const char* prologue = nullptr,
|
|
|
|
const char* epilogue = nullptr) {
|
|
|
|
std::ostringstream actual_stream;
|
|
|
|
for (const char* snippet : snippet_list) {
|
|
|
|
std::string source_code;
|
|
|
|
if (prologue) source_code += prologue;
|
|
|
|
source_code += snippet;
|
|
|
|
if (epilogue) source_code += epilogue;
|
|
|
|
printer.PrintExpectation(actual_stream, source_code);
|
2015-12-16 17:24:20 +00:00
|
|
|
}
|
2016-02-25 12:07:07 +00:00
|
|
|
return actual_stream.str();
|
|
|
|
}
|
2015-12-16 17:24:20 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
bool CompareTexts(const std::string& generated, const std::string& expected) {
|
|
|
|
std::istringstream generated_stream(generated);
|
|
|
|
std::istringstream expected_stream(expected);
|
|
|
|
std::string generated_line;
|
|
|
|
std::string expected_line;
|
|
|
|
// Line number does not include golden file header.
|
|
|
|
int line_number = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
std::getline(generated_stream, generated_line);
|
|
|
|
std::getline(expected_stream, expected_line);
|
|
|
|
|
|
|
|
if (!generated_stream.good() && !expected_stream.good()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!generated_stream.good()) {
|
|
|
|
std::cerr << "Expected has extra lines after line " << line_number
|
|
|
|
<< "\n";
|
|
|
|
std::cerr << " Expected: '" << expected_line << "'\n";
|
|
|
|
return false;
|
|
|
|
} else if (!expected_stream.good()) {
|
|
|
|
std::cerr << "Generated has extra lines after line " << line_number
|
|
|
|
<< "\n";
|
|
|
|
std::cerr << " Generated: '" << generated_line << "'\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (generated_line != expected_line) {
|
|
|
|
std::cerr << "Inputs differ at line " << line_number << "\n";
|
|
|
|
std::cerr << " Generated: '" << generated_line << "'\n";
|
|
|
|
std::cerr << " Expected: '" << expected_line << "'\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
line_number++;
|
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(PrimitiveReturnStatements) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
|
|
|
"",
|
2015-10-26 18:11:23 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return;\n",
|
2015-08-18 13:46:43 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return null;\n",
|
2015-08-18 13:46:43 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return true;\n",
|
2015-09-24 11:48:22 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return false;\n",
|
2016-01-11 16:37:53 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return 0;\n",
|
2015-10-30 11:17:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return +1;\n",
|
2015-09-24 11:48:22 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return -1;\n",
|
2015-08-18 13:46:43 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return +127;\n",
|
2015-08-18 13:46:43 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return -128;\n",
|
2016-07-21 09:18:47 +00:00
|
|
|
|
|
|
|
"return 2.0;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("PrimitiveReturnStatements.golden")));
|
2015-09-24 11:48:22 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(PrimitiveExpressions) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"var x = 0; return x;\n",
|
2015-09-24 11:48:22 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var x = 0; return x + 3;\n",
|
2015-09-24 11:48:22 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var x = 0; return x - 3;\n",
|
2015-09-24 11:48:22 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var x = 4; return x * 3;\n",
|
2015-09-24 11:48:22 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var x = 4; return x / 3;\n",
|
2015-09-24 11:48:22 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var x = 4; return x % 3;\n",
|
2015-09-24 15:20:47 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var x = 1; return x | 2;\n",
|
2015-09-24 15:20:47 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var x = 1; return x ^ 2;\n",
|
2015-10-13 09:39:55 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var x = 1; return x & 2;\n",
|
2015-10-13 09:39:55 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var x = 10; return x << 3;\n",
|
2015-09-24 11:48:22 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var x = 10; return x >> 3;\n",
|
2015-08-18 13:46:43 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var x = 10; return x >>> 3;\n",
|
2015-08-18 13:46:43 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var x = 0; return (x, 3);\n",
|
2015-08-18 13:46:43 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("PrimitiveExpressions.golden")));
|
2015-08-18 13:46:43 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(LogicalExpressions) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"var x = 0; return x || 3;\n",
|
2015-08-18 13:46:43 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var x = 0; return (x == 1) || 3;\n",
|
2015-10-15 09:11:40 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var x = 0; return x && 3;\n",
|
2015-10-15 09:11:40 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var x = 0; return (x == 0) && 3;\n",
|
2015-10-15 09:11:40 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var x = 0; return x || (1, 2, 3);\n",
|
2015-08-18 13:46:43 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 2, b = 3, c = 4; return a || (a, b, a, b, c = 5, 3);\n",
|
2015-08-27 10:32:26 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
"var x = 1; var a = 2, b = 3; return x || (" //
|
|
|
|
REPEAT_32("\n a = 1, b = 2, ") //
|
2016-05-11 12:21:56 +00:00
|
|
|
"3);\n",
|
2015-08-27 10:32:26 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
"var x = 0; var a = 2, b = 3; return x && (" //
|
|
|
|
REPEAT_32("\n a = 1, b = 2, ") //
|
2016-05-11 12:21:56 +00:00
|
|
|
"3);\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = 1; var a = 2, b = 3; return (x > 3) || (" //
|
|
|
|
REPEAT_32("\n a = 1, b = 2, ") //
|
2016-05-11 12:21:56 +00:00
|
|
|
"3);\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = 0; var a = 2, b = 3; return (x < 5) && (" //
|
|
|
|
REPEAT_32("\n a = 1, b = 2, ") //
|
2016-05-11 12:21:56 +00:00
|
|
|
"3);\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return 0 && 3;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return 1 || 3;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var x = 1; return x && 3 || 0, 1;\n",
|
2015-08-27 10:32:26 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("LogicalExpressions.golden")));
|
2015-08-18 13:46:43 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(Parameters) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
|
|
|
|
|
|
|
const char* snippets[] = {
|
|
|
|
"function f() { return this; }",
|
2015-08-28 15:40:52 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
"function f(arg1) { return arg1; }",
|
|
|
|
|
|
|
|
"function f(arg1) { return this; }",
|
|
|
|
|
|
|
|
"function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return arg4; }",
|
|
|
|
|
|
|
|
"function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return this; }",
|
|
|
|
|
|
|
|
"function f(arg1) { arg1 = 1; }",
|
|
|
|
|
|
|
|
"function f(arg1, arg2, arg3, arg4) { arg2 = 1; }",
|
2016-02-04 12:33:13 +00:00
|
|
|
};
|
2015-08-28 15:40:52 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets, "", "\nf();"),
|
|
|
|
LoadGolden("Parameters.golden")));
|
2015-09-24 15:20:47 +00:00
|
|
|
}
|
2015-08-28 15:40:52 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(IntegerConstants) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"return 12345678;\n",
|
2015-08-28 15:40:52 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1234; return 5678;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1234; return 1234;\n",
|
2015-10-30 11:17:07 +00:00
|
|
|
};
|
2016-02-04 12:33:13 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("IntegerConstants.golden")));
|
2015-09-24 15:20:47 +00:00
|
|
|
}
|
2015-08-28 15:40:52 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(HeapNumberConstants) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"return 1.2;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1.2; return 2.6;\n",
|
2015-08-28 15:40:52 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 3.14; return 3.14;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var a;" //
|
|
|
|
REPEAT_256("\na = 1.414;") //
|
2016-05-11 12:21:56 +00:00
|
|
|
" a = 3.14;\n",
|
2016-02-04 12:33:13 +00:00
|
|
|
};
|
2015-09-24 15:20:47 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("HeapNumberConstants.golden")));
|
2015-08-28 15:40:52 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(StringConstants) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"return \"This is a string\";\n",
|
2015-08-28 15:40:52 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = \"First string\"; return \"Second string\";\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = \"Same string\"; return \"Same string\";\n",
|
2015-12-09 08:32:56 +00:00
|
|
|
};
|
2016-02-04 12:33:13 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("StringConstants.golden")));
|
2015-09-02 13:03:06 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(PropertyLoads) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
2015-09-09 15:46:04 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
|
|
|
"function f(a) { return a.name; }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f({name : \"test\"});\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"function f(a) { return a[\"key\"]; }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f({key : \"test\"});\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"function f(a) { return a[100]; }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f({100 : \"test\"});\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"function f(a, b) { return a[b]; }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f({arg : \"test\"}, \"arg\");\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"function f(a) { var b = a.name; return a[-124]; }\n"
|
|
|
|
"f({\"-124\" : \"test\", name : 123 })",
|
|
|
|
|
|
|
|
"function f(a) {\n"
|
|
|
|
" var b;\n"
|
|
|
|
" b = a.name;\n"
|
|
|
|
REPEAT_127(" b = a.name;\n")
|
|
|
|
" return a.name;\n"
|
|
|
|
"}\n"
|
|
|
|
"f({name : \"test\"})\n",
|
|
|
|
|
|
|
|
"function f(a, b) {\n"
|
|
|
|
" var c;\n"
|
|
|
|
" c = a[b];\n"
|
|
|
|
REPEAT_127(" c = a[b];\n")
|
|
|
|
" return a[b];\n"
|
|
|
|
"}\n"
|
|
|
|
"f({name : \"test\"}, \"name\")\n",
|
2016-02-04 12:33:13 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("PropertyLoads.golden")));
|
2015-09-09 15:46:04 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(PropertyStores) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
2015-09-14 10:05:18 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
|
|
|
"function f(a) { a.name = \"val\"; }\n"
|
|
|
|
"f({name : \"test\"})",
|
2015-09-14 10:05:18 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
"function f(a) { a[\"key\"] = \"val\"; }\n"
|
|
|
|
"f({key : \"test\"})",
|
2015-09-14 10:05:18 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
"function f(a) { a[100] = \"val\"; }\n"
|
|
|
|
"f({100 : \"test\"})",
|
|
|
|
|
|
|
|
"function f(a, b) { a[b] = \"val\"; }\n"
|
|
|
|
"f({arg : \"test\"}, \"arg\")",
|
|
|
|
|
|
|
|
"function f(a) { a.name = a[-124]; }\n"
|
|
|
|
"f({\"-124\" : \"test\", name : 123 })",
|
|
|
|
|
|
|
|
"function f(a) { \"use strict\"; a.name = \"val\"; }\n"
|
|
|
|
"f({name : \"test\"})",
|
|
|
|
|
|
|
|
"function f(a, b) { \"use strict\"; a[b] = \"val\"; }\n"
|
|
|
|
"f({arg : \"test\"}, \"arg\")",
|
|
|
|
|
|
|
|
"function f(a) {\n"
|
|
|
|
" a.name = 1;\n"
|
|
|
|
REPEAT_127(" a.name = 1;\n")
|
|
|
|
" a.name = 2;\n"
|
|
|
|
"}\n"
|
|
|
|
"f({name : \"test\"})\n",
|
|
|
|
|
|
|
|
"function f(a) {\n"
|
|
|
|
" 'use strict';\n"
|
|
|
|
" a.name = 1;\n"
|
|
|
|
REPEAT_127(" a.name = 1;\n")
|
|
|
|
" a.name = 2;\n"
|
|
|
|
"}\n"
|
|
|
|
"f({name : \"test\"})\n",
|
|
|
|
|
|
|
|
"function f(a, b) {\n"
|
|
|
|
" a[b] = 1;\n"
|
|
|
|
REPEAT_127(" a[b] = 1;\n")
|
|
|
|
" a[b] = 2;\n"
|
|
|
|
"}\n"
|
|
|
|
"f({name : \"test\"})\n",
|
|
|
|
|
|
|
|
"function f(a, b) {\n"
|
|
|
|
" 'use strict';\n"
|
|
|
|
" a[b] = 1;\n"
|
|
|
|
REPEAT_127(" a[b] = 1;\n")
|
|
|
|
" a[b] = 2;\n"
|
|
|
|
"}\n"
|
|
|
|
"f({name : \"test\"})\n",
|
2015-11-17 12:18:25 +00:00
|
|
|
};
|
2016-02-04 12:33:13 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("PropertyStores.golden")));
|
2015-09-24 11:48:22 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
#define FUNC_ARG "new (function Obj() { this.func = function() { return; }})()"
|
2015-09-24 11:48:22 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(PropertyCall) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
|
|
|
|
|
|
|
const char* snippets[] = {
|
|
|
|
"function f(a) { return a.func(); }\n"
|
|
|
|
"f(" FUNC_ARG ")",
|
|
|
|
|
|
|
|
"function f(a, b, c) { return a.func(b, c); }\n"
|
|
|
|
"f(" FUNC_ARG ", 1, 2)",
|
|
|
|
|
|
|
|
"function f(a, b) { return a.func(b + b, b); }\n"
|
|
|
|
"f(" FUNC_ARG ", 1)",
|
|
|
|
|
|
|
|
"function f(a) {\n"
|
|
|
|
" a.func;\n" //
|
|
|
|
REPEAT_127(" a.func;\n") //
|
|
|
|
" return a.func(); }\n"
|
|
|
|
"f(" FUNC_ARG ")",
|
2016-12-15 10:59:57 +00:00
|
|
|
|
|
|
|
"function f(a) { return a.func(1).func(2).func(3); }\n"
|
|
|
|
"f(new (function Obj() { this.func = function(a) { return this; }})())",
|
2015-09-24 11:48:22 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("PropertyCall.golden")));
|
2015-09-24 11:48:22 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(LoadGlobal) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
2015-09-24 11:48:22 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
|
|
|
"var a = 1;\n"
|
|
|
|
"function f() { return a; }\n"
|
|
|
|
"f()",
|
|
|
|
|
|
|
|
"function t() { }\n"
|
|
|
|
"function f() { return t; }\n"
|
|
|
|
"f()",
|
|
|
|
|
|
|
|
"a = 1;\n"
|
|
|
|
"function f() { return a; }\n"
|
|
|
|
"f()",
|
|
|
|
|
|
|
|
"a = 1;\n"
|
|
|
|
"function f(b) {\n"
|
|
|
|
" b.name;\n"
|
|
|
|
REPEAT_127(" b.name;\n")
|
|
|
|
" return a;\n"
|
|
|
|
"}\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f({name: 1});\n",
|
2015-10-07 21:18:58 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("LoadGlobal.golden")));
|
2015-10-07 21:18:58 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(StoreGlobal) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
2015-10-07 21:18:58 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
|
|
|
"var a = 1;\n"
|
|
|
|
"function f() { a = 2; }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var a = \"test\"; function f(b) { a = b; }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f(\"global\");\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"'use strict'; var a = 1;\n"
|
|
|
|
"function f() { a = 2; }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"a = 1;\n"
|
|
|
|
"function f() { a = 2; }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"a = 1;\n"
|
|
|
|
"function f(b) {\n"
|
|
|
|
" b.name;\n"
|
|
|
|
REPEAT_127(" b.name;\n")
|
|
|
|
" a = 2;\n"
|
|
|
|
"}\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f({name: 1});\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"a = 1;\n"
|
|
|
|
"function f(b) {\n"
|
|
|
|
" 'use strict';\n"
|
|
|
|
" b.name;\n"
|
|
|
|
REPEAT_127(" b.name;\n")
|
|
|
|
" a = 2;\n"
|
|
|
|
"}\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f({name: 1});\n",
|
2015-10-07 21:18:58 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("StoreGlobal.golden")));
|
2015-10-07 21:18:58 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(CallGlobal) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
|
|
|
|
|
|
|
const char* snippets[] = {
|
|
|
|
"function t() { }\n"
|
|
|
|
"function f() { return t(); }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2015-10-07 21:18:58 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
"function t(a, b, c) { }\n"
|
|
|
|
"function f() { return t(1, 2, 3); }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2015-09-24 11:48:22 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("CallGlobal.golden")));
|
2015-09-14 10:05:18 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(CallRuntime) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
2015-09-24 15:20:47 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
|
|
|
"function f() { %TheHole() }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"function f(a) { return %IsArray(a) }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f(undefined);\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"function f() { return %Add(1, 2) }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"function f() { return %spread_iterable([1]) }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2016-02-04 12:33:13 +00:00
|
|
|
};
|
2015-09-24 15:20:47 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("CallRuntime.golden")));
|
2015-09-24 15:20:47 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(IfConditions) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
|
|
|
|
|
|
|
const char* snippets[] = {
|
|
|
|
"function f() {\n"
|
|
|
|
" if (0) {\n"
|
|
|
|
" return 1;\n"
|
|
|
|
" } else {\n"
|
|
|
|
" return -1;\n"
|
|
|
|
" }\n"
|
|
|
|
"};\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"function f() {\n"
|
|
|
|
" if ('lucky') {\n"
|
|
|
|
" return 1;\n"
|
|
|
|
" } else {\n"
|
|
|
|
" return -1;\n"
|
|
|
|
" }\n"
|
|
|
|
"};\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"function f() {\n"
|
|
|
|
" if (false) {\n"
|
|
|
|
" return 1;\n"
|
|
|
|
" } else {\n"
|
|
|
|
" return -1;\n"
|
|
|
|
" }\n"
|
|
|
|
"};\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"function f() {\n"
|
|
|
|
" if (false) {\n"
|
|
|
|
" return 1;\n"
|
|
|
|
" }\n"
|
|
|
|
"};\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"function f() {\n"
|
|
|
|
" var a = 1;\n"
|
|
|
|
" if (a) {\n"
|
|
|
|
" a += 1;\n"
|
|
|
|
" } else {\n"
|
|
|
|
" return 2;\n"
|
|
|
|
" }\n"
|
|
|
|
"};\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"function f(a) {\n"
|
|
|
|
" if (a <= 0) {\n"
|
|
|
|
" return 200;\n"
|
|
|
|
" } else {\n"
|
|
|
|
" return -200;\n"
|
|
|
|
" }\n"
|
|
|
|
"};\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f(99);\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"function f(a, b) { if (a in b) { return 200; } }"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f('prop', { prop: 'yes'});\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"function f(z) { var a = 0; var b = 0; if (a === 0.01) {\n"
|
|
|
|
REPEAT_64(" b = a; a = b;\n")
|
2016-05-11 12:21:56 +00:00
|
|
|
" return 200; } else { return -200; } } f(0.001);\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"function f() {\n"
|
|
|
|
" var a = 0; var b = 0;\n"
|
|
|
|
" if (a) {\n"
|
|
|
|
REPEAT_64(" b = a; a = b;\n")
|
|
|
|
" return 200; } else { return -200; }\n"
|
|
|
|
"};\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"function f(a, b) {\n"
|
|
|
|
" if (a == b) { return 1; }\n"
|
|
|
|
" if (a === b) { return 1; }\n"
|
|
|
|
" if (a < b) { return 1; }\n"
|
|
|
|
" if (a > b) { return 1; }\n"
|
|
|
|
" if (a <= b) { return 1; }\n"
|
|
|
|
" if (a >= b) { return 1; }\n"
|
|
|
|
" if (a in b) { return 1; }\n"
|
|
|
|
" if (a instanceof b) { return 1; }\n"
|
|
|
|
" return 0;\n"
|
|
|
|
"}\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f(1, 1);\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"function f() {\n"
|
|
|
|
" var a = 0;\n"
|
|
|
|
" if (a) {\n"
|
|
|
|
" return 20;\n"
|
|
|
|
" } else {\n"
|
|
|
|
" return -20;\n"
|
|
|
|
" }\n"
|
|
|
|
"};\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2016-08-15 13:10:41 +00:00
|
|
|
|
|
|
|
"function f(a, b) {\n"
|
|
|
|
" if (a == b || a < 0) {\n"
|
|
|
|
" return 1;\n"
|
|
|
|
" } else if (a > 0 && b > 0) {\n"
|
|
|
|
" return 0;\n"
|
|
|
|
" } else {\n"
|
|
|
|
" return -1;\n"
|
|
|
|
" }\n"
|
|
|
|
"};\n"
|
|
|
|
"f(-1, 1);\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("IfConditions.golden")));
|
2016-02-25 12:07:07 +00:00
|
|
|
}
|
2015-09-24 15:20:47 +00:00
|
|
|
|
2015-10-07 21:18:58 +00:00
|
|
|
TEST(DeclareGlobals) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
|
|
|
printer.set_top_level(true);
|
2015-10-21 13:00:31 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1;\n",
|
2015-10-21 13:00:31 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"function f() {}\n",
|
2015-10-21 13:00:31 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
"var a = 1;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"a=2;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"function f() {}\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2015-12-16 17:06:05 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("DeclareGlobals.golden")));
|
2015-12-16 17:06:05 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(BreakableBlocks) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
const char* snippets[] = {
|
|
|
|
"var x = 0;\n"
|
|
|
|
"label: {\n"
|
|
|
|
" x = x + 1;\n"
|
|
|
|
" break label;\n"
|
|
|
|
" x = x + 1;\n"
|
|
|
|
"}\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return x;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var sum = 0;\n"
|
|
|
|
"outer: {\n"
|
|
|
|
" for (var x = 0; x < 10; ++x) {\n"
|
|
|
|
" for (var y = 0; y < 3; ++y) {\n"
|
|
|
|
" ++sum;\n"
|
|
|
|
" if (x + y == 12) { break outer; }\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
"}\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return sum;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"outer: {\n"
|
|
|
|
" let y = 10;\n"
|
|
|
|
" function f() { return y; }\n"
|
|
|
|
" break outer;\n"
|
|
|
|
"}\n",
|
|
|
|
|
|
|
|
"let x = 1;\n"
|
|
|
|
"outer: {\n"
|
|
|
|
" inner: {\n"
|
|
|
|
" let y = 2;\n"
|
|
|
|
" function f() { return x + y; }\n"
|
|
|
|
" if (y) break outer;\n"
|
|
|
|
" y = 3;\n"
|
|
|
|
" }\n"
|
|
|
|
"}\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"x = 4;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("BreakableBlocks.golden")));
|
2016-02-25 12:07:07 +00:00
|
|
|
}
|
2015-12-16 17:06:05 +00:00
|
|
|
|
2015-10-01 15:04:09 +00:00
|
|
|
TEST(BasicLoops) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
|
|
|
"var x = 0;\n"
|
|
|
|
"while (false) { x = 99; break; continue; }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return x;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = 0;\n"
|
|
|
|
"while (false) {\n"
|
|
|
|
" x = x + 1;\n"
|
|
|
|
"};\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return x;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = 0;\n"
|
|
|
|
"var y = 1;\n"
|
|
|
|
"while (x < 10) {\n"
|
|
|
|
" y = y * 12;\n"
|
|
|
|
" x = x + 1;\n"
|
|
|
|
" if (x == 3) continue;\n"
|
|
|
|
" if (x == 4) break;\n"
|
|
|
|
"}\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return y;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var i = 0;\n"
|
|
|
|
"while (true) {\n"
|
|
|
|
" if (i < 0) continue;\n"
|
|
|
|
" if (i == 3) break;\n"
|
|
|
|
" if (i == 4) break;\n"
|
|
|
|
" if (i == 10) continue;\n"
|
|
|
|
" if (i == 5) break;\n"
|
|
|
|
" i = i + 1;\n"
|
|
|
|
"}\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return i;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var i = 0;\n"
|
|
|
|
"while (true) {\n"
|
|
|
|
" while (i < 3) {\n"
|
|
|
|
" if (i == 2) break;\n"
|
|
|
|
" i = i + 1;\n"
|
|
|
|
" }\n"
|
|
|
|
" i = i + 1;\n"
|
|
|
|
" break;\n"
|
|
|
|
"}\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return i;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = 10;\n"
|
|
|
|
"var y = 1;\n"
|
|
|
|
"while (x) {\n"
|
|
|
|
" y = y * 12;\n"
|
|
|
|
" x = x - 1;\n"
|
|
|
|
"}\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return y;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = 0; var y = 1;\n"
|
|
|
|
"do {\n"
|
|
|
|
" y = y * 10;\n"
|
|
|
|
" if (x == 5) break;\n"
|
|
|
|
" if (x == 6) continue;\n"
|
|
|
|
" x = x + 1;\n"
|
|
|
|
"} while (x < 10);\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return y;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = 10;\n"
|
|
|
|
"var y = 1;\n"
|
|
|
|
"do {\n"
|
|
|
|
" y = y * 12;\n"
|
|
|
|
" x = x - 1;\n"
|
|
|
|
"} while (x);\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return y;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = 0; var y = 1;\n"
|
|
|
|
"do {\n"
|
|
|
|
" y = y * 10;\n"
|
|
|
|
" if (x == 5) break;\n"
|
|
|
|
" x = x + 1;\n"
|
|
|
|
" if (x == 6) continue;\n"
|
|
|
|
"} while (false);\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return y;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = 0; var y = 1;\n"
|
|
|
|
"do {\n"
|
|
|
|
" y = y * 10;\n"
|
|
|
|
" if (x == 5) break;\n"
|
|
|
|
" x = x + 1;\n"
|
|
|
|
" if (x == 6) continue;\n"
|
|
|
|
"} while (true);\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return y;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = 0;\n"
|
|
|
|
"for (;;) {\n"
|
|
|
|
" if (x == 1) break;\n"
|
|
|
|
" if (x == 2) continue;\n"
|
|
|
|
" x = x + 1;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"for (var x = 0;;) {\n"
|
|
|
|
" if (x == 1) break;\n"
|
|
|
|
" if (x == 2) continue;\n"
|
|
|
|
" x = x + 1;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = 0;\n"
|
|
|
|
"for (;; x = x + 1) {\n"
|
|
|
|
" if (x == 1) break;\n"
|
|
|
|
" if (x == 2) continue;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"for (var x = 0;; x = x + 1) {\n"
|
|
|
|
" if (x == 1) break;\n"
|
|
|
|
" if (x == 2) continue;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var u = 0;\n"
|
|
|
|
"for (var i = 0; i < 100; i = i + 1) {\n"
|
|
|
|
" u = u + 1;\n"
|
|
|
|
" continue;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var y = 1;\n"
|
|
|
|
"for (var x = 10; x; --x) {\n"
|
|
|
|
" y = y * 12;\n"
|
|
|
|
"}\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return y;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = 0;\n"
|
|
|
|
"for (var i = 0; false; i++) {\n"
|
|
|
|
" x = x + 1;\n"
|
|
|
|
"};\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return x;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = 0;\n"
|
|
|
|
"for (var i = 0; true; ++i) {\n"
|
|
|
|
" x = x + 1;\n"
|
|
|
|
" if (x == 20) break;\n"
|
|
|
|
"};\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return x;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var a = 0;\n"
|
|
|
|
"while (a) {\n"
|
|
|
|
" { \n"
|
|
|
|
" let z = 1;\n"
|
|
|
|
" function f() { z = 2; }\n"
|
|
|
|
" if (z) continue;\n"
|
|
|
|
" z++;\n"
|
|
|
|
" }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("BasicLoops.golden")));
|
2015-10-01 15:04:09 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 19:08:11 +00:00
|
|
|
TEST(JumpsRequiringConstantWideOperands) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
|
|
|
REPEAT_256("var x = 0.1;\n")
|
|
|
|
REPEAT_32("var x = 0.2;\n")
|
|
|
|
REPEAT_16("var x = 0.3;\n")
|
|
|
|
REPEAT_8("var x = 0.4;\n")
|
|
|
|
"for (var i = 0; i < 3; i++) {\n"
|
|
|
|
" if (i == 1) continue;\n"
|
|
|
|
" if (i == 2) break;\n"
|
|
|
|
"}\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return 3;\n",
|
2016-02-04 12:33:13 +00:00
|
|
|
};
|
2016-01-05 19:08:11 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("JumpsRequiringConstantWideOperands.golden")));
|
2016-01-05 19:08:11 +00:00
|
|
|
}
|
|
|
|
|
2015-10-06 14:15:09 +00:00
|
|
|
TEST(UnaryOperators) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
|
|
|
"var x = 0;\n"
|
|
|
|
"while (x != 10) {\n"
|
|
|
|
" x = x + 10;\n"
|
|
|
|
"}\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return x;\n",
|
2015-10-28 09:49:20 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
"var x = false;\n"
|
|
|
|
"do {\n"
|
|
|
|
" x = !x;\n"
|
|
|
|
"} while(x == false);\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return x;\n",
|
2015-10-28 09:49:20 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
"var x = 101;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return void(x * 3);\n",
|
2015-10-28 09:49:20 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
"var x = 1234;\n"
|
|
|
|
"var y = void (x * x - 1);\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return y;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = 13;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return ~x;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = 13;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return +x;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = 13;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return -x;\n",
|
2015-11-03 17:03:27 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("UnaryOperators.golden")));
|
2015-11-03 17:03:27 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(Typeof) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
|
|
|
|
|
|
|
const char* snippets[] = {
|
|
|
|
"function f() {\n"
|
|
|
|
" var x = 13;\n"
|
|
|
|
" return typeof(x);\n"
|
|
|
|
"};",
|
2015-11-03 17:03:27 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
"var x = 13;\n"
|
|
|
|
"function f() {\n"
|
|
|
|
" return typeof(x);\n"
|
|
|
|
"};",
|
2015-10-06 14:15:09 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets, "", "\nf();"),
|
|
|
|
LoadGolden("Typeof.golden")));
|
2015-10-06 14:15:09 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(Delete) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2015-10-06 14:15:09 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = {x:13, y:14}; return delete a.x;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"'use strict'; var a = {x:13, y:14}; return delete a.x;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = {1:13, 2:14}; return delete a[2];\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 10; return delete a;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"'use strict';\n"
|
|
|
|
"var a = {1:10};\n"
|
|
|
|
"(function f1() {return a;});\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return delete a[1];\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return delete 'test';\n",
|
2016-02-04 12:33:13 +00:00
|
|
|
};
|
2015-10-28 09:49:20 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("Delete.golden")));
|
2015-10-28 09:49:20 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(GlobalDelete) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
|
|
|
|
|
|
|
const char* snippets[] = {
|
|
|
|
"var a = {x:13, y:14};\n"
|
|
|
|
"function f() {\n"
|
|
|
|
" return delete a.x;\n"
|
|
|
|
"};\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"a = {1:13, 2:14};\n"
|
|
|
|
"function f() {\n"
|
|
|
|
" 'use strict';\n"
|
|
|
|
" return delete a[1];\n"
|
|
|
|
"};\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var a = {x:13, y:14};\n"
|
|
|
|
"function f() {\n"
|
|
|
|
" return delete a;\n"
|
|
|
|
"};\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"b = 30;\n"
|
|
|
|
"function f() {\n"
|
|
|
|
" return delete b;\n"
|
|
|
|
"};\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("GlobalDelete.golden")));
|
2016-02-25 12:07:07 +00:00
|
|
|
}
|
2015-10-28 09:49:20 +00:00
|
|
|
|
2015-10-13 09:39:55 +00:00
|
|
|
TEST(FunctionLiterals) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2015-10-13 09:39:55 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"return function(){ }\n",
|
2015-10-13 09:39:55 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return (function(){ })()\n",
|
2015-10-13 14:00:40 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return (function(x){ return x; })(1)\n",
|
2015-10-16 16:14:23 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("FunctionLiterals.golden")));
|
2015-10-16 16:14:23 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(RegExpLiterals) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2015-10-16 16:14:23 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"return /ab+d/;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return /(\\w+)\\s(\\w+)/i;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return /ab+d/.exec('abdd');\n",
|
2015-12-09 11:53:07 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("RegExpLiterals.golden")));
|
2015-12-09 11:53:07 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(RegExpLiteralsWide) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2015-12-09 11:53:07 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
|
|
|
"var a;" //
|
|
|
|
REPEAT_256("\na = 1.23;") //
|
2016-05-11 12:21:56 +00:00
|
|
|
"\nreturn /ab+d/;\n",
|
2015-10-13 14:00:40 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("RegExpLiteralsWide.golden")));
|
2015-10-13 14:00:40 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(ArrayLiterals) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2015-10-14 10:10:01 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"return [ 1, 2 ];\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1; return [ a, a + 1 ];\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return [ [ 1, 2 ], [ 3 ] ];\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1; return [ [ a, 2 ], [ a + 2 ] ];\n",
|
2015-12-09 11:53:07 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("ArrayLiterals.golden")));
|
2015-12-09 11:53:07 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(ArrayLiteralsWide) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2015-12-09 11:53:07 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
|
|
|
"var a;" //
|
|
|
|
REPEAT_256("\na = 1.23;") //
|
2016-05-11 12:21:56 +00:00
|
|
|
"\nreturn [ 1 , 2 ];\n",
|
2015-10-14 10:10:01 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("ArrayLiteralsWide.golden")));
|
2015-10-14 10:10:01 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(ObjectLiterals) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2015-10-14 10:10:01 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"return { };\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return { name: 'string', val: 9.2 };\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1; return { name: 'string', val: a };\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1; return { val: a, val: a + 1 };\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return { func: function() { } };\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return { func(a) { return a; } };\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return { get a() { return 2; } };\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return { get a() { return this.x; }, set a(val) { this.x = val } };\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return { set b(val) { this.y = val } };\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1; return { 1: a };\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return { __proto__: null };\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 'test'; return { [a]: 1 };\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 'test'; return { val: a, [a]: 1 };\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 'test'; return { [a]: 1, __proto__: {} };\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var n = 'name'; return { [n]: 'val', get a() { }, set a(b) {} };\n",
|
2015-12-09 11:53:07 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("ObjectLiterals.golden")));
|
2015-12-09 11:53:07 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(ObjectLiteralsWide) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
|
|
|
"var a;" //
|
|
|
|
REPEAT_256("\na = 1.23;") //
|
2016-05-11 12:21:56 +00:00
|
|
|
"\nreturn { name: 'string', val: 9.2 };\n",
|
2015-10-21 13:00:31 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("ObjectLiteralsWide.golden")));
|
2015-10-21 13:00:31 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(TopLevelObjectLiterals) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
|
|
|
printer.set_top_level(true);
|
2015-10-21 13:00:31 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = { func: function() { } };\n",
|
2015-10-15 10:35:18 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("TopLevelObjectLiterals.golden")));
|
2015-10-15 10:35:18 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(TryCatch) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2015-10-15 10:35:18 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"try { return 1; } catch(e) { return 2; }\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var a;\n"
|
|
|
|
"try { a = 1 } catch(e1) {};\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"try { a = 2 } catch(e2) { a = 3 }\n",
|
2015-10-15 10:35:18 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("TryCatch.golden")));
|
2015-10-15 10:35:18 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(TryFinally) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
|
|
|
"var a = 1;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"try { a = 2; } finally { a = 3; }\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var a = 1;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"try { a = 2; } catch(e) { a = 20 } finally { a = 3; }\n",
|
2015-10-15 16:46:16 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
"var a; try {\n"
|
|
|
|
" try { a = 1 } catch(e) { a = 2 }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"} catch(e) { a = 20 } finally { a = 3; }\n",
|
2015-10-19 10:59:00 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("TryFinally.golden")));
|
2015-10-19 10:59:00 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(Throw) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"throw 1;\n",
|
2015-10-19 10:59:00 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"throw 'Error';\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1; if (a) { throw 'Error'; };\n",
|
2015-10-21 13:00:31 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(
|
|
|
|
CompareTexts(BuildActual(printer, snippets), LoadGolden("Throw.golden")));
|
2015-10-21 13:00:31 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(CallNew) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
2015-10-21 13:00:31 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
|
|
|
"function bar() { this.value = 0; }\n"
|
|
|
|
"function f() { return new bar(); }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2015-11-17 12:18:25 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
"function bar(x) { this.value = 18; this.x = x;}\n"
|
|
|
|
"function f() { return new bar(3); }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2015-11-17 12:18:25 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
"function bar(w, x, y, z) {\n"
|
|
|
|
" this.value = 18;\n"
|
|
|
|
" this.x = x;\n"
|
|
|
|
" this.y = y;\n"
|
|
|
|
" this.z = z;\n"
|
|
|
|
"}\n"
|
|
|
|
"function f() { return new bar(3, 4, 5); }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
};
|
2015-10-16 15:29:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("CallNew.golden")));
|
2016-02-25 12:07:07 +00:00
|
|
|
}
|
2016-01-11 16:37:53 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(ContextVariables) {
|
2016-01-11 16:37:53 +00:00
|
|
|
// The wide check below relies on MIN_CONTEXT_SLOTS + 3 + 249 == 256, if this
|
|
|
|
// ever changes, the REPEAT_XXX should be changed to output the correct number
|
|
|
|
// of unique variables to trigger the wide slot load / store.
|
|
|
|
STATIC_ASSERT(Context::MIN_CONTEXT_SLOTS + 3 + 249 == 256);
|
2015-10-16 15:29:07 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a; return function() { a = 1; };\n",
|
2015-10-16 15:29:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1; return function() { a = 2; };\n",
|
2015-10-16 15:29:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1; var b = 2; return function() { a = 2; b = 3 };\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a; (function() { a = 2; })(); return a;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"'use strict';\n"
|
|
|
|
"let a = 1;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"{ let b = 2; return function() { a + b; }; }\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"'use strict';\n"
|
2016-09-07 06:54:36 +00:00
|
|
|
REPEAT_250_UNIQUE_VARS()
|
2016-02-25 12:07:07 +00:00
|
|
|
"eval();\n"
|
|
|
|
"var b = 100;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return b\n",
|
2015-10-16 15:29:07 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("ContextVariables.golden")));
|
2015-10-16 15:29:07 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(ContextParameters) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
2015-10-22 20:40:20 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
|
|
|
"function f(arg1) { return function() { arg1 = 2; }; }",
|
|
|
|
|
|
|
|
"function f(arg1) { var a = function() { arg1 = 2; }; return arg1; }",
|
|
|
|
|
|
|
|
"function f(a1, a2, a3, a4) { return function() { a1 = a3; }; }",
|
|
|
|
|
|
|
|
"function f() { var self = this; return function() { self = 2; }; }",
|
2015-10-26 18:11:23 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets, "", "\nf();"),
|
|
|
|
LoadGolden("ContextParameters.golden")));
|
2015-10-26 18:11:23 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(OuterContextVariables) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
|
|
|
|
|
|
|
const char* snippets[] = {
|
|
|
|
"function Outer() {\n"
|
|
|
|
" var outerVar = 1;\n"
|
|
|
|
" function Inner(innerArg) {\n"
|
|
|
|
" this.innerFunc = function() { return outerVar * innerArg; }\n"
|
|
|
|
" }\n"
|
|
|
|
" this.getInnerFunc = function() { return new Inner(1).innerFunc; }\n"
|
|
|
|
"}\n"
|
|
|
|
"var f = new Outer().getInnerFunc();",
|
|
|
|
|
|
|
|
"function Outer() {\n"
|
|
|
|
" var outerVar = 1;\n"
|
|
|
|
" function Inner(innerArg) {\n"
|
|
|
|
" this.innerFunc = function() { outerVar = innerArg; }\n"
|
|
|
|
" }\n"
|
|
|
|
" this.getInnerFunc = function() { return new Inner(1).innerFunc; }\n"
|
|
|
|
"}\n"
|
|
|
|
"var f = new Outer().getInnerFunc();",
|
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets, "", "\nf();"),
|
|
|
|
LoadGolden("OuterContextVariables.golden")));
|
2016-02-25 12:07:07 +00:00
|
|
|
}
|
2015-10-26 18:11:23 +00:00
|
|
|
|
2015-10-22 20:40:20 +00:00
|
|
|
TEST(CountOperators) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1; return ++a;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1; return a++;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1; return --a;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1; return a--;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = { val: 1 }; return a.val++;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = { val: 1 }; return --a.val;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var name = 'var'; var a = { val: 1 }; return a[name]--;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var name = 'var'; var a = { val: 1 }; return ++a[name];\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1; var b = function() { return a }; return ++a;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1; var b = function() { return a }; return a--;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var idx = 1; var a = [1, 2]; return a[idx++] = 2;\n",
|
2015-10-22 20:40:20 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("CountOperators.golden")));
|
2015-10-22 20:40:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GlobalCountOperators) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
|
|
|
|
|
|
|
const char* snippets[] = {
|
|
|
|
"var global = 1;\n"
|
|
|
|
"function f() { return ++global; }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var global = 1;\n"
|
|
|
|
"function f() { return global--; }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"unallocated = 1;\n"
|
|
|
|
"function f() { 'use strict'; return --unallocated; }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"unallocated = 1;\n"
|
|
|
|
"function f() { return unallocated++; }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2015-10-22 20:40:20 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("GlobalCountOperators.golden")));
|
2015-10-22 20:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CompoundExpressions) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1; a += 2;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1; a /= 2;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = { val: 2 }; a.name *= 2;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = { 1: 2 }; a[1] ^= 2;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1; (function f() { return a; }); a |= 24;\n",
|
2015-10-22 20:42:22 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("CompoundExpressions.golden")));
|
2015-10-22 20:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GlobalCompoundExpressions) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
|
|
|
|
|
|
|
const char* snippets[] = {
|
|
|
|
"var global = 1;\n"
|
|
|
|
"function f() { return global &= 1; }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"unallocated = 1;\n"
|
|
|
|
"function f() { return unallocated += 1; }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"f();\n",
|
2015-10-22 20:42:22 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("GlobalCompoundExpressions.golden")));
|
2015-10-22 20:40:20 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 21:41:47 +00:00
|
|
|
TEST(CreateArguments) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
|
|
|
|
|
|
|
const char* snippets[] = {
|
|
|
|
"function f() { return arguments; }",
|
|
|
|
|
|
|
|
"function f() { return arguments[0]; }",
|
|
|
|
|
|
|
|
"function f() { 'use strict'; return arguments; }",
|
|
|
|
|
|
|
|
"function f(a) { return arguments[0]; }",
|
|
|
|
|
|
|
|
"function f(a, b, c) { return arguments; }",
|
|
|
|
|
|
|
|
"function f(a, b, c) { 'use strict'; return arguments; }",
|
2015-10-22 21:41:47 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets, "", "\nf();"),
|
|
|
|
LoadGolden("CreateArguments.golden")));
|
2015-10-22 21:41:47 +00:00
|
|
|
}
|
|
|
|
|
[runtime] Optimize and unify rest parameters.
Replace the somewhat awkward RestParamAccessStub, which would always
call into the runtime anyway with a proper FastNewRestParameterStub,
which is basically based on the code that was already there for strict
arguments object materialization. But for rest parameters we could
optimize even further (leading to 8-10x improvements for functions with
rest parameters), by fixing the internal formal parameter count:
Every SharedFunctionInfo has a formal_parameter_count field, which
specifies the number of formal parameters, and is used to decide whether
we need to create an arguments adaptor frame when calling a function
(i.e. if there's a mismatch between the actual and expected parameters).
Previously the formal_parameter_count included the rest parameter, which
was sort of unfortunate, as that meant that calling a function with only
the non-rest parameters still required an arguments adaptor (plus some
other oddities). Now with this CL we fix, so that we do no longer
include the rest parameter in that count. Thereby checking for rest
parameters is very efficient, as we only need to check whether there is
an arguments adaptor frame, and if not create an empty array, otherwise
check whether the arguments adaptor frame has more parameters than
specified by the formal_parameter_count.
The FastNewRestParameterStub is written in a way that it can be directly
used by Ignition as well, and with some tweaks to the TurboFan backends
and the CodeStubAssembler, we should be able to rewrite it as
TurboFanCodeStub in the near future.
Drive-by-fix: Refactor and unify the CreateArgumentsType which was
different in TurboFan and Ignition; now we have a single enum class
which is used in both TurboFan and Ignition.
R=jarin@chromium.org, rmcilroy@chromium.org
TBR=rossberg@chromium.org
BUG=v8:2159
LOG=n
Review URL: https://codereview.chromium.org/1676883002
Cr-Commit-Position: refs/heads/master@{#33809}
2016-02-08 10:08:21 +00:00
|
|
|
TEST(CreateRestParameter) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
|
|
|
|
|
|
|
const char* snippets[] = {
|
|
|
|
"function f(...restArgs) { return restArgs; }",
|
|
|
|
|
|
|
|
"function f(a, ...restArgs) { return restArgs; }",
|
|
|
|
|
|
|
|
"function f(a, ...restArgs) { return restArgs[0]; }",
|
|
|
|
|
|
|
|
"function f(a, ...restArgs) { return restArgs[0] + arguments[0]; }",
|
2016-02-04 10:02:34 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets, "", "\nf();"),
|
|
|
|
LoadGolden("CreateRestParameter.golden")));
|
2016-02-04 10:02:34 +00:00
|
|
|
}
|
2015-10-22 21:41:47 +00:00
|
|
|
|
2015-10-29 12:06:00 +00:00
|
|
|
TEST(ForIn) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"for (var p in null) {}\n",
|
2015-10-29 12:06:00 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"for (var p in undefined) {}\n",
|
2015-10-29 12:06:00 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"for (var p in undefined) {}\n",
|
2015-10-29 12:06:00 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
"var x = 'potatoes';\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"for (var p in x) { return p; }\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = 0;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"for (var p in [1,2,3]) { x += p; }\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = { 'a': 1, 'b': 2 };\n"
|
|
|
|
"for (x['a'] in [10, 20, 30]) {\n"
|
|
|
|
" if (x['a'] == 10) continue;\n"
|
|
|
|
" if (x['a'] == 20) break;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = [ 10, 11, 12 ] ;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"for (x[0] in [1,2,3]) { return x[3]; }\n",
|
2016-01-22 15:54:24 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(
|
|
|
|
CompareTexts(BuildActual(printer, snippets), LoadGolden("ForIn.golden")));
|
2016-01-22 15:54:24 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(ForOf) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"for (var p of [0, 1, 2]) {}\n",
|
2016-01-22 15:54:24 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
"var x = 'potatoes';\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"for (var p of x) { return p; }\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"for (var x of [10, 20, 30]) {\n"
|
|
|
|
" if (x == 10) continue;\n"
|
|
|
|
" if (x == 20) break;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = { 'a': 1, 'b': 2 };\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"for (x['a'] of [1,2,3]) { return x['a']; }\n",
|
2015-10-26 15:31:05 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(
|
|
|
|
CompareTexts(BuildActual(printer, snippets), LoadGolden("ForOf.golden")));
|
2015-10-26 15:31:05 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(Conditional) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"return 1 ? 2 : 3;\n",
|
2015-10-30 12:55:05 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"return 1 ? 2 ? 3 : 4 : 5;\n",
|
2016-08-15 13:10:41 +00:00
|
|
|
|
|
|
|
"return 0 < 1 ? 2 : 3;\n",
|
|
|
|
|
|
|
|
"var x = 0;\n"
|
|
|
|
"return x ? 2 : 3;\n",
|
2015-10-30 12:55:05 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("Conditional.golden")));
|
2015-10-30 12:55:05 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(Switch) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
|
|
|
"var a = 1;\n"
|
|
|
|
"switch(a) {\n"
|
|
|
|
" case 1: return 2;\n"
|
|
|
|
" case 2: return 3;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var a = 1;\n"
|
|
|
|
"switch(a) {\n"
|
|
|
|
" case 1: a = 2; break;\n"
|
|
|
|
" case 2: a = 3; break;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var a = 1;\n"
|
|
|
|
"switch(a) {\n"
|
|
|
|
" case 1: a = 2; // fall-through\n"
|
|
|
|
" case 2: a = 3; break;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var a = 1;\n"
|
|
|
|
"switch(a) {\n"
|
|
|
|
" case 2: break;\n"
|
|
|
|
" case 3: break;\n"
|
|
|
|
" default: a = 1; break;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var a = 1;\n"
|
|
|
|
"switch(typeof(a)) {\n"
|
|
|
|
" case 2: a = 1; break;\n"
|
|
|
|
" case 3: a = 2; break;\n"
|
|
|
|
" default: a = 3; break;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var a = 1;\n"
|
|
|
|
"switch(a) {\n"
|
|
|
|
" case typeof(a): a = 1; break;\n"
|
|
|
|
" default: a = 2; break;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var a = 1;\n"
|
|
|
|
"switch(a) {\n"
|
|
|
|
" case 1:\n"
|
|
|
|
REPEAT_64(" a = 2;\n")
|
|
|
|
" break;\n"
|
|
|
|
" case 2:\n"
|
|
|
|
" a = 3;\n"
|
|
|
|
" break;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var a = 1;\n"
|
|
|
|
"switch(a) {\n"
|
|
|
|
" case 1: \n"
|
|
|
|
" switch(a + 1) {\n"
|
|
|
|
" case 2 : a = 1; break;\n"
|
|
|
|
" default : a = 2; break;\n"
|
|
|
|
" } // fall-through\n"
|
|
|
|
" case 2: a = 3;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("Switch.golden")));
|
2016-02-25 12:07:07 +00:00
|
|
|
}
|
2015-11-03 11:27:54 +00:00
|
|
|
|
|
|
|
TEST(BasicBlockToBoolean) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1; if (a || a < 0) { return 1; }\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1; if (a && a < 0) { return 1; }\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1; a = (a || a < 0) ? 2 : 3;\n",
|
2015-11-03 11:27:54 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("BasicBlockToBoolean.golden")));
|
2015-11-03 11:27:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DeadCodeRemoval) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"return; var a = 1; a();\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"if (false) { return; }; var a = 1;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"if (true) { return 1; } else { return 2; };\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = 1; if (a) { return 1; }; return 2;\n",
|
2015-11-03 11:27:54 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("DeadCodeRemoval.golden")));
|
2015-11-03 11:27:54 +00:00
|
|
|
}
|
|
|
|
|
2015-11-06 15:00:26 +00:00
|
|
|
TEST(ThisFunction) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
|
|
|
|
|
|
|
const char* snippets[] = {
|
|
|
|
"var f;\n"
|
|
|
|
"f = function f() {};",
|
|
|
|
|
|
|
|
"var f;\n"
|
|
|
|
"f = function f() { return f; };",
|
2015-11-06 15:00:26 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets, "", "\nf();"),
|
|
|
|
LoadGolden("ThisFunction.golden")));
|
2015-11-06 15:00:26 +00:00
|
|
|
}
|
|
|
|
|
2015-11-06 15:45:54 +00:00
|
|
|
TEST(NewTarget) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2015-11-13 14:14:57 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"return new.target;\n",
|
2015-11-13 14:14:57 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"new.target;\n",
|
2015-11-06 15:45:54 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("NewTarget.golden")));
|
2015-11-06 15:45:54 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(RemoveRedundantLdar) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
|
|
|
"var ld_a = 1;\n" // This test is to check Ldar does not
|
|
|
|
"while(true) {\n" // get removed if the preceding Star is
|
|
|
|
" ld_a = ld_a + ld_a;\n" // in a different basicblock.
|
|
|
|
" if (ld_a > 10) break;\n"
|
|
|
|
"}\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return ld_a;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var ld_a = 1;\n"
|
|
|
|
"do {\n"
|
|
|
|
" ld_a = ld_a + ld_a;\n"
|
|
|
|
" if (ld_a > 10) continue;\n"
|
|
|
|
"} while(false);\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return ld_a;\n",
|
2015-11-20 11:17:10 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
"var ld_a = 1;\n"
|
|
|
|
" ld_a = ld_a + ld_a;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
" return ld_a;\n",
|
2016-02-04 12:33:13 +00:00
|
|
|
};
|
2015-11-20 11:17:10 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("RemoveRedundantLdar.golden")));
|
2015-11-20 11:17:10 +00:00
|
|
|
}
|
|
|
|
|
2016-12-06 11:32:09 +00:00
|
|
|
TEST(GenerateTestUndetectable) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
|
|
|
const char* snippets[] = {
|
|
|
|
"var obj_a = {val:1};\n"
|
|
|
|
"var b = 10;\n"
|
|
|
|
"if (obj_a == null) { b = 20;}\n"
|
|
|
|
"return b;\n",
|
2016-12-16 15:01:08 +00:00
|
|
|
|
2016-12-06 11:32:09 +00:00
|
|
|
"var obj_a = {val:1};\n"
|
|
|
|
"var b = 10;\n"
|
|
|
|
"if (obj_a == undefined) { b = 20;}\n"
|
|
|
|
"return b;\n",
|
2016-12-16 15:01:08 +00:00
|
|
|
|
2016-12-06 11:32:09 +00:00
|
|
|
"var obj_a = {val:1};\n"
|
|
|
|
"var b = 10;\n"
|
|
|
|
"if (obj_a != null) { b = 20;}\n"
|
|
|
|
"return b;\n",
|
2016-12-16 15:01:08 +00:00
|
|
|
|
2016-12-06 11:32:09 +00:00
|
|
|
"var obj_a = {val:1};\n"
|
|
|
|
"var b = 10;\n"
|
|
|
|
"if (obj_a != undefined) { b = 20;}\n"
|
2016-12-16 15:01:08 +00:00
|
|
|
"return b;\n",
|
|
|
|
|
|
|
|
"var obj_a = {val:1};\n"
|
|
|
|
"var b = 10;\n"
|
|
|
|
"if (obj_a === null) { b = 20;}\n"
|
|
|
|
"return b;\n",
|
|
|
|
|
|
|
|
"var obj_a = {val:1};\n"
|
|
|
|
"var b = 10;\n"
|
|
|
|
"if (obj_a === undefined) { b = 20;}\n"
|
|
|
|
"return b;\n",
|
|
|
|
|
|
|
|
"var obj_a = {val:1};\n"
|
|
|
|
"var b = 10;\n"
|
|
|
|
"if (obj_a !== null) { b = 20;}\n"
|
|
|
|
"return b;\n",
|
|
|
|
|
|
|
|
"var obj_a = {val:1};\n"
|
|
|
|
"var b = 10;\n"
|
|
|
|
"if (obj_a !== undefined) { b = 20;}\n"
|
2016-12-06 11:32:09 +00:00
|
|
|
"return b;\n"};
|
|
|
|
|
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("GenerateTestUndetectable.golden")));
|
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(AssignmentsInBinaryExpression) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
|
|
|
"var x = 0, y = 1;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return (x = 2, y = 3, x = 4, y = 5);\n",
|
2015-12-16 17:24:20 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
"var x = 55;\n"
|
|
|
|
"var y = (x = 100);\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return y;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = 55;\n"
|
|
|
|
"x = x + (x = 100) + (x = 101);\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return x;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = 55;\n"
|
|
|
|
"x = (x = 56) - x + (x = 57);\n"
|
|
|
|
"x++;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return x;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = 55;\n"
|
|
|
|
"var y = x + (x = 1) + (x = 2) + (x = 3);\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return y;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = 55;\n"
|
|
|
|
"var x = x + (x = 1) + (x = 2) + (x = 3);\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return x;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x = 10, y = 20;\n"
|
|
|
|
"return x + (x = 1) + (x + 1) * (y = 2) + (y = 3) + (x = 4) + (y = 5) + "
|
|
|
|
"y;\n",
|
|
|
|
|
|
|
|
"var x = 17;\n"
|
|
|
|
"return 1 + x + (x++) + (++x);\n",
|
2016-01-08 15:45:59 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("AssignmentsInBinaryExpression.golden")));
|
2016-01-08 15:45:59 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
TEST(Eval) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"return eval('1;');\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(
|
|
|
|
CompareTexts(BuildActual(printer, snippets), LoadGolden("Eval.golden")));
|
2016-02-25 12:07:07 +00:00
|
|
|
}
|
2016-01-08 15:45:59 +00:00
|
|
|
|
|
|
|
TEST(LookupSlot) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-09-16 13:26:44 +00:00
|
|
|
printer.set_test_function_name("f");
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-09-16 13:26:44 +00:00
|
|
|
// clang-format off
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"eval('var x = 10;'); return x;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"eval('var x = 10;'); return typeof x;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"x = 20; return eval('');\n",
|
2016-09-16 13:26:44 +00:00
|
|
|
|
|
|
|
"var x = 20;\n"
|
|
|
|
"f = function(){\n"
|
|
|
|
" eval('var x = 10');\n"
|
|
|
|
" return x;\n"
|
|
|
|
"}\n"
|
2016-09-20 10:31:24 +00:00
|
|
|
"f();\n",
|
|
|
|
|
|
|
|
"x = 20;\n"
|
|
|
|
"f = function(){\n"
|
|
|
|
" eval('var x = 10');\n"
|
|
|
|
" return x;\n"
|
|
|
|
"}\n"
|
2016-09-16 13:26:44 +00:00
|
|
|
"f();\n"
|
2016-01-08 15:45:59 +00:00
|
|
|
};
|
2016-09-16 13:26:44 +00:00
|
|
|
// clang-format on
|
2016-01-08 15:45:59 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("LookupSlot.golden")));
|
2016-01-12 13:11:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CallLookupSlot) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"g = function(){}; eval(''); return g();\n",
|
2016-01-12 13:11:27 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("CallLookupSlot.golden")));
|
2016-01-08 15:45:59 +00:00
|
|
|
}
|
|
|
|
|
2016-01-18 12:00:04 +00:00
|
|
|
// TODO(mythria): tests for variable/function declaration in lookup slots.
|
|
|
|
|
2015-12-16 17:24:20 +00:00
|
|
|
TEST(LookupSlotInEval) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
|
|
|
|
|
|
|
const char* snippets[] = {
|
|
|
|
"return x;",
|
|
|
|
|
|
|
|
"x = 10;",
|
|
|
|
|
|
|
|
"'use strict'; x = 10;",
|
|
|
|
|
|
|
|
"return typeof x;",
|
2015-12-16 17:24:20 +00:00
|
|
|
};
|
2016-01-05 11:36:26 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
std::string actual = BuildActual(printer, snippets,
|
|
|
|
"var f;\n"
|
|
|
|
"var x = 1;\n"
|
|
|
|
"function f1() {\n"
|
|
|
|
" eval(\"function t() { ",
|
|
|
|
|
|
|
|
" }; f = t; f();\");\n"
|
|
|
|
"}\n"
|
|
|
|
"f1();");
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(actual, LoadGolden("LookupSlotInEval.golden")));
|
2016-02-25 12:07:07 +00:00
|
|
|
}
|
2016-01-05 11:36:26 +00:00
|
|
|
|
|
|
|
TEST(LookupSlotWideInEval) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
|
|
|
|
|
|
|
const char* snippets[] = {
|
|
|
|
REPEAT_256(" \"var y = 2.3;\" +\n") //
|
|
|
|
" \"return x;\" +\n",
|
|
|
|
|
|
|
|
REPEAT_256(" \"var y = 2.3;\" +\n") //
|
|
|
|
" \"return typeof x;\" +\n",
|
|
|
|
|
|
|
|
REPEAT_256(" \"var y = 2.3;\" +\n") //
|
|
|
|
" \"x = 10;\" +\n",
|
|
|
|
|
|
|
|
" \"'use strict';\" +\n" //
|
|
|
|
REPEAT_256(" \"var y = 2.3;\" +\n") //
|
|
|
|
" \"x = 10;\" +\n",
|
2016-01-05 11:36:26 +00:00
|
|
|
};
|
2015-12-16 17:24:20 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
std::string actual = BuildActual(printer, snippets,
|
|
|
|
"var f;\n"
|
|
|
|
"var x = 1;\n"
|
|
|
|
"function f1() {\n"
|
|
|
|
" eval(\"function t() {\" +\n",
|
|
|
|
|
|
|
|
" \"};\" +\n"
|
|
|
|
" \"f = t; f();\"\n);\n"
|
|
|
|
"}\n"
|
|
|
|
"f1();");
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(actual, LoadGolden("LookupSlotWideInEval.golden")));
|
2016-02-25 12:07:07 +00:00
|
|
|
}
|
2015-12-23 09:11:13 +00:00
|
|
|
|
2016-01-08 15:45:59 +00:00
|
|
|
TEST(DeleteLookupSlotInEval) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
|
|
|
|
|
|
|
const char* snippets[] = {
|
|
|
|
"delete x;",
|
|
|
|
|
|
|
|
"return delete y;",
|
|
|
|
|
|
|
|
"return delete z;",
|
2015-12-23 09:11:13 +00:00
|
|
|
};
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
std::string actual = BuildActual(printer, snippets,
|
|
|
|
"var f;\n"
|
|
|
|
"var x = 1;\n"
|
|
|
|
"z = 10;\n"
|
|
|
|
"function f1() {\n"
|
|
|
|
" var y;\n"
|
|
|
|
" eval(\"function t() { ",
|
|
|
|
|
|
|
|
" }; f = t; f();\");\n"
|
|
|
|
"}\n"
|
|
|
|
"f1();");
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(actual, LoadGolden("DeleteLookupSlotInEval.golden")));
|
2015-12-23 09:11:13 +00:00
|
|
|
}
|
|
|
|
|
2016-01-26 13:55:28 +00:00
|
|
|
TEST(WideRegisters) {
|
|
|
|
// Prepare prologue that creates frame for lots of registers.
|
|
|
|
std::ostringstream os;
|
|
|
|
for (size_t i = 0; i < 157; ++i) {
|
|
|
|
os << "var x" << i << ";\n";
|
|
|
|
}
|
|
|
|
std::string prologue(os.str());
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
|
|
|
"x0 = x127;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return x0;\n",
|
2016-01-26 13:55:28 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
"x127 = x126;\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return x127;\n",
|
2016-02-02 14:31:35 +00:00
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
"if (x2 > 3) { return x129; }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return x128;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x0 = 0;\n"
|
|
|
|
"if (x129 == 3) { var x129 = x0; }\n"
|
|
|
|
"if (x2 > 3) { return x0; }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return x129;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x0 = 0;\n"
|
|
|
|
"var x1 = 0;\n"
|
|
|
|
"for (x128 = 0; x128 < 64; x128++) {"
|
|
|
|
" x1 += x128;"
|
|
|
|
"}"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return x128;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var x0 = 1234;\n"
|
|
|
|
"var x1 = 0;\n"
|
|
|
|
"for (x128 in x0) {"
|
|
|
|
" x1 += x128;"
|
|
|
|
"}"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return x1;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"x0 = %Add(x64, x63);\n"
|
|
|
|
"x1 = %Add(x27, x143);\n"
|
|
|
|
"%TheHole();\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"return x1;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets, prologue.c_str()),
|
|
|
|
LoadGolden("WideRegisters.golden")));
|
2016-01-26 13:55:28 +00:00
|
|
|
}
|
|
|
|
|
2016-02-08 14:14:35 +00:00
|
|
|
TEST(ConstVariable) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"const x = 10;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"const x = 10; return x;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"const x = ( x = 20);\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"const x = 10; x = 20;\n",
|
2016-02-08 14:14:35 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("ConstVariable.golden")));
|
2016-02-08 14:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LetVariable) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"let x = 10;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"let x = 10; return x;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"let x = (x = 20);\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"let x = 10; x = 20;\n",
|
2016-02-08 14:14:35 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("LetVariable.golden")));
|
2016-02-08 14:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ConstVariableContextSlot) {
|
|
|
|
// TODO(mythria): Add tests for initialization of this via super calls.
|
|
|
|
// TODO(mythria): Add tests that walk the context chain.
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"const x = 10; function f1() {return x;}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"const x = 10; function f1() {return x;} return x;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"const x = (x = 20); function f1() {return x;}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"const x = 10; x = 20; function f1() {return x;}\n",
|
2016-02-08 14:14:35 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("ConstVariableContextSlot.golden")));
|
2016-02-08 14:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LetVariableContextSlot) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"let x = 10; function f1() {return x;}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"let x = 10; function f1() {return x;} return x;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"let x = (x = 20); function f1() {return x;}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"let x = 10; x = 20; function f1() {return x;}\n",
|
2016-02-08 14:14:35 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("LetVariableContextSlot.golden")));
|
2016-02-08 14:14:35 +00:00
|
|
|
}
|
|
|
|
|
2016-01-26 17:18:20 +00:00
|
|
|
TEST(DoExpression) {
|
|
|
|
bool old_flag = FLAG_harmony_do_expressions;
|
|
|
|
FLAG_harmony_do_expressions = true;
|
|
|
|
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = do { }; return a;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"var a = do { var x = 100; }; return a;\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
"while(true) { var a = 10; a = do { ++a; break; }; a = 20; }\n",
|
2016-01-26 17:18:20 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("DoExpression.golden")));
|
2016-02-25 12:07:07 +00:00
|
|
|
|
2016-01-26 17:18:20 +00:00
|
|
|
FLAG_harmony_do_expressions = old_flag;
|
|
|
|
}
|
|
|
|
|
2016-02-03 14:41:19 +00:00
|
|
|
TEST(WithStatement) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"with ({x:42}) { return x; }\n",
|
2016-02-03 14:41:19 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("WithStatement.golden")));
|
2016-02-03 14:41:19 +00:00
|
|
|
}
|
|
|
|
|
2016-02-04 15:06:25 +00:00
|
|
|
TEST(DoDebugger) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
2016-05-11 12:21:56 +00:00
|
|
|
"debugger;\n",
|
2016-02-04 15:06:25 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("DoDebugger.golden")));
|
2016-02-04 15:06:25 +00:00
|
|
|
}
|
|
|
|
|
2016-02-09 11:43:23 +00:00
|
|
|
TEST(ClassDeclarations) {
|
2016-02-25 12:07:07 +00:00
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-02-25 12:07:07 +00:00
|
|
|
const char* snippets[] = {
|
|
|
|
"class Person {\n"
|
|
|
|
" constructor(name) { this.name = name; }\n"
|
|
|
|
" speak() { console.log(this.name + ' is speaking.'); }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"class person {\n"
|
|
|
|
" constructor(name) { this.name = name; }\n"
|
|
|
|
" speak() { console.log(this.name + ' is speaking.'); }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var n0 = 'a';\n"
|
|
|
|
"var n1 = 'b';\n"
|
|
|
|
"class N {\n"
|
|
|
|
" [n0]() { return n0; }\n"
|
|
|
|
" static [n1]() { return n1; }\n"
|
2016-05-11 12:21:56 +00:00
|
|
|
"}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
|
|
|
|
"var count = 0;\n"
|
|
|
|
"class C { constructor() { count++; }}\n"
|
|
|
|
"return new C();\n",
|
2016-12-07 10:34:15 +00:00
|
|
|
|
|
|
|
"(class {})\n"
|
|
|
|
"class E { static name () {}}\n",
|
2016-02-25 12:07:07 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("ClassDeclarations.golden")));
|
2016-02-04 17:47:08 +00:00
|
|
|
}
|
|
|
|
|
2016-03-16 14:41:05 +00:00
|
|
|
TEST(ClassAndSuperClass) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-03-16 14:41:05 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("test");
|
|
|
|
const char* snippets[] = {
|
|
|
|
"var test;\n"
|
|
|
|
"(function() {\n"
|
|
|
|
" class A {\n"
|
|
|
|
" method() { return 2; }\n"
|
|
|
|
" }\n"
|
|
|
|
" class B extends A {\n"
|
|
|
|
" method() { return super.method() + 1; }\n"
|
|
|
|
" }\n"
|
|
|
|
" test = new B().method;\n"
|
|
|
|
" test();\n"
|
|
|
|
"})();\n",
|
|
|
|
|
|
|
|
"var test;\n"
|
|
|
|
"(function() {\n"
|
|
|
|
" class A {\n"
|
|
|
|
" get x() { return 1; }\n"
|
|
|
|
" set x(val) { return; }\n"
|
|
|
|
" }\n"
|
|
|
|
" class B extends A {\n"
|
|
|
|
" method() { super.x = 2; return super.x; }\n"
|
|
|
|
" }\n"
|
|
|
|
" test = new B().method;\n"
|
|
|
|
" test();\n"
|
|
|
|
"})();\n",
|
|
|
|
|
|
|
|
"var test;\n"
|
|
|
|
"(function() {\n"
|
|
|
|
" class A {\n"
|
|
|
|
" constructor(x) { this.x_ = x; }\n"
|
|
|
|
" }\n"
|
|
|
|
" class B extends A {\n"
|
|
|
|
" constructor() { super(1); this.y_ = 2; }\n"
|
|
|
|
" }\n"
|
|
|
|
" test = new B().constructor;\n"
|
|
|
|
"})();\n",
|
|
|
|
|
|
|
|
"var test;\n"
|
|
|
|
"(function() {\n"
|
|
|
|
" class A {\n"
|
|
|
|
" constructor() { this.x_ = 1; }\n"
|
|
|
|
" }\n"
|
|
|
|
" class B extends A {\n"
|
|
|
|
" constructor() { super(); this.y_ = 2; }\n"
|
|
|
|
" }\n"
|
|
|
|
" test = new B().constructor;\n"
|
|
|
|
"})();\n",
|
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("ClassAndSuperClass.golden")));
|
2016-03-16 14:41:05 +00:00
|
|
|
}
|
2016-02-15 08:18:16 +00:00
|
|
|
|
2016-04-18 14:13:04 +00:00
|
|
|
TEST(Generators) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
2016-04-18 14:13:04 +00:00
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("f");
|
|
|
|
|
|
|
|
const char* snippets[] = {
|
2016-05-24 12:51:18 +00:00
|
|
|
"function* f() { }\n"
|
|
|
|
"f();\n",
|
2016-04-18 14:13:04 +00:00
|
|
|
|
2016-05-24 12:51:18 +00:00
|
|
|
"function* f() { yield 42 }\n"
|
|
|
|
"f();\n",
|
2016-04-18 14:13:04 +00:00
|
|
|
|
2016-05-24 12:51:18 +00:00
|
|
|
"function* f() { for (let x of [42]) yield x }\n"
|
|
|
|
"f();\n",
|
2016-04-18 14:13:04 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 12:21:56 +00:00
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("Generators.golden")));
|
2016-04-18 14:13:04 +00:00
|
|
|
}
|
|
|
|
|
2016-10-04 18:42:13 +00:00
|
|
|
TEST(Modules) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_module(true);
|
|
|
|
printer.set_top_level(true);
|
|
|
|
|
|
|
|
const char* snippets[] = {
|
|
|
|
"import \"bar\";\n",
|
|
|
|
|
|
|
|
"import {foo} from \"bar\";\n",
|
|
|
|
|
|
|
|
"import {foo as goo} from \"bar\";\n"
|
|
|
|
"goo(42);\n"
|
|
|
|
"{ let x; { goo(42) } };\n",
|
|
|
|
|
|
|
|
"export var foo = 42;\n"
|
|
|
|
"foo++;\n"
|
|
|
|
"{ let x; { foo++ } };\n",
|
|
|
|
|
|
|
|
"export let foo = 42;\n"
|
|
|
|
"foo++;\n"
|
|
|
|
"{ let x; { foo++ } };\n",
|
|
|
|
|
|
|
|
"export const foo = 42;\n"
|
|
|
|
"foo++;\n"
|
|
|
|
"{ let x; { foo++ } };\n",
|
|
|
|
|
|
|
|
"export default (function () {});\n",
|
|
|
|
|
|
|
|
"export default (class {});\n",
|
|
|
|
|
|
|
|
"export {foo as goo} from \"bar\"\n",
|
|
|
|
|
|
|
|
"export * from \"bar\"\n",
|
2016-11-02 09:30:24 +00:00
|
|
|
|
|
|
|
"import * as foo from \"bar\"\n"
|
|
|
|
"foo.f(foo, foo.x);\n",
|
2016-10-04 18:42:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("Modules.golden")));
|
|
|
|
}
|
|
|
|
|
2016-12-01 09:42:07 +00:00
|
|
|
TEST(SuperCallAndSpread) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
|
|
|
printer.set_wrap(false);
|
|
|
|
printer.set_test_function_name("test");
|
|
|
|
const char* snippets[] = {
|
|
|
|
"var test;\n"
|
|
|
|
"(function() {\n"
|
|
|
|
" class A {\n"
|
|
|
|
" constructor(...args) { this.baseArgs = args; }\n"
|
|
|
|
" }\n"
|
|
|
|
" class B extends A {}\n"
|
|
|
|
" test = new B(1, 2, 3).constructor;\n"
|
|
|
|
"})();\n",
|
|
|
|
|
|
|
|
"var test;\n"
|
|
|
|
"(function() {\n"
|
|
|
|
" class A {\n"
|
|
|
|
" constructor(...args) { this.baseArgs = args; }\n"
|
|
|
|
" }\n"
|
|
|
|
" class B extends A {\n"
|
|
|
|
" constructor(...args) { super(1, ...args); }\n"
|
|
|
|
" }\n"
|
|
|
|
" test = new B(1, 2, 3).constructor;\n"
|
|
|
|
"})();\n",
|
|
|
|
|
|
|
|
"var test;\n"
|
|
|
|
"(function() {\n"
|
|
|
|
" class A {\n"
|
|
|
|
" constructor(...args) { this.baseArgs = args; }\n"
|
|
|
|
" }\n"
|
|
|
|
" class B extends A {\n"
|
|
|
|
" constructor(...args) { super(1, ...args, 1); }\n"
|
|
|
|
" }\n"
|
|
|
|
" test = new B(1, 2, 3).constructor;\n"
|
|
|
|
"})();\n",
|
|
|
|
};
|
|
|
|
|
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("SuperCallAndSpread.golden")));
|
|
|
|
}
|
|
|
|
|
2017-01-23 09:03:35 +00:00
|
|
|
TEST(CallAndSpread) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
|
|
|
const char* snippets[] = {"Math.max(...[1, 2, 3]);\n",
|
|
|
|
"Math.max(0, ...[1, 2, 3]);\n",
|
|
|
|
"Math.max(0, ...[1, 2, 3], 4);\n"};
|
|
|
|
|
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("CallAndSpread.golden")));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(NewAndSpread) {
|
|
|
|
InitializedIgnitionHandleScope scope;
|
|
|
|
BytecodeExpectationsPrinter printer(CcTest::isolate());
|
|
|
|
const char* snippets[] = {
|
|
|
|
"class A { constructor(...args) { this.args = args; } }\n"
|
|
|
|
"new A(...[1, 2, 3]);\n",
|
|
|
|
|
|
|
|
"class A { constructor(...args) { this.args = args; } }\n"
|
|
|
|
"new A(0, ...[1, 2, 3]);\n",
|
|
|
|
|
|
|
|
"class A { constructor(...args) { this.args = args; } }\n"
|
|
|
|
"new A(0, ...[1, 2, 3], 4);\n"};
|
|
|
|
|
|
|
|
CHECK(CompareTexts(BuildActual(printer, snippets),
|
|
|
|
LoadGolden("NewAndSpread.golden")));
|
|
|
|
}
|
|
|
|
|
2015-08-18 13:46:43 +00:00
|
|
|
} // namespace interpreter
|
|
|
|
} // namespace internal
|
2015-09-30 13:46:56 +00:00
|
|
|
} // namespace v8
|