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

Side by Side Diff: test/cctest/cctest.h

Issue 24271002: remove GetCurrent from LocalContext (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 3 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 | « no previous file | test/cctest/test-api.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 2008 the V8 project authors. All rights reserved. 1 // Copyright 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 static RegisterThreadedTest* first_; 213 static RegisterThreadedTest* first_;
214 static int count_; 214 static int count_;
215 CcTest::TestFunction* callback_; 215 CcTest::TestFunction* callback_;
216 RegisterThreadedTest* prev_; 216 RegisterThreadedTest* prev_;
217 const char* name_; 217 const char* name_;
218 }; 218 };
219 219
220 // A LocalContext holds a reference to a v8::Context. 220 // A LocalContext holds a reference to a v8::Context.
221 class LocalContext { 221 class LocalContext {
222 public: 222 public:
223 LocalContext(v8::Isolate* isolate,
224 v8::ExtensionConfiguration* extensions = 0,
225 v8::Handle<v8::ObjectTemplate> global_template =
226 v8::Handle<v8::ObjectTemplate>(),
227 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) {
228 Initialize(isolate, extensions, global_template, global_object);
229 }
230
223 LocalContext(v8::ExtensionConfiguration* extensions = 0, 231 LocalContext(v8::ExtensionConfiguration* extensions = 0,
224 v8::Handle<v8::ObjectTemplate> global_template = 232 v8::Handle<v8::ObjectTemplate> global_template =
225 v8::Handle<v8::ObjectTemplate>(), 233 v8::Handle<v8::ObjectTemplate>(),
226 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) { 234 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) {
227 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 235 Initialize(CcTest::isolate(), extensions, global_template, global_object);
228 v8::HandleScope scope(isolate);
229 v8::Local<v8::Context> context = v8::Context::New(isolate,
230 extensions,
231 global_template,
232 global_object);
233 context_.Reset(isolate, context);
234 context->Enter();
235 // We can't do this later perhaps because of a fatal error.
236 isolate_ = context->GetIsolate();
237 } 236 }
238 237
239 virtual ~LocalContext() { 238 virtual ~LocalContext() {
240 v8::HandleScope scope(isolate_); 239 v8::HandleScope scope(isolate_);
241 v8::Local<v8::Context>::New(isolate_, context_)->Exit(); 240 v8::Local<v8::Context>::New(isolate_, context_)->Exit();
242 context_.Dispose(); 241 context_.Dispose();
243 } 242 }
244 243
245 v8::Context* operator->() { 244 v8::Context* operator->() {
246 return *reinterpret_cast<v8::Context**>(&context_); 245 return *reinterpret_cast<v8::Context**>(&context_);
247 } 246 }
248 v8::Context* operator*() { return operator->(); } 247 v8::Context* operator*() { return operator->(); }
249 bool IsReady() { return !context_.IsEmpty(); } 248 bool IsReady() { return !context_.IsEmpty(); }
250 249
251 v8::Local<v8::Context> local() { 250 v8::Local<v8::Context> local() {
252 return v8::Local<v8::Context>::New(isolate_, context_); 251 return v8::Local<v8::Context>::New(isolate_, context_);
253 } 252 }
254 253
255 private: 254 private:
255 void Initialize(v8::Isolate* isolate,
256 v8::ExtensionConfiguration* extensions,
257 v8::Handle<v8::ObjectTemplate> global_template,
258 v8::Handle<v8::Value> global_object) {
259 v8::HandleScope scope(isolate);
260 v8::Local<v8::Context> context = v8::Context::New(isolate,
261 extensions,
262 global_template,
263 global_object);
264 context_.Reset(isolate, context);
265 context->Enter();
266 // We can't do this later perhaps because of a fatal error.
267 isolate_ = isolate;
268 }
269
256 v8::Persistent<v8::Context> context_; 270 v8::Persistent<v8::Context> context_;
257 v8::Isolate* isolate_; 271 v8::Isolate* isolate_;
258 }; 272 };
259 273
260 static inline v8::Local<v8::Value> v8_num(double x) { 274 static inline v8::Local<v8::Value> v8_num(double x) {
261 return v8::Number::New(x); 275 return v8::Number::New(x);
262 } 276 }
263 277
264 278
265 static inline v8::Local<v8::String> v8_str(const char* x) { 279 static inline v8::Local<v8::String> v8_str(const char* x) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 static inline void SimulateFullSpace(v8::internal::PagedSpace* space) { 325 static inline void SimulateFullSpace(v8::internal::PagedSpace* space) {
312 int old_linear_size = static_cast<int>(space->limit() - space->top()); 326 int old_linear_size = static_cast<int>(space->limit() - space->top());
313 space->Free(space->top(), old_linear_size); 327 space->Free(space->top(), old_linear_size);
314 space->SetTop(space->limit(), space->limit()); 328 space->SetTop(space->limit(), space->limit());
315 space->ResetFreeList(); 329 space->ResetFreeList();
316 space->ClearStats(); 330 space->ClearStats();
317 } 331 }
318 332
319 333
320 #endif // ifndef CCTEST_H_ 334 #endif // ifndef CCTEST_H_
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698