OLD | NEW |
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 Loading... |
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 } |
OLD | NEW |