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

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

Issue 1618693005: [Interpreter] Add ForOf support. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2786 matching lines...) Expand 10 before | Expand all | Expand 10 after
2797 2797
2798 for (size_t i = 0; i < arraysize(for_in_samples); i++) { 2798 for (size_t i = 0; i < arraysize(for_in_samples); i++) {
2799 InterpreterTester tester(handles.main_isolate(), for_in_samples[i].first); 2799 InterpreterTester tester(handles.main_isolate(), for_in_samples[i].first);
2800 auto callable = tester.GetCallable<>(); 2800 auto callable = tester.GetCallable<>();
2801 Handle<Object> return_val = callable().ToHandleChecked(); 2801 Handle<Object> return_val = callable().ToHandleChecked();
2802 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), for_in_samples[i].second); 2802 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), for_in_samples[i].second);
2803 } 2803 }
2804 } 2804 }
2805 2805
2806 2806
2807 TEST(InterpreterForOf) {
2808 HandleAndZoneScope handles;
2809 i::Isolate* isolate = handles.main_isolate();
2810 i::Factory* factory = isolate->factory();
2811
2812 std::pair<const char*, Handle<Object>> for_of[] = {
2813 {"function f() {\n"
2814 " var r = 0;\n"
2815 " for (var a of [0,6,7,9]) { r += a; }\n"
2816 " return r;\n"
2817 "}",
2818 handle(Smi::FromInt(22), isolate)},
2819 {"function f() {\n"
2820 " var r = '';\n"
2821 " for (var a of 'foobar') { r = a + r; }\n"
2822 " return r;\n"
2823 "}",
2824 factory->NewStringFromStaticChars("raboof")},
2825 {"function f() {\n"
2826 " var a = [1, 2, 3];\n"
2827 " a.name = 4;\n"
2828 " var r = 0;\n"
2829 " for (var x of a) { r += x; }\n"
2830 " return r;\n"
2831 "}",
2832 handle(Smi::FromInt(6), isolate)},
2833 {"function f() {\n"
2834 " var r = '';\n"
2835 " var data = [1, 2, 3]; \n"
2836 " for (a of data) { delete data[0]; r += a; } return r; }",
2837 factory->NewStringFromStaticChars("123")},
2838 {"function f() {\n"
2839 " var r = '';\n"
2840 " var data = [1, 2, 3]; \n"
2841 " for (a of data) { delete data[2]; r += a; } return r; }",
2842 factory->NewStringFromStaticChars("12undefined")},
2843 {"function f() {\n"
2844 " var r = '';\n"
2845 " var data = [1, 2, 3]; \n"
2846 " for (a of data) { delete data; r += a; } return r; }",
2847 factory->NewStringFromStaticChars("123")},
2848 {"function f() {\n"
2849 " var r = '';\n"
2850 " var input = 'foobar';\n"
2851 " for (var a of input) {\n"
2852 " if (a == 'b') break;\n"
2853 " r += a;\n"
2854 " }\n"
2855 " return r;\n"
2856 "}",
2857 factory->NewStringFromStaticChars("foo")},
2858 {"function f() {\n"
2859 " var r = '';\n"
2860 " var input = 'foobar';\n"
2861 " for (var a of input) {\n"
2862 " if (a == 'b') continue;\n"
2863 " r += a;\n"
2864 " }\n"
2865 " return r;\n"
2866 "}",
2867 factory->NewStringFromStaticChars("fooar")},
2868 {"function f() {\n"
2869 " var r = '';\n"
2870 " var data = [1, 2, 3, 4]; \n"
2871 " for (a of data) { data[2] = 567; r += a; }\n"
2872 " return r;\n"
2873 "}",
2874 factory->NewStringFromStaticChars("125674")},
2875 {"function f() {\n"
2876 " var r = '';\n"
2877 " var data = [1, 2, 3, 4]; \n"
2878 " for (a of data) { data[4] = 567; r += a; }\n"
2879 " return r;\n"
2880 "}",
2881 factory->NewStringFromStaticChars("1234567")},
2882 {"function f() {\n"
2883 " var r = '';\n"
2884 " var data = [1, 2, 3, 4]; \n"
2885 " for (a of data) { data[5] = 567; r += a; }\n"
2886 " return r;\n"
2887 "}",
2888 factory->NewStringFromStaticChars("1234undefined567")},
2889 {"function f() {\n"
2890 " var r = '';\n"
2891 " var obj = new Object();\n"
2892 " obj[Symbol.iterator] = function() { return {\n"
2893 " index: 3,\n"
2894 " data: ['a', 'b', 'c', 'd'],"
2895 " next: function() {"
2896 " return {"
2897 " done: this.index == -1,\n"
2898 " value: this.index < 0 ? undefined : this.data[this.index--]\n"
2899 " }\n"
2900 " }\n"
2901 " }}\n"
2902 " for (a of obj) { r += a }\n"
2903 " return r;\n"
2904 "}",
2905 factory->NewStringFromStaticChars("dcba")},
2906 };
2907
2908 for (size_t i = 0; i < arraysize(for_of); i++) {
2909 InterpreterTester tester(handles.main_isolate(), for_of[i].first);
2910 auto callable = tester.GetCallable<>();
2911 Handle<Object> return_val = callable().ToHandleChecked();
2912 CHECK(return_val->SameValue(*for_of[i].second));
2913 }
2914 }
2915
2916
2807 TEST(InterpreterSwitch) { 2917 TEST(InterpreterSwitch) {
2808 HandleAndZoneScope handles; 2918 HandleAndZoneScope handles;
2809 i::Isolate* isolate = handles.main_isolate(); 2919 i::Isolate* isolate = handles.main_isolate();
2810 i::Factory* factory = isolate->factory(); 2920 i::Factory* factory = isolate->factory();
2811 2921
2812 std::pair<const char*, Handle<Object>> switch_ops[] = { 2922 std::pair<const char*, Handle<Object>> switch_ops[] = {
2813 std::make_pair("var a = 1;\n" 2923 std::make_pair("var a = 1;\n"
2814 "switch(a) {\n" 2924 "switch(a) {\n"
2815 " case 1: return 2;\n" 2925 " case 1: return 2;\n"
2816 " case 2: return 3;\n" 2926 " case 2: return 3;\n"
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
3530 auto callable = tester.GetCallable<>(); 3640 auto callable = tester.GetCallable<>();
3531 3641
3532 Handle<i::Object> return_value = callable().ToHandleChecked(); 3642 Handle<i::Object> return_value = callable().ToHandleChecked();
3533 CHECK(return_value->SameValue(*eval_func_decl[i].second)); 3643 CHECK(return_value->SameValue(*eval_func_decl[i].second));
3534 } 3644 }
3535 } 3645 }
3536 3646
3537 } // namespace interpreter 3647 } // namespace interpreter
3538 } // namespace internal 3648 } // namespace internal
3539 } // namespace v8 3649 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698