| 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/compiler.h" | 7 #include "src/compiler.h" |
| 8 #include "src/interpreter/bytecode-array-iterator.h" | 8 #include "src/interpreter/bytecode-array-iterator.h" |
| 9 #include "src/interpreter/bytecode-generator.h" | 9 #include "src/interpreter/bytecode-generator.h" |
| 10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
| (...skipping 4149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4160 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4160 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4161 } | 4161 } |
| 4162 } | 4162 } |
| 4163 | 4163 |
| 4164 | 4164 |
| 4165 TEST(TryCatch) { | 4165 TEST(TryCatch) { |
| 4166 InitializedHandleScope handle_scope; | 4166 InitializedHandleScope handle_scope; |
| 4167 BytecodeGeneratorHelper helper; | 4167 BytecodeGeneratorHelper helper; |
| 4168 | 4168 |
| 4169 int closure = Register::function_closure().index(); | 4169 int closure = Register::function_closure().index(); |
| 4170 int context = Register::function_context().index(); |
| 4170 | 4171 |
| 4171 ExpectedSnippet<const char*> snippets[] = { | 4172 ExpectedSnippet<const char*> snippets[] = { |
| 4172 {"try { return 1; } catch(e) { return 2; }", | 4173 {"try { return 1; } catch(e) { return 2; }", |
| 4173 5 * kPointerSize, | 4174 5 * kPointerSize, |
| 4174 1, | 4175 1, |
| 4175 23, | 4176 25, |
| 4176 { | 4177 { |
| 4177 B(LdaSmi8), U8(1), // | 4178 B(LdaSmi8), U8(1), // |
| 4178 B(Return), // | 4179 B(Return), // |
| 4179 B(Star), R(3), // | 4180 B(Star), R(3), // |
| 4180 B(LdaConstant), U8(0), // | 4181 B(LdaConstant), U8(0), // |
| 4181 B(Star), R(2), // | 4182 B(Star), R(2), // |
| 4182 B(Ldar), R(closure), // | 4183 B(Ldar), R(closure), // |
| 4183 B(Star), R(4), // | 4184 B(Star), R(4), // |
| 4184 B(CallRuntime), U16(Runtime::kPushCatchContext), R(2), U8(3), // | 4185 B(CallRuntime), U16(Runtime::kPushCatchContext), R(2), U8(3), // |
| 4186 B(PushContext), R(0), // |
| 4185 B(LdaSmi8), U8(2), // | 4187 B(LdaSmi8), U8(2), // |
| 4186 B(Return), // | 4188 B(Return), // |
| 4187 // TODO(mstarzinger): Potential optimization, elide next bytes. | 4189 // TODO(mstarzinger): Potential optimization, elide next bytes. |
| 4188 B(LdaUndefined), // | 4190 B(LdaUndefined), // |
| 4189 B(Return), // | 4191 B(Return), // |
| 4190 }, | 4192 }, |
| 4191 1, | 4193 1, |
| 4192 {"e"}, | 4194 {"e"}, |
| 4193 1, | 4195 1, |
| 4194 {{0, 3, 3}}}, | 4196 {{0, 3, 3}}}, |
| 4195 {"var a; try { a = 1 } catch(e1) {}; try { a = 2 } catch(e2) { a = 3 }", | 4197 {"var a; try { a = 1 } catch(e1) {}; try { a = 2 } catch(e2) { a = 3 }", |
| 4196 6 * kPointerSize, | 4198 6 * kPointerSize, |
| 4197 1, | 4199 1, |
| 4198 48, | 4200 56, |
| 4199 { | 4201 { |
| 4200 B(LdaSmi8), U8(1), // | 4202 B(LdaSmi8), U8(1), // |
| 4201 B(Star), R(0), // | 4203 B(Star), R(0), // |
| 4202 B(Jump), U8(17), // | 4204 B(Jump), U8(21), // |
| 4203 B(Star), R(4), // | 4205 B(Star), R(4), // |
| 4204 B(LdaConstant), U8(0), // | 4206 B(LdaConstant), U8(0), // |
| 4205 B(Star), R(3), // | 4207 B(Star), R(3), // |
| 4206 B(Ldar), R(closure), // | 4208 B(Ldar), R(closure), // |
| 4207 B(Star), R(5), // | 4209 B(Star), R(5), // |
| 4208 B(CallRuntime), U16(Runtime::kPushCatchContext), R(3), U8(3), // | 4210 B(CallRuntime), U16(Runtime::kPushCatchContext), R(3), U8(3), // |
| 4211 B(PushContext), R(1), // |
| 4212 B(PopContext), R(context), // |
| 4209 B(LdaSmi8), U8(2), // | 4213 B(LdaSmi8), U8(2), // |
| 4210 B(Star), R(0), // | 4214 B(Star), R(0), // |
| 4211 B(Jump), U8(21), // | 4215 B(Jump), U8(25), // |
| 4212 B(Star), R(4), // | 4216 B(Star), R(4), // |
| 4213 B(LdaConstant), U8(1), // | 4217 B(LdaConstant), U8(1), // |
| 4214 B(Star), R(3), // | 4218 B(Star), R(3), // |
| 4215 B(Ldar), R(closure), // | 4219 B(Ldar), R(closure), // |
| 4216 B(Star), R(5), // | 4220 B(Star), R(5), // |
| 4217 B(CallRuntime), U16(Runtime::kPushCatchContext), R(3), U8(3), // | 4221 B(CallRuntime), U16(Runtime::kPushCatchContext), R(3), U8(3), // |
| 4222 B(PushContext), R(1), // |
| 4218 B(LdaSmi8), U8(3), // | 4223 B(LdaSmi8), U8(3), // |
| 4219 B(Star), R(0), // | 4224 B(Star), R(0), // |
| 4225 B(PopContext), R(context), // |
| 4220 B(LdaUndefined), // | 4226 B(LdaUndefined), // |
| 4221 B(Return), // | 4227 B(Return), // |
| 4222 }, | 4228 }, |
| 4223 2, | 4229 2, |
| 4224 {"e1", "e2"}, | 4230 {"e1", "e2"}, |
| 4225 2, | 4231 2, |
| 4226 {{0, 4, 6}, {21, 25, 27}}}, | 4232 {{0, 4, 6}, {25, 29, 31}}}, |
| 4227 }; | 4233 }; |
| 4228 | 4234 |
| 4229 for (size_t i = 0; i < arraysize(snippets); i++) { | 4235 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 4230 Handle<BytecodeArray> bytecode_array = | 4236 Handle<BytecodeArray> bytecode_array = |
| 4231 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 4237 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 4232 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4238 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4233 } | 4239 } |
| 4234 } | 4240 } |
| 4235 | 4241 |
| 4236 | 4242 |
| 4237 TEST(TryFinally) { | 4243 TEST(TryFinally) { |
| 4238 InitializedHandleScope handle_scope; | 4244 InitializedHandleScope handle_scope; |
| 4239 BytecodeGeneratorHelper helper; | 4245 BytecodeGeneratorHelper helper; |
| 4240 | 4246 |
| 4241 int closure = Register::function_closure().index(); | 4247 int closure = Register::function_closure().index(); |
| 4248 int context = Register::function_context().index(); |
| 4242 | 4249 |
| 4243 ExpectedSnippet<const char*> snippets[] = { | 4250 ExpectedSnippet<const char*> snippets[] = { |
| 4244 {"var a = 1; try { a = 2; } finally { a = 3; }", | 4251 {"var a = 1; try { a = 2; } finally { a = 3; }", |
| 4245 2 * kPointerSize, | 4252 2 * kPointerSize, |
| 4246 1, | 4253 1, |
| 4247 14, | 4254 14, |
| 4248 { | 4255 { |
| 4249 B(LdaSmi8), U8(1), // | 4256 B(LdaSmi8), U8(1), // |
| 4250 B(Star), R(0), // | 4257 B(Star), R(0), // |
| 4251 B(LdaSmi8), U8(2), // | 4258 B(LdaSmi8), U8(2), // |
| 4252 B(Star), R(0), // | 4259 B(Star), R(0), // |
| 4253 B(LdaSmi8), U8(3), // | 4260 B(LdaSmi8), U8(3), // |
| 4254 B(Star), R(0), // | 4261 B(Star), R(0), // |
| 4255 B(LdaUndefined), // | 4262 B(LdaUndefined), // |
| 4256 B(Return), // | 4263 B(Return), // |
| 4257 }, | 4264 }, |
| 4258 0, | 4265 0, |
| 4259 {}, | 4266 {}, |
| 4260 1, | 4267 1, |
| 4261 {{4, 8, 8}}}, | 4268 {{4, 8, 8}}}, |
| 4262 {"var a = 1; try { a = 2; } catch(e) { a = 20 } finally { a = 3; }", | 4269 {"var a = 1; try { a = 2; } catch(e) { a = 20 } finally { a = 3; }", |
| 4263 7 * kPointerSize, | 4270 7 * kPointerSize, |
| 4264 1, | 4271 1, |
| 4265 35, | 4272 39, |
| 4266 { | 4273 { |
| 4267 B(LdaSmi8), U8(1), // | 4274 B(LdaSmi8), U8(1), // |
| 4268 B(Star), R(0), // | 4275 B(Star), R(0), // |
| 4269 B(LdaSmi8), U8(2), // | 4276 B(LdaSmi8), U8(2), // |
| 4270 B(Star), R(0), // | 4277 B(Star), R(0), // |
| 4271 B(Jump), U8(21), // | 4278 B(Jump), U8(25), // |
| 4272 B(Star), R(5), // | 4279 B(Star), R(5), // |
| 4273 B(LdaConstant), U8(0), // | 4280 B(LdaConstant), U8(0), // |
| 4274 B(Star), R(4), // | 4281 B(Star), R(4), // |
| 4275 B(Ldar), R(closure), // | 4282 B(Ldar), R(closure), // |
| 4276 B(Star), R(6), // | 4283 B(Star), R(6), // |
| 4277 B(CallRuntime), U16(Runtime::kPushCatchContext), R(4), U8(3), // | 4284 B(CallRuntime), U16(Runtime::kPushCatchContext), R(4), U8(3), // |
| 4285 B(PushContext), R(1), // |
| 4278 B(LdaSmi8), U8(20), // | 4286 B(LdaSmi8), U8(20), // |
| 4279 B(Star), R(0), // | 4287 B(Star), R(0), // |
| 4288 B(PopContext), R(context), // |
| 4280 B(LdaSmi8), U8(3), // | 4289 B(LdaSmi8), U8(3), // |
| 4281 B(Star), R(0), // | 4290 B(Star), R(0), // |
| 4282 B(LdaUndefined), // | 4291 B(LdaUndefined), // |
| 4283 B(Return), // | 4292 B(Return), // |
| 4284 }, | 4293 }, |
| 4285 1, | 4294 1, |
| 4286 {"e"}, | 4295 {"e"}, |
| 4287 2, | 4296 2, |
| 4288 {{4, 29, 29}, {4, 8, 10}}}, | 4297 {{4, 33, 33}, {4, 8, 10}}}, |
| 4289 {"var a; try {" | 4298 {"var a; try {" |
| 4290 " try { a = 1 } catch(e) { a = 2 }" | 4299 " try { a = 1 } catch(e) { a = 2 }" |
| 4291 "} catch(e) { a = 20 } finally { a = 3; }", | 4300 "} catch(e) { a = 20 } finally { a = 3; }", |
| 4292 8 * kPointerSize, | 4301 8 * kPointerSize, |
| 4293 1, | 4302 1, |
| 4294 52, | 4303 60, |
| 4295 { | 4304 { |
| 4296 B(LdaSmi8), U8(1), // | 4305 B(LdaSmi8), U8(1), // |
| 4297 B(Star), R(0), // | 4306 B(Star), R(0), // |
| 4298 B(Jump), U8(21), // | 4307 B(Jump), U8(25), // |
| 4299 B(Star), R(6), // | 4308 B(Star), R(6), // |
| 4300 B(LdaConstant), U8(0), // | 4309 B(LdaConstant), U8(0), // |
| 4301 B(Star), R(5), // | 4310 B(Star), R(5), // |
| 4302 B(Ldar), R(closure), // | 4311 B(Ldar), R(closure), // |
| 4303 B(Star), R(7), // | 4312 B(Star), R(7), // |
| 4304 B(CallRuntime), U16(Runtime::kPushCatchContext), R(5), U8(3), // | 4313 B(CallRuntime), U16(Runtime::kPushCatchContext), R(5), U8(3), // |
| 4314 B(PushContext), R(1), // |
| 4305 B(LdaSmi8), U8(2), // | 4315 B(LdaSmi8), U8(2), // |
| 4306 B(Star), R(0), // | 4316 B(Star), R(0), // |
| 4307 B(Jump), U8(21), // | 4317 B(PopContext), R(context), // |
| 4318 B(Jump), U8(25), // |
| 4308 B(Star), R(5), // | 4319 B(Star), R(5), // |
| 4309 B(LdaConstant), U8(0), // | 4320 B(LdaConstant), U8(0), // |
| 4310 B(Star), R(4), // | 4321 B(Star), R(4), // |
| 4311 B(Ldar), R(closure), // | 4322 B(Ldar), R(closure), // |
| 4312 B(Star), R(6), // | 4323 B(Star), R(6), // |
| 4313 B(CallRuntime), U16(Runtime::kPushCatchContext), R(4), U8(3), // | 4324 B(CallRuntime), U16(Runtime::kPushCatchContext), R(4), U8(3), // |
| 4325 B(PushContext), R(1), // |
| 4314 B(LdaSmi8), U8(20), // | 4326 B(LdaSmi8), U8(20), // |
| 4315 B(Star), R(0), // | 4327 B(Star), R(0), // |
| 4328 B(PopContext), R(context), // |
| 4316 B(LdaSmi8), U8(3), // | 4329 B(LdaSmi8), U8(3), // |
| 4317 B(Star), R(0), // | 4330 B(Star), R(0), // |
| 4318 B(LdaUndefined), // | 4331 B(LdaUndefined), // |
| 4319 B(Return), // | 4332 B(Return), // |
| 4320 }, | 4333 }, |
| 4321 1, | 4334 1, |
| 4322 {"e"}, | 4335 {"e"}, |
| 4323 3, | 4336 3, |
| 4324 {{0, 46, 46}, {0, 25, 27}, {0, 4, 6}}}, | 4337 {{0, 54, 54}, {0, 29, 31}, {0, 4, 6}}}, |
| 4325 }; | 4338 }; |
| 4326 | 4339 |
| 4327 for (size_t i = 0; i < arraysize(snippets); i++) { | 4340 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 4328 Handle<BytecodeArray> bytecode_array = | 4341 Handle<BytecodeArray> bytecode_array = |
| 4329 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 4342 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 4330 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4343 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4331 } | 4344 } |
| 4332 } | 4345 } |
| 4333 | 4346 |
| 4334 | 4347 |
| (...skipping 2548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6883 std::string(function_epilogue); | 6896 std::string(function_epilogue); |
| 6884 Handle<BytecodeArray> bytecode_array = | 6897 Handle<BytecodeArray> bytecode_array = |
| 6885 helper.MakeBytecode(script.c_str(), "*", "f"); | 6898 helper.MakeBytecode(script.c_str(), "*", "f"); |
| 6886 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 6899 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 6887 } | 6900 } |
| 6888 } | 6901 } |
| 6889 | 6902 |
| 6890 } // namespace interpreter | 6903 } // namespace interpreter |
| 6891 } // namespace internal | 6904 } // namespace internal |
| 6892 } // namespace v8 | 6905 } // namespace v8 |
| OLD | NEW |