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