| 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 4242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4253 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4253 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4254 } | 4254 } |
| 4255 } | 4255 } |
| 4256 | 4256 |
| 4257 | 4257 |
| 4258 TEST(TryCatch) { | 4258 TEST(TryCatch) { |
| 4259 InitializedHandleScope handle_scope; | 4259 InitializedHandleScope handle_scope; |
| 4260 BytecodeGeneratorHelper helper; | 4260 BytecodeGeneratorHelper helper; |
| 4261 | 4261 |
| 4262 int closure = Register::function_closure().index(); | 4262 int closure = Register::function_closure().index(); |
| 4263 int context = Register::current_context().index(); |
| 4263 | 4264 |
| 4264 ExpectedSnippet<const char*> snippets[] = { | 4265 ExpectedSnippet<const char*> snippets[] = { |
| 4265 {"try { return 1; } catch(e) { return 2; }", | 4266 {"try { return 1; } catch(e) { return 2; }", |
| 4266 5 * kPointerSize, | 4267 5 * kPointerSize, |
| 4267 1, | 4268 1, |
| 4268 36, | 4269 39, |
| 4269 { | 4270 { |
| 4271 B(Mov), R(context), R(1), // |
| 4270 B(LdaSmi8), U8(1), // | 4272 B(LdaSmi8), U8(1), // |
| 4271 B(Return), // | 4273 B(Return), // |
| 4272 B(Star), R(3), // | 4274 B(Star), R(3), // |
| 4273 B(LdaConstant), U8(0), // | 4275 B(LdaConstant), U8(0), // |
| 4274 B(Star), R(2), // | 4276 B(Star), R(2), // |
| 4275 B(Ldar), R(closure), // | 4277 B(Ldar), R(closure), // |
| 4276 B(Star), R(4), // | 4278 B(Star), R(4), // |
| 4277 B(CallRuntime), U16(Runtime::kPushCatchContext), R(2), U8(3), // | 4279 B(CallRuntime), U16(Runtime::kPushCatchContext), R(2), U8(3), // |
| 4278 B(Star), R(1), // | 4280 B(Star), R(1), // |
| 4279 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // | 4281 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4280 /* */ R(0), U8(0), // | 4282 /* */ R(0), U8(0), // |
| 4281 B(Ldar), R(1), // | 4283 B(Ldar), R(1), // |
| 4282 B(PushContext), R(0), // | 4284 B(PushContext), R(0), // |
| 4283 B(LdaSmi8), U8(2), // | 4285 B(LdaSmi8), U8(2), // |
| 4284 B(PopContext), R(0), // | 4286 B(PopContext), R(0), // |
| 4285 B(Return), // | 4287 B(Return), // |
| 4286 // TODO(mstarzinger): Potential optimization, elide next bytes. | 4288 // TODO(mstarzinger): Potential optimization, elide next bytes. |
| 4287 B(LdaUndefined), // | 4289 B(LdaUndefined), // |
| 4288 B(Return), // | 4290 B(Return), // |
| 4289 }, | 4291 }, |
| 4290 1, | 4292 1, |
| 4291 {"e"}, | 4293 {"e"}, |
| 4292 1, | 4294 1, |
| 4293 {{0, 3, 3}}}, | 4295 {{3, 6, 6}}}, |
| 4294 {"var a; try { a = 1 } catch(e1) {}; try { a = 2 } catch(e2) { a = 3 }", | 4296 {"var a; try { a = 1 } catch(e1) {}; try { a = 2 } catch(e2) { a = 3 }", |
| 4295 6 * kPointerSize, | 4297 6 * kPointerSize, |
| 4296 1, | 4298 1, |
| 4297 74, | 4299 80, |
| 4298 { | 4300 { |
| 4301 B(Mov), R(context), R(2), // |
| 4299 B(LdaSmi8), U8(1), // | 4302 B(LdaSmi8), U8(1), // |
| 4300 B(Star), R(0), // | 4303 B(Star), R(0), // |
| 4301 B(Jump), U8(30), // | 4304 B(Jump), U8(30), // |
| 4302 B(Star), R(4), // | 4305 B(Star), R(4), // |
| 4303 B(LdaConstant), U8(0), // | 4306 B(LdaConstant), U8(0), // |
| 4304 B(Star), R(3), // | 4307 B(Star), R(3), // |
| 4305 B(Ldar), R(closure), // | 4308 B(Ldar), R(closure), // |
| 4306 B(Star), R(5), // | 4309 B(Star), R(5), // |
| 4307 B(CallRuntime), U16(Runtime::kPushCatchContext), R(3), U8(3), // | 4310 B(CallRuntime), U16(Runtime::kPushCatchContext), R(3), U8(3), // |
| 4308 B(Star), R(2), // | 4311 B(Star), R(2), // |
| 4309 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // | 4312 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4310 /* */ R(0), U8(0), // | 4313 /* */ R(0), U8(0), // |
| 4311 B(Ldar), R(2), // | 4314 B(Ldar), R(2), // |
| 4312 B(PushContext), R(1), // | 4315 B(PushContext), R(1), // |
| 4313 B(PopContext), R(1), // | 4316 B(PopContext), R(1), // |
| 4317 B(Mov), R(context), R(2), // |
| 4314 B(LdaSmi8), U8(2), // | 4318 B(LdaSmi8), U8(2), // |
| 4315 B(Star), R(0), // | 4319 B(Star), R(0), // |
| 4316 B(Jump), U8(34), // | 4320 B(Jump), U8(34), // |
| 4317 B(Star), R(4), // | 4321 B(Star), R(4), // |
| 4318 B(LdaConstant), U8(1), // | 4322 B(LdaConstant), U8(1), // |
| 4319 B(Star), R(3), // | 4323 B(Star), R(3), // |
| 4320 B(Ldar), R(closure), // | 4324 B(Ldar), R(closure), // |
| 4321 B(Star), R(5), // | 4325 B(Star), R(5), // |
| 4322 B(CallRuntime), U16(Runtime::kPushCatchContext), R(3), U8(3), // | 4326 B(CallRuntime), U16(Runtime::kPushCatchContext), R(3), U8(3), // |
| 4323 B(Star), R(2), // | 4327 B(Star), R(2), // |
| 4324 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // | 4328 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4325 /* */ R(0), U8(0), // | 4329 /* */ R(0), U8(0), // |
| 4326 B(Ldar), R(2), // | 4330 B(Ldar), R(2), // |
| 4327 B(PushContext), R(1), // | 4331 B(PushContext), R(1), // |
| 4328 B(LdaSmi8), U8(3), // | 4332 B(LdaSmi8), U8(3), // |
| 4329 B(Star), R(0), // | 4333 B(Star), R(0), // |
| 4330 B(PopContext), R(1), // | 4334 B(PopContext), R(1), // |
| 4331 B(LdaUndefined), // | 4335 B(LdaUndefined), // |
| 4332 B(Return), // | 4336 B(Return), // |
| 4333 }, | 4337 }, |
| 4334 2, | 4338 2, |
| 4335 {"e1", "e2"}, | 4339 {"e1", "e2"}, |
| 4336 2, | 4340 2, |
| 4337 {{0, 4, 6}, {34, 38, 40}}}, | 4341 {{3, 7, 9}, {40, 44, 46}}}, |
| 4338 }; | 4342 }; |
| 4339 | 4343 |
| 4340 for (size_t i = 0; i < arraysize(snippets); i++) { | 4344 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 4341 Handle<BytecodeArray> bytecode_array = | 4345 Handle<BytecodeArray> bytecode_array = |
| 4342 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 4346 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 4343 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4347 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4344 } | 4348 } |
| 4345 } | 4349 } |
| 4346 | 4350 |
| 4347 | 4351 |
| 4348 TEST(TryFinally) { | 4352 TEST(TryFinally) { |
| 4349 InitializedHandleScope handle_scope; | 4353 InitializedHandleScope handle_scope; |
| 4350 BytecodeGeneratorHelper helper; | 4354 BytecodeGeneratorHelper helper; |
| 4351 | 4355 |
| 4352 int closure = Register::function_closure().index(); | 4356 int closure = Register::function_closure().index(); |
| 4357 int context = Register::current_context().index(); |
| 4353 | 4358 |
| 4354 ExpectedSnippet<const char*> snippets[] = { | 4359 ExpectedSnippet<const char*> snippets[] = { |
| 4355 {"var a = 1; try { a = 2; } finally { a = 3; }", | 4360 {"var a = 1; try { a = 2; } finally { a = 3; }", |
| 4356 4 * kPointerSize, | 4361 4 * kPointerSize, |
| 4357 1, | 4362 1, |
| 4358 47, | 4363 50, |
| 4359 { | 4364 { |
| 4360 B(LdaSmi8), U8(1), // | 4365 B(LdaSmi8), U8(1), // |
| 4361 B(Star), R(0), // | 4366 B(Star), R(0), // |
| 4367 B(Mov), R(context), R(3), // |
| 4362 B(LdaSmi8), U8(2), // | 4368 B(LdaSmi8), U8(2), // |
| 4363 B(Star), R(0), // | 4369 B(Star), R(0), // |
| 4364 B(LdaSmi8), U8(-1), // | 4370 B(LdaSmi8), U8(-1), // |
| 4365 B(Star), R(1), // | 4371 B(Star), R(1), // |
| 4366 B(Jump), U8(7), // | 4372 B(Jump), U8(7), // |
| 4367 B(Star), R(2), // | 4373 B(Star), R(2), // |
| 4368 B(LdaZero), // | 4374 B(LdaZero), // |
| 4369 B(Star), R(1), // | 4375 B(Star), R(1), // |
| 4370 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // | 4376 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4371 /* */ R(0), U8(0), // | 4377 /* */ R(0), U8(0), // |
| 4372 B(Star), R(3), // | 4378 B(Star), R(3), // |
| 4373 B(LdaSmi8), U8(3), // | 4379 B(LdaSmi8), U8(3), // |
| 4374 B(Star), R(0), // | 4380 B(Star), R(0), // |
| 4375 B(CallRuntime), U16(Runtime::kInterpreterSetPendingMessage), // | 4381 B(CallRuntime), U16(Runtime::kInterpreterSetPendingMessage), // |
| 4376 /* */ R(3), U8(1), // | 4382 /* */ R(3), U8(1), // |
| 4377 B(LdaZero), // | 4383 B(LdaZero), // |
| 4378 B(TestEqualStrict), R(1), // | 4384 B(TestEqualStrict), R(1), // |
| 4379 B(JumpIfTrue), U8(4), // | 4385 B(JumpIfTrue), U8(4), // |
| 4380 B(Jump), U8(5), // | 4386 B(Jump), U8(5), // |
| 4381 B(Ldar), R(2), // | 4387 B(Ldar), R(2), // |
| 4382 B(ReThrow), // | 4388 B(ReThrow), // |
| 4383 B(LdaUndefined), // | 4389 B(LdaUndefined), // |
| 4384 B(Return), // | 4390 B(Return), // |
| 4385 }, | 4391 }, |
| 4386 0, | 4392 0, |
| 4387 {}, | 4393 {}, |
| 4388 1, | 4394 1, |
| 4389 {{4, 8, 14}}}, | 4395 {{7, 11, 17}}}, |
| 4390 {"var a = 1; try { a = 2; } catch(e) { a = 20 } finally { a = 3; }", | 4396 {"var a = 1; try { a = 2; } catch(e) { a = 20 } finally { a = 3; }", |
| 4391 9 * kPointerSize, | 4397 9 * kPointerSize, |
| 4392 1, | 4398 1, |
| 4393 81, | 4399 87, |
| 4394 { | 4400 { |
| 4395 B(LdaSmi8), U8(1), // | 4401 B(LdaSmi8), U8(1), // |
| 4396 B(Star), R(0), // | 4402 B(Star), R(0), // |
| 4403 B(Mov), R(context), R(4), // |
| 4404 B(Mov), R(context), R(5), // |
| 4397 B(LdaSmi8), U8(2), // | 4405 B(LdaSmi8), U8(2), // |
| 4398 B(Star), R(0), // | 4406 B(Star), R(0), // |
| 4399 B(Jump), U8(34), // | 4407 B(Jump), U8(34), // |
| 4400 B(Star), R(7), // | 4408 B(Star), R(7), // |
| 4401 B(LdaConstant), U8(0), // | 4409 B(LdaConstant), U8(0), // |
| 4402 B(Star), R(6), // | 4410 B(Star), R(6), // |
| 4403 B(Ldar), R(closure), // | 4411 B(Ldar), R(closure), // |
| 4404 B(Star), R(8), // | 4412 B(Star), R(8), // |
| 4405 B(CallRuntime), U16(Runtime::kPushCatchContext), R(6), U8(3), // | 4413 B(CallRuntime), U16(Runtime::kPushCatchContext), R(6), U8(3), // |
| 4406 B(Star), R(5), // | 4414 B(Star), R(5), // |
| (...skipping 22 matching lines...) Expand all Loading... |
| 4429 B(JumpIfTrue), U8(4), // | 4437 B(JumpIfTrue), U8(4), // |
| 4430 B(Jump), U8(5), // | 4438 B(Jump), U8(5), // |
| 4431 B(Ldar), R(3), // | 4439 B(Ldar), R(3), // |
| 4432 B(ReThrow), // | 4440 B(ReThrow), // |
| 4433 B(LdaUndefined), // | 4441 B(LdaUndefined), // |
| 4434 B(Return), // | 4442 B(Return), // |
| 4435 }, | 4443 }, |
| 4436 1, | 4444 1, |
| 4437 {"e"}, | 4445 {"e"}, |
| 4438 2, | 4446 2, |
| 4439 {{4, 42, 48}, {4, 8, 10}}}, | 4447 {{7, 48, 54}, {10, 14, 16}}}, |
| 4440 {"var a; try {" | 4448 {"var a; try {" |
| 4441 " try { a = 1 } catch(e) { a = 2 }" | 4449 " try { a = 1 } catch(e) { a = 2 }" |
| 4442 "} catch(e) { a = 20 } finally { a = 3; }", | 4450 "} catch(e) { a = 20 } finally { a = 3; }", |
| 4443 10 * kPointerSize, | 4451 10 * kPointerSize, |
| 4444 1, | 4452 1, |
| 4445 111, | 4453 120, |
| 4446 { | 4454 { |
| 4455 B(Mov), R(context), R(4), // |
| 4456 B(Mov), R(context), R(5), // |
| 4457 B(Mov), R(context), R(6), // |
| 4447 B(LdaSmi8), U8(1), // | 4458 B(LdaSmi8), U8(1), // |
| 4448 B(Star), R(0), // | 4459 B(Star), R(0), // |
| 4449 B(Jump), U8(34), // | 4460 B(Jump), U8(34), // |
| 4450 B(Star), R(8), // | 4461 B(Star), R(8), // |
| 4451 B(LdaConstant), U8(0), // | 4462 B(LdaConstant), U8(0), // |
| 4452 B(Star), R(7), // | 4463 B(Star), R(7), // |
| 4453 B(Ldar), R(closure), // | 4464 B(Ldar), R(closure), // |
| 4454 B(Star), R(9), // | 4465 B(Star), R(9), // |
| 4455 B(CallRuntime), U16(Runtime::kPushCatchContext), R(7), U8(3), // | 4466 B(CallRuntime), U16(Runtime::kPushCatchContext), R(7), U8(3), // |
| 4456 B(Star), R(6), // | 4467 B(Star), R(6), // |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4494 B(JumpIfTrue), U8(4), // | 4505 B(JumpIfTrue), U8(4), // |
| 4495 B(Jump), U8(5), // | 4506 B(Jump), U8(5), // |
| 4496 B(Ldar), R(3), // | 4507 B(Ldar), R(3), // |
| 4497 B(ReThrow), // | 4508 B(ReThrow), // |
| 4498 B(LdaUndefined), // | 4509 B(LdaUndefined), // |
| 4499 B(Return), // | 4510 B(Return), // |
| 4500 }, | 4511 }, |
| 4501 1, | 4512 1, |
| 4502 {"e"}, | 4513 {"e"}, |
| 4503 3, | 4514 3, |
| 4504 {{0, 72, 78}, {0, 38, 40}, {0, 4, 6}}}, | 4515 {{3, 81, 87}, {6, 47, 49}, {9, 13, 15}}}, |
| 4505 }; | 4516 }; |
| 4506 | 4517 |
| 4507 for (size_t i = 0; i < arraysize(snippets); i++) { | 4518 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 4508 Handle<BytecodeArray> bytecode_array = | 4519 Handle<BytecodeArray> bytecode_array = |
| 4509 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 4520 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 4510 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4521 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4511 } | 4522 } |
| 4512 } | 4523 } |
| 4513 | 4524 |
| 4514 | 4525 |
| (...skipping 3225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7740 for (size_t i = 0; i < arraysize(snippets); i++) { | 7751 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 7741 Handle<BytecodeArray> bytecode_array = | 7752 Handle<BytecodeArray> bytecode_array = |
| 7742 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 7753 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 7743 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 7754 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 7744 } | 7755 } |
| 7745 } | 7756 } |
| 7746 | 7757 |
| 7747 } // namespace interpreter | 7758 } // namespace interpreter |
| 7748 } // namespace internal | 7759 } // namespace internal |
| 7749 } // namespace v8 | 7760 } // namespace v8 |
| OLD | NEW |