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

Side by Side Diff: include/v8.h

Issue 22795004: abstract eternal into class (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 4 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 | src/api.cc » ('j') | src/api.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 class StackTrace; 138 class StackTrace;
139 class String; 139 class String;
140 class StringObject; 140 class StringObject;
141 class Symbol; 141 class Symbol;
142 class SymbolObject; 142 class SymbolObject;
143 class Uint32; 143 class Uint32;
144 class Utils; 144 class Utils;
145 class Value; 145 class Value;
146 template <class T> class Handle; 146 template <class T> class Handle;
147 template <class T> class Local; 147 template <class T> class Local;
148 template <class T> class Eternal;
148 template <class T> class Persistent; 149 template <class T> class Persistent;
149 class FunctionTemplate; 150 class FunctionTemplate;
150 class ObjectTemplate; 151 class ObjectTemplate;
151 class Data; 152 class Data;
152 class AccessorInfo; 153 class AccessorInfo;
153 template<typename T> class PropertyCallbackInfo; 154 template<typename T> class PropertyCallbackInfo;
154 class StackTrace; 155 class StackTrace;
155 class StackFrame; 156 class StackFrame;
156 class Isolate; 157 class Isolate;
157 class DeclaredAccessorDescriptor; 158 class DeclaredAccessorDescriptor;
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 friend class HandleScope; 382 friend class HandleScope;
382 383
383 #ifndef V8_USE_UNSAFE_HANDLES 384 #ifndef V8_USE_UNSAFE_HANDLES
384 V8_INLINE(static Handle<T> New(Isolate* isolate, T* that)); 385 V8_INLINE(static Handle<T> New(Isolate* isolate, T* that));
385 #endif 386 #endif
386 387
387 T* val_; 388 T* val_;
388 }; 389 };
389 390
390 391
391 // A value which will never be returned by Local::Eternalize
392 // Useful for static initialization
393 const int kUninitializedEternalIndex = -1;
394
395
396 /** 392 /**
397 * A light-weight stack-allocated object handle. All operations 393 * A light-weight stack-allocated object handle. All operations
398 * that return objects from within v8 return them in local handles. They 394 * that return objects from within v8 return them in local handles. They
399 * are created within HandleScopes, and all local handles allocated within a 395 * are created within HandleScopes, and all local handles allocated within a
400 * handle scope are destroyed when the handle scope is destroyed. Hence it 396 * handle scope are destroyed when the handle scope is destroyed. Hence it
401 * is not necessary to explicitly deallocate local handles. 397 * is not necessary to explicitly deallocate local handles.
402 */ 398 */
403 // TODO(dcarney): deprecate entire class 399 // TODO(dcarney): deprecate entire class
404 template <class T> class Local : public Handle<T> { 400 template <class T> class Local : public Handle<T> {
405 public: 401 public:
(...skipping 25 matching lines...) Expand all
431 template <class S> V8_INLINE(Local(Handle<S> that)) 427 template <class S> V8_INLINE(Local(Handle<S> that))
432 : Handle<T>(reinterpret_cast<T*>(*that)) { 428 : Handle<T>(reinterpret_cast<T*>(*that)) {
433 TYPE_CHECK(T, S); 429 TYPE_CHECK(T, S);
434 } 430 }
435 #endif 431 #endif
436 432
437 template <class S> V8_INLINE(Local<S> As()) { 433 template <class S> V8_INLINE(Local<S> As()) {
438 return Local<S>::Cast(*this); 434 return Local<S>::Cast(*this);
439 } 435 }
440 436
441 // Keep this Local alive for the lifetime of the Isolate.
442 // It remains retrievable via the returned index,
443 V8_INLINE(int Eternalize(Isolate* isolate));
444 V8_INLINE(static Local<T> GetEternal(Isolate* isolate, int index));
445
446 /** 437 /**
447 * Create a local handle for the content of another handle. 438 * Create a local handle for the content of another handle.
448 * The referee is kept alive by the local handle even when 439 * The referee is kept alive by the local handle even when
449 * the original handle is destroyed/disposed. 440 * the original handle is destroyed/disposed.
450 */ 441 */
451 V8_INLINE(static Local<T> New(Handle<T> that)); 442 V8_INLINE(static Local<T> New(Handle<T> that));
452 V8_INLINE(static Local<T> New(Isolate* isolate, Handle<T> that)); 443 V8_INLINE(static Local<T> New(Isolate* isolate, Handle<T> that));
453 #ifndef V8_USE_UNSAFE_HANDLES 444 #ifndef V8_USE_UNSAFE_HANDLES
454 // TODO(dcarney): remove before cutover 445 // TODO(dcarney): remove before cutover
455 V8_INLINE(static Local<T> New(Isolate* isolate, const Persistent<T>& that)); 446 V8_INLINE(static Local<T> New(Isolate* isolate, const Persistent<T>& that));
456 447
457 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR 448 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR
458 449
459 private: 450 private:
460 #endif 451 #endif
461 template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } 452 template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { }
462 #endif 453 #endif
463 454
464 private: 455 private:
465 friend class Utils; 456 friend class Utils;
457 template<class F> friend class Eternal;
466 template<class F> friend class Persistent; 458 template<class F> friend class Persistent;
467 template<class F> friend class Handle; 459 template<class F> friend class Handle;
468 friend class Arguments; 460 friend class Arguments;
469 template<class F> friend class FunctionCallbackInfo; 461 template<class F> friend class FunctionCallbackInfo;
470 template<class F> friend class PropertyCallbackInfo; 462 template<class F> friend class PropertyCallbackInfo;
471 friend class String; 463 friend class String;
472 friend class Object; 464 friend class Object;
473 friend class AccessorInfo; 465 friend class AccessorInfo;
474 friend class Context; 466 friend class Context;
475 template<class F> friend class internal::CustomArguments; 467 template<class F> friend class internal::CustomArguments;
476 friend class HandleScope; 468 friend class HandleScope;
477 469
478 V8_INLINE(static Local<T> New(Isolate* isolate, T* that)); 470 V8_INLINE(static Local<T> New(Isolate* isolate, T* that));
479 }; 471 };
480 472
473
474 // Eternal handles are set-once handles that live for the life of the isolate.
475 template <class T> class Eternal {
476 public:
477 V8_INLINE(Eternal()) : index_(kInitialValue) { }
478 template<class S>
479 V8_INLINE(Eternal(Isolate* isolate, Local<S> handle))
480 : index_(kInitialValue) {
481 Set(isolate, handle);
482 }
483 // Can only be safely called if already set.
484 V8_INLINE(Local<T> Get(Isolate* isolate));
485 V8_INLINE(bool IsSet()) { return index_ != kInitialValue; }
486 template<class S>
Sven Panne 2013/08/13 06:11:18 Why do we have a separate template parameter here?
dcarney 2013/08/13 06:46:24 As discussed offline, TYPE_CHECK is in implementat
487 V8_INLINE(void Set(Isolate* isolate, Local<S> handle));
488
489 private:
490 static const int kInitialValue = -1;
491 int index_;
492 };
493
494
481 /** 495 /**
482 * An object reference that is independent of any handle scope. Where 496 * An object reference that is independent of any handle scope. Where
483 * a Local handle only lives as long as the HandleScope in which it was 497 * a Local handle only lives as long as the HandleScope in which it was
484 * allocated, a Persistent handle remains valid until it is explicitly 498 * allocated, a Persistent handle remains valid until it is explicitly
485 * disposed. 499 * disposed.
486 * 500 *
487 * A persistent handle contains a reference to a storage cell within 501 * A persistent handle contains a reference to a storage cell within
488 * the v8 engine which holds an object value and which is updated by 502 * the v8 engine which holds an object value and which is updated by
489 * the garbage collector whenever the object is moved. A new storage 503 * the garbage collector whenever the object is moved. A new storage
490 * cell can be created using Persistent::New and existing handles can 504 * cell can be created using Persistent::New and existing handles can
(...skipping 4299 matching lines...) Expand 10 before | Expand all | Expand 10 after
4790 V8(); 4804 V8();
4791 4805
4792 static internal::Object** GlobalizeReference(internal::Isolate* isolate, 4806 static internal::Object** GlobalizeReference(internal::Isolate* isolate,
4793 internal::Object** handle); 4807 internal::Object** handle);
4794 static void DisposeGlobal(internal::Object** global_handle); 4808 static void DisposeGlobal(internal::Object** global_handle);
4795 typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback; 4809 typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback;
4796 static void MakeWeak(internal::Object** global_handle, 4810 static void MakeWeak(internal::Object** global_handle,
4797 void* data, 4811 void* data,
4798 RevivableCallback weak_reference_callback); 4812 RevivableCallback weak_reference_callback);
4799 static void ClearWeak(internal::Object** global_handle); 4813 static void ClearWeak(internal::Object** global_handle);
4800 static int Eternalize(internal::Isolate* isolate, 4814 static void Eternalize(internal::Isolate* isolate,
4801 internal::Object** handle); 4815 internal::Object** handle,
4816 int* index);
4802 static internal::Object** GetEternal(internal::Isolate* isolate, int index); 4817 static internal::Object** GetEternal(internal::Isolate* isolate, int index);
4803 4818
4804 template <class T> friend class Handle; 4819 template <class T> friend class Handle;
4805 template <class T> friend class Local; 4820 template <class T> friend class Local;
4821 template <class T> friend class Eternal;
4806 template <class T> friend class Persistent; 4822 template <class T> friend class Persistent;
4807 friend class Context; 4823 friend class Context;
4808 }; 4824 };
4809 4825
4810 4826
4811 /** 4827 /**
4812 * An external exception handler. 4828 * An external exception handler.
4813 */ 4829 */
4814 class V8_EXPORT TryCatch { 4830 class V8_EXPORT TryCatch {
4815 public: 4831 public:
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
5657 Local<T> Local<T>::New(Isolate* isolate, T* that) { 5673 Local<T> Local<T>::New(Isolate* isolate, T* that) {
5658 if (that == NULL) return Local<T>(); 5674 if (that == NULL) return Local<T>();
5659 T* that_ptr = that; 5675 T* that_ptr = that;
5660 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); 5676 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
5661 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( 5677 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
5662 reinterpret_cast<internal::Isolate*>(isolate), *p))); 5678 reinterpret_cast<internal::Isolate*>(isolate), *p)));
5663 } 5679 }
5664 5680
5665 5681
5666 template<class T> 5682 template<class T>
5667 int Local<T>::Eternalize(Isolate* isolate) { 5683 template<class S>
5668 return V8::Eternalize(reinterpret_cast<internal::Isolate*>(isolate), 5684 void Eternal<T>::Set(Isolate* isolate, Local<S> handle) {
5669 reinterpret_cast<internal::Object**>(this->val_)); 5685 TYPE_CHECK(T, S);
5686 V8::Eternalize(reinterpret_cast<internal::Isolate*>(isolate),
5687 reinterpret_cast<internal::Object**>(*handle),
5688 &this->index_);
5670 } 5689 }
5671 5690
5672 5691
5673 template<class T> 5692 template<class T>
5674 Local<T> Local<T>::GetEternal(Isolate* isolate, int index) { 5693 Local<T> Eternal<T>::Get(Isolate* isolate) {
5675 internal::Object** handle = 5694 internal::Object** handle =
5676 V8::GetEternal(reinterpret_cast<internal::Isolate*>(isolate), index); 5695 V8::GetEternal(reinterpret_cast<internal::Isolate*>(isolate), index_);
5677 return Local<T>(T::Cast(reinterpret_cast<Value*>(handle))); 5696 return Local<T>(T::Cast(reinterpret_cast<Value*>(handle)));
5678 } 5697 }
5679 5698
5680 5699
5681 #ifdef V8_USE_UNSAFE_HANDLES 5700 #ifdef V8_USE_UNSAFE_HANDLES
5682 template <class T> 5701 template <class T>
5683 Persistent<T> Persistent<T>::New(Handle<T> that) { 5702 Persistent<T> Persistent<T>::New(Handle<T> that) {
5684 return New(Isolate::GetCurrent(), that.val_); 5703 return New(Isolate::GetCurrent(), that.val_);
5685 } 5704 }
5686 5705
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after
6586 */ 6605 */
6587 6606
6588 6607
6589 } // namespace v8 6608 } // namespace v8
6590 6609
6591 6610
6592 #undef TYPE_CHECK 6611 #undef TYPE_CHECK
6593 6612
6594 6613
6595 #endif // V8_H_ 6614 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | src/api.cc » ('j') | src/api.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698