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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "src/compilation-info.h" | 7 #include "src/compilation-info.h" |
8 #include "src/compiler/pipeline.h" | 8 #include "src/compiler/pipeline.h" |
9 #include "src/execution.h" | 9 #include "src/execution.h" |
10 #include "src/handles.h" | 10 #include "src/handles.h" |
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 outer_eval_prologue, outer_eval_snippets[i].code_snippet, | 1110 outer_eval_prologue, outer_eval_snippets[i].code_snippet, |
1111 outer_eval_epilogue, kFunctionName); | 1111 outer_eval_epilogue, kFunctionName); |
1112 | 1112 |
1113 BytecodeGraphTester tester(isolate, zone, script.start()); | 1113 BytecodeGraphTester tester(isolate, zone, script.start()); |
1114 auto callable = tester.GetCallable<>(); | 1114 auto callable = tester.GetCallable<>(); |
1115 Handle<Object> return_value = callable().ToHandleChecked(); | 1115 Handle<Object> return_value = callable().ToHandleChecked(); |
1116 CHECK(return_value->SameValue(*outer_eval_snippets[i].return_value())); | 1116 CHECK(return_value->SameValue(*outer_eval_snippets[i].return_value())); |
1117 } | 1117 } |
1118 } | 1118 } |
1119 | 1119 |
| 1120 TEST(BytecodeGraphBuilderLookupGlobalSlot) { |
| 1121 HandleAndZoneScope scope; |
| 1122 Isolate* isolate = scope.main_isolate(); |
| 1123 Zone* zone = scope.main_zone(); |
| 1124 Factory* factory = isolate->factory(); |
| 1125 |
| 1126 // Testing with eval called in the current context. |
| 1127 const char* inner_eval_prologue = "x = 0; function inner() {"; |
| 1128 const char* inner_eval_epilogue = "}; return inner();"; |
| 1129 |
| 1130 ExpectedSnippet<0> inner_eval_snippets[] = { |
| 1131 {"eval(''); return x;", {factory->NewNumber(0)}}, |
| 1132 {"eval('var x = 1'); return x;", {factory->NewNumber(1)}}, |
| 1133 {"'use strict'; eval('var x = 1'); return x;", {factory->NewNumber(0)}}}; |
| 1134 |
| 1135 for (size_t i = 0; i < arraysize(inner_eval_snippets); i++) { |
| 1136 ScopedVector<char> script(1024); |
| 1137 SNPrintF(script, "function %s(p1) { %s %s %s } ; %s() ;", kFunctionName, |
| 1138 inner_eval_prologue, inner_eval_snippets[i].code_snippet, |
| 1139 inner_eval_epilogue, kFunctionName); |
| 1140 |
| 1141 BytecodeGraphTester tester(isolate, zone, script.start()); |
| 1142 auto callable = tester.GetCallable<>(); |
| 1143 Handle<Object> return_value = callable().ToHandleChecked(); |
| 1144 CHECK(return_value->SameValue(*inner_eval_snippets[i].return_value())); |
| 1145 } |
| 1146 |
| 1147 // Testing with eval called in a parent context. |
| 1148 const char* outer_eval_prologue = ""; |
| 1149 const char* outer_eval_epilogue = |
| 1150 "function inner() { return x; }; return inner();"; |
| 1151 |
| 1152 ExpectedSnippet<0> outer_eval_snippets[] = { |
| 1153 {"x = 0; eval('');", {factory->NewNumber(0)}}, |
| 1154 {"x = 0; eval('var x = 1');", {factory->NewNumber(1)}}, |
| 1155 {"'use strict'; x = 0; eval('var x = 1');", {factory->NewNumber(0)}}}; |
| 1156 |
| 1157 for (size_t i = 0; i < arraysize(outer_eval_snippets); i++) { |
| 1158 ScopedVector<char> script(1024); |
| 1159 SNPrintF(script, "function %s() { %s %s %s } ; %s() ;", kFunctionName, |
| 1160 outer_eval_prologue, outer_eval_snippets[i].code_snippet, |
| 1161 outer_eval_epilogue, kFunctionName); |
| 1162 |
| 1163 BytecodeGraphTester tester(isolate, zone, script.start()); |
| 1164 auto callable = tester.GetCallable<>(); |
| 1165 Handle<Object> return_value = callable().ToHandleChecked(); |
| 1166 CHECK(return_value->SameValue(*outer_eval_snippets[i].return_value())); |
| 1167 } |
| 1168 } |
| 1169 |
1120 TEST(BytecodeGraphBuilderLookupSlotWide) { | 1170 TEST(BytecodeGraphBuilderLookupSlotWide) { |
1121 HandleAndZoneScope scope; | 1171 HandleAndZoneScope scope; |
1122 Isolate* isolate = scope.main_isolate(); | 1172 Isolate* isolate = scope.main_isolate(); |
1123 Zone* zone = scope.main_zone(); | 1173 Zone* zone = scope.main_zone(); |
1124 Factory* factory = isolate->factory(); | 1174 Factory* factory = isolate->factory(); |
1125 | 1175 |
1126 const char* function_prologue = | 1176 const char* function_prologue = |
1127 "var f;" | 1177 "var f;" |
1128 "var x = 12;" | 1178 "var x = 12;" |
1129 "y = 10;" | 1179 "y = 10;" |
(...skipping 1876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3006 | 3056 |
3007 BytecodeGraphTester tester(isolate, zone, script.start()); | 3057 BytecodeGraphTester tester(isolate, zone, script.start()); |
3008 auto callable = tester.GetCallable<>(); | 3058 auto callable = tester.GetCallable<>(); |
3009 Handle<Object> return_value = callable().ToHandleChecked(); | 3059 Handle<Object> return_value = callable().ToHandleChecked(); |
3010 CHECK(return_value->SameValue(*snippet.return_value())); | 3060 CHECK(return_value->SameValue(*snippet.return_value())); |
3011 } | 3061 } |
3012 | 3062 |
3013 } // namespace compiler | 3063 } // namespace compiler |
3014 } // namespace internal | 3064 } // namespace internal |
3015 } // namespace v8 | 3065 } // namespace v8 |
OLD | NEW |