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

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: Created 5 years, 3 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 a64f37fc5e9435695849438960bef19e813bb204..2a82ff8a2a787ab842c27e263bbd42677ae2ab04 100644
--- a/test/cctest/interpreter/test-interpreter.cc
+++ b/test/cctest/interpreter/test-interpreter.cc
@@ -513,6 +513,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;
@@ -530,6 +551,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;
@@ -547,6 +590,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();

Powered by Google App Engine
This is Rietveld 408576698