| 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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 221 |
| 222 v8::Handle<Integer> DeclarationContext::Query(Local<String> key) { | 222 v8::Handle<Integer> DeclarationContext::Query(Local<String> key) { |
| 223 return v8::Handle<Integer>(); | 223 return v8::Handle<Integer>(); |
| 224 } | 224 } |
| 225 | 225 |
| 226 | 226 |
| 227 // Test global declaration of a property the interceptor doesn't know | 227 // Test global declaration of a property the interceptor doesn't know |
| 228 // about and doesn't handle. | 228 // about and doesn't handle. |
| 229 TEST(Unknown) { | 229 TEST(Unknown) { |
| 230 HandleScope scope(CcTest::isolate()); | 230 HandleScope scope(CcTest::isolate()); |
| 231 v8::V8::Initialize(); |
| 231 | 232 |
| 232 { DeclarationContext context; | 233 { DeclarationContext context; |
| 233 context.Check("var x; x", | 234 context.Check("var x; x", |
| 234 1, // access | 235 1, // access |
| 235 1, // declaration | 236 1, // declaration |
| 236 2, // declaration + initialization | 237 2, // declaration + initialization |
| 237 EXPECT_RESULT, Undefined()); | 238 EXPECT_RESULT, Undefined(CcTest::isolate())); |
| 238 } | 239 } |
| 239 | 240 |
| 240 { DeclarationContext context; | 241 { DeclarationContext context; |
| 241 context.Check("var x = 0; x", | 242 context.Check("var x = 0; x", |
| 242 1, // access | 243 1, // access |
| 243 2, // declaration + initialization | 244 2, // declaration + initialization |
| 244 2, // declaration + initialization | 245 2, // declaration + initialization |
| 245 EXPECT_RESULT, Number::New(0)); | 246 EXPECT_RESULT, Number::New(0)); |
| 246 } | 247 } |
| 247 | 248 |
| 248 { DeclarationContext context; | 249 { DeclarationContext context; |
| 249 context.Check("function x() { }; x", | 250 context.Check("function x() { }; x", |
| 250 1, // access | 251 1, // access |
| 251 0, | 252 0, |
| 252 0, | 253 0, |
| 253 EXPECT_RESULT); | 254 EXPECT_RESULT); |
| 254 } | 255 } |
| 255 | 256 |
| 256 { DeclarationContext context; | 257 { DeclarationContext context; |
| 257 context.Check("const x; x", | 258 context.Check("const x; x", |
| 258 1, // access | 259 1, // access |
| 259 2, // declaration + initialization | 260 2, // declaration + initialization |
| 260 1, // declaration | 261 1, // declaration |
| 261 EXPECT_RESULT, Undefined()); | 262 EXPECT_RESULT, Undefined(CcTest::isolate())); |
| 262 } | 263 } |
| 263 | 264 |
| 264 { DeclarationContext context; | 265 { DeclarationContext context; |
| 266 // SB 0 - BUG 1213579 |
| 265 context.Check("const x = 0; x", | 267 context.Check("const x = 0; x", |
| 266 1, // access | 268 1, // access |
| 267 2, // declaration + initialization | 269 2, // declaration + initialization |
| 268 1, // declaration | 270 1, // declaration |
| 269 EXPECT_RESULT, Undefined()); // SB 0 - BUG 1213579 | 271 EXPECT_RESULT, Undefined(CcTest::isolate())); |
| 270 } | 272 } |
| 271 } | 273 } |
| 272 | 274 |
| 273 | 275 |
| 274 | 276 |
| 275 class PresentPropertyContext: public DeclarationContext { | 277 class PresentPropertyContext: public DeclarationContext { |
| 276 protected: | 278 protected: |
| 277 virtual v8::Handle<Integer> Query(Local<String> key) { | 279 virtual v8::Handle<Integer> Query(Local<String> key) { |
| 278 return Integer::New(v8::None); | 280 return Integer::New(v8::None); |
| 279 } | 281 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 306 0, | 308 0, |
| 307 0, | 309 0, |
| 308 EXPECT_RESULT); | 310 EXPECT_RESULT); |
| 309 } | 311 } |
| 310 | 312 |
| 311 { PresentPropertyContext context; | 313 { PresentPropertyContext context; |
| 312 context.Check("const x; x", | 314 context.Check("const x; x", |
| 313 1, // access | 315 1, // access |
| 314 1, // initialization | 316 1, // initialization |
| 315 1, // (re-)declaration | 317 1, // (re-)declaration |
| 316 EXPECT_RESULT, Undefined()); | 318 EXPECT_RESULT, Undefined(CcTest::isolate())); |
| 317 } | 319 } |
| 318 | 320 |
| 319 { PresentPropertyContext context; | 321 { PresentPropertyContext context; |
| 320 context.Check("const x = 0; x", | 322 context.Check("const x = 0; x", |
| 321 1, // access | 323 1, // access |
| 322 1, // initialization | 324 1, // initialization |
| 323 1, // (re-)declaration | 325 1, // (re-)declaration |
| 324 EXPECT_RESULT, Number::New(0)); | 326 EXPECT_RESULT, Number::New(0)); |
| 325 } | 327 } |
| 326 } | 328 } |
| 327 | 329 |
| 328 | 330 |
| 329 | 331 |
| 330 class AbsentPropertyContext: public DeclarationContext { | 332 class AbsentPropertyContext: public DeclarationContext { |
| 331 protected: | 333 protected: |
| 332 virtual v8::Handle<Integer> Query(Local<String> key) { | 334 virtual v8::Handle<Integer> Query(Local<String> key) { |
| 333 return v8::Handle<Integer>(); | 335 return v8::Handle<Integer>(); |
| 334 } | 336 } |
| 335 }; | 337 }; |
| 336 | 338 |
| 337 | 339 |
| 338 TEST(Absent) { | 340 TEST(Absent) { |
| 339 HandleScope scope(CcTest::isolate()); | 341 v8::Isolate* isolate = CcTest::isolate(); |
| 342 v8::V8::Initialize(); |
| 343 HandleScope scope(isolate); |
| 340 | 344 |
| 341 { AbsentPropertyContext context; | 345 { AbsentPropertyContext context; |
| 342 context.Check("var x; x", | 346 context.Check("var x; x", |
| 343 1, // access | 347 1, // access |
| 344 1, // declaration | 348 1, // declaration |
| 345 2, // declaration + initialization | 349 2, // declaration + initialization |
| 346 EXPECT_RESULT, Undefined()); | 350 EXPECT_RESULT, Undefined(isolate)); |
| 347 } | 351 } |
| 348 | 352 |
| 349 { AbsentPropertyContext context; | 353 { AbsentPropertyContext context; |
| 350 context.Check("var x = 0; x", | 354 context.Check("var x = 0; x", |
| 351 1, // access | 355 1, // access |
| 352 2, // declaration + initialization | 356 2, // declaration + initialization |
| 353 2, // declaration + initialization | 357 2, // declaration + initialization |
| 354 EXPECT_RESULT, Number::New(0)); | 358 EXPECT_RESULT, Number::New(0)); |
| 355 } | 359 } |
| 356 | 360 |
| 357 { AbsentPropertyContext context; | 361 { AbsentPropertyContext context; |
| 358 context.Check("function x() { }; x", | 362 context.Check("function x() { }; x", |
| 359 1, // access | 363 1, // access |
| 360 0, | 364 0, |
| 361 0, | 365 0, |
| 362 EXPECT_RESULT); | 366 EXPECT_RESULT); |
| 363 } | 367 } |
| 364 | 368 |
| 365 { AbsentPropertyContext context; | 369 { AbsentPropertyContext context; |
| 366 context.Check("const x; x", | 370 context.Check("const x; x", |
| 367 1, // access | 371 1, // access |
| 368 2, // declaration + initialization | 372 2, // declaration + initialization |
| 369 1, // declaration | 373 1, // declaration |
| 370 EXPECT_RESULT, Undefined()); | 374 EXPECT_RESULT, Undefined(isolate)); |
| 371 } | 375 } |
| 372 | 376 |
| 373 { AbsentPropertyContext context; | 377 { AbsentPropertyContext context; |
| 374 context.Check("const x = 0; x", | 378 context.Check("const x = 0; x", |
| 375 1, // access | 379 1, // access |
| 376 2, // declaration + initialization | 380 2, // declaration + initialization |
| 377 1, // declaration | 381 1, // declaration |
| 378 EXPECT_RESULT, Undefined()); // SB 0 - BUG 1213579 | 382 EXPECT_RESULT, Undefined(isolate)); // SB 0 - BUG 1213579 |
| 379 } | 383 } |
| 380 | 384 |
| 381 { AbsentPropertyContext context; | 385 { AbsentPropertyContext context; |
| 382 context.Check("if (false) { var x = 0 }; x", | 386 context.Check("if (false) { var x = 0 }; x", |
| 383 1, // access | 387 1, // access |
| 384 1, // declaration | 388 1, // declaration |
| 385 1, // declaration + initialization | 389 1, // declaration + initialization |
| 386 EXPECT_RESULT, Undefined()); | 390 EXPECT_RESULT, Undefined(isolate)); |
| 387 } | 391 } |
| 388 } | 392 } |
| 389 | 393 |
| 390 | 394 |
| 391 | 395 |
| 392 class AppearingPropertyContext: public DeclarationContext { | 396 class AppearingPropertyContext: public DeclarationContext { |
| 393 public: | 397 public: |
| 394 enum State { | 398 enum State { |
| 395 DECLARE, | 399 DECLARE, |
| 396 INITIALIZE_IF_ASSIGN, | 400 INITIALIZE_IF_ASSIGN, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 419 // Do the lookup in the object. | 423 // Do the lookup in the object. |
| 420 return v8::Handle<Integer>(); | 424 return v8::Handle<Integer>(); |
| 421 } | 425 } |
| 422 | 426 |
| 423 private: | 427 private: |
| 424 State state_; | 428 State state_; |
| 425 }; | 429 }; |
| 426 | 430 |
| 427 | 431 |
| 428 TEST(Appearing) { | 432 TEST(Appearing) { |
| 433 v8::V8::Initialize(); |
| 429 HandleScope scope(CcTest::isolate()); | 434 HandleScope scope(CcTest::isolate()); |
| 430 | 435 |
| 431 { AppearingPropertyContext context; | 436 { AppearingPropertyContext context; |
| 432 context.Check("var x; x", | 437 context.Check("var x; x", |
| 433 1, // access | 438 1, // access |
| 434 1, // declaration | 439 1, // declaration |
| 435 2, // declaration + initialization | 440 2, // declaration + initialization |
| 436 EXPECT_RESULT, Undefined()); | 441 EXPECT_RESULT, Undefined(CcTest::isolate())); |
| 437 } | 442 } |
| 438 | 443 |
| 439 { AppearingPropertyContext context; | 444 { AppearingPropertyContext context; |
| 440 context.Check("var x = 0; x", | 445 context.Check("var x = 0; x", |
| 441 1, // access | 446 1, // access |
| 442 2, // declaration + initialization | 447 2, // declaration + initialization |
| 443 2, // declaration + initialization | 448 2, // declaration + initialization |
| 444 EXPECT_RESULT, Number::New(0)); | 449 EXPECT_RESULT, Number::New(0)); |
| 445 } | 450 } |
| 446 | 451 |
| 447 { AppearingPropertyContext context; | 452 { AppearingPropertyContext context; |
| 448 context.Check("function x() { }; x", | 453 context.Check("function x() { }; x", |
| 449 1, // access | 454 1, // access |
| 450 0, | 455 0, |
| 451 0, | 456 0, |
| 452 EXPECT_RESULT); | 457 EXPECT_RESULT); |
| 453 } | 458 } |
| 454 | 459 |
| 455 { AppearingPropertyContext context; | 460 { AppearingPropertyContext context; |
| 456 context.Check("const x; x", | 461 context.Check("const x; x", |
| 457 1, // access | 462 1, // access |
| 458 2, // declaration + initialization | 463 2, // declaration + initialization |
| 459 1, // declaration | 464 1, // declaration |
| 460 EXPECT_RESULT, Undefined()); | 465 EXPECT_RESULT, Undefined(CcTest::isolate())); |
| 461 } | 466 } |
| 462 | 467 |
| 463 { AppearingPropertyContext context; | 468 { AppearingPropertyContext context; |
| 464 context.Check("const x = 0; x", | 469 context.Check("const x = 0; x", |
| 465 1, // access | 470 1, // access |
| 466 2, // declaration + initialization | 471 2, // declaration + initialization |
| 467 1, // declaration | 472 1, // declaration |
| 468 EXPECT_RESULT, Undefined()); | 473 EXPECT_RESULT, Undefined(CcTest::isolate())); |
| 469 // Result is undefined because declaration succeeded but | 474 // Result is undefined because declaration succeeded but |
| 470 // initialization to 0 failed (due to context behavior). | 475 // initialization to 0 failed (due to context behavior). |
| 471 } | 476 } |
| 472 } | 477 } |
| 473 | 478 |
| 474 | 479 |
| 475 | 480 |
| 476 class ReappearingPropertyContext: public DeclarationContext { | 481 class ReappearingPropertyContext: public DeclarationContext { |
| 477 public: | 482 public: |
| 478 enum State { | 483 enum State { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 // Do the lookup in the object. | 516 // Do the lookup in the object. |
| 512 return Handle<Integer>(); | 517 return Handle<Integer>(); |
| 513 } | 518 } |
| 514 | 519 |
| 515 private: | 520 private: |
| 516 State state_; | 521 State state_; |
| 517 }; | 522 }; |
| 518 | 523 |
| 519 | 524 |
| 520 TEST(Reappearing) { | 525 TEST(Reappearing) { |
| 526 v8::V8::Initialize(); |
| 521 HandleScope scope(CcTest::isolate()); | 527 HandleScope scope(CcTest::isolate()); |
| 522 | 528 |
| 523 { ReappearingPropertyContext context; | 529 { ReappearingPropertyContext context; |
| 524 context.Check("const x; var x = 0", | 530 context.Check("const x; var x = 0", |
| 525 0, | 531 0, |
| 526 3, // const declaration+initialization, var initialization | 532 3, // const declaration+initialization, var initialization |
| 527 3, // 2 x declaration + var initialization | 533 3, // 2 x declaration + var initialization |
| 528 EXPECT_RESULT, Undefined()); | 534 EXPECT_RESULT, Undefined(CcTest::isolate())); |
| 529 } | 535 } |
| 530 } | 536 } |
| 531 | 537 |
| 532 | 538 |
| 533 | 539 |
| 534 class ExistsInPrototypeContext: public DeclarationContext { | 540 class ExistsInPrototypeContext: public DeclarationContext { |
| 535 protected: | 541 protected: |
| 536 virtual v8::Handle<Integer> Query(Local<String> key) { | 542 virtual v8::Handle<Integer> Query(Local<String> key) { |
| 537 // Let it seem that the property exists in the prototype object. | 543 // Let it seem that the property exists in the prototype object. |
| 538 return Integer::New(v8::None); | 544 return Integer::New(v8::None); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 557 0, | 563 0, |
| 558 0, | 564 0, |
| 559 EXPECT_RESULT, Number::New(87)); | 565 EXPECT_RESULT, Number::New(87)); |
| 560 } | 566 } |
| 561 | 567 |
| 562 { ExistsInPrototypeContext context; | 568 { ExistsInPrototypeContext context; |
| 563 context.Check("var x; x", | 569 context.Check("var x; x", |
| 564 0, | 570 0, |
| 565 0, | 571 0, |
| 566 0, | 572 0, |
| 567 EXPECT_RESULT, Undefined()); | 573 EXPECT_RESULT, Undefined(CcTest::isolate())); |
| 568 } | 574 } |
| 569 | 575 |
| 570 { ExistsInPrototypeContext context; | 576 { ExistsInPrototypeContext context; |
| 571 context.Check("var x = 0; x", | 577 context.Check("var x = 0; x", |
| 572 0, | 578 0, |
| 573 0, | 579 0, |
| 574 0, | 580 0, |
| 575 EXPECT_RESULT, Number::New(0)); | 581 EXPECT_RESULT, Number::New(0)); |
| 576 } | 582 } |
| 577 | 583 |
| 578 { ExistsInPrototypeContext context; | 584 { ExistsInPrototypeContext context; |
| 579 context.Check("const x; x", | 585 context.Check("const x; x", |
| 580 0, | 586 0, |
| 581 0, | 587 0, |
| 582 0, | 588 0, |
| 583 EXPECT_RESULT, Undefined()); | 589 EXPECT_RESULT, Undefined(CcTest::isolate())); |
| 584 } | 590 } |
| 585 | 591 |
| 586 { ExistsInPrototypeContext context; | 592 { ExistsInPrototypeContext context; |
| 587 context.Check("const x = 0; x", | 593 context.Check("const x = 0; x", |
| 588 0, | 594 0, |
| 589 0, | 595 0, |
| 590 0, | 596 0, |
| 591 EXPECT_RESULT, Number::New(0)); | 597 EXPECT_RESULT, Number::New(0)); |
| 592 } | 598 } |
| 593 } | 599 } |
| 594 | 600 |
| 595 | 601 |
| 596 | 602 |
| 597 class AbsentInPrototypeContext: public DeclarationContext { | 603 class AbsentInPrototypeContext: public DeclarationContext { |
| 598 protected: | 604 protected: |
| 599 virtual v8::Handle<Integer> Query(Local<String> key) { | 605 virtual v8::Handle<Integer> Query(Local<String> key) { |
| 600 // Let it seem that the property is absent in the prototype object. | 606 // Let it seem that the property is absent in the prototype object. |
| 601 return Handle<Integer>(); | 607 return Handle<Integer>(); |
| 602 } | 608 } |
| 603 | 609 |
| 604 // Use the prototype as the holder for the interceptors. | 610 // Use the prototype as the holder for the interceptors. |
| 605 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { | 611 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { |
| 606 return function->PrototypeTemplate(); | 612 return function->PrototypeTemplate(); |
| 607 } | 613 } |
| 608 }; | 614 }; |
| 609 | 615 |
| 610 | 616 |
| 611 TEST(AbsentInPrototype) { | 617 TEST(AbsentInPrototype) { |
| 612 i::FLAG_es52_globals = true; | 618 i::FLAG_es52_globals = true; |
| 619 v8::V8::Initialize(); |
| 613 HandleScope scope(CcTest::isolate()); | 620 HandleScope scope(CcTest::isolate()); |
| 614 | 621 |
| 615 { AbsentInPrototypeContext context; | 622 { AbsentInPrototypeContext context; |
| 616 context.Check("if (false) { var x = 0; }; x", | 623 context.Check("if (false) { var x = 0; }; x", |
| 617 0, | 624 0, |
| 618 0, | 625 0, |
| 619 0, | 626 0, |
| 620 EXPECT_RESULT, Undefined()); | 627 EXPECT_RESULT, Undefined(CcTest::isolate())); |
| 621 } | 628 } |
| 622 } | 629 } |
| 623 | 630 |
| 624 | 631 |
| 625 | 632 |
| 626 class ExistsInHiddenPrototypeContext: public DeclarationContext { | 633 class ExistsInHiddenPrototypeContext: public DeclarationContext { |
| 627 public: | 634 public: |
| 628 ExistsInHiddenPrototypeContext() { | 635 ExistsInHiddenPrototypeContext() { |
| 629 hidden_proto_ = FunctionTemplate::New(); | 636 hidden_proto_ = FunctionTemplate::New(); |
| 630 hidden_proto_->SetHiddenPrototype(true); | 637 hidden_proto_->SetHiddenPrototype(true); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 0, | 689 0, |
| 683 EXPECT_RESULT); | 690 EXPECT_RESULT); |
| 684 } | 691 } |
| 685 | 692 |
| 686 // TODO(mstarzinger): The semantics of global const is vague. | 693 // TODO(mstarzinger): The semantics of global const is vague. |
| 687 { ExistsInHiddenPrototypeContext context; | 694 { ExistsInHiddenPrototypeContext context; |
| 688 context.Check("const x; x", | 695 context.Check("const x; x", |
| 689 0, | 696 0, |
| 690 0, | 697 0, |
| 691 1, // (re-)declaration | 698 1, // (re-)declaration |
| 692 EXPECT_RESULT, Undefined()); | 699 EXPECT_RESULT, Undefined(CcTest::isolate())); |
| 693 } | 700 } |
| 694 | 701 |
| 695 // TODO(mstarzinger): The semantics of global const is vague. | 702 // TODO(mstarzinger): The semantics of global const is vague. |
| 696 { ExistsInHiddenPrototypeContext context; | 703 { ExistsInHiddenPrototypeContext context; |
| 697 context.Check("const x = 0; x", | 704 context.Check("const x = 0; x", |
| 698 0, | 705 0, |
| 699 0, | 706 0, |
| 700 1, // (re-)declaration | 707 1, // (re-)declaration |
| 701 EXPECT_RESULT, Number::New(0)); | 708 EXPECT_RESULT, Number::New(0)); |
| 702 } | 709 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 SimpleContext context; | 854 SimpleContext context; |
| 848 context.Check(firsts[i], EXPECT_RESULT, Number::New(1)); | 855 context.Check(firsts[i], EXPECT_RESULT, Number::New(1)); |
| 849 // TODO(rossberg): All tests should actually be errors in Harmony, | 856 // TODO(rossberg): All tests should actually be errors in Harmony, |
| 850 // but we currently do not detect the cases where the first declaration | 857 // but we currently do not detect the cases where the first declaration |
| 851 // is not lexical. | 858 // is not lexical. |
| 852 context.Check(seconds[j], | 859 context.Check(seconds[j], |
| 853 i < 2 ? EXPECT_RESULT : EXPECT_ERROR, Number::New(2)); | 860 i < 2 ? EXPECT_RESULT : EXPECT_ERROR, Number::New(2)); |
| 854 } | 861 } |
| 855 } | 862 } |
| 856 } | 863 } |
| OLD | NEW |