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.
|
|
|
|
|
|
|
|
#include "src/v8.h"
|
|
|
|
|
|
|
|
#include "src/compiler.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"
|
|
|
|
#include "test/cctest/cctest.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 {
|
|
|
|
|
|
|
|
class BytecodeGeneratorHelper {
|
|
|
|
public:
|
2015-08-27 10:32:26 +00:00
|
|
|
const char* kFunctionName = "f";
|
2015-08-18 13:46:43 +00:00
|
|
|
|
2015-09-28 18:05:56 +00:00
|
|
|
static const int kLastParamIndex =
|
2015-09-02 13:03:06 +00:00
|
|
|
-InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize;
|
|
|
|
|
2015-08-18 13:46:43 +00:00
|
|
|
BytecodeGeneratorHelper() {
|
|
|
|
i::FLAG_ignition = true;
|
2015-10-15 10:35:18 +00:00
|
|
|
i::FLAG_ignition_fake_try_catch = true;
|
2016-01-08 15:45:59 +00:00
|
|
|
i::FLAG_ignition_fallback_on_eval_and_catch = false;
|
2015-09-10 16:21:34 +00:00
|
|
|
i::FLAG_ignition_filter = StrDup(kFunctionName);
|
|
|
|
i::FLAG_always_opt = false;
|
2015-10-02 18:13:41 +00:00
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2016-01-11 23:09:27 +00:00
|
|
|
i::FLAG_legacy_const = true;
|
2015-08-18 13:46:43 +00:00
|
|
|
CcTest::i_isolate()->interpreter()->Initialize();
|
|
|
|
}
|
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
Isolate* isolate() { return CcTest::i_isolate(); }
|
2015-09-02 13:03:06 +00:00
|
|
|
Factory* factory() { return CcTest::i_isolate()->factory(); }
|
|
|
|
|
2015-10-07 21:18:58 +00:00
|
|
|
Handle<BytecodeArray> MakeTopLevelBytecode(const char* source) {
|
|
|
|
const char* old_ignition_filter = i::FLAG_ignition_filter;
|
|
|
|
i::FLAG_ignition_filter = "*";
|
|
|
|
Local<v8::Script> script = v8_compile(source);
|
|
|
|
i::FLAG_ignition_filter = old_ignition_filter;
|
|
|
|
i::Handle<i::JSFunction> js_function = v8::Utils::OpenHandle(*script);
|
|
|
|
return handle(js_function->shared()->bytecode_array(), CcTest::i_isolate());
|
|
|
|
}
|
|
|
|
|
2015-08-18 13:46:43 +00:00
|
|
|
Handle<BytecodeArray> MakeBytecode(const char* script,
|
|
|
|
const char* function_name) {
|
|
|
|
CompileRun(script);
|
2015-10-30 12:56:15 +00:00
|
|
|
v8::Local<v8::Context> context =
|
|
|
|
v8::Isolate::GetCurrent()->GetCurrentContext();
|
|
|
|
Local<Function> function = Local<Function>::Cast(
|
|
|
|
CcTest::global()->Get(context, v8_str(function_name)).ToLocalChecked());
|
2015-10-23 12:26:49 +00:00
|
|
|
i::Handle<i::JSFunction> js_function =
|
|
|
|
i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*function));
|
2015-08-18 13:46:43 +00:00
|
|
|
return handle(js_function->shared()->bytecode_array(), CcTest::i_isolate());
|
|
|
|
}
|
|
|
|
|
2015-12-16 17:24:20 +00:00
|
|
|
Handle<BytecodeArray> MakeBytecode(const char* script, const char* filter,
|
|
|
|
const char* function_name) {
|
|
|
|
const char* old_ignition_filter = i::FLAG_ignition_filter;
|
|
|
|
i::FLAG_ignition_filter = filter;
|
|
|
|
Handle<BytecodeArray> return_val = MakeBytecode(script, function_name);
|
|
|
|
i::FLAG_ignition_filter = old_ignition_filter;
|
|
|
|
return return_val;
|
|
|
|
}
|
|
|
|
|
2015-08-18 13:46:43 +00:00
|
|
|
Handle<BytecodeArray> MakeBytecodeForFunctionBody(const char* body) {
|
2016-01-05 19:08:11 +00:00
|
|
|
static const char kFormat[] = "function %s() { %s }\n%s();";
|
|
|
|
static const int kFormatLength = arraysize(kFormat);
|
|
|
|
int length = kFormatLength + 2 * StrLength(kFunctionName) + StrLength(body);
|
|
|
|
ScopedVector<char> program(length);
|
|
|
|
length = SNPrintF(program, kFormat, kFunctionName, body, kFunctionName);
|
|
|
|
CHECK_GT(length, 0);
|
2015-08-18 13:46:43 +00:00
|
|
|
return MakeBytecode(program.start(), kFunctionName);
|
|
|
|
}
|
2015-08-27 10:32:26 +00:00
|
|
|
|
|
|
|
Handle<BytecodeArray> MakeBytecodeForFunction(const char* function) {
|
2015-10-30 11:17:07 +00:00
|
|
|
ScopedVector<char> program(3072);
|
2015-08-27 10:32:26 +00:00
|
|
|
SNPrintF(program, "%s\n%s();", function, kFunctionName);
|
|
|
|
return MakeBytecode(program.start(), kFunctionName);
|
|
|
|
}
|
2015-10-26 18:11:23 +00:00
|
|
|
|
|
|
|
Handle<BytecodeArray> MakeBytecodeForFunctionNoFilter(const char* function) {
|
2015-10-30 11:17:07 +00:00
|
|
|
ScopedVector<char> program(3072);
|
2015-10-26 18:11:23 +00:00
|
|
|
SNPrintF(program, "%s\n%s();", function, kFunctionName);
|
2015-12-16 17:24:20 +00:00
|
|
|
return MakeBytecode(program.start(), "*", kFunctionName);
|
2015-10-26 18:11:23 +00:00
|
|
|
}
|
2015-08-18 13:46:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-09-24 11:48:22 +00:00
|
|
|
// Helper macros for handcrafting bytecode sequences.
|
|
|
|
#define B(x) static_cast<uint8_t>(Bytecode::k##x)
|
|
|
|
#define U8(x) static_cast<uint8_t>((x) & 0xff)
|
|
|
|
#define R(x) static_cast<uint8_t>(-(x) & 0xff)
|
2015-10-21 15:28:55 +00:00
|
|
|
#define A(x, n) R(helper.kLastParamIndex - (n) + 1 + (x))
|
|
|
|
#define THIS(n) A(0, n)
|
2015-10-02 18:13:41 +00:00
|
|
|
#if defined(V8_TARGET_LITTLE_ENDIAN)
|
|
|
|
#define U16(x) static_cast<uint8_t>((x) & 0xff), \
|
|
|
|
static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff)
|
2016-01-05 19:08:11 +00:00
|
|
|
#define U16I(x) static_cast<uint8_t>((x) & 0xff), \
|
|
|
|
static_cast<uint8_t>(((x++) >> kBitsPerByte) & 0xff)
|
2015-10-02 18:13:41 +00:00
|
|
|
#elif defined(V8_TARGET_BIG_ENDIAN)
|
|
|
|
#define U16(x) static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff), \
|
|
|
|
static_cast<uint8_t>((x) & 0xff)
|
2016-01-05 19:08:11 +00:00
|
|
|
#define U16I(x) static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff), \
|
|
|
|
static_cast<uint8_t>((x++) & 0xff)
|
2015-10-02 18:13:41 +00:00
|
|
|
#else
|
|
|
|
#error Unknown byte ordering
|
|
|
|
#endif
|
2015-09-24 11:48:22 +00:00
|
|
|
|
2016-01-11 16:37:53 +00:00
|
|
|
#define XSTR(A) #A
|
|
|
|
#define STR(A) XSTR(A)
|
|
|
|
|
2015-10-30 11:17:07 +00:00
|
|
|
#define COMMA() ,
|
|
|
|
#define SPACE()
|
2016-01-11 16:37:53 +00:00
|
|
|
#define UNIQUE_VAR() "var a" STR(__COUNTER__) " = 0;\n"
|
2015-10-30 11:17:07 +00:00
|
|
|
|
2016-01-05 19:08:11 +00:00
|
|
|
#define REPEAT_2(SEP, ...) \
|
2015-10-30 11:17:07 +00:00
|
|
|
__VA_ARGS__ SEP() __VA_ARGS__
|
|
|
|
#define REPEAT_4(SEP, ...) \
|
|
|
|
REPEAT_2(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__)
|
|
|
|
#define REPEAT_8(SEP, ...) \
|
|
|
|
REPEAT_4(SEP, __VA_ARGS__) SEP() REPEAT_4(SEP, __VA_ARGS__)
|
|
|
|
#define REPEAT_16(SEP, ...) \
|
|
|
|
REPEAT_8(SEP, __VA_ARGS__) SEP() REPEAT_8(SEP, __VA_ARGS__)
|
|
|
|
#define REPEAT_32(SEP, ...) \
|
|
|
|
REPEAT_16(SEP, __VA_ARGS__) SEP() REPEAT_16(SEP, __VA_ARGS__)
|
|
|
|
#define REPEAT_64(SEP, ...) \
|
|
|
|
REPEAT_32(SEP, __VA_ARGS__) SEP() REPEAT_32(SEP, __VA_ARGS__)
|
|
|
|
#define REPEAT_128(SEP, ...) \
|
|
|
|
REPEAT_64(SEP, __VA_ARGS__) SEP() REPEAT_64(SEP, __VA_ARGS__)
|
|
|
|
#define REPEAT_256(SEP, ...) \
|
|
|
|
REPEAT_128(SEP, __VA_ARGS__) SEP() REPEAT_128(SEP, __VA_ARGS__)
|
|
|
|
|
|
|
|
#define REPEAT_127(SEP, ...) \
|
|
|
|
REPEAT_64(SEP, __VA_ARGS__) SEP() REPEAT_32(SEP, __VA_ARGS__) SEP() \
|
|
|
|
REPEAT_16(SEP, __VA_ARGS__) SEP() REPEAT_8(SEP, __VA_ARGS__) SEP() \
|
|
|
|
REPEAT_4(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__) SEP() \
|
|
|
|
__VA_ARGS__
|
2015-09-24 11:48:22 +00:00
|
|
|
|
2016-01-11 16:37:53 +00:00
|
|
|
#define REPEAT_249(SEP, ...) \
|
|
|
|
REPEAT_127(SEP, __VA_ARGS__) SEP() REPEAT_64(SEP, __VA_ARGS__) SEP() \
|
|
|
|
REPEAT_32(SEP, __VA_ARGS__) SEP() REPEAT_16(SEP, __VA_ARGS__) SEP() \
|
|
|
|
REPEAT_8(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__)
|
|
|
|
|
|
|
|
#define REPEAT_249_UNIQUE_VARS() \
|
|
|
|
UNIQUE_VAR() REPEAT_127(UNIQUE_VAR) UNIQUE_VAR() REPEAT_64(UNIQUE_VAR) \
|
|
|
|
UNIQUE_VAR() REPEAT_32(UNIQUE_VAR) UNIQUE_VAR() REPEAT_16(UNIQUE_VAR) \
|
|
|
|
UNIQUE_VAR() REPEAT_8(UNIQUE_VAR) UNIQUE_VAR() REPEAT_2(UNIQUE_VAR)
|
|
|
|
|
2015-08-18 13:46:43 +00:00
|
|
|
// Structure for containing expected bytecode snippets.
|
2015-10-30 11:17:07 +00:00
|
|
|
template<typename T, int C = 6>
|
2015-08-18 13:46:43 +00:00
|
|
|
struct ExpectedSnippet {
|
2015-09-02 13:03:06 +00:00
|
|
|
const char* code_snippet;
|
2015-08-18 13:46:43 +00:00
|
|
|
int frame_size;
|
2015-08-27 10:32:26 +00:00
|
|
|
int parameter_count;
|
2015-08-18 13:46:43 +00:00
|
|
|
int bytecode_length;
|
2015-10-30 11:17:07 +00:00
|
|
|
const uint8_t bytecode[2048];
|
2015-08-28 15:40:52 +00:00
|
|
|
int constant_count;
|
2015-10-30 11:17:07 +00:00
|
|
|
T constants[C];
|
2015-08-18 13:46:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-09-24 11:48:22 +00:00
|
|
|
static void CheckConstant(int expected, Object* actual) {
|
|
|
|
CHECK_EQ(expected, Smi::cast(actual)->value());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void CheckConstant(double expected, Object* actual) {
|
|
|
|
CHECK_EQ(expected, HeapNumber::cast(actual)->value());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void CheckConstant(const char* expected, Object* actual) {
|
|
|
|
Handle<String> expected_string =
|
|
|
|
CcTest::i_isolate()->factory()->NewStringFromAsciiChecked(expected);
|
|
|
|
CHECK(String::cast(actual)->Equals(*expected_string));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-24 15:20:47 +00:00
|
|
|
static void CheckConstant(Handle<Object> expected, Object* actual) {
|
|
|
|
CHECK(actual == *expected || expected->StrictEquals(actual));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-13 09:39:55 +00:00
|
|
|
static void CheckConstant(InstanceType expected, Object* actual) {
|
|
|
|
CHECK_EQ(expected, HeapObject::cast(actual)->map()->instance_type());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-30 11:17:07 +00:00
|
|
|
template <typename T, int C>
|
|
|
|
static void CheckBytecodeArrayEqual(const ExpectedSnippet<T, C>& expected,
|
2015-10-22 20:42:22 +00:00
|
|
|
Handle<BytecodeArray> actual) {
|
2015-10-21 13:00:31 +00:00
|
|
|
CHECK_EQ(expected.frame_size, actual->frame_size());
|
|
|
|
CHECK_EQ(expected.parameter_count, actual->parameter_count());
|
|
|
|
CHECK_EQ(expected.bytecode_length, actual->length());
|
2015-10-16 15:29:07 +00:00
|
|
|
if (expected.constant_count == 0) {
|
2015-10-21 13:00:31 +00:00
|
|
|
CHECK_EQ(CcTest::heap()->empty_fixed_array(), actual->constant_pool());
|
2015-10-16 15:29:07 +00:00
|
|
|
} else {
|
2015-10-21 13:00:31 +00:00
|
|
|
CHECK_EQ(expected.constant_count, actual->constant_pool()->length());
|
2015-10-16 15:29:07 +00:00
|
|
|
for (int i = 0; i < expected.constant_count; i++) {
|
|
|
|
CheckConstant(expected.constants[i], actual->constant_pool()->get(i));
|
2015-09-24 11:48:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BytecodeArrayIterator iterator(actual);
|
|
|
|
int i = 0;
|
|
|
|
while (!iterator.done()) {
|
|
|
|
int bytecode_index = i++;
|
|
|
|
Bytecode bytecode = iterator.current_bytecode();
|
|
|
|
if (Bytecodes::ToByte(bytecode) != expected.bytecode[bytecode_index]) {
|
|
|
|
std::ostringstream stream;
|
|
|
|
stream << "Check failed: expected bytecode [" << bytecode_index
|
|
|
|
<< "] to be " << Bytecodes::ToString(static_cast<Bytecode>(
|
|
|
|
expected.bytecode[bytecode_index]))
|
|
|
|
<< " but got " << Bytecodes::ToString(bytecode);
|
|
|
|
FATAL(stream.str().c_str());
|
|
|
|
}
|
2015-10-01 17:22:58 +00:00
|
|
|
for (int j = 0; j < Bytecodes::NumberOfOperands(bytecode); ++j) {
|
|
|
|
OperandType operand_type = Bytecodes::GetOperandType(bytecode, j);
|
|
|
|
int operand_index = i;
|
|
|
|
i += static_cast<int>(Bytecodes::SizeOfOperand(operand_type));
|
|
|
|
uint32_t raw_operand = iterator.GetRawOperand(j, operand_type);
|
|
|
|
uint32_t expected_operand;
|
|
|
|
switch (Bytecodes::SizeOfOperand(operand_type)) {
|
|
|
|
case OperandSize::kNone:
|
|
|
|
UNREACHABLE();
|
2015-10-08 19:02:29 +00:00
|
|
|
return;
|
2015-10-01 17:22:58 +00:00
|
|
|
case OperandSize::kByte:
|
|
|
|
expected_operand =
|
|
|
|
static_cast<uint32_t>(expected.bytecode[operand_index]);
|
|
|
|
break;
|
|
|
|
case OperandSize::kShort:
|
2015-11-05 23:42:21 +00:00
|
|
|
expected_operand =
|
|
|
|
ReadUnalignedUInt16(&expected.bytecode[operand_index]);
|
2015-10-01 17:22:58 +00:00
|
|
|
break;
|
2015-10-08 19:02:29 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return;
|
2015-10-01 17:22:58 +00:00
|
|
|
}
|
|
|
|
if (raw_operand != expected_operand) {
|
2015-09-24 11:48:22 +00:00
|
|
|
std::ostringstream stream;
|
|
|
|
stream << "Check failed: expected operand [" << j << "] for bytecode ["
|
|
|
|
<< bytecode_index << "] to be "
|
2015-10-01 17:22:58 +00:00
|
|
|
<< static_cast<unsigned int>(expected_operand) << " but got "
|
2015-09-24 11:48:22 +00:00
|
|
|
<< static_cast<unsigned int>(raw_operand);
|
|
|
|
FATAL(stream.str().c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
iterator.Advance();
|
|
|
|
}
|
|
|
|
}
|
2015-08-18 13:46:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(PrimitiveReturnStatements) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
2015-09-24 11:48:22 +00:00
|
|
|
ExpectedSnippet<int> snippets[] = {
|
2015-09-08 15:02:44 +00:00
|
|
|
{"", 0, 1, 2, {B(LdaUndefined), B(Return)}, 0},
|
2015-08-28 15:40:52 +00:00
|
|
|
{"return;", 0, 1, 2, {B(LdaUndefined), B(Return)}, 0},
|
|
|
|
{"return null;", 0, 1, 2, {B(LdaNull), B(Return)}, 0},
|
|
|
|
{"return true;", 0, 1, 2, {B(LdaTrue), B(Return)}, 0},
|
|
|
|
{"return false;", 0, 1, 2, {B(LdaFalse), B(Return)}, 0},
|
|
|
|
{"return 0;", 0, 1, 2, {B(LdaZero), B(Return)}, 0},
|
|
|
|
{"return +1;", 0, 1, 3, {B(LdaSmi8), U8(1), B(Return)}, 0},
|
|
|
|
{"return -1;", 0, 1, 3, {B(LdaSmi8), U8(-1), B(Return)}, 0},
|
|
|
|
{"return +127;", 0, 1, 3, {B(LdaSmi8), U8(127), B(Return)}, 0},
|
|
|
|
{"return -128;", 0, 1, 3, {B(LdaSmi8), U8(-128), B(Return)}, 0},
|
2015-08-18 13:46:43 +00:00
|
|
|
};
|
|
|
|
|
2015-09-24 15:20:47 +00:00
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
2015-09-24 11:48:22 +00:00
|
|
|
Handle<BytecodeArray> bytecode_array =
|
2015-09-02 13:03:06 +00:00
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
2015-09-24 11:48:22 +00:00
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
2015-08-18 13:46:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(PrimitiveExpressions) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
2015-09-24 11:48:22 +00:00
|
|
|
ExpectedSnippet<int> snippets[] = {
|
2015-08-18 13:46:43 +00:00
|
|
|
{"var x = 0; return x;",
|
|
|
|
kPointerSize,
|
2015-08-27 10:32:26 +00:00
|
|
|
1,
|
2015-11-13 14:14:57 +00:00
|
|
|
4,
|
2015-10-15 09:11:40 +00:00
|
|
|
{B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Return)},
|
2015-10-12 10:45:19 +00:00
|
|
|
0},
|
2015-08-18 13:46:43 +00:00
|
|
|
{"var x = 0; return x + 3;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-08-27 10:32:26 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
10,
|
2015-10-15 09:11:40 +00:00
|
|
|
{B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(Return)},
|
2015-10-12 10:45:19 +00:00
|
|
|
0},
|
2015-10-12 13:35:57 +00:00
|
|
|
{"var x = 0; return x - 3;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-12 13:35:57 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
10,
|
2015-10-15 09:11:40 +00:00
|
|
|
{B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Sub), R(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(Return)},
|
2015-10-12 13:35:57 +00:00
|
|
|
0},
|
|
|
|
{"var x = 4; return x * 3;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-12 13:35:57 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
11,
|
2015-10-15 09:11:40 +00:00
|
|
|
{B(LdaSmi8), U8(4), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Mul), R(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(Return)},
|
2015-10-12 13:35:57 +00:00
|
|
|
0},
|
|
|
|
{"var x = 4; return x / 3;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-12 13:35:57 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
11,
|
2015-10-15 09:11:40 +00:00
|
|
|
{B(LdaSmi8), U8(4), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Div), R(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(Return)},
|
2015-10-12 13:35:57 +00:00
|
|
|
0},
|
|
|
|
{"var x = 4; return x % 3;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-12 13:35:57 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
11,
|
2015-10-15 09:11:40 +00:00
|
|
|
{B(LdaSmi8), U8(4), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Mod), R(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(Return)},
|
2015-10-12 13:35:57 +00:00
|
|
|
0},
|
|
|
|
{"var x = 1; return x | 2;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-12 13:35:57 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
11,
|
2015-10-15 09:11:40 +00:00
|
|
|
{B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(BitwiseOr), R(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(Return)},
|
2015-10-12 13:35:57 +00:00
|
|
|
0},
|
|
|
|
{"var x = 1; return x ^ 2;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-12 13:35:57 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
11,
|
2015-10-15 09:11:40 +00:00
|
|
|
{B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(BitwiseXor), R(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(Return)},
|
2015-10-12 13:35:57 +00:00
|
|
|
0},
|
|
|
|
{"var x = 1; return x & 2;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-12 13:35:57 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
11,
|
2015-10-15 09:11:40 +00:00
|
|
|
{B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(BitwiseAnd), R(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(Return)},
|
2015-10-12 13:35:57 +00:00
|
|
|
0},
|
2015-10-12 10:45:19 +00:00
|
|
|
{"var x = 10; return x << 3;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-12 10:45:19 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
11,
|
2015-10-15 09:11:40 +00:00
|
|
|
{B(LdaSmi8), U8(10), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(ShiftLeft), R(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(Return)},
|
2015-10-12 10:45:19 +00:00
|
|
|
0},
|
|
|
|
{"var x = 10; return x >> 3;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-12 10:45:19 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
11,
|
2015-10-15 09:11:40 +00:00
|
|
|
{B(LdaSmi8), U8(10), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(ShiftRight), R(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(Return)},
|
2015-10-12 10:45:19 +00:00
|
|
|
0},
|
|
|
|
{"var x = 10; return x >>> 3;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-12 10:45:19 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
11,
|
2015-10-15 09:11:40 +00:00
|
|
|
{B(LdaSmi8), U8(10), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(ShiftRightLogical), R(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(Return)},
|
|
|
|
0},
|
|
|
|
{"var x = 0; return (x, 3);",
|
2016-01-13 15:40:32 +00:00
|
|
|
1 * kPointerSize,
|
2015-10-15 09:11:40 +00:00
|
|
|
1,
|
2015-10-21 15:28:55 +00:00
|
|
|
6,
|
2015-10-15 09:11:40 +00:00
|
|
|
{B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Return)},
|
|
|
|
0}};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(LogicalExpressions) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
ExpectedSnippet<int> snippets[] = {
|
|
|
|
{"var x = 0; return x || 3;",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
2015-11-13 14:14:57 +00:00
|
|
|
8,
|
2015-10-15 09:11:40 +00:00
|
|
|
{B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(JumpIfToBooleanTrue), U8(4), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Return)},
|
|
|
|
0},
|
2015-10-30 16:48:18 +00:00
|
|
|
{"var x = 0; return (x == 1) || 3;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-30 16:48:18 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
14,
|
2015-10-30 16:48:18 +00:00
|
|
|
{B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-10-30 16:48:18 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(1), //
|
2015-10-30 16:48:18 +00:00
|
|
|
B(JumpIfTrue), U8(4), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Return)},
|
|
|
|
0},
|
2015-10-15 09:11:40 +00:00
|
|
|
{"var x = 0; return x && 3;",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
2015-11-13 14:14:57 +00:00
|
|
|
8,
|
2015-10-15 09:11:40 +00:00
|
|
|
{B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(JumpIfToBooleanFalse), U8(4), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Return)},
|
|
|
|
0},
|
2015-10-30 16:48:18 +00:00
|
|
|
{"var x = 0; return (x == 0) && 3;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-30 16:48:18 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
13,
|
2015-10-30 16:48:18 +00:00
|
|
|
{B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-10-30 16:48:18 +00:00
|
|
|
B(LdaZero), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(1), //
|
2015-10-30 16:48:18 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Return)},
|
|
|
|
0},
|
2015-10-21 15:28:55 +00:00
|
|
|
{"var x = 0; return x || (1, 2, 3);",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
2015-11-13 14:14:57 +00:00
|
|
|
8,
|
2015-10-21 15:28:55 +00:00
|
|
|
{B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(JumpIfToBooleanTrue), U8(4), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Return)},
|
|
|
|
0},
|
|
|
|
{"var a = 2, b = 3, c = 4; return a || (a, b, a, b, c = 5, 3);",
|
|
|
|
3 * kPointerSize,
|
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
31,
|
|
|
|
{B(LdaSmi8), U8(2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(4), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(JumpIfToBooleanTrue), U8(16), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(LdaSmi8), U8(5), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
2015-10-21 15:28:55 +00:00
|
|
|
B(Return)},
|
|
|
|
0},
|
2015-10-15 09:11:40 +00:00
|
|
|
{"var x = 1; var a = 2, b = 3; return x || ("
|
2015-10-30 11:17:07 +00:00
|
|
|
REPEAT_32(SPACE, "a = 1, b = 2, ")
|
2015-10-15 09:11:40 +00:00
|
|
|
"3);",
|
|
|
|
3 * kPointerSize,
|
|
|
|
1,
|
2015-10-30 11:17:07 +00:00
|
|
|
275,
|
2015-10-15 09:11:40 +00:00
|
|
|
{B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(JumpIfToBooleanTrueConstant), U8(0), //
|
2015-10-30 11:17:07 +00:00
|
|
|
REPEAT_32(COMMA, //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Star), R(2)), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Return)},
|
|
|
|
1,
|
2015-10-30 11:17:07 +00:00
|
|
|
{260, 0, 0, 0}},
|
2015-10-15 09:11:40 +00:00
|
|
|
{"var x = 0; var a = 2, b = 3; return x && ("
|
2015-10-30 11:17:07 +00:00
|
|
|
REPEAT_32(SPACE, "a = 1, b = 2, ")
|
2015-10-15 09:11:40 +00:00
|
|
|
"3);",
|
|
|
|
3 * kPointerSize,
|
|
|
|
1,
|
2015-10-30 11:17:07 +00:00
|
|
|
274,
|
2015-10-15 09:11:40 +00:00
|
|
|
{B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(JumpIfToBooleanFalseConstant), U8(0), //
|
2015-10-30 11:17:07 +00:00
|
|
|
REPEAT_32(COMMA, //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Star), R(2)), //
|
2015-10-30 11:17:07 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Return)}, //
|
2015-10-15 09:11:40 +00:00
|
|
|
1,
|
2015-10-30 11:17:07 +00:00
|
|
|
{260, 0, 0, 0}},
|
2015-10-30 16:48:18 +00:00
|
|
|
{"var x = 1; var a = 2, b = 3; return (x > 3) || ("
|
|
|
|
REPEAT_32(SPACE, "a = 1, b = 2, ")
|
|
|
|
"3);",
|
2016-01-13 15:40:32 +00:00
|
|
|
4 * kPointerSize,
|
2015-10-30 16:48:18 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
281,
|
2015-10-30 16:48:18 +00:00
|
|
|
{B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Star), R(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(3), //
|
2015-10-30 16:48:18 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestGreaterThan), R(3), //
|
2015-10-30 16:48:18 +00:00
|
|
|
B(JumpIfTrueConstant), U8(0), //
|
|
|
|
REPEAT_32(COMMA, //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Star), R(2)), //
|
2015-10-30 16:48:18 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Return)},
|
|
|
|
1,
|
|
|
|
{260, 0, 0, 0}},
|
|
|
|
{"var x = 0; var a = 2, b = 3; return (x < 5) && ("
|
|
|
|
REPEAT_32(SPACE, "a = 1, b = 2, ")
|
|
|
|
"3);",
|
2016-01-13 15:40:32 +00:00
|
|
|
4 * kPointerSize,
|
2015-10-30 16:48:18 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
280,
|
2015-10-30 16:48:18 +00:00
|
|
|
{B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Star), R(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(3), //
|
2015-10-30 16:48:18 +00:00
|
|
|
B(LdaSmi8), U8(5), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestLessThan), R(3), //
|
2015-10-30 16:48:18 +00:00
|
|
|
B(JumpIfFalseConstant), U8(0), //
|
|
|
|
REPEAT_32(COMMA, //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Star), R(2)), //
|
2015-10-30 16:48:18 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Return)},
|
|
|
|
1,
|
|
|
|
{260, 0, 0, 0}},
|
2015-10-15 09:11:40 +00:00
|
|
|
{"return 0 && 3;",
|
|
|
|
0 * kPointerSize,
|
|
|
|
1,
|
|
|
|
2,
|
2015-10-21 15:28:55 +00:00
|
|
|
{B(LdaZero), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(Return)},
|
|
|
|
0},
|
|
|
|
{"return 1 || 3;",
|
|
|
|
0 * kPointerSize,
|
|
|
|
1,
|
|
|
|
3,
|
2015-10-21 15:28:55 +00:00
|
|
|
{B(LdaSmi8), U8(1), //
|
2015-10-15 09:11:40 +00:00
|
|
|
B(Return)},
|
|
|
|
0},
|
|
|
|
{"var x = 1; return x && 3 || 0, 1;",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
2015-11-13 14:14:57 +00:00
|
|
|
14,
|
2015-10-15 09:11:40 +00:00
|
|
|
{B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(JumpIfToBooleanFalse), U8(4), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(JumpIfToBooleanTrue), U8(3), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Return)},
|
2015-10-12 10:45:19 +00:00
|
|
|
0}};
|
2015-08-18 13:46:43 +00:00
|
|
|
|
2015-09-24 15:20:47 +00:00
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
2015-09-24 11:48:22 +00:00
|
|
|
Handle<BytecodeArray> bytecode_array =
|
2015-09-02 13:03:06 +00:00
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
2015-09-24 11:48:22 +00:00
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
2015-08-27 10:32:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(Parameters) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
2015-09-24 11:48:22 +00:00
|
|
|
ExpectedSnippet<int> snippets[] = {
|
2015-08-27 10:32:26 +00:00
|
|
|
{"function f() { return this; }",
|
2015-10-21 15:28:55 +00:00
|
|
|
0,
|
|
|
|
1,
|
|
|
|
3,
|
|
|
|
{B(Ldar), THIS(1), B(Return)},
|
|
|
|
0},
|
2015-08-27 10:32:26 +00:00
|
|
|
{"function f(arg1) { return arg1; }",
|
2015-10-21 15:28:55 +00:00
|
|
|
0,
|
|
|
|
2,
|
|
|
|
3,
|
|
|
|
{B(Ldar), A(1, 2), B(Return)},
|
|
|
|
0},
|
2015-08-27 10:32:26 +00:00
|
|
|
{"function f(arg1) { return this; }",
|
2015-10-21 15:28:55 +00:00
|
|
|
0,
|
|
|
|
2,
|
|
|
|
3,
|
|
|
|
{B(Ldar), THIS(2), B(Return)},
|
|
|
|
0},
|
2015-08-27 10:32:26 +00:00
|
|
|
{"function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return arg4; }",
|
2015-10-21 15:28:55 +00:00
|
|
|
0,
|
|
|
|
8,
|
|
|
|
3,
|
|
|
|
{B(Ldar), A(4, 8), B(Return)},
|
|
|
|
0},
|
2015-08-27 10:32:26 +00:00
|
|
|
{"function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return this; }",
|
2015-10-21 15:28:55 +00:00
|
|
|
0,
|
|
|
|
8,
|
|
|
|
3,
|
|
|
|
{B(Ldar), THIS(8), B(Return)},
|
|
|
|
0},
|
2015-10-07 21:18:58 +00:00
|
|
|
{"function f(arg1) { arg1 = 1; }",
|
2015-10-21 15:28:55 +00:00
|
|
|
0,
|
|
|
|
2,
|
|
|
|
6,
|
|
|
|
{B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), A(1, 2), //
|
|
|
|
B(LdaUndefined), //
|
2015-10-07 21:18:58 +00:00
|
|
|
B(Return)},
|
|
|
|
0},
|
|
|
|
{"function f(arg1, arg2, arg3, arg4) { arg2 = 1; }",
|
2015-10-21 15:28:55 +00:00
|
|
|
0,
|
|
|
|
5,
|
|
|
|
6,
|
|
|
|
{B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), A(2, 5), //
|
|
|
|
B(LdaUndefined), //
|
2015-10-07 21:18:58 +00:00
|
|
|
B(Return)},
|
|
|
|
0},
|
2015-08-27 10:32:26 +00:00
|
|
|
};
|
|
|
|
|
2015-09-24 15:20:47 +00:00
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
2015-09-24 11:48:22 +00:00
|
|
|
Handle<BytecodeArray> bytecode_array =
|
2015-09-02 13:03:06 +00:00
|
|
|
helper.MakeBytecodeForFunction(snippets[i].code_snippet);
|
2015-09-24 11:48:22 +00:00
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
2015-08-18 13:46:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-28 15:40:52 +00:00
|
|
|
|
2015-09-24 15:20:47 +00:00
|
|
|
TEST(IntegerConstants) {
|
2015-08-28 15:40:52 +00:00
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
2015-09-24 15:20:47 +00:00
|
|
|
ExpectedSnippet<int> snippets[] = {
|
|
|
|
{"return 12345678;",
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
3,
|
|
|
|
{
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{12345678}},
|
|
|
|
{"var a = 1234; return 5678;",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
7,
|
|
|
|
{
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaConstant), U8(1), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
2,
|
|
|
|
{1234, 5678}},
|
|
|
|
{"var a = 1234; return 1234;",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
7,
|
|
|
|
{
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{1234}}};
|
2015-08-28 15:40:52 +00:00
|
|
|
|
2015-09-24 15:20:47 +00:00
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
2015-09-24 11:48:22 +00:00
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
2015-08-28 15:40:52 +00:00
|
|
|
}
|
2015-09-24 15:20:47 +00:00
|
|
|
}
|
2015-08-28 15:40:52 +00:00
|
|
|
|
|
|
|
|
2015-09-24 15:20:47 +00:00
|
|
|
TEST(HeapNumberConstants) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
2015-10-30 11:17:07 +00:00
|
|
|
int wide_idx = 0;
|
|
|
|
|
|
|
|
ExpectedSnippet<double, 257> snippets[] = {
|
2015-09-24 15:20:47 +00:00
|
|
|
{"return 1.2;",
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
3,
|
|
|
|
{
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{1.2}},
|
|
|
|
{"var a = 1.2; return 2.6;",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
7,
|
|
|
|
{
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaConstant), U8(1), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
2,
|
|
|
|
{1.2, 2.6}},
|
|
|
|
{"var a = 3.14; return 3.14;",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
7,
|
|
|
|
{
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaConstant), U8(1), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
2,
|
2015-10-30 11:17:07 +00:00
|
|
|
{3.14, 3.14}},
|
|
|
|
{"var a;"
|
|
|
|
REPEAT_256(SPACE, " a = 1.414;")
|
|
|
|
" a = 3.14;",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
1031,
|
|
|
|
{
|
|
|
|
REPEAT_256(COMMA, //
|
|
|
|
B(LdaConstant), U8(wide_idx++), //
|
|
|
|
B(Star), R(0)), //
|
2015-11-04 19:38:50 +00:00
|
|
|
B(LdaConstantWide), U16(wide_idx), //
|
2015-10-30 11:17:07 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
257,
|
|
|
|
{REPEAT_256(COMMA, 1.414),
|
|
|
|
3.14}}
|
|
|
|
};
|
2015-09-24 15:20:47 +00:00
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
2015-08-28 15:40:52 +00:00
|
|
|
}
|
2015-09-24 15:20:47 +00:00
|
|
|
}
|
2015-08-28 15:40:52 +00:00
|
|
|
|
|
|
|
|
2015-09-24 15:20:47 +00:00
|
|
|
TEST(StringConstants) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
ExpectedSnippet<const char*> snippets[] = {
|
|
|
|
{"return \"This is a string\";",
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
3,
|
|
|
|
{
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"This is a string"}},
|
|
|
|
{"var a = \"First string\"; return \"Second string\";",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
7,
|
|
|
|
{
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaConstant), U8(1), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
2,
|
|
|
|
{"First string", "Second string"}},
|
|
|
|
{"var a = \"Same string\"; return \"Same string\";",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
7,
|
|
|
|
{
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"Same string"}}};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
2015-08-28 15:40:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-02 13:03:06 +00:00
|
|
|
TEST(PropertyLoads) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
2015-10-01 13:48:05 +00:00
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
FeedbackVectorSpec feedback_spec(&zone);
|
|
|
|
FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot();
|
|
|
|
FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot();
|
2015-09-02 13:03:06 +00:00
|
|
|
|
|
|
|
Handle<i::TypeFeedbackVector> vector =
|
2015-10-07 10:33:22 +00:00
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
|
2015-09-02 13:03:06 +00:00
|
|
|
|
2015-10-30 11:17:07 +00:00
|
|
|
// These are a hack used by the LoadICXXXWide tests below.
|
|
|
|
int wide_idx_1 = vector->GetIndex(slot1) - 2;
|
|
|
|
int wide_idx_2 = vector->GetIndex(slot1) - 2;
|
|
|
|
int wide_idx_3 = vector->GetIndex(slot1) - 2;
|
|
|
|
int wide_idx_4 = vector->GetIndex(slot1) - 2;
|
|
|
|
|
2015-09-02 13:03:06 +00:00
|
|
|
ExpectedSnippet<const char*> snippets[] = {
|
|
|
|
{"function f(a) { return a.name; }\nf({name : \"test\"})",
|
2016-01-13 15:40:32 +00:00
|
|
|
1 * kPointerSize,
|
2015-09-24 15:20:47 +00:00
|
|
|
2,
|
2016-01-13 15:40:32 +00:00
|
|
|
9,
|
2015-09-02 13:03:06 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LoadICSloppy), R(0), U8(0), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(Return), //
|
2015-09-02 13:03:06 +00:00
|
|
|
},
|
2015-09-24 15:20:47 +00:00
|
|
|
1,
|
|
|
|
{"name"}},
|
2015-09-02 13:03:06 +00:00
|
|
|
{"function f(a) { return a[\"key\"]; }\nf({key : \"test\"})",
|
2016-01-13 15:40:32 +00:00
|
|
|
1 * kPointerSize,
|
2015-09-24 15:20:47 +00:00
|
|
|
2,
|
2016-01-13 15:40:32 +00:00
|
|
|
9,
|
2015-09-02 13:03:06 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LoadICSloppy), R(0), U8(0), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(Return) //
|
2015-09-02 13:03:06 +00:00
|
|
|
},
|
2015-09-24 15:20:47 +00:00
|
|
|
1,
|
|
|
|
{"key"}},
|
2015-09-02 13:03:06 +00:00
|
|
|
{"function f(a) { return a[100]; }\nf({100 : \"test\"})",
|
2016-01-13 15:40:32 +00:00
|
|
|
1 * kPointerSize,
|
2015-09-24 15:20:47 +00:00
|
|
|
2,
|
2016-01-13 15:40:32 +00:00
|
|
|
10,
|
2015-09-02 13:03:06 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(100), //
|
|
|
|
B(KeyedLoadICSloppy), R(0), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(Return) //
|
2015-09-24 15:20:47 +00:00
|
|
|
},
|
|
|
|
0},
|
2015-09-02 13:03:06 +00:00
|
|
|
{"function f(a, b) { return a[b]; }\nf({arg : \"test\"}, \"arg\")",
|
2016-01-13 15:40:32 +00:00
|
|
|
1 * kPointerSize,
|
2015-09-24 15:20:47 +00:00
|
|
|
3,
|
2016-01-13 15:40:32 +00:00
|
|
|
10,
|
2015-09-02 13:03:06 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 3), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(KeyedLoadICSloppy), R(0), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(Return) //
|
2015-09-24 15:20:47 +00:00
|
|
|
},
|
|
|
|
0},
|
2015-09-02 13:03:06 +00:00
|
|
|
{"function f(a) { var b = a.name; return a[-124]; }\n"
|
|
|
|
"f({\"-124\" : \"test\", name : 123 })",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-09-24 15:20:47 +00:00
|
|
|
2,
|
2016-01-13 15:40:32 +00:00
|
|
|
20,
|
2015-09-02 13:03:06 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LoadICSloppy), R(1), U8(0), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(-124), //
|
|
|
|
B(KeyedLoadICSloppy), R(1), U8(vector->GetIndex(slot2)), //
|
|
|
|
B(Return), //
|
2015-09-02 13:03:06 +00:00
|
|
|
},
|
2015-09-24 15:20:47 +00:00
|
|
|
1,
|
2015-10-07 07:54:07 +00:00
|
|
|
{"name"}},
|
|
|
|
{"function f(a) { \"use strict\"; return a.name; }\nf({name : \"test\"})",
|
2016-01-13 15:40:32 +00:00
|
|
|
1 * kPointerSize,
|
2015-10-07 07:54:07 +00:00
|
|
|
2,
|
2016-01-13 15:40:32 +00:00
|
|
|
9,
|
2015-10-07 07:54:07 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LoadICStrict), R(0), U8(0), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(Return), //
|
2015-10-07 07:54:07 +00:00
|
|
|
},
|
2015-10-21 15:28:55 +00:00
|
|
|
1,
|
|
|
|
{"name"}},
|
2015-12-09 08:32:56 +00:00
|
|
|
{"function f(a, b) { \"use strict\"; return a[b]; }\n"
|
|
|
|
"f({arg : \"test\"}, \"arg\")",
|
2016-01-13 15:40:32 +00:00
|
|
|
1 * kPointerSize,
|
2015-12-09 08:32:56 +00:00
|
|
|
3,
|
2016-01-13 15:40:32 +00:00
|
|
|
10,
|
2015-12-09 08:32:56 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 3), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), A(2, 3), //
|
|
|
|
B(KeyedLoadICStrict), R(0), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(Return), //
|
2015-12-09 08:32:56 +00:00
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"function f(a) {\n"
|
2016-01-04 09:23:01 +00:00
|
|
|
" var b;\n"
|
|
|
|
"b = a.name;"
|
|
|
|
REPEAT_127(SPACE, " b = a.name; ")
|
|
|
|
" return a.name; }\n"
|
|
|
|
"f({name : \"test\"})\n",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-12-09 08:32:56 +00:00
|
|
|
2,
|
2016-01-13 15:40:32 +00:00
|
|
|
1291,
|
2015-12-09 08:32:56 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LoadICSloppy), R(1), U8(0), U8(wide_idx_1 += 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
REPEAT_127(COMMA, //
|
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LoadICSloppy), R(1), U8(0), //
|
|
|
|
U8((wide_idx_1 += 2)), //
|
|
|
|
B(Star), R(0)), //
|
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LoadICSloppyWide), R(1), U16(0), U16(wide_idx_1 + 2), //
|
|
|
|
B(Return), //
|
2015-12-09 08:32:56 +00:00
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"name"}},
|
|
|
|
{"function f(a) {\n"
|
2016-01-04 09:23:01 +00:00
|
|
|
" 'use strict'; var b;\n"
|
|
|
|
" b = a.name;\n"
|
|
|
|
REPEAT_127(SPACE, " b = a.name; ")
|
|
|
|
" return a.name; }\n"
|
|
|
|
"f({name : \"test\"})\n",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-12-09 08:32:56 +00:00
|
|
|
2,
|
2016-01-13 15:40:32 +00:00
|
|
|
1291,
|
2015-12-09 08:32:56 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LoadICStrict), R(1), U8(0), U8((wide_idx_2 += 2)), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
REPEAT_127(COMMA, //
|
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LoadICStrict), R(1), U8(0), //
|
|
|
|
U8((wide_idx_2 += 2)), //
|
|
|
|
B(Star), R(0)), //
|
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LoadICStrictWide), R(1), U16(0), U16(wide_idx_2 + 2), //
|
|
|
|
B(Return), //
|
2015-12-09 08:32:56 +00:00
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"name"}},
|
|
|
|
{"function f(a, b) {\n"
|
2016-01-04 09:23:01 +00:00
|
|
|
" var c;\n"
|
|
|
|
" c = a[b];"
|
|
|
|
REPEAT_127(SPACE, " c = a[b]; ")
|
|
|
|
" return a[b]; }\n"
|
|
|
|
"f({name : \"test\"}, \"name\")\n",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-12-09 08:32:56 +00:00
|
|
|
3,
|
2016-01-13 15:40:32 +00:00
|
|
|
1419,
|
2015-12-09 08:32:56 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Ldar), A(2, 3), //
|
|
|
|
B(KeyedLoadICSloppy), R(1), U8((wide_idx_3 += 2)), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
REPEAT_127(COMMA, //
|
|
|
|
B(Ldar), A(1, 3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Ldar), A(2, 3), //
|
|
|
|
B(KeyedLoadICSloppy), R(1), U8((wide_idx_3 += 2)), //
|
|
|
|
B(Star), R(0)), //
|
|
|
|
B(Ldar), A(1, 3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Ldar), A(2, 3), //
|
|
|
|
B(KeyedLoadICSloppyWide), R(1), U16(wide_idx_3 + 2), //
|
|
|
|
B(Return), //
|
2015-12-09 08:32:56 +00:00
|
|
|
}},
|
|
|
|
{"function f(a, b) {\n"
|
2016-01-04 09:23:01 +00:00
|
|
|
" 'use strict'; var c;\n"
|
|
|
|
" c = a[b];"
|
|
|
|
REPEAT_127(SPACE, " c = a[b]; ")
|
|
|
|
" return a[b]; }\n"
|
|
|
|
"f({name : \"test\"}, \"name\")\n",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-12-09 08:32:56 +00:00
|
|
|
3,
|
2016-01-13 15:40:32 +00:00
|
|
|
1419,
|
2015-12-09 08:32:56 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Ldar), A(2, 3), //
|
|
|
|
B(KeyedLoadICStrict), R(1), U8((wide_idx_4 += 2)), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
REPEAT_127(COMMA, //
|
|
|
|
B(Ldar), A(1, 3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Ldar), A(2, 3), //
|
|
|
|
B(KeyedLoadICStrict), R(1), U8((wide_idx_4 += 2)), //
|
|
|
|
B(Star), R(0)), //
|
|
|
|
B(Ldar), A(1, 3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Ldar), A(2, 3), //
|
|
|
|
B(KeyedLoadICStrictWide), R(1), U16(wide_idx_4 + 2), //
|
|
|
|
B(Return), //
|
2015-12-09 08:32:56 +00:00
|
|
|
}},
|
|
|
|
};
|
2015-09-24 15:20:47 +00:00
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
2015-09-24 11:48:22 +00:00
|
|
|
Handle<BytecodeArray> bytecode_array =
|
2015-09-28 18:05:56 +00:00
|
|
|
helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName);
|
2015-09-24 11:48:22 +00:00
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
2015-09-02 13:03:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-09 15:46:04 +00:00
|
|
|
|
|
|
|
TEST(PropertyStores) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
2015-10-01 13:48:05 +00:00
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
FeedbackVectorSpec feedback_spec(&zone);
|
|
|
|
FeedbackVectorSlot slot1 = feedback_spec.AddStoreICSlot();
|
|
|
|
FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot();
|
2015-09-09 15:46:04 +00:00
|
|
|
|
|
|
|
Handle<i::TypeFeedbackVector> vector =
|
2015-10-07 10:33:22 +00:00
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
|
2015-09-09 15:46:04 +00:00
|
|
|
|
2015-10-30 11:17:07 +00:00
|
|
|
// These are a hack used by the StoreICXXXWide tests below.
|
|
|
|
int wide_idx_1 = vector->GetIndex(slot1) - 2;
|
|
|
|
int wide_idx_2 = vector->GetIndex(slot1) - 2;
|
|
|
|
int wide_idx_3 = vector->GetIndex(slot1) - 2;
|
|
|
|
int wide_idx_4 = vector->GetIndex(slot1) - 2;
|
|
|
|
|
2015-09-09 15:46:04 +00:00
|
|
|
ExpectedSnippet<const char*> snippets[] = {
|
|
|
|
{"function f(a) { a.name = \"val\"; }\nf({name : \"test\"})",
|
2016-01-13 15:40:32 +00:00
|
|
|
kPointerSize,
|
2015-09-24 15:20:47 +00:00
|
|
|
2,
|
2016-01-13 15:40:32 +00:00
|
|
|
12,
|
2015-09-09 15:46:04 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(StoreICSloppy), R(0), U8(1), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
2015-09-09 15:46:04 +00:00
|
|
|
},
|
2015-09-24 15:20:47 +00:00
|
|
|
2,
|
2015-12-23 09:34:00 +00:00
|
|
|
{"val", "name"}},
|
2015-09-09 15:46:04 +00:00
|
|
|
{"function f(a) { a[\"key\"] = \"val\"; }\nf({key : \"test\"})",
|
2016-01-13 15:40:32 +00:00
|
|
|
kPointerSize,
|
2015-09-24 15:20:47 +00:00
|
|
|
2,
|
2016-01-13 15:40:32 +00:00
|
|
|
12,
|
2015-09-09 15:46:04 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(StoreICSloppy), R(0), U8(1), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
2015-09-09 15:46:04 +00:00
|
|
|
},
|
2015-09-24 15:20:47 +00:00
|
|
|
2,
|
2015-12-23 09:34:00 +00:00
|
|
|
{"val", "key"}},
|
2015-09-09 15:46:04 +00:00
|
|
|
{"function f(a) { a[100] = \"val\"; }\nf({100 : \"test\"})",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-09-24 15:20:47 +00:00
|
|
|
2,
|
2016-01-13 15:40:32 +00:00
|
|
|
16,
|
2015-09-09 15:46:04 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(100), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(KeyedStoreICSloppy), R(0), R(1), //
|
|
|
|
U8(vector->GetIndex(slot1)), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
2015-09-09 15:46:04 +00:00
|
|
|
},
|
2015-09-24 15:20:47 +00:00
|
|
|
1,
|
|
|
|
{"val"}},
|
2015-09-09 15:46:04 +00:00
|
|
|
{"function f(a, b) { a[b] = \"val\"; }\nf({arg : \"test\"}, \"arg\")",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-09-24 15:20:47 +00:00
|
|
|
3,
|
2016-01-13 15:40:32 +00:00
|
|
|
16,
|
2015-09-09 15:46:04 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 3), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), A(2, 3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(KeyedStoreICSloppy), R(0), R(1), //
|
|
|
|
U8(vector->GetIndex(slot1)), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
2015-09-09 15:46:04 +00:00
|
|
|
},
|
2015-09-24 15:20:47 +00:00
|
|
|
1,
|
|
|
|
{"val"}},
|
2015-09-09 15:46:04 +00:00
|
|
|
{"function f(a) { a.name = a[-124]; }\n"
|
|
|
|
"f({\"-124\" : \"test\", name : 123 })",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-09-24 15:20:47 +00:00
|
|
|
2,
|
2016-01-13 15:40:32 +00:00
|
|
|
19,
|
2015-09-09 15:46:04 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(-124), //
|
|
|
|
B(KeyedLoadICSloppy), R(1), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(StoreICSloppy), R(0), U8(0), U8(vector->GetIndex(slot2)), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
2015-09-09 15:46:04 +00:00
|
|
|
},
|
2015-09-24 15:20:47 +00:00
|
|
|
1,
|
2015-10-07 07:54:07 +00:00
|
|
|
{"name"}},
|
|
|
|
{"function f(a) { \"use strict\"; a.name = \"val\"; }\n"
|
|
|
|
"f({name : \"test\"})",
|
2016-01-13 15:40:32 +00:00
|
|
|
kPointerSize,
|
2015-10-07 07:54:07 +00:00
|
|
|
2,
|
2016-01-13 15:40:32 +00:00
|
|
|
12,
|
2015-10-07 07:54:07 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(StoreICStrict), R(0), U8(1), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
2015-10-07 07:54:07 +00:00
|
|
|
},
|
2015-10-21 15:28:55 +00:00
|
|
|
2,
|
2015-12-23 09:34:00 +00:00
|
|
|
{"val", "name"}},
|
2015-10-07 07:54:07 +00:00
|
|
|
{"function f(a, b) { \"use strict\"; a[b] = \"val\"; }\n"
|
|
|
|
"f({arg : \"test\"}, \"arg\")",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-07 07:54:07 +00:00
|
|
|
3,
|
2016-01-13 15:40:32 +00:00
|
|
|
16,
|
2015-10-07 07:54:07 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 3), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), A(2, 3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(KeyedStoreICStrict), R(0), R(1), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
2015-10-07 07:54:07 +00:00
|
|
|
},
|
2015-10-21 15:28:55 +00:00
|
|
|
1,
|
2015-10-30 11:17:07 +00:00
|
|
|
{"val"}},
|
2016-01-04 09:23:01 +00:00
|
|
|
{"function f(a) {\n"
|
|
|
|
"a.name = 1;"
|
|
|
|
REPEAT_127(SPACE, " a.name = 1; ")
|
|
|
|
" a.name = 2; }\n"
|
|
|
|
"f({name : \"test\"})\n",
|
2016-01-13 15:40:32 +00:00
|
|
|
kPointerSize,
|
2015-10-30 11:17:07 +00:00
|
|
|
2,
|
2016-01-13 15:40:32 +00:00
|
|
|
1294,
|
2015-10-30 11:17:07 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(StoreICSloppy), R(0), U8(0), U8((wide_idx_1 += 2)), //
|
|
|
|
REPEAT_127(COMMA, //
|
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(StoreICSloppy), R(0), U8(0), //
|
|
|
|
U8((wide_idx_1 += 2))), //
|
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(StoreICSloppyWide), R(0), U16(0), U16(wide_idx_1 + 2), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
2015-10-30 11:17:07 +00:00
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"name"}},
|
|
|
|
{"function f(a) {\n"
|
2016-01-04 09:23:01 +00:00
|
|
|
" 'use strict';\n"
|
|
|
|
" a.name = 1;"
|
|
|
|
REPEAT_127(SPACE, " a.name = 1; ")
|
|
|
|
" a.name = 2; }\n"
|
|
|
|
"f({name : \"test\"})\n",
|
2016-01-13 15:40:32 +00:00
|
|
|
kPointerSize,
|
2015-10-30 11:17:07 +00:00
|
|
|
2,
|
2016-01-13 15:40:32 +00:00
|
|
|
1294,
|
2015-10-30 11:17:07 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(StoreICStrict), R(0), U8(0), U8(wide_idx_2 += 2), //
|
|
|
|
REPEAT_127(COMMA, //
|
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(StoreICStrict), R(0), U8(0), //
|
|
|
|
U8((wide_idx_2 += 2))), //
|
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(StoreICStrictWide), R(0), U16(0), U16(wide_idx_2 + 2), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
2015-10-30 11:17:07 +00:00
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"name"}},
|
2016-01-04 09:23:01 +00:00
|
|
|
{"function f(a, b) {\n"
|
|
|
|
" a[b] = 1;"
|
|
|
|
REPEAT_127(SPACE, " a[b] = 1; ")
|
|
|
|
" a[b] = 2; }\n"
|
|
|
|
"f({name : \"test\"})\n",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-30 11:17:07 +00:00
|
|
|
3,
|
2016-01-13 15:40:32 +00:00
|
|
|
1809,
|
2015-12-09 08:32:56 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 3), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), A(2, 3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(KeyedStoreICSloppy), R(0), R(1), U8(wide_idx_3 += 2), //
|
|
|
|
REPEAT_127(COMMA, //
|
|
|
|
B(Ldar), A(1, 3), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), A(2, 3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(KeyedStoreICSloppy), R(0), R(1), //
|
|
|
|
U8((wide_idx_3 += 2))), //
|
|
|
|
B(Ldar), A(1, 3), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), A(2, 3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(KeyedStoreICSloppyWide), R(0), R(1), U16(wide_idx_3 + 2), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
2015-10-30 11:17:07 +00:00
|
|
|
}},
|
|
|
|
{"function f(a, b) {\n"
|
2016-01-04 09:23:01 +00:00
|
|
|
" 'use strict';\n"
|
|
|
|
" a[b] = 1;"
|
|
|
|
REPEAT_127(SPACE, " a[b] = 1; ")
|
|
|
|
" a[b] = 2; }\n"
|
|
|
|
"f({name : \"test\"})\n",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-30 11:17:07 +00:00
|
|
|
3,
|
2016-01-13 15:40:32 +00:00
|
|
|
1809,
|
2015-12-09 08:32:56 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 3), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), A(2, 3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(KeyedStoreICStrict), R(0), R(1), U8(wide_idx_4 += 2), //
|
|
|
|
REPEAT_127(COMMA, //
|
|
|
|
B(Ldar), A(1, 3), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), A(2, 3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(KeyedStoreICStrict), R(0), R(1), //
|
|
|
|
U8((wide_idx_4 += 2))), //
|
|
|
|
B(Ldar), A(1, 3), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), A(2, 3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(KeyedStoreICStrictWide), R(0), R(1), U16(wide_idx_4 + 2), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
2015-10-30 11:17:07 +00:00
|
|
|
}}};
|
2015-09-24 15:20:47 +00:00
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
2015-09-24 11:48:22 +00:00
|
|
|
Handle<BytecodeArray> bytecode_array =
|
2015-09-28 18:05:56 +00:00
|
|
|
helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName);
|
2015-09-24 11:48:22 +00:00
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
2015-09-09 15:46:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-14 10:05:18 +00:00
|
|
|
|
|
|
|
#define FUNC_ARG "new (function Obj() { this.func = function() { return; }})()"
|
|
|
|
|
|
|
|
|
|
|
|
TEST(PropertyCall) {
|
|
|
|
InitializedHandleScope handle_scope;
|
2015-10-07 21:18:58 +00:00
|
|
|
BytecodeGeneratorHelper helper;
|
2015-10-01 13:48:05 +00:00
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
FeedbackVectorSpec feedback_spec(&zone);
|
2015-11-17 12:18:25 +00:00
|
|
|
FeedbackVectorSlot slot1 = feedback_spec.AddCallICSlot();
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot();
|
2015-09-14 10:05:18 +00:00
|
|
|
|
|
|
|
Handle<i::TypeFeedbackVector> vector =
|
2015-10-07 10:33:22 +00:00
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
|
2015-09-14 10:05:18 +00:00
|
|
|
|
2015-11-17 12:18:25 +00:00
|
|
|
// These are a hack used by the CallWide test below.
|
|
|
|
int wide_idx = vector->GetIndex(slot1) - 2;
|
|
|
|
|
2015-09-14 10:05:18 +00:00
|
|
|
ExpectedSnippet<const char*> snippets[] = {
|
|
|
|
{"function f(a) { return a.func(); }\nf(" FUNC_ARG ")",
|
2015-09-24 15:20:47 +00:00
|
|
|
2 * kPointerSize,
|
|
|
|
2,
|
2015-11-17 12:18:25 +00:00
|
|
|
16,
|
2015-09-14 10:05:18 +00:00
|
|
|
{
|
2015-10-22 14:55:32 +00:00
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LoadICSloppy), R(1), U8(0), U8(vector->GetIndex(slot2)), //
|
|
|
|
B(Star), R(0), //
|
2015-11-17 12:18:25 +00:00
|
|
|
B(Call), R(0), R(1), U8(0), U8(vector->GetIndex(slot1)), //
|
2015-10-22 14:55:32 +00:00
|
|
|
B(Return), //
|
2015-09-14 10:05:18 +00:00
|
|
|
},
|
2015-09-24 15:20:47 +00:00
|
|
|
1,
|
|
|
|
{"func"}},
|
2015-09-14 10:05:18 +00:00
|
|
|
{"function f(a, b, c) { return a.func(b, c); }\nf(" FUNC_ARG ", 1, 2)",
|
2015-09-24 15:20:47 +00:00
|
|
|
4 * kPointerSize,
|
|
|
|
4,
|
2015-11-17 12:18:25 +00:00
|
|
|
24,
|
2015-09-14 10:05:18 +00:00
|
|
|
{
|
2015-10-22 14:55:32 +00:00
|
|
|
B(Ldar), A(1, 4), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LoadICSloppy), R(1), U8(0), U8(vector->GetIndex(slot2)), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), A(2, 4), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(Ldar), A(3, 4), //
|
|
|
|
B(Star), R(3), //
|
2015-11-17 12:18:25 +00:00
|
|
|
B(Call), R(0), R(1), U8(2), U8(vector->GetIndex(slot1)), //
|
2015-10-22 14:55:32 +00:00
|
|
|
B(Return) //
|
2015-09-14 10:05:18 +00:00
|
|
|
},
|
2015-09-24 15:20:47 +00:00
|
|
|
1,
|
|
|
|
{"func"}},
|
|
|
|
{"function f(a, b) { return a.func(b + b, b); }\nf(" FUNC_ARG ", 1)",
|
|
|
|
4 * kPointerSize,
|
|
|
|
3,
|
2016-01-13 15:40:32 +00:00
|
|
|
30,
|
2015-09-24 15:20:47 +00:00
|
|
|
{
|
2015-10-22 14:55:32 +00:00
|
|
|
B(Ldar), A(1, 3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LoadICSloppy), R(1), U8(0), U8(vector->GetIndex(slot2)), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), A(2, 3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(3), //
|
|
|
|
B(Ldar), A(2, 3), //
|
|
|
|
B(Add), R(3), //
|
2015-10-22 14:55:32 +00:00
|
|
|
B(Star), R(2), //
|
|
|
|
B(Ldar), A(2, 3), //
|
|
|
|
B(Star), R(3), //
|
2015-11-17 12:18:25 +00:00
|
|
|
B(Call), R(0), R(1), U8(2), U8(vector->GetIndex(slot1)), //
|
2015-10-22 14:55:32 +00:00
|
|
|
B(Return), //
|
2015-09-14 10:05:18 +00:00
|
|
|
},
|
2015-09-24 15:20:47 +00:00
|
|
|
1,
|
2015-11-17 12:18:25 +00:00
|
|
|
{"func"}},
|
2016-01-04 09:23:01 +00:00
|
|
|
{"function f(a) {\n"
|
|
|
|
" a.func;\n"
|
|
|
|
REPEAT_127(SPACE, " a.func;\n")
|
|
|
|
" return a.func(); }\nf(" FUNC_ARG ")",
|
2015-11-17 12:18:25 +00:00
|
|
|
2 * kPointerSize,
|
|
|
|
2,
|
2016-01-13 15:40:32 +00:00
|
|
|
1044,
|
2015-11-17 12:18:25 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LoadICSloppy), R(0), U8(0), U8(wide_idx += 2), //
|
|
|
|
REPEAT_127(COMMA, //
|
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LoadICSloppy), R(0), U8(0), U8((wide_idx += 2))), //
|
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LoadICSloppyWide), R(1), U16(0), U16(wide_idx + 4), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(CallWide), R(0), R(1), U16(0), U16(wide_idx + 2), //
|
|
|
|
B(Return), //
|
2015-11-17 12:18:25 +00:00
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"func"}},
|
|
|
|
};
|
2015-09-24 15:20:47 +00:00
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
2015-09-24 11:48:22 +00:00
|
|
|
Handle<BytecodeArray> bytecode_array =
|
2015-09-28 18:05:56 +00:00
|
|
|
helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName);
|
2015-09-24 11:48:22 +00:00
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(LoadGlobal) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
2015-10-22 09:17:02 +00:00
|
|
|
Zone zone;
|
2015-09-24 11:48:22 +00:00
|
|
|
|
2015-10-22 09:17:02 +00:00
|
|
|
FeedbackVectorSpec feedback_spec(&zone);
|
2015-10-22 14:55:32 +00:00
|
|
|
FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot();
|
2015-10-22 09:17:02 +00:00
|
|
|
|
|
|
|
Handle<i::TypeFeedbackVector> vector =
|
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
|
|
|
|
|
2015-10-30 11:17:07 +00:00
|
|
|
// These are a hack used by the LdaGlobalXXXWide tests below.
|
|
|
|
int wide_idx_1 = vector->GetIndex(slot) - 2;
|
|
|
|
int wide_idx_2 = vector->GetIndex(slot) - 2;
|
|
|
|
|
2015-10-22 14:55:32 +00:00
|
|
|
ExpectedSnippet<const char*> snippets[] = {
|
|
|
|
{"var a = 1;\nfunction f() { return a; }\nf()",
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
4,
|
|
|
|
{
|
|
|
|
B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"a"}},
|
|
|
|
{"function t() { }\nfunction f() { return t; }\nf()",
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
4,
|
|
|
|
{
|
|
|
|
B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"t"}},
|
|
|
|
{"'use strict'; var a = 1;\nfunction f() { return a; }\nf()",
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
4,
|
|
|
|
{
|
|
|
|
B(LdaGlobalStrict), U8(0), U8(vector->GetIndex(slot)), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"a"}},
|
|
|
|
{"a = 1;\nfunction f() { return a; }\nf()",
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
4,
|
|
|
|
{
|
|
|
|
B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"a"}},
|
2016-01-04 09:23:01 +00:00
|
|
|
{"a = 1;"
|
|
|
|
"function f(b) {\n"
|
|
|
|
" b.name;\n"
|
|
|
|
REPEAT_127(SPACE, "b.name; ")
|
|
|
|
" return a;"
|
|
|
|
"}\nf({name: 1});",
|
2016-01-13 15:40:32 +00:00
|
|
|
kPointerSize,
|
2015-10-30 11:17:07 +00:00
|
|
|
2,
|
2016-01-13 15:40:32 +00:00
|
|
|
1030,
|
2015-10-30 11:17:07 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LoadICSloppy), R(0), U8(0), U8(wide_idx_1 += 2), //
|
|
|
|
REPEAT_127(COMMA, //
|
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LoadICSloppy), R(0), U8(0), U8(wide_idx_1 += 2)), //
|
|
|
|
B(LdaGlobalSloppyWide), U16(1), U16(wide_idx_1 + 2), //
|
|
|
|
B(Return), //
|
2015-10-30 11:17:07 +00:00
|
|
|
},
|
|
|
|
2,
|
|
|
|
{"name", "a"}},
|
2016-01-04 09:23:01 +00:00
|
|
|
{"a = 1;"
|
|
|
|
"function f(b) {\n"
|
|
|
|
" 'use strict';\n"
|
|
|
|
" b.name\n"
|
|
|
|
REPEAT_127(SPACE, "b.name; ")
|
|
|
|
" return a;"
|
|
|
|
"}\nf({name: 1});",
|
2016-01-13 15:40:32 +00:00
|
|
|
kPointerSize,
|
2015-10-30 11:17:07 +00:00
|
|
|
2,
|
2016-01-13 15:40:32 +00:00
|
|
|
1030,
|
2015-10-30 11:17:07 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LoadICStrict), R(0), U8(0), U8(wide_idx_2 += 2), //
|
|
|
|
REPEAT_127(COMMA, //
|
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LoadICStrict), R(0), U8(0), U8(wide_idx_2 += 2)), //
|
|
|
|
B(LdaGlobalStrictWide), U16(1), U16(wide_idx_2 + 2), //
|
|
|
|
B(Return), //
|
2015-10-30 11:17:07 +00:00
|
|
|
},
|
|
|
|
2,
|
|
|
|
{"name", "a"}},
|
2015-09-24 11:48:22 +00:00
|
|
|
};
|
|
|
|
|
2015-09-24 15:20:47 +00:00
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
2015-09-24 11:48:22 +00:00
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecode(snippets[i].code_snippet, "f");
|
2015-10-22 14:55:32 +00:00
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
2015-09-24 11:48:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-07 21:18:58 +00:00
|
|
|
TEST(StoreGlobal) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
2015-10-22 09:17:02 +00:00
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
FeedbackVectorSpec feedback_spec(&zone);
|
2015-10-22 14:55:32 +00:00
|
|
|
FeedbackVectorSlot slot = feedback_spec.AddStoreICSlot();
|
2015-10-07 21:18:58 +00:00
|
|
|
|
|
|
|
Handle<i::TypeFeedbackVector> vector =
|
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
|
|
|
|
|
2015-10-30 11:17:07 +00:00
|
|
|
// These are a hack used by the StaGlobalXXXWide tests below.
|
|
|
|
int wide_idx_1 = vector->GetIndex(slot) - 2;
|
|
|
|
int wide_idx_2 = vector->GetIndex(slot) - 2;
|
|
|
|
|
2015-10-07 21:18:58 +00:00
|
|
|
ExpectedSnippet<const char*> snippets[] = {
|
2015-10-22 14:55:32 +00:00
|
|
|
{"var a = 1;\nfunction f() { a = 2; }\nf()",
|
|
|
|
0,
|
2015-10-07 21:18:58 +00:00
|
|
|
1,
|
2015-10-22 14:55:32 +00:00
|
|
|
7,
|
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
2015-10-07 21:18:58 +00:00
|
|
|
1,
|
|
|
|
{"a"}},
|
2015-10-22 14:55:32 +00:00
|
|
|
{"var a = \"test\"; function f(b) { a = b; }\nf(\"global\")",
|
|
|
|
0,
|
|
|
|
2,
|
|
|
|
7,
|
|
|
|
{
|
|
|
|
B(Ldar), R(helper.kLastParamIndex), //
|
|
|
|
B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
2015-10-07 21:18:58 +00:00
|
|
|
1,
|
2015-10-22 14:55:32 +00:00
|
|
|
{"a"}},
|
|
|
|
{"'use strict'; var a = 1;\nfunction f() { a = 2; }\nf()",
|
|
|
|
0,
|
2015-10-07 21:18:58 +00:00
|
|
|
1,
|
2015-10-22 14:55:32 +00:00
|
|
|
7,
|
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(StaGlobalStrict), U8(0), U8(vector->GetIndex(slot)), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"a"}},
|
|
|
|
{"a = 1;\nfunction f() { a = 2; }\nf()",
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
7,
|
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"a"}},
|
2016-01-04 09:23:01 +00:00
|
|
|
{"a = 1;"
|
|
|
|
"function f(b) {"
|
|
|
|
" b.name;\n"
|
|
|
|
REPEAT_127(SPACE, "b.name; ")
|
|
|
|
" a = 2; }\n"
|
|
|
|
"f({name: 1});",
|
2016-01-13 15:40:32 +00:00
|
|
|
kPointerSize,
|
2015-10-30 11:17:07 +00:00
|
|
|
2,
|
2016-01-13 15:40:32 +00:00
|
|
|
1033,
|
|
|
|
{
|
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LoadICSloppy), R(0), U8(0), U8(wide_idx_1 += 2), //
|
|
|
|
REPEAT_127(COMMA, //
|
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LoadICSloppy), R(0), U8(0), U8(wide_idx_1 += 2)), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(StaGlobalSloppyWide), U16(1), U16(wide_idx_1 + 2), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
2015-10-30 11:17:07 +00:00
|
|
|
},
|
|
|
|
2,
|
|
|
|
{"name", "a"}},
|
2016-01-04 09:23:01 +00:00
|
|
|
{"a = 1;"
|
|
|
|
"function f(b) {\n"
|
|
|
|
" 'use strict';\n"
|
|
|
|
" b.name;\n"
|
|
|
|
REPEAT_127(SPACE, "b.name; ")
|
|
|
|
" a = 2; }\n"
|
|
|
|
"f({name: 1});",
|
2016-01-13 15:40:32 +00:00
|
|
|
kPointerSize,
|
2015-10-30 11:17:07 +00:00
|
|
|
2,
|
2016-01-13 15:40:32 +00:00
|
|
|
1033,
|
|
|
|
{
|
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LoadICStrict), R(0), U8(0), U8(wide_idx_2 += 2), //
|
|
|
|
REPEAT_127(COMMA, //
|
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LoadICStrict), R(0), U8(0), U8(wide_idx_2 += 2)), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(StaGlobalStrictWide), U16(1), U16(wide_idx_2 + 2), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
2015-10-30 11:17:07 +00:00
|
|
|
},
|
|
|
|
2,
|
|
|
|
{"name", "a"}},
|
2015-10-07 21:18:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecode(snippets[i].code_snippet, "f");
|
2015-10-13 13:09:48 +00:00
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
2015-10-07 21:18:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-22 14:55:32 +00:00
|
|
|
TEST(CallGlobal) {
|
2015-10-07 21:18:58 +00:00
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
FeedbackVectorSpec feedback_spec(&zone);
|
2015-11-17 12:18:25 +00:00
|
|
|
FeedbackVectorSlot slot1 = feedback_spec.AddCallICSlot();
|
2015-10-22 14:55:32 +00:00
|
|
|
FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot();
|
2015-10-07 21:18:58 +00:00
|
|
|
|
|
|
|
Handle<i::TypeFeedbackVector> vector =
|
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
|
|
|
|
|
|
|
|
ExpectedSnippet<const char*> snippets[] = {
|
2015-10-22 14:55:32 +00:00
|
|
|
{"function t() { }\nfunction f() { return t(); }\nf()",
|
|
|
|
2 * kPointerSize,
|
2015-10-07 21:18:58 +00:00
|
|
|
1,
|
2015-11-17 12:18:25 +00:00
|
|
|
14,
|
2015-10-22 14:55:32 +00:00
|
|
|
{
|
2015-11-17 12:18:25 +00:00
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Call), R(0), R(1), U8(0), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(Return) //
|
2015-10-22 14:55:32 +00:00
|
|
|
},
|
2015-10-07 21:18:58 +00:00
|
|
|
1,
|
2015-10-22 14:55:32 +00:00
|
|
|
{"t"}},
|
|
|
|
{"function t(a, b, c) { }\nfunction f() { return t(1, 2, 3); }\nf()",
|
|
|
|
5 * kPointerSize,
|
2015-10-07 21:18:58 +00:00
|
|
|
1,
|
2015-11-17 12:18:25 +00:00
|
|
|
26,
|
2015-10-22 14:55:32 +00:00
|
|
|
{
|
2015-11-17 12:18:25 +00:00
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Star), R(3), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Star), R(4), //
|
|
|
|
B(Call), R(0), R(1), U8(3), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(Return) //
|
2015-10-22 14:55:32 +00:00
|
|
|
},
|
2015-10-07 21:18:58 +00:00
|
|
|
1,
|
|
|
|
{"t"}},
|
|
|
|
};
|
|
|
|
|
2015-10-22 14:55:32 +00:00
|
|
|
size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
|
|
|
|
for (size_t i = 0; i < num_snippets; i++) {
|
2015-10-07 21:18:58 +00:00
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecode(snippets[i].code_snippet, "f");
|
2015-10-13 13:09:48 +00:00
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
2015-10-07 21:18:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-02 18:13:41 +00:00
|
|
|
TEST(CallRuntime) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
2015-11-04 09:21:26 +00:00
|
|
|
ExpectedSnippet<InstanceType> snippets[] = {
|
2015-10-02 18:13:41 +00:00
|
|
|
{
|
|
|
|
"function f() { %TheHole() }\nf()",
|
2015-11-04 09:21:26 +00:00
|
|
|
0,
|
2015-10-02 18:13:41 +00:00
|
|
|
1,
|
|
|
|
7,
|
|
|
|
{
|
|
|
|
B(CallRuntime), U16(Runtime::kTheHole), R(0), U8(0), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"function f(a) { return %IsArray(a) }\nf(undefined)",
|
|
|
|
1 * kPointerSize,
|
|
|
|
2,
|
|
|
|
10,
|
|
|
|
{
|
2015-10-21 15:28:55 +00:00
|
|
|
B(Ldar), A(1, 2), //
|
2015-10-02 18:13:41 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(CallRuntime), U16(Runtime::kIsArray), R(0), U8(1), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"function f() { return %Add(1, 2) }\nf()",
|
|
|
|
2 * kPointerSize,
|
|
|
|
1,
|
|
|
|
14,
|
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(CallRuntime), U16(Runtime::kAdd), R(0), U8(2), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
2015-09-24 11:48:22 +00:00
|
|
|
},
|
2015-11-04 09:21:26 +00:00
|
|
|
{
|
|
|
|
"function f() { return %spread_iterable([1]) }\nf()",
|
|
|
|
2 * kPointerSize,
|
|
|
|
1,
|
2015-12-09 11:53:07 +00:00
|
|
|
15,
|
2015-11-04 09:21:26 +00:00
|
|
|
{
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Star), R(0), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateArrayLiteral), U8(0), U8(0), U8(3), //
|
2015-11-04 09:21:26 +00:00
|
|
|
B(Star), R(1), //
|
|
|
|
B(CallJSRuntime), U16(Context::SPREAD_ITERABLE_INDEX), R(0), //
|
|
|
|
U8(1), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE},
|
|
|
|
},
|
2015-09-24 11:48:22 +00:00
|
|
|
};
|
|
|
|
|
2015-09-24 15:20:47 +00:00
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
2015-09-24 11:48:22 +00:00
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecode(snippets[i].code_snippet, "f");
|
2015-10-13 13:09:48 +00:00
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
2015-09-14 10:05:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-24 15:20:47 +00:00
|
|
|
|
|
|
|
TEST(IfConditions) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
Handle<Object> unused = helper.factory()->undefined_value();
|
|
|
|
|
|
|
|
ExpectedSnippet<Handle<Object>> snippets[] = {
|
2015-09-28 18:05:56 +00:00
|
|
|
{"function f() { if (0) { return 1; } else { return -1; } } f()",
|
2015-09-24 15:20:47 +00:00
|
|
|
0,
|
|
|
|
1,
|
2015-11-03 11:27:54 +00:00
|
|
|
3,
|
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(-1), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
2015-09-24 15:20:47 +00:00
|
|
|
0,
|
2015-10-14 10:10:01 +00:00
|
|
|
{unused, unused, unused, unused, unused, unused}},
|
2015-09-28 18:05:56 +00:00
|
|
|
{"function f() { if ('lucky') { return 1; } else { return -1; } } f();",
|
2015-09-24 15:20:47 +00:00
|
|
|
0,
|
|
|
|
1,
|
2015-11-03 11:27:54 +00:00
|
|
|
3,
|
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
2015-11-02 15:24:25 +00:00
|
|
|
0,
|
|
|
|
{unused, unused, unused, unused, unused, unused}},
|
2015-09-28 18:05:56 +00:00
|
|
|
{"function f() { if (false) { return 1; } else { return -1; } } f();",
|
2015-09-24 15:20:47 +00:00
|
|
|
0,
|
|
|
|
1,
|
2015-11-03 11:27:54 +00:00
|
|
|
3,
|
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(-1), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
2015-11-02 15:24:25 +00:00
|
|
|
0,
|
|
|
|
{unused, unused, unused, unused, unused, unused}},
|
|
|
|
{"function f() { if (false) { return 1; } } f();",
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
2,
|
2015-11-03 11:27:54 +00:00
|
|
|
{
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0,
|
|
|
|
{unused, unused, unused, unused, unused, unused}},
|
|
|
|
{"function f() { var a = 1; if (a) { a += 1; } else { return 2; } } f();",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-11-03 11:27:54 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
23,
|
2015-11-03 11:27:54 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(JumpIfToBooleanFalse), U8(14), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-11-03 11:27:54 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(1), //
|
2015-11-03 11:27:54 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(Jump), U8(5), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Return), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
2015-09-24 15:20:47 +00:00
|
|
|
0,
|
2015-10-14 10:10:01 +00:00
|
|
|
{unused, unused, unused, unused, unused, unused}},
|
2015-09-28 18:05:56 +00:00
|
|
|
{"function f(a) { if (a <= 0) { return 200; } else { return -200; } }"
|
|
|
|
"f(99);",
|
2016-01-13 15:40:32 +00:00
|
|
|
kPointerSize,
|
2015-09-24 15:20:47 +00:00
|
|
|
2,
|
2016-01-13 15:40:32 +00:00
|
|
|
17,
|
2015-11-03 11:27:54 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(TestLessThanOrEqual), R(0), //
|
|
|
|
B(JumpIfFalse), U8(5), //
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Return), //
|
|
|
|
B(LdaConstant), U8(1), //
|
|
|
|
B(Return), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
2015-11-03 11:27:54 +00:00
|
|
|
},
|
2015-09-24 15:20:47 +00:00
|
|
|
2,
|
|
|
|
{helper.factory()->NewNumberFromInt(200),
|
2015-10-14 10:10:01 +00:00
|
|
|
helper.factory()->NewNumberFromInt(-200), unused, unused, unused,
|
|
|
|
unused}},
|
2015-09-28 18:05:56 +00:00
|
|
|
{"function f(a, b) { if (a in b) { return 200; } }"
|
|
|
|
"f('prop', { prop: 'yes'});",
|
2016-01-13 15:40:32 +00:00
|
|
|
kPointerSize,
|
2015-09-24 15:20:47 +00:00
|
|
|
3,
|
2016-01-13 15:40:32 +00:00
|
|
|
15,
|
2015-11-03 11:27:54 +00:00
|
|
|
{
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 3), //
|
|
|
|
B(Star), R(0), //
|
2015-11-03 11:27:54 +00:00
|
|
|
B(Ldar), A(2, 3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestIn), R(0), //
|
2015-11-03 11:27:54 +00:00
|
|
|
B(JumpIfFalse), U8(5), //
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Return), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
2015-09-24 15:20:47 +00:00
|
|
|
1,
|
2015-10-14 10:10:01 +00:00
|
|
|
{helper.factory()->NewNumberFromInt(200), unused, unused, unused, unused,
|
|
|
|
unused}},
|
2015-09-24 15:20:47 +00:00
|
|
|
{"function f(z) { var a = 0; var b = 0; if (a === 0.01) { "
|
2015-11-13 14:14:57 +00:00
|
|
|
REPEAT_64(SPACE, "b = a; a = b; ")
|
2015-09-28 18:05:56 +00:00
|
|
|
" return 200; } else { return -200; } } f(0.001)",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-09-24 15:20:47 +00:00
|
|
|
2,
|
2016-01-13 15:40:32 +00:00
|
|
|
282,
|
2015-10-21 15:28:55 +00:00
|
|
|
{
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(2), //
|
2015-10-21 15:28:55 +00:00
|
|
|
B(LdaConstant), U8(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqualStrict), R(2), //
|
2015-10-21 15:28:55 +00:00
|
|
|
B(JumpIfFalseConstant), U8(2), //
|
2015-11-13 14:14:57 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
REPEAT_64(COMMA, //
|
2015-10-30 11:17:07 +00:00
|
|
|
B(Star), R(1), //
|
|
|
|
B(Star), R(0)), //
|
2015-10-21 15:28:55 +00:00
|
|
|
B(LdaConstant), U8(1), //
|
|
|
|
B(Return), //
|
|
|
|
B(LdaConstant), U8(3), //
|
|
|
|
B(Return), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return)}, //
|
2015-09-24 15:20:47 +00:00
|
|
|
4,
|
|
|
|
{helper.factory()->NewHeapNumber(0.01),
|
|
|
|
helper.factory()->NewNumberFromInt(200),
|
2015-11-13 14:14:57 +00:00
|
|
|
helper.factory()->NewNumberFromInt(263),
|
2015-10-21 15:28:55 +00:00
|
|
|
helper.factory()->NewNumberFromInt(-200), unused, unused}},
|
2015-10-30 16:48:18 +00:00
|
|
|
{"function f() { var a = 0; var b = 0; if (a) { "
|
2015-11-13 14:14:57 +00:00
|
|
|
REPEAT_64(SPACE, "b = a; a = b; ")
|
2015-10-30 16:48:18 +00:00
|
|
|
" return 200; } else { return -200; } } f()",
|
|
|
|
2 * kPointerSize,
|
|
|
|
1,
|
2015-11-13 14:14:57 +00:00
|
|
|
276,
|
2015-10-30 16:48:18 +00:00
|
|
|
{
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(JumpIfToBooleanFalseConstant), U8(1), //
|
2015-11-13 14:14:57 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
REPEAT_64(COMMA, //
|
2015-10-30 16:48:18 +00:00
|
|
|
B(Star), R(1), //
|
|
|
|
B(Star), R(0)), //
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Return), //
|
|
|
|
B(LdaConstant), U8(2), //
|
|
|
|
B(Return), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return)}, //
|
|
|
|
3,
|
|
|
|
{helper.factory()->NewNumberFromInt(200),
|
2015-11-13 14:14:57 +00:00
|
|
|
helper.factory()->NewNumberFromInt(263),
|
2015-10-30 16:48:18 +00:00
|
|
|
helper.factory()->NewNumberFromInt(-200), unused, unused, unused}},
|
|
|
|
|
2015-09-28 18:05:56 +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"
|
|
|
|
"} f(1, 1);",
|
2016-01-13 15:40:32 +00:00
|
|
|
kPointerSize,
|
2015-09-28 18:05:56 +00:00
|
|
|
3,
|
2016-01-13 15:40:32 +00:00
|
|
|
106,
|
2015-09-28 18:05:56 +00:00
|
|
|
{
|
2015-10-01 15:04:09 +00:00
|
|
|
#define IF_CONDITION_RETURN(condition) \
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), A(1, 3), \
|
|
|
|
B(Star), R(0), \
|
2015-10-30 11:17:07 +00:00
|
|
|
B(Ldar), A(2, 3), \
|
2016-01-13 15:40:32 +00:00
|
|
|
B(condition), R(0), \
|
2015-10-21 15:28:55 +00:00
|
|
|
B(JumpIfFalse), U8(5), \
|
|
|
|
B(LdaSmi8), U8(1), \
|
|
|
|
B(Return),
|
2015-09-28 18:05:56 +00:00
|
|
|
IF_CONDITION_RETURN(TestEqual) //
|
|
|
|
IF_CONDITION_RETURN(TestEqualStrict) //
|
|
|
|
IF_CONDITION_RETURN(TestLessThan) //
|
|
|
|
IF_CONDITION_RETURN(TestGreaterThan) //
|
|
|
|
IF_CONDITION_RETURN(TestLessThanOrEqual) //
|
|
|
|
IF_CONDITION_RETURN(TestGreaterThanOrEqual) //
|
|
|
|
IF_CONDITION_RETURN(TestIn) //
|
|
|
|
IF_CONDITION_RETURN(TestInstanceOf) //
|
2015-10-21 15:28:55 +00:00
|
|
|
B(LdaZero), //
|
|
|
|
B(Return)}, //
|
2015-09-28 18:05:56 +00:00
|
|
|
#undef IF_CONDITION_RETURN
|
|
|
|
0,
|
2015-10-14 10:10:01 +00:00
|
|
|
{unused, unused, unused, unused, unused, unused}},
|
2015-11-02 15:24:25 +00:00
|
|
|
{"function f() {"
|
|
|
|
" var a = 0;"
|
|
|
|
" if (a) {"
|
|
|
|
" return 20;"
|
|
|
|
"} else {"
|
|
|
|
" return -20;}"
|
|
|
|
"};"
|
|
|
|
"f();",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
2015-11-13 14:14:57 +00:00
|
|
|
13,
|
2015-11-02 15:24:25 +00:00
|
|
|
{
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
2015-11-03 11:27:54 +00:00
|
|
|
B(JumpIfToBooleanFalse), U8(5), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(LdaSmi8), U8(20), //
|
|
|
|
B(Return), //
|
|
|
|
B(LdaSmi8), U8(-20), //
|
|
|
|
B(Return), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return)
|
|
|
|
},
|
|
|
|
0,
|
2015-11-13 14:14:57 +00:00
|
|
|
{unused, unused, unused, unused, unused, unused}}};
|
2015-09-24 15:20:47 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
2015-09-28 18:05:56 +00:00
|
|
|
helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName);
|
2015-09-24 15:20:47 +00:00
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-07 21:18:58 +00:00
|
|
|
TEST(DeclareGlobals) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
2015-10-21 13:00:31 +00:00
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
// Create different feedback vector specs to be precise on slot numbering.
|
2015-10-22 14:55:32 +00:00
|
|
|
FeedbackVectorSpec feedback_spec_stores(&zone);
|
|
|
|
FeedbackVectorSlot store_slot_1 = feedback_spec_stores.AddStoreICSlot();
|
|
|
|
FeedbackVectorSlot store_slot_2 = feedback_spec_stores.AddStoreICSlot();
|
|
|
|
USE(store_slot_1);
|
2015-10-21 13:00:31 +00:00
|
|
|
|
2015-10-22 14:55:32 +00:00
|
|
|
Handle<i::TypeFeedbackVector> store_vector =
|
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec_stores);
|
2015-10-21 13:00:31 +00:00
|
|
|
|
2015-10-22 14:55:32 +00:00
|
|
|
FeedbackVectorSpec feedback_spec_loads(&zone);
|
|
|
|
FeedbackVectorSlot load_slot_1 = feedback_spec_loads.AddLoadICSlot();
|
2015-11-17 12:18:25 +00:00
|
|
|
FeedbackVectorSlot call_slot_1 = feedback_spec_loads.AddCallICSlot();
|
2015-10-21 13:00:31 +00:00
|
|
|
|
2015-10-22 14:55:32 +00:00
|
|
|
Handle<i::TypeFeedbackVector> load_vector =
|
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec_loads);
|
2015-10-21 13:00:31 +00:00
|
|
|
|
|
|
|
ExpectedSnippet<InstanceType> snippets[] = {
|
|
|
|
{"var a = 1;",
|
|
|
|
4 * kPointerSize,
|
|
|
|
1,
|
|
|
|
30,
|
|
|
|
{
|
2015-10-22 14:55:32 +00:00
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2), //
|
|
|
|
B(LdaConstant), U8(1), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(3), //
|
|
|
|
B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(1), U8(3), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return) //
|
2015-10-21 13:00:31 +00:00
|
|
|
},
|
|
|
|
2,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
{"function f() {}",
|
|
|
|
2 * kPointerSize,
|
|
|
|
1,
|
|
|
|
14,
|
|
|
|
{
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(CallRuntime), U16(Runtime::kDeclareGlobals), R(0), U8(2), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE}},
|
|
|
|
{"var a = 1;\na=2;",
|
|
|
|
4 * kPointerSize,
|
|
|
|
1,
|
2015-11-13 14:14:57 +00:00
|
|
|
36,
|
2015-10-21 13:00:31 +00:00
|
|
|
{
|
2015-10-22 14:55:32 +00:00
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2), //
|
|
|
|
B(LdaConstant), U8(1), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(3), //
|
|
|
|
B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(1), U8(3), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(StaGlobalSloppy), U8(1), //
|
|
|
|
U8(store_vector->GetIndex(store_slot_2)), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Return) //
|
2015-10-21 13:00:31 +00:00
|
|
|
},
|
|
|
|
2,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
{"function f() {}\nf();",
|
2015-10-22 14:55:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-10-21 13:00:31 +00:00
|
|
|
1,
|
2015-11-17 12:18:25 +00:00
|
|
|
28,
|
2015-10-21 13:00:31 +00:00
|
|
|
{
|
2015-11-17 12:18:25 +00:00
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(LdaGlobalSloppy), U8(1), //
|
|
|
|
U8(load_vector->GetIndex(load_slot_1)), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Call), R(1), R(2), U8(0), //
|
|
|
|
U8(load_vector->GetIndex(call_slot_1)), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Return) //
|
2015-10-21 13:00:31 +00:00
|
|
|
},
|
|
|
|
2,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeTopLevelBytecode(snippets[i].code_snippet);
|
2015-10-22 20:42:22 +00:00
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
2015-10-21 13:00:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-16 17:06:05 +00:00
|
|
|
TEST(BreakableBlocks) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
ExpectedSnippet<int> snippets[] = {
|
|
|
|
{"var x = 0;\n"
|
|
|
|
"label: {\n"
|
|
|
|
" x = x + 1;\n"
|
|
|
|
" break label;\n"
|
|
|
|
" x = x + 1;\n"
|
|
|
|
"}\n"
|
|
|
|
"return x;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-12-16 17:06:05 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
16,
|
2015-12-16 17:06:05 +00:00
|
|
|
{
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-12-16 17:06:05 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(1), //
|
2015-12-16 17:06:05 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(Jump), U8(2), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Return) //
|
|
|
|
}},
|
|
|
|
{"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"
|
|
|
|
"return sum;",
|
2016-01-13 15:40:32 +00:00
|
|
|
5 * kPointerSize,
|
2015-12-16 17:06:05 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
72,
|
2015-12-16 17:06:05 +00:00
|
|
|
{
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Star), R(3), //
|
2015-12-16 17:06:05 +00:00
|
|
|
B(LdaSmi8), U8(10), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestLessThan), R(3), //
|
|
|
|
B(JumpIfFalse), U8(55), //
|
2015-12-16 17:06:05 +00:00
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(2), //
|
|
|
|
B(Star), R(3), //
|
2015-12-16 17:06:05 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestLessThan), R(3), //
|
|
|
|
B(JumpIfFalse), U8(34), //
|
2015-12-16 17:06:05 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(ToNumber), //
|
|
|
|
B(Inc), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(1), //
|
2015-12-16 17:06:05 +00:00
|
|
|
B(Star), R(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(2), //
|
|
|
|
B(Add), R(3), //
|
|
|
|
B(Star), R(4), //
|
2015-12-16 17:06:05 +00:00
|
|
|
B(LdaSmi8), U8(12), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(4), //
|
2015-12-16 17:06:05 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
|
|
|
B(Jump), U8(18), //
|
|
|
|
B(Ldar), R(2), //
|
|
|
|
B(ToNumber), //
|
|
|
|
B(Inc), //
|
|
|
|
B(Star), R(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-40), //
|
2015-12-16 17:06:05 +00:00
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(ToNumber), //
|
|
|
|
B(Inc), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-61), //
|
2015-12-16 17:06:05 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-01 15:04:09 +00:00
|
|
|
TEST(BasicLoops) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
ExpectedSnippet<int> snippets[] = {
|
2015-12-16 16:29:09 +00:00
|
|
|
{"var x = 0;\n"
|
|
|
|
"while (false) { x = 99; break; continue; }\n"
|
|
|
|
"return x;",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
4,
|
|
|
|
{
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Return) //
|
|
|
|
}},
|
|
|
|
{"var x = 0;"
|
|
|
|
"while (false) {"
|
|
|
|
" x = x + 1;"
|
|
|
|
"};"
|
|
|
|
"return x;",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
4,
|
|
|
|
{
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
2015-10-01 15:04:09 +00:00
|
|
|
{"var x = 0;"
|
|
|
|
"var y = 1;"
|
|
|
|
"while (x < 10) {"
|
2015-10-21 15:28:55 +00:00
|
|
|
" y = y * 12;"
|
2015-10-01 15:04:09 +00:00
|
|
|
" x = x + 1;"
|
2015-12-16 16:29:09 +00:00
|
|
|
" if (x == 3) continue;"
|
|
|
|
" if (x == 4) break;"
|
2015-10-01 15:04:09 +00:00
|
|
|
"}"
|
|
|
|
"return y;",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-10-01 15:04:09 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
64,
|
2015-10-01 15:04:09 +00:00
|
|
|
{
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(2), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(10), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestLessThan), R(2), //
|
|
|
|
B(JumpIfFalse), U8(46), //
|
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Star), R(2), //
|
2015-10-21 15:28:55 +00:00
|
|
|
B(LdaSmi8), U8(12), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Mul), R(2), //
|
2015-10-01 15:04:09 +00:00
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(2), //
|
2015-10-01 15:04:09 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(2), //
|
2015-10-01 15:04:09 +00:00
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(2), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(2), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-38), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(2), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(2), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
|
|
|
B(Jump), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-52), //
|
2015-10-01 15:04:09 +00:00
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"var i = 0;"
|
2015-12-16 16:29:09 +00:00
|
|
|
"while (true) {"
|
2015-10-01 15:04:09 +00:00
|
|
|
" if (i < 0) continue;"
|
|
|
|
" if (i == 3) break;"
|
|
|
|
" if (i == 4) break;"
|
|
|
|
" if (i == 10) continue;"
|
|
|
|
" if (i == 5) break;"
|
|
|
|
" i = i + 1;"
|
|
|
|
"}"
|
|
|
|
"return i;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-01 15:04:09 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
77,
|
2015-10-01 15:04:09 +00:00
|
|
|
{
|
2015-11-02 15:24:25 +00:00
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(LdaZero), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestLessThan), R(1), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-9), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(1), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(50), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(LdaSmi8), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(1), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(38), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(LdaSmi8), U8(10), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(1), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-45), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(LdaSmi8), U8(5), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(1), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(14), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(1), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-69), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Return), //
|
2015-10-01 15:04:09 +00:00
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"var i = 0;"
|
2015-12-16 16:29:09 +00:00
|
|
|
"while (true) {"
|
2015-10-01 15:04:09 +00:00
|
|
|
" while (i < 3) {"
|
|
|
|
" if (i == 2) break;"
|
|
|
|
" i = i + 1;"
|
|
|
|
" }"
|
|
|
|
" i = i + 1;"
|
|
|
|
" break;"
|
|
|
|
"}"
|
|
|
|
"return i;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-01 15:04:09 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
54,
|
2015-10-01 15:04:09 +00:00
|
|
|
{
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestLessThan), R(1), //
|
|
|
|
B(JumpIfFalse), U8(26), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-10-01 15:04:09 +00:00
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(1), //
|
2015-10-01 15:04:09 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(14), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-10-01 15:04:09 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(1), //
|
2015-10-01 15:04:09 +00:00
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-32), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-10-01 15:04:09 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(1), //
|
2015-10-01 15:04:09 +00:00
|
|
|
B(Star), R(0), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(Jump), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-46), //
|
2015-10-01 15:04:09 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
2015-10-30 16:48:18 +00:00
|
|
|
{"var x = 10;"
|
|
|
|
"var y = 1;"
|
|
|
|
"while (x) {"
|
|
|
|
" y = y * 12;"
|
|
|
|
" x = x - 1;"
|
|
|
|
"}"
|
|
|
|
"return y;",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-10-30 16:48:18 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
37,
|
2015-10-30 16:48:18 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(10), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(Ldar), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(JumpIfToBooleanFalse), U8(24), //
|
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Star), R(2), //
|
2015-10-30 16:48:18 +00:00
|
|
|
B(LdaSmi8), U8(12), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Mul), R(2), //
|
2015-10-30 16:48:18 +00:00
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(2), //
|
2015-10-30 16:48:18 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Sub), R(2), //
|
2015-10-30 16:48:18 +00:00
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-24), //
|
2015-10-30 16:48:18 +00:00
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Return), //
|
2015-12-16 16:29:09 +00:00
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"var x = 0; var y = 1;"
|
|
|
|
"do {"
|
|
|
|
" y = y * 10;"
|
|
|
|
" if (x == 5) break;"
|
|
|
|
" if (x == 6) continue;"
|
|
|
|
" x = x + 1;"
|
|
|
|
"} while (x < 10);"
|
|
|
|
"return y;",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-12-16 16:29:09 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
64,
|
2015-12-16 16:29:09 +00:00
|
|
|
{
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Star), R(2), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(10), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Mul), R(2), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(2), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(5), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(2), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(34), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(2), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(6), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(2), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(12), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(2), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(2), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(2), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(10), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestLessThan), R(2), //
|
|
|
|
B(JumpIfTrue), U8(-52), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
2015-11-02 15:24:25 +00:00
|
|
|
0},
|
|
|
|
{"var x = 10;"
|
2015-11-13 14:14:57 +00:00
|
|
|
"var y = 1;"
|
|
|
|
"do {"
|
|
|
|
" y = y * 12;"
|
|
|
|
" x = x - 1;"
|
2015-12-16 16:29:09 +00:00
|
|
|
"} while (x);"
|
2015-11-13 14:14:57 +00:00
|
|
|
"return y;",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-11-13 14:14:57 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
35,
|
2015-11-13 14:14:57 +00:00
|
|
|
{
|
2015-10-30 16:48:18 +00:00
|
|
|
B(LdaSmi8), U8(10), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Star), R(2), //
|
2015-10-30 16:48:18 +00:00
|
|
|
B(LdaSmi8), U8(12), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Mul), R(2), //
|
2015-10-30 16:48:18 +00:00
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(2), //
|
2015-10-30 16:48:18 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Sub), R(2), //
|
2015-10-30 16:48:18 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(JumpIfToBooleanTrue), U8(-22), //
|
2015-10-30 16:48:18 +00:00
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Return), //
|
2015-11-13 14:14:57 +00:00
|
|
|
},
|
2015-11-02 15:24:25 +00:00
|
|
|
0},
|
|
|
|
{"var x = 0; var y = 1;"
|
|
|
|
"do {"
|
|
|
|
" y = y * 10;"
|
|
|
|
" if (x == 5) break;"
|
|
|
|
" x = x + 1;"
|
|
|
|
" if (x == 6) continue;"
|
|
|
|
"} while (false);"
|
|
|
|
"return y;",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-11-02 15:24:25 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
52,
|
2015-11-02 15:24:25 +00:00
|
|
|
{
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Star), R(2), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(LdaSmi8), U8(10), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Mul), R(2), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(2), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(LdaSmi8), U8(5), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(2), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(22), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(2), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(2), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(2), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(LdaSmi8), U8(6), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(2), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
|
|
|
B(Jump), U8(2), //
|
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"var x = 0; var y = 1;"
|
|
|
|
"do {"
|
|
|
|
" y = y * 10;"
|
|
|
|
" if (x == 5) break;"
|
|
|
|
" x = x + 1;"
|
|
|
|
" if (x == 6) continue;"
|
|
|
|
"} while (true);"
|
|
|
|
"return y;",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-11-02 15:24:25 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
54,
|
2015-11-02 15:24:25 +00:00
|
|
|
{
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Star), R(2), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(LdaSmi8), U8(10), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Mul), R(2), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(2), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(LdaSmi8), U8(5), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(2), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(24), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(2), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(2), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(2), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(LdaSmi8), U8(6), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(2), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-40), //
|
|
|
|
B(Jump), U8(-42), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
2015-12-16 16:29:09 +00:00
|
|
|
{"var x = 0; "
|
|
|
|
"for (;;) {"
|
|
|
|
" if (x == 1) break;"
|
|
|
|
" if (x == 2) continue;"
|
2015-11-02 15:24:25 +00:00
|
|
|
" x = x + 1;"
|
2015-12-16 16:29:09 +00:00
|
|
|
"}",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-11-02 15:24:25 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
41,
|
2015-11-02 15:24:25 +00:00
|
|
|
{
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(26), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-22), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-34), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"for (var x = 0;;) {"
|
|
|
|
" if (x == 1) break;"
|
|
|
|
" if (x == 2) continue;"
|
|
|
|
" x = x + 1;"
|
|
|
|
"}",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-12-16 16:29:09 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
41,
|
2015-12-16 16:29:09 +00:00
|
|
|
{
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(26), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-22), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-34), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"var x = 0; "
|
|
|
|
"for (;; x = x + 1) {"
|
|
|
|
" if (x == 1) break;"
|
|
|
|
" if (x == 2) continue;"
|
|
|
|
"}",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-12-16 16:29:09 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
41,
|
2015-12-16 16:29:09 +00:00
|
|
|
{
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(26), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
|
|
|
B(Jump), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-34), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"for (var x = 0;; x = x + 1) {"
|
|
|
|
" if (x == 1) break;"
|
|
|
|
" if (x == 2) continue;"
|
|
|
|
"}",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-12-16 16:29:09 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
41,
|
2015-12-16 16:29:09 +00:00
|
|
|
{
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(26), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
|
|
|
B(Jump), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-34), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"var u = 0;"
|
|
|
|
"for (var i = 0; i < 100; i = i + 1) {"
|
|
|
|
" u = u + 1;"
|
|
|
|
" continue;"
|
|
|
|
"}",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-12-16 16:29:09 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
42,
|
2015-12-16 16:29:09 +00:00
|
|
|
{
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Star), R(2), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(100), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestLessThan), R(2), //
|
|
|
|
B(JumpIfFalse), U8(26), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(2), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(2), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(Jump), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Star), R(2), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(2), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-32), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"var y = 1;"
|
|
|
|
"for (var x = 10; x; --x) {"
|
|
|
|
" y = y * 12;"
|
|
|
|
"}"
|
|
|
|
"return y;",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-12-16 16:29:09 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
33,
|
2015-12-16 16:29:09 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(10), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Ldar), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(JumpIfToBooleanFalse), U8(20), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(2), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(12), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Mul), R(2), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(ToNumber), //
|
|
|
|
B(Dec), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-20), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Return), //
|
2015-11-02 15:24:25 +00:00
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"var x = 0;"
|
2015-12-16 16:29:09 +00:00
|
|
|
"for (var i = 0; false; i++) {"
|
2015-11-02 15:24:25 +00:00
|
|
|
" x = x + 1;"
|
|
|
|
"};"
|
|
|
|
"return x;",
|
|
|
|
2 * kPointerSize,
|
|
|
|
1,
|
|
|
|
9,
|
|
|
|
{
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"var x = 0;"
|
2015-12-16 16:29:09 +00:00
|
|
|
"for (var i = 0; true; ++i) {"
|
2015-11-02 15:24:25 +00:00
|
|
|
" x = x + 1;"
|
|
|
|
" if (x == 20) break;"
|
|
|
|
"};"
|
|
|
|
"return x;",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-11-02 15:24:25 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
37,
|
2015-11-02 15:24:25 +00:00
|
|
|
{
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(2), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(2), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(2), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(LdaSmi8), U8(20), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(2), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
|
|
|
B(Jump), U8(10), //
|
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(ToNumber), //
|
|
|
|
B(Inc), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-26), //
|
2015-11-02 15:24:25 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
};
|
2015-10-01 15:04:09 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-06 14:15:09 +00:00
|
|
|
|
2016-01-05 19:08:11 +00:00
|
|
|
TEST(JumpsRequiringConstantWideOperands) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
int constant_count = 0;
|
2016-01-13 15:40:32 +00:00
|
|
|
ExpectedSnippet<Handle<Object>, 316> snippets[] = {
|
2016-01-05 19:08:11 +00:00
|
|
|
{
|
|
|
|
REPEAT_256(SPACE, "var x = 0.1;")
|
|
|
|
REPEAT_32(SPACE, "var x = 0.2;")
|
|
|
|
REPEAT_16(SPACE, "var x = 0.3;")
|
|
|
|
REPEAT_8(SPACE, "var x = 0.4;")
|
|
|
|
"for (var i = 0; i < 3; i++) {\n"
|
|
|
|
" if (i == 1) continue;\n"
|
|
|
|
" if (i == 2) break;\n"
|
|
|
|
"}\n"
|
|
|
|
"return 3;",
|
|
|
|
kPointerSize * 3,
|
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
1359,
|
2016-01-05 19:08:11 +00:00
|
|
|
{
|
|
|
|
#define L(c) B(LdaConstant), U8(c), B(Star), R(0)
|
2016-01-13 15:40:32 +00:00
|
|
|
REPEAT_256(COMMA, L(constant_count++)),
|
2016-01-05 19:08:11 +00:00
|
|
|
#undef L
|
|
|
|
#define LW(c) B(LdaConstantWide), U16I(c), B(Star), R(0)
|
2016-01-13 15:40:32 +00:00
|
|
|
REPEAT_32(COMMA, LW(constant_count)),
|
|
|
|
REPEAT_16(COMMA, LW(constant_count)),
|
|
|
|
REPEAT_8(COMMA, LW(constant_count)),
|
2016-01-05 19:08:11 +00:00
|
|
|
#undef LW
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Star), R(2), //
|
2016-01-05 19:08:11 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestLessThan), R(2), //
|
2016-01-05 19:08:11 +00:00
|
|
|
B(JumpIfFalseConstantWide), U16(313), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Star), R(2), //
|
2016-01-05 19:08:11 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(2), //
|
2016-01-05 19:08:11 +00:00
|
|
|
B(JumpIfFalseConstantWide), U16(312), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(JumpConstantWide), U16(315), //
|
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Star), R(2), //
|
2016-01-05 19:08:11 +00:00
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(2), //
|
2016-01-05 19:08:11 +00:00
|
|
|
B(JumpIfFalseConstantWide), U16(312), //
|
|
|
|
B(JumpConstantWide), U16(314), //
|
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(ToNumber), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(Inc), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-47), //
|
2016-01-05 19:08:11 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
2016-01-13 15:40:32 +00:00
|
|
|
316,
|
2016-01-05 19:08:11 +00:00
|
|
|
{
|
|
|
|
#define S(x) CcTest::i_isolate()->factory()->NewNumber(x)
|
|
|
|
REPEAT_256(COMMA, S(0.1)),
|
|
|
|
REPEAT_32(COMMA, S(0.2)),
|
|
|
|
REPEAT_16(COMMA, S(0.3)),
|
|
|
|
REPEAT_8(COMMA, S(0.4)),
|
|
|
|
#undef S
|
|
|
|
#define N(x) CcTest::i_isolate()->factory()->NewNumberFromInt(x)
|
2016-01-13 15:40:32 +00:00
|
|
|
N(6), N(41), N(13), N(17)
|
2016-01-05 19:08:11 +00:00
|
|
|
#undef N
|
|
|
|
}}};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-06 14:15:09 +00:00
|
|
|
TEST(UnaryOperators) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
ExpectedSnippet<int> snippets[] = {
|
|
|
|
{"var x = 0;"
|
|
|
|
"while (x != 10) {"
|
|
|
|
" x = x + 10;"
|
|
|
|
"}"
|
|
|
|
"return x;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-06 14:15:09 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
29,
|
2015-10-06 14:15:09 +00:00
|
|
|
{
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-10-06 14:15:09 +00:00
|
|
|
B(LdaSmi8), U8(10), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(1), //
|
2015-10-06 14:15:09 +00:00
|
|
|
B(LogicalNot), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(JumpIfFalse), U8(14), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(10), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-21), //
|
2015-10-06 14:15:09 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"var x = false;"
|
|
|
|
"do {"
|
|
|
|
" x = !x;"
|
|
|
|
"} while(x == false);"
|
|
|
|
"return x;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-06 14:15:09 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
20,
|
2015-10-06 14:15:09 +00:00
|
|
|
{
|
2015-10-21 15:28:55 +00:00
|
|
|
B(LdaFalse), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(LogicalNot), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-10-21 15:28:55 +00:00
|
|
|
B(LdaFalse), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqual), R(1), //
|
|
|
|
B(JumpIfTrue), U8(-12), //
|
2015-10-21 15:28:55 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Return), //
|
2015-10-06 14:15:09 +00:00
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"var x = 101;"
|
|
|
|
"return void(x * 3);",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-06 14:15:09 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
12,
|
2015-10-06 14:15:09 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(101), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-10-06 14:15:09 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Mul), R(1), //
|
2015-10-06 14:15:09 +00:00
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"var x = 1234;"
|
|
|
|
"var y = void (x * x - 1);"
|
|
|
|
"return y;",
|
2016-01-13 15:40:32 +00:00
|
|
|
4 * kPointerSize,
|
2015-10-06 14:15:09 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
20,
|
2015-10-06 14:15:09 +00:00
|
|
|
{
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Star), R(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Mul), R(2), //
|
|
|
|
B(Star), R(3), //
|
2015-10-06 14:15:09 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Sub), R(3), //
|
2015-10-06 14:15:09 +00:00
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{1234}},
|
2015-10-28 09:49:20 +00:00
|
|
|
{"var x = 13;"
|
|
|
|
"return ~x;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-28 09:49:20 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
11,
|
2015-10-28 09:49:20 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(13), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-10-28 09:49:20 +00:00
|
|
|
B(LdaSmi8), U8(-1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(BitwiseXor), R(1), //
|
2015-10-28 09:49:20 +00:00
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"var x = 13;"
|
|
|
|
"return +x;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-28 09:49:20 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
11,
|
2015-10-28 09:49:20 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(13), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-10-28 09:49:20 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Mul), R(1), //
|
2015-10-28 09:49:20 +00:00
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"var x = 13;"
|
|
|
|
"return -x;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-28 09:49:20 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
11,
|
2015-10-28 09:49:20 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(13), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-10-28 09:49:20 +00:00
|
|
|
B(LdaSmi8), U8(-1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Mul), R(1), //
|
2015-10-28 09:49:20 +00:00
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0}};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-03 17:03:27 +00:00
|
|
|
TEST(Typeof) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
FeedbackVectorSpec feedback_spec(&zone);
|
|
|
|
FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot();
|
|
|
|
|
|
|
|
Handle<i::TypeFeedbackVector> vector =
|
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
|
|
|
|
|
|
|
|
ExpectedSnippet<const char*> snippets[] = {
|
|
|
|
{"function f() {\n"
|
|
|
|
" var x = 13;\n"
|
|
|
|
" return typeof(x);\n"
|
|
|
|
"}; f();",
|
|
|
|
kPointerSize,
|
|
|
|
1,
|
2015-11-13 14:14:57 +00:00
|
|
|
6,
|
2015-11-03 17:03:27 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(13), //
|
2015-11-13 14:14:57 +00:00
|
|
|
B(Star), R(0), //
|
2015-11-03 17:03:27 +00:00
|
|
|
B(TypeOf), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"var x = 13;\n"
|
|
|
|
"function f() {\n"
|
|
|
|
" return typeof(x);\n"
|
|
|
|
"}; f();",
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
5,
|
|
|
|
{
|
|
|
|
B(LdaGlobalInsideTypeofSloppy), U8(0), //
|
|
|
|
U8(vector->GetIndex(slot)), //
|
|
|
|
B(TypeOf), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"x"}},
|
|
|
|
{"var x = 13;\n"
|
|
|
|
"function f() {\n"
|
|
|
|
" 'use strict';\n"
|
|
|
|
" return typeof(x);\n"
|
|
|
|
"}; f();",
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
5,
|
|
|
|
{
|
|
|
|
B(LdaGlobalInsideTypeofStrict), U8(0), //
|
|
|
|
U8(vector->GetIndex(slot)), //
|
|
|
|
B(TypeOf), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"x"}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunction(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-28 09:49:20 +00:00
|
|
|
TEST(Delete) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
int deep_elements_flags =
|
|
|
|
ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos;
|
|
|
|
int closure = Register::function_closure().index();
|
|
|
|
int first_context_slot = Context::MIN_CONTEXT_SLOTS;
|
|
|
|
|
|
|
|
ExpectedSnippet<InstanceType> snippets[] = {
|
|
|
|
{"var a = {x:13, y:14}; return delete a.x;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-28 09:49:20 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
13,
|
2015-10-28 09:49:20 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(LdaConstant), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(DeletePropertySloppy), R(1), //
|
2015-10-28 09:49:20 +00:00
|
|
|
B(Return)
|
|
|
|
},
|
|
|
|
2,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
{"'use strict'; var a = {x:13, y:14}; return delete a.x;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-28 09:49:20 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
13,
|
2015-10-28 09:49:20 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(LdaConstant), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(DeletePropertyStrict), R(1), //
|
2015-10-28 09:49:20 +00:00
|
|
|
B(Return)
|
|
|
|
},
|
|
|
|
2,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
{"var a = {1:13, 2:14}; return delete a[2];",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-28 09:49:20 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
13,
|
2015-10-28 09:49:20 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(DeletePropertySloppy), R(1), //
|
2015-10-28 09:49:20 +00:00
|
|
|
B(Return)
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE}},
|
|
|
|
{"var a = 10; return delete a;",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
6,
|
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(10), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaFalse), //
|
|
|
|
B(Return)
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"'use strict';"
|
|
|
|
"var a = {1:10};"
|
|
|
|
"(function f1() {return a;});"
|
|
|
|
"return delete a[1];",
|
|
|
|
2 * kPointerSize,
|
|
|
|
1,
|
2015-12-09 11:53:07 +00:00
|
|
|
27,
|
2015-10-28 09:49:20 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CallRuntime), U16(Runtime::kNewFunctionContext), //
|
|
|
|
R(closure), U8(1), //
|
|
|
|
B(PushContext), R(0), //
|
|
|
|
B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot), //
|
|
|
|
B(CreateClosure), U8(1), U8(0), //
|
|
|
|
B(LdaContextSlot), R(0), U8(first_context_slot), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(DeletePropertyStrict), R(1), //
|
2015-10-28 09:49:20 +00:00
|
|
|
B(Return)
|
|
|
|
},
|
|
|
|
2,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE,
|
|
|
|
InstanceType::SHARED_FUNCTION_INFO_TYPE}},
|
|
|
|
{"return delete 'test';",
|
|
|
|
0 * kPointerSize,
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
{
|
|
|
|
B(LdaTrue), //
|
|
|
|
B(Return)
|
|
|
|
},
|
|
|
|
0},
|
2015-10-06 14:15:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-28 09:49:20 +00:00
|
|
|
TEST(GlobalDelete) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
int context = Register::function_context().index();
|
2015-11-27 16:59:28 +00:00
|
|
|
int native_context_index = Context::NATIVE_CONTEXT_INDEX;
|
|
|
|
int global_context_index = Context::EXTENSION_INDEX;
|
2015-10-28 09:49:20 +00:00
|
|
|
FeedbackVectorSpec feedback_spec(&zone);
|
|
|
|
FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot();
|
|
|
|
|
|
|
|
Handle<i::TypeFeedbackVector> vector =
|
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
|
|
|
|
|
|
|
|
ExpectedSnippet<InstanceType> snippets[] = {
|
|
|
|
{"var a = {x:13, y:14};\n function f() { return delete a.x; };\n f();",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
10,
|
2015-11-27 16:59:28 +00:00
|
|
|
{B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaConstant), U8(1), //
|
|
|
|
B(DeletePropertySloppy), R(0), //
|
|
|
|
B(Return)},
|
2015-10-28 09:49:20 +00:00
|
|
|
2,
|
|
|
|
{InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
{"a = {1:13, 2:14};\n"
|
|
|
|
"function f() {'use strict'; return delete a[1];};\n f();",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
10,
|
2015-11-27 16:59:28 +00:00
|
|
|
{B(LdaGlobalStrict), U8(0), U8(vector->GetIndex(slot)), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(DeletePropertyStrict), R(0), //
|
|
|
|
B(Return)},
|
2015-10-28 09:49:20 +00:00
|
|
|
1,
|
|
|
|
{InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
{"var a = {x:13, y:14};\n function f() { return delete a; };\n f();",
|
2015-11-27 16:59:28 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-28 09:49:20 +00:00
|
|
|
1,
|
2015-11-27 16:59:28 +00:00
|
|
|
15,
|
|
|
|
{B(LdaContextSlot), R(context), U8(native_context_index), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaContextSlot), R(0), U8(global_context_index), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(DeletePropertySloppy), R(1), //
|
|
|
|
B(Return)},
|
2015-10-28 09:49:20 +00:00
|
|
|
1,
|
|
|
|
{InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
{"b = 30;\n function f() { return delete b; };\n f();",
|
2015-11-27 16:59:28 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-28 09:49:20 +00:00
|
|
|
1,
|
2015-11-27 16:59:28 +00:00
|
|
|
15,
|
|
|
|
{B(LdaContextSlot), R(context), U8(native_context_index), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaContextSlot), R(0), U8(global_context_index), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(DeletePropertySloppy), R(1), //
|
|
|
|
B(Return)},
|
2015-10-28 09:49:20 +00:00
|
|
|
1,
|
|
|
|
{InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecode(snippets[i].code_snippet, "f");
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-13 09:39:55 +00:00
|
|
|
TEST(FunctionLiterals) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
2015-11-17 12:18:25 +00:00
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
FeedbackVectorSpec feedback_spec(&zone);
|
|
|
|
FeedbackVectorSlot slot = feedback_spec.AddCallICSlot();
|
|
|
|
|
|
|
|
Handle<i::TypeFeedbackVector> vector =
|
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
|
2015-10-13 09:39:55 +00:00
|
|
|
|
|
|
|
ExpectedSnippet<InstanceType> snippets[] = {
|
|
|
|
{"return function(){ }",
|
|
|
|
0,
|
|
|
|
1,
|
2015-11-26 14:33:06 +00:00
|
|
|
4,
|
2015-10-13 09:39:55 +00:00
|
|
|
{
|
2015-11-26 14:33:06 +00:00
|
|
|
B(CreateClosure), U8(0), U8(0), //
|
|
|
|
B(Return) //
|
2015-10-13 09:39:55 +00:00
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::SHARED_FUNCTION_INFO_TYPE}},
|
|
|
|
{"return (function(){ })()",
|
|
|
|
2 * kPointerSize,
|
|
|
|
1,
|
2015-11-26 14:33:06 +00:00
|
|
|
14,
|
2015-10-13 09:39:55 +00:00
|
|
|
{
|
2015-11-17 12:18:25 +00:00
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Star), R(1), //
|
2015-11-26 14:33:06 +00:00
|
|
|
B(CreateClosure), U8(0), U8(0), //
|
2015-11-17 12:18:25 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(Call), R(0), R(1), U8(0), U8(vector->GetIndex(slot)), //
|
|
|
|
B(Return) //
|
2015-10-13 09:39:55 +00:00
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::SHARED_FUNCTION_INFO_TYPE}},
|
|
|
|
{"return (function(x){ return x; })(1)",
|
|
|
|
3 * kPointerSize,
|
|
|
|
1,
|
2015-11-26 14:33:06 +00:00
|
|
|
18,
|
2015-10-13 09:39:55 +00:00
|
|
|
{
|
2015-11-17 12:18:25 +00:00
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Star), R(1), //
|
2015-11-26 14:33:06 +00:00
|
|
|
B(CreateClosure), U8(0), U8(0), //
|
2015-11-17 12:18:25 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(Call), R(0), R(1), U8(1), U8(vector->GetIndex(slot)), //
|
|
|
|
B(Return) //
|
2015-10-13 09:39:55 +00:00
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::SHARED_FUNCTION_INFO_TYPE}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-13 14:00:40 +00:00
|
|
|
|
2015-10-16 16:14:23 +00:00
|
|
|
TEST(RegExpLiterals) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
FeedbackVectorSpec feedback_spec(&zone);
|
2015-11-17 12:18:25 +00:00
|
|
|
FeedbackVectorSlot slot1 = feedback_spec.AddCallICSlot();
|
2015-10-16 16:14:23 +00:00
|
|
|
FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot();
|
2015-11-25 13:46:09 +00:00
|
|
|
uint8_t i_flags = JSRegExp::kIgnoreCase;
|
2015-10-16 16:14:23 +00:00
|
|
|
|
|
|
|
Handle<i::TypeFeedbackVector> vector =
|
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
|
|
|
|
|
|
|
|
ExpectedSnippet<const char*> snippets[] = {
|
|
|
|
{"return /ab+d/;",
|
2015-11-25 13:46:09 +00:00
|
|
|
0 * kPointerSize,
|
2015-10-16 16:14:23 +00:00
|
|
|
1,
|
2015-12-09 11:53:07 +00:00
|
|
|
5,
|
2015-10-16 16:14:23 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateRegExpLiteral), U8(0), U8(0), U8(0), //
|
|
|
|
B(Return), //
|
2015-10-16 16:14:23 +00:00
|
|
|
},
|
2015-11-25 13:46:09 +00:00
|
|
|
1,
|
|
|
|
{"ab+d"}},
|
2015-10-16 16:14:23 +00:00
|
|
|
{"return /(\\w+)\\s(\\w+)/i;",
|
2015-11-25 13:46:09 +00:00
|
|
|
0 * kPointerSize,
|
2015-10-16 16:14:23 +00:00
|
|
|
1,
|
2015-12-09 11:53:07 +00:00
|
|
|
5,
|
2015-10-16 16:14:23 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateRegExpLiteral), U8(0), U8(0), U8(i_flags), //
|
|
|
|
B(Return), //
|
2015-10-16 16:14:23 +00:00
|
|
|
},
|
2015-11-25 13:46:09 +00:00
|
|
|
1,
|
|
|
|
{"(\\w+)\\s(\\w+)"}},
|
2015-10-16 16:14:23 +00:00
|
|
|
{"return /ab+d/.exec('abdd');",
|
|
|
|
3 * kPointerSize,
|
|
|
|
1,
|
2015-12-09 11:53:07 +00:00
|
|
|
22,
|
2015-10-16 16:14:23 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateRegExpLiteral), U8(0), U8(0), U8(0), //
|
2015-10-22 14:55:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-11-25 13:46:09 +00:00
|
|
|
B(LoadICSloppy), R(1), U8(1), U8(vector->GetIndex(slot2)), //
|
2015-10-22 14:55:32 +00:00
|
|
|
B(Star), R(0), //
|
2015-11-25 13:46:09 +00:00
|
|
|
B(LdaConstant), U8(2), //
|
2015-10-22 14:55:32 +00:00
|
|
|
B(Star), R(2), //
|
2015-11-17 12:18:25 +00:00
|
|
|
B(Call), R(0), R(1), U8(1), U8(vector->GetIndex(slot1)), //
|
2015-10-22 14:55:32 +00:00
|
|
|
B(Return), //
|
2015-10-16 16:14:23 +00:00
|
|
|
},
|
2015-11-25 13:46:09 +00:00
|
|
|
3,
|
|
|
|
{"ab+d", "exec", "abdd"}},
|
2015-10-16 16:14:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-09 11:53:07 +00:00
|
|
|
TEST(RegExpLiteralsWide) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
int wide_idx = 0;
|
|
|
|
|
|
|
|
ExpectedSnippet<InstanceType, 257> snippets[] = {
|
|
|
|
{"var a;" REPEAT_256(SPACE, "a = 1.23;") "return /ab+d/;",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
1031,
|
|
|
|
{
|
|
|
|
REPEAT_256(COMMA, //
|
|
|
|
B(LdaConstant), U8(wide_idx++), //
|
|
|
|
B(Star), R(0)), //
|
|
|
|
B(CreateRegExpLiteralWide), U16(256), U16(0), U8(0), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
257,
|
|
|
|
{REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE),
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-13 14:00:40 +00:00
|
|
|
TEST(ArrayLiterals) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
2015-10-14 13:19:49 +00:00
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
FeedbackVectorSpec feedback_spec(&zone);
|
|
|
|
FeedbackVectorSlot slot1 = feedback_spec.AddKeyedStoreICSlot();
|
|
|
|
FeedbackVectorSlot slot2 = feedback_spec.AddKeyedStoreICSlot();
|
|
|
|
FeedbackVectorSlot slot3 = feedback_spec.AddKeyedStoreICSlot();
|
|
|
|
|
|
|
|
Handle<i::TypeFeedbackVector> vector =
|
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
|
2015-10-13 14:00:40 +00:00
|
|
|
|
|
|
|
int simple_flags =
|
|
|
|
ArrayLiteral::kDisableMementos | ArrayLiteral::kShallowElements;
|
|
|
|
int deep_elements_flags = ArrayLiteral::kDisableMementos;
|
|
|
|
ExpectedSnippet<InstanceType> snippets[] = {
|
|
|
|
{"return [ 1, 2 ];",
|
|
|
|
0,
|
|
|
|
1,
|
2015-12-09 11:53:07 +00:00
|
|
|
5,
|
2015-10-13 14:00:40 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateArrayLiteral), U8(0), U8(0), U8(simple_flags), //
|
|
|
|
B(Return) //
|
2015-10-13 14:00:40 +00:00
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE}},
|
|
|
|
{"var a = 1; return [ a, a + 1 ];",
|
2016-01-13 15:40:32 +00:00
|
|
|
4 * kPointerSize,
|
2015-10-13 14:00:40 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
38,
|
2015-10-13 14:00:40 +00:00
|
|
|
{
|
2015-10-14 13:19:49 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateArrayLiteral), U8(0), U8(0), U8(3), //
|
2015-10-14 13:19:49 +00:00
|
|
|
B(Star), R(2), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(KeyedStoreICSloppy), R(2), R(1), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(3), //
|
2015-10-14 13:19:49 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(3), //
|
2015-10-14 13:19:49 +00:00
|
|
|
B(KeyedStoreICSloppy), R(2), R(1), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(Ldar), R(2), //
|
2015-10-21 15:28:55 +00:00
|
|
|
B(Return), //
|
2015-10-13 14:00:40 +00:00
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE}},
|
|
|
|
{"return [ [ 1, 2 ], [ 3 ] ];",
|
|
|
|
0,
|
|
|
|
1,
|
2015-12-09 11:53:07 +00:00
|
|
|
5,
|
2015-10-13 14:00:40 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateArrayLiteral), U8(0), U8(2), U8(deep_elements_flags), //
|
|
|
|
B(Return) //
|
2015-10-13 14:00:40 +00:00
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE}},
|
|
|
|
{"var a = 1; return [ [ a, 2 ], [ a + 2 ] ];",
|
2016-01-13 15:40:32 +00:00
|
|
|
6 * kPointerSize,
|
2015-10-13 14:00:40 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
68,
|
2015-10-13 14:00:40 +00:00
|
|
|
{
|
2015-10-14 13:19:49 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateArrayLiteral), U8(0), U8(2), U8(deep_elements_flags), //
|
2015-10-14 13:19:49 +00:00
|
|
|
B(Star), R(2), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(1), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateArrayLiteral), U8(1), U8(0), U8(simple_flags), //
|
2015-10-14 13:19:49 +00:00
|
|
|
B(Star), R(4), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(3), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(KeyedStoreICSloppy), R(4), R(3), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(Ldar), R(4), //
|
|
|
|
B(KeyedStoreICSloppy), R(2), R(1), U8(vector->GetIndex(slot3)), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateArrayLiteral), U8(2), U8(1), U8(simple_flags), //
|
2015-10-14 13:19:49 +00:00
|
|
|
B(Star), R(4), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(5), //
|
2015-10-14 13:19:49 +00:00
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(5), //
|
2015-10-14 13:19:49 +00:00
|
|
|
B(KeyedStoreICSloppy), R(4), R(3), U8(vector->GetIndex(slot2)), //
|
|
|
|
B(Ldar), R(4), //
|
|
|
|
B(KeyedStoreICSloppy), R(2), R(1), U8(vector->GetIndex(slot3)), //
|
|
|
|
B(Ldar), R(2), //
|
|
|
|
B(Return), //
|
2015-10-13 14:00:40 +00:00
|
|
|
},
|
|
|
|
3,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE,
|
|
|
|
InstanceType::FIXED_ARRAY_TYPE}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-14 10:10:01 +00:00
|
|
|
|
2015-12-09 11:53:07 +00:00
|
|
|
TEST(ArrayLiteralsWide) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
int wide_idx = 0;
|
|
|
|
int simple_flags =
|
|
|
|
ArrayLiteral::kDisableMementos | ArrayLiteral::kShallowElements;
|
|
|
|
|
|
|
|
ExpectedSnippet<InstanceType, 257> snippets[] = {
|
|
|
|
{"var a;" REPEAT_256(SPACE, "a = 1.23;") "return [ 1 , 2 ];",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
1031,
|
|
|
|
{
|
|
|
|
REPEAT_256(COMMA, //
|
|
|
|
B(LdaConstant), U8(wide_idx++), //
|
|
|
|
B(Star), R(0)), //
|
|
|
|
B(CreateArrayLiteralWide), U16(256), U16(0), U8(simple_flags), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
257,
|
|
|
|
{REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE),
|
|
|
|
InstanceType::FIXED_ARRAY_TYPE}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-14 10:10:01 +00:00
|
|
|
TEST(ObjectLiterals) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
2015-10-22 14:55:32 +00:00
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
FeedbackVectorSpec feedback_spec(&zone);
|
|
|
|
FeedbackVectorSlot slot1 = feedback_spec.AddStoreICSlot();
|
|
|
|
|
|
|
|
Handle<i::TypeFeedbackVector> vector =
|
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
|
2015-10-14 10:10:01 +00:00
|
|
|
|
|
|
|
int simple_flags = ObjectLiteral::kFastElements |
|
|
|
|
ObjectLiteral::kShallowProperties |
|
|
|
|
ObjectLiteral::kDisableMementos;
|
|
|
|
int deep_elements_flags =
|
|
|
|
ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos;
|
|
|
|
ExpectedSnippet<InstanceType> snippets[] = {
|
|
|
|
{"return { };",
|
|
|
|
0,
|
|
|
|
1,
|
2015-12-09 11:53:07 +00:00
|
|
|
5,
|
2015-10-14 10:10:01 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(0), U8(0), U8(simple_flags), //
|
|
|
|
B(Return) //
|
2015-10-14 10:10:01 +00:00
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE}},
|
|
|
|
{"return { name: 'string', val: 9.2 };",
|
|
|
|
0,
|
|
|
|
1,
|
2015-12-09 11:53:07 +00:00
|
|
|
5,
|
2015-10-14 10:10:01 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), //
|
|
|
|
B(Return) //
|
2015-10-14 10:10:01 +00:00
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE}},
|
|
|
|
{"var a = 1; return { name: 'string', val: a };",
|
2015-10-22 14:55:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-14 10:10:01 +00:00
|
|
|
1,
|
2015-12-09 11:53:07 +00:00
|
|
|
19,
|
2015-10-14 10:10:01 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(StoreICSloppy), R(1), U8(1), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Return), //
|
2015-10-14 10:10:01 +00:00
|
|
|
},
|
|
|
|
2,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
{"var a = 1; return { val: a, val: a + 1 };",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-10-14 10:10:01 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
25,
|
2015-10-14 10:10:01 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(2), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(2), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(StoreICSloppy), R(1), U8(1), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Return), //
|
2015-10-14 10:10:01 +00:00
|
|
|
},
|
|
|
|
2,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
{"return { func: function() { } };",
|
2015-10-22 14:55:32 +00:00
|
|
|
1 * kPointerSize,
|
2015-10-14 10:10:01 +00:00
|
|
|
1,
|
2015-12-09 11:53:07 +00:00
|
|
|
16,
|
2015-10-14 10:10:01 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), //
|
|
|
|
B(Star), R(0), //
|
2015-12-23 09:34:00 +00:00
|
|
|
B(CreateClosure), U8(1), U8(0), //
|
|
|
|
B(StoreICSloppy), R(0), U8(2), U8(vector->GetIndex(slot1)), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Return), //
|
2015-10-14 10:10:01 +00:00
|
|
|
},
|
|
|
|
3,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE,
|
2015-12-23 09:34:00 +00:00
|
|
|
InstanceType::SHARED_FUNCTION_INFO_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
2015-10-14 10:10:01 +00:00
|
|
|
{"return { func(a) { return a; } };",
|
2015-10-22 14:55:32 +00:00
|
|
|
1 * kPointerSize,
|
2015-10-14 10:10:01 +00:00
|
|
|
1,
|
2015-12-09 11:53:07 +00:00
|
|
|
16,
|
2015-10-14 10:10:01 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), //
|
|
|
|
B(Star), R(0), //
|
2015-12-23 09:34:00 +00:00
|
|
|
B(CreateClosure), U8(1), U8(0), //
|
|
|
|
B(StoreICSloppy), R(0), U8(2), U8(vector->GetIndex(slot1)), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Return), //
|
2015-10-14 10:10:01 +00:00
|
|
|
},
|
|
|
|
3,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE,
|
2015-12-23 09:34:00 +00:00
|
|
|
InstanceType::SHARED_FUNCTION_INFO_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
2015-10-14 10:10:01 +00:00
|
|
|
{"return { get a() { return 2; } };",
|
|
|
|
5 * kPointerSize,
|
|
|
|
1,
|
2015-12-09 11:53:07 +00:00
|
|
|
29,
|
2015-10-14 10:10:01 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), //
|
2015-10-14 10:10:01 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaConstant), U8(1), //
|
|
|
|
B(Star), R(1), //
|
2015-11-26 14:33:06 +00:00
|
|
|
B(CreateClosure), U8(2), U8(0), //
|
2015-10-14 10:10:01 +00:00
|
|
|
B(Star), R(2), //
|
|
|
|
B(LdaNull), //
|
|
|
|
B(Star), R(3), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(4), //
|
|
|
|
B(CallRuntime), U16(Runtime::kDefineAccessorPropertyUnchecked), //
|
|
|
|
R(0), U8(5), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
3,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
|
|
|
|
InstanceType::SHARED_FUNCTION_INFO_TYPE}},
|
|
|
|
{"return { get a() { return this.x; }, set a(val) { this.x = val } };",
|
|
|
|
5 * kPointerSize,
|
|
|
|
1,
|
2015-12-09 11:53:07 +00:00
|
|
|
31,
|
2015-10-14 10:10:01 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), //
|
2015-10-14 10:10:01 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaConstant), U8(1), //
|
|
|
|
B(Star), R(1), //
|
2015-11-26 14:33:06 +00:00
|
|
|
B(CreateClosure), U8(2), U8(0), //
|
2015-10-14 10:10:01 +00:00
|
|
|
B(Star), R(2), //
|
2015-11-26 14:33:06 +00:00
|
|
|
B(CreateClosure), U8(3), U8(0), //
|
2015-10-14 10:10:01 +00:00
|
|
|
B(Star), R(3), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(4), //
|
|
|
|
B(CallRuntime), U16(Runtime::kDefineAccessorPropertyUnchecked), //
|
|
|
|
R(0), U8(5), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
4,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
|
|
|
|
InstanceType::SHARED_FUNCTION_INFO_TYPE,
|
|
|
|
InstanceType::SHARED_FUNCTION_INFO_TYPE}},
|
2015-10-14 14:51:55 +00:00
|
|
|
{"return { set b(val) { this.y = val } };",
|
2015-10-14 10:10:01 +00:00
|
|
|
5 * kPointerSize,
|
|
|
|
1,
|
2015-12-09 11:53:07 +00:00
|
|
|
29,
|
2015-10-14 10:10:01 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), //
|
2015-10-14 10:10:01 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaConstant), U8(1), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaNull), //
|
|
|
|
B(Star), R(2), //
|
2015-11-26 14:33:06 +00:00
|
|
|
B(CreateClosure), U8(2), U8(0), //
|
2015-10-14 10:10:01 +00:00
|
|
|
B(Star), R(3), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(4), //
|
|
|
|
B(CallRuntime), U16(Runtime::kDefineAccessorPropertyUnchecked), //
|
|
|
|
R(0), U8(5), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
2015-10-14 14:51:55 +00:00
|
|
|
3,
|
2015-10-14 10:10:01 +00:00
|
|
|
{InstanceType::FIXED_ARRAY_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
|
|
|
|
InstanceType::SHARED_FUNCTION_INFO_TYPE}},
|
|
|
|
{"var a = 1; return { 1: a };",
|
|
|
|
5 * kPointerSize,
|
|
|
|
1,
|
2015-12-09 11:53:07 +00:00
|
|
|
29,
|
2015-10-14 10:10:01 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(3), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(4), //
|
|
|
|
B(CallRuntime), U16(Runtime::kSetProperty), R(1), U8(4), //
|
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Return), //
|
2015-10-14 10:10:01 +00:00
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE}},
|
|
|
|
{"return { __proto__: null }",
|
|
|
|
2 * kPointerSize,
|
|
|
|
1,
|
2015-12-09 11:53:07 +00:00
|
|
|
17,
|
2015-10-14 10:10:01 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(0), U8(0), U8(simple_flags), //
|
2015-10-14 10:10:01 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaNull), B(Star), R(1), //
|
|
|
|
B(CallRuntime), U16(Runtime::kInternalSetPrototype), R(0), U8(2), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE}},
|
|
|
|
{"var a = 'test'; return { [a]: 1 }",
|
|
|
|
5 * kPointerSize,
|
|
|
|
1,
|
2015-12-09 11:53:07 +00:00
|
|
|
30,
|
2015-10-14 10:10:01 +00:00
|
|
|
{
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Star), R(0), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(1), U8(0), U8(simple_flags), //
|
2015-10-14 10:10:01 +00:00
|
|
|
B(Star), R(1), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(ToName), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(3), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(4), //
|
|
|
|
B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(1), //
|
|
|
|
U8(4), //
|
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
2,
|
|
|
|
{InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
|
|
|
|
InstanceType::FIXED_ARRAY_TYPE}},
|
|
|
|
{"var a = 'test'; return { val: a, [a]: 1 }",
|
|
|
|
5 * kPointerSize,
|
|
|
|
1,
|
2015-12-09 11:53:07 +00:00
|
|
|
36,
|
2015-10-14 10:10:01 +00:00
|
|
|
{
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Star), R(0), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(1), U8(0), U8(deep_elements_flags), //
|
2015-10-14 10:10:01 +00:00
|
|
|
B(Star), R(1), //
|
|
|
|
B(Ldar), R(0), //
|
2015-10-22 14:55:32 +00:00
|
|
|
B(StoreICSloppy), R(1), U8(2), U8(vector->GetIndex(slot1)), //
|
2015-10-14 10:10:01 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(ToName), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(3), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(4), //
|
|
|
|
B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(1), //
|
|
|
|
U8(4), //
|
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
3,
|
|
|
|
{InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
|
|
|
|
InstanceType::FIXED_ARRAY_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
{"var a = 'test'; return { [a]: 1, __proto__: {} }",
|
|
|
|
5 * kPointerSize,
|
|
|
|
1,
|
2015-12-09 11:53:07 +00:00
|
|
|
41,
|
2015-10-14 10:10:01 +00:00
|
|
|
{
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Star), R(0), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(1), U8(1), U8(simple_flags), //
|
2015-10-14 10:10:01 +00:00
|
|
|
B(Star), R(1), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(ToName), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(3), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(4), //
|
|
|
|
B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(1), //
|
|
|
|
U8(4), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(1), U8(0), U8(13), //
|
2015-10-14 10:10:01 +00:00
|
|
|
B(Star), R(2), //
|
|
|
|
B(CallRuntime), U16(Runtime::kInternalSetPrototype), R(1), U8(2), //
|
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
2,
|
|
|
|
{InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
|
|
|
|
InstanceType::FIXED_ARRAY_TYPE}},
|
|
|
|
{"var n = 'name'; return { [n]: 'val', get a() { }, set a(b) {} };",
|
|
|
|
5 * kPointerSize,
|
|
|
|
1,
|
2015-12-09 11:53:07 +00:00
|
|
|
64,
|
2015-10-14 10:10:01 +00:00
|
|
|
{
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Star), R(0), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(1), U8(0), U8(simple_flags), //
|
2015-10-14 10:10:01 +00:00
|
|
|
B(Star), R(1), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(ToName), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(LdaConstant), U8(2), //
|
|
|
|
B(Star), R(3), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(4), //
|
|
|
|
B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(1), //
|
|
|
|
U8(4), //
|
|
|
|
B(LdaConstant), U8(3), //
|
|
|
|
B(Star), R(2), //
|
2015-11-26 14:33:06 +00:00
|
|
|
B(CreateClosure), U8(4), U8(0), //
|
2015-10-14 10:10:01 +00:00
|
|
|
B(Star), R(3), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(4), //
|
|
|
|
B(CallRuntime), U16(Runtime::kDefineGetterPropertyUnchecked), //
|
2015-10-22 14:55:32 +00:00
|
|
|
R(1), U8(4), //
|
2015-10-14 10:10:01 +00:00
|
|
|
B(LdaConstant), U8(3), //
|
|
|
|
B(Star), R(2), //
|
2015-11-26 14:33:06 +00:00
|
|
|
B(CreateClosure), U8(5), U8(0), //
|
2015-10-14 10:10:01 +00:00
|
|
|
B(Star), R(3), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(4), //
|
|
|
|
B(CallRuntime), U16(Runtime::kDefineSetterPropertyUnchecked), //
|
2015-10-22 14:55:32 +00:00
|
|
|
R(1), U8(4), //
|
2015-10-14 10:10:01 +00:00
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
6,
|
|
|
|
{InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
|
|
|
|
InstanceType::FIXED_ARRAY_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
|
|
|
|
InstanceType::SHARED_FUNCTION_INFO_TYPE,
|
|
|
|
InstanceType::SHARED_FUNCTION_INFO_TYPE}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-09 11:53:07 +00:00
|
|
|
TEST(ObjectLiteralsWide) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
int deep_elements_flags =
|
|
|
|
ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos;
|
|
|
|
int wide_idx = 0;
|
|
|
|
|
|
|
|
ExpectedSnippet<InstanceType, 257> snippets[] = {
|
|
|
|
{"var a;" REPEAT_256(SPACE,
|
|
|
|
"a = 1.23;") "return { name: 'string', val: 9.2 };",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
1031,
|
|
|
|
{
|
|
|
|
REPEAT_256(COMMA, //
|
|
|
|
B(LdaConstant), U8(wide_idx++), //
|
|
|
|
B(Star), R(0)), //
|
|
|
|
B(CreateObjectLiteralWide), U16(256), U16(0), //
|
|
|
|
U8(deep_elements_flags), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
257,
|
|
|
|
{REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE),
|
|
|
|
InstanceType::FIXED_ARRAY_TYPE}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-14 10:10:01 +00:00
|
|
|
TEST(TopLevelObjectLiterals) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
2015-10-21 13:00:31 +00:00
|
|
|
int has_function_flags = ObjectLiteral::kFastElements |
|
|
|
|
ObjectLiteral::kHasFunction |
|
|
|
|
ObjectLiteral::kDisableMementos;
|
|
|
|
ExpectedSnippet<InstanceType> snippets[] = {
|
|
|
|
{"var a = { func: function() { } };",
|
2015-10-22 14:55:32 +00:00
|
|
|
5 * kPointerSize,
|
2015-10-21 13:00:31 +00:00
|
|
|
1,
|
2015-12-09 11:53:07 +00:00
|
|
|
48,
|
2015-10-21 13:00:31 +00:00
|
|
|
{
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2), //
|
|
|
|
B(LdaConstant), U8(1), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(2), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(2), U8(0), U8(has_function_flags), //
|
2015-10-21 13:00:31 +00:00
|
|
|
B(Star), R(4), //
|
2015-12-23 09:34:00 +00:00
|
|
|
B(CreateClosure), U8(3), U8(1), //
|
|
|
|
B(StoreICSloppy), R(4), U8(4), U8(3), //
|
2015-10-21 13:00:31 +00:00
|
|
|
B(CallRuntime), U16(Runtime::kToFastProperties), R(4), U8(1), //
|
|
|
|
B(Ldar), R(4), //
|
|
|
|
B(Star), R(3), //
|
|
|
|
B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(1), U8(3), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
5,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
|
|
|
|
InstanceType::FIXED_ARRAY_TYPE,
|
2015-12-23 09:34:00 +00:00
|
|
|
InstanceType::SHARED_FUNCTION_INFO_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
2015-10-21 13:00:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeTopLevelBytecode(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-15 10:35:18 +00:00
|
|
|
TEST(TryCatch) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
// TODO(rmcilroy): modify tests when we have real try catch support.
|
|
|
|
ExpectedSnippet<int> snippets[] = {
|
|
|
|
{"try { return 1; } catch(e) { return 2; }",
|
2015-10-21 15:28:55 +00:00
|
|
|
kPointerSize,
|
2015-10-15 10:35:18 +00:00
|
|
|
1,
|
2015-11-03 11:27:54 +00:00
|
|
|
3,
|
2015-10-15 10:35:18 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(TryFinally) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
// TODO(rmcilroy): modify tests when we have real try finally support.
|
|
|
|
ExpectedSnippet<int> snippets[] = {
|
|
|
|
{"var a = 1; try { a = 2; } finally { a = 3; }",
|
2015-10-21 15:28:55 +00:00
|
|
|
kPointerSize,
|
2015-10-15 10:35:18 +00:00
|
|
|
1,
|
|
|
|
14,
|
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"var a = 1; try { a = 2; } catch(e) { a = 20 } finally { a = 3; }",
|
2015-10-16 15:29:07 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-15 10:35:18 +00:00
|
|
|
1,
|
|
|
|
14,
|
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-15 16:46:16 +00:00
|
|
|
|
2015-10-19 10:59:00 +00:00
|
|
|
TEST(Throw) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
// TODO(rmcilroy): modify tests when we have real try catch support.
|
|
|
|
ExpectedSnippet<const char*> snippets[] = {
|
|
|
|
{"throw 1;",
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
3,
|
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Throw), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"throw 'Error';",
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
3,
|
|
|
|
{
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Throw), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"Error"}},
|
2015-11-03 11:27:54 +00:00
|
|
|
{"var a = 1; if (a) { throw 'Error'; };",
|
|
|
|
1 * kPointerSize,
|
2015-10-19 10:59:00 +00:00
|
|
|
1,
|
2015-11-13 14:14:57 +00:00
|
|
|
11,
|
2015-10-19 10:59:00 +00:00
|
|
|
{
|
2015-11-03 11:27:54 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(JumpIfToBooleanFalse), U8(5), //
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Throw), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
2015-10-19 10:59:00 +00:00
|
|
|
},
|
2015-11-02 15:24:25 +00:00
|
|
|
1,
|
|
|
|
{"Error"}},
|
2015-10-19 10:59:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-15 16:46:16 +00:00
|
|
|
TEST(CallNew) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
2015-10-21 13:00:31 +00:00
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
FeedbackVectorSpec feedback_spec(&zone);
|
2015-12-04 07:33:44 +00:00
|
|
|
FeedbackVectorSlot slot1 = feedback_spec.AddGeneralSlot();
|
2015-10-21 13:00:31 +00:00
|
|
|
FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot();
|
|
|
|
USE(slot1);
|
|
|
|
|
|
|
|
Handle<i::TypeFeedbackVector> vector =
|
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
|
|
|
|
|
|
|
|
ExpectedSnippet<InstanceType> snippets[] = {
|
|
|
|
{"function bar() { this.value = 0; }\n"
|
|
|
|
"function f() { return new bar(); }\n"
|
|
|
|
"f()",
|
2015-10-22 14:55:32 +00:00
|
|
|
1 * kPointerSize,
|
2015-10-21 13:00:31 +00:00
|
|
|
1,
|
2015-10-22 14:55:32 +00:00
|
|
|
10,
|
2015-10-21 13:00:31 +00:00
|
|
|
{
|
2015-10-22 14:55:32 +00:00
|
|
|
B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(New), R(0), R(0), U8(0), //
|
|
|
|
B(Return), //
|
2015-10-21 13:00:31 +00:00
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
{"function bar(x) { this.value = 18; this.x = x;}\n"
|
|
|
|
"function f() { return new bar(3); }\n"
|
|
|
|
"f()",
|
|
|
|
2 * kPointerSize,
|
|
|
|
1,
|
2015-10-22 14:55:32 +00:00
|
|
|
14,
|
2015-10-21 13:00:31 +00:00
|
|
|
{
|
2015-10-22 14:55:32 +00:00
|
|
|
B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(New), R(0), R(1), U8(1), //
|
|
|
|
B(Return), //
|
2015-10-21 13:00:31 +00:00
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
{"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"
|
|
|
|
"f()",
|
|
|
|
4 * kPointerSize,
|
|
|
|
1,
|
2015-10-22 14:55:32 +00:00
|
|
|
22,
|
2015-10-21 13:00:31 +00:00
|
|
|
{
|
2015-10-22 14:55:32 +00:00
|
|
|
B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(4), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(LdaSmi8), U8(5), //
|
|
|
|
B(Star), R(3), //
|
|
|
|
B(New), R(0), R(1), U8(3), //
|
|
|
|
B(Return), //
|
2015-10-21 13:00:31 +00:00
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecode(snippets[i].code_snippet, "f");
|
2015-10-22 20:42:22 +00:00
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
2015-10-21 13:00:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-16 15:29:07 +00:00
|
|
|
TEST(ContextVariables) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
2015-11-17 12:18:25 +00:00
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
FeedbackVectorSpec feedback_spec(&zone);
|
|
|
|
FeedbackVectorSlot slot = feedback_spec.AddCallICSlot();
|
|
|
|
|
|
|
|
Handle<i::TypeFeedbackVector> vector =
|
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
|
2015-10-16 15:29:07 +00:00
|
|
|
|
|
|
|
int closure = Register::function_closure().index();
|
2016-01-11 16:37:53 +00:00
|
|
|
int new_target = Register::new_target().index();
|
2015-10-16 15:29:07 +00:00
|
|
|
int first_context_slot = Context::MIN_CONTEXT_SLOTS;
|
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);
|
|
|
|
int wide_slot = first_context_slot + 3;
|
|
|
|
|
2015-10-16 15:29:07 +00:00
|
|
|
ExpectedSnippet<InstanceType> snippets[] = {
|
|
|
|
{"var a; return function() { a = 1; };",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
2015-11-26 14:33:06 +00:00
|
|
|
11,
|
2015-10-16 15:29:07 +00:00
|
|
|
{
|
|
|
|
B(CallRuntime), U16(Runtime::kNewFunctionContext), //
|
|
|
|
R(closure), U8(1), //
|
|
|
|
B(PushContext), R(0), //
|
2015-11-26 14:33:06 +00:00
|
|
|
B(CreateClosure), U8(0), U8(0), //
|
2015-10-16 15:29:07 +00:00
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::SHARED_FUNCTION_INFO_TYPE}},
|
|
|
|
{"var a = 1; return function() { a = 2; };",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
2015-11-26 14:33:06 +00:00
|
|
|
16,
|
2015-10-16 15:29:07 +00:00
|
|
|
{
|
|
|
|
B(CallRuntime), U16(Runtime::kNewFunctionContext), //
|
|
|
|
R(closure), U8(1), //
|
|
|
|
B(PushContext), R(0), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot), //
|
2015-11-26 14:33:06 +00:00
|
|
|
B(CreateClosure), U8(0), U8(0), //
|
2015-10-16 15:29:07 +00:00
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::SHARED_FUNCTION_INFO_TYPE}},
|
|
|
|
{"var a = 1; var b = 2; return function() { a = 2; b = 3 };",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
2015-11-26 14:33:06 +00:00
|
|
|
21,
|
2015-10-16 15:29:07 +00:00
|
|
|
{
|
|
|
|
B(CallRuntime), U16(Runtime::kNewFunctionContext), //
|
|
|
|
R(closure), U8(1), //
|
|
|
|
B(PushContext), R(0), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot + 1), //
|
2015-11-26 14:33:06 +00:00
|
|
|
B(CreateClosure), U8(0), U8(0), //
|
2015-10-16 15:29:07 +00:00
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::SHARED_FUNCTION_INFO_TYPE}},
|
|
|
|
{"var a; (function() { a = 2; })(); return a;",
|
|
|
|
3 * kPointerSize,
|
|
|
|
1,
|
2015-11-26 14:33:06 +00:00
|
|
|
24,
|
2015-10-16 15:29:07 +00:00
|
|
|
{
|
2015-11-17 12:18:25 +00:00
|
|
|
B(CallRuntime), U16(Runtime::kNewFunctionContext), //
|
|
|
|
R(closure), U8(1), //
|
|
|
|
B(PushContext), R(0), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Star), R(2), //
|
2015-11-26 14:33:06 +00:00
|
|
|
B(CreateClosure), U8(0), U8(0), //
|
2015-11-17 12:18:25 +00:00
|
|
|
B(Star), R(1), //
|
|
|
|
B(Call), R(1), R(2), U8(0), U8(vector->GetIndex(slot)), //
|
|
|
|
B(LdaContextSlot), R(0), U8(first_context_slot), //
|
|
|
|
B(Return), //
|
2015-10-16 15:29:07 +00:00
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::SHARED_FUNCTION_INFO_TYPE}},
|
|
|
|
{"'use strict'; let a = 1; { let b = 2; return function() { a + b; }; }",
|
|
|
|
4 * kPointerSize,
|
|
|
|
1,
|
2015-11-26 14:33:06 +00:00
|
|
|
44,
|
2015-10-16 15:29:07 +00:00
|
|
|
{
|
|
|
|
B(CallRuntime), U16(Runtime::kNewFunctionContext), //
|
|
|
|
R(closure), U8(1), //
|
|
|
|
B(PushContext), R(0), //
|
|
|
|
B(LdaTheHole), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot), //
|
2015-10-21 15:28:55 +00:00
|
|
|
B(LdaConstant), U8(0), //
|
2015-10-16 15:29:07 +00:00
|
|
|
B(Star), R(2), //
|
|
|
|
B(Ldar), R(closure), //
|
|
|
|
B(Star), R(3), //
|
|
|
|
B(CallRuntime), U16(Runtime::kPushBlockContext), R(2), U8(2), //
|
|
|
|
B(PushContext), R(1), //
|
|
|
|
B(LdaTheHole), //
|
|
|
|
B(StaContextSlot), R(1), U8(first_context_slot), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(StaContextSlot), R(1), U8(first_context_slot), //
|
2015-11-26 14:33:06 +00:00
|
|
|
B(CreateClosure), U8(1), U8(0), //
|
2015-10-16 15:29:07 +00:00
|
|
|
B(Return), //
|
|
|
|
},
|
2015-10-21 15:28:55 +00:00
|
|
|
2,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE,
|
2015-10-16 15:29:07 +00:00
|
|
|
InstanceType::SHARED_FUNCTION_INFO_TYPE}},
|
2016-01-11 16:37:53 +00:00
|
|
|
{"'use strict';\n"
|
|
|
|
REPEAT_249_UNIQUE_VARS()
|
|
|
|
"eval();"
|
|
|
|
"var b = 100;"
|
|
|
|
"return b",
|
|
|
|
3 * kPointerSize,
|
|
|
|
1,
|
|
|
|
1041,
|
|
|
|
{
|
|
|
|
B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
|
|
|
|
U8(1), //
|
|
|
|
B(PushContext), R(0), //
|
|
|
|
B(Ldar), THIS(1), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot), //
|
|
|
|
B(CreateUnmappedArguments), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot + 1), //
|
|
|
|
B(Ldar), R(new_target), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot + 2), //
|
|
|
|
REPEAT_249(COMMA, //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(StaContextSlot), R(0), U8(wide_slot++)), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(LdaGlobalStrict), U8(0), U8(1), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Call), R(1), R(2), U8(0), U8(0), //
|
|
|
|
B(LdaSmi8), U8(100), //
|
|
|
|
B(StaContextSlotWide), R(0), U16(256), //
|
|
|
|
B(LdaContextSlotWide), R(0), U16(256), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
2015-10-16 15:29:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ContextParameters) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
int closure = Register::function_closure().index();
|
|
|
|
int first_context_slot = Context::MIN_CONTEXT_SLOTS;
|
2015-10-22 20:42:22 +00:00
|
|
|
|
2015-10-16 15:29:07 +00:00
|
|
|
ExpectedSnippet<InstanceType> snippets[] = {
|
|
|
|
{"function f(arg1) { return function() { arg1 = 2; }; }",
|
|
|
|
1 * kPointerSize,
|
|
|
|
2,
|
2015-11-26 14:33:06 +00:00
|
|
|
16,
|
2015-10-16 15:29:07 +00:00
|
|
|
{
|
|
|
|
B(CallRuntime), U16(Runtime::kNewFunctionContext), //
|
|
|
|
R(closure), U8(1), //
|
|
|
|
B(PushContext), R(0), //
|
|
|
|
B(Ldar), R(helper.kLastParamIndex), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot), //
|
2015-11-26 14:33:06 +00:00
|
|
|
B(CreateClosure), U8(0), U8(0), //
|
2015-10-16 15:29:07 +00:00
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::SHARED_FUNCTION_INFO_TYPE}},
|
|
|
|
{"function f(arg1) { var a = function() { arg1 = 2; }; return arg1; }",
|
|
|
|
2 * kPointerSize,
|
|
|
|
2,
|
2015-11-26 14:33:06 +00:00
|
|
|
21,
|
2015-10-16 15:29:07 +00:00
|
|
|
{
|
|
|
|
B(CallRuntime), U16(Runtime::kNewFunctionContext), //
|
|
|
|
R(closure), U8(1), //
|
|
|
|
B(PushContext), R(1), //
|
|
|
|
B(Ldar), R(helper.kLastParamIndex), //
|
|
|
|
B(StaContextSlot), R(1), U8(first_context_slot), //
|
2015-11-26 14:33:06 +00:00
|
|
|
B(CreateClosure), U8(0), U8(0), //
|
2015-10-16 15:29:07 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaContextSlot), R(1), U8(first_context_slot), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::SHARED_FUNCTION_INFO_TYPE}},
|
|
|
|
{"function f(a1, a2, a3, a4) { return function() { a1 = a3; }; }",
|
|
|
|
1 * kPointerSize,
|
|
|
|
5,
|
2015-11-26 14:33:06 +00:00
|
|
|
21,
|
2015-10-16 15:29:07 +00:00
|
|
|
{
|
|
|
|
B(CallRuntime), U16(Runtime::kNewFunctionContext), //
|
|
|
|
R(closure), U8(1), //
|
|
|
|
B(PushContext), R(0), //
|
|
|
|
B(Ldar), R(helper.kLastParamIndex - 3), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot + 1), //
|
|
|
|
B(Ldar), R(helper.kLastParamIndex -1), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot), //
|
2015-11-26 14:33:06 +00:00
|
|
|
B(CreateClosure), U8(0), U8(0), //
|
2015-10-16 15:29:07 +00:00
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::SHARED_FUNCTION_INFO_TYPE}},
|
|
|
|
{"function f() { var self = this; return function() { self = 2; }; }",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
2015-11-26 14:33:06 +00:00
|
|
|
16,
|
2015-10-16 15:29:07 +00:00
|
|
|
{
|
|
|
|
B(CallRuntime), U16(Runtime::kNewFunctionContext), //
|
|
|
|
R(closure), U8(1), //
|
|
|
|
B(PushContext), R(0), //
|
|
|
|
B(Ldar), R(helper.kLastParamIndex), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot), //
|
2015-11-26 14:33:06 +00:00
|
|
|
B(CreateClosure), U8(0), U8(0), //
|
2015-10-16 15:29:07 +00:00
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::SHARED_FUNCTION_INFO_TYPE}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunction(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-22 20:40:20 +00:00
|
|
|
|
2015-10-26 18:11:23 +00:00
|
|
|
TEST(OuterContextVariables) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
int context = Register::function_context().index();
|
|
|
|
int first_context_slot = Context::MIN_CONTEXT_SLOTS;
|
|
|
|
|
|
|
|
ExpectedSnippet<InstanceType> snippets[] = {
|
|
|
|
{"function Outer() {"
|
|
|
|
" var outerVar = 1;"
|
|
|
|
" function Inner(innerArg) {"
|
|
|
|
" this.innerFunc = function() { return outerVar * innerArg; }"
|
|
|
|
" }"
|
|
|
|
" this.getInnerFunc = function() { return new Inner(1).innerFunc; }"
|
|
|
|
"}"
|
|
|
|
"var f = new Outer().getInnerFunc();",
|
|
|
|
2 * kPointerSize,
|
|
|
|
1,
|
|
|
|
20,
|
|
|
|
{
|
|
|
|
B(Ldar), R(context), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaContextSlot), R(0), U8(Context::PREVIOUS_INDEX), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaContextSlot), R(0), U8(first_context_slot), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaContextSlot), R(context), U8(first_context_slot), //
|
|
|
|
B(Mul), R(1), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"function Outer() {"
|
|
|
|
" var outerVar = 1;"
|
|
|
|
" function Inner(innerArg) {"
|
|
|
|
" this.innerFunc = function() { outerVar = innerArg; }"
|
|
|
|
" }"
|
|
|
|
" this.getInnerFunc = function() { return new Inner(1).innerFunc; }"
|
|
|
|
"}"
|
|
|
|
"var f = new Outer().getInnerFunc();",
|
|
|
|
2 * kPointerSize,
|
|
|
|
1,
|
|
|
|
21,
|
|
|
|
{
|
|
|
|
B(LdaContextSlot), R(context), U8(first_context_slot), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), R(context), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaContextSlot), R(1), U8(Context::PREVIOUS_INDEX), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(StaContextSlot), R(1), U8(first_context_slot), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionNoFilter(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-22 20:40:20 +00:00
|
|
|
TEST(CountOperators) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
FeedbackVectorSpec feedback_spec(&zone);
|
|
|
|
FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot();
|
|
|
|
FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot();
|
|
|
|
Handle<i::TypeFeedbackVector> vector =
|
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
|
|
|
|
|
2015-10-27 13:33:11 +00:00
|
|
|
FeedbackVectorSpec store_feedback_spec(&zone);
|
|
|
|
FeedbackVectorSlot store_slot = store_feedback_spec.AddStoreICSlot();
|
|
|
|
Handle<i::TypeFeedbackVector> store_vector =
|
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &store_feedback_spec);
|
|
|
|
|
2015-10-22 20:40:20 +00:00
|
|
|
int closure = Register::function_closure().index();
|
|
|
|
int first_context_slot = Context::MIN_CONTEXT_SLOTS;
|
|
|
|
|
|
|
|
int object_literal_flags =
|
|
|
|
ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos;
|
2015-10-27 13:33:11 +00:00
|
|
|
int array_literal_flags =
|
|
|
|
ArrayLiteral::kDisableMementos | ArrayLiteral::kShallowElements;
|
2015-10-22 20:40:20 +00:00
|
|
|
|
|
|
|
ExpectedSnippet<InstanceType> snippets[] = {
|
|
|
|
{"var a = 1; return ++a;",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
2015-11-13 14:14:57 +00:00
|
|
|
9,
|
2015-10-22 20:40:20 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(ToNumber), //
|
|
|
|
B(Inc), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"var a = 1; return a++;",
|
|
|
|
2 * kPointerSize,
|
|
|
|
1,
|
2015-11-13 14:14:57 +00:00
|
|
|
13,
|
2015-10-22 20:40:20 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(ToNumber), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Inc), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"var a = 1; return --a;",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
2015-11-13 14:14:57 +00:00
|
|
|
9,
|
2015-10-22 20:40:20 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(ToNumber), //
|
|
|
|
B(Dec), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"var a = 1; return a--;",
|
|
|
|
2 * kPointerSize,
|
|
|
|
1,
|
2015-11-13 14:14:57 +00:00
|
|
|
13,
|
2015-10-22 20:40:20 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(ToNumber), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Dec), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"var a = { val: 1 }; return a.val++;",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-10-22 20:40:20 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
23,
|
2015-10-22 20:40:20 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(0), U8(0), U8(object_literal_flags), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(LoadICSloppy), R(1), U8(1), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(ToNumber), //
|
|
|
|
B(Star), R(2), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(Inc), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(StoreICSloppy), R(1), U8(1), U8(vector->GetIndex(slot2)), //
|
|
|
|
B(Ldar), R(2), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(Return), //
|
2015-10-22 20:40:20 +00:00
|
|
|
},
|
|
|
|
2,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
{"var a = { val: 1 }; return --a.val;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-22 20:40:20 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
19,
|
2015-10-22 20:40:20 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(0), U8(0), U8(object_literal_flags), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
|
|
|
B(LoadICSloppy), R(1), U8(1), U8(vector->GetIndex(slot1)), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(ToNumber), //
|
|
|
|
B(Dec), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(StoreICSloppy), R(1), U8(1), U8(vector->GetIndex(slot2)), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(Return), //
|
2015-10-22 20:40:20 +00:00
|
|
|
},
|
|
|
|
2,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
{"var name = 'var'; var a = { val: 1 }; return a[name]--;",
|
2016-01-13 15:40:32 +00:00
|
|
|
5 * kPointerSize,
|
2015-10-22 20:40:20 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
30,
|
2015-10-22 20:40:20 +00:00
|
|
|
{
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Star), R(0), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(1), U8(0), U8(object_literal_flags), //
|
2015-10-22 20:40:20 +00:00
|
|
|
B(Star), R(1), //
|
|
|
|
B(Star), R(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
2015-10-22 20:40:20 +00:00
|
|
|
B(Star), R(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(KeyedLoadICSloppy), R(2), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(ToNumber), //
|
|
|
|
B(Star), R(4), //
|
2015-10-22 20:40:20 +00:00
|
|
|
B(Dec), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(KeyedStoreICSloppy), R(2), R(3), U8(vector->GetIndex(slot2)), //
|
|
|
|
B(Ldar), R(4), //
|
2015-10-22 20:40:20 +00:00
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
2,
|
|
|
|
{InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
|
|
|
|
InstanceType::FIXED_ARRAY_TYPE}},
|
|
|
|
{"var name = 'var'; var a = { val: 1 }; return ++a[name];",
|
2016-01-13 15:40:32 +00:00
|
|
|
4 * kPointerSize,
|
2015-10-22 20:40:20 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
26,
|
2015-10-22 20:40:20 +00:00
|
|
|
{
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Star), R(0), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(1), U8(0), U8(object_literal_flags), //
|
2015-10-22 20:40:20 +00:00
|
|
|
B(Star), R(1), //
|
|
|
|
B(Star), R(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(3), //
|
|
|
|
B(KeyedLoadICSloppy), R(2), U8(vector->GetIndex(slot1)), //
|
2015-10-22 20:40:20 +00:00
|
|
|
B(ToNumber), //
|
|
|
|
B(Inc), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(KeyedStoreICSloppy), R(2), R(3), U8(vector->GetIndex(slot2)), //
|
2015-10-22 20:40:20 +00:00
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
2,
|
|
|
|
{InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
|
|
|
|
InstanceType::FIXED_ARRAY_TYPE}},
|
|
|
|
{"var a = 1; var b = function() { return a }; return ++a;",
|
|
|
|
2 * kPointerSize,
|
|
|
|
1,
|
2015-11-26 14:33:06 +00:00
|
|
|
26,
|
2015-10-22 20:40:20 +00:00
|
|
|
{
|
|
|
|
B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
|
|
|
|
U8(1), //
|
|
|
|
B(PushContext), R(1), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(StaContextSlot), R(1), U8(first_context_slot), //
|
2015-11-26 14:33:06 +00:00
|
|
|
B(CreateClosure), U8(0), U8(0), //
|
2015-10-22 20:40:20 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaContextSlot), R(1), U8(first_context_slot), //
|
|
|
|
B(ToNumber), //
|
|
|
|
B(Inc), //
|
|
|
|
B(StaContextSlot), R(1), U8(first_context_slot), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::SHARED_FUNCTION_INFO_TYPE}},
|
|
|
|
{"var a = 1; var b = function() { return a }; return a--;",
|
|
|
|
3 * kPointerSize,
|
|
|
|
1,
|
2015-11-26 14:33:06 +00:00
|
|
|
30,
|
2015-10-22 20:40:20 +00:00
|
|
|
{
|
|
|
|
B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
|
|
|
|
U8(1), //
|
|
|
|
B(PushContext), R(1), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(StaContextSlot), R(1), U8(first_context_slot), //
|
2015-11-26 14:33:06 +00:00
|
|
|
B(CreateClosure), U8(0), U8(0), //
|
2015-10-22 20:40:20 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaContextSlot), R(1), U8(first_context_slot), //
|
|
|
|
B(ToNumber), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(Dec), //
|
|
|
|
B(StaContextSlot), R(1), U8(first_context_slot), //
|
|
|
|
B(Ldar), R(2), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::SHARED_FUNCTION_INFO_TYPE}},
|
2015-10-27 13:33:11 +00:00
|
|
|
{"var idx = 1; var a = [1, 2]; return a[idx++] = 2;",
|
2016-01-13 15:40:32 +00:00
|
|
|
4 * kPointerSize,
|
2015-10-27 13:33:11 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
27,
|
2015-10-27 13:33:11 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateArrayLiteral), U8(0), U8(0), U8(array_literal_flags), //
|
2015-10-27 13:33:11 +00:00
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(2), //
|
2015-10-27 13:33:11 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(ToNumber), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(3), //
|
2015-10-27 13:33:11 +00:00
|
|
|
B(Inc), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(KeyedStoreICSloppy), R(2), R(3), //
|
2015-10-27 13:33:11 +00:00
|
|
|
U8(store_vector->GetIndex(store_slot)), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE}},
|
2015-10-22 20:40:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(GlobalCountOperators) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
FeedbackVectorSpec feedback_spec(&zone);
|
|
|
|
FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot();
|
|
|
|
FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot();
|
|
|
|
|
|
|
|
Handle<i::TypeFeedbackVector> vector =
|
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
|
|
|
|
|
|
|
|
ExpectedSnippet<const char*> snippets[] = {
|
|
|
|
{"var global = 1;\nfunction f() { return ++global; }\nf()",
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
9,
|
|
|
|
{
|
|
|
|
B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(ToNumber), //
|
|
|
|
B(Inc), //
|
|
|
|
B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"global"}},
|
|
|
|
{"var global = 1;\nfunction f() { return global--; }\nf()",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
13,
|
|
|
|
{
|
|
|
|
B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(ToNumber), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Dec), //
|
|
|
|
B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Return),
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"global"}},
|
|
|
|
{"unallocated = 1;\nfunction f() { 'use strict'; return --unallocated; }"
|
|
|
|
"f()",
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
9,
|
|
|
|
{
|
|
|
|
B(LdaGlobalStrict), U8(0), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(ToNumber), //
|
|
|
|
B(Dec), //
|
|
|
|
B(StaGlobalStrict), U8(0), U8(vector->GetIndex(slot2)), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"unallocated"}},
|
|
|
|
{"unallocated = 1;\nfunction f() { return unallocated++; }\nf()",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
13,
|
|
|
|
{
|
|
|
|
B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(ToNumber), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Inc), //
|
|
|
|
B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Return),
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"unallocated"}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecode(snippets[i].code_snippet, "f");
|
2015-10-22 20:42:22 +00:00
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(CompoundExpressions) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
int closure = Register::function_closure().index();
|
|
|
|
int first_context_slot = Context::MIN_CONTEXT_SLOTS;
|
|
|
|
|
|
|
|
FeedbackVectorSpec feedback_spec(&zone);
|
|
|
|
FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot();
|
|
|
|
FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot();
|
|
|
|
|
|
|
|
Handle<i::TypeFeedbackVector> vector =
|
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
|
|
|
|
|
|
|
|
int object_literal_flags =
|
|
|
|
ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos;
|
|
|
|
ExpectedSnippet<InstanceType> snippets[] = {
|
|
|
|
{"var a = 1; a += 2;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-22 20:42:22 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
14,
|
2015-10-22 20:42:22 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-10-22 20:42:22 +00:00
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(1), //
|
2015-10-22 20:42:22 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"var a = 1; a /= 2;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-22 20:42:22 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
14,
|
2015-10-22 20:42:22 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-10-22 20:42:22 +00:00
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Div), R(1), //
|
2015-10-22 20:42:22 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"var a = { val: 2 }; a.name *= 2;",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-10-22 20:42:22 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
24,
|
2015-10-22 20:42:22 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(0), U8(0), U8(object_literal_flags), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(LoadICSloppy), R(1), U8(1), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(Star), R(2), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Mul), R(2), //
|
|
|
|
B(StoreICSloppy), R(1), U8(1), U8(vector->GetIndex(slot2)), //
|
2015-12-09 11:53:07 +00:00
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
2015-10-22 20:42:22 +00:00
|
|
|
},
|
|
|
|
2,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
{"var a = { 1: 2 }; a[1] ^= 2;",
|
2016-01-13 15:40:32 +00:00
|
|
|
4 * kPointerSize,
|
2015-10-22 20:42:22 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
27,
|
2015-10-22 20:42:22 +00:00
|
|
|
{
|
2015-12-09 11:53:07 +00:00
|
|
|
B(CreateObjectLiteral), U8(0), U8(0), U8(object_literal_flags), //
|
2015-10-22 20:42:22 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2015-10-22 20:42:22 +00:00
|
|
|
B(Star), R(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(KeyedLoadICSloppy), R(1), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(Star), R(3), //
|
2015-10-22 20:42:22 +00:00
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(BitwiseXor), R(3), //
|
|
|
|
B(KeyedStoreICSloppy), R(1), R(2), U8(vector->GetIndex(slot2)), //
|
2015-10-22 20:42:22 +00:00
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE}},
|
|
|
|
{"var a = 1; (function f() { return a; }); a |= 24;",
|
|
|
|
2 * kPointerSize,
|
|
|
|
1,
|
2015-11-26 14:33:06 +00:00
|
|
|
29,
|
2015-10-22 20:42:22 +00:00
|
|
|
{
|
|
|
|
B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
|
|
|
|
U8(1), //
|
|
|
|
B(PushContext), R(0), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot), //
|
2015-11-26 14:33:06 +00:00
|
|
|
B(CreateClosure), U8(0), U8(0), //
|
2015-10-22 20:42:22 +00:00
|
|
|
B(LdaContextSlot), R(0), U8(first_context_slot), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(24), //
|
|
|
|
B(BitwiseOr), R(1), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::SHARED_FUNCTION_INFO_TYPE}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(GlobalCompoundExpressions) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
FeedbackVectorSpec feedback_spec(&zone);
|
|
|
|
FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot();
|
|
|
|
FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot();
|
|
|
|
|
|
|
|
Handle<i::TypeFeedbackVector> vector =
|
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
|
|
|
|
|
|
|
|
ExpectedSnippet<const char*> snippets[] = {
|
|
|
|
{"var global = 1;\nfunction f() { return global &= 1; }\nf()",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
13,
|
|
|
|
{
|
|
|
|
B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(BitwiseAnd), R(0), //
|
|
|
|
B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"global"}},
|
|
|
|
{"unallocated = 1;\nfunction f() { return unallocated += 1; }\nf()",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
13,
|
|
|
|
{
|
|
|
|
B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot1)), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Add), R(0), //
|
|
|
|
B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"unallocated"}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecode(snippets[i].code_snippet, "f");
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
2015-10-22 20:40:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-22 21:41:47 +00:00
|
|
|
|
|
|
|
TEST(CreateArguments) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
int closure = Register::function_closure().index();
|
|
|
|
int first_context_slot = Context::MIN_CONTEXT_SLOTS;
|
|
|
|
|
|
|
|
FeedbackVectorSpec feedback_spec(&zone);
|
|
|
|
FeedbackVectorSlot slot = feedback_spec.AddKeyedLoadICSlot();
|
|
|
|
|
|
|
|
Handle<i::TypeFeedbackVector> vector =
|
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
|
|
|
|
|
|
|
|
ExpectedSnippet<const char*> snippets[] = {
|
|
|
|
{"function f() { return arguments; }",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
2015-11-13 14:14:57 +00:00
|
|
|
4,
|
2015-10-22 21:41:47 +00:00
|
|
|
{
|
|
|
|
B(CreateMappedArguments), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"function f() { return arguments[0]; }",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-10-22 21:41:47 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
10,
|
2015-10-22 21:41:47 +00:00
|
|
|
{
|
|
|
|
B(CreateMappedArguments), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-10-22 21:41:47 +00:00
|
|
|
B(LdaZero), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(KeyedLoadICSloppy), R(1), U8(vector->GetIndex(slot)), //
|
2015-10-22 21:41:47 +00:00
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"function f() { 'use strict'; return arguments; }",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
2015-11-13 14:14:57 +00:00
|
|
|
4,
|
2015-10-22 21:41:47 +00:00
|
|
|
{
|
|
|
|
B(CreateUnmappedArguments), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"function f(a) { return arguments[0]; }",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-10-22 21:41:47 +00:00
|
|
|
2,
|
2016-01-13 15:40:32 +00:00
|
|
|
22,
|
2015-10-22 21:41:47 +00:00
|
|
|
{
|
|
|
|
B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
|
|
|
|
U8(1), //
|
|
|
|
B(PushContext), R(1), //
|
|
|
|
B(Ldar), R(BytecodeGeneratorHelper::kLastParamIndex), //
|
|
|
|
B(StaContextSlot), R(1), U8(first_context_slot), //
|
|
|
|
B(CreateMappedArguments), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(2), //
|
2015-10-22 21:41:47 +00:00
|
|
|
B(LdaZero), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(KeyedLoadICSloppy), R(2), U8(vector->GetIndex(slot)), //
|
2015-10-22 21:41:47 +00:00
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"function f(a, b, c) { return arguments; }",
|
|
|
|
2 * kPointerSize,
|
|
|
|
4,
|
2015-11-13 14:14:57 +00:00
|
|
|
26,
|
2015-10-22 21:41:47 +00:00
|
|
|
{
|
|
|
|
B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
|
|
|
|
U8(1), //
|
|
|
|
B(PushContext), R(1), //
|
|
|
|
B(Ldar), R(BytecodeGeneratorHelper::kLastParamIndex - 2), //
|
|
|
|
B(StaContextSlot), R(1), U8(first_context_slot + 2), //
|
|
|
|
B(Ldar), R(BytecodeGeneratorHelper::kLastParamIndex - 1), //
|
|
|
|
B(StaContextSlot), R(1), U8(first_context_slot + 1), //
|
|
|
|
B(Ldar), R(BytecodeGeneratorHelper::kLastParamIndex), //
|
|
|
|
B(StaContextSlot), R(1), U8(first_context_slot), //
|
|
|
|
B(CreateMappedArguments), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"function f(a, b, c) { 'use strict'; return arguments; }",
|
|
|
|
1 * kPointerSize,
|
|
|
|
4,
|
2015-11-13 14:14:57 +00:00
|
|
|
4,
|
2015-10-22 21:41:47 +00:00
|
|
|
{
|
|
|
|
B(CreateUnmappedArguments), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunction(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(IllegalRedeclaration) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
2015-11-24 14:15:58 +00:00
|
|
|
CHECK_GE(MessageTemplate::kVarRedeclaration, 128);
|
|
|
|
// Must adapt bytecode if this changes.
|
|
|
|
|
|
|
|
ExpectedSnippet<Handle<Object>, 2> snippets[] = {
|
2015-10-22 21:41:47 +00:00
|
|
|
{"const a = 1; { var a = 2; }",
|
|
|
|
3 * kPointerSize,
|
|
|
|
1,
|
|
|
|
14,
|
|
|
|
{
|
|
|
|
B(LdaConstant), U8(0), //
|
2015-11-24 14:15:58 +00:00
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaConstant), U8(1), //
|
2015-10-22 21:41:47 +00:00
|
|
|
B(Star), R(2), //
|
|
|
|
B(CallRuntime), U16(Runtime::kNewSyntaxError), R(1), U8(2), //
|
|
|
|
B(Throw), //
|
|
|
|
},
|
2015-11-24 14:15:58 +00:00
|
|
|
2,
|
|
|
|
{helper.factory()->NewNumberFromInt(MessageTemplate::kVarRedeclaration),
|
|
|
|
helper.factory()->NewStringFromAsciiChecked("a")}},
|
2015-10-22 21:41:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-26 15:31:05 +00:00
|
|
|
|
2015-10-29 12:06:00 +00:00
|
|
|
TEST(ForIn) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
int simple_flags =
|
|
|
|
ArrayLiteral::kDisableMementos | ArrayLiteral::kShallowElements;
|
|
|
|
int deep_elements_flags =
|
|
|
|
ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos;
|
|
|
|
|
|
|
|
FeedbackVectorSpec feedback_spec(&zone);
|
|
|
|
feedback_spec.AddStoreICSlot();
|
|
|
|
FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot();
|
|
|
|
FeedbackVectorSlot slot3 = feedback_spec.AddStoreICSlot();
|
|
|
|
FeedbackVectorSlot slot4 = feedback_spec.AddStoreICSlot();
|
|
|
|
Handle<i::TypeFeedbackVector> vector =
|
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
|
|
|
|
|
|
|
|
ExpectedSnippet<InstanceType> snippets[] = {
|
|
|
|
{"for (var p in null) {}",
|
|
|
|
2 * kPointerSize,
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
{B(LdaUndefined), B(Return)},
|
|
|
|
0},
|
|
|
|
{"for (var p in undefined) {}",
|
|
|
|
2 * kPointerSize,
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
{B(LdaUndefined), B(Return)},
|
|
|
|
0},
|
2015-12-21 13:30:47 +00:00
|
|
|
{"for (var p in undefined) {}",
|
|
|
|
2 * kPointerSize,
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
{B(LdaUndefined), B(Return)},
|
|
|
|
0},
|
2015-10-29 12:06:00 +00:00
|
|
|
{"var x = 'potatoes';\n"
|
|
|
|
"for (var p in x) { return p; }",
|
2015-12-21 13:30:47 +00:00
|
|
|
8 * kPointerSize,
|
2015-10-29 12:06:00 +00:00
|
|
|
1,
|
2016-01-18 12:39:18 +00:00
|
|
|
42,
|
2015-10-29 12:06:00 +00:00
|
|
|
{
|
2016-01-18 12:39:18 +00:00
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(JumpIfUndefined), U8(36), //
|
|
|
|
B(JumpIfNull), U8(34), //
|
|
|
|
B(ToObject), //
|
|
|
|
B(JumpIfNull), U8(31), //
|
|
|
|
B(Star), R(3), //
|
|
|
|
B(ForInPrepare), R(4), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(7), //
|
|
|
|
B(ForInDone), R(7), R(6), //
|
|
|
|
B(JumpIfTrue), U8(19), //
|
|
|
|
B(ForInNext), R(3), R(7), R(4), //
|
|
|
|
B(JumpIfUndefined), U8(7), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(Return), //
|
|
|
|
B(ForInStep), R(7), //
|
|
|
|
B(Star), R(7), //
|
|
|
|
B(Jump), U8(-20), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
2015-10-29 12:06:00 +00:00
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
{"var x = 0;\n"
|
|
|
|
"for (var p in [1,2,3]) { x += p; }",
|
2016-01-13 15:40:32 +00:00
|
|
|
9 * kPointerSize,
|
2015-10-29 12:06:00 +00:00
|
|
|
1,
|
2016-01-18 12:39:18 +00:00
|
|
|
54,
|
2015-10-29 12:06:00 +00:00
|
|
|
{
|
2015-12-21 13:30:47 +00:00
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(CreateArrayLiteral), U8(0), U8(0), U8(3), //
|
2016-01-18 12:39:18 +00:00
|
|
|
B(JumpIfUndefined), U8(45), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(JumpIfNull), U8(43), //
|
2016-01-18 12:39:18 +00:00
|
|
|
B(ToObject), //
|
|
|
|
B(JumpIfNull), U8(40), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(Star), R(3), //
|
2016-01-18 12:39:18 +00:00
|
|
|
B(ForInPrepare), R(4), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(7), //
|
|
|
|
B(ForInDone), R(7), R(6), //
|
2016-01-18 12:39:18 +00:00
|
|
|
B(JumpIfTrue), U8(28), //
|
|
|
|
B(ForInNext), R(3), R(7), R(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(JumpIfUndefined), U8(16), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(Star), R(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Star), R(8), //
|
|
|
|
B(Ldar), R(2), //
|
|
|
|
B(Add), R(8), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(Star), R(1), //
|
|
|
|
B(ForInStep), R(7), //
|
|
|
|
B(Star), R(7), //
|
2016-01-18 12:39:18 +00:00
|
|
|
B(Jump), U8(-29), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
2015-10-29 12:06:00 +00:00
|
|
|
},
|
|
|
|
1,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE}},
|
|
|
|
{"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-01-14 13:43:14 +00:00
|
|
|
8 * kPointerSize,
|
2015-10-29 12:06:00 +00:00
|
|
|
1,
|
2016-01-18 12:39:18 +00:00
|
|
|
91,
|
2015-10-29 12:06:00 +00:00
|
|
|
{
|
2015-12-21 13:30:47 +00:00
|
|
|
B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(CreateArrayLiteral), U8(1), U8(1), U8(simple_flags), //
|
2016-01-18 12:39:18 +00:00
|
|
|
B(JumpIfUndefined), U8(79), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(JumpIfNull), U8(77), //
|
2016-01-18 12:39:18 +00:00
|
|
|
B(ToObject), //
|
|
|
|
B(JumpIfNull), U8(74), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(Star), R(1), //
|
2016-01-18 12:39:18 +00:00
|
|
|
B(ForInPrepare), R(2), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(5), //
|
|
|
|
B(ForInDone), R(5), R(4), //
|
2016-01-18 12:39:18 +00:00
|
|
|
B(JumpIfTrue), U8(62), //
|
|
|
|
B(ForInNext), R(1), R(5), R(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(JumpIfUndefined), U8(50), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(Star), R(6), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(7), //
|
|
|
|
B(Ldar), R(6), //
|
|
|
|
B(StoreICSloppy), R(7), U8(2), U8(vector->GetIndex(slot4)), //
|
|
|
|
B(Ldar), R(0), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(Star), R(6), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(LoadICSloppy), R(6), U8(2), U8(vector->GetIndex(slot2)), //
|
2016-01-14 13:43:14 +00:00
|
|
|
B(Star), R(7), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(LdaSmi8), U8(10), //
|
2016-01-14 13:43:14 +00:00
|
|
|
B(TestEqual), R(7), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(20), //
|
|
|
|
B(Ldar), R(0), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(Star), R(6), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(LoadICSloppy), R(6), U8(2), U8(vector->GetIndex(slot3)), //
|
2016-01-14 13:43:14 +00:00
|
|
|
B(Star), R(7), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(LdaSmi8), U8(20), //
|
2016-01-14 13:43:14 +00:00
|
|
|
B(TestEqual), R(7), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
|
|
|
B(Jump), U8(8), //
|
|
|
|
B(ForInStep), R(5), //
|
|
|
|
B(Star), R(5), //
|
2016-01-18 12:39:18 +00:00
|
|
|
B(Jump), U8(-63), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
2015-10-29 12:06:00 +00:00
|
|
|
},
|
|
|
|
3,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
{"var x = [ 10, 11, 12 ] ;\n"
|
|
|
|
"for (x[0] in [1,2,3]) { return x[3]; }",
|
2016-01-13 15:40:32 +00:00
|
|
|
9 * kPointerSize,
|
2015-10-29 12:06:00 +00:00
|
|
|
1,
|
2016-01-18 12:39:18 +00:00
|
|
|
68,
|
2015-10-29 12:06:00 +00:00
|
|
|
{
|
2015-12-21 13:30:47 +00:00
|
|
|
B(CreateArrayLiteral), U8(0), U8(0), U8(simple_flags), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(CreateArrayLiteral), U8(1), U8(1), U8(simple_flags), //
|
2016-01-18 12:39:18 +00:00
|
|
|
B(JumpIfUndefined), U8(56), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(JumpIfNull), U8(54), //
|
2016-01-18 12:39:18 +00:00
|
|
|
B(ToObject), //
|
|
|
|
B(JumpIfNull), U8(51), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(Star), R(1), //
|
2016-01-18 12:39:18 +00:00
|
|
|
B(ForInPrepare), R(2), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(5), //
|
|
|
|
B(ForInDone), R(5), R(4), //
|
2016-01-18 12:39:18 +00:00
|
|
|
B(JumpIfTrue), U8(39), //
|
|
|
|
B(ForInNext), R(1), R(5), R(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(JumpIfUndefined), U8(27), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(Star), R(6), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(Star), R(7), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(8), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(Ldar), R(6), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(KeyedStoreICSloppy), R(7), R(8), U8(vector->GetIndex(slot3)), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(6), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(KeyedLoadICSloppy), R(6), U8(vector->GetIndex(slot2)), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(Return), //
|
|
|
|
B(ForInStep), R(5), //
|
|
|
|
B(Star), R(5), //
|
2016-01-18 12:39:18 +00:00
|
|
|
B(Jump), U8(-40), //
|
2015-12-21 13:30:47 +00:00
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
2015-10-29 12:06:00 +00:00
|
|
|
},
|
|
|
|
2,
|
|
|
|
{InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-26 15:31:05 +00:00
|
|
|
TEST(Conditional) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
ExpectedSnippet<int> snippets[] = {
|
|
|
|
{"return 1 ? 2 : 3;",
|
|
|
|
0,
|
|
|
|
1,
|
2015-10-30 16:48:18 +00:00
|
|
|
11,
|
2015-10-26 15:31:05 +00:00
|
|
|
{
|
2015-10-30 16:48:18 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(JumpIfToBooleanFalse), U8(6), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Jump), U8(4), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Return), //
|
2015-10-26 15:31:05 +00:00
|
|
|
}},
|
|
|
|
{"return 1 ? 2 ? 3 : 4 : 5;",
|
|
|
|
0,
|
|
|
|
1,
|
2015-10-30 16:48:18 +00:00
|
|
|
19,
|
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(JumpIfToBooleanFalse), U8(14), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(JumpIfToBooleanFalse), U8(6), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Jump), U8(4), //
|
|
|
|
B(LdaSmi8), U8(4), //
|
|
|
|
B(Jump), U8(4), //
|
|
|
|
B(LdaSmi8), U8(5), //
|
|
|
|
B(Return), //
|
2015-10-26 15:31:05 +00:00
|
|
|
}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-30 12:55:05 +00:00
|
|
|
|
|
|
|
TEST(Switch) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
ExpectedSnippet<int> snippets[] = {
|
|
|
|
{"var a = 1;\n"
|
|
|
|
"switch(a) {\n"
|
|
|
|
" case 1: return 2;\n"
|
|
|
|
" case 2: return 3;\n"
|
|
|
|
"}\n",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-10-30 12:55:05 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
30,
|
2015-10-30 12:55:05 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), // The tag variable is allocated as a
|
2015-11-13 14:14:57 +00:00
|
|
|
B(Star), R(0), // local by the parser, hence the store
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(2), // to another local register.
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(TestEqualStrict), R(2), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(JumpIfTrue), U8(10), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqualStrict), R(2), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(JumpIfTrue), U8(7), //
|
|
|
|
B(Jump), U8(8), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Return), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Return), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"var a = 1;\n"
|
|
|
|
"switch(a) {\n"
|
|
|
|
" case 1: a = 2; break;\n"
|
|
|
|
" case 2: a = 3; break;\n"
|
|
|
|
"}\n",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-10-30 12:55:05 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
36,
|
2015-10-30 12:55:05 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(2), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqualStrict), R(2), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(JumpIfTrue), U8(10), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqualStrict), R(2), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(JumpIfTrue), U8(10), //
|
|
|
|
B(Jump), U8(14), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Jump), U8(8), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Jump), U8(2), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"var a = 1;\n"
|
|
|
|
"switch(a) {\n"
|
|
|
|
" case 1: a = 2; // fall-through\n"
|
|
|
|
" case 2: a = 3; break;\n"
|
|
|
|
"}\n",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-10-30 12:55:05 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
34,
|
2015-10-30 12:55:05 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(2), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqualStrict), R(2), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(JumpIfTrue), U8(10), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqualStrict), R(2), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(JumpIfTrue), U8(8), //
|
|
|
|
B(Jump), U8(12), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Jump), U8(2), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"var a = 1;\n"
|
|
|
|
"switch(a) {\n"
|
|
|
|
" case 2: break;\n"
|
|
|
|
" case 3: break;\n"
|
|
|
|
" default: a = 1; break;\n"
|
|
|
|
"}\n",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-10-30 12:55:05 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
34,
|
2015-10-30 12:55:05 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(2), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqualStrict), R(2), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(JumpIfTrue), U8(10), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqualStrict), R(2), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(JumpIfTrue), U8(6), //
|
|
|
|
B(Jump), U8(6), //
|
|
|
|
B(Jump), U8(10), //
|
|
|
|
B(Jump), U8(8), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Jump), U8(2), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"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"
|
|
|
|
"}\n",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-10-30 12:55:05 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
43,
|
2015-10-30 12:55:05 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(TypeOf), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(2), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqualStrict), R(2), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(JumpIfTrue), U8(10), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqualStrict), R(2), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(JumpIfTrue), U8(10), //
|
|
|
|
B(Jump), U8(14), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Jump), U8(14), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Jump), U8(8), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Jump), U8(2), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"var a = 1;\n"
|
|
|
|
"switch(a) {\n"
|
|
|
|
" case typeof(a): a = 1; break;\n"
|
|
|
|
" default: a = 2; break;\n"
|
|
|
|
"}\n",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-10-30 12:55:05 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
31,
|
2015-10-30 12:55:05 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(2), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(TypeOf), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqualStrict), R(2), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(JumpIfTrue), U8(4), //
|
|
|
|
B(Jump), U8(8), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Jump), U8(8), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Jump), U8(2), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"var a = 1;\n"
|
|
|
|
"switch(a) {\n"
|
|
|
|
" case 1:\n" REPEAT_64(SPACE, " a = 2;")
|
|
|
|
"break;\n"
|
|
|
|
" case 2: a = 3; break;"
|
|
|
|
"}\n",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-10-30 12:55:05 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
288,
|
2015-10-30 12:55:05 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(2), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqualStrict), R(2), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(JumpIfTrue), U8(10), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqualStrict), R(2), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(JumpIfTrueConstant), U8(0), //
|
|
|
|
B(JumpConstant), U8(1), //
|
|
|
|
REPEAT_64(COMMA, //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Star), R(1)), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(Jump), U8(8), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Jump), U8(2), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
2,
|
|
|
|
{262, 266}},
|
|
|
|
{"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"
|
|
|
|
"}\n",
|
2016-01-13 15:40:32 +00:00
|
|
|
5 * kPointerSize,
|
2015-10-30 12:55:05 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
60,
|
2015-10-30 12:55:05 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(3), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqualStrict), R(3), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(JumpIfTrue), U8(10), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqualStrict), R(3), //
|
|
|
|
B(JumpIfTrue), U8(36), //
|
|
|
|
B(Jump), U8(38), //
|
|
|
|
B(Ldar), R(2), //
|
|
|
|
B(Star), R(4), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(4), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(4), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestEqualStrict), R(4), //
|
2015-10-30 12:55:05 +00:00
|
|
|
B(JumpIfTrue), U8(4), //
|
|
|
|
B(Jump), U8(8), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(Jump), U8(8), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(Jump), U8(2), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-03 11:27:54 +00:00
|
|
|
|
|
|
|
TEST(BasicBlockToBoolean) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
2016-01-13 15:40:32 +00:00
|
|
|
// Check that we generate JumpIfToBoolean if they are at the start of basic
|
2015-11-03 11:27:54 +00:00
|
|
|
// blocks.
|
|
|
|
ExpectedSnippet<int> snippets[] = {
|
|
|
|
{"var a = 1; if (a || a < 0) { return 1; }",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-11-03 11:27:54 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
20,
|
2015-11-03 11:27:54 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(JumpIfToBooleanTrue), U8(9), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-11-03 11:27:54 +00:00
|
|
|
B(LdaZero), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestLessThan), R(1), //
|
2015-11-03 11:27:54 +00:00
|
|
|
B(JumpIfToBooleanFalse), U8(5), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Return), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"var a = 1; if (a && a < 0) { return 1; }",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-11-03 11:27:54 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
20,
|
2015-11-03 11:27:54 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(JumpIfToBooleanFalse), U8(9), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-11-03 11:27:54 +00:00
|
|
|
B(LdaZero), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestLessThan), R(1), //
|
2015-11-03 11:27:54 +00:00
|
|
|
B(JumpIfToBooleanFalse), U8(5), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Return), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"var a = 1; a = (a || a < 0) ? 2 : 3;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-11-03 11:27:54 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
25,
|
2015-11-03 11:27:54 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(JumpIfToBooleanTrue), U8(9), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(1), //
|
2015-11-03 11:27:54 +00:00
|
|
|
B(LdaZero), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestLessThan), R(1), //
|
2015-11-03 11:27:54 +00:00
|
|
|
B(JumpIfToBooleanFalse), U8(6), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Jump), U8(4), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DeadCodeRemoval) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
ExpectedSnippet<int> snippets[] = {
|
|
|
|
{"return; var a = 1; a();",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
{
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"if (false) { return; }; var a = 1;",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
6,
|
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"if (true) { return 1; } else { return 2; };",
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
3,
|
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"var a = 1; if (a) { return 1; }; return 2;",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
2015-11-13 14:14:57 +00:00
|
|
|
12,
|
2015-11-03 11:27:54 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(JumpIfToBooleanFalse), U8(5), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Return), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-06 15:00:26 +00:00
|
|
|
|
|
|
|
TEST(ThisFunction) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
int closure = Register::function_closure().index();
|
|
|
|
|
|
|
|
ExpectedSnippet<int> snippets[] = {
|
|
|
|
{"var f;\n f = function f() { }",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
9,
|
|
|
|
{
|
|
|
|
B(LdaTheHole), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), R(closure), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"var f;\n f = function f() { return f; }",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
2015-11-13 14:14:57 +00:00
|
|
|
8,
|
2015-11-06 15:00:26 +00:00
|
|
|
{
|
|
|
|
B(LdaTheHole), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), R(closure), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunction(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-06 15:45:54 +00:00
|
|
|
|
|
|
|
TEST(NewTarget) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
2015-11-25 11:36:38 +00:00
|
|
|
int new_target = Register::new_target().index();
|
|
|
|
|
2015-11-06 15:45:54 +00:00
|
|
|
ExpectedSnippet<int> snippets[] = {
|
|
|
|
{"return new.target;",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
2015-11-25 11:36:38 +00:00
|
|
|
5,
|
|
|
|
{
|
|
|
|
B(Ldar), R(new_target), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
|
|
|
{"new.target;",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
6,
|
2015-11-06 15:45:54 +00:00
|
|
|
{
|
2015-11-25 11:36:38 +00:00
|
|
|
B(Ldar), R(new_target), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
}},
|
2015-11-13 14:14:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(RemoveRedundantLdar) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
ExpectedSnippet<int> snippets[] = {
|
2015-12-16 16:29:09 +00:00
|
|
|
{"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.
|
2015-11-13 14:14:57 +00:00
|
|
|
" if (ld_a > 10) break;\n"
|
|
|
|
"}\n"
|
|
|
|
"return ld_a;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-11-13 14:14:57 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
29,
|
2015-12-16 16:29:09 +00:00
|
|
|
{B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), R(0), // This load should not be removed as it
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), // is the target of the branch.
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Add), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(10), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestGreaterThan), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
|
|
|
B(Jump), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Jump), U8(-20), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Return)}},
|
2015-11-13 14:14:57 +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"
|
|
|
|
"return ld_a;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-11-13 14:14:57 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
27,
|
2015-12-16 16:29:09 +00:00
|
|
|
{B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Ldar), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Add), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(10), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(TestGreaterThan), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(JumpIfFalse), U8(4), //
|
|
|
|
B(Jump), U8(2), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Return)}},
|
|
|
|
{"var ld_a = 1;\n"
|
|
|
|
" ld_a = ld_a + ld_a;\n"
|
|
|
|
" return ld_a;",
|
2016-01-13 15:40:32 +00:00
|
|
|
2 * kPointerSize,
|
2015-12-16 16:29:09 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
13,
|
2015-11-13 14:14:57 +00:00
|
|
|
{
|
2015-12-16 16:29:09 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Add), R(1), //
|
2015-12-16 16:29:09 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(Return) //
|
2015-11-06 15:45:54 +00:00
|
|
|
}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-20 11:17:10 +00:00
|
|
|
|
|
|
|
TEST(AssignmentsInBinaryExpression) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
ExpectedSnippet<const char*> snippets[] = {
|
|
|
|
{"var x = 0, y = 1;\n"
|
|
|
|
"return (x = 2, y = 3, x = 4, y = 5)",
|
|
|
|
2 * kPointerSize,
|
|
|
|
1,
|
|
|
|
24,
|
|
|
|
{
|
|
|
|
B(LdaZero), B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(LdaSmi8), U8(4), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(5), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"var x = 55;\n"
|
|
|
|
"var y = (x = 100);\n"
|
|
|
|
"return y",
|
|
|
|
2 * kPointerSize,
|
|
|
|
1,
|
|
|
|
11,
|
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(55), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(100), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"var x = 55;\n"
|
|
|
|
"x = x + (x = 100) + (x = 101);\n"
|
|
|
|
"return x;",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-11-20 11:17:10 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
23,
|
2015-11-20 11:17:10 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(55), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(LdaSmi8), U8(100), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Add), R(1), //
|
2015-11-20 11:17:10 +00:00
|
|
|
B(Star), R(2), //
|
|
|
|
B(LdaSmi8), U8(101), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(0), //
|
2015-11-20 11:17:10 +00:00
|
|
|
B(Add), R(2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"var x = 55;\n"
|
|
|
|
"x = (x = 56) - x + (x = 57);\n"
|
|
|
|
"x++;\n"
|
|
|
|
"return x;",
|
|
|
|
3 * kPointerSize,
|
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
31,
|
2015-11-20 11:17:10 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(55), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(56), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Sub), R(1), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(LdaSmi8), U8(57), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(0), //
|
2015-11-20 11:17:10 +00:00
|
|
|
B(Add), R(2), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(ToNumber), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Inc), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"var x = 55;\n"
|
|
|
|
"var y = x + (x = 1) + (x = 2) + (x = 3);\n"
|
|
|
|
"return y;",
|
2016-01-13 15:40:32 +00:00
|
|
|
4 * kPointerSize,
|
2015-11-20 11:17:10 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
31,
|
2015-11-20 11:17:10 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(55), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Star), R(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Add), R(2), //
|
2015-11-20 11:17:10 +00:00
|
|
|
B(Star), R(3), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(0), //
|
2015-11-20 11:17:10 +00:00
|
|
|
B(Add), R(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(2), //
|
2015-11-20 11:17:10 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(Add), R(2), //
|
2015-11-20 11:17:10 +00:00
|
|
|
B(Star), R(1), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"var x = 55;\n"
|
|
|
|
"var x = x + (x = 1) + (x = 2) + (x = 3);\n"
|
|
|
|
"return x;",
|
2016-01-13 15:40:32 +00:00
|
|
|
3 * kPointerSize,
|
2015-11-20 11:17:10 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
31,
|
2015-11-20 11:17:10 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(55), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Add), R(1), //
|
2015-11-20 11:17:10 +00:00
|
|
|
B(Star), R(2), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(0), //
|
2015-11-20 11:17:10 +00:00
|
|
|
B(Add), R(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(1), //
|
2015-11-20 11:17:10 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(Add), R(1), //
|
2015-11-20 11:17:10 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"var x = 10, y = 20;\n"
|
|
|
|
"return x + (x = 1) + (x + 1) * (y = 2) + (y = 3) + (x = 4) + (y = 5) + "
|
|
|
|
"y;\n",
|
2016-01-13 15:40:32 +00:00
|
|
|
5 * kPointerSize,
|
2015-11-20 11:17:10 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
69,
|
2015-11-20 11:17:10 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(10), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(20), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
2015-11-20 11:17:10 +00:00
|
|
|
B(Star), R(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(Add), R(2), //
|
2015-11-20 11:17:10 +00:00
|
|
|
B(Star), R(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Star), R(2), //
|
2015-11-20 11:17:10 +00:00
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Add), R(2), //
|
|
|
|
B(Star), R(4), //
|
|
|
|
B(LdaSmi8), U8(2), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Mul), R(4), //
|
|
|
|
B(Add), R(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(2), //
|
2015-11-20 11:17:10 +00:00
|
|
|
B(LdaSmi8), U8(3), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(2), //
|
2015-11-20 11:17:10 +00:00
|
|
|
B(Star), R(3), //
|
|
|
|
B(LdaSmi8), U8(4), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(0), //
|
2015-12-22 09:26:06 +00:00
|
|
|
B(Add), R(3), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(2), //
|
2015-11-20 11:17:10 +00:00
|
|
|
B(LdaSmi8), U8(5), //
|
|
|
|
B(Star), R(1), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Add), R(2), //
|
2015-11-20 11:17:10 +00:00
|
|
|
B(Star), R(3), //
|
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Add), R(3), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"var x = 17;\n"
|
|
|
|
"return 1 + x + (x++) + (++x);\n",
|
2016-01-13 15:40:32 +00:00
|
|
|
4 * kPointerSize,
|
2015-11-20 11:17:10 +00:00
|
|
|
1,
|
2016-01-13 15:40:32 +00:00
|
|
|
37,
|
2015-11-20 11:17:10 +00:00
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(17), //
|
|
|
|
B(Star), R(0), //
|
|
|
|
B(LdaSmi8), U8(1), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(Add), R(1), //
|
|
|
|
B(Star), R(2), //
|
|
|
|
B(Ldar), R(0), //
|
|
|
|
B(ToNumber), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Inc), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(0), //
|
2015-11-20 11:17:10 +00:00
|
|
|
B(Ldar), R(1), //
|
|
|
|
B(Add), R(2), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(3), //
|
|
|
|
B(Ldar), R(0), //
|
2015-11-20 11:17:10 +00:00
|
|
|
B(ToNumber), //
|
|
|
|
B(Inc), //
|
2016-01-13 15:40:32 +00:00
|
|
|
B(Star), R(0), //
|
|
|
|
B(Add), R(3), //
|
2015-11-20 11:17:10 +00:00
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
0}};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-16 17:24:20 +00:00
|
|
|
|
2016-01-08 15:45:59 +00:00
|
|
|
TEST(Eval) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
int closure = Register::function_closure().index();
|
|
|
|
int new_target = Register::new_target().index();
|
|
|
|
|
|
|
|
int first_context_slot = Context::MIN_CONTEXT_SLOTS;
|
|
|
|
|
|
|
|
ExpectedSnippet<const char*> snippets[] = {
|
|
|
|
{"return eval('1;');",
|
|
|
|
9 * kPointerSize,
|
|
|
|
1,
|
2016-01-12 13:11:27 +00:00
|
|
|
67,
|
2016-01-08 15:45:59 +00:00
|
|
|
{
|
2016-01-18 12:00:04 +00:00
|
|
|
B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
|
|
|
|
U8(1), //
|
|
|
|
B(PushContext), R(0), //
|
|
|
|
B(Ldar), THIS(1), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot), //
|
|
|
|
B(CreateMappedArguments), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot + 1), //
|
|
|
|
B(Ldar), R(new_target), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot + 2), //
|
|
|
|
B(Mov), R(0), R(3), //
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Star), R(4), //
|
|
|
|
B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), //
|
|
|
|
R(3), U8(2), R(1), //
|
|
|
|
B(LdaConstant), U8(1), //
|
|
|
|
B(Star), R(3), //
|
|
|
|
B(Mov), R(1), R(4), //
|
|
|
|
B(Mov), R(3), R(5), //
|
|
|
|
B(Mov), R(closure), R(6), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(7), //
|
|
|
|
B(LdaSmi8), U8(10), //
|
|
|
|
B(Star), R(8), //
|
|
|
|
B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), //
|
|
|
|
U8(5), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Call), R(1), R(2), U8(1), U8(0), //
|
|
|
|
B(Return), //
|
2016-01-08 15:45:59 +00:00
|
|
|
},
|
|
|
|
2,
|
|
|
|
{"eval", "1;"}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(LookupSlot) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
int closure = Register::function_closure().index();
|
|
|
|
int first_context_slot = Context::MIN_CONTEXT_SLOTS;
|
|
|
|
int new_target = Register::new_target().index();
|
|
|
|
|
|
|
|
ExpectedSnippet<const char*> snippets[] = {
|
|
|
|
{"eval('var x = 10;'); return x;",
|
|
|
|
9 * kPointerSize,
|
|
|
|
1,
|
2016-01-12 13:11:27 +00:00
|
|
|
69,
|
2016-01-08 15:45:59 +00:00
|
|
|
{
|
2016-01-18 12:00:04 +00:00
|
|
|
B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
|
|
|
|
U8(1), //
|
|
|
|
B(PushContext), R(0), //
|
|
|
|
B(Ldar), THIS(1), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot), //
|
|
|
|
B(CreateMappedArguments), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot + 1), //
|
|
|
|
B(Ldar), R(new_target), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot + 2), //
|
|
|
|
B(Mov), R(0), R(3), //
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Star), R(4), //
|
|
|
|
B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), //
|
|
|
|
R(3), U8(2), R(1), //
|
|
|
|
B(LdaConstant), U8(1), //
|
|
|
|
B(Star), R(3), //
|
|
|
|
B(Mov), R(1), R(4), //
|
|
|
|
B(Mov), R(3), R(5), //
|
|
|
|
B(Mov), R(closure), R(6), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(7), //
|
|
|
|
B(LdaSmi8), U8(10), //
|
|
|
|
B(Star), R(8), //
|
|
|
|
B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), //
|
|
|
|
U8(5), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Call), R(1), R(2), U8(1), U8(0), //
|
|
|
|
B(LdaLookupSlot), U8(2), //
|
|
|
|
B(Return), //
|
2016-01-08 15:45:59 +00:00
|
|
|
},
|
|
|
|
3,
|
|
|
|
{"eval", "var x = 10;", "x"}},
|
|
|
|
{"eval('var x = 10;'); return typeof x;",
|
2016-01-18 12:00:04 +00:00
|
|
|
9 * kPointerSize,
|
|
|
|
1,
|
|
|
|
70,
|
|
|
|
{
|
|
|
|
B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
|
|
|
|
U8(1), //
|
|
|
|
B(PushContext), R(0), //
|
|
|
|
B(Ldar), THIS(1), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot), //
|
|
|
|
B(CreateMappedArguments), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot + 1), //
|
|
|
|
B(Ldar), R(new_target), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot + 2), //
|
|
|
|
B(Mov), R(0), R(3), //
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(Star), R(4), //
|
|
|
|
B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), //
|
|
|
|
R(3), U8(2), R(1), //
|
|
|
|
B(LdaConstant), U8(1), //
|
|
|
|
B(Star), R(3), //
|
|
|
|
B(Mov), R(1), R(4), //
|
|
|
|
B(Mov), R(3), R(5), //
|
|
|
|
B(Mov), R(closure), R(6), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(7), //
|
|
|
|
B(LdaSmi8), U8(10), //
|
|
|
|
B(Star), R(8), //
|
|
|
|
B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), //
|
|
|
|
U8(5), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Call), R(1), R(2), U8(1), U8(0), //
|
|
|
|
B(LdaLookupSlotInsideTypeof), U8(2), //
|
|
|
|
B(TypeOf), //
|
|
|
|
B(Return), //
|
2016-01-08 15:45:59 +00:00
|
|
|
},
|
|
|
|
3,
|
|
|
|
{"eval", "var x = 10;", "x"}},
|
|
|
|
{"x = 20; return eval('');",
|
|
|
|
9 * kPointerSize,
|
|
|
|
1,
|
2016-01-12 13:11:27 +00:00
|
|
|
71,
|
2016-01-08 15:45:59 +00:00
|
|
|
{
|
2016-01-18 12:00:04 +00:00
|
|
|
B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
|
|
|
|
U8(1), //
|
|
|
|
B(PushContext), R(0), //
|
|
|
|
B(Ldar), THIS(1), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot), //
|
|
|
|
B(CreateMappedArguments), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot + 1), //
|
|
|
|
B(Ldar), R(new_target), //
|
|
|
|
B(StaContextSlot), R(0), U8(first_context_slot + 2), //
|
|
|
|
B(LdaSmi8), U8(20), //
|
|
|
|
B(StaLookupSlotSloppy), U8(0), //
|
|
|
|
B(Mov), R(0), R(3), //
|
|
|
|
B(LdaConstant), U8(1), //
|
|
|
|
B(Star), R(4), //
|
|
|
|
B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), //
|
|
|
|
R(3), U8(2), R(1), //
|
|
|
|
B(LdaConstant), U8(2), //
|
|
|
|
B(Star), R(3), //
|
|
|
|
B(Mov), R(1), R(4), //
|
|
|
|
B(Mov), R(3), R(5), //
|
|
|
|
B(Mov), R(closure), R(6), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(7), //
|
|
|
|
B(LdaSmi8), U8(10), //
|
|
|
|
B(Star), R(8), //
|
|
|
|
B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), //
|
|
|
|
U8(5), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Call), R(1), R(2), U8(1), U8(0), //
|
|
|
|
B(Return), //
|
2016-01-08 15:45:59 +00:00
|
|
|
},
|
|
|
|
3,
|
|
|
|
{"x", "eval", ""}},
|
|
|
|
};
|
|
|
|
|
2016-01-12 13:11:27 +00:00
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(CallLookupSlot) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
Zone zone;
|
|
|
|
|
|
|
|
FeedbackVectorSpec feedback_spec(&zone);
|
|
|
|
FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot();
|
|
|
|
FeedbackVectorSlot slot2 = feedback_spec.AddCallICSlot();
|
|
|
|
USE(slot1);
|
|
|
|
|
|
|
|
Handle<i::TypeFeedbackVector> vector =
|
|
|
|
i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
|
|
|
|
|
|
|
|
int closure = Register::function_closure().index();
|
|
|
|
int new_target = Register::new_target().index();
|
|
|
|
|
|
|
|
ExpectedSnippet<InstanceType> snippets[] = {
|
|
|
|
{"g = function(){}; eval(''); return g();",
|
|
|
|
9 * kPointerSize,
|
|
|
|
1,
|
|
|
|
90,
|
|
|
|
{
|
|
|
|
B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
|
|
|
|
U8(1), //
|
|
|
|
B(PushContext), R(0), //
|
|
|
|
B(Ldar), THIS(1), //
|
|
|
|
B(StaContextSlot), R(0), U8(4), //
|
|
|
|
B(CreateMappedArguments), //
|
|
|
|
B(StaContextSlot), R(0), U8(5), //
|
|
|
|
B(Ldar), R(new_target), //
|
|
|
|
B(StaContextSlot), R(0), U8(6), //
|
|
|
|
B(CreateClosure), U8(0), U8(0), //
|
|
|
|
B(StaLookupSlotSloppy), U8(1), //
|
2016-01-18 12:00:04 +00:00
|
|
|
B(Mov), R(0), R(3), //
|
2016-01-12 13:11:27 +00:00
|
|
|
B(LdaConstant), U8(2), //
|
|
|
|
B(Star), R(4), //
|
|
|
|
B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), //
|
|
|
|
R(3), U8(2), R(1), //
|
|
|
|
B(LdaConstant), U8(3), //
|
|
|
|
B(Star), R(3), //
|
|
|
|
B(Mov), R(1), R(4), //
|
|
|
|
B(Mov), R(3), R(5), //
|
|
|
|
B(Mov), R(closure), R(6), //
|
|
|
|
B(LdaZero), //
|
|
|
|
B(Star), R(7), //
|
|
|
|
B(LdaSmi8), U8(10), //
|
|
|
|
B(Star), R(8), //
|
|
|
|
B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), //
|
|
|
|
U8(5), //
|
|
|
|
B(Star), R(1), //
|
|
|
|
B(Call), R(1), R(2), U8(1), U8(0), //
|
2016-01-18 12:00:04 +00:00
|
|
|
B(Mov), R(0), R(3), //
|
2016-01-12 13:11:27 +00:00
|
|
|
B(LdaConstant), U8(1), //
|
|
|
|
B(Star), R(4), //
|
|
|
|
B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), //
|
|
|
|
R(3), U8(2), R(1), //
|
|
|
|
B(Call), R(1), R(2), U8(0), U8(vector->GetIndex(slot2)), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
4,
|
|
|
|
{InstanceType::SHARED_FUNCTION_INFO_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
};
|
|
|
|
|
2016-01-08 15:45:59 +00:00
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
const char* function_prologue = "var f;"
|
|
|
|
"var x = 1;"
|
|
|
|
"function f1() {"
|
|
|
|
" eval(\"function t() {";
|
|
|
|
const char* function_epilogue = " }; f = t; f();\");"
|
|
|
|
"}"
|
|
|
|
"f1();";
|
|
|
|
|
|
|
|
ExpectedSnippet<const char*> snippets[] = {
|
|
|
|
{"return x;",
|
|
|
|
0 * kPointerSize,
|
|
|
|
1,
|
|
|
|
3,
|
|
|
|
{
|
|
|
|
B(LdaLookupSlot), U8(0), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"x"}},
|
|
|
|
{"x = 10;",
|
|
|
|
0 * kPointerSize,
|
|
|
|
1,
|
|
|
|
6,
|
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(10), //
|
|
|
|
B(StaLookupSlotSloppy), U8(0), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"x"}},
|
|
|
|
{"'use strict'; x = 10;",
|
|
|
|
0 * kPointerSize,
|
|
|
|
1,
|
|
|
|
6,
|
|
|
|
{
|
|
|
|
B(LdaSmi8), U8(10), //
|
|
|
|
B(StaLookupSlotStrict), U8(0), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"x"}},
|
|
|
|
{"return typeof x;",
|
|
|
|
0 * kPointerSize,
|
|
|
|
1,
|
|
|
|
4,
|
|
|
|
{
|
|
|
|
B(LdaLookupSlotInsideTypeof), U8(0), //
|
|
|
|
B(TypeOf), //
|
|
|
|
B(Return), //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"x"}},
|
|
|
|
};
|
|
|
|
|
2016-01-05 11:36:26 +00:00
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
std::string script = std::string(function_prologue) +
|
|
|
|
std::string(snippets[i].code_snippet) +
|
|
|
|
std::string(function_epilogue);
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
2016-01-18 12:00:04 +00:00
|
|
|
helper.MakeBytecode(script.c_str(), "*", "f");
|
2016-01-05 11:36:26 +00:00
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(LookupSlotWideInEval) {
|
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
const char* function_prologue =
|
|
|
|
"var f;"
|
|
|
|
"var x = 1;"
|
|
|
|
"function f1() {"
|
|
|
|
" eval(\"function t() {";
|
|
|
|
const char* function_epilogue =
|
|
|
|
" }; f = t; f();\");"
|
|
|
|
"}"
|
|
|
|
"f1();";
|
|
|
|
|
|
|
|
int const_count[] = {0, 0, 0, 0};
|
|
|
|
ExpectedSnippet<InstanceType, 257> snippets[] = {
|
|
|
|
{REPEAT_256(SPACE, "var y = 2.3;")
|
|
|
|
"return x;",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
1028,
|
|
|
|
{
|
|
|
|
REPEAT_256(SPACE, //
|
|
|
|
B(LdaConstant), U8(const_count[0]++), //
|
|
|
|
B(Star), R(0), ) //
|
|
|
|
B(LdaLookupSlotWide), U16(256), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
257,
|
|
|
|
{REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE),
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
{REPEAT_256(SPACE, "var y = 2.3;")
|
|
|
|
"return typeof x;",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
1029,
|
|
|
|
{
|
|
|
|
REPEAT_256(SPACE, //
|
|
|
|
B(LdaConstant), U8(const_count[1]++), //
|
|
|
|
B(Star), R(0), ) //
|
|
|
|
B(LdaLookupSlotInsideTypeofWide), U16(256), //
|
|
|
|
B(TypeOf), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
257,
|
|
|
|
{REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE),
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
{REPEAT_256(SPACE, "var y = 2.3;")
|
|
|
|
"x = 10;",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
1031,
|
|
|
|
{
|
|
|
|
REPEAT_256(SPACE, //
|
|
|
|
B(LdaConstant), U8(const_count[2]++), //
|
|
|
|
B(Star), R(0), ) //
|
|
|
|
B(LdaSmi8), U8(10), //
|
|
|
|
B(StaLookupSlotSloppyWide), U16(256), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
257,
|
|
|
|
{REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE),
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
{"'use strict';"
|
|
|
|
REPEAT_256(SPACE, "var y = 2.3;")
|
|
|
|
"x = 10;",
|
|
|
|
1 * kPointerSize,
|
|
|
|
1,
|
|
|
|
1031,
|
|
|
|
{
|
|
|
|
REPEAT_256(SPACE,
|
|
|
|
B(LdaConstant), U8(const_count[3]++), //
|
|
|
|
B(Star), R(0), ) //
|
|
|
|
B(LdaSmi8), U8(10), //
|
|
|
|
B(StaLookupSlotStrictWide), U16(256), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
257,
|
|
|
|
{REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE),
|
|
|
|
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
|
|
|
};
|
|
|
|
|
2015-12-16 17:24:20 +00:00
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
std::string script = std::string(function_prologue) +
|
|
|
|
std::string(snippets[i].code_snippet) +
|
|
|
|
std::string(function_epilogue);
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
2016-01-18 12:00:04 +00:00
|
|
|
helper.MakeBytecode(script.c_str(), "*", "f");
|
2015-12-16 17:24:20 +00:00
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-23 09:11:13 +00:00
|
|
|
|
2016-01-08 15:45:59 +00:00
|
|
|
TEST(DeleteLookupSlotInEval) {
|
2015-12-23 09:11:13 +00:00
|
|
|
InitializedHandleScope handle_scope;
|
|
|
|
BytecodeGeneratorHelper helper;
|
|
|
|
|
|
|
|
const char* function_prologue = "var f;"
|
|
|
|
"var x = 1;"
|
|
|
|
"z = 10;"
|
|
|
|
"function f1() {"
|
|
|
|
" var y;"
|
|
|
|
" eval(\"function t() {";
|
|
|
|
const char* function_epilogue = " }; f = t; f();\");"
|
|
|
|
"}"
|
|
|
|
"f1();";
|
|
|
|
|
|
|
|
ExpectedSnippet<const char*> snippets[] = {
|
|
|
|
{"delete x;",
|
|
|
|
0 * kPointerSize,
|
|
|
|
1,
|
|
|
|
5,
|
|
|
|
{
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(DeleteLookupSlot), //
|
|
|
|
B(LdaUndefined), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"x"}},
|
|
|
|
{"return delete y;",
|
|
|
|
0 * kPointerSize,
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
{
|
|
|
|
B(LdaFalse), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
0},
|
|
|
|
{"return delete z;",
|
|
|
|
0 * kPointerSize,
|
|
|
|
1,
|
|
|
|
4,
|
|
|
|
{
|
|
|
|
B(LdaConstant), U8(0), //
|
|
|
|
B(DeleteLookupSlot), //
|
|
|
|
B(Return) //
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
{"z"}},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(snippets); i++) {
|
|
|
|
std::string script = std::string(function_prologue) +
|
|
|
|
std::string(snippets[i].code_snippet) +
|
|
|
|
std::string(function_epilogue);
|
|
|
|
Handle<BytecodeArray> bytecode_array =
|
2016-01-18 12:00:04 +00:00
|
|
|
helper.MakeBytecode(script.c_str(), "*", "f");
|
2015-12-23 09:11:13 +00:00
|
|
|
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-18 13:46:43 +00:00
|
|
|
} // namespace interpreter
|
|
|
|
} // namespace internal
|
2015-09-30 13:46:56 +00:00
|
|
|
} // namespace v8
|