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

Side by Side Diff: include/v8.h

Issue 18842: Experimental: periodic merge of the bleeding_edge branch to the... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/toiger/
Patch Set: Created 11 years, 11 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 | « SConstruct ('k') | src/api.h » ('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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 * place in the new handle scope until it is deleted. After that, 389 * place in the new handle scope until it is deleted. After that,
390 * new handles will again be allocated in the original handle scope. 390 * new handles will again be allocated in the original handle scope.
391 * 391 *
392 * After the handle scope of a local handle has been deleted the 392 * After the handle scope of a local handle has been deleted the
393 * garbage collector will no longer track the object stored in the 393 * garbage collector will no longer track the object stored in the
394 * handle and may deallocate it. The behavior of accessing a handle 394 * handle and may deallocate it. The behavior of accessing a handle
395 * for which the handle scope has been deleted is undefined. 395 * for which the handle scope has been deleted is undefined.
396 */ 396 */
397 class EXPORT HandleScope { 397 class EXPORT HandleScope {
398 public: 398 public:
399 HandleScope() : previous_(current_), is_closed_(false) { 399 HandleScope();
400 current_.extensions = 0;
401 }
402 400
403 ~HandleScope() { 401 ~HandleScope();
404 // TODO(1245391): In a perfect world, there would be a way of not
405 // having to check for explicitly closed scopes maybe through
406 // subclassing HandleScope?
407 if (!is_closed_) RestorePreviousState();
408 }
409 402
410 /** 403 /**
411 * TODO(1245391): Consider introducing a subclass for this.
412 * Closes the handle scope and returns the value as a handle in the 404 * Closes the handle scope and returns the value as a handle in the
413 * previous scope, which is the new current scope after the call. 405 * previous scope, which is the new current scope after the call.
414 */ 406 */
415 template <class T> Local<T> Close(Handle<T> value); 407 template <class T> Local<T> Close(Handle<T> value);
416 408
417 /** 409 /**
418 * Counts the number of allocated handles. 410 * Counts the number of allocated handles.
419 */ 411 */
420 static int NumberOfHandles(); 412 static int NumberOfHandles();
421 413
422 /** 414 /**
423 * Creates a new handle with the given value. 415 * Creates a new handle with the given value.
424 */ 416 */
425 static void** CreateHandle(void* value); 417 static void** CreateHandle(void* value);
426 418
427 private: 419 private:
428 // Make it impossible to create heap-allocated or illegal handle 420 // Make it impossible to create heap-allocated or illegal handle
429 // scopes by disallowing certain operations. 421 // scopes by disallowing certain operations.
430 HandleScope(const HandleScope&); 422 HandleScope(const HandleScope&);
431 void operator=(const HandleScope&); 423 void operator=(const HandleScope&);
432 void* operator new(size_t size); 424 void* operator new(size_t size);
433 void operator delete(void*, size_t); 425 void operator delete(void*, size_t);
434 426
427 // This Data class is accessible internally through a typedef in the
428 // ImplementationUtilities class.
435 class EXPORT Data { 429 class EXPORT Data {
436 public: 430 public:
437 int extensions; 431 int extensions;
438 void** next; 432 void** next;
439 void** limit; 433 void** limit;
440 inline void Initialize() { 434 inline void Initialize() {
441 extensions = -1; 435 extensions = -1;
442 next = limit = NULL; 436 next = limit = NULL;
443 } 437 }
444 }; 438 };
445 439
446 static Data current_; 440 Data previous_;
447 const Data previous_;
448 441
449 /** 442 // Allow for the active closing of HandleScopes which allows to pass a handle
450 * Re-establishes the previous scope state. Should be called only 443 // from the HandleScope being closed to the next top most HandleScope.
451 * once, and only for the current scope.
452 */
453 void RestorePreviousState() {
454 if (current_.extensions > 0) DeleteExtensions();
455 current_ = previous_;
456 #ifdef DEBUG
457 ZapRange(current_.next, current_.limit);
458 #endif
459 }
460
461 // TODO(1245391): Consider creating a subclass for this.
462 bool is_closed_; 444 bool is_closed_;
463 void** RawClose(void** value); 445 void** RawClose(void** value);
464 446
465 /** Deallocates any extensions used by the current scope.*/
466 static void DeleteExtensions();
467
468 // Zaps the handles in the half-open interval [start, end).
469 static void ZapRange(void** start, void** end);
470
471 friend class ImplementationUtilities; 447 friend class ImplementationUtilities;
472 }; 448 };
473 449
474 450
475 // --- S p e c i a l o b j e c t s --- 451 // --- S p e c i a l o b j e c t s ---
476 452
477 453
478 /** 454 /**
479 * The superclass of values and API object templates. 455 * The superclass of values and API object templates.
480 */ 456 */
(...skipping 1796 matching lines...) Expand 10 before | Expand all | Expand 10 after
2277 /** 2253 /**
2278 * Stop preemption. 2254 * Stop preemption.
2279 */ 2255 */
2280 static void StopPreemption(); 2256 static void StopPreemption();
2281 2257
2282 /** 2258 /**
2283 * Returns whether or not the locker is locked by the current thread. 2259 * Returns whether or not the locker is locked by the current thread.
2284 */ 2260 */
2285 static bool IsLocked(); 2261 static bool IsLocked();
2286 2262
2263 /**
2264 * Returns whether v8::Locker is being used by this V8 instance.
2265 */
2266 static bool IsActive() { return active_; }
2267
2287 private: 2268 private:
2288 bool has_lock_; 2269 bool has_lock_;
2289 bool top_level_; 2270 bool top_level_;
2290 2271
2272 static bool active_;
2273
2291 // Disallow copying and assigning. 2274 // Disallow copying and assigning.
2292 Locker(const Locker&); 2275 Locker(const Locker&);
2293 void operator=(const Locker&); 2276 void operator=(const Locker&);
2294 }; 2277 };
2295 2278
2296 2279
2297 2280
2298 // --- I m p l e m e n t a t i o n --- 2281 // --- I m p l e m e n t a t i o n ---
2299 2282
2300 template <class T> 2283 template <class T>
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
2463 2446
2464 } // namespace v8 2447 } // namespace v8
2465 2448
2466 2449
2467 #undef EXPORT 2450 #undef EXPORT
2468 #undef EXPORT_INLINE 2451 #undef EXPORT_INLINE
2469 #undef TYPE_CHECK 2452 #undef TYPE_CHECK
2470 2453
2471 2454
2472 #endif // V8_H_ 2455 #endif // V8_H_
OLDNEW
« no previous file with comments | « SConstruct ('k') | src/api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698