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

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

Issue 1583783003: [Interpreter] Adds support for variable/function declarations in lookup slots. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fixes comments 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 3544 matching lines...) Expand 10 before | Expand all | Expand 10 after
3555 for (size_t i = 0; i < arraysize(eval_global); i++) { 3555 for (size_t i = 0; i < arraysize(eval_global); i++) {
3556 InterpreterTester tester(handles.main_isolate(), eval_global[i].first, 3556 InterpreterTester tester(handles.main_isolate(), eval_global[i].first,
3557 "test"); 3557 "test");
3558 auto callable = tester.GetCallable<>(); 3558 auto callable = tester.GetCallable<>();
3559 3559
3560 Handle<i::Object> return_value = callable().ToHandleChecked(); 3560 Handle<i::Object> return_value = callable().ToHandleChecked();
3561 CHECK(return_value->SameValue(*eval_global[i].second)); 3561 CHECK(return_value->SameValue(*eval_global[i].second));
3562 } 3562 }
3563 } 3563 }
3564 3564
3565
3566 TEST(InterpreterEvalVariableDecl) {
3567 HandleAndZoneScope handles;
3568 i::Isolate* isolate = handles.main_isolate();
3569 i::Factory* factory = isolate->factory();
3570
3571 std::pair<const char*, Handle<Object>> eval_global[] = {
3572 {"function f() { eval('var x = 10; x++;'); return x; }",
3573 handle(Smi::FromInt(11), isolate)},
3574 {"function f() { var x = 20; eval('var x = 10; x++;'); return x; }",
3575 handle(Smi::FromInt(11), isolate)},
3576 {"function f() {"
3577 " var x = 20;"
3578 " eval('\"use strict\"; var x = 10; x++;');"
3579 " return x; }",
3580 handle(Smi::FromInt(20), isolate)},
3581 {"function f() {"
3582 " var y = 30;"
3583 " eval('var x = {1:20}; x[2]=y;');"
3584 " return x[2]; }",
3585 handle(Smi::FromInt(30), isolate)},
3586 {"function f() {"
3587 " eval('var x = {name:\"test\"};');"
3588 " return x.name; }",
3589 factory->NewStringFromStaticChars("test")},
3590 {"function f() {"
3591 " eval('var x = [{name:\"test\"}, {type:\"cc\"}];');"
3592 " return x[1].type+x[0].name; }",
3593 factory->NewStringFromStaticChars("cctest")},
3594 {"function f() {\n"
3595 " var x = 3;\n"
3596 " var get_eval_x;\n"
3597 " eval('\"use strict\"; "
3598 " var x = 20; "
3599 " get_eval_x = function func() {return x;};');\n"
3600 " return get_eval_x() + x;\n"
3601 "}",
3602 handle(Smi::FromInt(23), isolate)},
3603 // TODO(mythria): Add tests with const declarations.
3604 };
3605
3606 for (size_t i = 0; i < arraysize(eval_global); i++) {
3607 InterpreterTester tester(handles.main_isolate(), eval_global[i].first, "*");
3608 auto callable = tester.GetCallable<>();
3609
3610 Handle<i::Object> return_value = callable().ToHandleChecked();
3611 CHECK(return_value->SameValue(*eval_global[i].second));
3612 }
3613 }
3614
3615
3616 TEST(InterpreterEvalFunctionDecl) {
3617 HandleAndZoneScope handles;
3618 i::Isolate* isolate = handles.main_isolate();
3619
3620 std::pair<const char*, Handle<Object>> eval_func_decl[] = {
3621 {"function f() {\n"
3622 " var x = 3;\n"
3623 " eval('var x = 20;"
3624 " function get_x() {return x;};');\n"
3625 " return get_x() + x;\n"
3626 "}",
3627 handle(Smi::FromInt(40), isolate)},
3628 };
3629
3630 for (size_t i = 0; i < arraysize(eval_func_decl); i++) {
3631 InterpreterTester tester(handles.main_isolate(), eval_func_decl[i].first,
3632 "*");
3633 auto callable = tester.GetCallable<>();
3634
3635 Handle<i::Object> return_value = callable().ToHandleChecked();
3636 CHECK(return_value->SameValue(*eval_func_decl[i].second));
3637 }
3638 }
3639
3565 } // namespace interpreter 3640 } // namespace interpreter
3566 } // namespace internal 3641 } // namespace internal
3567 } // namespace v8 3642 } // 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