Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: test/cctest/test-decls.cc

Issue 15038002: Revert "deprecate Context::New which returns Persistent" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-debug.cc ('k') | test/cctest/test-hashing.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 Isolate* isolate = Isolate::GetCurrent(); 121 HandleScope scope(Isolate::GetCurrent());
122 HandleScope scope(isolate);
123 Local<FunctionTemplate> function = FunctionTemplate::New(); 122 Local<FunctionTemplate> function = FunctionTemplate::New();
124 Local<Value> data = External::New(this); 123 Local<Value> data = External::New(this);
125 GetHolder(function)->SetNamedPropertyHandler(&HandleGet, 124 GetHolder(function)->SetNamedPropertyHandler(&HandleGet,
126 &HandleSet, 125 &HandleSet,
127 &HandleQuery, 126 &HandleQuery,
128 0, 0, 127 0, 0,
129 data); 128 data);
130 context_.Reset(isolate, 129 context_ = Context::New(0, function->InstanceTemplate(), Local<Value>());
131 Context::New(isolate,
132 0,
133 function->InstanceTemplate(),
134 Local<Value>()));
135 context_->Enter(); 130 context_->Enter();
136 is_initialized_ = true; 131 is_initialized_ = true;
137 PostInitializeContext(Local<Context>::New(isolate, context_)); 132 PostInitializeContext(Local<Context>::New(Isolate::GetCurrent(), context_));
138 } 133 }
139 134
140 135
141 void DeclarationContext::Check(const char* source, 136 void DeclarationContext::Check(const char* source,
142 int get, int set, int query, 137 int get, int set, int query,
143 Expectations expectations, 138 Expectations expectations,
144 v8::Handle<Value> value) { 139 v8::Handle<Value> value) {
145 InitializeIfNeeded(); 140 InitializeIfNeeded();
146 // A retry after a GC may pollute the counts, so perform gc now 141 // A retry after a GC may pollute the counts, so perform gc now
147 // to avoid that. 142 // to avoid that.
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 0, 692 0,
698 1, // (re-)declaration 693 1, // (re-)declaration
699 EXPECT_RESULT, Number::New(0)); 694 EXPECT_RESULT, Number::New(0));
700 } 695 }
701 } 696 }
702 697
703 698
704 699
705 class SimpleContext { 700 class SimpleContext {
706 public: 701 public:
707 SimpleContext() 702 SimpleContext() {
708 : handle_scope_(Isolate::GetCurrent()), 703 context_ = Context::New();
709 context_(Context::New(Isolate::GetCurrent())) {
710 context_->Enter(); 704 context_->Enter();
711 } 705 }
712 706
713 ~SimpleContext() { 707 virtual ~SimpleContext() {
714 context_->Exit(); 708 context_->Exit();
709 context_.Dispose(context_->GetIsolate());
715 } 710 }
716 711
717 void Check(const char* source, 712 void Check(const char* source,
718 Expectations expectations, 713 Expectations expectations,
719 v8::Handle<Value> value = Local<Value>()) { 714 v8::Handle<Value> value = Local<Value>()) {
720 HandleScope scope(context_->GetIsolate()); 715 HandleScope scope(context_->GetIsolate());
721 TryCatch catcher; 716 TryCatch catcher;
722 catcher.SetVerbose(true); 717 catcher.SetVerbose(true);
723 Local<Script> script = Script::Compile(String::New(source)); 718 Local<Script> script = Script::Compile(String::New(source));
724 if (expectations == EXPECT_ERROR) { 719 if (expectations == EXPECT_ERROR) {
(...skipping 10 matching lines...) Expand all
735 } else { 730 } else {
736 CHECK(expectations == EXPECT_EXCEPTION); 731 CHECK(expectations == EXPECT_EXCEPTION);
737 CHECK(catcher.HasCaught()); 732 CHECK(catcher.HasCaught());
738 if (!value.IsEmpty()) { 733 if (!value.IsEmpty()) {
739 CHECK_EQ(value, catcher.Exception()); 734 CHECK_EQ(value, catcher.Exception());
740 } 735 }
741 } 736 }
742 } 737 }
743 738
744 private: 739 private:
745 HandleScope handle_scope_; 740 Persistent<Context> context_;
746 Local<Context> context_;
747 }; 741 };
748 742
749 743
750 TEST(CrossScriptReferences) { 744 TEST(CrossScriptReferences) {
751 HandleScope scope(Isolate::GetCurrent()); 745 HandleScope scope(Isolate::GetCurrent());
752 746
753 { SimpleContext context; 747 { SimpleContext context;
754 context.Check("var x = 1; x", 748 context.Check("var x = 1; x",
755 EXPECT_RESULT, Number::New(1)); 749 EXPECT_RESULT, Number::New(1));
756 context.Check("var x = 2; x", 750 context.Check("var x = 2; x",
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 SimpleContext context; 839 SimpleContext context;
846 context.Check(firsts[i], EXPECT_RESULT, Number::New(1)); 840 context.Check(firsts[i], EXPECT_RESULT, Number::New(1));
847 // TODO(rossberg): All tests should actually be errors in Harmony, 841 // TODO(rossberg): All tests should actually be errors in Harmony,
848 // but we currently do not detect the cases where the first declaration 842 // but we currently do not detect the cases where the first declaration
849 // is not lexical. 843 // is not lexical.
850 context.Check(seconds[j], 844 context.Check(seconds[j],
851 i < 2 ? EXPECT_RESULT : EXPECT_ERROR, Number::New(2)); 845 i < 2 ? EXPECT_RESULT : EXPECT_ERROR, Number::New(2));
852 } 846 }
853 } 847 }
854 } 848 }
OLDNEW
« no previous file with comments | « test/cctest/test-debug.cc ('k') | test/cctest/test-hashing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698