Chromium Code Reviews| 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 40, |
| 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::kInterpreterClearPendingMessage), // |
| 4360 B(Star), R(0), // | 4372 /* */ R(0), U8(0), // |
| 4361 B(LdaZero), // | 4373 B(LdaSmi8), U8(3), // |
| 4362 B(TestEqualStrict), R(1), // | 4374 B(Star), R(0), // |
| 4363 B(JumpIfTrue), U8(4), // | 4375 B(LdaZero), // |
| 4364 B(Jump), U8(5), // | 4376 B(TestEqualStrict), R(1), // |
| 4365 B(Ldar), R(2), // | 4377 B(JumpIfTrue), U8(4), // |
| 4366 B(ReThrow), // | 4378 B(Jump), U8(5), // |
| 4367 B(LdaUndefined), // | 4379 B(Ldar), R(2), // |
| 4368 B(Return), // | 4380 B(ReThrow), // |
| 4381 B(LdaUndefined), // | |
| 4382 B(Return), // | |
| 4369 }, | 4383 }, |
| 4370 0, | 4384 0, |
| 4371 {}, | 4385 {}, |
| 4372 1, | 4386 1, |
| 4373 {{4, 8, 14}}}, | 4387 {{4, 8, 14}}}, |
| 4374 {"var a = 1; try { a = 2; } catch(e) { a = 20 } finally { a = 3; }", | 4388 {"var a = 1; try { a = 2; } catch(e) { a = 20 } finally { a = 3; }", |
| 4375 9 * kPointerSize, | 4389 9 * kPointerSize, |
| 4376 1, | 4390 1, |
| 4377 60, | 4391 74, |
| 4378 { | 4392 { |
| 4379 B(LdaSmi8), U8(1), // | 4393 B(LdaSmi8), U8(1), // |
| 4380 B(Star), R(0), // | 4394 B(Star), R(0), // |
| 4381 B(LdaSmi8), U8(2), // | 4395 B(LdaSmi8), U8(2), // |
| 4382 B(Star), R(0), // | 4396 B(Star), R(0), // |
| 4383 B(Jump), U8(25), // | 4397 B(Jump), U8(34), // |
| 4384 B(Star), R(7), // | 4398 B(Star), R(7), // |
| 4385 B(LdaConstant), U8(0), // | 4399 B(LdaConstant), U8(0), // |
| 4386 B(Star), R(6), // | 4400 B(Star), R(6), // |
| 4387 B(Ldar), R(closure), // | 4401 B(Ldar), R(closure), // |
| 4388 B(Star), R(8), // | 4402 B(Star), R(8), // |
| 4389 B(CallRuntime), U16(Runtime::kPushCatchContext), R(6), U8(3), // | 4403 B(CallRuntime), U16(Runtime::kPushCatchContext), R(6), U8(3), // |
| 4390 B(PushContext), R(1), // | 4404 B(Star), R(5), // |
| 4391 B(LdaSmi8), U8(20), // | 4405 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4392 B(Star), R(0), // | 4406 /* */ R(0), U8(0), // |
| 4393 B(PopContext), R(1), // | 4407 B(Ldar), R(5), // |
| 4394 B(LdaSmi8), U8(-1), // | 4408 B(PushContext), R(1), // |
| 4395 B(Star), R(2), // | 4409 B(LdaSmi8), U8(20), // |
| 4396 B(Jump), U8(7), // | 4410 B(Star), R(0), // |
| 4397 B(Star), R(3), // | 4411 B(PopContext), R(1), // |
| 4398 B(LdaZero), // | 4412 B(LdaSmi8), U8(-1), // |
| 4399 B(Star), R(2), // | 4413 B(Star), R(2), // |
| 4400 B(LdaSmi8), U8(3), // | 4414 B(Jump), U8(7), // |
| 4401 B(Star), R(0), // | 4415 B(Star), R(3), // |
| 4402 B(LdaZero), // | 4416 B(LdaZero), // |
| 4403 B(TestEqualStrict), R(2), // | 4417 B(Star), R(2), // |
| 4404 B(JumpIfTrue), U8(4), // | 4418 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4405 B(Jump), U8(5), // | 4419 /* */ R(0), U8(0), // |
| 4406 B(Ldar), R(3), // | 4420 B(LdaSmi8), U8(3), // |
| 4407 B(ReThrow), // | 4421 B(Star), R(0), // |
| 4408 B(LdaUndefined), // | 4422 B(LdaZero), // |
| 4409 B(Return), // | 4423 B(TestEqualStrict), R(2), // |
| 4424 B(JumpIfTrue), U8(4), // | |
| 4425 B(Jump), U8(5), // | |
| 4426 B(Ldar), R(3), // | |
| 4427 B(ReThrow), // | |
| 4428 B(LdaUndefined), // | |
| 4429 B(Return), // | |
| 4410 }, | 4430 }, |
| 4411 1, | 4431 1, |
| 4412 {"e"}, | 4432 {"e"}, |
| 4413 2, | 4433 2, |
| 4414 {{4, 33, 39}, {4, 8, 10}}}, | 4434 {{4, 42, 48}, {4, 8, 10}}}, |
| 4415 {"var a; try {" | 4435 {"var a; try {" |
| 4416 " try { a = 1 } catch(e) { a = 2 }" | 4436 " try { a = 1 } catch(e) { a = 2 }" |
| 4417 "} catch(e) { a = 20 } finally { a = 3; }", | 4437 "} catch(e) { a = 20 } finally { a = 3; }", |
| 4418 10 * kPointerSize, | 4438 10 * kPointerSize, |
| 4419 1, | 4439 1, |
| 4420 81, | 4440 104, |
| 4421 { | 4441 { |
| 4422 B(LdaSmi8), U8(1), // | 4442 B(LdaSmi8), U8(1), // |
| 4423 B(Star), R(0), // | 4443 B(Star), R(0), // |
| 4424 B(Jump), U8(25), // | 4444 B(Jump), U8(34), // |
| 4425 B(Star), R(8), // | 4445 B(Star), R(8), // |
| 4426 B(LdaConstant), U8(0), // | 4446 B(LdaConstant), U8(0), // |
| 4427 B(Star), R(7), // | 4447 B(Star), R(7), // |
| 4428 B(Ldar), R(closure), // | 4448 B(Ldar), R(closure), // |
| 4429 B(Star), R(9), // | 4449 B(Star), R(9), // |
| 4430 B(CallRuntime), U16(Runtime::kPushCatchContext), R(7), U8(3), // | 4450 B(CallRuntime), U16(Runtime::kPushCatchContext), R(7), U8(3), // |
| 4431 B(PushContext), R(1), // | 4451 B(Star), R(6), // |
| 4432 B(LdaSmi8), U8(2), // | 4452 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4433 B(Star), R(0), // | 4453 /* */ R(0), U8(0), // |
|
rmcilroy
2016/02/01 14:21:46
Nice hack for git cl format - I'll need to remembe
| |
| 4434 B(PopContext), R(1), // | 4454 B(Ldar), R(6), // |
| 4435 B(Jump), U8(25), // | 4455 B(PushContext), R(1), // |
| 4436 B(Star), R(7), // | 4456 B(LdaSmi8), U8(2), // |
| 4437 B(LdaConstant), U8(0), // | 4457 B(Star), R(0), // |
| 4438 B(Star), R(6), // | 4458 B(PopContext), R(1), // |
| 4439 B(Ldar), R(closure), // | 4459 B(Jump), U8(34), // |
| 4440 B(Star), R(8), // | 4460 B(Star), R(7), // |
| 4441 B(CallRuntime), U16(Runtime::kPushCatchContext), R(6), U8(3), // | 4461 B(LdaConstant), U8(0), // |
| 4442 B(PushContext), R(1), // | 4462 B(Star), R(6), // |
| 4443 B(LdaSmi8), U8(20), // | 4463 B(Ldar), R(closure), // |
| 4444 B(Star), R(0), // | 4464 B(Star), R(8), // |
| 4445 B(PopContext), R(1), // | 4465 B(CallRuntime), U16(Runtime::kPushCatchContext), R(6), U8(3), // |
| 4446 B(LdaSmi8), U8(-1), // | 4466 B(Star), R(5), // |
| 4447 B(Star), R(2), // | 4467 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4448 B(Jump), U8(7), // | 4468 /* */ R(0), U8(0), // |
| 4449 B(Star), R(3), // | 4469 B(Ldar), R(5), // |
| 4450 B(LdaZero), // | 4470 B(PushContext), R(1), // |
| 4451 B(Star), R(2), // | 4471 B(LdaSmi8), U8(20), // |
| 4452 B(LdaSmi8), U8(3), // | 4472 B(Star), R(0), // |
| 4453 B(Star), R(0), // | 4473 B(PopContext), R(1), // |
| 4454 B(LdaZero), // | 4474 B(LdaSmi8), U8(-1), // |
| 4455 B(TestEqualStrict), R(2), // | 4475 B(Star), R(2), // |
| 4456 B(JumpIfTrue), U8(4), // | 4476 B(Jump), U8(7), // |
| 4457 B(Jump), U8(5), // | 4477 B(Star), R(3), // |
| 4458 B(Ldar), R(3), // | 4478 B(LdaZero), // |
| 4459 B(ReThrow), // | 4479 B(Star), R(2), // |
| 4460 B(LdaUndefined), // | 4480 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4461 B(Return), // | 4481 /* */ R(0), U8(0), // |
| 4482 B(LdaSmi8), U8(3), // | |
| 4483 B(Star), R(0), // | |
| 4484 B(LdaZero), // | |
| 4485 B(TestEqualStrict), R(2), // | |
| 4486 B(JumpIfTrue), U8(4), // | |
| 4487 B(Jump), U8(5), // | |
| 4488 B(Ldar), R(3), // | |
| 4489 B(ReThrow), // | |
| 4490 B(LdaUndefined), // | |
| 4491 B(Return), // | |
| 4462 }, | 4492 }, |
| 4463 1, | 4493 1, |
| 4464 {"e"}, | 4494 {"e"}, |
| 4465 3, | 4495 3, |
| 4466 {{0, 54, 60}, {0, 29, 31}, {0, 4, 6}}}, | 4496 {{0, 72, 78}, {0, 38, 40}, {0, 4, 6}}}, |
| 4467 }; | 4497 }; |
| 4468 | 4498 |
| 4469 for (size_t i = 0; i < arraysize(snippets); i++) { | 4499 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 4470 Handle<BytecodeArray> bytecode_array = | 4500 Handle<BytecodeArray> bytecode_array = |
| 4471 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 4501 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 4472 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4502 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4473 } | 4503 } |
| 4474 } | 4504 } |
| 4475 | 4505 |
| 4476 | 4506 |
| (...skipping 3082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7559 Handle<BytecodeArray> bytecode_array = | 7589 Handle<BytecodeArray> bytecode_array = |
| 7560 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 7590 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 7561 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 7591 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 7562 } | 7592 } |
| 7563 FLAG_harmony_do_expressions = old_flag; | 7593 FLAG_harmony_do_expressions = old_flag; |
| 7564 } | 7594 } |
| 7565 | 7595 |
| 7566 } // namespace interpreter | 7596 } // namespace interpreter |
| 7567 } // namespace internal | 7597 } // namespace internal |
| 7568 } // namespace v8 | 7598 } // namespace v8 |
| OLD | NEW |