OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 { PresentPropertyContext context; | 278 { PresentPropertyContext context; |
279 context.Check("function x() { }; x", | 279 context.Check("function x() { }; x", |
280 1, // access | 280 1, // access |
281 0, | 281 0, |
282 0, | 282 0, |
283 EXPECT_RESULT); | 283 EXPECT_RESULT); |
284 } | 284 } |
285 | 285 |
286 { PresentPropertyContext context; | 286 { PresentPropertyContext context; |
287 context.Check("const x; x", | 287 context.Check("const x; x", |
288 1, // access | |
289 0, | 288 0, |
290 2, // (re-)declaration + initialization | 289 0, |
291 EXPECT_EXCEPTION); // x is not defined! | 290 1, // (re-)declaration |
| 291 EXPECT_EXCEPTION); // x has already been declared! |
292 } | 292 } |
293 | 293 |
294 { PresentPropertyContext context; | 294 { PresentPropertyContext context; |
295 context.Check("const x = 0; x", | 295 context.Check("const x = 0; x", |
296 1, // access | |
297 0, | 296 0, |
298 2, // (re-)declaration + initialization | 297 0, |
299 EXPECT_EXCEPTION); // x is not defined! | 298 1, // (re-)declaration |
| 299 EXPECT_EXCEPTION); // x has already been declared! |
300 } | 300 } |
301 } | 301 } |
302 | 302 |
303 | 303 |
304 | 304 |
305 class AbsentPropertyContext: public DeclarationContext { | 305 class AbsentPropertyContext: public DeclarationContext { |
306 protected: | 306 protected: |
307 virtual v8::Handle<Integer> Query(Local<String> key) { | 307 virtual v8::Handle<Integer> Query(Local<String> key) { |
308 return v8::Handle<Integer>(); | 308 return v8::Handle<Integer>(); |
309 } | 309 } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 { AppearingPropertyContext context; | 422 { AppearingPropertyContext context; |
423 context.Check("function x() { }; x", | 423 context.Check("function x() { }; x", |
424 1, // access | 424 1, // access |
425 0, | 425 0, |
426 0, | 426 0, |
427 EXPECT_RESULT); | 427 EXPECT_RESULT); |
428 } | 428 } |
429 | 429 |
430 { AppearingPropertyContext context; | 430 { AppearingPropertyContext context; |
431 context.Check("const x; x", | 431 context.Check("const x; x", |
432 1, // access | 432 0, |
433 1, // declaration | 433 1, // declaration |
434 2, // declaration + initialization | 434 2, // declaration + initialization |
435 EXPECT_RESULT, Undefined()); | 435 EXPECT_EXCEPTION); // x has already been declared! |
436 } | 436 } |
437 | 437 |
438 { AppearingPropertyContext context; | 438 { AppearingPropertyContext context; |
439 context.Check("const x = 0; x", | 439 context.Check("const x = 0; x", |
440 1, // access | 440 0, |
441 1, // declaration | 441 1, // declaration |
442 2, // declaration + initialization | 442 2, // declaration + initialization |
443 EXPECT_RESULT, Undefined()); | 443 EXPECT_EXCEPTION); // x has already been declared! |
444 // Result is undefined because declaration succeeded but | |
445 // initialization to 0 failed (due to context behavior). | |
446 } | 444 } |
447 } | 445 } |
448 | 446 |
449 | 447 |
450 | 448 |
451 class ReappearingPropertyContext: public DeclarationContext { | 449 class ReappearingPropertyContext: public DeclarationContext { |
452 public: | 450 public: |
453 enum State { | 451 enum State { |
454 DECLARE, | 452 DECLARE, |
455 DONT_DECLARE, | 453 DONT_DECLARE, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 State state_; | 489 State state_; |
492 }; | 490 }; |
493 | 491 |
494 | 492 |
495 TEST(Reappearing) { | 493 TEST(Reappearing) { |
496 HandleScope scope; | 494 HandleScope scope; |
497 | 495 |
498 { ReappearingPropertyContext context; | 496 { ReappearingPropertyContext context; |
499 context.Check("const x; var x = 0", | 497 context.Check("const x; var x = 0", |
500 0, | 498 0, |
501 3, // const declaration+initialization, var initialization | 499 2, // var declaration + const initialization |
502 4, // 2 x declaration + 2 x initialization | 500 4, // 2 x declaration + 2 x initialization |
503 EXPECT_RESULT, Undefined()); | 501 EXPECT_EXCEPTION); // x has already been declared! |
504 } | 502 } |
505 } | 503 } |
506 | 504 |
507 | 505 |
508 | 506 |
509 class ExistsInPrototypeContext: public DeclarationContext { | 507 class ExistsInPrototypeContext: public DeclarationContext { |
510 protected: | 508 protected: |
511 virtual v8::Handle<Integer> Query(Local<String> key) { | 509 virtual v8::Handle<Integer> Query(Local<String> key) { |
512 // Let it seem that the property exists in the prototype object. | 510 // Let it seem that the property exists in the prototype object. |
513 return Integer::New(v8::None); | 511 return Integer::New(v8::None); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 HandleScope scope; | 584 HandleScope scope; |
587 | 585 |
588 { AbsentInPrototypeContext context; | 586 { AbsentInPrototypeContext context; |
589 context.Check("if (false) { var x = 0; }; x", | 587 context.Check("if (false) { var x = 0; }; x", |
590 0, | 588 0, |
591 0, | 589 0, |
592 1, // declaration | 590 1, // declaration |
593 EXPECT_RESULT, Undefined()); | 591 EXPECT_RESULT, Undefined()); |
594 } | 592 } |
595 } | 593 } |
OLD | NEW |