| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 // The handlers are called as static functions that forward | 89 // The handlers are called as static functions that forward |
| 90 // to the instance specific virtual methods. | 90 // to the instance specific virtual methods. |
| 91 static void HandleGet(Local<String> key, | 91 static void HandleGet(Local<String> key, |
| 92 const v8::PropertyCallbackInfo<v8::Value>& info); | 92 const v8::PropertyCallbackInfo<v8::Value>& info); |
| 93 static void HandleSet(Local<String> key, | 93 static void HandleSet(Local<String> key, |
| 94 Local<Value> value, | 94 Local<Value> value, |
| 95 const v8::PropertyCallbackInfo<v8::Value>& info); | 95 const v8::PropertyCallbackInfo<v8::Value>& info); |
| 96 static void HandleQuery(Local<String> key, | 96 static void HandleQuery(Local<String> key, |
| 97 const v8::PropertyCallbackInfo<v8::Integer>& info); | 97 const v8::PropertyCallbackInfo<v8::Integer>& info); |
| 98 | 98 |
| 99 v8::Isolate* isolate() const { return CcTest::isolate(); } | |
| 100 | |
| 101 private: | 99 private: |
| 102 bool is_initialized_; | 100 bool is_initialized_; |
| 103 Persistent<Context> context_; | 101 Persistent<Context> context_; |
| 104 | 102 |
| 105 int get_count_; | 103 int get_count_; |
| 106 int set_count_; | 104 int set_count_; |
| 107 int query_count_; | 105 int query_count_; |
| 108 | 106 |
| 109 static DeclarationContext* GetInstance(Local<Value> data); | 107 static DeclarationContext* GetInstance(Local<Value> data); |
| 110 }; | 108 }; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 1, // declaration | 237 1, // declaration |
| 240 2, // declaration + initialization | 238 2, // declaration + initialization |
| 241 EXPECT_RESULT, Undefined(CcTest::isolate())); | 239 EXPECT_RESULT, Undefined(CcTest::isolate())); |
| 242 } | 240 } |
| 243 | 241 |
| 244 { DeclarationContext context; | 242 { DeclarationContext context; |
| 245 context.Check("var x = 0; x", | 243 context.Check("var x = 0; x", |
| 246 1, // access | 244 1, // access |
| 247 2, // declaration + initialization | 245 2, // declaration + initialization |
| 248 2, // declaration + initialization | 246 2, // declaration + initialization |
| 249 EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | 247 EXPECT_RESULT, Number::New(0)); |
| 250 } | 248 } |
| 251 | 249 |
| 252 { DeclarationContext context; | 250 { DeclarationContext context; |
| 253 context.Check("function x() { }; x", | 251 context.Check("function x() { }; x", |
| 254 1, // access | 252 1, // access |
| 255 0, | 253 0, |
| 256 0, | 254 0, |
| 257 EXPECT_RESULT); | 255 EXPECT_RESULT); |
| 258 } | 256 } |
| 259 | 257 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 273 1, // declaration | 271 1, // declaration |
| 274 EXPECT_RESULT, Undefined(CcTest::isolate())); | 272 EXPECT_RESULT, Undefined(CcTest::isolate())); |
| 275 } | 273 } |
| 276 } | 274 } |
| 277 | 275 |
| 278 | 276 |
| 279 | 277 |
| 280 class PresentPropertyContext: public DeclarationContext { | 278 class PresentPropertyContext: public DeclarationContext { |
| 281 protected: | 279 protected: |
| 282 virtual v8::Handle<Integer> Query(Local<String> key) { | 280 virtual v8::Handle<Integer> Query(Local<String> key) { |
| 283 return Integer::New(isolate(), v8::None); | 281 return Integer::New(v8::None); |
| 284 } | 282 } |
| 285 }; | 283 }; |
| 286 | 284 |
| 287 | 285 |
| 288 | 286 |
| 289 TEST(Present) { | 287 TEST(Present) { |
| 290 HandleScope scope(CcTest::isolate()); | 288 HandleScope scope(CcTest::isolate()); |
| 291 | 289 |
| 292 { PresentPropertyContext context; | 290 { PresentPropertyContext context; |
| 293 context.Check("var x; x", | 291 context.Check("var x; x", |
| 294 1, // access | 292 1, // access |
| 295 0, | 293 0, |
| 296 2, // declaration + initialization | 294 2, // declaration + initialization |
| 297 EXPECT_EXCEPTION); // x is not defined! | 295 EXPECT_EXCEPTION); // x is not defined! |
| 298 } | 296 } |
| 299 | 297 |
| 300 { PresentPropertyContext context; | 298 { PresentPropertyContext context; |
| 301 context.Check("var x = 0; x", | 299 context.Check("var x = 0; x", |
| 302 1, // access | 300 1, // access |
| 303 1, // initialization | 301 1, // initialization |
| 304 2, // declaration + initialization | 302 2, // declaration + initialization |
| 305 EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | 303 EXPECT_RESULT, Number::New(0)); |
| 306 } | 304 } |
| 307 | 305 |
| 308 { PresentPropertyContext context; | 306 { PresentPropertyContext context; |
| 309 context.Check("function x() { }; x", | 307 context.Check("function x() { }; x", |
| 310 1, // access | 308 1, // access |
| 311 0, | 309 0, |
| 312 0, | 310 0, |
| 313 EXPECT_RESULT); | 311 EXPECT_RESULT); |
| 314 } | 312 } |
| 315 | 313 |
| 316 { PresentPropertyContext context; | 314 { PresentPropertyContext context; |
| 317 context.Check("const x; x", | 315 context.Check("const x; x", |
| 318 1, // access | 316 1, // access |
| 319 1, // initialization | 317 1, // initialization |
| 320 1, // (re-)declaration | 318 1, // (re-)declaration |
| 321 EXPECT_RESULT, Undefined(CcTest::isolate())); | 319 EXPECT_RESULT, Undefined(CcTest::isolate())); |
| 322 } | 320 } |
| 323 | 321 |
| 324 { PresentPropertyContext context; | 322 { PresentPropertyContext context; |
| 325 context.Check("const x = 0; x", | 323 context.Check("const x = 0; x", |
| 326 1, // access | 324 1, // access |
| 327 1, // initialization | 325 1, // initialization |
| 328 1, // (re-)declaration | 326 1, // (re-)declaration |
| 329 EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | 327 EXPECT_RESULT, Number::New(0)); |
| 330 } | 328 } |
| 331 } | 329 } |
| 332 | 330 |
| 333 | 331 |
| 334 | 332 |
| 335 class AbsentPropertyContext: public DeclarationContext { | 333 class AbsentPropertyContext: public DeclarationContext { |
| 336 protected: | 334 protected: |
| 337 virtual v8::Handle<Integer> Query(Local<String> key) { | 335 virtual v8::Handle<Integer> Query(Local<String> key) { |
| 338 return v8::Handle<Integer>(); | 336 return v8::Handle<Integer>(); |
| 339 } | 337 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 351 1, // declaration | 349 1, // declaration |
| 352 2, // declaration + initialization | 350 2, // declaration + initialization |
| 353 EXPECT_RESULT, Undefined(isolate)); | 351 EXPECT_RESULT, Undefined(isolate)); |
| 354 } | 352 } |
| 355 | 353 |
| 356 { AbsentPropertyContext context; | 354 { AbsentPropertyContext context; |
| 357 context.Check("var x = 0; x", | 355 context.Check("var x = 0; x", |
| 358 1, // access | 356 1, // access |
| 359 2, // declaration + initialization | 357 2, // declaration + initialization |
| 360 2, // declaration + initialization | 358 2, // declaration + initialization |
| 361 EXPECT_RESULT, Number::New(isolate, 0)); | 359 EXPECT_RESULT, Number::New(0)); |
| 362 } | 360 } |
| 363 | 361 |
| 364 { AbsentPropertyContext context; | 362 { AbsentPropertyContext context; |
| 365 context.Check("function x() { }; x", | 363 context.Check("function x() { }; x", |
| 366 1, // access | 364 1, // access |
| 367 0, | 365 0, |
| 368 0, | 366 0, |
| 369 EXPECT_RESULT); | 367 EXPECT_RESULT); |
| 370 } | 368 } |
| 371 | 369 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 switch (state_) { | 409 switch (state_) { |
| 412 case DECLARE: | 410 case DECLARE: |
| 413 // Force declaration by returning that the | 411 // Force declaration by returning that the |
| 414 // property is absent. | 412 // property is absent. |
| 415 state_ = INITIALIZE_IF_ASSIGN; | 413 state_ = INITIALIZE_IF_ASSIGN; |
| 416 return Handle<Integer>(); | 414 return Handle<Integer>(); |
| 417 case INITIALIZE_IF_ASSIGN: | 415 case INITIALIZE_IF_ASSIGN: |
| 418 // Return that the property is present so we only get the | 416 // Return that the property is present so we only get the |
| 419 // setter called when initializing with a value. | 417 // setter called when initializing with a value. |
| 420 state_ = UNKNOWN; | 418 state_ = UNKNOWN; |
| 421 return Integer::New(isolate(), v8::None); | 419 return Integer::New(v8::None); |
| 422 default: | 420 default: |
| 423 CHECK(state_ == UNKNOWN); | 421 CHECK(state_ == UNKNOWN); |
| 424 break; | 422 break; |
| 425 } | 423 } |
| 426 // Do the lookup in the object. | 424 // Do the lookup in the object. |
| 427 return v8::Handle<Integer>(); | 425 return v8::Handle<Integer>(); |
| 428 } | 426 } |
| 429 | 427 |
| 430 private: | 428 private: |
| 431 State state_; | 429 State state_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 442 1, // declaration | 440 1, // declaration |
| 443 2, // declaration + initialization | 441 2, // declaration + initialization |
| 444 EXPECT_RESULT, Undefined(CcTest::isolate())); | 442 EXPECT_RESULT, Undefined(CcTest::isolate())); |
| 445 } | 443 } |
| 446 | 444 |
| 447 { AppearingPropertyContext context; | 445 { AppearingPropertyContext context; |
| 448 context.Check("var x = 0; x", | 446 context.Check("var x = 0; x", |
| 449 1, // access | 447 1, // access |
| 450 2, // declaration + initialization | 448 2, // declaration + initialization |
| 451 2, // declaration + initialization | 449 2, // declaration + initialization |
| 452 EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | 450 EXPECT_RESULT, Number::New(0)); |
| 453 } | 451 } |
| 454 | 452 |
| 455 { AppearingPropertyContext context; | 453 { AppearingPropertyContext context; |
| 456 context.Check("function x() { }; x", | 454 context.Check("function x() { }; x", |
| 457 1, // access | 455 1, // access |
| 458 0, | 456 0, |
| 459 0, | 457 0, |
| 460 EXPECT_RESULT); | 458 EXPECT_RESULT); |
| 461 } | 459 } |
| 462 | 460 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 switch (state_) { | 495 switch (state_) { |
| 498 case DECLARE: | 496 case DECLARE: |
| 499 // Force the first declaration by returning that | 497 // Force the first declaration by returning that |
| 500 // the property is absent. | 498 // the property is absent. |
| 501 state_ = DONT_DECLARE; | 499 state_ = DONT_DECLARE; |
| 502 return Handle<Integer>(); | 500 return Handle<Integer>(); |
| 503 case DONT_DECLARE: | 501 case DONT_DECLARE: |
| 504 // Ignore the second declaration by returning | 502 // Ignore the second declaration by returning |
| 505 // that the property is already there. | 503 // that the property is already there. |
| 506 state_ = INITIALIZE; | 504 state_ = INITIALIZE; |
| 507 return Integer::New(isolate(), v8::None); | 505 return Integer::New(v8::None); |
| 508 case INITIALIZE: | 506 case INITIALIZE: |
| 509 // Force an initialization by returning that | 507 // Force an initialization by returning that |
| 510 // the property is absent. This will make sure | 508 // the property is absent. This will make sure |
| 511 // that the setter is called and it will not | 509 // that the setter is called and it will not |
| 512 // lead to redeclaration conflicts (yet). | 510 // lead to redeclaration conflicts (yet). |
| 513 state_ = UNKNOWN; | 511 state_ = UNKNOWN; |
| 514 return Handle<Integer>(); | 512 return Handle<Integer>(); |
| 515 default: | 513 default: |
| 516 CHECK(state_ == UNKNOWN); | 514 CHECK(state_ == UNKNOWN); |
| 517 break; | 515 break; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 534 0, | 532 0, |
| 535 3, // const declaration+initialization, var initialization | 533 3, // const declaration+initialization, var initialization |
| 536 3, // 2 x declaration + var initialization | 534 3, // 2 x declaration + var initialization |
| 537 EXPECT_RESULT, Undefined(CcTest::isolate())); | 535 EXPECT_RESULT, Undefined(CcTest::isolate())); |
| 538 } | 536 } |
| 539 } | 537 } |
| 540 | 538 |
| 541 | 539 |
| 542 | 540 |
| 543 class ExistsInPrototypeContext: public DeclarationContext { | 541 class ExistsInPrototypeContext: public DeclarationContext { |
| 544 public: | |
| 545 ExistsInPrototypeContext() { InitializeIfNeeded(); } | |
| 546 protected: | 542 protected: |
| 547 virtual v8::Handle<Integer> Query(Local<String> key) { | 543 virtual v8::Handle<Integer> Query(Local<String> key) { |
| 548 // Let it seem that the property exists in the prototype object. | 544 // Let it seem that the property exists in the prototype object. |
| 549 return Integer::New(isolate(), v8::None); | 545 return Integer::New(v8::None); |
| 550 } | 546 } |
| 551 | 547 |
| 552 // Use the prototype as the holder for the interceptors. | 548 // Use the prototype as the holder for the interceptors. |
| 553 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { | 549 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { |
| 554 return function->PrototypeTemplate(); | 550 return function->PrototypeTemplate(); |
| 555 } | 551 } |
| 556 }; | 552 }; |
| 557 | 553 |
| 558 | 554 |
| 559 TEST(ExistsInPrototype) { | 555 TEST(ExistsInPrototype) { |
| 560 i::FLAG_es52_globals = true; | 556 i::FLAG_es52_globals = true; |
| 561 HandleScope scope(CcTest::isolate()); | 557 HandleScope scope(CcTest::isolate()); |
| 562 | 558 |
| 563 // Sanity check to make sure that the holder of the interceptor | 559 // Sanity check to make sure that the holder of the interceptor |
| 564 // really is the prototype object. | 560 // really is the prototype object. |
| 565 { ExistsInPrototypeContext context; | 561 { ExistsInPrototypeContext context; |
| 566 context.Check("this.x = 87; this.x", | 562 context.Check("this.x = 87; this.x", |
| 567 0, | 563 0, |
| 568 0, | 564 0, |
| 569 0, | 565 0, |
| 570 EXPECT_RESULT, Number::New(CcTest::isolate(), 87)); | 566 EXPECT_RESULT, Number::New(87)); |
| 571 } | 567 } |
| 572 | 568 |
| 573 { ExistsInPrototypeContext context; | 569 { ExistsInPrototypeContext context; |
| 574 context.Check("var x; x", | 570 context.Check("var x; x", |
| 575 0, | 571 0, |
| 576 0, | 572 0, |
| 577 0, | 573 0, |
| 578 EXPECT_RESULT, Undefined(CcTest::isolate())); | 574 EXPECT_RESULT, Undefined(CcTest::isolate())); |
| 579 } | 575 } |
| 580 | 576 |
| 581 { ExistsInPrototypeContext context; | 577 { ExistsInPrototypeContext context; |
| 582 context.Check("var x = 0; x", | 578 context.Check("var x = 0; x", |
| 583 0, | 579 0, |
| 584 0, | 580 0, |
| 585 0, | 581 0, |
| 586 EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | 582 EXPECT_RESULT, Number::New(0)); |
| 587 } | 583 } |
| 588 | 584 |
| 589 { ExistsInPrototypeContext context; | 585 { ExistsInPrototypeContext context; |
| 590 context.Check("const x; x", | 586 context.Check("const x; x", |
| 591 0, | 587 0, |
| 592 0, | 588 0, |
| 593 0, | 589 0, |
| 594 EXPECT_RESULT, Undefined(CcTest::isolate())); | 590 EXPECT_RESULT, Undefined(CcTest::isolate())); |
| 595 } | 591 } |
| 596 | 592 |
| 597 { ExistsInPrototypeContext context; | 593 { ExistsInPrototypeContext context; |
| 598 context.Check("const x = 0; x", | 594 context.Check("const x = 0; x", |
| 599 0, | 595 0, |
| 600 0, | 596 0, |
| 601 0, | 597 0, |
| 602 EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | 598 EXPECT_RESULT, Number::New(0)); |
| 603 } | 599 } |
| 604 } | 600 } |
| 605 | 601 |
| 606 | 602 |
| 607 | 603 |
| 608 class AbsentInPrototypeContext: public DeclarationContext { | 604 class AbsentInPrototypeContext: public DeclarationContext { |
| 609 protected: | 605 protected: |
| 610 virtual v8::Handle<Integer> Query(Local<String> key) { | 606 virtual v8::Handle<Integer> Query(Local<String> key) { |
| 611 // Let it seem that the property is absent in the prototype object. | 607 // Let it seem that the property is absent in the prototype object. |
| 612 return Handle<Integer>(); | 608 return Handle<Integer>(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 638 class ExistsInHiddenPrototypeContext: public DeclarationContext { | 634 class ExistsInHiddenPrototypeContext: public DeclarationContext { |
| 639 public: | 635 public: |
| 640 ExistsInHiddenPrototypeContext() { | 636 ExistsInHiddenPrototypeContext() { |
| 641 hidden_proto_ = FunctionTemplate::New(CcTest::isolate()); | 637 hidden_proto_ = FunctionTemplate::New(CcTest::isolate()); |
| 642 hidden_proto_->SetHiddenPrototype(true); | 638 hidden_proto_->SetHiddenPrototype(true); |
| 643 } | 639 } |
| 644 | 640 |
| 645 protected: | 641 protected: |
| 646 virtual v8::Handle<Integer> Query(Local<String> key) { | 642 virtual v8::Handle<Integer> Query(Local<String> key) { |
| 647 // Let it seem that the property exists in the hidden prototype object. | 643 // Let it seem that the property exists in the hidden prototype object. |
| 648 return Integer::New(isolate(), v8::None); | 644 return Integer::New(v8::None); |
| 649 } | 645 } |
| 650 | 646 |
| 651 // Install the hidden prototype after the global object has been created. | 647 // Install the hidden prototype after the global object has been created. |
| 652 virtual void PostInitializeContext(Handle<Context> context) { | 648 virtual void PostInitializeContext(Handle<Context> context) { |
| 653 Local<Object> global_object = context->Global(); | 649 Local<Object> global_object = context->Global(); |
| 654 Local<Object> hidden_proto = hidden_proto_->GetFunction()->NewInstance(); | 650 Local<Object> hidden_proto = hidden_proto_->GetFunction()->NewInstance(); |
| 655 Local<Object> inner_global = | 651 Local<Object> inner_global = |
| 656 Local<Object>::Cast(global_object->GetPrototype()); | 652 Local<Object>::Cast(global_object->GetPrototype()); |
| 657 inner_global->SetPrototype(hidden_proto); | 653 inner_global->SetPrototype(hidden_proto); |
| 658 } | 654 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 677 0, | 673 0, |
| 678 2, // declaration + initialization | 674 2, // declaration + initialization |
| 679 EXPECT_EXCEPTION); // x is not defined! | 675 EXPECT_EXCEPTION); // x is not defined! |
| 680 } | 676 } |
| 681 | 677 |
| 682 { ExistsInHiddenPrototypeContext context; | 678 { ExistsInHiddenPrototypeContext context; |
| 683 context.Check("var x = 0; x", | 679 context.Check("var x = 0; x", |
| 684 1, // access | 680 1, // access |
| 685 1, // initialization | 681 1, // initialization |
| 686 2, // declaration + initialization | 682 2, // declaration + initialization |
| 687 EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | 683 EXPECT_RESULT, Number::New(0)); |
| 688 } | 684 } |
| 689 | 685 |
| 690 { ExistsInHiddenPrototypeContext context; | 686 { ExistsInHiddenPrototypeContext context; |
| 691 context.Check("function x() { }; x", | 687 context.Check("function x() { }; x", |
| 692 0, | 688 0, |
| 693 0, | 689 0, |
| 694 0, | 690 0, |
| 695 EXPECT_RESULT); | 691 EXPECT_RESULT); |
| 696 } | 692 } |
| 697 | 693 |
| 698 // TODO(mstarzinger): The semantics of global const is vague. | 694 // TODO(mstarzinger): The semantics of global const is vague. |
| 699 { ExistsInHiddenPrototypeContext context; | 695 { ExistsInHiddenPrototypeContext context; |
| 700 context.Check("const x; x", | 696 context.Check("const x; x", |
| 701 0, | 697 0, |
| 702 0, | 698 0, |
| 703 1, // (re-)declaration | 699 1, // (re-)declaration |
| 704 EXPECT_RESULT, Undefined(CcTest::isolate())); | 700 EXPECT_RESULT, Undefined(CcTest::isolate())); |
| 705 } | 701 } |
| 706 | 702 |
| 707 // TODO(mstarzinger): The semantics of global const is vague. | 703 // TODO(mstarzinger): The semantics of global const is vague. |
| 708 { ExistsInHiddenPrototypeContext context; | 704 { ExistsInHiddenPrototypeContext context; |
| 709 context.Check("const x = 0; x", | 705 context.Check("const x = 0; x", |
| 710 0, | 706 0, |
| 711 0, | 707 0, |
| 712 1, // (re-)declaration | 708 1, // (re-)declaration |
| 713 EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | 709 EXPECT_RESULT, Number::New(0)); |
| 714 } | 710 } |
| 715 } | 711 } |
| 716 | 712 |
| 717 | 713 |
| 718 | 714 |
| 719 class SimpleContext { | 715 class SimpleContext { |
| 720 public: | 716 public: |
| 721 SimpleContext() | 717 SimpleContext() |
| 722 : handle_scope_(CcTest::isolate()), | 718 : handle_scope_(CcTest::isolate()), |
| 723 context_(Context::New(CcTest::isolate())) { | 719 context_(Context::New(CcTest::isolate())) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 } | 752 } |
| 757 } | 753 } |
| 758 | 754 |
| 759 private: | 755 private: |
| 760 HandleScope handle_scope_; | 756 HandleScope handle_scope_; |
| 761 Local<Context> context_; | 757 Local<Context> context_; |
| 762 }; | 758 }; |
| 763 | 759 |
| 764 | 760 |
| 765 TEST(CrossScriptReferences) { | 761 TEST(CrossScriptReferences) { |
| 766 v8::Isolate* isolate = CcTest::isolate(); | 762 HandleScope scope(CcTest::isolate()); |
| 767 HandleScope scope(isolate); | |
| 768 | 763 |
| 769 { SimpleContext context; | 764 { SimpleContext context; |
| 770 context.Check("var x = 1; x", | 765 context.Check("var x = 1; x", |
| 771 EXPECT_RESULT, Number::New(isolate, 1)); | 766 EXPECT_RESULT, Number::New(1)); |
| 772 context.Check("var x = 2; x", | 767 context.Check("var x = 2; x", |
| 773 EXPECT_RESULT, Number::New(isolate, 2)); | 768 EXPECT_RESULT, Number::New(2)); |
| 774 context.Check("const x = 3; x", | 769 context.Check("const x = 3; x", |
| 775 EXPECT_RESULT, Number::New(isolate, 3)); | 770 EXPECT_RESULT, Number::New(3)); |
| 776 context.Check("const x = 4; x", | 771 context.Check("const x = 4; x", |
| 777 EXPECT_RESULT, Number::New(isolate, 4)); | 772 EXPECT_RESULT, Number::New(4)); |
| 778 context.Check("x = 5; x", | 773 context.Check("x = 5; x", |
| 779 EXPECT_RESULT, Number::New(isolate, 5)); | 774 EXPECT_RESULT, Number::New(5)); |
| 780 context.Check("var x = 6; x", | 775 context.Check("var x = 6; x", |
| 781 EXPECT_RESULT, Number::New(isolate, 6)); | 776 EXPECT_RESULT, Number::New(6)); |
| 782 context.Check("this.x", | 777 context.Check("this.x", |
| 783 EXPECT_RESULT, Number::New(isolate, 6)); | 778 EXPECT_RESULT, Number::New(6)); |
| 784 context.Check("function x() { return 7 }; x()", | 779 context.Check("function x() { return 7 }; x()", |
| 785 EXPECT_RESULT, Number::New(isolate, 7)); | 780 EXPECT_RESULT, Number::New(7)); |
| 786 } | 781 } |
| 787 | 782 |
| 788 { SimpleContext context; | 783 { SimpleContext context; |
| 789 context.Check("const x = 1; x", | 784 context.Check("const x = 1; x", |
| 790 EXPECT_RESULT, Number::New(isolate, 1)); | 785 EXPECT_RESULT, Number::New(1)); |
| 791 context.Check("var x = 2; x", // assignment ignored | 786 context.Check("var x = 2; x", // assignment ignored |
| 792 EXPECT_RESULT, Number::New(isolate, 1)); | 787 EXPECT_RESULT, Number::New(1)); |
| 793 context.Check("const x = 3; x", | 788 context.Check("const x = 3; x", |
| 794 EXPECT_RESULT, Number::New(isolate, 1)); | 789 EXPECT_RESULT, Number::New(1)); |
| 795 context.Check("x = 4; x", // assignment ignored | 790 context.Check("x = 4; x", // assignment ignored |
| 796 EXPECT_RESULT, Number::New(isolate, 1)); | 791 EXPECT_RESULT, Number::New(1)); |
| 797 context.Check("var x = 5; x", // assignment ignored | 792 context.Check("var x = 5; x", // assignment ignored |
| 798 EXPECT_RESULT, Number::New(isolate, 1)); | 793 EXPECT_RESULT, Number::New(1)); |
| 799 context.Check("this.x", | 794 context.Check("this.x", |
| 800 EXPECT_RESULT, Number::New(isolate, 1)); | 795 EXPECT_RESULT, Number::New(1)); |
| 801 context.Check("function x() { return 7 }; x", | 796 context.Check("function x() { return 7 }; x", |
| 802 EXPECT_EXCEPTION); | 797 EXPECT_EXCEPTION); |
| 803 } | 798 } |
| 804 } | 799 } |
| 805 | 800 |
| 806 | 801 |
| 807 TEST(CrossScriptReferencesHarmony) { | 802 TEST(CrossScriptReferencesHarmony) { |
| 808 i::FLAG_use_strict = true; | 803 i::FLAG_use_strict = true; |
| 809 i::FLAG_harmony_scoping = true; | 804 i::FLAG_harmony_scoping = true; |
| 810 i::FLAG_harmony_modules = true; | 805 i::FLAG_harmony_modules = true; |
| 811 | 806 |
| 812 v8::Isolate* isolate = CcTest::isolate(); | 807 HandleScope scope(CcTest::isolate()); |
| 813 HandleScope scope(isolate); | |
| 814 | 808 |
| 815 const char* decs[] = { | 809 const char* decs[] = { |
| 816 "var x = 1; x", "x", "this.x", | 810 "var x = 1; x", "x", "this.x", |
| 817 "function x() { return 1 }; x()", "x()", "this.x()", | 811 "function x() { return 1 }; x()", "x()", "this.x()", |
| 818 "let x = 1; x", "x", "this.x", | 812 "let x = 1; x", "x", "this.x", |
| 819 "const x = 1; x", "x", "this.x", | 813 "const x = 1; x", "x", "this.x", |
| 820 "module x { export let a = 1 }; x.a", "x.a", "this.x.a", | 814 "module x { export let a = 1 }; x.a", "x.a", "this.x.a", |
| 821 NULL | 815 NULL |
| 822 }; | 816 }; |
| 823 | 817 |
| 824 for (int i = 0; decs[i] != NULL; i += 3) { | 818 for (int i = 0; decs[i] != NULL; i += 3) { |
| 825 SimpleContext context; | 819 SimpleContext context; |
| 826 context.Check(decs[i], EXPECT_RESULT, Number::New(isolate, 1)); | 820 context.Check(decs[i], EXPECT_RESULT, Number::New(1)); |
| 827 context.Check(decs[i+1], EXPECT_RESULT, Number::New(isolate, 1)); | 821 context.Check(decs[i+1], EXPECT_RESULT, Number::New(1)); |
| 828 // TODO(rossberg): The current ES6 draft spec does not reflect lexical | 822 // TODO(rossberg): The current ES6 draft spec does not reflect lexical |
| 829 // bindings on the global object. However, this will probably change, in | 823 // bindings on the global object. However, this will probably change, in |
| 830 // which case we reactivate the following test. | 824 // which case we reactivate the following test. |
| 831 if (i/3 < 2) { | 825 if (i/3 < 2) context.Check(decs[i+2], EXPECT_RESULT, Number::New(1)); |
| 832 context.Check(decs[i+2], EXPECT_RESULT, Number::New(isolate, 1)); | |
| 833 } | |
| 834 } | 826 } |
| 835 } | 827 } |
| 836 | 828 |
| 837 | 829 |
| 838 TEST(CrossScriptConflicts) { | 830 TEST(CrossScriptConflicts) { |
| 839 i::FLAG_use_strict = true; | 831 i::FLAG_use_strict = true; |
| 840 i::FLAG_harmony_scoping = true; | 832 i::FLAG_harmony_scoping = true; |
| 841 i::FLAG_harmony_modules = true; | 833 i::FLAG_harmony_modules = true; |
| 842 | 834 |
| 843 HandleScope scope(CcTest::isolate()); | 835 HandleScope scope(CcTest::isolate()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 855 "function x() { return 2 }; x()", | 847 "function x() { return 2 }; x()", |
| 856 "let x = 2; x", | 848 "let x = 2; x", |
| 857 "const x = 2; x", | 849 "const x = 2; x", |
| 858 "module x { export let a = 2 }; x.a", | 850 "module x { export let a = 2 }; x.a", |
| 859 NULL | 851 NULL |
| 860 }; | 852 }; |
| 861 | 853 |
| 862 for (int i = 0; firsts[i] != NULL; ++i) { | 854 for (int i = 0; firsts[i] != NULL; ++i) { |
| 863 for (int j = 0; seconds[j] != NULL; ++j) { | 855 for (int j = 0; seconds[j] != NULL; ++j) { |
| 864 SimpleContext context; | 856 SimpleContext context; |
| 865 context.Check(firsts[i], EXPECT_RESULT, | 857 context.Check(firsts[i], EXPECT_RESULT, Number::New(1)); |
| 866 Number::New(CcTest::isolate(), 1)); | |
| 867 // TODO(rossberg): All tests should actually be errors in Harmony, | 858 // TODO(rossberg): All tests should actually be errors in Harmony, |
| 868 // but we currently do not detect the cases where the first declaration | 859 // but we currently do not detect the cases where the first declaration |
| 869 // is not lexical. | 860 // is not lexical. |
| 870 context.Check(seconds[j], | 861 context.Check(seconds[j], |
| 871 i < 2 ? EXPECT_RESULT : EXPECT_ERROR, | 862 i < 2 ? EXPECT_RESULT : EXPECT_ERROR, Number::New(2)); |
| 872 Number::New(CcTest::isolate(), 2)); | |
| 873 } | 863 } |
| 874 } | 864 } |
| 875 } | 865 } |
| OLD | NEW |