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

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: 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 1587 matching lines...) Expand 10 before | Expand all | Expand 10 after
1598 1598
1599 for (size_t i = 0; i < arraysize(literals); i++) { 1599 for (size_t i = 0; i < arraysize(literals); i++) {
1600 std::string source(InterpreterTester::SourceForBody(literals[i].first)); 1600 std::string source(InterpreterTester::SourceForBody(literals[i].first));
1601 InterpreterTester tester(handles.main_isolate(), source.c_str()); 1601 InterpreterTester tester(handles.main_isolate(), source.c_str());
1602 auto callable = tester.GetCallable<>(); 1602 auto callable = tester.GetCallable<>();
1603 1603
1604 Handle<i::Object> return_value = callable().ToHandleChecked(); 1604 Handle<i::Object> return_value = callable().ToHandleChecked();
1605 CHECK(return_value->SameValue(*literals[i].second)); 1605 CHECK(return_value->SameValue(*literals[i].second));
1606 } 1606 }
1607 } 1607 }
1608
1609
1610 TEST(InterpreterObjectLiterals) {
1611 HandleAndZoneScope handles;
1612 i::Isolate* isolate = handles.main_isolate();
1613 i::Factory* factory = isolate->factory();
1614
1615 std::pair<const char*, Handle<Object>> literals[14] = {
1616 std::make_pair("return { }.name;",
1617 factory->undefined_value()),
1618 std::make_pair("return { name: 'string', val: 9.2 }.name;",
1619 factory->NewStringFromStaticChars("string")),
1620 std::make_pair("var a = 15; return { name: 'string', val: a }.val;",
1621 Handle<Object>(Smi::FromInt(15), isolate)),
1622 std::make_pair("var a = 5; return { val: a, val: a + 1 }.val;",
1623 Handle<Object>(Smi::FromInt(6), isolate)),
1624 std::make_pair("return { func: function() { return 'test' } }.func();",
1625 factory->NewStringFromStaticChars("test")),
1626 std::make_pair("return { func(a) { return a + 'st'; } }.func('te');",
1627 factory->NewStringFromStaticChars("test")),
1628 std::make_pair("return { get a() { return 22; } }.a;",
1629 Handle<Object>(Smi::FromInt(22), isolate)),
1630 std::make_pair("var a = { get b() { return this.x + 't'; },\n"
1631 " set b(val) { this.x = val + 's' } };\n"
1632 "a.b = 'te';\n"
1633 "return a.b;",
1634 factory->NewStringFromStaticChars("test")),
1635 std::make_pair("var a = 123; return { 1: a }[1];",
1636 Handle<Object>(Smi::FromInt(123), isolate)),
1637 std::make_pair("return Object.getPrototypeOf({ __proto__: null });",
1638 factory->null_value()),
1639 std::make_pair("var a = 'test'; return { [a]: 1 }.test;",
1640 Handle<Object>(Smi::FromInt(1), isolate)),
1641 std::make_pair("var a = 'test'; return { b: a, [a]: a + 'ing' }['test']",
1642 factory->NewStringFromStaticChars("testing")),
1643 std::make_pair("var a = 'proto_str';\n"
1644 "var b = { [a]: 1, __proto__: { var : a } };\n"
1645 "return Object.getPrototypeOf(b).var",
1646 factory->NewStringFromStaticChars("proto_str")),
1647 std::make_pair("var n = 'name';\n"
1648 "return { [n]: 'val', get a() { return 987 } }['a'];",
1649 Handle<Object>(Smi::FromInt(987), isolate)),
1650 };
1651
1652 for (size_t i = 0; i < arraysize(literals); i++) {
1653 std::string source(InterpreterTester::SourceForBody(literals[i].first));
1654 InterpreterTester tester(handles.main_isolate(), source.c_str());
1655 auto callable = tester.GetCallable<>();
1656
1657 Handle<i::Object> return_value = callable().ToHandleChecked();
1658 CHECK(return_value->SameValue(*literals[i].second));
1659 }
1660 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698