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

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

Issue 1386313005: [Interpreter] Adds Object literal support. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@int_literal_2
Patch Set: Rebase and review comments 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 7d2f527fe29757612e7d0e406cf984d0d110f86c..5fad731b4183e700c3ad92b76b4a8f4878712bc9 100644
--- a/test/cctest/interpreter/test-interpreter.cc
+++ b/test/cctest/interpreter/test-interpreter.cc
@@ -1672,3 +1672,56 @@ TEST(InterpreterArrayLiterals) {
CHECK(return_value->SameValue(*literals[i].second));
}
}
+
+
+TEST(InterpreterObjectLiterals) {
+ HandleAndZoneScope handles;
+ i::Isolate* isolate = handles.main_isolate();
+ i::Factory* factory = isolate->factory();
+
+ std::pair<const char*, Handle<Object>> literals[14] = {
+ std::make_pair("return { }.name;",
+ factory->undefined_value()),
+ std::make_pair("return { name: 'string', val: 9.2 }.name;",
+ factory->NewStringFromStaticChars("string")),
+ std::make_pair("var a = 15; return { name: 'string', val: a }.val;",
+ Handle<Object>(Smi::FromInt(15), isolate)),
+ std::make_pair("var a = 5; return { val: a, val: a + 1 }.val;",
+ Handle<Object>(Smi::FromInt(6), isolate)),
+ std::make_pair("return { func: function() { return 'test' } }.func();",
+ factory->NewStringFromStaticChars("test")),
+ std::make_pair("return { func(a) { return a + 'st'; } }.func('te');",
+ factory->NewStringFromStaticChars("test")),
+ std::make_pair("return { get a() { return 22; } }.a;",
+ Handle<Object>(Smi::FromInt(22), isolate)),
+ std::make_pair("var a = { get b() { return this.x + 't'; },\n"
+ " set b(val) { this.x = val + 's' } };\n"
+ "a.b = 'te';\n"
+ "return a.b;",
+ factory->NewStringFromStaticChars("test")),
+ std::make_pair("var a = 123; return { 1: a }[1];",
+ Handle<Object>(Smi::FromInt(123), isolate)),
+ std::make_pair("return Object.getPrototypeOf({ __proto__: null });",
+ factory->null_value()),
+ std::make_pair("var a = 'test'; return { [a]: 1 }.test;",
+ Handle<Object>(Smi::FromInt(1), isolate)),
+ std::make_pair("var a = 'test'; return { b: a, [a]: a + 'ing' }['test']",
+ factory->NewStringFromStaticChars("testing")),
+ std::make_pair("var a = 'proto_str';\n"
+ "var b = { [a]: 1, __proto__: { var : a } };\n"
+ "return Object.getPrototypeOf(b).var",
+ factory->NewStringFromStaticChars("proto_str")),
+ std::make_pair("var n = 'name';\n"
+ "return { [n]: 'val', get a() { return 987 } }['a'];",
+ Handle<Object>(Smi::FromInt(987), isolate)),
+ };
+
+ for (size_t i = 0; i < arraysize(literals); i++) {
+ std::string source(InterpreterTester::SourceForBody(literals[i].first));
+ InterpreterTester tester(handles.main_isolate(), source.c_str());
+ auto callable = tester.GetCallable<>();
+
+ Handle<i::Object> return_value = callable().ToHandleChecked();
+ CHECK(return_value->SameValue(*literals[i].second));
+ }
+}
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | test/unittests/interpreter/bytecode-array-builder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698