| 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 4248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | 4264 |
| 4265 ExpectedSnippet<const char*> snippets[] = { | 4265 ExpectedSnippet<const char*> snippets[] = { |
| 4266 {"try { return 1; } catch(e) { return 2; }", | 4266 {"try { return 1; } catch(e) { return 2; }", |
| 4267 5 * kPointerSize, | 4267 5 * kPointerSize, |
| 4268 1, | 4268 1, |
| 4269 27, | 4269 36, |
| 4270 { | 4270 { |
| 4271 B(LdaSmi8), U8(1), // | 4271 B(LdaSmi8), U8(1), // |
| 4272 B(Return), // | 4272 B(Return), // |
| 4273 B(Star), R(3), // | 4273 B(Star), R(3), // |
| 4274 B(LdaConstant), U8(0), // | 4274 B(LdaConstant), U8(0), // |
| 4275 B(Star), R(2), // | 4275 B(Star), R(2), // |
| 4276 B(Ldar), R(closure), // | 4276 B(Ldar), R(closure), // |
| 4277 B(Star), R(4), // | 4277 B(Star), R(4), // |
| 4278 B(CallRuntime), U16(Runtime::kPushCatchContext), R(2), U8(3), // | 4278 B(CallRuntime), U16(Runtime::kPushCatchContext), R(2), U8(3), // |
| 4279 B(PushContext), R(0), // | 4279 B(Star), R(1), // |
| 4280 B(LdaSmi8), U8(2), // | 4280 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4281 B(PopContext), R(0), // | 4281 /* */ R(0), U8(0), // |
| 4282 B(Return), // | 4282 B(Ldar), R(1), // |
| 4283 B(PushContext), R(0), // |
| 4284 B(LdaSmi8), U8(2), // |
| 4285 B(PopContext), R(0), // |
| 4286 B(Return), // |
| 4283 // TODO(mstarzinger): Potential optimization, elide next bytes. | 4287 // TODO(mstarzinger): Potential optimization, elide next bytes. |
| 4284 B(LdaUndefined), // | 4288 B(LdaUndefined), // |
| 4285 B(Return), // | 4289 B(Return), // |
| 4286 }, | 4290 }, |
| 4287 1, | 4291 1, |
| 4288 {"e"}, | 4292 {"e"}, |
| 4289 1, | 4293 1, |
| 4290 {{0, 3, 3}}}, | 4294 {{0, 3, 3}}}, |
| 4291 {"var a; try { a = 1 } catch(e1) {}; try { a = 2 } catch(e2) { a = 3 }", | 4295 {"var a; try { a = 1 } catch(e1) {}; try { a = 2 } catch(e2) { a = 3 }", |
| 4292 6 * kPointerSize, | 4296 6 * kPointerSize, |
| 4293 1, | 4297 1, |
| 4294 56, | 4298 74, |
| 4295 { | 4299 { |
| 4296 B(LdaSmi8), U8(1), // | 4300 B(LdaSmi8), U8(1), // |
| 4297 B(Star), R(0), // | 4301 B(Star), R(0), // |
| 4298 B(Jump), U8(21), // | 4302 B(Jump), U8(30), // |
| 4299 B(Star), R(4), // | 4303 B(Star), R(4), // |
| 4300 B(LdaConstant), U8(0), // | 4304 B(LdaConstant), U8(0), // |
| 4301 B(Star), R(3), // | 4305 B(Star), R(3), // |
| 4302 B(Ldar), R(closure), // | 4306 B(Ldar), R(closure), // |
| 4303 B(Star), R(5), // | 4307 B(Star), R(5), // |
| 4304 B(CallRuntime), U16(Runtime::kPushCatchContext), R(3), U8(3), // | 4308 B(CallRuntime), U16(Runtime::kPushCatchContext), R(3), U8(3), // |
| 4305 B(PushContext), R(1), // | 4309 B(Star), R(2), // |
| 4306 B(PopContext), R(1), // | 4310 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4307 B(LdaSmi8), U8(2), // | 4311 /* */ R(0), U8(0), // |
| 4308 B(Star), R(0), // | 4312 B(Ldar), R(2), // |
| 4309 B(Jump), U8(25), // | 4313 B(PushContext), R(1), // |
| 4310 B(Star), R(4), // | 4314 B(PopContext), R(1), // |
| 4311 B(LdaConstant), U8(1), // | 4315 B(LdaSmi8), U8(2), // |
| 4312 B(Star), R(3), // | 4316 B(Star), R(0), // |
| 4313 B(Ldar), R(closure), // | 4317 B(Jump), U8(34), // |
| 4314 B(Star), R(5), // | 4318 B(Star), R(4), // |
| 4315 B(CallRuntime), U16(Runtime::kPushCatchContext), R(3), U8(3), // | 4319 B(LdaConstant), U8(1), // |
| 4316 B(PushContext), R(1), // | 4320 B(Star), R(3), // |
| 4317 B(LdaSmi8), U8(3), // | 4321 B(Ldar), R(closure), // |
| 4318 B(Star), R(0), // | 4322 B(Star), R(5), // |
| 4319 B(PopContext), R(1), // | 4323 B(CallRuntime), U16(Runtime::kPushCatchContext), R(3), U8(3), // |
| 4320 B(LdaUndefined), // | 4324 B(Star), R(2), // |
| 4321 B(Return), // | 4325 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4326 /* */ R(0), U8(0), // |
| 4327 B(Ldar), R(2), // |
| 4328 B(PushContext), R(1), // |
| 4329 B(LdaSmi8), U8(3), // |
| 4330 B(Star), R(0), // |
| 4331 B(PopContext), R(1), // |
| 4332 B(LdaUndefined), // |
| 4333 B(Return), // |
| 4322 }, | 4334 }, |
| 4323 2, | 4335 2, |
| 4324 {"e1", "e2"}, | 4336 {"e1", "e2"}, |
| 4325 2, | 4337 2, |
| 4326 {{0, 4, 6}, {25, 29, 31}}}, | 4338 {{0, 4, 6}, {34, 38, 40}}}, |
| 4327 }; | 4339 }; |
| 4328 | 4340 |
| 4329 for (size_t i = 0; i < arraysize(snippets); i++) { | 4341 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 4330 Handle<BytecodeArray> bytecode_array = | 4342 Handle<BytecodeArray> bytecode_array = |
| 4331 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 4343 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 4332 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4344 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4333 } | 4345 } |
| 4334 } | 4346 } |
| 4335 | 4347 |
| 4336 | 4348 |
| 4337 TEST(TryFinally) { | 4349 TEST(TryFinally) { |
| 4338 InitializedHandleScope handle_scope; | 4350 InitializedHandleScope handle_scope; |
| 4339 BytecodeGeneratorHelper helper; | 4351 BytecodeGeneratorHelper helper; |
| 4340 | 4352 |
| 4341 int closure = Register::function_closure().index(); | 4353 int closure = Register::function_closure().index(); |
| 4342 | 4354 |
| 4343 ExpectedSnippet<const char*> snippets[] = { | 4355 ExpectedSnippet<const char*> snippets[] = { |
| 4344 {"var a = 1; try { a = 2; } finally { a = 3; }", | 4356 {"var a = 1; try { a = 2; } finally { a = 3; }", |
| 4345 4 * kPointerSize, | 4357 4 * kPointerSize, |
| 4346 1, | 4358 1, |
| 4347 35, | 4359 52, |
| 4348 { | 4360 { |
| 4349 B(LdaSmi8), U8(1), // | 4361 B(LdaSmi8), U8(1), // |
| 4350 B(Star), R(0), // | 4362 B(Star), R(0), // |
| 4351 B(LdaSmi8), U8(2), // | 4363 B(LdaSmi8), U8(2), // |
| 4352 B(Star), R(0), // | 4364 B(Star), R(0), // |
| 4353 B(LdaSmi8), U8(-1), // | 4365 B(LdaSmi8), U8(-1), // |
| 4354 B(Star), R(1), // | 4366 B(Star), R(1), // |
| 4355 B(Jump), U8(7), // | 4367 B(Jump), U8(7), // |
| 4356 B(Star), R(2), // | 4368 B(Star), R(2), // |
| 4357 B(LdaZero), // | 4369 B(LdaZero), // |
| 4358 B(Star), R(1), // | 4370 B(Star), R(1), // |
| 4359 B(LdaSmi8), U8(3), // | 4371 B(CallRuntime), U16(Runtime::kInterpreterGetPendingMessage), // |
| 4360 B(Star), R(0), // | 4372 /* */ R(0), U8(0), // |
| 4361 B(LdaZero), // | 4373 B(Star), R(3), // |
| 4362 B(TestEqualStrict), R(1), // | 4374 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4363 B(JumpIfTrue), U8(4), // | 4375 /* */ R(0), U8(0), // |
| 4364 B(Jump), U8(5), // | 4376 B(LdaSmi8), U8(3), // |
| 4365 B(Ldar), R(2), // | 4377 B(Star), R(0), // |
| 4366 B(ReThrow), // | 4378 B(CallRuntime), U16(Runtime::kInterpreterSetPendingMessage), // |
| 4367 B(LdaUndefined), // | 4379 /* */ R(3), U8(1), // |
| 4368 B(Return), // | 4380 B(LdaZero), // |
| 4381 B(TestEqualStrict), R(1), // |
| 4382 B(JumpIfTrue), U8(4), // |
| 4383 B(Jump), U8(5), // |
| 4384 B(Ldar), R(2), // |
| 4385 B(ReThrow), // |
| 4386 B(LdaUndefined), // |
| 4387 B(Return), // |
| 4369 }, | 4388 }, |
| 4370 0, | 4389 0, |
| 4371 {}, | 4390 {}, |
| 4372 1, | 4391 1, |
| 4373 {{4, 8, 14}}}, | 4392 {{4, 8, 14}}}, |
| 4374 {"var a = 1; try { a = 2; } catch(e) { a = 20 } finally { a = 3; }", | 4393 {"var a = 1; try { a = 2; } catch(e) { a = 20 } finally { a = 3; }", |
| 4375 9 * kPointerSize, | 4394 9 * kPointerSize, |
| 4376 1, | 4395 1, |
| 4377 60, | 4396 86, |
| 4378 { | 4397 { |
| 4379 B(LdaSmi8), U8(1), // | 4398 B(LdaSmi8), U8(1), // |
| 4380 B(Star), R(0), // | 4399 B(Star), R(0), // |
| 4381 B(LdaSmi8), U8(2), // | 4400 B(LdaSmi8), U8(2), // |
| 4382 B(Star), R(0), // | 4401 B(Star), R(0), // |
| 4383 B(Jump), U8(25), // | 4402 B(Jump), U8(34), // |
| 4384 B(Star), R(7), // | 4403 B(Star), R(7), // |
| 4385 B(LdaConstant), U8(0), // | 4404 B(LdaConstant), U8(0), // |
| 4386 B(Star), R(6), // | 4405 B(Star), R(6), // |
| 4387 B(Ldar), R(closure), // | 4406 B(Ldar), R(closure), // |
| 4388 B(Star), R(8), // | 4407 B(Star), R(8), // |
| 4389 B(CallRuntime), U16(Runtime::kPushCatchContext), R(6), U8(3), // | 4408 B(CallRuntime), U16(Runtime::kPushCatchContext), R(6), U8(3), // |
| 4390 B(PushContext), R(1), // | 4409 B(Star), R(5), // |
| 4391 B(LdaSmi8), U8(20), // | 4410 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4392 B(Star), R(0), // | 4411 /* */ R(0), U8(0), // |
| 4393 B(PopContext), R(1), // | 4412 B(Ldar), R(5), // |
| 4394 B(LdaSmi8), U8(-1), // | 4413 B(PushContext), R(1), // |
| 4395 B(Star), R(2), // | 4414 B(LdaSmi8), U8(20), // |
| 4396 B(Jump), U8(7), // | 4415 B(Star), R(0), // |
| 4397 B(Star), R(3), // | 4416 B(PopContext), R(1), // |
| 4398 B(LdaZero), // | 4417 B(LdaSmi8), U8(-1), // |
| 4399 B(Star), R(2), // | 4418 B(Star), R(2), // |
| 4400 B(LdaSmi8), U8(3), // | 4419 B(Jump), U8(7), // |
| 4401 B(Star), R(0), // | 4420 B(Star), R(3), // |
| 4402 B(LdaZero), // | 4421 B(LdaZero), // |
| 4403 B(TestEqualStrict), R(2), // | 4422 B(Star), R(2), // |
| 4404 B(JumpIfTrue), U8(4), // | 4423 B(CallRuntime), U16(Runtime::kInterpreterGetPendingMessage), // |
| 4405 B(Jump), U8(5), // | 4424 /* */ R(0), U8(0), // |
| 4406 B(Ldar), R(3), // | 4425 B(Star), R(4), // |
| 4407 B(ReThrow), // | 4426 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4408 B(LdaUndefined), // | 4427 /* */ R(0), U8(0), // |
| 4409 B(Return), // | 4428 B(LdaSmi8), U8(3), // |
| 4429 B(Star), R(0), // |
| 4430 B(CallRuntime), U16(Runtime::kInterpreterSetPendingMessage), // |
| 4431 /* */ R(4), U8(1), // |
| 4432 B(LdaZero), // |
| 4433 B(TestEqualStrict), R(2), // |
| 4434 B(JumpIfTrue), U8(4), // |
| 4435 B(Jump), U8(5), // |
| 4436 B(Ldar), R(3), // |
| 4437 B(ReThrow), // |
| 4438 B(LdaUndefined), // |
| 4439 B(Return), // |
| 4410 }, | 4440 }, |
| 4411 1, | 4441 1, |
| 4412 {"e"}, | 4442 {"e"}, |
| 4413 2, | 4443 2, |
| 4414 {{4, 33, 39}, {4, 8, 10}}}, | 4444 {{4, 42, 48}, {4, 8, 10}}}, |
| 4415 {"var a; try {" | 4445 {"var a; try {" |
| 4416 " try { a = 1 } catch(e) { a = 2 }" | 4446 " try { a = 1 } catch(e) { a = 2 }" |
| 4417 "} catch(e) { a = 20 } finally { a = 3; }", | 4447 "} catch(e) { a = 20 } finally { a = 3; }", |
| 4418 10 * kPointerSize, | 4448 10 * kPointerSize, |
| 4419 1, | 4449 1, |
| 4420 81, | 4450 116, |
| 4421 { | 4451 { |
| 4422 B(LdaSmi8), U8(1), // | 4452 B(LdaSmi8), U8(1), // |
| 4423 B(Star), R(0), // | 4453 B(Star), R(0), // |
| 4424 B(Jump), U8(25), // | 4454 B(Jump), U8(34), // |
| 4425 B(Star), R(8), // | 4455 B(Star), R(8), // |
| 4426 B(LdaConstant), U8(0), // | 4456 B(LdaConstant), U8(0), // |
| 4427 B(Star), R(7), // | 4457 B(Star), R(7), // |
| 4428 B(Ldar), R(closure), // | 4458 B(Ldar), R(closure), // |
| 4429 B(Star), R(9), // | 4459 B(Star), R(9), // |
| 4430 B(CallRuntime), U16(Runtime::kPushCatchContext), R(7), U8(3), // | 4460 B(CallRuntime), U16(Runtime::kPushCatchContext), R(7), U8(3), // |
| 4431 B(PushContext), R(1), // | 4461 B(Star), R(6), // |
| 4432 B(LdaSmi8), U8(2), // | 4462 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4433 B(Star), R(0), // | 4463 /* */ R(0), U8(0), // |
| 4434 B(PopContext), R(1), // | 4464 B(Ldar), R(6), // |
| 4435 B(Jump), U8(25), // | 4465 B(PushContext), R(1), // |
| 4436 B(Star), R(7), // | 4466 B(LdaSmi8), U8(2), // |
| 4437 B(LdaConstant), U8(0), // | 4467 B(Star), R(0), // |
| 4438 B(Star), R(6), // | 4468 B(PopContext), R(1), // |
| 4439 B(Ldar), R(closure), // | 4469 B(Jump), U8(34), // |
| 4440 B(Star), R(8), // | 4470 B(Star), R(7), // |
| 4441 B(CallRuntime), U16(Runtime::kPushCatchContext), R(6), U8(3), // | 4471 B(LdaConstant), U8(0), // |
| 4442 B(PushContext), R(1), // | 4472 B(Star), R(6), // |
| 4443 B(LdaSmi8), U8(20), // | 4473 B(Ldar), R(closure), // |
| 4444 B(Star), R(0), // | 4474 B(Star), R(8), // |
| 4445 B(PopContext), R(1), // | 4475 B(CallRuntime), U16(Runtime::kPushCatchContext), R(6), U8(3), // |
| 4446 B(LdaSmi8), U8(-1), // | 4476 B(Star), R(5), // |
| 4447 B(Star), R(2), // | 4477 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4448 B(Jump), U8(7), // | 4478 /* */ R(0), U8(0), // |
| 4449 B(Star), R(3), // | 4479 B(Ldar), R(5), // |
| 4450 B(LdaZero), // | 4480 B(PushContext), R(1), // |
| 4451 B(Star), R(2), // | 4481 B(LdaSmi8), U8(20), // |
| 4452 B(LdaSmi8), U8(3), // | 4482 B(Star), R(0), // |
| 4453 B(Star), R(0), // | 4483 B(PopContext), R(1), // |
| 4454 B(LdaZero), // | 4484 B(LdaSmi8), U8(-1), // |
| 4455 B(TestEqualStrict), R(2), // | 4485 B(Star), R(2), // |
| 4456 B(JumpIfTrue), U8(4), // | 4486 B(Jump), U8(7), // |
| 4457 B(Jump), U8(5), // | 4487 B(Star), R(3), // |
| 4458 B(Ldar), R(3), // | 4488 B(LdaZero), // |
| 4459 B(ReThrow), // | 4489 B(Star), R(2), // |
| 4460 B(LdaUndefined), // | 4490 B(CallRuntime), U16(Runtime::kInterpreterGetPendingMessage), // |
| 4461 B(Return), // | 4491 /* */ R(0), U8(0), // |
| 4492 B(Star), R(4), // |
| 4493 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4494 /* */ R(0), U8(0), // |
| 4495 B(LdaSmi8), U8(3), // |
| 4496 B(Star), R(0), // |
| 4497 B(CallRuntime), U16(Runtime::kInterpreterSetPendingMessage), // |
| 4498 /* */ R(4), U8(1), // |
| 4499 B(LdaZero), // |
| 4500 B(TestEqualStrict), R(2), // |
| 4501 B(JumpIfTrue), U8(4), // |
| 4502 B(Jump), U8(5), // |
| 4503 B(Ldar), R(3), // |
| 4504 B(ReThrow), // |
| 4505 B(LdaUndefined), // |
| 4506 B(Return), // |
| 4462 }, | 4507 }, |
| 4463 1, | 4508 1, |
| 4464 {"e"}, | 4509 {"e"}, |
| 4465 3, | 4510 3, |
| 4466 {{0, 54, 60}, {0, 29, 31}, {0, 4, 6}}}, | 4511 {{0, 72, 78}, {0, 38, 40}, {0, 4, 6}}}, |
| 4467 }; | 4512 }; |
| 4468 | 4513 |
| 4469 for (size_t i = 0; i < arraysize(snippets); i++) { | 4514 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 4470 Handle<BytecodeArray> bytecode_array = | 4515 Handle<BytecodeArray> bytecode_array = |
| 4471 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 4516 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 4472 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4517 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4473 } | 4518 } |
| 4474 } | 4519 } |
| 4475 | 4520 |
| 4476 | 4521 |
| (...skipping 3082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7559 Handle<BytecodeArray> bytecode_array = | 7604 Handle<BytecodeArray> bytecode_array = |
| 7560 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 7605 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 7561 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 7606 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 7562 } | 7607 } |
| 7563 FLAG_harmony_do_expressions = old_flag; | 7608 FLAG_harmony_do_expressions = old_flag; |
| 7564 } | 7609 } |
| 7565 | 7610 |
| 7566 } // namespace interpreter | 7611 } // namespace interpreter |
| 7567 } // namespace internal | 7612 } // namespace internal |
| 7568 } // namespace v8 | 7613 } // namespace v8 |
| OLD | NEW |