Chromium Code Reviews| 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/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
| (...skipping 3531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3542 for (size_t i = 0; i < arraysize(eval_global); i++) { | 3542 for (size_t i = 0; i < arraysize(eval_global); i++) { |
| 3543 InterpreterTester tester(handles.main_isolate(), eval_global[i].first, | 3543 InterpreterTester tester(handles.main_isolate(), eval_global[i].first, |
| 3544 "test"); | 3544 "test"); |
| 3545 auto callable = tester.GetCallable<>(); | 3545 auto callable = tester.GetCallable<>(); |
| 3546 | 3546 |
| 3547 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3547 Handle<i::Object> return_value = callable().ToHandleChecked(); |
| 3548 CHECK(return_value->SameValue(*eval_global[i].second)); | 3548 CHECK(return_value->SameValue(*eval_global[i].second)); |
| 3549 } | 3549 } |
| 3550 } | 3550 } |
| 3551 | 3551 |
| 3552 | |
| 3553 TEST(InterpreterEvalVariableDecl) { | |
| 3554 HandleAndZoneScope handles; | |
| 3555 i::Isolate* isolate = handles.main_isolate(); | |
| 3556 i::Factory* factory = isolate->factory(); | |
| 3557 | |
| 3558 std::pair<const char*, Handle<Object>> eval_global[] = { | |
| 3559 {"function f() { eval('var x = 10; x++;'); return x; }", | |
| 3560 handle(Smi::FromInt(11), isolate)}, | |
| 3561 {"function f() { var x = 20; eval('var x = 10; x++;'); return x; }", | |
| 3562 handle(Smi::FromInt(11), isolate)}, | |
| 3563 {"function f() {" | |
| 3564 " var x = 20;" | |
| 3565 " eval('\"use strict\"; var x = 10; x++;');" | |
| 3566 " return x; }", | |
| 3567 handle(Smi::FromInt(20), isolate)}, | |
| 3568 {"function f() {" | |
| 3569 " var y = 30;" | |
| 3570 " eval('var x = {1:20}; x[2]=y;');" | |
| 3571 " return x[2]; }", | |
| 3572 handle(Smi::FromInt(30), isolate)}, | |
| 3573 {"function f() {" | |
| 3574 " eval('var x = {name:\"test\"};');" | |
| 3575 " return x.name; }", | |
| 3576 factory->NewStringFromStaticChars("test")}, | |
| 3577 {"function f() {" | |
| 3578 " eval('var x = [{name:\"test\"}, {type:\"cc\"}];');" | |
| 3579 " return x[1].type+x[0].name; }", | |
| 3580 factory->NewStringFromStaticChars("cctest")}, | |
| 3581 // TODO(mythria): Add tests with const declarations. | |
| 3582 }; | |
| 3583 | |
| 3584 for (size_t i = 0; i < arraysize(eval_global); i++) { | |
| 3585 InterpreterTester tester(handles.main_isolate(), eval_global[i].first, "*"); | |
| 3586 auto callable = tester.GetCallable<>(); | |
| 3587 | |
| 3588 Handle<i::Object> return_value = callable().ToHandleChecked(); | |
| 3589 CHECK(return_value->SameValue(*eval_global[i].second)); | |
| 3590 } | |
| 3591 } | |
| 3592 | |
| 3593 | |
| 3594 TEST(InterpreterEvalFunctionDecl) { | |
| 3595 HandleAndZoneScope handles; | |
| 3596 i::Isolate* isolate = handles.main_isolate(); | |
| 3597 | |
| 3598 std::pair<const char*, Handle<Object>> eval_global[] = { | |
| 3599 {"function f() {\n" | |
| 3600 " var get_eval_x;\n" | |
| 3601 " var x = 3;\n" | |
| 3602 " eval('\"use strict\"; " | |
| 3603 " var x = 20; " | |
| 3604 " function func() {return x;}; " | |
| 3605 " get_eval_x = func;');\n" | |
| 3606 " return get_eval_x() + x;\n" | |
| 3607 "}", | |
| 3608 handle(Smi::FromInt(23), isolate)}, | |
| 3609 {"function f() {\n" | |
| 3610 " var get_x;\n" | |
| 3611 " var x = 3;\n" | |
| 3612 " eval('var x = 20;" | |
| 3613 " function func() {return x;};" | |
| 3614 " get_x = func;');\n" | |
| 3615 " return get_x() + x;\n" | |
|
rmcilroy
2016/01/14 11:21:12
These are testing variable declarations (since you
mythria
2016/01/15 11:27:04
In strict mode, we cannot function declarations ev
| |
| 3616 "}", | |
| 3617 handle(Smi::FromInt(40), isolate)}, | |
| 3618 }; | |
| 3619 | |
| 3620 for (size_t i = 0; i < arraysize(eval_global); i++) { | |
| 3621 InterpreterTester tester(handles.main_isolate(), eval_global[i].first, "*"); | |
| 3622 auto callable = tester.GetCallable<>(); | |
| 3623 | |
| 3624 Handle<i::Object> return_value = callable().ToHandleChecked(); | |
| 3625 CHECK(return_value->SameValue(*eval_global[i].second)); | |
| 3626 } | |
| 3627 } | |
| 3628 | |
| 3552 } // namespace interpreter | 3629 } // namespace interpreter |
| 3553 } // namespace internal | 3630 } // namespace internal |
| 3554 } // namespace v8 | 3631 } // namespace v8 |
| OLD | NEW |