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

Side by Side Diff: test/cctest/interpreter/test-interpreter.cc

Issue 1422443006: [Intepreter] Don't throw reference errors for globals in typeof. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased Created 5 years, 1 month 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 // TODO(rmcilroy): Remove this define after this flag is turned on globally 5 // TODO(rmcilroy): Remove this define after this flag is turned on globally
6 #define V8_IMMINENT_DEPRECATION_WARNINGS 6 #define V8_IMMINENT_DEPRECATION_WARNINGS
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/execution.h" 10 #include "src/execution.h"
(...skipping 1622 matching lines...) Expand 10 before | Expand all | Expand 10 after
1633 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 1633 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
1634 InterpreterTester tester(handles.main_isolate(), bytecode_array); 1634 InterpreterTester tester(handles.main_isolate(), bytecode_array);
1635 auto callable = tester.GetCallable<>(); 1635 auto callable = tester.GetCallable<>();
1636 Handle<Object> return_value = callable().ToHandleChecked(); 1636 Handle<Object> return_value = callable().ToHandleChecked();
1637 CHECK(return_value->IsBoolean()); 1637 CHECK(return_value->IsBoolean());
1638 CHECK_EQ(return_value->BooleanValue(), object_type_tuples[i].second); 1638 CHECK_EQ(return_value->BooleanValue(), object_type_tuples[i].second);
1639 } 1639 }
1640 } 1640 }
1641 1641
1642 1642
1643 TEST(InterpreterTypeOf) { 1643 TEST(InterpreterTypeof) {
1644 HandleAndZoneScope handles; 1644 HandleAndZoneScope handles;
1645 i::Factory* factory = handles.main_isolate()->factory();
1646 1645
1647 std::pair<Handle<Object>, const char*> object_type_tuples[] = { 1646 std::pair<const char*, const char*> typeof_vals[] = {
1648 std::make_pair(factory->undefined_value(), "undefined"), 1647 std::make_pair("return typeof undefined;", "undefined"),
1649 std::make_pair(factory->null_value(), "object"), 1648 std::make_pair("return typeof null;", "object"),
1650 std::make_pair(factory->true_value(), "boolean"), 1649 std::make_pair("return typeof true;", "boolean"),
1651 std::make_pair(factory->false_value(), "boolean"), 1650 std::make_pair("return typeof false;", "boolean"),
1652 std::make_pair(factory->NewNumber(9.1), "number"), 1651 std::make_pair("return typeof 9.1;", "number"),
1653 std::make_pair(factory->NewNumberFromInt(7771), "number"), 1652 std::make_pair("return typeof 7771;", "number"),
1654 std::make_pair( 1653 std::make_pair("return typeof 'hello';", "string"),
1655 Handle<Object>::cast(factory->NewStringFromStaticChars("hello")), 1654 std::make_pair("return typeof global_unallocated;", "undefined"),
1656 "string"),
1657 }; 1655 };
1658 1656
1659 for (size_t i = 0; i < arraysize(object_type_tuples); i++) { 1657 for (size_t i = 0; i < arraysize(typeof_vals); i++) {
1660 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); 1658 std::string source(InterpreterTester::SourceForBody(typeof_vals[i].first));
1661 Register r0(0); 1659 InterpreterTester tester(handles.main_isolate(), source.c_str());
1662 builder.set_locals_count(0); 1660
1663 builder.set_context_count(0);
1664 builder.set_parameter_count(0);
1665 LoadAny(&builder, factory, object_type_tuples[i].first);
1666 builder.TypeOf();
1667 builder.Return();
1668 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
1669 InterpreterTester tester(handles.main_isolate(), bytecode_array);
1670 auto callable = tester.GetCallable<>(); 1661 auto callable = tester.GetCallable<>();
1671 Handle<v8::internal::String> return_value = 1662 Handle<v8::internal::String> return_value =
1672 Handle<v8::internal::String>::cast(callable().ToHandleChecked()); 1663 Handle<v8::internal::String>::cast(callable().ToHandleChecked());
1673 auto actual = return_value->ToCString(); 1664 auto actual = return_value->ToCString();
1674 CHECK_EQ(strcmp(&actual[0], object_type_tuples[i].second), 0); 1665 CHECK_EQ(strcmp(&actual[0], typeof_vals[i].second), 0);
1675 } 1666 }
1676 } 1667 }
1677 1668
1678 1669
1679 TEST(InterpreterCallRuntime) { 1670 TEST(InterpreterCallRuntime) {
1680 HandleAndZoneScope handles; 1671 HandleAndZoneScope handles;
1681 1672
1682 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); 1673 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
1683 builder.set_locals_count(2); 1674 builder.set_locals_count(2);
1684 builder.set_context_count(0); 1675 builder.set_context_count(0);
(...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after
2890 auto callable = tester.GetCallable<>(); 2881 auto callable = tester.GetCallable<>();
2891 2882
2892 Handle<i::Object> return_value = callable().ToHandleChecked(); 2883 Handle<i::Object> return_value = callable().ToHandleChecked();
2893 CHECK(return_value->SameValue(*switch_ops[i].second)); 2884 CHECK(return_value->SameValue(*switch_ops[i].second));
2894 } 2885 }
2895 } 2886 }
2896 2887
2897 } // namespace interpreter 2888 } // namespace interpreter
2898 } // namespace internal 2889 } // namespace internal
2899 } // namespace v8 2890 } // namespace v8
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