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

Side by Side Diff: include/v8.h

Issue 14788013: Add Persistent<T>::Reset which disposes the handle and redirects it to point to another object. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: code review (svenpanne) + fixes (val_ -> this->val_) 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
« 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 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 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 669
670 V8_INLINE(uint16_t WrapperClassId() const); 670 V8_INLINE(uint16_t WrapperClassId() const);
671 671
672 /** 672 /**
673 * Returns the class ID previously assigned to this handle or 0 if no class ID 673 * Returns the class ID previously assigned to this handle or 0 if no class ID
674 * was previously assigned. 674 * was previously assigned.
675 */ 675 */
676 // TODO(dcarney): remove before cutover 676 // TODO(dcarney): remove before cutover
677 V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const); 677 V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const);
678 678
679 /**
680 * Disposes the current contents of the handle and replaces it.
681 */
682 V8_INLINE(void Reset(Isolate* isolate, const Handle<T>& other));
683
679 #ifndef V8_USE_UNSAFE_HANDLES 684 #ifndef V8_USE_UNSAFE_HANDLES
680 685
681 #ifndef V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT 686 #ifndef V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT
682 687
683 private: 688 private:
684 #endif 689 #endif
685 // TODO(dcarney): make unlinkable before cutover 690 // TODO(dcarney): make unlinkable before cutover
686 V8_INLINE(Persistent(const Persistent& that)) : val_(that.val_) {} 691 V8_INLINE(Persistent(const Persistent& that)) : val_(that.val_) {}
687 // TODO(dcarney): make unlinkable before cutover 692 // TODO(dcarney): make unlinkable before cutover
688 V8_INLINE(Persistent& operator=(const Persistent& that)) { // NOLINT 693 V8_INLINE(Persistent& operator=(const Persistent& that)) { // NOLINT
(...skipping 4653 matching lines...) Expand 10 before | Expand all | Expand 10 after
5342 true, 5347 true,
5343 I::kNodeIsPartiallyDependentShift); 5348 I::kNodeIsPartiallyDependentShift);
5344 } 5349 }
5345 5350
5346 template <class T> 5351 template <class T>
5347 void Persistent<T>::SetWrapperClassId(uint16_t class_id) { 5352 void Persistent<T>::SetWrapperClassId(uint16_t class_id) {
5348 SetWrapperClassId(Isolate::GetCurrent(), class_id); 5353 SetWrapperClassId(Isolate::GetCurrent(), class_id);
5349 } 5354 }
5350 5355
5351 template <class T> 5356 template <class T>
5357 void Persistent<T>::Reset(Isolate* isolate, const Handle<T>& other) {
5358 Dispose(isolate);
5359 #ifdef V8_USE_UNSAFE_HANDLES
5360 *this = *New(isolate, other);
5361 #else
5362 if (other.IsEmpty()) {
5363 this->val_ = NULL;
5364 return;
5365 }
5366 internal::Object** p = reinterpret_cast<internal::Object**>(other.val_);
5367 this->val_ = reinterpret_cast<T*>(
5368 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p));
5369 #endif
5370 }
5371
5372 template <class T>
5352 void Persistent<T>::SetWrapperClassId(Isolate* isolate, uint16_t class_id) { 5373 void Persistent<T>::SetWrapperClassId(Isolate* isolate, uint16_t class_id) {
5353 typedef internal::Internals I; 5374 typedef internal::Internals I;
5354 if (this->IsEmpty()) return; 5375 if (this->IsEmpty()) return;
5355 if (!I::IsInitialized(isolate)) return; 5376 if (!I::IsInitialized(isolate)) return;
5356 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); 5377 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
5357 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; 5378 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
5358 *reinterpret_cast<uint16_t*>(addr) = class_id; 5379 *reinterpret_cast<uint16_t*>(addr) = class_id;
5359 } 5380 }
5360 5381
5361 template <class T> 5382 template <class T>
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
5912 5933
5913 5934
5914 } // namespace v8 5935 } // namespace v8
5915 5936
5916 5937
5917 #undef V8EXPORT 5938 #undef V8EXPORT
5918 #undef TYPE_CHECK 5939 #undef TYPE_CHECK
5919 5940
5920 5941
5921 #endif // V8_H_ 5942 #endif // V8_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