| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 111 |
| 112 | 112 |
| 113 DeclarationContext::DeclarationContext() | 113 DeclarationContext::DeclarationContext() |
| 114 : is_initialized_(false), get_count_(0), set_count_(0), query_count_(0) { | 114 : is_initialized_(false), get_count_(0), set_count_(0), query_count_(0) { |
| 115 // Do nothing. | 115 // Do nothing. |
| 116 } | 116 } |
| 117 | 117 |
| 118 | 118 |
| 119 void DeclarationContext::InitializeIfNeeded() { | 119 void DeclarationContext::InitializeIfNeeded() { |
| 120 if (is_initialized_) return; | 120 if (is_initialized_) return; |
| 121 HandleScope scope(Isolate::GetCurrent()); | 121 Isolate* isolate = Isolate::GetCurrent(); |
| 122 HandleScope scope(isolate); |
| 122 Local<FunctionTemplate> function = FunctionTemplate::New(); | 123 Local<FunctionTemplate> function = FunctionTemplate::New(); |
| 123 Local<Value> data = External::New(this); | 124 Local<Value> data = External::New(this); |
| 124 GetHolder(function)->SetNamedPropertyHandler(&HandleGet, | 125 GetHolder(function)->SetNamedPropertyHandler(&HandleGet, |
| 125 &HandleSet, | 126 &HandleSet, |
| 126 &HandleQuery, | 127 &HandleQuery, |
| 127 0, 0, | 128 0, 0, |
| 128 data); | 129 data); |
| 129 context_ = Context::New(0, function->InstanceTemplate(), Local<Value>()); | 130 context_.Reset(isolate, |
| 131 Context::New(isolate, |
| 132 0, |
| 133 function->InstanceTemplate(), |
| 134 Local<Value>())); |
| 130 context_->Enter(); | 135 context_->Enter(); |
| 131 is_initialized_ = true; | 136 is_initialized_ = true; |
| 132 PostInitializeContext(Local<Context>::New(Isolate::GetCurrent(), context_)); | 137 PostInitializeContext(Local<Context>::New(isolate, context_)); |
| 133 } | 138 } |
| 134 | 139 |
| 135 | 140 |
| 136 void DeclarationContext::Check(const char* source, | 141 void DeclarationContext::Check(const char* source, |
| 137 int get, int set, int query, | 142 int get, int set, int query, |
| 138 Expectations expectations, | 143 Expectations expectations, |
| 139 v8::Handle<Value> value) { | 144 v8::Handle<Value> value) { |
| 140 InitializeIfNeeded(); | 145 InitializeIfNeeded(); |
| 141 // A retry after a GC may pollute the counts, so perform gc now | 146 // A retry after a GC may pollute the counts, so perform gc now |
| 142 // to avoid that. | 147 // to avoid that. |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 0, | 697 0, |
| 693 1, // (re-)declaration | 698 1, // (re-)declaration |
| 694 EXPECT_RESULT, Number::New(0)); | 699 EXPECT_RESULT, Number::New(0)); |
| 695 } | 700 } |
| 696 } | 701 } |
| 697 | 702 |
| 698 | 703 |
| 699 | 704 |
| 700 class SimpleContext { | 705 class SimpleContext { |
| 701 public: | 706 public: |
| 702 SimpleContext() { | 707 SimpleContext() |
| 703 context_ = Context::New(); | 708 : handle_scope_(Isolate::GetCurrent()), |
| 709 context_(Context::New(Isolate::GetCurrent())) { |
| 704 context_->Enter(); | 710 context_->Enter(); |
| 705 } | 711 } |
| 706 | 712 |
| 707 virtual ~SimpleContext() { | 713 ~SimpleContext() { |
| 708 context_->Exit(); | 714 context_->Exit(); |
| 709 context_.Dispose(context_->GetIsolate()); | |
| 710 } | 715 } |
| 711 | 716 |
| 712 void Check(const char* source, | 717 void Check(const char* source, |
| 713 Expectations expectations, | 718 Expectations expectations, |
| 714 v8::Handle<Value> value = Local<Value>()) { | 719 v8::Handle<Value> value = Local<Value>()) { |
| 715 HandleScope scope(context_->GetIsolate()); | 720 HandleScope scope(context_->GetIsolate()); |
| 716 TryCatch catcher; | 721 TryCatch catcher; |
| 717 catcher.SetVerbose(true); | 722 catcher.SetVerbose(true); |
| 718 Local<Script> script = Script::Compile(String::New(source)); | 723 Local<Script> script = Script::Compile(String::New(source)); |
| 719 if (expectations == EXPECT_ERROR) { | 724 if (expectations == EXPECT_ERROR) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 730 } else { | 735 } else { |
| 731 CHECK(expectations == EXPECT_EXCEPTION); | 736 CHECK(expectations == EXPECT_EXCEPTION); |
| 732 CHECK(catcher.HasCaught()); | 737 CHECK(catcher.HasCaught()); |
| 733 if (!value.IsEmpty()) { | 738 if (!value.IsEmpty()) { |
| 734 CHECK_EQ(value, catcher.Exception()); | 739 CHECK_EQ(value, catcher.Exception()); |
| 735 } | 740 } |
| 736 } | 741 } |
| 737 } | 742 } |
| 738 | 743 |
| 739 private: | 744 private: |
| 740 Persistent<Context> context_; | 745 HandleScope handle_scope_; |
| 746 Local<Context> context_; |
| 741 }; | 747 }; |
| 742 | 748 |
| 743 | 749 |
| 744 TEST(CrossScriptReferences) { | 750 TEST(CrossScriptReferences) { |
| 745 HandleScope scope(Isolate::GetCurrent()); | 751 HandleScope scope(Isolate::GetCurrent()); |
| 746 | 752 |
| 747 { SimpleContext context; | 753 { SimpleContext context; |
| 748 context.Check("var x = 1; x", | 754 context.Check("var x = 1; x", |
| 749 EXPECT_RESULT, Number::New(1)); | 755 EXPECT_RESULT, Number::New(1)); |
| 750 context.Check("var x = 2; x", | 756 context.Check("var x = 2; x", |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 SimpleContext context; | 845 SimpleContext context; |
| 840 context.Check(firsts[i], EXPECT_RESULT, Number::New(1)); | 846 context.Check(firsts[i], EXPECT_RESULT, Number::New(1)); |
| 841 // TODO(rossberg): All tests should actually be errors in Harmony, | 847 // TODO(rossberg): All tests should actually be errors in Harmony, |
| 842 // but we currently do not detect the cases where the first declaration | 848 // but we currently do not detect the cases where the first declaration |
| 843 // is not lexical. | 849 // is not lexical. |
| 844 context.Check(seconds[j], | 850 context.Check(seconds[j], |
| 845 i < 2 ? EXPECT_RESULT : EXPECT_ERROR, Number::New(2)); | 851 i < 2 ? EXPECT_RESULT : EXPECT_ERROR, Number::New(2)); |
| 846 } | 852 } |
| 847 } | 853 } |
| 848 } | 854 } |
| OLD | NEW |