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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/execution.h" 7 #include "src/execution.h"
8 #include "src/handles.h" 8 #include "src/handles.h"
9 #include "src/interpreter/bytecode-array-builder.h" 9 #include "src/interpreter/bytecode-array-builder.h"
10 #include "src/interpreter/interpreter.h" 10 #include "src/interpreter/interpreter.h"
(...skipping 1654 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 1665
1666 for (size_t i = 0; i < arraysize(literals); i++) { 1666 for (size_t i = 0; i < arraysize(literals); i++) {
1667 std::string source(InterpreterTester::SourceForBody(literals[i].first)); 1667 std::string source(InterpreterTester::SourceForBody(literals[i].first));
1668 InterpreterTester tester(handles.main_isolate(), source.c_str()); 1668 InterpreterTester tester(handles.main_isolate(), source.c_str());
1669 auto callable = tester.GetCallable<>(); 1669 auto callable = tester.GetCallable<>();
1670 1670
1671 Handle<i::Object> return_value = callable().ToHandleChecked(); 1671 Handle<i::Object> return_value = callable().ToHandleChecked();
1672 CHECK(return_value->SameValue(*literals[i].second)); 1672 CHECK(return_value->SameValue(*literals[i].second));
1673 } 1673 }
1674 } 1674 }
1675
1676
1677 TEST(InterpreterObjectLiterals) {
1678 HandleAndZoneScope handles;
1679 i::Isolate* isolate = handles.main_isolate();
1680 i::Factory* factory = isolate->factory();
1681
1682 std::pair<const char*, Handle<Object>> literals[14] = {
1683 std::make_pair("return { }.name;",
1684 factory->undefined_value()),
1685 std::make_pair("return { name: 'string', val: 9.2 }.name;",
1686 factory->NewStringFromStaticChars("string")),
1687 std::make_pair("var a = 15; return { name: 'string', val: a }.val;",
1688 Handle<Object>(Smi::FromInt(15), isolate)),
1689 std::make_pair("var a = 5; return { val: a, val: a + 1 }.val;",
1690 Handle<Object>(Smi::FromInt(6), isolate)),
1691 std::make_pair("return { func: function() { return 'test' } }.func();",
1692 factory->NewStringFromStaticChars("test")),
1693 std::make_pair("return { func(a) { return a + 'st'; } }.func('te');",
1694 factory->NewStringFromStaticChars("test")),
1695 std::make_pair("return { get a() { return 22; } }.a;",
1696 Handle<Object>(Smi::FromInt(22), isolate)),
1697 std::make_pair("var a = { get b() { return this.x + 't'; },\n"
1698 " set b(val) { this.x = val + 's' } };\n"
1699 "a.b = 'te';\n"
1700 "return a.b;",
1701 factory->NewStringFromStaticChars("test")),
1702 std::make_pair("var a = 123; return { 1: a }[1];",
1703 Handle<Object>(Smi::FromInt(123), isolate)),
1704 std::make_pair("return Object.getPrototypeOf({ __proto__: null });",
1705 factory->null_value()),
1706 std::make_pair("var a = 'test'; return { [a]: 1 }.test;",
1707 Handle<Object>(Smi::FromInt(1), isolate)),
1708 std::make_pair("var a = 'test'; return { b: a, [a]: a + 'ing' }['test']",
1709 factory->NewStringFromStaticChars("testing")),
1710 std::make_pair("var a = 'proto_str';\n"
1711 "var b = { [a]: 1, __proto__: { var : a } };\n"
1712 "return Object.getPrototypeOf(b).var",
1713 factory->NewStringFromStaticChars("proto_str")),
1714 std::make_pair("var n = 'name';\n"
1715 "return { [n]: 'val', get a() { return 987 } }['a'];",
1716 Handle<Object>(Smi::FromInt(987), isolate)),
1717 };
1718
1719 for (size_t i = 0; i < arraysize(literals); i++) {
1720 std::string source(InterpreterTester::SourceForBody(literals[i].first));
1721 InterpreterTester tester(handles.main_isolate(), source.c_str());
1722 auto callable = tester.GetCallable<>();
1723
1724 Handle<i::Object> return_value = callable().ToHandleChecked();
1725 CHECK(return_value->SameValue(*literals[i].second));
1726 }
1727 }
OLDNEW
« 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