Index: src/i18n.cc |
diff --git a/src/i18n.cc b/src/i18n.cc |
index 80a739c285e16c6973116edd15cffe54fcabfe66..f340cc0bcf1e9524584b221186c9604a7fe6ea6d 100644 |
--- a/src/i18n.cc |
+++ b/src/i18n.cc |
@@ -864,15 +864,24 @@ icu::SimpleDateFormat* DateFormat::UnpackDateFormat( |
} |
-void DateFormat::DeleteDateFormat(v8::Isolate* isolate, |
- Persistent<v8::Value>* object, |
- void* param) { |
- // First delete the hidden C++ object. |
- delete reinterpret_cast<icu::SimpleDateFormat*>(Handle<JSObject>::cast( |
- v8::Utils::OpenPersistent(object))->GetInternalField(0)); |
- |
- // Then dispose of the persistent handle to JS object. |
- object->Reset(); |
+template<class T> |
+void DeleteNativeObjectAt(const v8::WeakCallbackData<v8::Value, void>& data, |
+ int index) { |
+ v8::Local<v8::Object> obj = v8::Handle<v8::Object>::Cast(data.GetValue()); |
+ delete reinterpret_cast<T*>(obj->GetAlignedPointerFromInternalField(index)); |
+} |
+ |
+ |
+static void DestroyGlobalHandle( |
+ const v8::WeakCallbackData<v8::Value, void>& data) { |
+ GlobalHandles::Destroy(reinterpret_cast<Object**>(data.GetParameter())); |
+} |
+ |
+ |
+void DateFormat::DeleteDateFormat( |
+ const v8::WeakCallbackData<v8::Value, void>& data) { |
+ DeleteNativeObjectAt<icu::SimpleDateFormat>(data, 0); |
+ DestroyGlobalHandle(data); |
} |
@@ -928,15 +937,10 @@ icu::DecimalFormat* NumberFormat::UnpackNumberFormat( |
} |
-void NumberFormat::DeleteNumberFormat(v8::Isolate* isolate, |
- Persistent<v8::Value>* object, |
- void* param) { |
- // First delete the hidden C++ object. |
- delete reinterpret_cast<icu::DecimalFormat*>(Handle<JSObject>::cast( |
- v8::Utils::OpenPersistent(object))->GetInternalField(0)); |
- |
- // Then dispose of the persistent handle to JS object. |
- object->Reset(); |
+void NumberFormat::DeleteNumberFormat( |
+ const v8::WeakCallbackData<v8::Value, void>& data) { |
+ DeleteNativeObjectAt<icu::DecimalFormat>(data, 0); |
+ DestroyGlobalHandle(data); |
} |
@@ -989,15 +993,10 @@ icu::Collator* Collator::UnpackCollator(Isolate* isolate, |
} |
-void Collator::DeleteCollator(v8::Isolate* isolate, |
- Persistent<v8::Value>* object, |
- void* param) { |
- // First delete the hidden C++ object. |
- delete reinterpret_cast<icu::Collator*>(Handle<JSObject>::cast( |
- v8::Utils::OpenPersistent(object))->GetInternalField(0)); |
- |
- // Then dispose of the persistent handle to JS object. |
- object->Reset(); |
+void Collator::DeleteCollator( |
+ const v8::WeakCallbackData<v8::Value, void>& data) { |
+ DeleteNativeObjectAt<icu::Collator>(data, 0); |
+ DestroyGlobalHandle(data); |
} |
@@ -1053,18 +1052,11 @@ icu::BreakIterator* BreakIterator::UnpackBreakIterator(Isolate* isolate, |
} |
-void BreakIterator::DeleteBreakIterator(v8::Isolate* isolate, |
- Persistent<v8::Value>* object, |
- void* param) { |
- // First delete the hidden C++ object. |
- delete reinterpret_cast<icu::BreakIterator*>(Handle<JSObject>::cast( |
- v8::Utils::OpenPersistent(object))->GetInternalField(0)); |
- |
- delete reinterpret_cast<icu::UnicodeString*>(Handle<JSObject>::cast( |
- v8::Utils::OpenPersistent(object))->GetInternalField(1)); |
- |
- // Then dispose of the persistent handle to JS object. |
- object->Reset(); |
+void BreakIterator::DeleteBreakIterator( |
+ const v8::WeakCallbackData<v8::Value, void>& data) { |
+ DeleteNativeObjectAt<icu::BreakIterator>(data, 0); |
+ DeleteNativeObjectAt<icu::UnicodeString>(data, 1); |
+ DestroyGlobalHandle(data); |
} |
} } // namespace v8::internal |