Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1251)

Unified Diff: test/cctest/interpreter/test-interpreter.cc

Issue 1378523005: [Interpreter] Add support for global declarations and load/store of global variables (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@int_toplevel
Patch Set: Fix test Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/cctest/interpreter/test-interpreter.cc
diff --git a/test/cctest/interpreter/test-interpreter.cc b/test/cctest/interpreter/test-interpreter.cc
index 9e087e7bf970cbe88fb4f24a462d08cafe950082..7343d0818269cf8865a0cb32fcc52094e06b861b 100644
--- a/test/cctest/interpreter/test-interpreter.cc
+++ b/test/cctest/interpreter/test-interpreter.cc
@@ -555,6 +555,27 @@ TEST(InterpreterParameter8) {
}
+TEST(InterpreterParameter1Assign) {
+ HandleAndZoneScope handles;
+ BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
+ builder.set_locals_count(0);
+ builder.set_parameter_count(1);
+ builder.LoadLiteral(Smi::FromInt(5))
+ .StoreAccumulatorInRegister(builder.Parameter(0))
+ .LoadAccumulatorWithRegister(builder.Parameter(0))
+ .Return();
+ Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
+
+ InterpreterTester tester(handles.main_isolate(), bytecode_array);
+ auto callable = tester.GetCallable<Handle<Object>>();
+
+ Handle<Object> return_val =
+ callable(Handle<Smi>(Smi::FromInt(3), handles.main_isolate()))
+ .ToHandleChecked();
+ CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5));
+}
+
+
TEST(InterpreterLoadGlobal) {
HandleAndZoneScope handles;
@@ -572,6 +593,28 @@ TEST(InterpreterLoadGlobal) {
}
+TEST(InterpreterStoreGlobal) {
+ HandleAndZoneScope handles;
+ i::Isolate* isolate = handles.main_isolate();
+ i::Factory* factory = isolate->factory();
+
+ // Test storing to a global.
+ std::string source(
+ "var global = 321;\n"
+ "function " + InterpreterTester::function_name() + "() {\n"
+ " global = 999;\n"
+ "}");
+ InterpreterTester tester(handles.main_isolate(), source.c_str());
+ auto callable = tester.GetCallable<>();
+
+ callable().ToHandleChecked();
+ Handle<i::String> name = factory->InternalizeUtf8String("global");
+ Handle<i::Object> global_obj =
+ Object::GetProperty(isolate->global_object(), name).ToHandleChecked();
+ CHECK_EQ(Smi::cast(*global_obj), Smi::FromInt(999));
+}
+
+
TEST(InterpreterCallGlobal) {
HandleAndZoneScope handles;
@@ -589,6 +632,45 @@ TEST(InterpreterCallGlobal) {
}
+TEST(InterpreterLoadUnallocated) {
+ HandleAndZoneScope handles;
+
+ // Test loading an unallocated global.
+ std::string source(
+ "unallocated = 123;\n"
+ "function " + InterpreterTester::function_name() + "() {\n"
+ " return unallocated;\n"
+ "}");
+ InterpreterTester tester(handles.main_isolate(), source.c_str());
+ auto callable = tester.GetCallable<>();
+
+ Handle<Object> return_val = callable().ToHandleChecked();
+ CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123));
+}
+
+
+TEST(InterpreterStoreUnallocated) {
+ HandleAndZoneScope handles;
+ i::Isolate* isolate = handles.main_isolate();
+ i::Factory* factory = isolate->factory();
+
+ // Test storing to an unallocated global.
+ std::string source(
+ "unallocated = 321;\n"
+ "function " + InterpreterTester::function_name() + "() {\n"
+ " unallocated = 999;\n"
+ "}");
+ InterpreterTester tester(handles.main_isolate(), source.c_str());
+ auto callable = tester.GetCallable<>();
+
+ callable().ToHandleChecked();
+ Handle<i::String> name = factory->InternalizeUtf8String("unallocated");
+ Handle<i::Object> global_obj =
+ Object::GetProperty(isolate->global_object(), name).ToHandleChecked();
+ CHECK_EQ(Smi::cast(*global_obj), Smi::FromInt(999));
+}
+
+
TEST(InterpreterLoadNamedProperty) {
HandleAndZoneScope handles;
i::Isolate* isolate = handles.main_isolate();
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | test/unittests/compiler/interpreter-assembler-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698