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

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

Issue 1689573004: [interpreter] Support for ES6 super keyword. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 10 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 3847 matching lines...) Expand 10 before | Expand all | Expand 10 after
3858 for (size_t i = 0; i < arraysize(examples); ++i) { 3858 for (size_t i = 0; i < arraysize(examples); ++i) {
3859 std::string source(InterpreterTester::SourceForBody(examples[i].first)); 3859 std::string source(InterpreterTester::SourceForBody(examples[i].first));
3860 InterpreterTester tester(handles.main_isolate(), source.c_str()); 3860 InterpreterTester tester(handles.main_isolate(), source.c_str());
3861 auto callable = tester.GetCallable<>(); 3861 auto callable = tester.GetCallable<>();
3862 3862
3863 Handle<i::Object> return_value = callable().ToHandleChecked(); 3863 Handle<i::Object> return_value = callable().ToHandleChecked();
3864 CHECK(return_value->SameValue(*examples[i].second)); 3864 CHECK(return_value->SameValue(*examples[i].second));
3865 } 3865 }
3866 } 3866 }
3867 3867
3868 TEST(InterpreterClassAndSuperClass) {
3869 HandleAndZoneScope handles;
3870 i::Isolate* isolate = handles.main_isolate();
3871 std::pair<const char*, Handle<Object>> examples[] = {
3872 {"class A {\n"
3873 " constructor(x) { this.x_ = x; }\n"
3874 " method() { return this.x_; }\n"
3875 "}\n"
3876 "class B extends A {\n"
3877 " constructor(x, y) { super(x); this.y_ = y; }\n"
3878 " method() { return super.method() + 1; }\n"
3879 "}\n"
3880 "return new B(998, 0).method();\n",
3881 handle(Smi::FromInt(999), isolate)},
3882 {"class A {\n"
3883 " constructor() { this.x_ = 2; this.y_ = 3; }\n"
3884 "}\n"
3885 "class B extends A {\n"
3886 " constructor() { super(); }"
3887 " method() { this.x_++; this.y_++; return this.x_ + this.y_; }\n"
3888 "}\n"
3889 "return new B().method();\n",
3890 handle(Smi::FromInt(7), isolate)},
3891 {"var calls = 0;\n"
3892 "class B {}\n"
3893 "B.prototype.x = 42;\n"
3894 "class C extends B {\n"
3895 " constructor() {\n"
3896 " super();\n"
3897 " calls++;\n"
3898 " }\n"
3899 "}\n"
3900 "new C;\n"
3901 "return calls;\n",
3902 handle(Smi::FromInt(1), isolate)},
3903 {"class A {\n"
3904 " method() { return 1; }\n"
3905 " get x() { return 2; }\n"
3906 "}\n"
3907 "class B extends A {\n"
3908 " method() { return super.x === 2 ? super.method() : -1; }\n"
3909 "}\n"
3910 "return new B().method();\n",
3911 handle(Smi::FromInt(1), isolate)},
3912 {"var object = { setY(v) { super.y = v; }};\n"
3913 "object.setY(10);\n"
3914 "return object.y;\n",
3915 handle(Smi::FromInt(10), isolate)},
3916 };
3917
3918 for (size_t i = 0; i < arraysize(examples); ++i) {
3919 std::string source(InterpreterTester::SourceForBody(examples[i].first));
3920 InterpreterTester tester(handles.main_isolate(), source.c_str());
3921 auto callable = tester.GetCallable<>();
3922 Handle<i::Object> return_value = callable().ToHandleChecked();
3923 CHECK(return_value->SameValue(*examples[i].second));
3924 }
3925 }
3926
3868 TEST(InterpreterConstDeclaration) { 3927 TEST(InterpreterConstDeclaration) {
3869 HandleAndZoneScope handles; 3928 HandleAndZoneScope handles;
3870 i::Isolate* isolate = handles.main_isolate(); 3929 i::Isolate* isolate = handles.main_isolate();
3871 i::Factory* factory = isolate->factory(); 3930 i::Factory* factory = isolate->factory();
3872 3931
3873 std::pair<const char*, Handle<Object>> const_decl[] = { 3932 std::pair<const char*, Handle<Object>> const_decl[] = {
3874 {"const x = 3; return x;", handle(Smi::FromInt(3), isolate)}, 3933 {"const x = 3; return x;", handle(Smi::FromInt(3), isolate)},
3875 {"let x = 10; x = x + 20; return x;", handle(Smi::FromInt(30), isolate)}, 3934 {"let x = 10; x = x + 20; return x;", handle(Smi::FromInt(30), isolate)},
3876 {"let x = 10; x = 20; return x;", handle(Smi::FromInt(20), isolate)}, 3935 {"let x = 10; x = 20; return x;", handle(Smi::FromInt(20), isolate)},
3877 {"let x; x = 20; return x;", handle(Smi::FromInt(20), isolate)}, 3936 {"let x; x = 20; return x;", handle(Smi::FromInt(20), isolate)},
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
4099 Handle<i::Object> return_value = callable().ToHandleChecked(); 4158 Handle<i::Object> return_value = callable().ToHandleChecked();
4100 CHECK(return_value->SameValue(*const_decl[i].second)); 4159 CHECK(return_value->SameValue(*const_decl[i].second));
4101 } 4160 }
4102 4161
4103 FLAG_legacy_const = old_flag_legacy_const; 4162 FLAG_legacy_const = old_flag_legacy_const;
4104 } 4163 }
4105 4164
4106 } // namespace interpreter 4165 } // namespace interpreter
4107 } // namespace internal 4166 } // namespace internal
4108 } // namespace v8 4167 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698