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/bytecode-array-iterator.h" | 10 #include "src/interpreter/bytecode-array-iterator.h" |
(...skipping 4165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4176 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 4176 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
4177 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); | 4177 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); |
4178 v8::Local<v8::String> expected_string = v8_str(const_decl[i].second); | 4178 v8::Local<v8::String> expected_string = v8_str(const_decl[i].second); |
4179 CHECK( | 4179 CHECK( |
4180 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) | 4180 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) |
4181 .FromJust()); | 4181 .FromJust()); |
4182 } | 4182 } |
4183 } | 4183 } |
4184 | 4184 |
4185 TEST(InterpreterGenerators) { | 4185 TEST(InterpreterGenerators) { |
4186 bool old_flag = FLAG_ignition_generators; | |
4187 FLAG_ignition_generators = true; | |
4188 | |
4189 HandleAndZoneScope handles; | 4186 HandleAndZoneScope handles; |
4190 i::Isolate* isolate = handles.main_isolate(); | 4187 i::Isolate* isolate = handles.main_isolate(); |
4191 i::Factory* factory = isolate->factory(); | 4188 i::Factory* factory = isolate->factory(); |
4192 | 4189 |
4193 std::pair<const char*, Handle<Object>> tests[] = { | 4190 std::pair<const char*, Handle<Object>> tests[] = { |
4194 {"function* f() { }; return f().next().value", | 4191 {"function* f() { }; return f().next().value", |
4195 factory->undefined_value()}, | 4192 factory->undefined_value()}, |
4196 {"function* f() { yield 42 }; return f().next().value", | 4193 {"function* f() { yield 42 }; return f().next().value", |
4197 factory->NewNumberFromInt(42)}, | 4194 factory->NewNumberFromInt(42)}, |
4198 {"function* f() { for (let x of [42]) yield x}; return f().next().value", | 4195 {"function* f() { for (let x of [42]) yield x}; return f().next().value", |
4199 factory->NewNumberFromInt(42)}, | 4196 factory->NewNumberFromInt(42)}, |
4200 }; | 4197 }; |
4201 | 4198 |
4202 for (size_t i = 0; i < arraysize(tests); i++) { | 4199 for (size_t i = 0; i < arraysize(tests); i++) { |
4203 std::string source(InterpreterTester::SourceForBody(tests[i].first)); | 4200 std::string source(InterpreterTester::SourceForBody(tests[i].first)); |
4204 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 4201 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
4205 auto callable = tester.GetCallable<>(); | 4202 auto callable = tester.GetCallable<>(); |
4206 | 4203 |
4207 Handle<i::Object> return_value = callable().ToHandleChecked(); | 4204 Handle<i::Object> return_value = callable().ToHandleChecked(); |
4208 CHECK(return_value->SameValue(*tests[i].second)); | 4205 CHECK(return_value->SameValue(*tests[i].second)); |
4209 } | 4206 } |
4210 | |
4211 FLAG_ignition_generators = old_flag; | |
4212 } | 4207 } |
4213 | 4208 |
4214 } // namespace interpreter | 4209 } // namespace interpreter |
4215 } // namespace internal | 4210 } // namespace internal |
4216 } // namespace v8 | 4211 } // namespace v8 |
OLD | NEW |